gpt4 book ai didi

Three.js 平面不转换阴影

转载 作者:行者123 更新时间:2023-12-02 19:45:36 25 4
gpt4 key购买 nike

我将一个平面和一个球体堆叠在一个更大的平面上,如下图所示

enter image description here

从 WebGL 检查器来看,似乎所有三个对象都绘制在阴影贴图中,但只有球体有效地出现在阴影贴图中,导致较小的平面永远不会在较大的平面上转换阴影

这里是场景搭建

renderer.shadowMap.enabled = true

camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 5000);
camera.position.z = 600;
window.controls = new THREE.OrbitControls(camera, renderer.domElement);


light = new THREE.SpotLight(0xffffff, 1, 0, Math.PI / 2);
light.position.set(1, 1000, 1);
light.castShadow = true;
light.shadow = new THREE.LightShadow(new THREE.PerspectiveCamera(50, 1, 1, 5000));

scene.add(light);

var planeGeometry = new THREE.PlaneGeometry( innerWidth * 0.5, innerHeight * 0.5, 10, 10);
var plane = new THREE.Mesh( planeGeometry, new THREE.MeshPhongMaterial({ color: 0xffcccc }));
plane.rotation.x = -Math.PI / 2;
plane.castShadow = true;
plane.receiveShadow = true;
scene.add(plane);


var sphere = new THREE.SphereGeometry(100, 16, 8);
var spheremesh = new THREE.Mesh(sphere, new THREE.MeshPhongMaterial( ));
spheremesh.position.y = 200;
spheremesh.castShadow = true;
spheremesh.receiveShadow = true;
scene.add(spheremesh);

var planeGeometry1 = new THREE.PlaneGeometry( innerWidth, innerHeight, 10, 10);
var plane1 = new THREE.Mesh( planeGeometry1, new THREE.MeshPhongMaterial( ));
plane1.position.y = -250;
plane1.rotation.x = -Math.PI / 2;
plane1.castShadow = true;
plane1.receiveShadow = true;
scene.add(plane1);

最佳答案

默认情况下,Three.js 在生成阴影贴图时会剔除正面。

这意味着只有背面(从光的角度来看)会转换阴影。剔除飞机的正面不会留下任何可以转换阴影的东西。

因此,一种选择是用具有深度的薄 BoxGeometry 替换 PlaneGeometry

第二个选项是设置

material.shadowSide = THREE.DoubleSide;

在这种情况下,您的飞机将转换阴影,但可能会出现自阴影伪影,因为您同时具有 plane.castShadow = trueplane.receiveShadow = true.

通常,第一个选项是最佳选择。

三.js r.151

关于Three.js 平面不转换阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44989568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com