We’ve tried to create a shadow caching solution for our project (which uses legacy deferred rendering), which you can also check out in the attached demo!
- Throw it in an empty project using legacy deferred rendering pipeline & linear color space
- Open Scene and play
- Move sphere with [WASD]
- Toggle shadow caching with
In this demo the shadows of the static boxes are rendered only once, and then stored in a cache. After that only dynamic shadows need to be rendered each frame, which can potentially save a lot of shadow batches from being drawn. In the demo shadow casters drop from 105 to only 6!
[IMG]https://i.ibb.co/wrJ6KYc/shadowcaching.png[/IMG]
*However...*
We got it working in this small demo, but as soon as we try to implement it in a larger scene we start seeing glitches. You see, we need to be able to disable shadow casting for static geometry for non-moving lights. But, as you might know, lights have no LayerMask for shadowing. So we tried using Light.lightShadowCasterMode, which can disable shadow casting for lightmapped objects, which was good enough for us!
*Or so we thought...*
According to the documentation this shadow caster mode is "Incompatible with the legacy renderers" and sure enough, in larger scenes lightShadowCasterMode has unpredictable behaviour. It only appears to work on some lights, and not on others.
[URL]https://docs.unity3d.com/ScriptReference/Light-lightShadowCasterMode.html[/URL]
And this is also where we ran out of ideas.
Does anyone else have any solutions *without* using Light.lightShadowCasterMode?