September 7, 2010

Maya Realtime Shaders – Big Update

Up to date downloads are available here: Download Page
I’ve been reading alot of technical papers and was inspired to rewrite and double check all my shaders.  First, some things were broken for example, ambient color was not doing what its supposed to do.  Second, I finally understood the whole linear-lighting thing and all my rgb inputs have been appropriately gamma corrected.  With linear lighting, tonemapping and exposure become much more useful, so I implemented a simplified version of the Uncharted 2 “film-tonemap curve”.  Third, I wanted to make it easier to do rewrites and maintain the code, so i switched the way I was working with multiple lights and inspired by rsl illuminace loop am now doing my lighting through a loop.  This means I can change the code without having to worry about the number of lights or keeping track of their variables and passing them to all needed functions.  I only have to initialize an array to hold that information.
lcUberShader.cgfx and lcNextGenShader.fx are now visually the same although slight differences in the languages are apparent in the code.  I still recommend using cgfx over hlsl for Maya.
lcSkinShader.cgfx and lcHairShader have few changes beyond linear math option and code style changes.  Some attributes have been removed or rearranged - especially with the lcSkinShader, old posts with attribute descriptions may no longer apply.
lcLitSphere.cgfx is an implementation of matcap/lit sphere shading – just for fun and in case anyone is interested.
Pictures: (click for larger)



  1. Nice stuff!

    BTW the skin shader v2.0 is missing "SSS Edge Color"...?

  2. I took some things out in the latest version of the skin shader - its gone through alot of changes so older posts on my blog are not necessarily reliable information. In the latest version you cant currently change the color of the 'sss effect' - the coloring blue/red is a side effect of the blended normal technique im using.

  3. Shader looks great! Do i have to turn on anything for this to work? I have cgfx shader on. Im running maya 2011 on a mac, and have an ati card which might be part of my problem. Im looking for a good cgfx shader to show some students how some of this works, and just need one running in maya and wanted to show them yours since it looks nice. I could still direct them here, but it would be nice to show them how things work. Might have to load this one up at work. Any help would be great, thanks!

  4. Try the second video from here: (the cgfx one)

    If you cant get it working its probably a graphics card incompatibility

  5. There are several problems with the lighting in the skin shader (have not inspected the other shaders)
    Basically, you are updating material properties in the main lighting loop for each light. Not only is this inefficient, each light will behave differently depending on what number it is.

    Cases I have found so far to move out side the lighting loop:

    1) Specular power and color keeps scaling down

    if(useGlossAlpha) specularPower*=pow((St.a+1),2);
    if(useSpecularMap) specularColor*=St.rgb;

    2) suppressCyan keeps changing value on each light

    suppressCyan = (1-suppressCyan);//invert for better UI usability

  6. @Damian - thanks for the bug catches - I'll make some changes and update the download links

  7. pretty cool stuff on shaders ,i wonder if something like this exist for 3dsmax for shading the hair in real time?

  8. Hi! Just tried out these shaders for the first time in Maya 2012! For the litSphere shader it appears to load the texture in upside down! It could be a Maya 2012 bug I'm not able to try it in a previous version. Great work though, super useful.

  9. @JaredM - confirmed the lcLitSphere inverted texture bug in Maya 2012. I developed it on earlier versions, its simple enough to add a switch to let you flip flop the orientation. There'll be an update in a day or so.