Is it possible to manually set the origin of shadow cascades

I am prototyping a game that makes heavy use of telescopic sights. For the sake of visual fidelity, I would like realtime shadows to sometimes be visible at extreme ranges; so that the player has a good view of the environment when using a scope. My current implementation simply multiplies the maximum shadow range by the magnification factor of the current scope, and it does the job.




This works great, but only when the camera is still. When the camera moves, shadows in the distance flicker and flash. I suspect this is a precision thing that can’t be solved without the brute force of a beefy computer. (If I’m wrong about this assumption, please let me know. I’d love a solution that doesn’t involve messing with backend systems)

With that established, I’m wondering if its possible to provide whatever part of unity handles shadows with, say, a point in 3d space from a raycast; and then have the shadow cascades expand out from that point, instead of the active main camera?

This is only what I infer would be the best solution to high precision realtime shadows at a distance. If there’s a better way to get a similar effect, I would be equally appreciative of a nudge towards it.
Thanks in advance

This is happening because the cascades are based on the position of the camera. When you use the low FOV to simulate the scope, you’re “zooming in” but the camera position isn’t changing. There are a few ways to address this:

  1. bake the shadows in (I don’t like this because it’s time consuming and harder to maintain, but it’s an option)
  2. switch to a camera that is actually closer for the zoom view
  3. adjust the shadow settings on the fly at runtime. You can adjust Shadow Distance to change the shadows – larger distance means they’ll draw farther, but at lower res. This can be a good strat to employ combined with other things; if you do it when swapping views or cameras it can be seamless.
  4. use a post processing effect to draw fake shadows with rays. Have a look at the built-in UnityShadowLibrary.cginc and Internal-ScreenSpaceShadows.shader for a foundation to start with. Basically, calculate the angle of the directional light against the world normal of the objects in scene and color in shadows where they ought to be yourself. You can view those included shaders by going to where your version of Unity is installed in program files or by downloading a separate copy here Download Archive