所以我有一个 ThreeJS 场景,并且添加了一些球体(多材质)。我还添加了定向光:
this.light = new THREE.DirectionalLight( 0xFFFFFF, 1 );
this.light.position.set( 2, 10, 2 );
this.light.castShadow = true;
this.light.shadowMapSoft = true;
this.light.shadowCameraVisible = true;
this.light.shadowCameraNear = 1;
this.light.shadowCameraFar = 10;
this.light.shadowBias = 0.0009;
this.light.shadowDarkness = 0.3;
this.light.shadowMapWidth = 1024;
this.light.shadowMapHeight = 1024;
this.light.shadowCameraLeft = -8;
this.light.shadowCameraRight = 8;
this.light.shadowCameraTop = 8;
this.light.shadowCameraBottom = -8;
So when the user adds or removes spheres, a function which executes "reforms" the shadow camera frustum like this :
this.light.position.set( posV.x, posV.y, posV.z);
this.light.shadowCamera.far = l2*3;
this.light.shadowCamera.left = -l2;
this.light.shadowCamera.right = l2;
this.light.shadowCamera.bottom = -l2;
this.light.shadowCamera.top = l2;
this.light.shadowCamera.updateProjectionMatrix();
上面代码的可能结果是这样的:
an other aspect of the exact situation of above :
我已将相机的视锥体可见性设置为打开,所以它就在那里。问题是无缘无故产生的阴影(由红色箭头指出)。此时场景中没有其他物体,并且球体完全位于相机视锥体内。
更新球体(添加/删除)后,此类阴影问题很常见,有人对此有任何想法吗?
I use 三.js r72,
谢谢!