1. three.js中使用CameraHelper来可视化调整阴影相机的范围
光源
const directionLight = new THREE.DirectionalLight(0xffffff, 1);
directionLight.position.set(100, 60, 20);
directionLight.castShadow = true;
scene.add(directionLight);
设置计算阴影的范围
directionLight.shadow.camera.left =
directionLight.shadow.camera.top =
directionLight.shadow.camera.bottom =
directionLight.shadow.camera.right =
directionLight.shadow.camera.near =
directionLight.shadow.camera.far =
有时候我们很难,调整好这个对应的数值,不过现在可以通过 CameraHelper来可视化调整这个阴影相机了
const cameraHelper = new THREE.CameraHelper(directionLight.shadow.camera);
scene.add(cameraHelper);
原则: 根据3D场景渲染范围,去设置.shadow.camera长方体的尺寸参数,一般要比渲染范围稍微大一些即可,过小阴影会导致不显示或者不完整,过大很大可能导致阴影模糊