Announcement

Collapse
No announcement yet.

VRayMultiSubText - Random by instance ID

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • VRayMultiSubText - Random by instance ID

    I wonder if someone could help? I feel like this will have been asked a million times before but can't find an answer so...

    Maya 2018.2
    V-Ray 3.6.03

    I've got a nParticles hooked up to an Instancer with a simple Sphere.
    On the Sphere I have VRayMtl with a VRayMultiSubTex in the Diffuse Color slot.
    On the VRayMultiSubTex I have a Default Color set (yellow) and Get ID from set to Random by instance ID

    In the docs it says "The VRayMultiSubTex will assign random colors based on the IDs of objects instanced with the particle instanced in Maya."

    Which bit am I missing to actually see random colors on each instance?

    Thanks,
    Chris

  • #2
    Hey, I'll have to disappoint you, but this doesn't actually work. We were wrong to add it in the first place and document it. The "by instance ID" is not compatible with Maya at all, although it's still in the UI.
    If it's simple colors you need to randomize, the setup without multiSubTex is not that complicated, although it does require some tweaking.

    The setup involves outputting user attributes per particle from the particle simulation, then reading them with a particleSamplerInfo and using that to drive the switch. It works both with VRaySwitchMtl, as well as MultiSubTex.
    I'm attaching two sample scenes, and here's more detailed info on the setup:

    Provided you've already set up a particle simulation and a particle instancer:
    A) Particle attribute export setup
    1. select the particleShape node.
    2. in the attribute editor, go to the "Add dynamic Attributes" rollout and click on "General".
    3. A new window opens, go to the "Particle" tab, select userScalar1PP and click "Add". You may close the window.
    4. go to the Per Particle (Array) Attributes tab, right click the User Scalar 1 PP field and do "Create Expression".
    5. now, with the Expression editor window open, you should have nParticleShape select in the Objects list and userScalar1PP selected in the Attributes list. The only thing that this selection does is to prep your expression input with nParticleShape1.userScalarPP= so even without the selection, you can type it in yourself.
    6. Add the expression. I've used a rand(0,2), which chooses a random number between 0 and 2 for each particle that's born (PP in the attribute name stands for Per Particle). You can choose as many as you need. rand(0,2) gives me a total of 3 values to work with: 0, 1 and 2. I'll need to keep that in mind and set up a total of 3 possible colors to choose from, otherwise I may end up with an out-of-range value, i.e. get a value, for which I don't have a color to choose from. But those values will get the default color of the MultiSubTex, so you can use that to your advantage as well.
    At this point my expression is this: nParticleShape1.userScalar1PP=rand(0,2);. Click Create and close the window. You'll see an "Expression..." in the user scalar 1 pp field in the attribute editor.
    7. With the particleShape node still selected, to go Attribtues > V-Ray > Per-particle attribute export. This will add some options in a newly created "Extra V-Ray Attributes" rollout at the bottom of the rollout stack in the attribute editor. Select userScalar1PP. This will export the per particle expression to vray.

    B) Shader setup
    1. Select your original instanced geometry (mine is a cube, yours was a sphere).
    2. Assign a VRayMtl, add multiSubTex to its diffuse slot and add 3 items (since I'm getting a total of 3 possible values). I've added simple colors, but any texture works as well. Note that I've not changed the default IDs for the items, the default counts from 0 onwards and I'm getting 0, 1 and 2 randomly, so at random, V-Ray will take one of those IDs.
    3. Set the Get ID from to Texture Switch.
    Now this next part is easier done in the hypershade.
    3. Create a particleSamplerInfo node.
    4. connect the userScalar1PP output from the particleSamplerInfo node to the idGenTex input of the MultiSubTex. idGenTex is the actual switch. I do that by shift-middleMouse-dragging the particleSamplerInfo onto the MultiSubTex, which brings up the connection editor, otherWise I have to go through one window too many. Or I guess you could click the large white output selector circle of the particleSamplerInfo node in the hypershade and choose the output from there, it should be even easier.

    And you should be good to go.
    The setup is absolutely the same for the VRaySwitchMater, only it doesn't have a get id from mode. Think of it always being in a get id from = texture mode if it were the multiSubTex. You just connect the particle sampler there. The V-Ray Switch Material allows you to do the same, but with entire shaders instead of simple colors or textures. Whichever suits your needs.

    Here's the example scenes (my original instanced cube is hidden, you'll need to select it from the outliner if you need it).

    Sorry to disappoint you with a more complicated setup than you might have expected.
    Let me know if that works for you or if you have any other questions about the setup.
    I'll make sure to fix the docs and add detailed tutorials about these and similar setups.
    Also - if you think of other tutorials that might be useful, just let me know.
    Attached Files
    Alex Yolov
    Product Manager
    V-Ray for Maya, Chaos Player
    www.chaos.com

    Comment


    • #3
      Here's another example for instancing proxies and overriding the proxy time per particle with the instancer. Since there was a request for it, I decided to post it here as well in case someone else finds it useful.
      In a setup where an animated proxy is instanced with the particle instancer, we can override the proxy animation time per particle. This again uses the dynamic particle attributes, expressions and Extra V-Ray Attributes > Instancer Overrides https://docs.chaosgroup.com/display/...cle+Attributes

      The end result is a random proxy time assigned to each particle when it is born. Say our proxy has 10 frames of animation, when a particle is born it will instance the proxy and assign it rand(0,10) time.

      1. select the particleShape node.
      2. in the attribute editor, go to the "Add dynamic Attributes" rollout and click on "General".
      3. A new window opens, in hte "New" tab add a new attribute. Name it, for example, proxyTime. Set Data Type to Float and Attribute Type to Per particle (array).
      4. go to the Per Particle (Array) Attributes tab, right click the proxyTime field and do "Create Expression".
      5. now, with the Expression editor window open, you should have nParticleShape select in the Objects list and proxyTime selected in the Attributes list. The only thing that this selection does is to prep your expression input with nParticleShape1.userScalarPP= so even without the selection, you can type it in yourself.
      6. Add the expression. I've used a rand(0,10), which chooses a random number between 0 and 2 for each particle that's born (PP in the attribute name stands for Per Particle). In the attached example a more complex expression is used, but I'll explain that later. We're using a float attribute, but Maya will round it to integer. We can do the rounding ourselves, in case we don't want to rely on Maya for that.
      At this point my expression is this: nParticleShape1.proxyTime=rand(0,10);. Click Create and close the window. You'll see an "Expression..." in the proxyTime field in the attribute editor.
      7. With the particleShape node still selected, to go Attribtues > V-Ray > Instancer Overrides. This will add some options in a newly created "Extra V-Ray Attributes" rollout at the bottom of the rollout stack in the attribute editor. IN the Instancer PP Times field, enter the name of our attribute - proxyTime.

      The attached scene uses this expression:
      Code:
      int $pTime = 1;
      int $t = `currentTime -q`;
      
      if ($t <= 50) {
          $pTime = 3;
      } else {
          $pTime = 4;
      }
      
      nParticleShape1.proxyTime = $pTime;
      Which basically means that particles born before or on frame 50 will instance the proxy at time 3 of its animation, and particles born after frame 50 will use frame 4 of the proxy animation.

      instancerPPTime_proxy.zip


      Note that this will just assign a static slice, if you will, to each particle and the proxy it instances will remain static. This could be useful, for example, with an object with animated deformations where you want to scatter it around with particles and each particle has different deformations (for example rocks or gravel) to create variation. But it will not give to each instanced animated proxy a random animation offset for it to play its own animation as the particle ages.
      Alex Yolov
      Product Manager
      V-Ray for Maya, Chaos Player
      www.chaos.com

      Comment


      • #4
        Hi Alex, sorry for not coming back to you sooner on this. I don't think I'm subscribed to the post so didn't get an update email. Thanks for taking the time to go through this. My end game with this was to try and hook all this up to MASH via the Instancer but, because this relies on particles that seems to be my blocker. We're going to look at seeing if we can us MASH's Python node to work round it. I'll let you know if we have any success!

        Comment


        • #5
          It would be interesting to know what you do at the end, so thanks in advance for sharing.
          Alex Yolov
          Product Manager
          V-Ray for Maya, Chaos Player
          www.chaos.com

          Comment


          • #6
            Originally posted by haich11 View Post
            Hi Alex, sorry for not coming back to you sooner on this. I don't think I'm subscribed to the post so didn't get an update email. Thanks for taking the time to go through this. My end game with this was to try and hook all this up to MASH via the Instancer but, because this relies on particles that seems to be my blocker. We're going to look at seeing if we can us MASH's Python node to work round it. I'll let you know if we have any success!
            Hello! Do you have any success in this task?
            Node "ID"(in MASH) randomly assigns an identifier to the instances, but I still do not understand how to use it in shading

            Comment


            • #7
              Hi UdushKudush is this with the multisubtex? What mode are you trying to use?
              Alex Yolov
              Product Manager
              V-Ray for Maya, Chaos Player
              www.chaos.com

              Comment


              • #8
                Originally posted by yolov View Post
                Hi UdushKudush is this with the multisubtex? What mode are you trying to use?
                Yes, Im trying to use multisubtex with instance mode, not ReproMesh

                Comment

                Working...
                X