Today we want to talk about how to use a custom hair shader to render XGen hair in mental ray for Maya. We will see how such a shader can be assigned, how various helper nodes can be used to alter the appearance of the hair and finally, we will make use of Disney’s expression language SeExpr() to create some interesting effects. For this purpose we use this little doll with a simple XGen hair cut:
By default, XGen uses the xgen_hair_phen shader. This shader mimics the appearance of hair by using a classical Phong model with 2 specular lobes. The shader’s diffuse color parameter can be fed by the custom XGen shader parameters root_color and tip_color. Those need to be defined in the “XGen Window” and allow us to make use of SeExpr(). We won’t go into details on xgen_hair_phen here but simply link to a good overview of all its parameters and an interesting tutorial on how to use it instead.
We start by assigning a different hair shader. For this, we select the XGen hair collection node in the “Outliner”, then choose “Assign New Material” under the “Lighting/Shading” menu and finally apply mib_illum_hair_x:
After some parameter tweaking, we end up with the following rendering:
Let’s add some root-to-tip color variation. In “Hypershade”, we create an xgen_root_tip_color_blend node and feed it into both the diffuse and the secondary color slots of the mib_illum_hair_x shader. The shader provides two color inputs which are blended together over the length of the hair. We choose the root color to be the same we had in mib_illum_hair_x before and orange for the tip:
To get some color variation not only along the length of the hair but also across the head, we now apply a texture to the root_color by connecting an xgen_ptex_lookup. We load the XGen region map for want of a better texture. Here is the result:
So far so good. But still no expressions involved.
In the “Output/Preview” section of the “XGen Window”, we add a new parameter of type color and name it custom_color (any name will do here):
The custom_color parameter appears in the UI but it does not look like a color yet. The little icon next to the new parameter will bring up the “Expression Editor”. We open it and type in the expression seen below to make it a color (red, for now):
Now let’s connect this newly created variable to our shading network. We create a xgen_seexpr node and connect it to the tip_color input of the xgen_root_tip_color_blend shader:
To make use of our custom_color parameter in the xgen_seexpr shader, we then type its name in the shader’s Customs attribute and type the expression
$custom_color; into the Expression field:
The rendering shows that the custom_color parameter has been picked up correctly:
Finally, lets replace this simple color by a more complex expression. XGen provides quite a long list of expression samples which can be accessed as shown in the image below. From the “Color” subset we choose “NoiseC”.
A bunch of new parameters will be added below our custom_shader parameters, Those parameters define the noise function we just selected. Instead of modifying them directly in the XGen window, let’s open the expression editor for immediate visual feedback. After some value tuning we get a quite colorful map:
And here the rendering we get out of this:
We could alter the expression to change the look even further, we could create more custom parameters and combine them in the xgen_seexpr shader, the possibilities are endless, so we simply leave further experiments to you and your imagination!