# What is wrong with my terrain lighting?

I've just implemented a simple algorithm to calculate terrain vertex normals and I'm using diffuse and ambient light currently, but for some reason the squares that make up my terrain are visible when I turn on lighting as you can see in the above image. I'm currently calculating the normal for the terrain using the cross product formula between two vectors of the squares that compose the terrain. Is it because I should be using something like the average between the neighbour normals? I'll leave bellow the algorithm I'm using:

        //m_Polygon->Position is the 3D position of the vertex.

XMVECTOR Normal = XMVector3Normalize(XMVector3Cross(Vector1, Vector2));

m_Polygon[m_Polygon.size() - 4].Normal = XMFLOAT3(XMVectorGetX(Normal), XMVectorGetY(Normal), XMVectorGetZ(Normal));

Normal = XMVector3Normalize(XMVector3Cross(Vector1, Vector2));

m_Polygon[m_Polygon.size() - 3].Normal = XMFLOAT3(XMVectorGetX(Normal), XMVectorGetY(Normal), XMVectorGetZ(Normal));

Normal = XMVector3Normalize(XMVector3Cross(Vector1, Vector2));

m_Polygon[m_Polygon.size() - 2].Normal = XMFLOAT3(XMVectorGetX(Normal), XMVectorGetY(Normal), XMVectorGetZ(Normal));

Normal = XMVector3Normalize(XMVector3Cross(Vector1, Vector2));

m_Polygon[m_Polygon.size() - 1].Normal = XMFLOAT3(XMVectorGetX(Normal), XMVectorGetY(Normal), XMVectorGetZ(Normal));


As you can see I'm using DirectXMath Library to calculate everything, I just calculate the normals for the last square(4 vertices distributed in clockwise order).

• Do you have 4 copies of each vertex, one for each quad meeting at that point? That may be 4x more data than you need if you always want smooth blending between quads. Oct 23, 2021 at 15:20
• Yes it is, but I was thinking of solving this later with indexing. Oct 23, 2021 at 15:42
• Solve it now and it will remove the seams, and cut the work of determining normals down to a quarter. 😉 Oct 23, 2021 at 15:48
• @DMGregory Thanks! Oct 25, 2021 at 23:03
• If you've solved your problem, be sure to share your solution as an Answer below. Oct 26, 2021 at 1:19