Jump to content
• Advertisement

#### Archived

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

# Terrain Normals

This topic is 5587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

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

##### Share on other sites
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()));				}

#### Share this post

##### Share on other sites
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

##### Share on other sites
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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
70
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633430
• Total Posts
3011826
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!