making up normals

Started by
5 comments, last by Malchivus 19 years, 4 months ago
assuming using opengl and only triangles .... i'm trying to figure out how to make up per vertex normals. i thought of just averageing together all the normals for all triangles touching a vertex, but then i realized that a triangle on the edge would have a messed up surface normal because the avereage of its normals would not be pulled in the right directions. i tried weighted averages but this didn't work, the same problem came up. i think i can do it by taking the normal of the face OPOSITE the vertex and using it to change the surface normal that i'm trying to turn into a vertex normal, but i'm not sure if this means my meshes will be individual polygons. does anyone know about anything to do this?
I just wanna get this done.
Advertisement
Some days I think the art of searching is dead...
that link said to do what i said wouldn't work, it would only work corectly if every vertex was connected to the same number of triangles (or maybe if the mesh was closed). if a vertex just floats off into the middle of nowhere, it is only conected to one triangle, won't the normal for the whole plane be wrong? the lighting calculations will be relying on the vertex on the edge of the mesh to 'pull' the other two back twoards the right direction, but it won't do this because it has not been combinded with any other triangles
I just wanna get this done.
meh, i'm not sure what you mean, because I use the system I linked to above on a 512*512 terrain and there are no signs of messed up normals.

This is important because not all verts have the same number of tris attached to them, for example corner verts only touch 2 tris, top, side and bottom verts only touch 3 (or 4, i forget which) and inside verts can touch up to 6 (or 8, meh i need to draw stuff at some point.. ) tris.

Just visulise it, take your hands and angle 'em so your index and middle finger touch (dont worry about your thumbs), the top and bottom of your hands for two verts and the bottom of your little fingers forming the 3rd verts. Now, imagine lines coming out at right angles, perform a cunning bit of maths in your head and you'll notice that adding them together will result in a normal pointing in the right direction.
Remember that If you are accumulating the face normals for each vertex you dont have to divide the accumulated vector by the number of faces attached to the vertex.

If you know that the face normals are already unit vectors you can simply accumulate them and then normalise the result to give you the vertex normal.

Twitter: [twitter]CaffinePwrdAl[/twitter]

Website: (Closed for maintainance and god knows what else)

Are you saying your lighting will be messed up because the normals from two surfaces facing totaly diffrent directions are being averaged?

 \C   |A  \   |   \ _____    |--  |B   |


Average(A+B)=C ? is that the problem, if so you need to implement Sharp Edge preservation, you do this by only averageing face normals that are with in "Edge Tolarence" you can do this by takeing the DotProduct of both normals

if ( DotProduct(A,B) > Cos(Tolarence) ) // where Tolarence is The radian measure of an angle, so if you choose 70 degree convert to radians, then the above situation will not happen cause those normals are 90 degrees apart.
{
Take_This_Into_Account_For_Averaging();
}

Perhapes this helped?
"I seek knowledge and to help those who also seek it"

ok phantom gotcha. i thought that it wouldn't work but i guess it will.


i was worried about when working with a mesh from a dodgey moddeler that comes with no normals, and has triangles that go off into space. earlier i was worried about what to do with triangles that a bsp process choped up (especialy if they needed to be smooth shaded) but in that case it is easily possible to find the normal at any point using the source triangle's normals.
I just wanna get this done.

This topic is closed to new replies.

Advertisement