imported FBX: rand Cd per shader? SOLVED

   1448   6   0
User Avatar
Member
1007 posts
Joined: April 2017
Offline
Hi!

I would like to have a random point Cd for each shader I had applied in Maya. When I import that in Houdini, I can see a prim s@shop_materialpath. I'm trying to generate a float value with the rand() fonction but it doesn't work with strings.

Any tips on having one Cd value per s@shop_materialpath name?

-Olivier
Edited by olivierth - April 23, 2020 10:10:05
User Avatar
Member
1737 posts
Joined: May 2006
Offline
@Cd = rand(random_shash(s@shop_materialpath));
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
1737 posts
Joined: May 2006
Offline
Or easier, an attribute randomise sop that uses shop_materialpath as the seed:

Attachments:
rand_shop_materialpath.JPG (26.0 KB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
1007 posts
Joined: April 2017
Offline
AH!!

The function I was looking for is random_shash. I'm not exactly sure of the math behind that function but it converts a string (letters) to a long number. For example:

phone = 215330074
antenna_red = -1700732245
buttons = 2079827859
etc.

By passing those values in a rand() I was able to get different @Cd values.

-Olivier
User Avatar
Member
7760 posts
Joined: Sept. 2011
Online
olivierth
AH!!

The function I was looking for is random_shash. I'm not exactly sure of the math behind that function but it converts a string (letters) to a long number. For example:

phone = 215330074
antenna_red = -1700732245
buttons = 2079827859
etc.

By passing those values in a rand() I was able to get different @Cd values.

-Olivier

I wouldn't use rand() with a hash, the number is potentially far too big. Instead I use random(), which is meant to take integers.
User Avatar
Member
8539 posts
Joined: July 2007
Offline
jsmack
I wouldn't use rand() with a hash, the number is potentially far too big. Instead I use random(), which is meant to take integers.
never used random(), but recently I had issue whith one scene where random() producd very biased random samples while when replaced with rand() it was pretty uniform, not that it may matter for this case, but it would be good to know the exact diffeerence between them and intended usage
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
7760 posts
Joined: Sept. 2011
Online
tamte
jsmack
I wouldn't use rand() with a hash, the number is potentially far too big. Instead I use random(), which is meant to take integers.
never used random(), but recently I had issue whith one scene where random() producd very biased random samples while when replaced with rand() it was pretty uniform, not that it may matter for this case, but it would be good to know the exact diffeerence between them and intended usage

random() is for integers; it's used internally by attribrandomize. It's similar to cellnoise() in some other shading languages. rand() is for float seeds. I don't know about one being more or less random than another, but I know casting too large of an int to a float may cause rand() to behave less random as too many bits of precision are dropped. You can partially get around this by doing what attribute randomize does using a divide and modulus of 65365 to split the bits into to components of a vector.
  • Quick Links