Skip to content

Commit e164711

Browse files
seungwon-ohEvergreen
authored and
Evergreen
committed
[Port][2022.3][UUM-90909] Fix artifacts when blending cascade shadows and distance shadowmask
1 parent 2338c99 commit e164711

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl

+15-7
Original file line numberDiff line numberDiff line change
@@ -276,20 +276,28 @@ SHADOW_TYPE EvaluateShadow_Directional( LightLoopContext lightLoopContext, Posit
276276
}
277277
else if (shadowSplitIndex == int(_CascadeShadowCount) - 1)
278278
{
279-
// float fade = lightLoopContext.shadowContext.fade;
280-
float3 camToPixel = posInput.positionWS - GetPrimaryCameraPosition();
281-
float distanceCamToPixel2 = dot(camToPixel, camToPixel);
282-
283-
HDDirectionalShadowData dsd = lightLoopContext.shadowContext.directionalShadowData;
284-
float fade = saturate(distanceCamToPixel2 * dsd.fadeScale + dsd.fadeBias);
279+
float fade = lightLoopContext.shadowContext.fade;
285280
// In the transition code (both dithering and blend) we use shadow = lerp( shadow, 1.0, fade ) for last transition
286281
// mean if we expend the code we have (shadow * (1 - fade) + fade). Here to make transition with shadow mask
287282
// we will remove fade and add fade * shadowMask which mean we do a lerp with shadow mask
288283
shadow = shadow - fade + fade * shadowMask;
289284
}
290285

291286
// See comment in EvaluateBSDF_Punctual
292-
shadow = light.nonLightMappedOnly ? min(shadowMask, shadow) : shadow;
287+
if (light.nonLightMappedOnly)
288+
{
289+
shadow = min(shadowMask, shadow);
290+
}
291+
else
292+
{
293+
// Use shadowmask when shadow value ​​cannot be retrieved due to shadow caster culling.
294+
float3 camToPixel = posInput.positionWS - GetPrimaryCameraPosition();
295+
float distanceCamToPixel2 = dot(camToPixel, camToPixel);
296+
297+
HDDirectionalShadowData dsd = lightLoopContext.shadowContext.directionalShadowData;
298+
float alpha = saturate(distanceCamToPixel2 * dsd.fadeScale + dsd.fadeBias);
299+
shadow = min(shadow, lerp(1.0, shadowMask, alpha * alpha));
300+
}
293301
#endif
294302

295303
shadow = lerp(shadowMask.SHADOW_TYPE_REPLICATE, shadow, light.shadowDimmer);

Tests/SRPTests/Projects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2324_Shadow_Mask_Directional_Blending/Scene Settings Profile.asset

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ MonoBehaviour:
1616
interCascadeBorders: 1
1717
maxShadowDistance:
1818
m_OverrideState: 1
19-
m_Value: 5
19+
m_Value: 7
2020
directionalTransmissionMultiplier:
2121
m_OverrideState: 1
2222
m_Value: 1

0 commit comments

Comments
 (0)