- Home /
Do i have to use shared vertices if i want my proceduraly generated mesh to look smooth?
I made a procedurally generated island and it came out looking like this to generate this mesh each face here has it's own unique vertices, so do i have to use shared vertices if i want a decent smooth looking terrain?
Answer by Bunny83 · Jul 17, 2020 at 03:35 PM
No, you don't have to use shared vertices. However having them seperate when it's not necessary just create additional problems. First of all when every triangle has its own vertices using RecalculateNormals is pretty pointless since it will make every triangle flatshaded. So if you want the mesh to look smooth, you have to manually calculate the normal vectors for each vertex. Of course in order for the mesh to look smooth, all vertices which essentially belong to the same vertex position have to have the exact same normal vector. If they don't, the mesh wouldn't look smooth.
If you want to know how to calculate the shared normal, just have a look at this question.
That completly makes sense i should of thought about it instead of trusting the recalculatenormals methode, now i'll just have to figure out how to calculate those normals thank you
Well as you can read in my linked answer the calculation itself isn't really difficult. The main issue is to figure out which vertices belong together. Since your mesh looks like it's a regular quad grid in the x-z-plane you should be able to figure out which vertices belong together just by looking at their indices. Of course this requires information about how you actually generated / laid out the vertices in the vertices array.
If each triangle has it's own 3 vertices and the diagonal cut through the "quads" is always oriented the same way you should have exactly 6 vertices at one location. Of course there are literally "edge" cases at the edges / corners where there are only 3, 2 or 1 vertices. Every outer edge vertex has 3 vertices. The corners can have 2 or 1 vertices.
Since you need each triangle flat surface normal in order to combine them you could still call RecalculateNormals and after that you just do the combining.
what would be better, to recalculate normals manually or have shared vertices?
Well, if the whole mesh should have smooth normals everywhere of course using shared vertices is better and faster ^^. With shared vertices you would only need about 1/6 of the vertices.
Though I simply assumed that, for some reason, you want to have the triangles seperated. $$anonymous$$aybe because of texturing or you want to carve holes in later. If you don't have any of those specific needs using shared vertices is much simpler and more memory friendly ^^.
Note that by "texturing" I was talking about specific texturing needs. Of course a shared mesh can still be textured. However it's essentially just one big subdivided quad.
yeah i think i'll just use shared vertices for now and if i find out i need to use unique vertices then i'll go ahead and recalculate normals