XGen Hair and custom shaders

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:

XGen Hair Scene

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:

Assigning a mentalray shader to the xgen hair collection

After some parameter tweaking, we end up with the following rendering:

doll with mib_illum_hair_x shader

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:

doll with mib_illum_hair_x shader

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:

doll with mib_illum_hair_x shader

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):

Create a custom shader parameter

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):

Color Expression

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:

Create xgen_seexpr node

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:

Connecting the custom shader parameter

The rendering shows that the custom_color parameter has been picked up correctly:

doll with mib_illum_hair_x shader

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”.

Load Expression
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:

Expression Editor

And here the rendering we get out of this:

Rendering

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

  1. Justin says:

    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!

    1. Justin says:

      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.

      1. nvsandra says:

        Hi Justin,
        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.
        Cheers, Sandra

      2. Justin says:

        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?

      3. nvsandra says:

        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.

    1. nvsandra says:

      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 …

    1. nvsandra says:

      yes 🙂
      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.

  2. Christopher says:

    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 ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s