Page Contents

 

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.

  1. 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.

     

  2. From the Preview/Output tab set the Percent attribute to 10 (this will affect only the viewport).
     
  3. From the Primitives tab
    1. Set the Density attribute to 100
    2. Set the Length attribute with the following expression

      $a=rand(0.5,1.5);
      $a
    3. Set the Taper to 0.8 and the Taper Start to 0.5 to make the splines more pointy like grass
    4. Set the Width to 0.05
    5. Set the following expression to the *Bend U/V* attribute through the expression editor:

      $a=rand(-1.5,1.5);
      $a
    6. And this one to the Bend Param

      $a=rand(0.3,0.9);
      $a
  4. 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.
     
  5. 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:

  1. Assign a V-Ray Hair Sampler to the Diffuse Color of the material
  2. Go to the Preview/Output tab of the XGen window and scroll down to the Custom Shader Parameters section
  3. Add root_color as type color like this

     

  4. You should then see your parameter added above the textbox and now an expression can be assigned to it


     

  5. Use this expression for the custom shader parameter

    [rand(0.3,0.7), rand(0.3,1),rand(0.3,0.7)]
  6. When you render it should be something like this

  7. 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.

  8. 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:



  9. 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:



Tessellation Parameters

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).