0
votes

I'm trying to load in heightmap data but I'm struggling to figure out how to work out the normals. Have looked online but can't seem to find anything useful.

I store the vertices using

m_HeightMapVtxCount = (m_HeightMapLength - 1) * m_HeightMapWidth * 2;
m_pVertices = new XMFLOAT3[m_HeightMapVtxCount];

Then the vertices are loaded in using

for (int l = 0; l < m_HeightMapLength - 1; ++l)
    {
        if(l % 2 == 0)  //for every second row - start at the bottom left corner, continue to the right, one row up and continue to the left
        {
            for(int w = 0; w < m_HeightMapWidth; ++w)
            {
                m_pVertices[i++] = XMFLOAT3(m_pHeightMap[w + l * m_HeightMapWidth]);        //bottom vertex
                m_pVertices[i++] = XMFLOAT3(m_pHeightMap[w + (l + 1) * m_HeightMapWidth]);  //top vertex
            }
        }
        else //for the row above, add the vertices from right to left
        {
            for(int w = m_HeightMapWidth - 1; w >= 0; --w)
            {
                m_pVertices[i++] = XMFLOAT3(m_pHeightMap[w + l * m_HeightMapWidth]);        //bottom vertex
                m_pVertices[i++] = XMFLOAT3(m_pHeightMap[w + (l + 1) * m_HeightMapWidth]);  //top vertex
            }
        }
    }

I was able to calculate the normals using triangle lists, that was quite simple, but unsure of how to do it using strips

Why not stick with strips then?Chuck Walbourn
Sorry, that was a typo. Meant to say lists. Using strips as they're more efficientChris
The topology has nothing to do with how you calculate the normals. Your approach for triangle lists should also work for strips. Btw, there are numerous ways to calculate normals (e.g. central differences, Sobel filter...). You should be a bit more specific on what you actually want or show the code for your triangle list approach.Nico Schertler