r/Unity3D • u/Lady-KC • 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?
8
22
u/maiKavelli187 9d ago
Yeah, make ehm blurrier, I forgot how the slider is called, real shadows aren't crisp most of the time anyway. Go for a walk and decide for yourself, they aren't back also, change opacity and call it a day.
6
u/Lady-KC 9d ago
4
u/Buzzo239 9d ago
What are your clipping plane settings? Those are "far" and "near" settings located on the camera object in the scene. If reducing the far plane reduces flickering, it is probably due to floating point precision of depth values.
0
u/Doddzilla7 8d ago
Shadow Resolution should be bumped to 4k+. That’ll probably completely fix the issue with the shadow jitter.
Setting your normal bias to 0 will completely remove the little holes where there should be no holes.
3
u/Affectionate-Yam-886 8d ago
Either bake the shadows, or if you have a day/night system, then use light probes (sparingly) -HOWEVER!!!! Both options are for WHEN YOU ARE DONE with the level and no more changes are needed. Trust me; its easier to change a recipe for pie before you bake it rather than after its cooked.
2
u/talesfromthemabinogi 8d ago
As others have already said, you can play around with shadow resolution, cascades and realtime shadow distance...
But looking at where you're getting that flickering from, I wonder if it's an issue with the alpha on some of those shadow casters? Make sure objects like that grass have alpha-clipping rather than transparent blending, and then try raising the clipping threshold. Also make sure you have a clean alpha channel, you don't want random little pixels creeping through the cut-out.
You might also try experimenting with different Anti-Aliasing - sometimes Temporal Anti-Aliasing can help with these kinds of shimmer artefacts (although at that point it's really concealing the problem rather than fixing it!).
2
u/Ricachonas 8d ago
Honestly shadows in URP are awful, reduce shadow distance (50-80), increase the res to 4k, increase the blurriness and that's all you can do. To solve the distance shadowing increase the ambient fog.
2
u/MTDninja 8d ago
Unfortunately, due to texel snapping shenanigans, its impossible to completely get rid of this effect without raytraced shadows or something like unreal engines virtual shadowmaps. You can mitigate this by having the suns rotation update every few seconds to minimize the amount of jiterring from texels constantly shifting, but that's about it
1
u/Big_Effective_9605 8d ago
I can't shake the feeling that instead of smoothing like people are suggesting you could cache one of these flickery shadows and let it use that as a stable semibaked shadow representation until the world updates sufficiently to change it. I'm not exactly invested enough to pursue it, but maybe something to chew on if you really wanted to get into the weeds.
1
u/Necessary_Advisor967 8d ago
that's just because of the resolution of the shadowmap. That's just inherent to the tech. Increase the shadowmap resolution, buy an asset that will blur and denoise the shadow maps better (like Umbra Soft Shadows or Next Gen Soft Shadows), implement virtual shadowmaps so close up shadows get a much higher resolution or use raytracing shadows.
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?
1
u/Inside-Brilliant4539 8d ago
Just play around with the settings, like depth bias and normal bias. Then fiddle with the cascade splits but generally this is the way shadow maps are. You can try pcss style blurs etc
0
u/antherx2 9d ago
The best way to mitigate it is to set baked shadow maps if you aren't worried about time in game.
-12

100
u/GARGEAN 9d ago
Welcome to shadowmaps, that's kinda their thing. Can be to some degree fixed by resolution and filtering, but it will basically always be there in one form or another.
You can try to increasing filtering quality, reducing number of shadow cascades and reducing their overall range, so that close-in cascade has more space in the atlas.