glNormal  Surface/Vertex normals
When using glNormal3fv to define a surface normal, do I give the normalized cross product of two of the surfaces vertices (vectors) or something else? This confusion arose when I looked at an example for drawing complex models from triangles. They called glNormal3fv every vertex, and not once for the entire surfarce. I thought one normal would correspond to the entire model. If I do have to specify it for every vertex, would it be the same for each one?
Thanks!
Thanks!
Generally you submit one normal for each vertex of a primitive ( such as a triangle, or quad ). Which is to say, one normal pervertex.
The normal refers to the normal at a point on a surface. Unless your model is a perfectly flat plane, it's likely to have more than one normal.
Quote:I thought one normal would correspond to the entire model.
The normal refers to the normal at a point on a surface. Unless your model is a perfectly flat plane, it's likely to have more than one normal.
TomorrowPlusX Wrote:Generally you submit one normal for each vertex of a primitive ( such as a triangle, or quad ). Which is to say, one normal pervertex.
The normal refers to the normal at a point on a surface. Unless your model is a perfectly flat plane, it's likely to have more than one normal.
Actually, that was a mistype. What I meant was one entire surface**, not an entire model.
Ok, but are those normals still derived from the normalized cross product of *any* two of the surfaces vertices? (In this case, triangle, striptriangles and such.) Or should it be the two that form that corner?
I'll check what the RedBook says about this again...
*reads*
Well, the example in the book is annoyingly messylike. It shows normal calculation for an icosahedron where the vertices are pointed to by indices which make up the corners. And they form up to vectors and then normalcrossproduct them to form one to pass to glNormal. For reference, this code is on page 90 of the Red Book (fourth edition).
Could anybody please give me an example of glNormal for drawing say a pyramid or cube?
Thanks!
On a slightly less related note:
Is it worth buying the next release of the red book (2.0)? I have version 1.4 (ed 4th).
If you have a faceted model like a pyramid or a cube, then you'll have face normals. You could specify them each once for the face, but it's still best to specify them for each vertex.
If you have a smooth model like a sphere, then you'll have vertex normals.
If you have a smooth model like a sphere, then you'll have vertex normals.
OneSadCookie Wrote:If you have a faceted model like a pyramid or a cube, then you'll have face normals. You could specify them each once for the face, but it's still best to specify them for each vertex.
If you have a smooth model like a sphere, then you'll have vertex normals.
What if it's smooth and faceted? Like a human body or something. I guess vertex normals then. So how does one calculated a vertex normal... is it different from a face normal?
Imagine sticking a nail through a piece of wood, then running the piece of wood over the surface of your object. The direction the nail is the normal to the surface.
For a smooth surface, the nail will move in a nice curve as you move the wood around.
For a faceted surface, the nail will suddenly flick from one direction to another as the wood moves from face to face.
A human body is solidly in the "smooth" camp. A cylinder is an exampe of something with some smooth and some faceted. A cube is all facets.
For a smooth surface, the nail will move in a nice curve as you move the wood around.
For a faceted surface, the nail will suddenly flick from one direction to another as the wood moves from face to face.
A human body is solidly in the "smooth" camp. A cylinder is an exampe of something with some smooth and some faceted. A cube is all facets.
OneSadCookie Wrote:Imagine sticking a nail through a piece of wood, then running the piece of wood over the surface of your object. The direction the nail is the normal to the surface.
For a smooth surface, the nail will move in a nice curve as you move the wood around.
For a faceted surface, the nail will suddenly flick from one direction to another as the wood moves from face to face.
A human body is solidly in the "smooth" camp. A cylinder is an exampe of something with some smooth and some faceted. A cube is all facets.
I understand surface normals. I did NOT know about the difference for smooth and faceted objects. Thanks for clarifying that!
If you want vertex normals for a model, you take the average of the face normals for each facet that shares that vertex. Pseudocode would be like this:
Code:
for each vertex
set a temporary vector to (0, 0, 0)
for each polygon
if one of the polygon's vertices is equal to the current vertex,
add that polygon's normal to the temporary vector
next
normalize the temporary vector
(no need to divide by the total polygons)
this is now the vertex normal
next
You can get better results by taking into account the area of the triangle providing each normal into account.
You should never need to do this, though  your modeling program should analytically determine the normals (eg. by differentiating a bezier patch), and you should load them from a file.
You should never need to do this, though  your modeling program should analytically determine the normals (eg. by differentiating a bezier patch), and you should load them from a file.
OneSadCookie Wrote:You should never need to do this, though  your modeling program should analytically determine the normals (eg. by differentiating a bezier patch), and you should load them from a file.I'm sorta getting off topic here, but I wanted to point out that the 3DS file format doesn't store any normals, most likely to save space. It just stores the vertices for the polygons in a specific order to make it possible to generate the facet and vertex normals after loading in the model. Most other formats seem to save the normals though.
Then the 3DS file format is broken, and you should use a sensible one ^_^
But what if the format doesn't, and it's not a 3DS. It uses some form of pregenerated normal table, which used to be up for download, but now appears to be unatainable. So I'm rewriting the system. I'm making a program to generate the normals, from the model. Then... I'll make my *own* model format based of this one, but with the normals and all texture data built in. It will be... brilliant!
imikedaman Wrote:If you want vertex normals for a model, you take the average of the face normals for each facet that shares that vertex. Pseudocode would be like this:
Code:
for each vertex
set a temporary vector to (0, 0, 0)
for each polygon
if one of the polygon's vertices is equal to the current vertex,
add that polygon's normal to the temporary vector
next
normalize the temporary vector
(no need to divide by the total polygons)
this is now the vertex normal
next
Ah so just normalizing a vertice (directly) is silly, and I should slap myself for even thinking of trying that?
Thanks for the tip!
If you normalize the vertex itself, then you will get a /model/ that is of size 1.
The only shape where the normals are normalized versions of the vertices is a sphere centered on the origin
The MD2 normal table is still available, under the GPL:
http://www.idsoftware.com/business/techdownloads/
The MD2 normal table is still available, under the GPL:
http://www.idsoftware.com/business/techdownloads/
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
texture no square surface  kendric  7  5,297 
Mar 20, 2009 05:26 PM Last Post: kendric 

surface rendering from data points  mc1961  6  5,996 
Nov 15, 2007 03:37 PM Last Post: TomorrowPlusX 

Trouble turning an SDL surface into an OpenGL texture  Joseph Duchesne  4  6,338 
May 22, 2007 05:14 PM Last Post: Joseph Duchesne 

Surface/Vertice Normals and Scene Placement  Jones  3  3,398 
Aug 22, 2006 02:45 PM Last Post: scgames 

Getting surface x & y coords?  Jones  4  3,716 
May 7, 2006 04:29 PM Last Post: Jones 