# How to solve seams in tiles due to normals?

**URL:** <https://forum.castle-engine.io/t/how-to-solve-seams-in-tiles-due-to-normals/1899>\
**Category:** Uncategorized\
**Created:** [May 11, 2025, 10:27pm UTC](https://forum.castle-engine.io/t/how-to-solve-seams-in-tiles-due-to-normals/1899 "2025-05-11T22:27:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![edj](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/edj/32/1701_2.png) [@edj](https://forum.castle-engine.io/u/edj)\
**Post date:** [May 11, 2025, 10:27pm UTC](https://forum.castle-engine.io/t/how-to-solve-seams-in-tiles-due-to-normals/1899/1 "2025-05-11T22:27:31Z")

</div>

I finally solved a problem that had been plaguing me where the splat maps had glaring discontinuous seams of data from ‘elsewhere’. Turns out my tiles were slightly misaligned in the world causing the glsl to behave oddly on the edges, wrapping splat data from the other edge of the tile.

Now I still have subtle (or not) seams between tiles both in the water layer (which includes snow) and terrain layer presumeably because the normal calculated at the edge vertices don’t account for their neighboring vertices in the neighboring tile. How would I fix these normals to match? I have access to the neighbor data but would have to manually calculate the normal. Is cge or x3d computing the normals somewhere? (TIndexedTriangleSetNode)

 ![image](https://forum.castle-engine.io/uploads/default/original/2X/2/230f34ff6e54c0fe5dfbdea53ede8e0d3b4c22d8.jpeg)

---

<div class="post-metadata">

**Author:** ![edj](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/edj/32/1701_2.png) [@edj](https://forum.castle-engine.io/u/edj)\
**Post date:** [May 11, 2025, 11:44pm UTC](https://forum.castle-engine.io/t/how-to-solve-seams-in-tiles-due-to-normals/1899/2 "2025-05-11T23:44:04Z")

</div>

I have partially answered my question. It looks like I need to initialize Triangles.Normal to TNormalNode with a normal for each vertex.  
I set all to vector3(0,1,0) and the seams go away, as does the shading since it is all same direction. How is the normal calculated when Normal is not set? I would like to be able to use the default for all non edge vertices and then average with corresponding vertex from neighboring tile for edge vertices (these vertices are the same location).

 ![image](https://forum.castle-engine.io/uploads/default/original/2X/7/7cd7187e3e5df76f40661b4c094487d3966f90bc.jpeg)

---

<div class="post-metadata">

**Author:** ![edj](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/edj/32/1701_2.png) [@edj](https://forum.castle-engine.io/u/edj)\
**Post date:** [May 12, 2025, 4:19pm UTC](https://forum.castle-engine.io/t/how-to-solve-seams-in-tiles-due-to-normals/1899/4 "2025-05-12T16:19:59Z")

</div>

I modelled my GetNormal from yours getting the heights bilerped direct from underlaying data array… and voila, no seams, at least in the snow. Now the only visible seams between tiles are because the splat layer doesn’t blur between tiles.

 ![image](https://forum.castle-engine.io/uploads/default/original/2X/b/be244e30df26b92ddcab71dcbb6279a5a239009d.jpeg)

---

<div class="post-metadata">

**Author:** ![edj](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/edj/32/1701_2.png) [@edj](https://forum.castle-engine.io/u/edj)\
**Post date:** [May 12, 2025, 4:35pm UTC](https://forum.castle-engine.io/t/how-to-solve-seams-in-tiles-due-to-normals/1899/5 "2025-05-12T16:35:04Z")

</div>

Almost seamless looks sooo much better. Thanks for all the help! The solution was of course your code in TCastleTerrain. (The line on the hill isn’t a seam but a stream flowing straight down that very straight hill.)

 ![image](https://forum.castle-engine.io/uploads/default/original/2X/4/4cc77802c448acb2e7fe54e728e8aaf3f4e7d897.jpeg)

---

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [May 12, 2025, 4:50pm UTC](https://forum.castle-engine.io/t/how-to-solve-seams-in-tiles-due-to-normals/1899/6 "2025-05-12T16:50:52Z")

</div>

I see you solved this already. Indeed, if you make terrain from multiple meshes, you need to provide explicit normal calculation to have continuous normals when one mesh is a “visual continuation” of another mesh.

For completeness, you asked how the normals are automatically calculated – this follows X3D spec of the respective nodes. See [X3D](https://castle-engine.io/x3d), [X3D Rendering component that includes IndexedTriangleFaceSet](https://castle-engine.io/x3d_implementation_rendering.php#section_supported_nodes) and finally [X3D spec about IndexedTriangleSet](https://www.web3d.org/documents/specifications/19775-1/V4.0/Part01/components/rendering.html#IndexedTriangleSet) :

> If the _normal_ field is not supplied, normals shall be generated as follows:
> 
> - If _normalPerVertex_ is TRUE, the normal at each vertex shall be the average of the normals for all triangles that share that vertex.
> - If _normalPerVertex_ is FALSE, the normal at each vertex shall be perpendicular to the face for that triangle.

It indeed doesn’t account for “neighbor” meshes, since it doesn’t have any idea you may want to have the 2 meshes “visually continuous”.
