Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    Replacing a shader

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 263 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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 😉

        1 Reply Last reply Reply Quote 0
        • First post
          Last post