Random textures from pool

   2492   3   1
User Avatar
Member
169 posts
Joined: April 2014
Offline
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
Edited by firefly9000 - April 24, 2018 12:37:45
Winter is coming!
User Avatar
Member
69 posts
Joined: Nov. 2016
Offline
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
User Avatar
Member
169 posts
Joined: April 2014
Offline
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.
Edited by firefly9000 - April 24, 2018 15:56:14
Winter is coming!
User Avatar
Member
8535 posts
Joined: July 2007
Offline
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);
Edited by tamte - April 24, 2018 17:45:21
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links