glNormal - Surface/Vertex normals

Jones
Unregistered
 
Post: #1
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!
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #2
Generally you submit one normal for each vertex of a primitive ( such as a triangle, or quad ). Which is to say, one normal per-vertex.

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.
Quote this message in a reply
Jones
Unregistered
 
Post: #3
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 per-vertex.

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

Ok, but are those normals still derived from the normalized cross product of *any* two of the surfaces vertices? (In this case, triangle, strip-triangles and such.) Or should it be the two that form that corner?

I'll check what the Red-Book says about this again...

*reads*

Well, the example in the book is annoyingly messy-like. 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 normal-cross-product 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).
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
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.
Quote this message in a reply
Jones
Unregistered
 
Post: #5
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
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.
Quote this message in a reply
Jones
Unregistered
 
Post: #7
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!
Quote this message in a reply
Member
Posts: 161
Joined: 2005.07
Post: #8
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
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
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.
Quote this message in a reply
Member
Posts: 161
Joined: 2005.07
Post: #10
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
Then the 3DS file format is broken, and you should use a sensible one ^_^
Quote this message in a reply
Jones
Unregistered
 
Post: #12
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 re-writing 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! Wink
Quote this message in a reply
Jones
Unregistered
 
Post: #13
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? Rasp

Thanks for the tip!
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #14
If you normalize the vertex itself, then you will get a /model/ that is of size 1. Smile
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #15
The only shape where the normals are normalized versions of the vertices is a sphere centered on the origin Rasp

The MD2 normal table is still available, under the GPL:
http://www.idsoftware.com/business/techdownloads/
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  texture no square surface kendric 7 4,546 Mar 20, 2009 05:26 PM
Last Post: kendric
  surface rendering from data points mc1961 6 5,106 Nov 15, 2007 03:37 PM
Last Post: TomorrowPlusX
  Trouble turning an SDL surface into an OpenGL texture Joseph Duchesne 4 5,785 May 22, 2007 05:14 PM
Last Post: Joseph Duchesne
  Surface/Vertice Normals and Scene Placement Jones 3 3,014 Aug 22, 2006 02:45 PM
Last Post: scgames
  Getting surface x & y coords? Jones 4 3,348 May 7, 2006 04:29 PM
Last Post: Jones