Jump to content
  • Advertisement
Sign in to follow this  
kok1001

Find vertex normal of unordered triangles on a mesh

This topic is 3772 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 have a mesh without any adjacent data (Index buffer), Can i find all its vertex normals (with Index buffer)? Also , can i have some examples or websites for this kind of thing? thx

Share this post


Link to post
Share on other sites
Advertisement
Hi,

the algorithm for calculating smooth vertex normals for a given triangle list looks like this (Pseudocode!):


for each triangle (v1,v2,v3) in mesh
face_normal = (v2-v1) cross (v3-v1)
normalize face_normal
for all points in triangle
store face_normal
end
end

for each vertex v1 in mesh
vertex_normal = 0;
counter = 0;
for each vertex v2 in mesh
if position of v1 equals position of v2
vertex_normal += normal of v2
counter += 1
end if
end
vertex_normal /= counter;
normalize vertex_normal
store vertex_normal in v1
end


However this can be optimized heavily. Don't forget to use a reliable epsilon to check vertex position differences against. If you have an Indexbuffer, simply access the Vertexbuffer indirectly by iterating through the index data.
Hope this helps you!

Best regards,
Porthos

Share this post


Link to post
Share on other sites
The method i tend to use is this:
Essentialy, you have all vertex normals initialised to 0, you then loop through all triangles calculating the triangle normal, and add this to each of the vertice's normals for that triangle.

You then loop through all vertices normalising their normals.


vertex normals initialised to 0

for each triangle
calculate triangle normal
add triangle normal to each vertice's normal in triangle

for each vertex
normalise normal

Share this post


Link to post
Share on other sites
i just reread the topic starters post and realised that ofcourse, mine is not suitable for his needs as it assumes that vertices are shared between triangles properly.

Share this post


Link to post
Share on other sites
Quote:
Original post by Porthos
Hi,

the algorithm for calculating smooth vertex normals for a given triangle list looks like this (Pseudocode!):


for each triangle (v1,v2,v3) in mesh
face_normal = (v2-v1) cross (v3-v1)
normalize face_normal
for all points in triangle
store face_normal
end
end

for each vertex v1 in mesh
vertex_normal = 0;
counter = 0;
for each vertex v2 in mesh
if position of v1 equals position of v2
vertex_normal += normal of v2
counter += 1
end if
end
vertex_normal /= counter;
normalize vertex_normal
store vertex_normal in v1
end


However this can be optimized heavily. Don't forget to use a reliable epsilon to check vertex position differences against. If you have an Indexbuffer, simply access the Vertexbuffer indirectly by iterating through the index data.
Hope this helps you!

Best regards,
Porthos


I also have this kind of problem.
how to optimized it?

The second part need to process each point ,and each loop search from the begin to the end , it will be quite slow.

will it be faster when i create a index buffer for it?
But...How?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

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!