Search - User list
Full Version: Random textures from pool
Root » Houdini Indie and Apprentice » Random textures from pool
firefly9000
What I'd like to do is the following:

I have about 4k groups that come as part of 1 obj.

I would like to assign shaders in the materials as such:

/matnet1/shader_**for each group pick a random nr from 1 to 5**

or, alternatively in the shader itself in the texture field if possible. Whatever is deemed simpler.

I'm sure I must be missing something as all the answers I found online were old and required adding of attributes and really complicated workflows some with sops that no longer exist.

Can someone point me in the right direction?

Thank you
huey_yeng
You can use Python to bulk apply the shaders in a random shuffle manner for the 4000(!) groups.

I'm still not familiar with the Python commands for assigning shaders but you can do something like this.

import random

shaders = [shader1, shader2, shader3, shader4, shader5]  # The shaders should go here

random.shuffle(shaders)
for each in shaders:
    # the code to apply the shaders goes here
firefly9000
huey_yeng
Member
59 posts
Joined: Nov. 2016
Offline

today 2:57 p.m.
You can use Python to bulk apply the shaders in a random shuffle manner for the 4000(!) groups.

I'm still not familiar with the Python commands for assigning shaders but you can do something like this.


Thank you for trying to help. I had figured out the randomization bit (though I did it differently), but I got stuck at the same part you did: Assigning the shaders programmatically per group.

My idea was to call them up on a per group basis (in the Material sop) but I have no clue how to do it… or even if it's doable or the right strategy.
tamte
if your groups are non-overlapping use Name SOP to convert them to name attribute (Name From Group checkbox, Group Mask: *)
then use random_shash() VEX to generate your 1-5 number from the name attrib and build the texture path override or shader path based on that

like this for example (Prim Wrangle, s@name is unique prim per-group name generated from groups):
int matid = floor(random_shash(s@name)%5)+1;
//set material
s@shop_materialpath = sprintf("/math/principledshader%d", matid );

// OR override basecolor_texture 
s@basecolor_texture = sprintf("/path/to/texture%d.rat", matid);
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB