Hello, I have a basic scene with two MeshStandardMaterials, and I’m using noise to displace the vertices. I have lighting and shadows enabled, but I can’t seem to get uniform lighting to work between the two meshes.: Here is my code
Try to calculate normal vectors by yourself, instead of using computeVertexNormals
:
function addNoise(quad){
const v = new THREE.Vector3(); // create once
const u = new THREE.Vector3(); // create once
const w = new THREE.Vector3(); // create once
for (let i = 0; i < quad.geometry.attributes.position.count; i++) {
v.fromBufferAttribute(quad.geometry.attributes.position, i);
quad.localToWorld( v );
u.copy(v);
w.copy(v);
v.z = noise3D(v.x/3,v.y/3,v.z/3);
quad.geometry.attributes.position.setZ(i,v.z )
u.x += 0.1;
u.z = noise3D(u.x/3,u.y/3,u.z/3);
w.y += 0.1;
w.z = noise3D(w.x/3,w.y/3,w.z/3);
u.sub(v).cross(w.sub(v)).normalize();
quad.geometry.attributes.normal.setXYZ(i,u.x,u.y,u.z)
}
quad.geometry.attributes.position.needsUpdate = true
quad.geometry.attributes.normal.needsUpdate = true
}
1 Like