Sample C++ shader code

Sample C++ shader code

Anonymous
Not applicable
2,199 Views
9 Replies
Message 1 of 10

Sample C++ shader code

Anonymous
Not applicable

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

0 Likes
2,200 Views
9 Replies
Replies (9)
Message 2 of 10

valerio_viperino
Participant
Participant

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

0 Likes
Message 3 of 10

Stephen.Blair
Community Manager
Community Manager

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

https://github.com/Autodesk/sitoa



// Stephen Blair
// Arnold Renderer Support
0 Likes
Message 4 of 10

Anonymous
Not applicable

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.

0 Likes
Message 5 of 10

Anonymous
Not applicable

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.

0 Likes
Message 6 of 10

maxtarpini
Collaborator
Collaborator

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.


0 Likes
Message 7 of 10

Anonymous
Not applicable
Oh I see, integrate as an independent function. Not like the previous AiOrenNayarIntegrate(). That's handy for custom brdfs as well. Thanks!
0 Likes
Message 8 of 10

Anonymous
Not applicable

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?

0 Likes
Message 9 of 10

maxtarpini
Collaborator
Collaborator

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.

0 Likes
Message 10 of 10

Anonymous
Not applicable

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?

0 Likes