Before reading this, it is advisable to read the XGen General page first.
Creating a simple scene
Here we will show you how to instance splines to imitate grass.
First create a plane and assign a description with splines randomly across the surface.
Note: There is no problem using groomable splines but we will use normal splines to show you how to control their attributes with expressions/maps procedurally.
- From the Preview/Output tab set the Percent attribute to 10 (this will affect only the viewport).
- From the Primitives tab
- Set the Density attribute to 100
Set the Length attribute with the following expression
- Set the Taper to 0.8 and the Taper Start to 0.5 to make the splines more pointy like grass
- Set the Width to 0.05
Set the following expression to the *Bend U/V* attribute through the expression editor:
And this one to the Bend Param
- Assign a VRayMtl to the description (select the description from the Outliner and right click in the viewport => Assign New Material). Change the Diffuse Color to green.
Create a V-Ray Dome Light and render. You should see something like the picture below:
Randomizing the color of each hair strand with expressions and maps
Splines can be uniquely colorized with the use of expressions and texture maps. This is done through the use of *Custom Shader Parameters*.
There are 2 such parameters that control the color of each strand: root_color and tip_color.
If they are both given, the color of each hair strand will be interpolated upwards from the root color to the tip color. If just one of them is given, the whole strand will be colored with it.
Here are the steps to colorize splines:
- Assign a V-Ray Hair Sampler to the Diffuse Color of the material
- Go to the Preview/Output tab of the XGen window and scroll down to the Custom Shader Parameters section
Add root_color as type color like this
You should then see your parameter added above the textbox and now an expression can be assigned to it
Use this expression for the custom shader parameter
When you render it should be something like this
- We can also use the tip_color together with the root_color
A texture map could be also used like explained in the XGen General page:
With this setup and using an image of painted easter eggs we get this:
Notice how the root part of the strands is green.
- If you don't want to be restricted to just 2 colors along the strand, you can use a ramp texture. This time instead of directly connecting the V-Ray Hair Sampler, assign a ramp texture to the Diffuse color of the material. Connect the distanceAlongStrand of the V-Ray Hair Sampler to the vCoord of the ramp texture. Your shading network should look like this:
- Or you can combine both methods. First you paint your root and/or tip color like in 7. But instead of connecting V-Ray Hair Sampler directly to the material, use a ramp texture with and attach the V-Ray Hair Sampler as a color at the positions you want to sample the textures, Your shading network should look like this:
V-Ray has options for the tessellation of XGen splines.
Go to the Preview/Output tab and from the Output Settings choose the Renderer to be V-Ray
Find the V-Ray Settings in the Preview/Output tab
The Hair Tessellation Mode and the slider below it can be used to tweak the tessellation and thus rendering speed, memory footprint and quality.
Limitations and Problems
When working with groomable splines, if a render or a RT render happens, to continue updating the splines with respect to the groom splines, one has to refresh XGen, groom a bit more and refresh again.
Only then will the splines regenerate accordingly to the groom splines (which are only for the viewport).