Artistic Experiments
  • Home
  • Reel
  • Shaders
    • Stylized Shaders
    • Lighting Techniques
    • Shader Effects
    • Cubemaps
    • Pixel Lit Shaders (Basic)
    • Vertex Lit Shaders (Basic)
    • Unlit Shaders (Basic)
  • Tools
  • WIP
  • Contact

CG Shaders - Oren-Nayar Fast

3/9/2014

1 Comment

 
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.
Picture
Picture
Picture
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

1 Comment
Baking with Bianca link
11/24/2020 05:13:04 pm

Nice blog you have, thanks for posting

Reply



Leave a Reply.

    CG Shaders

    Shaders I've built as i teach myself CG. Feel free to download and use for whatever. If you like them you can buy me a beer or something.

    Archives

    December 2014
    April 2014
    March 2014
    February 2014
    January 2014
    December 2013
    November 2013

    Categories

    All

    RSS Feed

Powered by Create your own unique website with customizable templates.