How to avoid this 'shading'?

Hey, I’m generating a procedural mesh, and sometimes I have this weird looking shadings, any ideas how to avoid/fix it?

The material is fully default: new pc.StandardMaterial();

How do you calculate normals?

this.mesh.setNormals(pc.calculateNormals(positions, indexArray));

Hmm, not sure. I don’t see that in my procedural meshes. Perhaps you could make a small example that shows it?

https://playcanvas.com/editor/scene/1878133

I’d rather have it flat/low poly than this :thinking:

Hmm, not sure. Perhaps due to the size? I think this mesh instance is 100m x 100m. Ping @mvaligursky


1 Like

The problem is pretty low resolution … per vertex interpolation of normals does not create very smooth looking normals and so you get the variation. Increasing that to 500 makes it very smooth.

Other suspect is your mesh generation, are the vertices getting shared correctly? When you generate index buffer, you get 6 unique indices (corner A … F), but you should only have 4, two would be shared - this might not smooth the normals when those are generated if some vertices are not fully connected to all faces around it.

1 Like

without increasing resolution, what would be the proper way for generating 4 indices instead of 6, what do i need to change? it’s been a while since i’ve used mesh api

You need to update the math a bit. Just imagine visually 4 vertices forming a quad using 2 triangles. Those 2 triangles will share 2 vertices (or 1 edge). So you need 4 vertices to describe 2 triangles. If you have 6 vertices (as you seem to have now), the triangles will not be connected (even though visually they will).

1 Like