我目前正在为我的场景使用定向照明。一个小角色可以四处走动。所有阴影都有效。但是,如果我开始对头像走得更远一点,阴影就不再适用了。我认为它可能来自光线的角度,但我无法改变它。我可以在阴影/非阴影区域周围画一个正方形。
这是我的代码。巨大的数字在这里让我测试事物
const dirLight = new THREE.DirectionalLight( 0xffffff, 1 );
dirLight.color.setHSL( 0.1, 1, 0.95 );
dirLight.position.set( - 1, 1.75, 1 );
dirLight.position.multiplyScalar( 30 );
dirLight.distance = 1200;
dirLight.focus = 1200;
dirLight.angle = Math.PI / 1;
scene.add( dirLight );
dirLight.castShadow = true;
dirLight.shadow.mapSize.width = 2048;
dirLight.shadow.mapSize.height = 2048;
const d = 100;
dirLight.shadow.camera.left = - d;
dirLight.shadow.camera.right = d;
dirLight.shadow.camera.top = d;
dirLight.shadow.camera.bottom = - d;
dirLight.shadow.camera.far = 35000;
dirLight.shadow.bias = - 0;
const dirLightHelper = new THREE.DirectionalLightHelper( dirLight, 10 );
scene.add( dirLightHelper );
这是接收阴影的地面代码
const groundGeo = new THREE.PlaneBufferGeometry( 10000, 10000 );
const groundMat = new THREE.MeshLambertMaterial( { color: 0xffffff } );
groundMat.color.setHSL( 0.095, 1, 0.75 );
const ground = new THREE.Mesh( groundGeo, groundMat );
ground.position.y = - 33;
ground.rotation.x = - Math.PI / 2;
ground.receiveShadow = true;
scene.add( ground );
我在 flamingo https://threejs.org/examples/?q=light#webgl_lights_hemisphere中重用了 ThreeJS 示例提供的大部分代码
这也是一个 imgur 的链接,我只是放了一些图片来查看阴影 https://imgur.com/a/MGrc5cw
谢谢