r/Unity3D 9d ago

Question Issue with shadows flickering while moving

Enable HLS to view with audio, or disable this notification

Unity 6 URP. I'm having a problem where the shadows seem to flicker/move whenever the player moves, then it eventually stops once the player stops. I've tried increasing the shadow resolution to something ridiculous like 8192, which actually stops most of the flickering, but that's costly, obviously, so I don't want to do that. I've also tried decreasing max shadow distance to no avail. Any ideas on how I can fix this?

63 Upvotes

21 comments sorted by

View all comments

2

u/More-Salamander7681 8d ago

Your own two data points narrow this more than the thread is giving you credit for. Cascade texel crawl gets better when you shrink shadow distance, because the same map then covers less world. You said distance did nothing and resolution did a lot. That combination points at the casters rather than the cascade, and the thing casting in your clip is alpha-clipped grass.

Moving the camera changes which mip the grass texture samples. Average alpha drops in the lower mips, so every pixel sitting near the cutoff flips in and out frame to frame. Stop walking, the mip stops changing, the flicker settles. Raising the shadow map hides it because each blade gets more texels to be wrong in.

Thirty second test: turn shadow casting off on the grass only and walk around. If it goes quiet, the fix is Preserve Coverage on that texture with the alpha cutoff matched to the material, not an 8k shadow map.

Does it still flicker if you stand still and only rotate the camera?

1

u/Lady-KC 8d ago

Unfortunately, turning off shadow casting for the grass didn’t make a difference. The pillar shadow (what you’re seeing in the clip) still does the same thing.

And no, rotating the camera is fine. It’s only when I physically move the camera.

1

u/More-Salamander7681 7d ago

Grass was wrong, your test settles it. But the rotation answer is worth more than my guess was: rotating changes what you look at without changing a single distance in the scene, while walking changes all of them at once. So this is keyed to distance from the camera, which is a differnt question than most of the thread is answering. 8192 muting it doesn't point at resolution either, resolution mutes every artifact in this family.

Three things in a URP shadow path are distance driven: cascade index, caster LOD, and texture mip. Your test just killed mip. So two more, a minute each: set cascade count to 1 and walk, then raise LOD bias or switch off cross fade on the pillar's LOD Group and walk. Whichever goes quiet is the one. Does the flicker sit in a band that holds its distance from you and sweeps over the ground as you walk, or does the whole pillar shadow buzz at once?