Search Unity

Discussion Shared vertices for terrain mesh

Discussion in 'General Graphics' started by heu3becteh, Dec 7, 2022.

  1. heu3becteh

    heu3becteh

    Joined:
    Aug 6, 2020
    Posts:
    25
    I have a procedural terrain mesh with many vetrices and triangles, using four triangles per quad (how excessive that is, by the way?), with middle one having mean height of four aruond it to prevent "saw" effect on some ridges.
    upload_2022-12-7_20-19-7.png

    Initially I have wanted to make low-poly voxel-like mesh, possibly with greedy meshing, but that was too memory-expensive. I also had one whole mesh of 200x200 quads as a prototype, so I had to change 16-bit to 32-bit format (proceduralTerrainMesh.indexFormat = IndexFormat.UInt32;).
    In this case shared vertices looked strange, and this mesh needed to be sharp anyway, also unique vertices with sharp normals are more convenient to divide into several mesh instances, allowing for culling and 16-bit index format.

    With shared vertices:
    upload_2022-12-7_20-20-2.png
    With unique vertices:
    upload_2022-12-7_20-20-8.png

    In this case there is no question that shared vertices are no good, I guess.

    As this approach was too expensive, I decided to have bigger quads, smooth mesh.
    But in this case on the contrary shared vertices look better.

    With unique vertices:
    upload_2022-12-7_20-20-29.png
    With shared vertices:
    upload_2022-12-7_20-20-35.png

    But in this case I guess there would be a problem to divide this mesh into pieces, a juncture will be visible?
    How is it better to proceed?
    Is it a good practice to have shared vertices on the terrain mesh?
    I guess for a smooth mesh it would make sense to use two triangles per quad too.

    Best regards.
     
  2. heu3becteh

    heu3becteh

    Joined:
    Aug 6, 2020
    Posts:
    25
    So I did divide my single mesh into separate smaller ones, and I have visible seams, as expected.
    upload_2022-12-10_18-10-35.png
    I did try to make similar normals for individual meshes at the borders, but the seams stand out anyway...

    There is an option to have unique vertices, then these seams will not stand out as much, as they will be everywhere X)
    upload_2022-12-10_18-10-48.png
    Maybe there is a way to make this mesh appear smooth as whole?

    For now I sort of like the stylized look of mesh with upward normals, maybe I will go with that.
    upload_2022-12-10_18-10-57.png

    Also it is possible to just use single mesh, even though there will be no culling and maybe 32-bit format for larger scenes...
    upload_2022-12-10_18-11-4.png
     
  3. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    731
    there shouldn't be seams if you did the normals correct. The better way is to just sample the normals from a normal texture in your fragment shader. This is how the default unity terrain works when gpu instancing is enabled on the terrain. Also, why not just use the built in terrain system?
     
  4. heu3becteh

    heu3becteh

    Joined:
    Aug 6, 2020
    Posts:
    25
    Thank you for the reply.

    Which way the normals are correct? If vertices are shared, maybe the normal direction for the vertices at the seam should be averaged between meshes?
    In a sense normals are more correct with unique vertices, when the normals for all the vetrices of triangle are facing the same way as the face. That way there are no "seams", but the resulting mesh is not "smooth".

    I did not quite get the part about sampling from normal texture... I believe I do not have a normal texture?

    Regarding the terrain system - I do not use it because I feel there is more control over meshes, their generation works with DOTS/ECS, Entity instances of these meshes should have a good performance.
    I do not know terrain system good enough to determine will I be able to procedurally control it the same way or better.