【问题标题】:Three JS shadow bug?三 JS 影子 bug?
【发布时间】:2018-08-11 16:30:07
【问题描述】:

我试图使用简单的定向光和阴影材质来创建阴影,问题是阴影似乎可以正常工作,在一个盒子里,当模型超出该区域时它就消失了???

image of the shadow at the bounds

代码如下:

var light = new THREE.DirectionalLight(0xffffff, 0);
renderer.shadowMap.enabled = true;
light.position.x = 100;
light.position.y = 150;
light.position.z = 0;
light.castShadow = true;
scene.add(light);

plane.receiveShadow = true;
plane.material = new THREE.ShadowMaterial({color: 0, opacity:1});

【问题讨论】:

标签: three.js 3d light shadows


【解决方案1】:

您必须配置DirectionalLight 的内部阴影相机才能获得正确的阴影。使用以下example 作为您自己的代码的模板。重要的部分是:

var d = 5;
directionalLight.castShadow = true;
directionalLight.shadow.camera.left = - d;
directionalLight.shadow.camera.right = d;
directionalLight.shadow.camera.top = d;
directionalLight.shadow.camera.bottom = - d;

directionalLight.shadow.camera.near = 1;
directionalLight.shadow.camera.far = 20;

此配置决定了场景的哪个部分将通过定向光创建和接收阴影。请注意将截锥体设置得尽可能紧,以获得清晰的结果。

【讨论】:

  • 好的,这确实控制了区域的宽度,但它改变了阴影的质量,正如你所说,那么,有没有办法防止这种质量损失 & 使阴影遍布场景?
  • 这很棘手。您可以尝试提高阴影贴图的分辨率,但这只能在一定程度上起作用。在某些情况下,您可以尝试移动定向光,使阴影始终出现在焦点区域(例如玩家在地图上的位置)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-08
  • 2021-08-16
  • 1970-01-01
  • 2012-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多