Using the vm_surface attribute with object instancing to instance shaders!
Date Created:Friday December 29th, 2006 03:41 AM
Date Modified:Wednesday July 30th, 2008 10:37 PM
Shader instancing works with Object instancing. This means we start out with a geometry object to instance, and the points object to instance the geometry to.
Notice the geometry that is going to be instanced, model, has its display flag turned off, so the model geometry does not render itself. This is because the points object will render with the model geometry instanced to each point.
1) Set up your geometry and points objects.
2) Turn the display flag off of the geometry object.
3) Navigate to the points object's Render tab, and toggle on "Point Instancing".
4) Make sure to have uv coordinates on the model.
Lets look inside of the points object:
5) Apply normals with a Point SOP. Set to 0 0 1.
6) Add an Attribute Create SOP for the instance attribute.
7) Change Attribute Name to "instance".
(tells Houdini which object to instance)
8) change Type to String, and enter the path to the geometry to be instanced in the string parameter.
9) Add another Attribute Create SOP for the shader attribute.
10) Change the Attribute Name to "vm_surface".
(this attribute tells Houdini what the surface shader is, "vm_displace" is used for displacements)
11) Change the Type to string.
12) Fill in the string parameter with a shader string.
When referencing a shader that is internally defined in Houdini, use the "opdef" syntax:
opdef:/Shop/shadername parm1 value parm2 value ...
opdef:/Shop/v_layered map_base "op://img/img1/pic1"
opdef:/Shop/v_layered map_base "/home/dan/image.pic"
To change parameters of a shader per point, simply use backticks inside of the string encapsulating an expression using the $PT variable.
opdef:/Shop/v_supermat diff `rand($PT)` `rand($PT)` `rand($PT)`
This would generate random values for the diffuse color parameter.
When referencing a shader created inside of VOPs you can use the "op" syntax:
op:/pathtovopnetwork parm1 value parm2 value ...
op:/vex/wood basecolor 1 1 1
When starting out it may be usefull to use a shader SOP to generate your strings.
Using a Shader SOP, try by toggling off "indirect references" and toggling on "generate point attributes for instancing", then looking at the geometry spreadsheet.
If you get in the habit of using shader attributes instead of Shader SOPs, remember to use primitive class when applying to geometry, and use point class when applying to the points for point instancing.
Please login or Click Here to register for downloads
Shader Instancing by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com