Archived

This topic is now archived and is closed to further replies.

AN_D_K

Terrain Normals

Recommended Posts

AN_D_K    158
I know that on a terrain mesh that each vertex has the average normal of all the triangles connected too it. All the vertices within the mesh are connected to 6 triangles and this has let me make a simple algorithm to get the values for it. What is troubling me is how to get the normals for the vertices that are on the outsides of the mesh as they are not connected to 6 triangles. How to I make an algorithm for these that will compliment my previous one?

Share this post


Link to post
Share on other sites
budipro    122
If you use triangle list and indices, then it should be easy to calculate the normals. Just loop through the indices and average the vertex normals those indices point to.

I haven''t figured out the way if you are not using list and indices. It seems quite complicated.

Here is the sample using list and indices:


for (int i = 0; i < indices.Length; i+=3)
{
normal = (CalcNormal(verts[indices[i+1]], verts[indices[i+2]], verts[indices[i]]));
verts[indices[i]].SetNormal(Vector3.Add(verts[indices[i]].GetNormal(), normal));
verts[indices[i+1]].SetNormal(Vector3.Add(verts[indices[i+1]].GetNormal(), normal));
verts[indices[i+2]].SetNormal(Vector3.Add(verts[indices[i+2]].GetNormal(), normal));

verts[indices[i]].SetNormal(Vector3.Normalize(verts[indices[i]].GetNormal()));
verts[indices[i+1]].SetNormal(Vector3.Normalize(verts[indices[i+1]].GetNormal()));
verts[indices[i+2]].SetNormal(Vector3.Normalize(verts[indices[i+2]].GetNormal()));
}

Share this post


Link to post
Share on other sites
joanusdmentia    1060
2 ways come to mind. You could assume that the normal of the non-existent triangles simply point upwards. Alternatively, just exclude them from the calculation (ie. average only the normals that you do have). How you do it is really up to you.

Share this post


Link to post
Share on other sites
_DarkWIng_    602
If you are using heightmap for terrain loop up "finite distance" approach for generation normals. It''s been discussed on this forums alot of times.

You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites