Terrain Normals

Started by
2 comments, last by AN_D_K 20 years, 8 months ago
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?
Advertisement
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()));				}
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 only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
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.

This topic is closed to new replies.

Advertisement