Search Unity

Unity Environment Ground Lighting and RGB Cookies.

Discussion in 'Shaders' started by Quatum1000, Jul 11, 2019.

  1. Quatum1000

    Quatum1000

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

    for a test, I'd like to use the custom Unity Environment Gradient Ground Lighting with a rgb cookie. I started to search for .cginc file where this shader is implemented. But can not find anything about in the CGIncludes folder.

    Untitled-1.jpg

    I found some variables in UnityShaderVariables.cginc
    fixed4 unity_AmbientGround; etc..

    but no real calculation and nothing else. Is this a perhaps screen-space image calculation?

    The -Environment Gradient Ground lightning- enlighten the geometry more smooth than a common directional light.

    Are these "Environment Gradient" shaders not accessible by any shader or .cginc file in unity?
    Thank you..
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Unity's ambient lighting system uses spherical harmonics to store and sample the ambient light color and intensity for all built-in shaders. When you set the Environment Lighting source to Gradient or Color it's still using those same spherical harmonics, the values are just being injected into the spherical harmonic data.

    When using Gradient or Color, those values are also passed to the shaders via the unity_Ambient* values, though again no built-in shader uses them. There also isn't anything to let the shader know which source setting is being used, so it's up to you to either ensure you're using the source type you want, or set a property or keyword to switch the shader between different modes.

    Generally, when using the source set to gradient, if you wanted to use the three colors directly, you'd do something like this:
    Code (csharp):
    1. fixed3 ambient = lerp(unity_AmbientEquator, unity_AmbientSky, saturate(worldNormal.y));
    2. ambient = lerp(unity_AmbientGround, ambient, saturate(worldNormal.y - 1));
    Or you can make it look a little nicer like this:
    Code (csharp):
    1. fixed3 ambient = lerp(unity_AmbientEquator, unity_AmbientSky, smoothstep(0, 1, worldNormal.y));
    2. ambient = lerp(unity_AmbientGround, ambient, smoothstep(-1, 0, worldNormal.y - 1));
    Neither are strictly "correct", but neither are "incorrect" either since there is no right or wrong way to implement the values since it's totally up to you on how you want it to look.
     
    Quatum1000 likes this.
  3. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Great.. Thank you!