Search Unity

Get Skybox color

Discussion in 'Editor & General Support' started by RedMattis, Apr 18, 2015.

  1. RedMattis

    RedMattis

    Joined:
    Apr 18, 2015
    Posts:
    33
    I'm using a Skybox as my source for ambient light. How to I get the color of the ambient light? Even better how do I get the light coming from a specific direction?

    I figured I could use it as input to color fog for example.
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,911
  3. RedMattis

    RedMattis

    Joined:
    Apr 18, 2015
    Posts:
    33
    Yeah, I was looking at that one before I posted actually. I'm not sure how I am supposed to use it though.

    The only functions I found on it are "Add Ambient Light", "AddDirectionalLight", "Clear", "Equals", "GetHashCode", "GetType" and "ToString". The last two simply returned "Unity.Rendering.SphericalHarmonicsL2", which I'm guessing is the class the probe is built from.
     
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,911
    It's used from Unity shaders, and is passed as:
    Code (csharp):
    1.  
    2.     half4 unity_SHAr;
    3.     half4 unity_SHAg;
    4.     half4 unity_SHAb;
    5.  
    In Unity installation path, search for UnityGlobalIllumination.cginc

    Code (csharp):
    1.  
    2.     #if UNITY_SHOULD_SAMPLE_SH
    3.         #if UNITY_SAMPLE_FULL_SH_PER_PIXEL
    4.             half3 sh = ShadeSH9(half4(normalWorld, 1.0));
    5.         #elif (SHADER_TARGET >= 30)
    6.             half3 sh = data.ambient + ShadeSH12Order(half4(normalWorld, 1.0));
    7.         #else
    8.             half3 sh = data.ambient;
    9.         #endif
    10.    
    11.         o_gi.indirect.diffuse += sh;
    12.     #endif
    13.  
    ShadeSH9 and ShadeSH12Order queries that data, and extracts ambient color which is added to o_gi.indirect.diffuse