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!
19 thoughts on “XGen Hair and custom shaders”
[…] out the post for XGen Hair and custom shaders […]
[…] a look at their post here. There’s also a comments section if you have a question on the […]
This is a good example of Xgen hair, for inspiration I’d like to see an example of Xgen fur !
[…] XGen Hair and custom shaders […]
Reblogged this on Cylibral Blog. and commented:
Great tutorial for creating XGen Hair with custom shaders and use of Disney’s expression language …
Could someone provide an example of an seExpression that will let me take a specific color and add a slight mod to its hue, sat, and value by one of those noise functions? The provided color expressions are great, but I don’t really need my hair or grass to look like cake sprinkles. lol. That’s the only look I seem to able to create. I could probably come up with one myself eventually but I’ve been more on the art side of things lately and less on the code so I’m a little rusty. An expression like that would be extremely handy though! Great tutorial!
If no one else can come up with this one I’ll probably sit down with it and see if I can work something up. If and when I do I’ll post it here because I’m sure someone else could really use it! Those default expressions are great, but the whole ‘cake sprinkles/rainbow’ look just isn’t very practical for me! lol Maybe I’m missing something and this is already built-in but I can’t find it.
here is a simple expression to slightly modify hair color:
$a = [0.360006093979,0.201281756163,0.112260624766]; #color
$strength = 0.3000; #0.00,1.00
$b = rand($strength*-1.0, $strength);
clamp($a+$b, 0.0, 1.0)
Just create a new custom color variable in the XGEN window and paste the code into the expression editor.
Hope this helps.
Awesome!! Thanks so much Sandra. This looks like it will do the trick. 🙂 I don’t have my brain wrapped around this expression language just yet so it’s hard for me to come up with good solutions for now. Once I’ve experimented with it more hopefully I’ll be able to start writing these myself. Any advice on good resources to learn it?
Some documentation can be found at wdas.github.io/SeExpr/doxygen/.
For me, the most useful learning resource is looking at the samples provided with XGEN.
nvsandra – The first line in your expression is an array of colors, how do you know what color the array reads or does Xgen give you that information for the Array ?
The first line defines exactly one color (an array of three floats) and this one is used. Not sure, if I got your question, though …
nvsandra – Where is the link ?
This is fixed now, thanks for noticing!
nsandra – Are you sure you posted the correct link ?
the most useful part for most people is probably the user documentation linked on that page, you can directly access it via wdas.github.io/SeExpr/doxygen/userdoc.html.
nvsandra – There is the useful information 🙂 I assume you can blend, for example, green into xgen hair using vector noise. I assume you have to look up the texture first, correct ?
Do you have the Xgen expression language mastered, it’s powerful but not much info on it.
[…] XGen Hair and custom shaders | Inside mental ray. […]