I started this as a fix for Unity’s transparency sorting issues and it kind of snowballed from there. Transparency sorting is a somewhat tricky issue, and this becomes abundantly clear when trying to create hair. I was wanting to try out a few hair shaders since i just finished Anisotropic highlights, but the sorting issues were driving me up the wall. Fortunately i found this paper which presented a solution.Basically it is a multipass shader that renders a depth mask first, and then renders the regular lighting with some adjusted depth settings. By rendering a depth mask early, they are able to avoid using alpha clip ever again. This results in properly sorted double faced transparency (I really should try this on some of my other shaders).

Here is some hair i made real quick on a female head i got from turbosquid. Its not the greatest but hey that’s why i’m not a character artist. On the Left we have Unity’s transparent specular. You can see the z fighting all along the left side. On the right we have my shader, with corrected sorting.

I liked the results so much it forced me to try out multipass in maya and i got it working in there too. I included an unlit version in that one, in case the anisotropic lighting slows things down too much while modeling. The transparency is a little ugly because of how Maya mips textures in the viewport for cg shaders but it works.
I did handle a few things slightly differently. Rather than setting the alpha clip threshold to 1, I set it to 0.3 and expose a power attribute to adjust the amount of blending/clipping. Additionally, in the paper they mentioned turning the depth writing back on during the final pass, but this caused some areas to disappear so i turned it off again ¯\_(ツ)_/¯EDIT: I updated the shaders to include Ambient Occlusion. For more infomation about this and how to bake AO with an alpha, check out my Kajiya Kay implementation.

Maya CGFX File:

wardtransparent.cgfx
File Size: 14 kb
File Type: cgfx

Download File


Unity SHADER File:

wardtransparent.shader
File Size: 25 kb
File Type: shader

Download File


One Response

Leave a Reply

Your email address will not be published. Required fields are marked *