Creating Grass with Splines

 

This tutorial shows you how to create a patch of grass very quickly and easily using XGen splines. We will also use some expressions to control the behavior and look of the grass.

The tutorial is broken up into the following chapters:

Creating the Grass
Bending the Grass
Randomly Changing the Grass Color with an Expression
Changing the Length with an Expression


A Maya scene can be downloaded here.


A video that shows how to setup this scene can be found here.

Creating the Grass

  • Create a polygon plane with 20 subdivisions in both Height and Width. This will enable us to sculpt it into the plane to form a varied base for our grass. Scale the plane up to around 10 in X and Z.

 

  • Select the polygon plane and go to XGen>Create Description. This will open up the Create XGen Description below.
  • Choose the Splines (use for long hair, vines, etc.). Leave the other default settings alone and click on Create.

 

  • It is good practice to lower the Percent value in the Preview/Output tab before continuing. If the Percent value is too high, you may find that your computer will stall due to a large number of primitives generated.

 

  • Increase the Density to around 5000 to cover the plane with grass. Lower the Width to around 0.05 to make the grass appear thinner. Increase the spline Length to 2. Adjust the Taper to 0.5 and the Taper Start to 0.5 so that the splines look more like blades of grass. 

 

  • Assign a Standard Surface shader to the XGen description. Change the Base Color to green. Create a Skydome light and render the scene. 

 

A plane with XGen grass splines (cube with a ramp has been placed under the plane).


Bending the Grass

Rather than bending the grass uniformly in one direction, we can use expressions to bend the grass in random directions. Bend U and V control how much the spline is bent at the corresponding CV. 0 is no bend, and 1.0 is a 90-degree bend.

Click on the Expression icon  next to Bend U[0] and Bend V[0] and enter the following text in the XGen Expression Editor:

$a=rand(-1.5,1.5);#-2.0,2.0
$a

 

The grass splines should appear bent randomly:

 

The grass is still looking a bit uniform. We can use the Bend Param[0] to add more variety. This attribute controls where along the spline the bending will occur. The values range from 0.0 (the base of the spline) to 1.0 (the tip).

  • Click on the Expression icon  next to Bend Param[0] and enter the following text in the XGen Expression Editor:
$a=rand(0.2,0.9);#0.0,1.0
$a

The grass bend looks more random thanks to the Bend Param[0]

Randomly Changing the Grass Color with an Expression

We can use an expression with XGen along with the Ai UserData Color node to randomly change the hue of the grass.

  • Create an Ai UserData Color node and connect it to the Color attribute of the Standard Surface shader assigned to the grass XGen description.

Ai UserData Color node connected to Color attribute of Standard Surface shader

 

  • Type grassColor in the Color Attr Name of the Ai UserData Color node. We will use the same grassColor name in the XGen description.

Add the name 'grassColor' to the Color Attr Name in the Ai UserData Color node

 

  • Click on the Preview/Output tab in Xgen and open up Output SettingsUnderneath you should see the Custom Shader Parameters. In the Name text field, type the same name that was used for the Color Attr Name with the Ai UserData Color node. In this case, we used the word 'grassColor'. Click on float and change it to Color because this is the attribute that we want to change.

 

  • Click on the Expression icon  next to the newly defined grassColor color attribute and enter the following expression:
[rand(0,0.5)^0.5, 1,rand(0,0.3)]

 

 

 

  • Render the scene. You should see that the green Hue shading of the grass is now random.

 

Changing the Length with an Expression

Now we can also randomly change the length of the grass using an Expression.

  • Click on the Expression icon  next to the Length attribute and enter the following expression:
$a=rand(0.5,1.0);#0.05,5.0
$a

 

 

 

The grass should look similar to this:

 

  • Finally, increase the Density to 10000, and you are ready for your finished render. Try adding some Backlighting and Specularity to the grass shader to get something that looks more realistic.

 

 

 

 

 


Thanks to Pedro Fernando Gómez for his assistance with XGen.

  • No labels