Sign in to follow this  
kok1001

Find vertex normal of unordered triangles on a mesh

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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this