Gradient texture to mask percentage of hairs

   219   1   1
User Avatar
Member
39 posts
Joined: 10月 2011
Offline
I'm trying to find a way to do the following for shading hair in karma/materialX:

I want to use a texture map where gradients between black and white dictate what percentage of hairs will be included in a mask. So, rather than a value of 0.5 assigning to a given hair a color that is a 50/50 mix of color1 and color2, it says that each hair has a 50% chance of being either color1 or color2. This results in a pointilism style of gradient that looks more realistic.

I've been able to do this in gaffer. There, I assigned a random value between 0 and 1 to each primitive, then compared that to the value on the map. Whether the random value was less than or equal to the value on the map would determine whether it would be assigned a value of 0 or 1 for the mask.

If you know how I could accomplish the same in karma/materialX, please share.
Edited by fbb - 2024年4月4日 18:52:34
User Avatar
Member
39 posts
Joined: 10月 2011
Offline
I've worked out how to do this and am sharing my solution:

1. In the hairgen node, store a random value per hair primitive to an attribute by using this code in a wrangle set to run over primitives:

f@randomVal = rand(486 * @id);

2. in your materialX network fetch your randomVal attribute with a "MtlX Geometery Property Value" node, then use a "MtlX If Greater or Equal" node to compare the randomVal attribute to your texture mask, and plug the result into the "mix" input of a "MtlX Mix" node. I've attached a screenshot of the materialX network I setup.


Edited by fbb - 2024年4月5日 09:46:35

Attachments:
driveRandomHairsMaskWithGradientTexture.png (38.7 KB)

  • Quick Links