Jump to content

Randomizing shader values


Recommended Posts

Hi Everybody,

I wonder if it is possible to randomize values of a shader, directly in VOPS or using expressions in the parameter field ...

For example, is there a way to randomize the diffuse value of a shader applied on a stamped copy object ?

Thanks in advance

Julien

Link to comment
Share on other sites

not sure about VOPs, but you could directly manipulate the shader strings in the primitive attributes. Assuming you're assigning the shaders with a Shader SOP, turn off "Use indirect references" on the shader SOP and then take a look at the primitive attributes in the geometry spreadsheet for it. You should see complete shader strings for each primitive, such as:

opdef:/Shop/v_plastic amb 1 1 1 diff 1 1 1 spec 1 1 1 rough 0.1 ... etc...

You can then copy that string and paste it into an AttributeCreate SOP and assign your shader that way. The cool part about this is that you can substitute all sorts of variables into those strings and have them passed to the shader at render time, such as:

opdef:/Shop/v_plastic amb 1 1 1 diff $CR $CG $CB spec 1 1 1 rough `param("myrough",0)` ... etc..

Hopefully that makes sense?

Link to comment
Share on other sites

  • 2 years later...

Hello. I'm having difficulties on following these instructions. Maybe it's because they're a bit old and Houdini has changed ?

I'm also trying to create some variation for stamped objects by using stamp() in a shader color parameter field. It seems like stamping from shops is not allowed or then it need some definitions that I'm not familiar with.

Is "geometry spreadsheet" different than spreadsheet ? And where are these "complete shader strings for each primitive, such as: opdef:/Shop/v_plastic amb 1 1 1 diff 1 1 1 spec 1 1 1 rough 0.1"

located at ?

I've attached a simple scene if someone wants to show a modern way for doing this.

Thanks!

stamping_with_shaders.zip

Link to comment
Share on other sites

Hello. I'm having difficulties on following these instructions. Maybe it's because they're a bit old and Houdini has changed?

No, this method still works and probably is the best way. However, you have several mistakes in your file:

1. You forgot to turn off Use Indirect References on the Shader SOP.

2. You're stamping a value of normalize(rand($PT)). rand($PT) returns a single number between 0 and 1. But normalize() takes a vector. So all this does is produce a value of 1. Each stamping variable is a single number.

3. The operator path that you give to the stamp() expression is incorrect although the Copy SOP is fairly tolerant on this.

Is "geometry spreadsheet" different than spreadsheet?

Yes.

... where are these "complete shader strings for each primitive ...

In the spreadsheet, under Primitives. Extend the vm_surface column.

Anyhow, you should be able to see random coloured spheres when you render in the attached file.

stamping_with_shaders_fixed.zip

Link to comment
Share on other sites

No, this method still works and probably is the best way. However, you have several mistakes in your file:

1. You forgot to turn off Use Indirect References on the Shader SOP.

2. You're stamping a value of normalize(rand($PT)). rand($PT) returns a single number between 0 and 1. But normalize() takes a vector. So all this does is produce a value of 1. Each stamping variable is a single number.

3. The operator path that you give to the stamp() expression is incorrect although the Copy SOP is fairly tolerant on this.

Thanks Edward! So the problem was in value randomizing expression. I always forget that normalize() wants a vector. I found those shader strings from spreadsheets primitive section..the very same I checked last night without luck. :blink:

"Use Indirect References" had been on and off for several tries but forgot to deactivate for my sample scene.

About the incorrect stamp() path..what would be the correct one ? This I thought probably to be the main problem..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...