Instancing a noise shader



  • On 22/02/2018 at 01:23, xxxxxxxx wrote:

    Hey Everyone,

    Ive created a python tag that takes a master shader and a list of displacers as its input.

    I would like to take the noise shader and instance it X amount of times, copying all of the data but changing the seed for each instance. Then feed this into each displacer object (so essentially i have exact same noise, just with a different seed).

    This is the code i have so far:

    _def main() :
     
      # GET USER DATA
      tex = op[c4d.ID_USERDATA,1]
      displacer = op[c4d.ID_USERDATA,2]
     
      # GET NOISE SHADER IN LUMINANCE CHANNEL
      shader = tex[c4d.MATERIAL_LUMINANCE_SHADER]

    # GET CLONE OF SHADER AND CHANGE SEED
      shader_2 = shader.GetClone()
      shader_2[SLA_NOISE_SEED] = 1024
     
      # ADD CLONED SHADER INTO THE DISPLACER SLOT
      displacer[c4d.ID_MG_SHADER_SHADER] = shader_2
    _
    The cloned shader wont load into the displacer slot when i try to run this code...

    However when i set the seed to different values for both and print them out, they seem to have worked

    So my question is, is what i am trying to do even possible (instancing a shader in one material)? Or do i need to store the cloned shader into a new material, am i not copying the data correctly etc etc

    Any help or clues much appreciated!

    Thanks,

    Cerac
    __



  • On 23/02/2018 at 08:40, xxxxxxxx wrote:

    Hi Cerac,

    this is something you shouldn't do in a Python tag. Tags are there to either store additional data for the host object or to influence parameters thereof. But tags are not allowed to modify the scene hierarchy (like e.g. inserting shaders). At least not during Execute() or inside of the drawing pipeline (Draw()). And the code you put into a Python tag is exactly this, it's basically the content of the Execute() function of a tag.
    There's also a practical reason (besides not being allowed to do so). The tag is being executed whenever the scene is evaluated, so for example (but not limited to) for every frame. With your code you'd insert new shaders with every execution.
    I'd say, something like this is rather done in script (Script Manager) or, if you have to do it in a tag, as reaction to a button press in Message() function.

    And finally there's one important step missing, which is also needed, when doing it in a script. The shader needs to be additionally inserted into the material via InsertShader().


Log in to reply