Skip to main content
GameDev.net gamedev.net
🔒 Locked

Terrain Normals

Started by AN_D_K Aug 5, 2003 at 6:00 PM 2 replies 650+ views
Original Post
AN_D_K
AN_D_K
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?
budipro
budipro
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()));
}
joanusdmentia
joanusdmentia
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.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o
_DarkWIng_
_DarkWIng_
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.
You should never let your fears become the boundaries of your dreams.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.