Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Normal specular/shadow calculation in UnityPBSLighting.cginc

Discussion in 'Shaders' started by Quatum1000, Apr 21, 2020.

  1. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Hi everyone,

    I'm searching for the calculation of spec and micro shadowing from the normals in PBS/BDRF lighting cginc.
    (Geometric Attenuation factors for microfacet-based BRDFs)

    When raising normals, specular and partial shadow intensity raising both for sure. The standard result is this.

    Untitled-1.jpg


    But require a reduced micro shadow intensity but the same specular intensity, in general.

    Untitled-2.jpg


    I have looked into the Internal_Deferred.shader for CalculateLight() and found :

    half4 res = UNITY_BRDF_PBS (data.diffuseColor, data.specularColor, oneMinusReflectivity, data.smoothness, data.normalWorld, -eyeVec, light, ind);

    and the UnityStandardBDRF.cginc and other includes.

    But I did not find where the specular light and micro-shadow is calculated from the normals.
    I think it must be calculated anywhere in this cginc.Does anyone knows where to find? Thank you.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Look again?
     
    Quatum1000 likes this.
  3. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Seems to be the DisneyDiffuse function() :)

    * There is also another specular property that is extremely difficultly to find.
    When raising specular intensity to 1.0 then albedo is completely overwritten by the spec color.

    * The specular disk size is too small as well, but the intensity should not be affected.
    But this could happen to the unique unity light fall off, that tries to enlight as much pixels as possible and the specular disk feels much smaller therefore. I wish I could have a separate value for the the disk size and form.
     
  4. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Its not possible to get a reduced micro shadow intensity. All normals are mixed up and the DisneyDiffuse function() affects the whole screen. If it should work per texture it seems the only way is to define a special value range in the normal texture .rg and react in DisneyDiffuse().

    It's used in the standard custom shaders:
    Code (CSharp):
    1. /// Path x:\Unity\20xx.x.xxxx\Editor\Data\CGIncludes\UnityPBSLighting.cginc
    2.  
    3. inline half4 LightingStandardSpecular_Deferred (SurfaceOutputStandardSpecular s, float3 viewDir, UnityGI gi, out half4 outGBuffer0, out half4 outGBuffer1, out half4 outGBuffer2)
    4. {
    5. ...
    6. s.Albedo = EnergyConservationBetweenDiffuseAndSpecular (s.Albedo, s.Specular, /*out*/ oneMinusReflectivity);
    7. ...
    8.  
    and function itself in:
    x:\Unity\20xx.x.xxxx\Editor\Data\CGIncludes\UnityStandardUtils.cginc