---
title: "VRayMultiSubTex - Random by instance ID with particle instancer"
canonical: "https://documentation.chaos.com/space/VMAYA/126490282/VRayMultiSubTex%20-%20Random%20by%20instance%20ID%20with%20particle%20instancer"
format: markdown
---
copied from [https://forums.chaosgroup.com/forum/v-ray-for-maya-forums/v-ray-for-maya-general/985102-vraymultisubtext-random-by-instance-id](https://forums.chaosgroup.com/forum/v-ray-for-maya-forums/v-ray-for-maya-general/985102-vraymultisubtext-random-by-instance-id)

attached very simple example scene is on the forum thread, get it from there to understand the setup better if needed.

todo: change the below into something that's easy to read. Change title to seomthing more meaningful afterwards.

 

28-02-2018, 04:52 PM

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.