View Full Version : simple question about vertex normals

airseb

01-27-2005, 11:10 AM

Hi,

i wonder something :

opengl wants the normals by what way ? I mean : want it a normal by vertex every time that a vertex is specified in the indice array, thus we can have several times the same normal in the array, or opengl just need an array with normal[0], normal[1],... the same number of times that there are vertices, so a normal one time in the array like others ?

don't hesitate to tell me if i'm not clear.

dovkruger

01-27-2005, 05:32 PM

Well, it's not totally clear, but on the assumption that you mean:

Question: Do I need the same number of normals as vertices?

I think the answer is, if you are trying to make the surfaces as smooth as possible, yes. If not, you can get by with one normal per triangle.

Consider two adjacent triangles (excuse the ascii)

a----b

| / |

| / |

c----dpoints a and d can each get the normal of their respective triangle, there's nothing else to do.

For points b and c, the question is do you assign them the normal of the first or second triangle?

You can just define normal for the first triangle:

computeNormal(a,b,c);

glVertex(a);

glVertex(b);

glVertex(c);

computeNormal(b,c,d);

glVertex(b);

glVertex(c);

glVertex(d);

If you have a sharp angled polygon, that might be the thing you want to do. But that isn't going to give you a smooth effect if you are trying to create a smooth surface, in which case the triangles are just an approximation. In that case, you might want the normal at b,c to be the average of the two normals. Taking that further, on a surface, point a could be the average of the 4 adjacent triangles, and point b could be the average of 6.

+------b------+

| /|\ |

| / | \ |

| / | \ |

| / | \ |

| / | \ |

+------a------+

|\ | /|

| \ | / |

| \ | / |

| \ | / |

| \ | / |

+------+------+Clear?

Dov

If you want lighting, then OpenGL needs normals. Instead, this is not used and is just memory consumption for nothing.

If you specify one normal for each face, you'll have a flat looking model.

If you specify one normal for each vertex, then OpenGL will be able to draw a smooth shaded looking model.

A normal is a vector that is always perpendicular to its matching face. For flat surfaces, all normals from each vertex are the same. For curve surfaces, then each normal of each vertex is generally different. This is because a curve surface can be considered as an infinite number of different segments of little planes (like triangles). So, at each point of a curve surface, we are fronting in a different plane.

If you really want to calculate normals of curve surfaces, you'll generally use derivatives. This is because each face of your model will generally be only an approximation (a reduction) of the real look of the model.

There's also the solution to use an average per-vertex normal, that is the average normal of all the normals of the faces passing to this vertex. This is a good solution to my point of view.

Hope this helps.

airseb

01-28-2005, 11:50 AM

ok thanks guys, but i haven't been clear enough :

i want to know if i have to specify 150 normals if there is 150 vertices, or 450 normals for 150 vertices which are repeated several times like in the "index array"which contain the number of vertices face per face like " 1 ,5,6, 1,56,14". here the vertex "1" is present twice and i want to know if i have to have an array with six normals with the normal "1" repeated twice or without repeating the vertices which are present several times ?

First of all, try to be more clear with what you are writing. I'm not sure anyone here is able to understand that easily (and I wasn't).

I think you have several misunderstandings with what are vertices and normals.

A vertex of a face CANNOT be THE vertex of another face. We say faces share the same vertex, but you'll NEVER encounter this situation, but under 'restrictive' situations like with using triangle strips and fans.

Indeed, even if this is obvious for our eyes to see that a vertex is the same for 2 faces or more, this is not possible for gl to do so. Again, only strips and fan can allow vertex sharing, but the gl computes itself the missing vertices with the appropriate algorithm.

So, each vertex of your face must have its own normal. From your quote above, wether you have 150 normals (in case of per-vertex and smooth shading), or wether you have 50 vertices (in case you want flat shading) and you specify the normals once per face.

You simply cannot have more normals than vertices.

Hope this helps quiete a lot.

airseb

01-29-2005, 04:10 AM

so, (to verify that i have understood)if i have 32 vertices, i have to make an array of 32 elements (which are normals) from 0 to 31 ?

if you want smooth shading yes: one vertex, one normal.

You can forgot some, opengl won't plaign about that generally. But this is not a good idea.

Originally posted by jide:

if you want smooth shading yes: one vertex, one normal.

You can forgot some, opengl won't plaign about that generally. But this is not a good idea.ok thanks ! because i was thinking that i had to put one normal per index of vertex...

dovkruger

02-01-2005, 01:17 PM

If you have data, as opposed to an analytical surface that you are rendering, then you are presumably plotting a surface using triangles. In such a case, you average the normals. The derivative is all very well *if you have it*.

If your intention is to make a polyhedron with discrete faces, then you do not average the normals, you define one normal for each face.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.