Material Stylesheets - random texture for assigned shader

   3441   4   2
User Avatar
Member
11 posts
Joined: 9月 2017
Offline
Hello,
I am trying to figure out the best way to randomize material assignments in my crowd.

Lets say I have one principle shader “Man_body” who's basecolor can be connected to a 5 possible texture nodes, “Man_skin_dark”, “Man_skin_light”, etc, say using a switch node. How do I use material stylesheets to randomely switch between the 5 textures, perhaps even in a weighted way (ie for eg 50% Man_skin_light, 30% Man_skin_dark, 10% Man_skin_medium, etc)?

Some non-houdini crowd solutions provide such a possibility out of the box, and I was hoping houdini would provide a convenient way to do this.

Thanks for your help!
Akhil
User Avatar
Member
338 posts
Joined: 12月 2014
Offline
One way to do this without material stylesheets is by setting paths to your textures as string attributes on your instance points and calling them at render time using a renderstate input to your shaders.

In VEX to randomize shirt textures numbered 1-5, on your instance points:

int randshirts = rint(fit01(rand(@ptnum),1,5));
s@shirtpath = sprintf(“$JOB/Houdini/tex/male_clothes/tshirt_%d.jpg”, randshirts);

Number your shirt variations sequentially (tshirt_1.jpg, tshirt_2.jpg, etc),set your renderstate to string and call shirtpath, wire that into the texture input you're using in your shader, voila randomized textures.

You can do something similar to vary skin tones and hair with ramps, set color attributes with ramps on your points and call them with renderstate. In this case use grayscale texures and wire the color renderstate into the base color, you can retain your skin and hair textures but modify their color per instance randomized along your color ramp.
User Avatar
Member
11 posts
Joined: 9月 2017
Offline
“set your renderstate to string and call shirtpath, wire that into the texture input ”

I didnt quite understand how this is done. How do I (1) set my renderstate(not sure what this is) and (2) wire the path to texture input?

Thanks for your patience!
User Avatar
Member
7849 posts
Joined: 9月 2011
Offline
The renderstate vop is a node for building materials that can read render properties and other renderer-information. This includes attributes applied to packed primitives, such as packed agents for crowds. The node has a type dropdown selection and a name field for the data being queried. In your case, as Andy said, string for signature and packed:shirtpath for the value name.
User Avatar
Member
11 posts
Joined: 9月 2017
Offline
Super cool! Thanks a lot, I was able to get it to work. The renderstate vop is a wonderful thing.

As a related question - does this in anyway slow down render time?

Im just imagininng a texture being loaded for each crowd agent, that would defeat the purpose of crowd simulation where we want to randomely apply a few preloaded textured to thousands of agents.
  • Quick Links