我希望能够在 Three.js 中更新定向光上阴影贴图的大小。
当简单地更新“shadowMapWidth”和“shadowMapHeight”时,没有任何反应。当我手动更新“shadowMapSize”时,阴影会更改分辨率,但由于阴影贴图渲染目标未设置为正确的分辨率而无法正确渲染。最后,当我更新阴影贴图渲染目标宽度和高度时,阴影完全消失(和/或定位不正确)。
如果有人有在 Three.js 中更改阴影灯的阴影贴图分辨率的经验,我希望得到一些帮助来使其正常工作。
您必须处理阴影贴图才能更新。试试这个:
light.shadowMapWidth = 4096;
light.shadowMapHeight = 4096;
light.shadowMap.dispose();
light.shadowMap = null;
这就是解决方案:
// initialize
this.light = new THREE.DirectionalLight(0xffffff, 2);
this.light.shadow.mapSize.width = 1024;
this.light.shadow.mapSize.height = 1024;
this.light.shadow.camera.near = 0.1;
this.light.shadow.camera.far = 5000;
this.light.shadow.bias = 0.00001;
this.light.shadow.autoUpdate = true;
// update
this.light.shadow.dispose();
this.light.shadow = null;
this.light.shadow = new DirectionalLightShadow();
this.light.shadow.mapSize.width = 1024*4;
this.light.shadow.mapSize.height = 1024*4;
this.light.shadow.camera.near = 0.1;
this.light.shadow.camera.far = 5000;
this.light.shadow.bias = 0.00001;
this.light.shadow.autoUpdate = true;
您需要导入
三/src/lights/DirectionalLightShadow.js