简体   繁体   English

threejs中3d对象上的神器

[英]Artifact on 3d objects in threejs

Whenever I add a narrow 3d object like the one below to the scene, I encounter some unwanted artifacts like a repeating texture on the object's surface.每当我向场景中添加如下所示的窄 3d object 时,我都会遇到一些不需要的伪像,例如对象表面上的重复纹理。 It worth mentioning that everything looks fine until I switch the receive shadow property of the object to true.值得一提的是,在我将 object 的 receive shadow 属性切换为 true 之前,一切看起来都很好。

在此处输入图像描述

to be more precise, I created a box geometry with the size of (0.35, 0.02, 0.15) then I made a MeshStandardMaterial and feed both geometry and material to a THREE.Mesh.更准确地说,我创建了一个大小为 (0.35, 0.02, 0.15) 的长方体几何体,然后我制作了一个 MeshStandardMaterial 并将几何体和材料都提供给 THREE.Mesh。 the lightning consists of ambient light and a directional light闪电由环境光和定向光组成

ideally, the object should look like this:理想情况下,object 应如下所示: 在此处输入图像描述

Here is the code for lightning, object, and material这里是闪电代码,object,还有素材

let ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
let directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
directionalLight.castShadow = true;
this.directionalLight.position.set(-20, 20, 32);

scene.add(this.ambientLight);
scene.add(this.directionalLight);

let box = new THREE.BoxGeometry(0.02, 0.15, 
0.35)
let material = new THREE.MeshStandardMaterial({color: 'white', 
shadowSide: THREE.FrontSide, side: THREE.DoubleSide})
let mesh = new THREE.Mesh(box, material)
mesh.receiveshadow = true
mesh.castshadow = true

scene.add(mesh)

This is known as shadow acne.这被称为阴影痤疮。 It happens when light hits a surface at a shallow angle.当光线以较小的角度照射表面时,就会发生这种情况。 You'll probably need to make small modifications to the LightShadow.bias property .您可能需要对LightShadow.bias属性进行小幅修改。 Quoting from the documentation:引用文档:

Shadow map bias, how much to add or subtract from the normalized depth when deciding whether a surface is in shadow. Shadow map 偏差,在决定表面是否处于阴影中时从归一化深度增加或减少多少。 The default is 0. Very tiny adjustments here (in the order of 0.0001) may help reduce artifacts in shadows.默认值为 0。此处非常微小的调整(大约 0.0001)可能有助于减少阴影中的伪影。

Try something like: directionalLight.shadow.bias = 0.0001;尝试类似的东西: directionalLight.shadow.bias = 0.0001; and start from there, making small adjustments until the shadow acne isn't noticeable.然后从那里开始,进行小幅调整,直到阴影痤疮不明显为止。

There's also a second parameter named LightShadow.normalBias that you could tweak.还有一个名为LightShadow.normalBias的第二个参数,您可以对其进行调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM