August 19, 2010

lcHairShader.cgfx – Maya Realtime Hair Shader

Download: lcHairShader.cgfx (save as)
08/21/2010 – fixed some problems with the shadowMap texture and AO texture and vertex color code.
This one is pretty cool – I’ve been reading some of the papers coming out of Siggraph and one by the Uncharted 2 Team referenced an old 2004 paper called “Practical Real-Time Hair Rendering and Shading” by Thorsten Scheuermann.  Its a really great paper and I decided to make a cgfx implementation of its hair technique for Maya.  The paper is interesting because it offers a single purpose anisotropic highlight function that is specially designed for hair – using no normal maps, the only real required map is a specular map to jitter the highlight and create the ‘strands’ effect.
My Maya shader is much expanded and has a lot of functions from my previous shaders as well as some new things.  Its a very versatile hair shader – although it tends to lend itself more to stylized looks than photorealism.
NOTE: Hair UV shells should all be aligned vertically – highlight orientation is based on the UV shell alignment.
There are a ton of attributes, but some of the more interesting ones are:
Main UV Texture Tiling – tiling is useful on main diffuse and specular textures to sort of set the size of the hair strands – normal map can be excluded from tiling
Hair Color – Multiplied by diffuse map – diffuse map can be B&W or colorized if you set hair color to white.
Spec Edge Sharpness – hardens the specular highlight to make it look shinier/slicker
Specular Highlight Shift – moves the highlight up and down the surface
Specular Noise Map Scale – controls the intensity of the specular jitter effect
AO in vertex color – you can bake AO into the vertex color – multiplies by the Ambient and Diffuse
Shadow Map – r is shadow for light 1, g is shadow for light 2, b is shadow for light 3, a (alpha) is AO
Texture Examples:
hairdiffuse (multiply by hair color) – alpha is hair transparency
 hair_normalmap normal map (for big waves)
specJitterspecular highlight jitter (this is normal map alpha channel)


  1. Hi,
    Great work. I was wondering if this shader has the ability to use transparency maps.

    Thanks. :)

  2. @Krystal - yes it does, transparency is sourced from the alpha channel of the diffuse texture, you need to turn on a checkbox in the attributes for this. Also only the 1-bit alpha mode will do layered transparency properly, 8-bit transparency is offered, but may not work correctly due to a flaw in Maya.

  3. hey man, great work. by the this shader for hair is for software render or mental ray...and is it flexible for using texture map for maya hair(pfx hair)......

  4. @biswaranjan - this shader is for the viewport or hardware renderer only. It is designed to work on hair modeled as 'hair planes' where they are all UV'd in the same vertical orientation.

  5. hey man cool looking shader - I haven't worked with this type of shader before so I wondered if you could help me; when rendering from maya all i get is a black image - not even an alpha...?

  6. Just in case you wanted to add it, I´ve created a way to author 'comb' maps which can provide a per pixel direction for anisotropy, so no need to align the hair UV islands vertically, and now it could work on textured in braids, or solid surfaces like a horse or cat.