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. Dismiss Notice

Fresnel approximation: I have two different implementations, which one is "correct"?

Discussion in 'Shaders' started by metaleap, May 13, 2014.

  1. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Consolidating various partially-redundant shader includes and noticed I used 2 different fresnel implementations:

    First one from some PBS tutorials, can't remember which:

    Code (csharp):
    1.  
    2. const half fresTerm = pow(1.0 - dotHL, 5.0) * (1.0 - f0) + f0;
    3.  
    Second one from J. Hable:

    Code (csharp):
    1.  
    2. const half expo = pow(1.0 - dotHL, 5.0);
    3. const half fresTerm = expo + f0 * (1.0 - expo);
    4.  
    For specular, both look "fine" to the physically-based-untrained-eye and even to mine. I can't tell visually which one is correct. But clearly both functions clearly give slightly different result floats as they do plain different things from their inputs.
     
  2. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,862
    what is wrong or right depends on your eye pleasure here, forexample i have 5 different fresnel calculations in my water shaders package for every case.
     
  3. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Yeah but I do everything reflective in a single deferred light pass so per-material fresnel is out :D

    I found another one by Lagarde:

    Code (csharp):
    1.  
    2. const half expo = pow(1.0 - dotHL, 5.0);
    3. const half fresTerm = f0 + (1.0f - f0) * expo
    4.  
    Seems like there is no end to Fresnel approximations :D
     
  4. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    687
    I've always used Schlick's approximation which is something like-

    Code (csharp):
    1.  fresnel = exponential + _Fresnel * (1.0 – exponential);
    where exponential is: pow( 1 – dot(V,H), 5.0);
     
  5. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,862
    So what? Just pick the fastest one with the better visual.
     
  6. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Guess I could "try" that :D :D
     
  7. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    It seems to me that both are pretty much the same. Just a different ordering of the variables with the same result.

    a + (1 - a) * b = b + a * (1 - b)