Hi there, recently I found camera FOV change would cause apparent CSM shadow flickering in my project, I’m searching for the solution and I would like anyone interested to give some suggestions or oppinions.
- I set
r.Shadow.MaxCSMResolution
to 1024 for the sake of performance (by defaut it’s 2048)
- I test with CameraShake in game and just scrubbing preview camera FOV in editor, and both of them cause this flickering.
- I test in Unreal 5.0, 5.1, 5.2 and found the same problem in all these releases.
After further searching and digging in source code, I found this problem is probably that infamous ‘Shadow edge shimmering’ which is caused by camera movement when shadow frustum follows the movement of main frustum. - This problem can be improved by increasing MaxCSMResolution, but it still appears occasionally.
It seems Unreal has done something to resolve this problem in ShadowSetup.cpp
PreShadowTranslation
is actually the center location vector of current shadow cascade, what these codes above did is to snap this Translation to nearest texel (of shadow depth rendertarget), to remove any sub-texel projection during ShadowDepthVS.
I like this trick here very much, and it managed to remove shadow flickering in camera translation and rotation, as the comments said above. But it doesn’t maintain stable shadows in camera FOV changes, which is the tricky part. I think maybe it’s because ‘Texel size’ also changes with FOV, and it ‘couples’ with changes of PreShadowTranslation
to create new sub-texel moves during projection in ShadowDepthVS, and as I said above, this sub-texel moves can be reduced by increasing CSMResolution.