ThreeJS 中阴影的奇怪行为

2024-05-18

所以我有一个 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 : enter image description here

    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 : enter image description here

我已将相机的视锥体可见性设置为打开,所以它就在那里。问题是无缘无故产生的阴影(由红色箭头指出)。此时场景中没有其他物体,并且球体完全位于相机视锥体内。

更新球体(添加/删除)后,此类阴影问题很常见,有人对此有任何想法吗?

I use 三.js r72, 谢谢!


根据您的评论,您看到的是自阴影伪影。

您需要调整shadowBias(现在称为shadow.bias) 范围。

改变阴影偏差会导致“彼得潘宁 https://msdn.microsoft.com/en-us/library/windows/desktop/ee416324(v=vs.85).aspx“(太多的积极偏见)和自我阴影伪影(太多的消极偏见)。

三.js r.73

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ThreeJS 中阴影的奇怪行为 的相关文章

随机推荐