I’ve been trying to add shadows to my huge terrain. I’ve been thinking it would be best to add the shadow to the camera so while to camera moves around the shadows are only rendered for whats within the view of the camera.
Here is my attempt:
let root = new THREE.Group(); root.add(camera); root.position.set(-3500, 50, -7800); // edge of terrain at -20000, 0, -20000 scene.add(root); let light = new THREE.DirectionalLight(0xfffffff, 0.5); light.position.set(0, 1, 0); light.castShadow = true; light.shadow.mapSize.width = 512; light.shadow.mapSize.height = 512; light.shadow.camera.near = 0.5; light.shadow.camera.far = 500 scene.add(new THREE.CameraHelper(light.shadow.camera)); scene.add(light); root.add(light.shadow.camera);
I also did not forget to enable receiveShadows on the terrain and castShadows on the objects on the terrain.
But I only get this:
The shadow camera seems too small. But, if I make the map size beyond 4096, it just slows everything down.
What are my options here? I wanted to have soft shadows from a little angle from the top as if its around afternoon.