Search Unity

Question Why are there artifacts in my normals of my procedural mesh?

Discussion in 'General Graphics' started by Sezze, Jan 17, 2021.

  1. Sezze

    Sezze

    Joined:
    Dec 28, 2017
    Posts:
    4
    I generated a heightmap which I used to generate a terrain (using a custom mesh). There are however these artifacts in the shape of a grid in my normals.

    The mesh is divided into chunks, but those borders are not visible due to manual normal calculation, these grid patterns do not follow the mesh bounds. The artifacts are identical if I use mesh.RecalculateNormals() instead of doing it manually, only visible difference is the seam between meshes.

    This is also visible in lit shaders, when the lighting reacted oddly to the seams I thought it was an issue in my textures but this shows up in these unlit shaders only showing the normals.

    I'm using HDRP if that matters.

    This black and white image shows the y component of my (world) normal, ie. how much it's facing up. (In this case this is shown with an unlit shader with the value squared to exaggerate the artifact).

    I have also drawn in the scale, so the grids are about 8 units in size, and the approximate size of a quad is also drawn in. The size of a quad is exactly one by one units in size.


    In this lower picture it is just straight up the world-space normal shown as a color.
     
  2. Vockerodt

    Vockerodt

    Joined:
    Jan 8, 2022
    Posts:
    2
    Yea, I seem to be having the same issue at the moment.
    A possible reason is that the vertices between triangles are shared, but I think if the verts were not shared, then I would probably get flat shading instead of smooth shading. I haven't tried this yet as it would probably involve allot of re-writing.

    I am generating the mesh in the same way that Sebastian Lague does in his marching squares cave generation video if that helps at all.

    Here is my world space shaded mesh:
    NormalTerrainViewIssue.png

    When I decrease the octaves of my noise generator, the problem becomes even more obvious:
    NormalTerrainViewIssueOneOctave.png

    And a wireframe:
    NormalTerrainViewIssueOneOctaveWireFrame.png
     
  3. Vockerodt

    Vockerodt

    Joined:
    Jan 8, 2022
    Posts:
    2
    Ok, so I think I found the solution to this, at least for me.

    I generate my noise via a compute shader. The function inputs look like this:
    Code (CSharp):
    1.  
    2. for (int i =0; i < octaves; i++)
    3.     {
    4.         float n = snoise2D(position/noiseScale*frequency+offsets[i]);
    5.         noise += n * amplitude;
    6.         amplitude *= persistence;
    7.         frequency *= lacunarity;
    8.     }
    9.  
    I simply move the offsets so that they are affected by the noise scale:
    Code (CSharp):
    1.  
    2. for (int i =0; i < octaves; i++)
    3.     {
    4.         float n = snoise2D((position+offsets[i])/noiseScale*frequency);
    5.         noise += n * amplitude;
    6.         amplitude *= persistence;
    7.         frequency *= lacunarity;
    8.     }
    9.  
    Before: Before.png
    After:
    After.png
     
    Last edited: Feb 14, 2022