【发布时间】:2021-11-27 05:32:32
【问题描述】:
我有一个巨大的飞机用作地面,我有一个定向光作为太阳光。
问题是,这个 directionalLight 不能在整个平面上投射阴影,所以我决定让 directionalLight 的阴影相机跟随主 PerspectiveCamera。
所以,这是我的代码:
camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
lightCameraConstant = 40;
dirLight = new THREE.DirectionalLight( 0xffffff, 1 );
dirLight.color.setHSL( 0.1, 0.5, 1 );
dirLight.position.set( 1500, 2000, 1500 );
dirLight.castShadow = true;
dirLight.shadow.mapSize.width = 4096;
dirLight.shadow.mapSize.height = 4096;
dirLight.shadow.camera.left = -lightCameraConstant;
dirLight.shadow.camera.right = lightCameraConstant;
dirLight.shadow.camera.top = lightCameraConstant;
dirLight.shadow.camera.bottom = -lightCameraConstant;
dirLight.shadow.camera.far = 3000;
dirLight.shadow.camera.near = 0.01;
dirLight.shadow.bias = -0.0001;
scene.add( dirLight );
var helper = new THREE.CameraHelper( dirLight.shadow.camera );
scene.add( helper );
然后在动画功能中我使用以下内容:
dirLight.shadow.camera.position.x = camera.position.x;
helper.update();
但这不起作用,阴影相机根本没有改变它的位置。
1- 如何在不改变 directionalLight 位置的情况下改变阴影相机位置?
2- 有什么方法可以在不使用疯狂资源的情况下覆盖大面积的阴影?
【问题讨论】:
-
正如 Marquizzo 下面所说,(2) 是一个广泛的问题,更适合 discourse.threejs.org。如果可以在 Stack Overflow 答案中简洁有力地解决它,那么该解决方案将内置到 three.js 中。
标签: three.js