Creating a Shadow Caching solution

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!

  1. Throw it in an empty project using legacy deferred rendering pipeline & linear color space
  2. Open Scene and play
  3. Move sphere with [WASD]
  4. 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?

7028881–832816–ShadowCaching.unitypackage (229 KB)

1 Like

Hi there! This would be EXTREMELY useful to have for my project as well. The project is far in, with a heavy reliance on real-time lights and shadows, I’ve done what I can to mitigate the performance impact but I’ve been dying for a proper built-in RP deferred shadow caching solution forever now.

Were you ever able to make progress on this?

Doesn’t static shadow caster on the mesh renderer does exactly this? (only hdrp I guess)