【问题标题】:Update position of shadow camera in render loop在渲染循环中更新阴影相机的位置
【发布时间】:2018-03-13 00:42:31
【问题描述】:

我正在尝试将定向光影相机的位置设置为与渲染循环中的主透视相机相同:

sunlight = new THREE.DirectionalLight(0xffffff, 1);
sunlight.position.x = camera.position.x ;
sunlight.position.y = 300;
sunlight.position.z = camera.position.z ;from top
sunlight.castShadow = true;

sunlight.shadow.mapSize.width = 2048 ;
sunlight.shadow.mapSize.height = 2048 ;
sunlight.shadow.bias = -0.0027;

sunlight.shadow.camera.left = -75;
sunlight.shadow.camera.right = 75;
sunlight.shadow.camera.top = 75;
sunlight.shadow.camera.bottom = -75;
sunlight.shadow.camera.position = camera.position;

sunlight.shadow.camera.far = sunlight.position.distanceTo(scene.position) + 20;
sunlight.shadow.camera.near = sunlight.position.distanceTo(scene.position) - (camera.position.y * 2);

sunlight.shadow.camera.updateProjectionMatrix();


function render() {
    renderer.render(scene, camera);

    sunlight.shadow.camera.position = camera.position;
    sunlight.shadow.camera.updateProjectionMatrix();
}

然而,影子摄像机根本不动。是否可以在运行时更新阴影相机的位置?

【问题讨论】:

    标签: three.js camera shadow


    【解决方案1】:

    shadow.camera 更像是阳光的内部组件。

    移动阳光使其跟随相机的方式更像是这样:

    sunlight.position.copy( camera.position );
    sunlight.target.copy( camera.position );
    sunlight.position.y += 20;
    

    这个 ^ 应该使阳光停留在相机上方,指向下方,距离为 20 个单位。

    此外,您的 shadow.camera.near / far 设置看起来有点奇怪。

    我只是将它们设置为类似

    light.shadow.camera.near = 0.5;
    light.shadow.camera.far = 50.0;
    

    ..或类似的东西。

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 2013-07-06
      • 2015-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多