You can use expressions to drive randomization of the geometry's size, shape, and orientation. This way, you can instance the same geometry multiple times, but have each instance appear differently in the scene.
A simple way to add variation to instanced geometry is to use a randomization expression.
To add randomization to the Twist attribute
- In the
Primitive Attributes section, click this icon
beside Twist.
- In the XGen Expression Editor, type the following expression:
rand(0,360).
- Click
Accept.
Each tree now has its own unique Twist value.
Generate variation using a Collection expression
Another way to generate randomization is to create a Collection expression. This type of expression can be applied to different primitive attribute values for all the Descriptions in the Collection.
In this example, you use a Collection expression to create a custom XGen attribute with a slider control. Using the slider control, you can generate randomized values which you can apply to attributes such as Length, Width, Depth, and Twist.
- In the XGen window, click the Expressions tab.
- Beside
Name, type a name for the custom expression such as
randomizer.
Leave this expression set to Float as it uses float values.
- Click the
icon to create the attribute.
- Click the
icon beside the attribute.
- In the
XGen Expression Editor type:
$a=;
This creates a slider control for the attribute.
- Type the following expression on the next line:
$a*rand(0.1, 3.0).
- Click
Accept.
In the expression, the slider value is multiplied by a randomization function. You can now set primitive attributes to use the randomized values generated by the expression.
- Click the
Primitives tab, and click the
icon beside Length.
- Clear what appears in the XGen Expression Editor, and type the custom attribute name followed by
(); for example,
randomizer(). Click
Accept.
The values assigned to Length is now randomly generated based on the custom attribute slider setting.
- Repeat the step above for Width, Depth, and Twist.
- Click the Expressions tab, and then use the custom attribute slider to generate an appropriate value.
You can also use the randomizer() expression to vary the size and orientation of the grass clumps in the scene.
Render the scene using your desired renderer. See Shading and Rendering XGen Primitives.