Fixing seams between adjacent terrain quads


how can I fix seams between adjacent terrain quads?
I’m working on a custom terrain editor and when I place two TerrainQuad objects next to each other there is something wrong with the normals, even if their edge vertices have the same location coordinates (except for straight upwards facing normals of flat surfaces).

Here is an image showing the issue:
Terrain Seams Issue

I put the ShowNormals material on it to better illustrate the problem. I think there must be something wrong with the normals. These hills near to the camera have the exact same shape but still the seam is quite noticeable. I guess it’s because when recalculating the normals of one quad it doesn’t know about the adjacent quads (of course) and doesn’t take these vertices into account.

Any ideas on how this could be solved?

How big are your tiles? Make them one bigger each way.

Since you mentioned tiles: I’m not using TerrainGrid here! I’m just placing TerrainQuads next to each other. But to answer the question these quads are all 129 x 129 large.

I didn’t use TerrainGrid because I thought it was made for things like loading multiple heightmaps for a giant terrain. But I need to generate all my terrain from code, no external files at all. Also my full terrain map won’t necessary be a square shape. With these requirements in mind would you recommend me to use TerrainGrid for this?

I’ve never used TerrainGrid I just know that the gap problem is a common one. And to generate proper normals you will need even more border data, still.

The presumption is also that you are putting your 129x129 tiles 128 units apart.

Yes, that’s true. I’m basically creating the quads with QUAD_SIZE = 129 and position them with (QUAD_SIZE - 1) * x (or z respectively; no scaling involved).

But they do line up perfectly regarding the vertex positions, it’s just the normals that are wrong and create a visible seam.

I guess in order to fix this I would need to go deeper to the mesh level and calculate the edge vertices normals by hand. That would be rather complicated and I was hoping that there is some kind of functionality like this already built in (like a TerrainQuad.setNormal(Vector2f xz, Vector3f normal) similar to setHeight).
I found out that TerrainPatch has a method called fixNormalEdges which seems to do what I need, but it is a protected method and I’m not sure yet how to use this properly.

On the other hand, maybe TerrainGrid does his already? I think I need to do some more testing on this.