PDA

View Full Version : How to autogenerate Normals?



11-26-2000, 04:23 AM
I've read through the docs and manuals i've found and they say something about autogenerating normals for better lighting - but where is this doc, manual or tutorial? Or does anyone have code for autogenerating normals? (glNormal3f...)
Ls

Michael Steinberg
11-27-2000, 04:56 AM
I think glEnable(GL_AUTO_NORMAL) that is. Building normals isn't too complicated though, if you just want normals for a face, the normal is simply a normalized cross-product of two edges-vectors (?).

Tim Stirling
11-28-2000, 08:53 AM
if you just want normals for a face, the normal is simply a normalized cross-product of two edges-vectors
What I want to know is that the two edge vertices form a plane, lets say a horizontal plane, the normal could point up or down so how does the cross product calculate which direction?



[This message has been edited by Tim Stirling (edited 11-28-2000).]

Deiussum
11-28-2000, 09:28 AM
It depends on the order you specify the edges. Say you have a function that takes 3 vertices and determines the face normal. If you call the function like so GetNormal(v1, v2, v3); the normal will face one direction, but if you call it using GetNormal(v2,v1,v3) it'll point in the opposite direction. The pseudo-code for the GetNormal function would look something like so...




Vector GetNormal(Vector v1, Vector v2, Vector v3)
{
Vector temp1, temp2;
Vector normal;

temp1 = v1 - v2;
temp2 = v2 - v3;

// assume * represents cross-product
normal = temp1 * temp2;
normal.Normalize();

return normal;
}




[This message has been edited by Deiussum (edited 11-29-2000).]

haust
11-28-2000, 10:04 PM
Note that use glEnable(GL_AUTO_NORMAL) is not a good idea : it may eat lots of CPU/GPU cycles....
Use it for test/debug stuff to see how openGL works with normals then use normals table.

11-29-2000, 02:41 AM
What do you mean with normals table?

11-29-2000, 04:31 AM
the comment in the snippet of code is wrong. it is not a dot product it should be cross product.

Deiussum
11-29-2000, 06:31 AM
Originally posted by hneed:
the comment in the snippet of code is wrong. it is not a dot product it should be cross product.

Oops. http://www.opengl.org/discussion_boards/ubb/smile.gif Fixed now. Not sure where my brain was when I typed that in.

Michael Steinberg
11-29-2000, 07:17 AM
If you stored the poly counterclockwise, take the crossproduct of to vectors that start at one vertex of it, and it will point towards the direction opengl also uses.

Spaceman
12-11-2000, 07:54 AM
glEnable(GL_AUTO_NORMAL); doesn't work.
Is there anything else to do for autogenerated normals ?

And what's with the glNormal(); calls?

RandyU
12-11-2000, 06:07 PM
Have you read SDK help? Here is description from it:

GL_AUTO_NORMAL

If enabled, compute surface normal vectors analytically when either GL_MAP2_VERTEX_3 or GL_MAP2_VERTEX_4 is used to generate vertexes.

gl_AUTO_NORMAL is useful only for NURBS and Bezier surface.
It seems to be no automatic normal generation in OpenGL. There is only automatic normalizing of normals(making them 1-length)
glNormal works :-)

robert
12-13-2000, 12:50 PM
it is best to generate your own normals though, as computing the normals bogs down opengl (especially with bezier curves)

just my 2 cents http://www.opengl.org/discussion_boards/ubb/smile.gif

j
12-13-2000, 02:06 PM
I think that GL_AUTO_NORMAL only works for the evaluators, and not for regular primitives. For those you need to call glNormal* with an appropriate normal.

j