Jump to content
  • Advertisement
Sign in to follow this  
vurentjie

vertex normal just checkin myself

This topic is 3786 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

hi, i want to begin experimenting with smooth shaded mesh objects in opengl, and just want to double check some of the math involved as well as some questions involving the programing operations. i do not ask for someone to do this for me, but advice is always valuable and saves time and the odd ache. so from the many, many articles i have read, and opinions and advice on posts on gamedev, as well as teaching myself about vectors and matrices from a textbook, i think i can grasp the basic concept, 1)i will create a 'closed-rounded' mesh object using mainly a struct for vert position, possibly struct for face data, and possibly vertex data from array, this is not problematic. 2)next i should make a function that computes the normal for each face, via three vertex points on that face and the cross-product to find the perpendicular. 3)then 'somehow' i will have to find a way to find shared vertices for adjacent faces for a closed-object that consists of an arbitrary amount of faces, some function (advice on how to go about this would be appreciated), 4)then i will add together adjacent face normals for a shared vertex - from what i have read, and the math that i have studied in the last while, averaging the normal here, by dividing by amount of faces, is trivial(i might be wrong though), but i am guessing i am not because for the next step, 5)i will normalize the vector to unit length, by firstly computing the vector length then dividing respective x-y-z components by this length...i write this from memory so might be wrong here will double check though. 6)now i have my vertex normals. if it is for a shared vertex the normal will be used for each instance where that vertex is called(i want to use GL_SMOOTH). can anyone please correct if any of this stands wrong.my main difficulty i am guessing is building function to find shared vertices - from thinking about it i am thinking a loop through all faces is first step, but then would i have to take that specific face for each loop iteration and loop again to compare against other faces - is there any math formula to solve this shorter way. Anyway I have said a lot here.Thanks in advance for any feedback.

Share this post


Link to post
Share on other sites
Advertisement
A common method for computing vertex normals is to compute each vertex normal as the sum of the normals of all the faces it touches, and then normalize it (if you leave the face normals un-normalized for this step, face area will automagically be factored in). Note that you don't 'average' the normal by dividing by the number of faces; just normalize it and you'll be good to go.

As far as figuring out which faces touch which vertices, you can brute-force it, or compute connectivity info in advance (this is assuming that your mesh is irregular - in a regular mesh such as that based on a heightmap, the connectivity is implicit).

The brute-force approach might go something like this:
for each vertex
zero the vertex normal
for each face
for each face index
if the index corresponds to the vertex in question
add the face normal to the vertex normal
normalize the normal

Share this post


Link to post
Share on other sites
thank you for the reply, i must go sleep a bit now, but will comment quickly,

i did not realize about normalizing face normals,
i retype your txt here to ask/comment at specific,

for each vertex
zero vertex normal (because going to add to later-yes?)
for each face
find face normal and normalize//i dont quite understand by "face area factored in", should i be normalizing face normal here?
for each face points that are this vertex
add face normal to vertex normal
normalize normal

your's is very nice example of workflow - if you can maybe explain just for interest sake what you mean by
face area will automagically be factored in[\quote]
maybe just a brief explanation as this is too brief for me to make something of.also not quite sure whether i should/shouldn't normalize face normal as you say autoMAGICally which also confuse me :)

Share this post


Link to post
Share on other sites
What I mean by 'face normals will automatically be factored in' is ('automagically' isn't a 'real' English word, so we'll just leave that out :):

- The length of the cross product of two vectors is proportional to the area of the parallelogram (and therefore triangle) formed by the vectors

- Therefore, the length of the (un-normalized) normal to a triangle face is proportional to the area of that triangle face

- Therefore, when adding together the (un-normalized) normals of triangle faces that share a vertex, triangles with larger areas will 'contribute' more to the vertex normal

- Therefore, the vertex normals will favor ('lean towards') faces with larger area

In most cases, I doubt the visual effect will differ much depending on whether you normalize the face normals before or after computing the vertex normals, so I'd just do what makes the most sense to you.

Share this post


Link to post
Share on other sites
yes thank you, after i read here yesterday, i go think about it some more, and i did understand that larger areas might have longer normals,
and sorry about confusion over auto-magic-ally, i just thought perhaps it was not typo,

thank you again, the advice you have shared is so appreciated. it is also nice to try write out what you think should happen, i find it helps me to make more sense of a situation-or find where not making sense.

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!