How do I fit the camera frustum inside directional light space?

In an open world, the camra postion can move anywhere, and the directional light can be changed anytime. So how can I adjust the shadow map camera to fix the current view.
Is there some examples?

Performance/quality wise, it’s not possible. Unless you use “tricks” but none of them use native real-time directional light

Personally, I’m using a dummy new THREE.Object3D(); as target for my light position and camera. Then in the render loop, I move them accordingly to user’s position. Shadow map size use fixed values, wich prevent performance issue. I use fog, or custom shaders to hide the shadows limits.
Static/far shadows are pre-rendered using a THREE.WebGLRenderTarget then added to the final terrain texture. Objects are baked with some fake top-light. It’s all tricks and shenanigans…

just in case someone try this, changing a directional light’s target require additional update:;;

In a game engine like UE or Unity, Shadow of sun can be updated every frame. We can move the shadow camera and modify some properties to fit the current view, the shadow near camera will be more accurate, that’s what I need.

This is exactly the idea behind Cascaded shadow maps (CSMs): by combining a set of them, it provides higher resolution of shadows near the camera and lower resolution far away. This is usually the case for large terrains and sun (single point-like) illumination.

You can try this implementation for Three.js, and the already shiped official example here

1 Like