Hello,

A piece of a project i’m working on involves generating the mesh of some arbitrary shape, i finished the code that generates the mesh for said shapes earlier today and it worked great . However, after i removed the redundant vertices, it seems to have enabled some sort of smoothing effect that makes everything look absolutely awful, flat faces composing of more than one triangle no longer look flat because the shape of each individual triangle is shaded into the object.

see here: Imgur: The magic of the Internet

I’m pretty sure i know what’s happening, its interpolating the surface normal to match the vertices smoothly throughout each triangle, this would be great if i was making a smoother object but my shapes are very rigid and smooth shading looks atrocious on them.

I’ve done some reading but the only solutions i’ve found are give each triangle its own 3 vertices which is the exact opposite of the optimization i’ve done, or make a shader, if i have to ill figure out how to do that but is there really not some checkbox i can uncheck to tell the GPU to not worry about normal interpolation? I mean flat shading is less GPU intensive anyway, i can understand it not being the default but is there not a built in option for this?

Hi there. I’m afraid the simple answer is that you have to have the extra vertices! It’s the vertices that have normals, so for 2 triangles with a corner at the same location to have different normals, they will need to have different vertices.

Another way of looking at it is that your definition of ‘redundant vertex’ sounds like it only takes into account position. However for the visuals to remain correct, a vertex is only redundant if all it’s properties match those of another.

 And incidently, and perhaps surprisingly ‘flat shading’ is not less intensive. Rasterizers all work by calculating the properties of a pixel on a triangle using a barycentric interpolation of the corresponding properties on the triangle’s vertices. To avoid this, you’d have to write some pretty funky stuff to store a normal per triangle in a separate buffer and read it in the pixel shader.