Skip to content

Commit 48ddd1c

Browse files
Revert: Fix shadow mask fade and optimize it at same time #5911
1 parent e34bfc8 commit 48ddd1c

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3535
- Fixed crossfade not working on the HD ST8 ShaderGraph [case 1369586](https://fogbugz.unity3d.com/f/cases/1369586/)
3636
- Fixed range compression factor being clamped. (case 1365707)
3737
- Fixed tooltip not showing on labels in ShaderGraphs (1358483).
38-
- Fixed and optimize distance shadowmask fade.
3938
- Fix API warnings in Matcap mode on Metal.
4039
- Fix D3D validation layer errors w.r.t shadow textures when an atlas is not used.
4140

com.unity.render-pipelines.high-definition/Runtime/Lighting/LightDefinition.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ struct DirectionalLightData
9595
[SurfaceDataAttributes(precision = FieldPrecision.Real)]
9696
public Vector4 shadowMaskSelector; // Used with ShadowMask feature
9797

98-
public Vector2 cascadesBorderFadeScaleBias;
99-
10098
public float diffuseDimmer;
10199
public float specularDimmer;
102100
public float penumbraTint;

com.unity.render-pipelines.high-definition/Runtime/Lighting/LightDefinition.cs.hlsl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ struct DirectionalLightData
7272
real minRoughness;
7373
int screenSpaceShadowIndex;
7474
real4 shadowMaskSelector;
75-
float2 cascadesBorderFadeScaleBias;
7675
float diffuseDimmer;
7776
float specularDimmer;
7877
float penumbraTint;

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,19 @@ SHADOW_TYPE EvaluateShadow_Directional( LightLoopContext lightLoopContext, Posit
269269
shadow = lightLoopContext.shadowValue;
270270

271271
#ifdef SHADOWS_SHADOWMASK
272-
float3 camToPixel = posInput.positionWS - GetPrimaryCameraPosition();
273-
float distanceCamToPixel2 = dot(camToPixel, camToPixel);
274-
float fade = saturate(distanceCamToPixel2 * light.cascadesBorderFadeScaleBias.x + light.cascadesBorderFadeScaleBias.y);
272+
// TODO: Optimize this code! Currently it is a bit like brute force to get the last transistion and fade to shadow mask, but there is
273+
// certainly more efficient to do
274+
// We reuse the transition from the cascade system to fade between shadow mask at max distance
275+
uint payloadOffset;
276+
real fade;
277+
int cascadeCount;
278+
int shadowSplitIndex = 0;
279+
280+
shadowSplitIndex = EvalShadow_GetSplitIndex(lightLoopContext.shadowContext, light.shadowIndex, posInput.positionWS, fade, cascadeCount);
281+
282+
// we have a fade caclulation for each cascade but we must lerp with shadow mask only for the last one
283+
// if shadowSplitIndex is -1 it mean we are outside cascade and should return 1.0 to use shadowmask: saturate(-shadowSplitIndex) return 0 for >= 0 and 1 for -1
284+
fade = ((shadowSplitIndex + 1) == cascadeCount) ? fade : saturate(-shadowSplitIndex);
275285

276286
// In the transition code (both dithering and blend) we use shadow = lerp( shadow, 1.0, fade ) for last transition
277287
// mean if we expend the code we have (shadow * (1 - fade) + fade). Here to make transition with shadow mask

0 commit comments

Comments
 (0)