Randomize texture for each object

Hey guys!

I was wondering if there is a Maya and/or V-Ray node that allows you to randomize your texture color in a defined space for each object that has the material. I couldn’t find anything on the internet - so maybe some power user could help me with that. Would be awesome if there is something deep hidden inside in Maya or V-Ray that allows you to do that.

Thanks in advance guys! :slight_smile:

Greetings
Felix

No, we don’t have such thing on a texture/color basis.
But you could use some MEL scripting to do that, where you give a range out of which you pick your colors and assign it afterwards.
Here’s an example, along with a scene:


string $objects[]=`ls -sl`;
string $o;
for ($o in $objects) {
    vray addAttributesFromGroup $o vray_user_attributes 1; // adds vray user attributes to the selected nodes
    vector $v=`rand <<0,0,0>> <<1,1,1>>`; // random range from 0 to 1 for the 3 color components
    evalDeferred("setAttr -type \"string\" "+$o+".vrayUserAttributes \"random="+$v.x+","+$v.y+","+$v.z+";\""); // sets the attribute and value for each node
}

Just select your objects and run this. Then assign one shader to all of them, in the diffuse add a vrayUserColor texture and just type in “random” in the attribute field.
randomColor.zip (11.8 KB)

Thanks! I am gonna try that out :slight_smile:

But such a node would be a great addition to V-Ray. Do you think that could be considered in the next versions?

Greetings

We’ll put some thought into this.

Actually, the V-Ray implementation of the samplerInfo node can produce a random floating-point number of each object in the scene, which could then be used to drive f.e. a Ramp node or something), we just have to expose this.

Best regards,
Vlado

I was thinking of something like the hairSamplers randombyStrand, and plug it into a ramp would be so great for vray (and maybe not that hard?). Maybe have a few different options like random by object, random by shell(element?, for example for tons of leafs all combined into one object, to save on the transform node count).

But that sounds already like what you are talking about Vlado. Would be VEERY powerful.
The same idea, but to randomize shaders would also be equally great (but in a different way).

So that means I can already plug the samplerInfo Node into my node and it will work our do you guys have to implement that in V-Ray first?

Thanks for your quick replys guys! :slight_smile:

We have to implement it first.

Well, we need to expose the additional V-Ray output for the samplerInfo… hopefully in a nightly build in a few days.

Best regards,
Vlado

Sounds good. Thanks guys! :slight_smile:

Yay! That would be awesome. How does one get access to Nightly builds? I’ve sent requests before to support@chaosgroup.com but that hasn’t seemed to work. Should I be contacting a different address?

Thanks,
Ben

You can email me to vlado@chaosgroup.com and I’ll pass it along. Our support guys are specifically instructed not to give out nightly builds indiscriminately :slight_smile:

Best regards,
Vlado

Wow, superb!
This works on a per Object base or per face? Or maybe even per shell? Per shell would be amazing, because on trees, grass etc. you don’t have single objects but a lot of combined shells.

There is a per-object option right now; Vlado Nedev recently coded something for Modo that works based on mesh elements, I guess we could use that too at some point.

Best regards,
Vlado

Sounds great. That would help in many situations!

This is already implemented in the nightlies and will be included in the next SP.

Here’s a quick example of how it works, along with a scene that I’m attaching:

- add extra vray attributes to a samplerInfo node (this will expose additional outputs to the samplerInfo)
- connect the samplerInfo.vrayRndomByID to a ramp’s vCoord (if you’re using a vRamp) OR uCoord (for a uRamp) | or both, if you intend to switch between ramp modes
--> the ramp’s position and color values will be the range of colors to be distributed to the objects
--> plug the ramp into a shader and use the same shader on lots of objects
random_by_render_id.zip (9.37 KB)

Thats really awesome! Gonna try it out.
We’ve needed a good way to do this for ages. (singleSwitch really isnt optimal, and its a hassle to add more objects).

Would it be possible to get this sampleInfo fix working for shell/elements too in the future?

Thanks once again!

If we add 1 color to the ramp, connect a texture to this color, an connect the vrayRndomByID to the V ramp, obviously, it will pick a random color from the texture, true ?

Yes, but if there’s only one color in the ramp, chances are all the random colors will equal this color.
The setup is similar to the one for hair/fur randomByStrand.

Thank you so much for this! This works great. Glad to be able to say goodbye to my old single shading switch workflow:-)