Tutorial by Lee Griggs Thanks to Pedro Fernando Gómez for his assistance with XGen.
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.
?• 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 the large number of primitives generated.
?• Increase the Density to around 5000 in order 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.
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 (see below) next to Bend U and Bend V and enter the following text in the XGen Expression Editor:
The grass splines should appear bent in a random fashion:
The grass is still looking a bit uniform. We can use the Bend Param to add more variety. This attribute controls where along the spline the bending will occur. The values ranges from 0.0 (the base of the spline) to 1.0 (the tip). ?• Click on the Expression icon (see below) next to Bend Param and enter the following text in the XGen Expression Editor:
$a=rand(0.2,0.9);#0.0,1.0 $aThe grass bend looks more random thanks to the Bend Param
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 Ai Standard shader assigned to the grass XGen description.Ai UserData Color node connected to Color attribute of Ai Standard 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 Settings. Underneath 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 (see below) next to the newly defined grassColor color attribute and enter the following expression:
?• Render the scene. You should see that the green Hue shading of the grass is now random.
Now we can also randomly change the length of the grass using an Expression. ?• Click on the Expression icon (see below) next to the Length attribute and enter the following expression:
The grass should look similar to this: