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

    Custom Shader Effector [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 489 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 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)
        
          random.seed(666)
              
          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)
                  shader.FreeRender()
              
              coll[i] = shader_lum
        
          
          md.SetArray(c4d.MODATA_FLAGS, visible, True)
          md.SetArray(c4d.MODATA_COLOR, coll, True)
          
          return True
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

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

        Hello,

        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:

          
          shader.InitRender(render.InitRenderStruct())  
            
          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  
          
          shader.FreeRender()  
          
        

        Best wishes
        Martin

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

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

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

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

            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  
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

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

              Hello,

              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,
              Sebastian

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

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

                ok - than solved

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