In the previous movie, we animated our characters’s XGen hair
using an anim wire modifier in tandem with nDynamics.
In this movie, we'll show you some techniques to shade and render it using the mental ray renderer.
Make sure you set your project folder to the provided scene folder,
then open the file "01-XGen_hair_part6_start.mb".
We brought the Emma bust into a render studio- type environment
using a 3-point light setup to give us good overall results.
In the first part of this series, we briefly configured the hair for rendering
and adjusted its XGen hair shader.
Let's review those settings to give us a foundation for the enhancements we'll add in this movie.
First, in the XGen window, go to the Preview/Output tab.
Give the Primitive Bound attribute a sufficiently high number, such as 40,
or click the Auto Set button to have Maya set it automatically.
This sets the length limit per primitive to the longest hair in your scene.
Next, open the Hypershade.
Recall that the XGen hair is automatically connected to an xgen_hair_phong material,
and that this shader's diffuse, ambient, and specular channels
are driven by an xgen_hair_phen shader
You can adjust the various attributes here to affect the color and shininess of the hair.
However, to see those changes in the workspace,
you must switch the current Renderer to Viewport 2.0.
Open the Render View window.
Set the renderer to mental ray and click the Render button.
You may notice the hair looks quite thick right now.
In the XGen window, reduce the Primitive Attributes’ Width attribute to 0.01.
While this thins out each hair strand, it also impacts the overall hair volume.
To keep a comparable level of volume,
we'll need to increase the Density of the primitives to a higher value.
Note that this can slow down rendering time due to the increased number of primitives.
As you iterate through different render setups,
you will need to weigh the performance vs quality implications of changes like this
based on the performance capabilities of your computer.
Notice how the color of our hair appears a little flat.
This is due to the normal of each primitive being calculated
by the phen shader’s Tube Shade option.
Although tube shade is designed to make objects appear rounder,
it's almost impossible to tell when the primitives are this thin, so turn it off.
Create a new render.
The hair’s shininess is much more pronounced,
which accents the clumping thus adding texture to our previously flat look.
Still, coloring the hair all one shade like this is a bit bland.
We could use the specular channels to create some highlights as we did in part 1,
but instead let’s try another way.
Return to the XGen window and go to the Preview/Output tab.
In the Preview Settings section,
the Primitive Color attribute controls the color of the hair in the workspace.
You'll recall we used this attribute in the previous movie
to clearly distinguish the hair from the animated guide curves.
This time, let's create a map for some finer control.
Click the Create map button. Create a new map named "XGen_female_ highlights"
and set Map Resolution to 10.
This creates a new PTEX file for the scalp geometry
onto which the hair description is bound. Unhide it so we can paint it.
Additionally, let’s lower the percentage of the primitives that are shown,
so they don’t completely obscure the painting process.
Double-click the 3D Paint Tool to open it in the Tool Settings Editor.
First let's set a base color. In the Flood section,
choose a dark purple color similar to the one we used for its diffuse channel, and click Flood Paint.
Next, in the Color section, choose a significantly lighter purple tone.
Paint the area around the front bangs.
Save the map and set the Percent value back to 100.
Update the XGen preview.
In the workspace, the hair color updates with a set of highlights within the region
specified by the map.
However, if you render again using mental ray,
you'll notice that those highlights don't appear in the rendered view.
This is because the phen shader overwrites the Primitive Color attribute at render time.
Instead, we want Maya to prioritize the highlights color map over the phen shader.
You can do this by creating two custom shader parameters: “root_color” and “tip_color”,
which control the rendered color of each primitive’s root and tip respectively.
Using one without the other colors the entire primitive,
while using them together allows you to gradient one color into another.
Maya will always check these two parameters before rendering XGen primitives.
If they exist, they supersede the phen shader.
Scroll down to the Custom Shader Parameters section and enter “root_color” as Name value.
Change its type to “Color” and then click the + button to create it.
We'll assign it an arbitrary starting color using a simple expression.
Click the Expression button to open the XGen Expression Editor.
Right now there's no expression assigned, so the parameter has no effect.
Click the Samples tab, then in the Expression list, click Global > UI. Choose color_black.
Maya adds the corresponding expression in the Expression text field. Click Accept.
The root_color attribute field changes to a swatch to match the expression’s output.
You can now adjust this swatch to customize the color of your rendered hair starting at the root.
Choose a different color from the current rendered color: let's say red.
Render the scene.
The hair appears red, superseding the phen shader's purple diffuse color.
However, since our custom shader parameter only controls the diffuse color,
we can still adjust the phen shader’s specular colors and highlights
to change the hair’s shininess if we so desire.
Now to replace this solid color with the hair highlights we painted earlier,
we'll need to use the corresponding map that we assigned in the Primitive Attributes section.
Copy this path and go back to the XGen Expression Editor.
In the Samples tab, click Global > UI > map_ptex.
Paste the path from the Primitive Color attribute here.
Make sure you leave the single quotes so Maya can properly parse the mapping.
Create a new render.
The render now matches the colors in the workspace.
Similarly to the “root_color”,
you can create a “tip_color” parameter to modify the color of each hair starting at the tip.
By mixing different color maps from root to tip, you can vary the styles of your hair coloring.
To further iterate on your renders, you can go to the Render Settings
and adjust the different options related to rendering sampling and indirect lighting,
among others.
Lastly, let’s render the animated hair created in the previous movie.
For this you’ll use batch rendering, which uses the dedicated renderer, in our case mental ray,
to create a rendered image of each frame in your timeline.
If you switch to the Modifiers tab,
you can see that the anim wire-driven simulation has Live Mode enabled.
Since rendering is a resource intensive process,
we’ll want to streamline everything else in our scene as much as possible
to reduce the processing stress on Maya.
To that end, let’s create a Groom Bake Manager Modifier as we did in the previous movie.
Once you’ve generated and applied the XPD bake,
you’ll notice that Maya now references it for generating the primitives
rather than generating them in realtime.
While this will decrease the strain on the system, you’ll have to remember to set this back to
“Randomly across the surface” if you ever want to change the attributes of the primitives.
Next, let’s also turn off the Anim Wire modifier’s Live Mode
and reference the alembic cache we created in the previous movie.
As you will recall, this also allows us to disable the nucleus solver,
which will further decrease the strain on your system.
Lastly, switch to the "Emma_camShape" camera...
...and ensure the "Update XGen Preview Automatically" option is turned on.
If you’re working in Maya 2014 extension,
you can simulate a batch render using a MEL script we’ve provided in the scene files.
Open the script in the Script Editor.
This code tells Maya to render a frame, using the current render settings,
then moves the time slider ahead one frame and repeats for the number of frames specified.
Because it uses our current render settings, we’ll need to go to the Render Settings
and change the Frame/Animation ext to a multi- frame extension such as "name.#.ext".
This way, we won’t overwrite our image file with each iteration of the loop.
Note that once you execute this script, you cannot stop it
until it cycles through the number of loop iterations.
Thus, make sure the iteration count is exactly the number of frames of your animation
you want to render.
Each rendered image will appear in the Render View
while simultaneously being output to your project’s images/tmp folder.
If you’re working in Maya 2015, you can batch render in mental ray without using a script.
First clear the XGen Preview, then turn off the Update Preview Automatically option.
In the XGen window, go to File > Export Patches for Batch Render.
This command exports a per-frame alembic cache file for your scalp,
which the dedicated renderer requires to properly move and animate the hair
as a background process.
Since our patches are bound to an animated object,
we’ll turn on the Animated option and set the Frame Range from 0 to 300.
Click Export File.
With the XPD exported, you can now go to the Rendering menu set
and select Render > Batch Render.
Unlike the previous method, Maya renders individual images in the background,
rather than using the Render View window.
However, it still outputs the image files to your project’s images directory.
You should now have the skills to create, style, animate, and render hair using XGen.