Custom Shader Effector [SOLVED]

  • On 26/03/2015 at 14:14, xxxxxxxx wrote:

    I think there is a big performance issue in the for statement. i want to transfer the color of a noise texture on my clones. this works fine but incredible slow. also if i drag something in the viewport it callculate all the samples again. any suggestions to awoid that? i also has to add a black color vector before the render statment to stop a variable issue with shader_lum

    import c4d
    from c4d.modules import mograph as mo
    from c4d.modules import render as render
    from c4d import Vector 
    from c4d.modules.render import ChannelData, InitRenderStruct
    import random
    def main() :
        shader = op[c4d.ID_USERDATA,1]
        cd = ChannelData()
        md = mo.GeGetMoData(op)
        cnt = md.GetCount()
        tresh = 0.5
        coll = md.GetArray(c4d.MODATA_COLOR)
        uvm = md.GetArray(c4d.MODATA_UVW)
        visible = md.GetArray(c4d.MODATA_FLAGS)
        if md==None:  return False  
        #if shader ==None: return False
        for i in reversed(xrange(0, cnt)) :
            cd.p = uvm[i]
            irs = render.InitRenderStruct()
            shader_lum = Vector(0,0,0)
            if shader.InitRender(irs) :
                shader_lum = shader.Sample(cd)
            coll[i] = shader_lum
        md.SetArray(c4d.MODATA_FLAGS, visible, True)
        md.SetArray(c4d.MODATA_COLOR, coll, True)
        return True

  • On 26/03/2015 at 16:15, xxxxxxxx wrote:


    for every clone you initialize the renderstruct, which is very cost intensive.
    You can simply initialize and free the renderstruct ouside the for loop, like:

      for i in reversed(xrange(0, cnt)) :  
          cd.p = uvm[i]  
          shader_lum = Vector(0,0,0)  
          shader_lum = shader.Sample(cd)  
          coll[i] = shader_lum  

    Best wishes

  • On 26/03/2015 at 17:48, xxxxxxxx wrote:

    works fine but is there a way to stop the calculation of an effector ?

  • On 27/03/2015 at 01:45, xxxxxxxx wrote:

    if any condition is True, return before calculation....

    def main() :  
      if op[c4d.ID_USERDATA,2] == True:return  

  • On 27/03/2015 at 08:05, xxxxxxxx wrote:


    when you move something in the scene or move the camera the effector has to do his calculations because the result may depend on the position of the object or the camera (as with the "Target" effector). So if you want to disable that, you could just turn the effector off.

    Best wishes,

  • On 01/04/2015 at 09:10, xxxxxxxx wrote:

    ok - than solved

Log in to reply