Search Unity

Fresnel in Unity 5 unified shader?

Discussion in 'Shaders' started by aiab_animech, Sep 10, 2014.

  1. aiab_animech

    aiab_animech

    Joined:
    Jul 4, 2012
    Posts:
    177
    Hello! I'm really looking forward to the unified PBR shader in Unity 5. Currently using marmoset.
    I've watched most videos I have found from Unite, but I haven't heard anything about fresnel. Maybe I've missed it, in that case I'm sorry.

    So, how does the unified shader handle fresnel input? Can't see it in the inspector properties for the material using the unified shader. Of course I could extend the shader with my own fresnel calculations (if the shader source is given to us), but it would be weird if the standard one didn't have this. Fresnel is a key component in PBR shading in my opinion, and omitting it would prevent us from creating real world materials correctly.
     
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Almost all dielectric materials share the same very small range of Fresnel values (about 0.04, I think, in linear space).

    So, generally it's easier to just hard code this value into the shader, only metals and some gemstones really need specific Fresnel values, and generally you won't notice it much if you use the values of 0.04 and something above a half for all dielectrics/metals, respectively.
     
  3. aiab_animech

    aiab_animech

    Joined:
    Jul 4, 2012
    Posts:
    177
    I don't really get your answer. Yes, fresnel isn't extremely varied for non-metals (but it is definitely varied), and as you say metals vary. And how do you tell the unified shader that something is a metal, and needs a very different fresnel compared to a plastic, for example? Does the specularity color paramter automatically tune the fresnel value? Is there a metallic-slider (I haven't seen one). At our company we don't create games; we create very realistic representations of real-life objects, which means a flat value doesn't cover it in any way.

    Examples of non-metals with highly varying fresnel are wood, porcelain and plastic. And the fresnel of these materials are waaay different than fresnel of chrome or steel.
     
  4. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    I'd suggest looking at "mastering physically based shading" talk from Unite 2014
    (and slides http://www.slideshare.net/RenaldasZioma/unite2014-mastering-physically-based-shading-in-unity-5)

    Basically, fresnel effect is defined by F0 aka "specular color". Metals have quite bright specular color that can be colored; non-metals have very dark gray specular color. The fresnel curves in both cases are not that different really - they go from F0 at "looking straight into surface" on one side, and go towards 1.0 (full reflectivity) at "looking at very grazing angle" for both metals & non-metals.
     
  5. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Generally, the standard these days is to have a metalness mask. Where it's 1, the albedo texture defined the specular value of metals (their diffuse is pure black, anyway, being metals). Where it's 0 you get a regular dielectric material where the albedo texture controls the diffuse colour (as most dielectric materials don't have coloured specular reflections, therefore don't need a specular colour value).
     
  6. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Yes and no, I think.

    One workflow is "metalness". Another workflow is "specular color". Both have pros & cons; specular color is "more physically correct"; metalness slightly cheaper.
     
  7. aiab_animech

    aiab_animech

    Joined:
    Jul 4, 2012
    Posts:
    177
    Ok, this makes sense.
    I'm a bit lost now however, because it really seems that there are conflicting ideas on how to work with PBR, even within the different workflows (albedo+spec/metalness).
    For example, I'm trying out DDO right now. And pretty much all sample dialectric materials have specular color, and not tiny amounts either. For example a sample wood material, which has a specular map that is pretty much equal to the gloss map. Same with how Marmoset seems to handle this (having a fresnel slider also).

    Aras, have you tried DDO with Unity 5? Any hints on getting it right?

    Also, say that I'm creating a wood material. The albedo map determines the color; should be some kind of brown normally. The gloss map determins if there are rougher and smoother areas in the wood. The specular map should be all black right (read: not use a specular map, use black color)?

    Also, the smoothness-parameter in the Unity 5 unified shader; can it be controlled with alpha in the specular map? There are certain hints that can be interpreted this way, but I'm not 100% sure. If that's the case, what does the alpha value of the specular color do? The same as the slider or nothing or something completely different?

    Thanks
     
  8. TrollHachem

    TrollHachem

    Joined:
    Dec 25, 2012
    Posts:
    65
    @Horp1 i remember i saw a video of someone using Ddo with unity 5 on youtube and it works fine , btw , if you watched the video (mastering PBS that aras linked) , he clearly says that the gloss (aka smoothness) is the alpha of the specular map :)
     
  9. aiab_animech

    aiab_animech

    Joined:
    Jul 4, 2012
    Posts:
    177
    I watched that video 2 times and didn't hear him say that. Must have missed it somehow. Then how about specular color alpha? Is it ignored?
     
  10. TrollHachem

    TrollHachem

    Joined:
    Dec 25, 2012
    Posts:
    65
    Well , because the smoothness slider exists i assume it's ignored.
     
  11. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Here´s the reason why I would like to see fresnel controls in Unitys standard shader:


    Try to get a similar result with the standard shader - its simply impossible.
     
  12. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    That is how it is usually implemented, but in reality the index of refraction is a complex number that varies with wavelength. (Where the complex part is the absorption k, which is only nonzero for metals.) So for metals it can actually be quite different:



    Supplying a 1D texture with the fresnel color can still be very useful even in 2016. And not just for mobile devices. Besides specific fresnel lookups for metals, there is also thin film reflection:


    And it would also help Carsten above. (Hi there, long time no see.) A 1D fresnel texture could be a nice addition to the standard shader.
     
  13. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    The metallic value in this case should be 0, not 1. Metallic set to 1 means the reflections are multiplied by the diffuse color, which since it's black is dulling them out.
     
  14. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    I tried with the UnityStandard shader to get as close to the Shaderforge look as possible.
    However, you can play with Standard vs Metallic and the diffuse/gloss values as long as you want - you´ll not get a comparable result (try attachment).

    Sorry - until now nobody convinced me saying "Fresnel controls are not necessary".
     

    Attached Files:

    Last edited: May 4, 2016
  15. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Just found the full fresnel formula that includes absorption again:

    fresnel.png

    And remember that both n and k typically vary with wavelength for metals. So for non-metals I think the typical approximation is absolutely fine, but for metals (and even more for thin films) the option to use a 1D fresnel texture can really offer a lot more realism.
     
  16. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Ah, now I see clearly what to do ! ;)