Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

what is in float4 _LightShadowData?

Discussion in 'Shaders' started by Lulucifer, Jan 10, 2013.

  1. Lulucifer

    Lulucifer

    Joined:
    Jul 8, 2012
    Posts:
    358
    It seems the z is something refers to distance, w is a constant,the code below
    Code (csharp):
    1.  
    2. half ComputeShadow(float3 vec, float fadeDist, float2 uv)
    3. {
    4.     #if defined(SHADOWS_DEPTH) || defined(SHADOWS_SCREEN) || defined(SHADOWS_CUBE)
    5.     float fade = fadeDist * _LightShadowData.z + _LightShadowData.w;
    6.     fade = saturate(fade);
    7.     #endif
    8.                  .......
    9. }
    10.  
    what about x and y, what the exact mean of each element ,x? y? z? w? :(
    anybody there!!
     
  2. Manul

    Manul

    Joined:
    Nov 30, 2012
    Posts:
    18
    LightShadowData.x is light.shadowstrength

    trying to dig out the rest from a project that used this ... unfortunately that project lay dormant for 3 months and not everything was well documented ...
     
  3. Lulucifer

    Lulucifer

    Joined:
    Jul 8, 2012
    Posts:
    358
    Tanks for your reply ,guy
    I will check this issue later on
     
  4. ght1875

    ght1875

    Joined:
    Jul 29, 2016
    Posts:
    26
    I cannot find documentation about it.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,265
    Because it's not in the documentation still.

    _LightShadowData.x - shadow strength
    _LightShadowData.y - Appears to be unused
    _LightShadowData.z - 1.0 / shadow far distance
    _LightShadowData.w - shadow near distance
     
  6. ght1875

    ght1875

    Joined:
    Jul 29, 2016
    Posts:
    26
    thank you
     
  7. Aldrick

    Aldrick

    Joined:
    Feb 19, 2014
    Posts:
    64

    As I test,_LightShadowData.r equals "1 - shadow strength" rather than shadow strength.
     
    INeatFreak, Lin-Dong and bgolus like this.
  8. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    958

    As this is the ONLY available explanation to _LightShadowData on the Internet, allow me to follow up on asking:

    How is _LightShadowData.z and _LightShadowData.w computed?

    It doesn't appear to be 1.0 / shadow far distance at all. It's not even 1.0 / min(camera.farClipPlane, shadowDistance).

    What I have tested and believed are:

    _LightShadowData.x = 1.0 - shadow distance.
    _LightShadowData.y = max(camera far clip / shadow distance, 1.0)
    // but not used in current built-in shader codebase
    _LightShadowData.z = 5.0f * max(camera far clip / shadow distance, 1.0) / min(camera far clip, shadow distance) // not sure about the 5.0f, but it seems like the value
    _LightShadowData.w = -1.0f * (2.0f + camera field of view / 180.0f * 2.0f) // fov is regarded as 0 when orthographic.

    So, can someone from Unity help us to answer this probably now *decade old question*?
     
    Last edited: Oct 24, 2020
    INeatFreak and Jason-Michael like this.
  9. lxycg

    lxycg

    Joined:
    Jul 16, 2018
    Posts:
    2
    upload_2020-12-3_16-51-7.png

    Perhaps _LightShadowData.x is the shadow strength.
     
  10. INeatFreak

    INeatFreak

    Joined:
    Sep 12, 2018
    Posts:
    46
    Here's the calculation code for version 2019.1

    Code (CSharp):
    1. _LightShadowData = new Vector4(
    2.     1 - light.shadowStrength,                                                             // x = 1.0 - shadowStrength
    3.     Mathf.Max(camera.farClipPlane / QualitySettings.shadowDistance, 1.0f),                // y = max(cameraFarClip / shadowDistance, 1.0) // but not used in current built-in shader codebase
    4.     5.0f / Mathf.Min(camera.farClipPlane, QualitySettings.shadowDistance),                // z = shadow bias
    5.     -1.0f * (2.0f + camera.fieldOfView / 180.0f * 2.0f)                                    // w = -1.0f * (2.0f + camera.fieldOfView / 180.0f * 2.0f) // fov is regarded as 0 when orthographic.
    6. );