# Calculate vertex normal of unordered triangles

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

## Recommended Posts

I have a mesh without any adjacent data, Can i calculate back all its vertex normals (as fast as possible)?

##### Share on other sites
Any vertex's normal is simply the addition of all the normals of the triangles that it is composed of divided by the number of normals. If you have a list of triangle objects (groups of 3 verticies), you can generate a unique vertex, index, and normal list from it.

Iterate through each triangle. For each vertex:

1) Add the vertex to the output vertex array if it is unique. Either way, add the index of the vertex to the output index list.
2) If the vertex is unique, add the normal of the triangle it came from to the normal list. It should have the same index into the index array as the unique vertex. If the vertex is not unique, lookup the normal associated with the index found in step 1 and add this triangle's normal to it, dividing by two.

In the end, you should have 3 lists. These can be rendered with GL_TRIANGLES.

Not sure if this is as fast as possible, but here are some optimizations that can be made if this function is too slow:

- store the vertex list so that looking to check if a vertex is unique requires less than a worst case O( n ) search.
- the most costly operation in this loop is the vector division. That should be as fast as possible

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 17
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634094
• Total Posts
3015498
×