Create Shader Not Rendering



  • 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()
    


  • 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.



  • 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



  • 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 )
    

Log in to reply