After getting Oren-Nayar working, I started looking for quicker solutions, as I can’t justify moving to SM 3.0 just for diffuse lighting. I happened upon Pope Kim’s blog post about an optimized Oren-Nayar shader they implemented for Warhammer 40000: Space Marine. It provided a neat solution that got me back to SM 2.0 (YAY!) but it wasn’t quite as good of a match to true Oren-Nayar as i had hoped. Specifically the view dependent Intensity was dimmed somewhat.After a few hours of testing i was able to come up with a solution that brought the intensity back up to normal when the view and light directions were roughly aligned. I found that in this case, if the soft rim light was multiplied by 0 instead of the “fakey_magic” value, the light intensity was corrected. In cases where the light and view vectors were perpendicular, the “fakey_magic” value held true. So in my final implementation I simply multiplied his “fakey_magic” value by a “fakeyFix” value calculated as: 1-(saturate(dot(L,V)) * result ). 

By setting  “fakeyFix” to 1 minus the saturated dot of the light and view vector, I assured the value would be 0 when perfectly aligned and 1 when perpendicular. By multiplying by “result” aka dot(NormalDir, LightDir), we reduce any shadow artifacts due to this method (when rotating towards parallel, the brightness intensifies much too rapidly. This brings it back to normal ranges). Below you can see some comparisons from different views. 1 is full Oren-Nayar, 2 is Pope Kim’s approximation, and 3 is my derivative approximation.
So far I haven’t seen any issues with this approach, but it is a hack on top of a hack on top of what is probably another hack, so uh…buyer beware. In any case I’m gonna call it good for now. All the excitement of exploring diffuse shading has me a bit overwhelmed.

Maya CGFX File:

orennayarfast.cgfx
File Size: 6 kb
File Type: cgfx

Download File


Unity SHADER File:

orennayarfast.shader
File Size: 9 kb
File Type: shader

Download File


One Response

Leave a Reply

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