Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to set a Shader for Roughness ????

    Cinema 4D SDK
    windows python r23
    4
    7
    1.4k
    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.
    • ThomasBT
      ThomasB
      last edited by ThomasB

      Hi,
      I read a lot of threads here about this reflection-layer etc....but I didn´t come up with the solution:

      I just want to feed the Roughness with an shader in my case a c4d.Xbitmap.
      But I have issues to access it because , the console says module has no attribute .....
      Here is small code snippet:

          mat=doc.SearchMaterial("Mat")
          ref_layer=mat.GetReflectionLayerIndex(0).GetDataID()
      
          gloss=op[c4d.ID_USERDATA,2]  #just the texture path from userdata
          color_gloss=c4d.BaseList2D(c4d.Xbitmap)
          color_gloss[c4d.BITMAPSHADER_FILENAME]=gloss
      
          mat[ref_layer + c4d.REFLECTION_LAYER_MAIN_VALUE_ROUGHNESSLINK]=color_gloss #Problem
          
          color_gloss[c4d.BITMAPSHADER_BLACKPOINT]=1
          color_gloss[c4d.BITMAPSHADER_WHITEPOINT]=0
          mat.InsertShader(color_gloss)
      
      

      But as I said, Cinema can´t find the Reflection_LAYER_MAIN_VALUE_ROUGHNESSLINK in the c4d module
      Also no highlighted code for this ID, even though i added per drag and drop into the code editor....
      What I am doing wrong?

      Thanks,
      T.S.B

      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by ferdinand

        Hello @ThomasB,

        thank you for reaching out to us. The problem in your script is that Cinema 4D R23 gave you an incorrect symbol when you dragged the roughness shader parameter into your script. You can always look up the correct symbols in our C++ or Python documentation, or right away use the numeric values they do stand for by inspecting the resource files. You can find a fixed version below.

        Cheers,
        Ferdinand

        """Cinema 4D R23 did link some incorrect symbols for the layer shader when
        dragging and dropping parameters into the console.
        
        This problem does not exist anymore as of R25.
        """
        
        import c4d
        
        def main():
            """
            """
            mat = doc.SearchMaterial("Mat")
            layerIndex = mat.GetReflectionLayerIndex(0).GetDataID()
        
            color_gloss = c4d.BaseList2D(c4d.Xbitmap)
            color_gloss[c4d.BITMAPSHADER_FILENAME] = op[c4d.ID_USERDATA, 1]
            # REFLECTION_LAYER_MAIN_SHADER_ROUGHNESS is the correct symbol. When push
            # comes to shove, you can also always look into header files to find out
            # the raw numeric values the symbols stand for.
            mat[layerIndex + c4d.REFLECTION_LAYER_MAIN_SHADER_ROUGHNESS] = color_gloss
            mat.InsertShader(color_gloss)
        
        
        if __name__ == '__main__':
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • ThomasBT
          ThomasB
          last edited by ThomasB

          Thanks
          for the quick answer Ferdinand, I already thought of something like that, but unfortunately I didn't find it straight away in the C ++ API ....
          Is this drag and drop misbehavior fixed in R25?

          Thanks,
          T.S.B

          1 Reply Last reply Reply Quote 0
          • B
            bentraje
            last edited by

            @ferdinand

            i think the problem is still existing in 2023.

            reflectance_roughness_link_error.gif

            DunhouD ferdinandF 2 Replies Last reply Reply Quote 0
            • DunhouD
              Dunhou @bentraje
              last edited by

              @bentraje
              Reflection layer symbols can't drag to console to get , maybe you can check Materials document , And GitHub Example for this.

              And Shout out to @ferdinand ,this is my topic for this .

              Here is a little code I used to set textures for BaseMaterials :

              import c4d
              
              def main():
                  # Creates a standard C4D Material
                  mat = c4d.Material()
                  if mat is None:
                      raise RuntimeError("Failed to create a new default material.")
              
                  # Removes the default specular layer
                  mat.RemoveReflectionLayerIndex(0)
              
                  # Adds a layer
                  layer = mat.AddReflectionLayer()
                  if layer is None:
                      raise RuntimeError("Failed to create a new reflection layer.")
              
                  # Sets the Layer to Blinn mode
                  mat[layer.GetDataID() + c4d.REFLECTION_LAYER_MAIN_DISTRIBUTION] = c4d.REFLECTION_DISTRIBUTION_SPECULAR_BLINN
                  
                  # Sets the shader for width
                  colormap = "filename"
                  shacolor = c4d.BaseList2D(c4d.Xbitmap)
                  shacolor[c4d.BITMAPSHADER_FILENAME] = colormap
                  mat.InsertShader(shacolor)    
                  
                  # Defines the Roughness float value
                  mat[layer.GetDataID() + c4d.REFLECTION_LAYER_MAIN_SHADER_ROUGHNESS] = shacolor
              
                  # Inserts a material in the active doc
                  doc.InsertMaterial(mat)
              
                  # Pushes an update event to Cinema 4D
                  c4d.EventAdd()
              
              if __name__ == '__main__':
                  main()
              

              https://boghma.com
              https://github.com/DunHouGo

              1 Reply Last reply Reply Quote 1
              • ferdinandF
                ferdinand @bentraje
                last edited by ferdinand

                Hey @bentraje,

                Thank you for reaching out to us and thank you @Dunhou for your answer.

                @bentraje said in How to set a Shader for Roughness ????:

                @ferdinand
                i think the problem is still existing in 2023.

                The description is dynamic for reflection layers. You must use the API with ReflectionLayer.GetDataID to get the base ID of a layer, as shown here in the thread by me and @Dunhou below.

                As far as I can see, I never made here any promise that we will fix this. This is not fixable because the ID is dynamic. We could try to replace the "incorrect" ID, but this could also be complicated.

                Cheers,
                Ferdinand

                MAXON SDK Specialist
                developers.maxon.net

                1 Reply Last reply Reply Quote 1
                • B
                  bentraje
                  last edited by

                  @Dunhou @ferdinand

                  Gotcha. Thanks for the confirmation and illustration links.

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