Flickering/Wobbly Shadows Issue due to Day/Night Cycle

Hi guys,

I’m losing my mind a little here. I have a particular issue in regards to shadows flickering or rather, wobble due to my day/night cycle and I’ve had to hit the forums to see if anyone else has mitigated the issue or have alternative ideas.

You can see the problem here: https://www.youtube.com/watch?v=IrMHcfgrQJs

My game is using a two tone cel shaded post process for a number of foliage and assets in game and the directional light movement is updating per tick or rather, frame.

Steps I have taken so far to try and mitigate the issue (which has helped somewhat)

  • Adjusted Shadow Bias, Distribution Exponent, Cascades Amount and Transition Factor (tuned to the best results I can get
  • Stepped the light movement (although this helped the effect is still there, just “slower”
  • Set r.shadow.filtermethod to 1 (improves the flickering very well but introduces weird artifacts on certain objects, I would like to avoid this)

I can mitigate the problem entirely by enabling virtual shadow maps but due to the WPO and animated light nature I’m invalidating every frame which is a huge performance hit.

Has anyone encountered this issue or have better knowledge than myself (very easy to achieve lol) and have some solutions?

Probably using a post process cel shader over Lumen, which typically won’t work, because Lumen is not completely temporally stable.

Thanks for the reply. Lumen is disabled already.
I’m only using a moveable directional and all dynamic shadows

It’s hard to research the issue because everything points to Lumen in search results at the moment.

I’m assuming that’s this is some kind of shadow confusion between the hard edge of the shadow, WPO and the lights direction being updated every frame. But my assumptions don’t mean much as I don’t really know where else to look for improvements.

Turn off your post process and post a video. If it isn’t lumen my next guess would be that it’s virtual shadowmaps and you’re using a directional light with a large source angle.

I’ll get that posted in a second.
As for virtual shadow maps, the example above is with it disabled. I can completely solve the issue by enabling virtual shadow maps.

Edit: Source Angle? is that something I should look into?

Here is the test with Post-Process Material disabled. Issue doesn’t seem to be there nearly as bad but you can see the effect still regardless. Just far more subtle due to soft shadow gradient I guess.

I could be asking for too much precision using simpler methods of shading.

Shouldn’t be jittering like that but it may just be that the shadow cascade resolution is just too low. I would try reducing the dynamic shadow casting distance significantly, increasing the number of cascades, or adjusting the cascade distribution (all settings in the directional light)

I’m having this same issue after changing my scalability settings, but switching it back doesn’t fix it. I wonder what the setting is that causes it.

Thanks for the input Ark,

I have adjusted all settings except for reducing the dynamic shadow distance prior to making this thread. Reason for not lowering the dynamic shadow distance is because I have to have Distance Field Shadows disabled as the effect is worse with those shadows in the distance!

The cleanest settings I could get are as follows:

  • Dynamic Shadow Distance 15000
  • Number of Cascades = 4
  • Distribution Exponent = 1.8
  • Shadow Bias = 0.5 (either lower or higher values just seem to ‘move’ the effect around)
  • Shadow Resolution = 2
    (may have missed some, brain is melting)

This is interesting,
I will look into this.

I haven’t really messed with scalability apart from r.screenpercentage for DLSS, and FSR upscaling, but I’m going to test that now too.

I’m not a fan of these pre-defined scalability and gameusersettings nodes. They seem to get in the way more than anything.

Alright,

I have done everything you mentioned again and beyond.

If I stop my animated directional light (night/day system) the problem stops. So I know the issue is with lights animated movement and some sort of shadow invalidation. (I’m not using virtual shadows or lumen)

But even with all post process materials disabled, shadow cascades at max, dynamic shadow distances checked (no significant improvements at any lower ranges), resolution at maximum, shadow bias, light source angle and intensity, auto exposure settings, skylight settings etc etc I saw miniscule improvements at major sacrifices of my visual quality. In that second video I posted above we can see that this invalidation or problem is apparent even without forcing lighting information into bands in post-process.

I just don’t understand enough about Unreal Engine’s dynamic lighting system to fix this issue, and it seems to be a rare issue… for some reason.

Did you find the solution?

Alright, I got it sorted out for my game.

The thing that helped me the most is r.Shadow.MaxCSMResolution. By default it’s set to 2048; increasing it to 4096 makes a difference, but it’s not all. Without it everything below still has impact for the final shadow quality, but increasing the CSM resolution helps immensely with flickering specifically.

By default directional light has Dynamic Shadow Distance MovableLight set to 40000, Distribution Exponent set to 3.0, and Num Dynamic Cascades set to 4.

The lower the distance, the sharper the shadows will be. There’s a point where it makes it worse, but for me 4000 worked perfectly.

Shadow Exponent also helps shifting some values related to shadow computition; 1.5-2.5 works the best for me.

Num cascades of 4 is the bare minimum that you should have to have acceptable quality. Increasing it to 5 helps the situation immensely, however, increasing it to 6 seems to make it worse. Setting it to anything to 7-10 doesn’t seem to make it any better, but the performance hit is greater.

Increasing the CSM max resolution obviously will make it consume more memory, and it’ll make the computition take some more time. Increasing directional num cascades has a minor performance hit.

Using TAA makes it a bit less noticeable as it’s making the whole image blurrier.

In case of TAA, you should be able to get away with 4 cascades, 4k distance and exponent 2.0-3.0.

In case of no AA, FXAA or CMAA2, you can go with a) 40000 distance, 5 cascades and exponent of 3 b) 4000 distance, 5 cascades and exponent of 1.5.

To permanently save CSM resolution, you would need to change your DefaultScalability.ini settings for each quality, for instance, to set it for Epic you do

[ShadowQuality@3]
r.Shadow.MaxResolution=4096

refer to this to see how to do that for other settings Scalability Reference for Unreal Engine | Unreal Engine 5.6 Documentation | Epic Developer Community.

You also might need to increase render target pool, as you might start getting this warning after increasing CSM max resolution

LogRenderTargetPool: Warning: r.RenderTargetPoolMin exceeded 653/400 MB (ok in editor, bad on fixed memory platform)

You would do that in the DefaultScalability.ini as well. It’s up to you to determine the value that fits your game.