Search Unity

Custom BRDF for Unity 5.x Surface Shaders: Possible?

Discussion in 'Shaders' started by jspoto, Jul 21, 2015.

  1. jspoto

    jspoto

    Joined:
    May 10, 2013
    Posts:
    8
    Hello -

    I've got a terrain rendering problem on a fairly large-scale Unity 5 project, that requires a custom BRDF, using the new Unity 5 deferred renderer.

    Unlike what the current documentation suggests, custom lighting models no longer work like they did in Unity 4 -- deferred or forward. They can be used, but they simply modify terms as they are written to the deferred buffers -- they can't meaningfully use lighting terms as suggested by even the simplest example in the docs (SimpleLambert, as discussed here)

    Which brings me to a custom BRDF -- In my case, I'd like to essentially override the UNITY_BRDF_PBS macro as defined in UnityPBSLighting.cging, or more specifically (for the PC platform) provide a custom variant of the BRDF1_Unity_PBS shading model as seen in UnityStandardBRDF.cginc to my surface shader.

    The reason: the default PBR BRDF model used by Unity simple isn't doing the job -- it takes a few (questionable) shortcuts, and the way refractive terms (fresnel) are handled result in unacceptable results at glancing angles. Which for terrain is a total deal breaker, since your typical panorama invariably includes expanses of such areas.

    Is this possible? I'm hoping there's some undocumented Unity 5 shader magic, that would allow me to override the BRDF used by the surface shader -- some comments in the include files hint at this, but I've yet to find some means to do it.

    Any help is appreciated, and thanks,

    (PS: I'm not looking for some kind of global override, but a BRDF override for a specific surface shader)
     
    Last edited: Jul 21, 2015
    crudeMe likes this.
  2. crudeMe

    crudeMe

    Joined:
    Jul 8, 2015
    Posts:
    92
    I've read somewhere Unity is using blinn-phong BRDF. I wonder if I can try Torrance-Sparrow ones. Sorry for non-informative post, I'm going to watch this thread. Thanks!
     
    bugsbun likes this.
  3. grizu

    grizu

    Joined:
    Jan 29, 2014
    Posts:
    5
    crudeMe likes this.
  4. bugsbun

    bugsbun

    Joined:
    Jun 26, 2017
    Posts:
    27
    Can you please confirm that Unity is still using blinn phong BRDF in 5.6.3 ? I would really appreciate it !
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,793
    AFAIK, ever since 5.3, Unity uses GGX.
     
    bugsbun likes this.
  6. bugsbun

    bugsbun

    Joined:
    Jun 26, 2017
    Posts:
    27
    Can I know the details, like I know 4 GGX variations, which one does Unity use ? Where can I read this up . Thanks!
     
  7. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,793
    There is a comment in UnityStandardBRDF.cginc (download the shader sources if you want to take a look), that says:
    That's for High quality shader (in the tier settings).

    Medium should be:
    And Low:
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Unity uses their own variation. So now you know of 5.