what is in float4 _LightShadowData?

It seems the z is something refers to distance, w is a constant,the code below

half ComputeShadow(float3 vec, float fadeDist, float2 uv)
{
	#if defined(SHADOWS_DEPTH) || defined(SHADOWS_SCREEN) || defined(SHADOWS_CUBE)
	float fade = fadeDist * _LightShadowData.z + _LightShadowData.w;
	fade = saturate(fade);
	#endif
                 .......
}

what about x and y, what the exact mean of each element ,x? y? z? w? :frowning:
anybody there!!

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 …

Tanks for your reply ,guy
I will check this issue later on

I cannot find documentation about it.

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

9 Likes

thank you

As I test,_LightShadowData.r equals “1 - shadow strength” rather than shadow strength.

3 Likes

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?

2 Likes

6584635--747898--upload_2020-12-3_16-51-7.png

Perhaps _LightShadowData.x is the shadow strength.

Here’s the calculation code for version 2019.1

_LightShadowData = new Vector4(
    1 - light.shadowStrength,                                                             // x = 1.0 - shadowStrength
    Mathf.Max(camera.farClipPlane / QualitySettings.shadowDistance, 1.0f),                // y = max(cameraFarClip / shadowDistance, 1.0) // but not used in current built-in shader codebase
    5.0f / Mathf.Min(camera.farClipPlane, QualitySettings.shadowDistance),                // z = shadow bias
    -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.
);