Skip to content

Commit 2468377

Browse files
FrancescoC-unitysebastienlagarde
authored andcommitted
Avoid issues causing faulty transitions in shadows (resulting in no shadows with unconventional aspect ratio) #2776
1 parent c170333 commit 2468377

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
- Fixed issue where some ShaderGraph generated shaders were not SRP compatible because of UnityPerMaterial cbuffer layout mismatches (case 1292501)
1414
- Fixed computation of geometric normal in path tracing (case 1293029).
1515
- Fixed issues with path-traced volumetric scattering (cases 1295222, 1295234).
16+
- Fixed issue with faulty shadow transition when view is close to an object under some aspect ratio conditions
1617

1718
### Changed
1819
- Now reflection probes cannot have SSAO, SSGI, SSR, ray tracing effects or volumetric reprojection.

com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,15 @@ int EvalShadow_GetSplitIndex(HDShadowContext shadowContext, int index, float3 po
206206

207207
// The above code will generate transitions on the whole cascade sphere boundary.
208208
// It means that depending on the light and camera direction, sometimes the transition appears on the wrong side of the cascade
209-
// To avoid that we attenuate the effect (lerp to 0.0) when view direction and cascade center to pixel vector face opposite directions.
209+
// To avoid that we attenuate the effect (lerp very sharply to 0.0) when view direction and cascade center to pixel vector face opposite directions.
210210
// This way you only get fade out on the right side of the cascade.
211211
float3 viewDir = GetWorldSpaceViewDir(positionWS);
212-
float cascDot = dot(viewDir, wposDir);
213-
alpha = lerp(alpha, 0.0, saturate(cascDot * 4.0));
214212

213+
float cascDot = dot(viewDir, wposDir);
214+
// At high border sizes the sharp lerp is noticeable, hence we need to lerp how sharpenss factor
215+
// if we are below 80% we keep the very sharp transition.
216+
float lerpSharpness = 8.0f + 512.0f * smoothstep(1.0f, 0.7f, border);// lerp(1024.0f, 8.0f, saturate(border - 0.8) / 0.2f);
217+
alpha = lerp(alpha, 0.0, saturate(cascDot * lerpSharpness));
215218
return shadowSplitIndex;
216219
}
217220

@@ -298,7 +301,7 @@ float EvalShadow_CascadedDepth_Dither_SplitIndex(HDShadowContext shadowContext,
298301

299302
/* We select what split we need to sample from */
300303
float nextSplit = min(shadowSplitIndex + 1, cascadeCount - 1);
301-
bool evalNextCascade = nextSplit != shadowSplitIndex && step(InterleavedGradientNoise(positionSS.xy, _TaaFrameInfo.z), alpha);
304+
bool evalNextCascade = nextSplit != shadowSplitIndex && alpha > 0 && step(InterleavedGradientNoise(positionSS.xy, _TaaFrameInfo.z), alpha);
302305

303306
if (evalNextCascade)
304307
{

0 commit comments

Comments
 (0)