Replacing a shader



  • On 05/12/2013 at 20:58, xxxxxxxx wrote:

    Hi, I want to replace a certain shader within a material.
    If I know where in the material I want the replacement to be done, no problem.
    But I want to replace a certain shader type, doesn´t matter where it is.

    So even if it´s a Bitmap in a Filter in the Color channel, I want it to be replaced.
    With GetFirstShader and then a GetNext/Up/Down loop I find all the shaders.

    But how can I insert that new one?
    I mean manually for the Filter/Bitmap in Color, it would be:

      
    material[c4d.MATERIAL_COLOR_SHADER][c4d.SLA_FILTER_TEXTURE] = NewShader  
    material.InsertShader(NewShader)  
    

    So how do I get this "path" into the new shader?



  • On 06/12/2013 at 18:39, xxxxxxxx wrote:

    Wow, that was a brain twister, but finally I got it working by scanning, inserting and removing within their base containers.
    Without Paul´s awesome Smart Shader List, which shows you the whole hierarchy (even with hidden shaders) within a material I wouldn´t have managed. Especially within vray mats...

    I think it is important for anybody, who doesn´t know it, this only seems to work properly:

    material[c4d.MATERIAL_COLOR_SHADER][c4d.SLA_FILTER_TEXTURE] = NewShader  
    material.InsertShader(NewShader)  
    

    It results in the new shader getting inserted next to the filter shader, if you do it by hand it gets inserted under. But in both cases it looks fine, the Newshader is in the Filter Texture slot.

    This results in two bugs, probably more. You can´t really delete the shader from the material anymore by hand, although you won´t see it. And if you go up from the newshader you will arrive at the material, not the parent shader.
    So I use:

      
    op[c4d.MATERIAL_COLOR_SHADER][c4d.SLA_FILTER_TEXTURE] = NewTexture  
    NewTexture.InsertUnder(op[c4d.MATERIAL_COLOR_SHADER])  
    

    Probably now big news for the pros, but me it would have saved lots of work ;-)


Log in to reply