Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Energy Conserving Blinn-Phong

Discussion in 'Made With Unity' started by avadlamani, Dec 10, 2013.

  1. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    Well, might as well get this out there.

    This is an "energy conserving blinn-phong" bumped specular shader. It allows for tight highlights and easy material definition ... ... Oh just have a webplayer!

    WEBPLAYER

    There is also an alternate shader that allows you to bind the three control values to a texture.

    Shaders are attached.

    Ugly screenshot time!

    $Sphere.png
    Shader Time!
    View attachment $Finished Shaders.unitypackage
     
    Last edited: Dec 12, 2013
  2. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    Does anyone know how change the thread title in this forum?
     
  3. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    IIRC you need to get an admin to do it, maybe ask Aurore?
     
  4. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    Ah well it doesn't really matter.
     
  5. Botanika

    Botanika

    Joined:
    Nov 2, 2013
    Posts:
    60
    Thanks, this shader looks cool :p
     
  6. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,347
    What is an "energy conserving shader"?
     
  7. Botanika

    Botanika

    Joined:
    Nov 2, 2013
    Posts:
    60
    the energy of light bouncing out of the surface of the material, should never exceed the energy of the incoming light . Just like in real life.

    Diffuse + Reflection + Refraction <= 1.
     
  8. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,347
    Doh I thought it was already like that for common shaders...
     
  9. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    No it isn't. You can see this, in the standard shaders, as at low Shininess levels the highlight is the same brightness as at a high shininess. So let's say a brightness of 1 covers 50 pixels. And then at lower gloss that same brightness (1) covers something like 150 pixels. And because diffuse is always the same here, you end up with something like...
    150 = 50
    which obviously isn't true.
     
  10. GameFabricator

    GameFabricator

    Joined:
    Dec 10, 2013
    Posts:
    14
    Very cool shader man! Here are some comments.

    I'd prefer the diffuse contribution to be consistent with gloss, spec and metalness set at 0. You can see in this image where I have 4 shaders, pure white, neutral grey (128rgb), your shader and one set to 100% env reflection. For some reason, the lighting on your shader is a bit flat, so the object loses form.
    $shader1.JPG

    This is also evident when cranking up the spec and gloss. They look great, but the lowered diff contribution flattens out the object.
    $shader2.JPG

    What I really like about this shader is that it's starting to push toward what UE4 is doing with their new physical material system - which is amazing BTW! In addition to tuning the diffuse contribution to make that feel more correct, I would consider adding in a cubemap reflection which is modulated by the spec and gloss. You could blur the cubemap by using its mips to generate a less reflective surface when dialing down the gloss.

    Actually, UE4's physical material system deals with it this way. The primary modulators in their shader are "Roughness" and "Metallic". They have Specular right now, but are probably going to remove it soon.

    Roughness describes how the surface scatters specular reflections on a micro level. It is the factor that determines how much reflection comes from the surface and to what degree it is blurred. Metallic controls the diffuse light spread and color reflection.

    In reality, almost all surfaces have reflective qualities, so their new physical material system is based on that notion.

    Lastly, rather than manually plugging in a cubemap, UE4 automatically samples light probes with cubemaps in the environment and blends between them as objects move about the scene. It would be cool to eventually implement something like this in Unity as well.
     
  11. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    Hmm... A shader based on roughness and metalness you say??

    ...
    ...

    Also, the reason the lighting on my shader is a bit flat is, to conserve energy in a lamberian model you have to divide the diffuse by pi. So to get the same brightness, you would have to have a light intensity pi.
     
    Last edited: Dec 11, 2013
  12. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    You had me at "Hello". :) I have no clue what that means but great work guys!
     
  13. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    Does anyone know how Unreal get their diffuse contribution? Is it a simple lerp(lambert, awesome reflective), or is it more complicated than that?
    Also screen shot of the shader 2.0:
    $UDKSpheres.png

    There are no directional lights in the scene.
    NOTE: I have had to make the shader, shader model 3.0 +
    WEBPLAYER

    Go fullscreen and right click to rotate.
     
    Last edited: Dec 12, 2013
  14. Aieth

    Aieth

    Joined:
    Apr 13, 2013
    Posts:
    805
    Actually in 3D graphics that pi is usually simplified out. I do believe Unity does this for their shaders and I do too in my shader package.
     
  15. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    Ok, good to know. Making the edits as we speak.
    Also, now that I look at it, this thread might be more suitable for the WIP forum.
     
    Last edited: Dec 12, 2013
  16. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    Done editing the top one.
     
  17. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,347
    Thank you for the explanation, dude :rolleyes:
     
  18. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    $CubemappedSpheres.png
    Just thought that I would post another image. The earlier webplayer has also been updated.
    Still no directional lights in the scene.

    WEBPLAYER
     
    Last edited: Dec 12, 2013
  19. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
  20. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    Does anyone know how the pro "light probes" system lerp's the coeffs dependent on distance.
     
  21. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,785
    This is looks great, but the only thing that i still don't understand how the energy conserving shader really behave if it got litted by multiple colored light....
     
  22. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    Try it out. I am giving these things away.
     
  23. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    Also, for people who are too lazy (like probably would be ;)) to download the shader package,
    At low metalness: the shader changes the highlight colour based on the light colour.
    At high metalness the whole shader get's multiplied by the light colour.
     
    Last edited: Dec 13, 2013
  24. GameFabricator

    GameFabricator

    Joined:
    Dec 10, 2013
    Posts:
    14
    Looks great!!
     
  25. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,785
    I did...it's just i'm still confused how did it actually behave with light :p
     
  26. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    You can check out the paper and related notes here:
    http://blog.selfshadow.com/publications/s2013-shading-course/
    "Real Shading in Unreal Engine 4 (Brian Karis)"