Community
Arnold General Rendering Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sample C++ shader code

9 REPLIES 9
Reply
Message 1 of 10
mkesson4VQY4
964 Views, 9 Replies

Sample C++ shader code

I am looking for a few C++ code samples of shaders. Can you direct me to a location where I can download the code?

9 REPLIES 9
Message 2 of 10

What kind of shader code are you looking for? You can find some examples of OSL shaders here:

https://thhube.github.io/tutorials/osl/osl.html

Message 3 of 10

SItoA is now open source, you can check that code.

https://github.com/Autodesk/sitoa



// Stephen Blair
// Arnold Renderer Support
Message 4 of 10
mkesson4VQY4
in reply to: mkesson4VQY4

Thank you Stephen. I use a text editor called Cutter, that I have written in Java, for all my teaching. I have adapted it to help my students write and compile shaders written in C++. It handles the writing of make files for OSX and Linux and .bat files on Windows. It avoids the necessity of using Visual Studio.

Despite what I am accomplishing with the added features of my "Cutter" text editor I'm still very new to writing shaders or what I would normally call pattern plugins in RenderMan. For example, I don't know how to assign a color to the transparency output of a node. I am looking for examples of C++ code that would help me gain a better understanding of writing Arnold shaders. At this stage I'm not interested in writing full-on materials (closures). I'm pretty comfortable with writing OSL shaders but I am new to writing C++ shaders.

Message 5 of 10
j1701115
in reply to: mkesson4VQY4

Since I'm also affected by this https://answers.arnoldrenderer.com/questions/20999/problem-logging-to-forum.html I'll post it here instead of creating a new thread because it's at least a little bit related.


The question is: How can I separate direct and indirect results I get from functions like AiOrenNayarBSDF()?

As described in the conversion notes (https://docs.arnoldrenderer.com/display/A5ARP/Converting+to+Closures) with Arnold 4 I got two functions. One for direct AiDirectDiffuse() and one for indirect AiIndirectDiffuse(). That way i can treat the results further.

With closures now however that seems to be more difficult. I found this:
https://forums.autodesk.com/t5/maya-programming/how-to-ignore-indirect-specular-with-aimicrofacetbsd...
but that only kicks in in advance. What I'm looking for are the different results of functions like AiOrenNayarBSDF() which I want to use further down the road in my shader.

Message 6 of 10
maxtarpini
in reply to: j1701115

You can implement your own eval/sample routines and ..

AtRGB diffuse, diffuse_direct, diffuse_indirect;
[...]
AtBSDF *diffuse_brdf = AiOrenNayarBSDF(state, diffuse_weight, state->Nf, roughness);
AiBSDFIntegrate(state, &diffuse_direct, &diffuse_indirect, diffuse_brdf);
diffuse = diffuse_direct + diffuse_indirect;
[...]

However then you're alone supporting for example transparency etc.


Message 7 of 10
j1701115
in reply to: j1701115

Oh I see, integrate as an independent function. Not like the previous AiOrenNayarIntegrate(). That's handy for custom brdfs as well. Thanks!
Message 8 of 10
j1701115
in reply to: j1701115

Okay great that works like a charm. The catch is that Maya doesn't let me assign this to an object if I have out.RGB() instead of out.CLOSURE() and have node->output_type set accordingly.
I thought about using an AiClosureMatte() as sort of a fake closure and use my result as weight but I don't want any additional unnecessary processing of course. However I assume there's a better way. So what's the official way in such cases?

Message 9 of 10
maxtarpini
in reply to: j1701115

No problems here I can use out.RGB() stuff in Maya with latest and also previous Arnold. Checked latest API changes and it seems nothing changed on this regard.

Message 10 of 10
j1701115
in reply to: j1701115

Sorry never mind. For my quick test I didn't throw in an mtd file. Everything is working fine.

BTW I spottet your Power Metal and it's amazing. The freedom STD allows is ideal. Are you going to release that at some point?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report