source-sdk-2013 icon indicating copy to clipboard operation
source-sdk-2013 copied to clipboard

all games: Fix a case of dynamic shadows bleeding through thin surfaces

Open copperpixel opened this issue 4 weeks ago • 3 comments

Description

CClientShadowMgr::ComputeExtraClipPlanes builds clip planes from the shadow bounding box corner farthest along the shadow direction to prevent dynamic shadows poking through surfaces.

If that corner goes through a brush it would cause the shadow to render on the other side of the brush's surface. This can happen when a model stands near a thin brush wall.

To fix this, this PR updates the compute routine to do a trace from the caster's render origin to our bounding box corner and push the corner's origin along the surface normal towards the caster as needed so the clip planes won't be positioned through solids.

Note that this doesn't address the lack of dynamic shadow clipping through walls in the shadow direction because of the engine's hard-coded limit of max 4 clip planes per shadow. If the limit were to be incremented by 3 (1 plane for each axis) it would suffice to provide a fix for that.

Comparison screenshots of some problematic spots on Dustbowl:

Before After
rttshadow_clipping_fix_dustbowl1_before rttshadow_clipping_fix_dustbowl1_after
rttshadow_clipping_fix_dustbowl2_before rttshadow_clipping_fix_dustbowl2_after
rttshadow_clipping_fix_dustbowl3_before rttshadow_clipping_fix_dustbowl3_after
rttshadow_clipping_fix_dustbowl4_before rttshadow_clipping_fix_dustbowl4_after

Closes https://github.com/ValveSoftware/Source-1-Games/issues/52

copperpixel avatar Dec 02 '25 18:12 copperpixel

Note that this doesn't address lack of dynamic shadow clipping oriented towards the shadow direction so it doesn't bleed through walls there because of the engine's hard-coded limit of max 4 clip planes per shadow.

I presume, in layman's terms, this means that improper shadows which are in the direction of the shadow will still appear, like so?

With shadows Shadows disabled
withshadows noshadows

(note shadows at crosshair)

SirYodaJedi avatar Dec 03 '25 00:12 SirYodaJedi

Replying to https://github.com/ValveSoftware/source-sdk-2013/pull/1686#issuecomment-3604450928

Yes.

Though if Valve were to raise the limit of clip planes it would've been possible to fix this a similar way to this PR.

copperpixel avatar Dec 03 '25 00:12 copperpixel

note: this has been implemented in gmod for 2 weeks now and there hasn't been any issues so far

wgetJane avatar Dec 15 '25 18:12 wgetJane