In our Creating XGen hair series, we showed you how to shade XGen primitives
using the default xgen_hair_phen shader.
In this movie, we’ll look at an alternative way to assign colors to your primitives
using ramp shaders and ptex maps, available as of Maya 2015 extension.
Make sure to set the current project to the provided scene folder,
then open the file "01-XGen_shading_start.mb".
This file is similar to the one we used in part 6 of our Creating XGen hair series,
just with a different hairstyle and sans animation.
Recall that by default, Maya uses an xgen_hair_phen shader
connected to the xgen_hair_phong shader to color the hair.
While this is perfectly functional, it does have a few limitations.
You have to use a set of custom shader parameters to color the hair's root and tip.
This means that each hair primitive is limited to two tones.
It also means that you have to render your scene to see these colors,
as they are not visible in the workspace via the XGen preview.
Let's update this shader network with a ramp node instead.
In the Hypershade, select the xgen_hair_phong shader and open the Node Editor.
Show the connections.
Delete the attached xgen_hair_phen shader.
Now create a new Ramp [Texture] node.
Rename it "hair_ramp".
Connect its Out Color attribute to the hair_phong shader's Color attribute.
We'll also need a new xgen_hair_length_mapping node.
This node represents the actual map in UV coordinates of the primitives from root to tip.
Connect its Out Value to the ramp's UV Coord > V Coord attribute.
Now select the ramp node.
In the Attribute Editor, the ramp represents the color of your hair primitives
from root (left) to tip (right), based on its input V coordinates.
Let’s go with a dirty blonde base with red colored tips.
As you can see, the primitives change color in realtime as you adjust the colors.
And of course they also appear in any renders performed using mental ray.
Feel free to add as many tones as you like simply by adding additional ramp points.
Next, recall that in the Creating XGen hair tutorial
we showed you how you can assign ptex texture maps to each of the custom shader parameters
to control the color of hair over a region of the head.
We can do the exact same thing here by assigning a ptex map
to the selected ramp color attribute rather than using a solid color.
Let’s try coloring only the tips of Emma’s pigtails the same color as her hair bands.
First, we’ll create a new map by painting it directly on the scalp.
Turn off the XGen Preview for now, then unhide the scalp_GEO node.
In the XGen Window, go to the Preview/Output tab.
We'll assign our ptex map to the Primitive Color attribute,
since it only affects the primitives in the workspace
and thus will be non-destructive to our rendered look.
Expand the Expression button next to Primitive Color and select Create Map.
Rename the map "tip_color_map" and increase Map Resolution to 15.
Maya floods the scalp white.
Open the 3D Paint Tool.
First flood the scalp with the same blonde color we used in our ramp earlier.
Now within each hairband, color the scalp red and black respectively.
Save the map and display the primitives again.
XGen updates the primitives appropriately,
though it colors the entire pigtails and not just their tips like we wanted.
That’s okay.
Remember that we're only using the Primitive Color attribute to preview the colors for now.
When you're happy with the look, click the Expression button.
In the XGen Expression Editor, clear out the expression field.
Go to the Samples tab, and select Global > UI > color_gray.
This instructs XGen to return the Primitive Color attribute back to its default value.
Now that we have created a ptex map file,
we just need to apply it to our new hair shader network.
Return to the Node Editor and select the hair_ramp node.
In the Attribute Editor, select the rightmost ramp handle, representing the hair tips,
and click the map button next to Selected Color.
In the Create Render Node window, first select the mental ray section,
then select the xgen_ptex_lookup node.
Assign the tip_color_map file you just created to this node.
Hide the scalp_geo node again and render the scene.
The hair tips on either pigtail are black or red, based on the ptex map you created.
You can use this method to create additional maps for any of the other selected colors.
With the right combination you can come up with some truly outrageous styles.