Skip to content

Commit 4261de2

Browse files
elliomanEvergreen
authored andcommitted
[Unity 6][URP] Fixing an issue where Shadow Near Plane incorrectly culls casters (UUM-63997)
Fixes UUM-63997.
1 parent cf75ff2 commit 4261de2

File tree

4 files changed

+1054
-5
lines changed

4 files changed

+1054
-5
lines changed

Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct Varyings
3030
UNITY_VERTEX_INPUT_INSTANCE_ID
3131
};
3232

33+
#define EPSILON 0.001
3334
float4 GetShadowPositionHClip(Attributes input)
3435
{
3536
float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
@@ -43,11 +44,12 @@ float4 GetShadowPositionHClip(Attributes input)
4344

4445
float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, lightDirectionWS));
4546

46-
#if UNITY_REVERSED_Z
47-
positionCS.z = min(positionCS.z, UNITY_NEAR_CLIP_VALUE);
48-
#else
49-
positionCS.z = max(positionCS.z, UNITY_NEAR_CLIP_VALUE);
50-
#endif
47+
#if UNITY_REVERSED_Z
48+
float clamped = min(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
49+
#else
50+
float clamped = max(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
51+
#endif
52+
positionCS.z = lerp(positionCS.z, clamped, saturate(_ShadowBias.y + EPSILON));
5153

5254
return positionCS;
5355
}

0 commit comments

Comments
 (0)