Instancing - Arnold for Houdini
HtoA supports Houdini's instance object node, a powerful geometry instancing tool.
Notes about instancing support in HtoA:
- Houdini will set the rotations when instancing, depending upon a number of different point attributes. The instancing logic in HtoA supports the same built-in instancing attributes as Houdini (see here for more details).
- For instancing, use the Instance object with fast point instancing. HtoA doesn’t support full point instancing.
- You can assign material to instances with the shop_materialpath string attribute on the instance points.
- Fast point instancing supports per-instance user data and instance OBJ property overrides.
- Light instancing is supported.
- Procedural can be instanced (see below).
There are a number of ways instancing can be done in Houdini:
- Instance object
- Instance attributes
- Instance file
- Example 1: Instancing a Torus Object
- Example 2: Instancing Ass Files with Instance
- Example 3: Instancing Ass Files with Geometry and VEXpression
- Example 4: Copy to Points
- Example 5: Colored Lights
- Example 6: Material Override
- Example 7: Trace Sets
- Example 8: Visibility
Example 1: Instancing a Torus Object
This scene file can be downloaded here.
- Start off by creating a torus object.
- Connect the torus to a Scatter node. In the options for the Scatter, increase the Force Total Count to around 200.
- Under Instance Object in the Instance tab, choose the torus. Change the Point Instancing to Fast point instancing. You should see now that the torus is instanced across itself.
- We can add some randomness to the points by using the following VEXpression code in a Point Wrangle node:
// Random Point Color:
float seed = 0.12345; // seed for rand
@N = rand(seed + @ptnum);
@N *= 2;
@N -= 1;
@Cd = rand(seed + 654654.1654 + @ptnum);
Example 2: Instancing Ass Files with Instance
This scene file can be downloaded here.
It is possible to create very complex scenes quite easily when combining Arnold Scene Source (ASS) files with Houdini's Instance Object.
- First you must render out a .ass file of the object to disk using an Arnold ROP node. Choose where to save the .ass file and select Render to Disk.
- Create an Arnold Procedural and choose the .ass file that was exported previously. In this case, it is a soldier model.
- Create an Instance node. The import points will represent the instances position, scale, and orientation (P, orient, pscale attributes). Enable Point instancing and under Instance Object, choose the Arnold Procedural object node which will point to the .ass file that was rendered to disk previously.
Example 3: Instancing Ass Files with Geometry and VEXpression
This scene file can be downloaded here.
In this example, an Attribute Wrangle node (connected to a Scatter node) inside a Geometry node has been used to source the .ass file using the following VEXpression:
s@instancefile = "C:/Users/Documents/soldier_houdini.ass";
For this to work, you need to add the ptinstance parameter to the root geometry obj node as a menu with the options "off", "on" and "fast".
Example 4: Copy to Points
copyToPoint SOP used to copy Alembic Packed Primitives files
Example 5: Colored Lights
A scene file can be downloaded here.
- Create an Arnold light (in this case a quad and rotated to face down, but it can be any type).
- Create an instancer object node.
- Scatter points on a grid.
- Attribute create a float attribute of size3 called 'color', with the 'Color' type. (Note: NOT a vector attribute, this will not work, it needs the color type info)
- Create a wrangle and randomly assign a value, like so:
v@color = random(@ptnum);
- You can randomize any parameter on the instancee this way, i.e. any parameter on the 'Arnold light' object node (or whatever object you are instancing).
- To override the intensity and exposure, add this to your wrangle
f@intensity = 0.5;
f@exposure = random(@ptnum) * 3;
Example 6: Material Override
A scene file can be downloaded here.
You can use an attribute randomize set to 'Custom Discrete' distribution (type: string), which lets you visually enter a list of material paths to randomly assign to the shop_materialpath of each point. It also lets you set the weight of each entry.
Alternatively, you could use a point wrangle with something like:
string materials[] = {
"/mat/mat_a",
"/mat/mat_b",
"/mat/mat_c"
};
float weights[] = {
1.0,
1.0,
0.5 // less of mat_c
};
int idx = sample_discrete(weights, random(@ptnum));
s@shop_materialpath = materials[idx];
Example 7: Trace Sets
A scene file can be downloaded here.
- Randomizing the instance value using an attribute randomize set to custom discrete, which will randomly select /obj/pig or /obj/rubbertoy for the string 'instance' attribute.
- @orient and @pscale are to control the per point transform.
- See
s@trace_sets = "toy";
in the wrangle - it is being run on a group of points (group parm of the wrangle), so you can just set the trace set for a subset of your instance points.
Example 8: Visibility
A scene file can be downloaded here.
A standard instancer setup except for the visibility attribute override.
The main considerations to be aware of are:
- In the attribute create, set the visibility to an '8-bit integer'. This isn't explicitly required. HtoA handles the conversion internally, but you can avoid that conversion if you set the type appropriately before writing to it in the wrangle.
- The values are being set on the 'hidepts' group only, but because the default value of an integer attribute in Houdini is 0, the default visibility is being set on all points and overrides it afterwards.
- Setting the visibility bitmask is currently unintuitive because we don't ship vex constants for each ray type mask. Consult the visibility section of the Arnold User Guide for a brief overview, or check the Arnold Python API for more details.
Technical users can check the contents of arnold.ai_ray to view the correct mask for each visibility type.