Hairy Games… Or Rather Hair in Games

Posted: February 12, 2012 in INFR 2350
Tags: , , ,

With my anticipation of going out and purchasing the new release of Final Fantasy XII-2 when I have free time, it reminds me of a very important aspect of making a game look realistic. Hair. I’ve always associated with gorgeous pre-rendered cutscenes to the Final Fantasy series, even their feature length film Final Fantasy VII:  Advent Children. I’ve always wondered what it was that made the characters look so good, and of course, I realize now it is hair!

We have a lot of hair, how can we approach creating and rendering hair? Do we render every single strand of hair?

Yes and no, there are several different approaches to rendering hair. Theoretically you could render every single strand of hair, but that would be highly inefficient and would take a lot of processing power. But now with better technology, we are able to render better looking characters. I will be discussing briefly on one of many approaches to rendering hair, since I’m not an expert.

Pre-Rendered Scenes in Final Fantasy VII, notice the block hair.

Pre-rendered scene from Final Fantasy XIII-II, notice the actual hair that is rendered versus a block of hair.

So how do we get it to look all pretty and stuff?

The approach I will be discussing a slightly dated, but was found through an ATI presentation. This hair rendering technique uses a polygonal hair model. Then by applying shaders it creates a realistic looking hair model.

The shader used is a mix of Kajiya-Kay-hair shading model and Marschner’s model presented at SIGGRAPH 2003. The technique uses a simple approximate depth-sorting scheme as well, so this is a simple approach to rendering hair.

The reason for choosing a polygonal model over a line model for hair is because it has a lower geometric complexity which helps depth sorting faster.

What is the Kajiya-Kay Model?

It is a lighting model for anisotropic strands where the hair strands tangent is used instead of the normal in lighting equations. The hair normal is assumed to lay in a plane spanned by the tangent and view vector (V):

What is the Marschner Model?

It is the model for scattering properties of hair. It mainly discusses the primary specular highlight is towards hair tips, while secondary specular highlights are colored and shifted towards hair roots. “Sparkly” hair is the result of the secondary specular highlighting. The math for this model is very complex, so developers will often just try to match these properties visually.

Are there any textures for hair?

Yes, a common texture for hair is stretched out noise. Randomly generated noise in top to bottom line pattern.There is also alpha textures to show where the hair is opaque and translucent. Examples of the textures:

How do the shaders work for hair rendering?

There are both vertex and pixel shaders being used for hair rendering. The role of vertex shaders are to pass down tangent, normal, view vectors, light vectors, and ambient occlusion terms. While the pixel shader is responsible for diffuse lighting using the Kaijya-Kay model, two shifted specular highlights for the hair, and combining the terms.

What all this means is, an ambient occlusion, diffuse term, and specular term are all created by the shaders and combined into a final product:

Hair requires depth sorting:

Depth sorting is needed to draw the hair in back-to-front order to give the hair a look of depth/correct alpha blending. It uses a static index buffer that goes from the inside to outside order, maintaining the back-to-front order of drawing the hair. This lets the program load the patches of hair created and is drawn in order on screen. Not every hair is individually drawn.

What is the rendering pipeline/scheme?

There are 3 passes with this technique to create the final product.

Pass 1 deals with opaque parts of the hair.

Pass 2 deals with transparent back-facing parts

Pass 3 deals with transparent front-facing parts

This sounds pretty easy, why doesn’t everyone use this technique?

The reason is that this technique has cons some developers do not like. It also may not be complex enough to give a desired output. Pros of this technique are low geometric complexity so this allows the vertex engine to run faster (less load) and makes depth sorting faster when drawing hair back-to-front. This approach also allows applications to be run on lower-end hardware using simpler shaders or fixed-function pipelines.

Cons for this approach on the other hand are that this approach is assuming there is close to no animation for the hair model. Hair blowing in the wind or ponytails need to be dealt with separately. This approach is also not suitable for all hairstyles. It is more suited for simple, “flatter” hair styles. Not ones with hair sticking out in peculiar patterns like Cloud from Final Fantasy VII. Nothing too extreme now.

There are ways to optimize this technique for better performance, but I have no been able to grasp it all. But don’t think that this is the only approach to creating hair in 3D computer graphics. There are many new and improved techniques, as well as old and outdated ones. Whatever approach suites the needs for an application can be used.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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