How to correct normals on edge of procedurally generated chunks

Hi everyone I’m currently trying to solve a issue where my chunks are not seaming. I am fairly certain its the normals that I need to mess with. I tried to average the normals that are on the edge of the chunk to no avail.

Here is a picture of the issue that I am dealing with.

 public void CalculateNormals() {
        mesh.RecalculateNormals();
        Vector3[] newNormals = mesh.normals;

        if(map.CheckIfChunkIsSpawned(ChunkPosition - new Vector2(0,1)) && map.CheckIfChunkIsSpawned(ChunkPosition + new Vector2(0,1))) {
            Chunk BottomNeighboringChunk = map.GetChunk(ChunkPosition - new Vector2(0,1));
            Chunk TopNeighboringChunk = map.GetChunk(ChunkPosition + new Vector2(0,1));
            for(int i = 0; i<MapConfig.CHUNK_SIZE; i++) {
                Vector3 Normal = newNormals[i];
              
                Vector3 NewNorm = (Normal + BottomNeighboringChunk.mesh.normals[i + (MapConfig.CHUNK_SIZE*MapConfig.CHUNK_SIZE)]) / 2;

                newNormals[i] = NewNorm;

                Normal = newNormals[i + (MapConfig.CHUNK_SIZE*MapConfig.CHUNK_SIZE)];

                NewNorm = (Normal + TopNeighboringChunk.mesh.normals[i]) / 2;

                newNormals[i + (MapConfig.CHUNK_SIZE*MapConfig.CHUNK_SIZE)] = NewNorm;
            }
        }

        mesh.normals = newNormals;
    }

Here is the code that I use to generate normals. I am only attempting the bottom and top seams first for simplicity.

I think you need to make the shared vertices on a chunk boundary identical. That is, since two neighboring chunks will have two different vertices that are actually the same point on the mesh, you need to make sure that those two vertices have the same position and normal. My guess is that at the moment, you set one of the chunks normals first, and later when you process the neighboring chunk, you then average it with the already-averaged first chunk, making them have different normals.

1 Like

Looking closely at your graphic, I think it’s more than the normals. I think you might be either missing (or duplicating) a single row of triangles (or perhaps an entire row of vertices) between your chunks.

I base this observation on the appearance of slight lateral discontinuity in the iso lines, moreso than just normal lighting issues. But… the lighting could be playing tricks on my eyes. It just looks like more than lighting.

I see that too. I believe its the lighting at this angle since I am rounding each height value to a int instead of having floats for my height values.