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

    Create Shader Not Rendering

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 405 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/03/2013 at 15:45, xxxxxxxx wrote:

      I have a problem where I have code that creates a shader and loads a file into the color and alpha channel and activates the alpha channel, but then nothing will render in either the viewport or the Picture Viewer. If I disable the alpha I can render again, but I dont know why I can render with both? Any ideas? Thanks!
      Using R14 Studio

      import c4d
      from c4d import documents
      #Welcome to the world of Python
        
        
      def main() :
        
                      #replace with your path
                      file = "/Volumes/Textures/Leaves/Leaf1.tif"
                      
                      def insertobj() :
                          obj = c4d.BaseObject(c4d.Oplane)
                          doc.InsertObject(obj)        
                          c4d.EventAdd()                 
          
                      doc = documents.GetActiveDocument()    
                      
                      mat = c4d.BaseMaterial(c4d.Mmaterial)  
                      sha = c4d.BaseList2D(c4d.Xbitmap)
                      sha[c4d.BITMAPSHADER_FILENAME]  = file
                      mat.InsertShader( sha )
                      mat[c4d.MATERIAL_COLOR_SHADER]  = sha
                      mat[c4d.MATERIAL_USE_ALPHA]=True
                      mat[c4d.MATERIAL_ALPHA_SHADER]  = sha
                      
                      mat.Message( c4d.MSG_UPDATE )
                      mat.Update( True, True )
                      doc.InsertMaterial( mat )
                      
                      insertobj()
                      mat = doc.SearchMaterial("Mat")
                      obj = doc.SearchObject("Plane")
                      doc.SetActiveObject(obj)
                      doc.SetActiveMaterial(mat)
                      c4d.CallCommand(12169);
                      
                      
              
               
        
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 05/03/2013 at 16:18, xxxxxxxx wrote:

        you cannot assign the same instance of a shader to multiple channels. that is a limitation of
        the c4d material system. you have to create a copy first.

        mat[c4d.MATERIAL_ALPHA_SHADER] = sha.GetClone()

        edit : note that you might run into more problems, when you try to copy more complex
        shader setups this way, due to the unpredictable way c4d.c4datom.getclone() works.
        copying shaders which contain object (instance) references themselves will not always 
        return the expected results.

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

          On 06/03/2013 at 07:22, xxxxxxxx wrote:

          The shader also has to be inserted into the material's shader-list. Use BaseMaterial.InsertShader()
          for this. This has to be done for every single clone of the shader as well. Do not invoke it twice
          per shader.

          Best,
          -Niklas

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

            On 06/03/2013 at 08:18, xxxxxxxx wrote:

            Thanks for your responses, that makes sense. However, when add the .GetClone() on the end it doesn't load the image into the alpha for me? was there more that has to be done?

            I tried what Niklas said about inserting the shader again with something like this:

            mat[c4d.MATERIAL_ALPHA_SHADER] = sha.GetClone()
            mat.InsertShader( sha.GetClone() )
            

            Edit: ok I got it, I think it was a newb thing. I assigned the sha.GetClone to variable first then it worked. Thanks again guys!

            sha2 = sha.GetClone()
            mat[c4d.MATERIAL_ALPHA_SHADER] = sha2
            mat.InsertShader( sha2 )
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post