Get all shaders use in a material

On 24/10/2017 at 00:47, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R18 
Platform:   Windows  ;   
Language(s) :     C++  ;

---------
Hello.

I need to know if there is any Color Shader in a Material parameter.
To do that I parse the inserted shaders in the material via GetFirstShader and GetNext.
I suppose I also have to parse the retrieved shaders recursively.

Is this the correct way to get all the shaders used in a material ?

Thank you for your time !

On 24/10/2017 at 01:21, xxxxxxxx wrote:

Hi Peterakos, your assumption is correct.
Actually traversing the shader tree almost behaves to the same "rules" of traversing the scene tree.

Best, Riccardo

On 26/10/2017 at 05:17, xxxxxxxx wrote:

Hi Peterakos,

in general Riccardo's answer is correct. But we figured out, one will be missing a few corner cases with this approach.
There are some shaders which support sub-shaders, but for historic and/or architectural reasons these do not insert their sub-shaders into the shader tree of a material.
For these you will need to do a separate traversal starting with the shader(s) from their parameters.

Here are the shaders, their IDs and shader parameters:

Colorizer (ID: Xcolorizer from xslacolorizer.h, parameter SLA_COLORIZER_TEXTURE)

MoGraph MultiShader (ID: 1019397, parameters MGMULTISHADER_LAYER_LINK (first shader, next ones follow by +1) and MGMULTISHADER_LAYERCOUNT (number of shaders) from xmg_multi.h)

Sketch&Toon Art Shader (ID: 1012161, parameters ARTSHADER_TEXTURE, ARTSHADER_SHADOW_TEXTURE and ARTSHADER_BACKFACE_TEXTURE from xartshader.h)

Sketch&Toon Hatch Shader (ID: 1012166, parameter HATCHINGSHADER_TEXTURE from xhatchingshader.h)

Sketch&Toon Spots Shader (ID: 1012160, parameter SPOTSHADER_GAP_TEXTURE from xspotshader.h)

You might consider to browse the descriptions of shaders for shader links to end up with a generic implementation. But then be extra careful you don't end in an endless loop, with shaders which do insert sub-shaders intro the tree (e.g. layer shader).