question

Malcolm Kesson avatar image
Malcolm Kesson asked ·

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?

10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

jack frost avatar image
jack frost answered ·

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-aimicrofacetbsdf/m-p/8736856#M9787
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.

5 comments Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

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.


1 Like 1 · ·
Oh I see, integrate as an independent function. Not like the previous AiOrenNayarIntegrate(). That's handy for custom brdfs as well. Thanks!
0 Likes 0 · ·

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 0 · ·

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 0 · ·

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?

1 Like 1 · ·
Malcolm Kesson avatar image
Malcolm Kesson answered ·

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.

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Stephen Blair avatar image
Stephen Blair answered ·

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

https://github.com/Autodesk/sitoa

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

V V avatar image
V V answered ·

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

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Welcome to the Arnold Answers community.

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using.

Please include images, scene and log files whenever possible as this helps the community answer your questions.

Instructions for generating full verbosity log files are available for MtoA, MaxtoA, C4DtoA, HtoA, KtoA, and Kick.

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

Bottom No panel present for this section.