Hello, so since shadows are tough on the CPU, I would like to consider the option of not updating them every frame, so basically on enable or on demand. However, when I Select any of those 2 options, there is very strange shadow deformation from my cameraview, I’ve tweaked every little shadow option and it’s always there, can’t figure out what’s causing it. I’ll post pics.
Shadows Update Mode Every Frame:
If it’s directional light, the shadow needs to be calculating every frame if the camera is moving. Because the camera that captures the depth information to calculate the shadow moves with the main camera.
Yeah this is weird thing been there forever. But I’d suggest writing script to update shadows every 0.1 second or more. Drastically improves performance
I see, so it’s not possible to use the Enable/Demand mode without those weird deformations. The best case then indeed would be updating shadows every X seconds via script for performance. Actually the On Demand mode is waiting for input from a script right.
For most (or some) AAA titled game, they change the shadow update frequency depend on cascade. They update the shadow in cascade 0 every frame and decrease the update frequency if cascade level is increase. For example, update every 2 frames on cascade 1, every 4 frames in cascade 2, etc.
That indeed sounds like smart optimization and high quality shadows. I’m probably fine either way as long as shadows dont update every frame, really drops FPS a lot, like 90 to 70. I’m a just a bit afraid when I put zombies in my scene, tris count will jump by a lot and fps will drop below 60.
The overall issue with the “on demand” style update for directional light shadow maps, is that they are completely view dependent. We had another long thread here a while back when we thought there was some bug with the new mixed cached shadow support for directional lights, but it turned out it was not a bug but rather just the fact that these shadow maps are view dependent and need to be updated quite frequently…
Now, if you update the entire directional light shadow map on demand once every few frames, the issue is that you will still get jittery updates for dynamic objects walking around in camera view.
So the way I deal with this now is as follows:
Set the shadows to on demand.
Enable the “always draw dynamic” box or whatever its called. This will update the shadow map every frame, but only for dynamic objects like the characters walking around etc.
Now that leaves the static stuff - what I do is update one cascade per frame. In my opinion this is better than just doing no update at all, and then suddenly doing a full shadow map update (all cascades) every X frames. This approach causes a mild spike which I dislike.
To update one cascade per frame, you can use HDAdditionalLightData.RequestSubShadowMapRendering().
Sounds good. I shall try few of these methods to see what works best for me in the near future.
So each frame you update one shadowmap and you pass indexes HDAdditionalLightData.RequestSubShadowMapRendering(1)
HDAdditionalLightData.RequestSubShadowMapRendering(2) etc. ? depending on how many shadow maps the light supports.
So in that case, directional lights should have 4 shadows maps(cascades) and it would gives us x4 performance compared to updating everything every frame.
Wait if I remember correctly your game uses day/night cycle, right? Is that how you actually manage to do all of that, or it’s just for static lighting involving dynamic objects like characters?
All the lighting is dynamic. The sunlight moves dynamically but slowly. Most of the environment is static, but some of the environment is dynamic (characters, foliage, etc).
The dynamic shadow maps for the directional light is updated every frame.
The on-demand shadow maps (static objects) for the direction light is updated one cascade per frame. This is frequent enough to avoid any issues due to movement of the camera (it is not so much the movement of the sunlight that is an issue, but rather the camera).