Search Unity

Question Procedural terrain generation with sharp edges (normals problem)

Discussion in 'World Building' started by MrMates, Dec 31, 2020.

  1. MrMates

    MrMates

    Joined:
    Sep 7, 2019
    Posts:
    1
    Hello,

    I am generating terrain for my game and I bumped into a problem with normals.

    I can generate terrain just fine, but the thing is that I'm aiming for a certain artstyle and I want sharp edges on my terrain. I'm using diamond square algorithm implemenation for heightmap based on int values and it's all working well, I get my vertices with correct coordinates and mesh renders fine.

    The problem is with lighting/normals. If I use the mesh.RecalculateNormals(), Unity automatically smoothes out my terrain obviously, cause I only have one vertex for each point. It results into this blob of nothing.


    So I decided to double up on my vertex count so Unity would actually make the desired sharp edges and adjusted the triangles accordingly, so no vertex is used twice. That kind of helped and I finally have the sharp edges, however another problem appeared.

    Each quad looks like the triangles are shaded in kind of inverted fashion or something. I even visualized the normals and they seem fine (I think?)


    So my question is:
    Any ideas on how to fix this? Or maybe another way to get the sharp edges without doubling up the vertices?

    Thank you
     
  2. ElicaIWD

    ElicaIWD

    Joined:
    Sep 12, 2017
    Posts:
    2
    Old post but I thought I may as well answer for any other wanderers.
    I think that you have probably assigned the wrong set of vertices to your triangles (not the ones with the correct normals for that triangle).