Square Enix © Goodbye Kansas

Table of Contents

This page provides a tutorial for using XGen Spline Primitives with V-Ray.

Overview


 In this tutorial, you will learn how to create a simple scene with XGen primitives to produce a grassy surface.

Before proceeding with this tutorial, it is advisable to read the XGen General page first.

Want to follow along but don’t have a license?


Download Free Trial



 


Part I: Creating a Grass in a Simple Scene


These steps will guide you through creating a simple grass surface.


Set Up the Splines

Here we will show you how to instance splines to create grass in your scene.

First create a plane and with XGen, 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

    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 Taper to 0.8 and Taper Start to 0.5 to make the splines more pointy like grass.
    4. Set 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

Set Up the Render

Assign a VRayMtl material to the description (select the description from the Outliner, right-click in the viewport, and choose Assign New Material). Change the Diffuse Color to green.

Create a V-Ray Dome Light in the scene and render. Your rendering should look similar to the image below.




Part II: Randomizing Hair Strand Color


Splines can be uniquely colorized with the use of expressions and texture maps through the use of Custom Shader Parameters.

There are two parameters that control the color of each strand: root_color and tip_color. If different colors are assigned to both, the color of each hair strand will be interpolated upwards from the root color to the tip color. If only one color is assigned to both, the whole strand will be colored evenly with that color.


Colorize the Roots

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





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:

[rand(0.3,0.7), rand(0.3,1),rand(0.3,0.7)]

Render the scene.









Colorize the Tips

We can also use the tip_color together with the root_color.

A texture map could be also used, as described on the XGen General page.

Using this setup and an image of painted easter eggs, we get the following render as a result. Notice how the root part of the strands remains green.







If you don't want to be restricted to just two 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 as in earlier steps. But instead of connecting the 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 V-Ray as the the Renderer. 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 IPR 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).



Was this helpful?