Normals
I think I've now figured out what they are and how to use them yet I'm running into trouble getting them. I have a bunch of triangular faces. To find the normal of the face, I simply use the equation (Vertex1-Vertex2)*(Vertex2-Vertex3), correct? That's what the OpenGL Redbook said anyway. So my problem is that when running something like that, all my normals coincidentally being (0,0,0) which obviously does me no good. Is that equation wrong or is there more to this deal? Or could it be because I'm using a perfect cube?
Here's a look at some of my output while initializing these normals:
Here's a look at some of my output while initializing these normals:
Code:
Vertex: (3, 6, 3)
Vertex: (-3, 6, 3)
Vertex: (-3, 0, 3)
X=(3 - -3)*(-3 - -3)
Y=(6 - 6)*(6 - 0)
Z=(3 - 3)*(3 - 3)
X=(6)*(0)
Y=(0)*(6)
Z=(0)*(0)
Initializing normal (0, 0, 0)
Magnitude: 0
Vertex: (3, 6, 3)
Vertex: (3, 6, -3)
Vertex: (-3, 6, -3)
X=(3 - 3)*(3 - -3)
Y=(6 - 6)*(6 - 6)
Z=(3 - -3)*(-3 - -3)
X=(0)*(6)
Y=(0)*(0)
Z=(6)*(0)
Initializing normal (0, 0, 0)
Magnitude: 0
Vertex: (3, 0, 3)
Vertex: (3, 0, -3)
Vertex: (3, 6, -3)
X=(3 - 3)*(3 - 3)
Y=(0 - 0)*(0 - 6)
Z=(3 - -3)*(-3 - -3)
X=(0)*(0)
Y=(0)*(-6)
Z=(6)*(0)
Initializing normal (0, -0, 0)
Magnitude: 0
Vertex: (-3, 0, -3)
Vertex: (-3, 0, 3)
Vertex: (-3, 6, 3)
X=(-3 - -3)*(-3 - -3)
Y=(0 - 0)*(0 - 6)
Z=(-3 - 3)*(3 - 3)
X=(0)*(0)
Y=(0)*(-6)
Z=(-6)*(0)
Initializing normal (0, -0, -0)
Magnitude: 0
Vertex: (-3, 0, -3)
Vertex: (-3, 6, -3)
Vertex: (3, 6, -3)
X=(-3 - -3)*(-3 - 3)
Y=(0 - 6)*(6 - 6)
Z=(-3 - -3)*(-3 - -3)
X=(0)*(-6)
Y=(-6)*(0)
Z=(0)*(0)
Initializing normal (-0, -0, 0)
Magnitude: 0
Vertex: (-3, 6, -3)
Vertex: (-3, 6, 3)
Vertex: (3, 6, 3)
X=(-3 - -3)*(-3 - 3)
Y=(6 - 6)*(6 - 6)
Z=(-3 - 3)*(3 - 3)
X=(0)*(-6)
Y=(0)*(0)
Z=(-6)*(0)
Initializing normal (-0, 0, -0)
Magnitude: 0
Vertex: (3, 6, -3)
Vertex: (3, 6, 3)
Vertex: (3, 0, 3)
X=(3 - 3)*(3 - 3)
Y=(6 - 6)*(6 - 0)
Z=(-3 - 3)*(3 - 3)
X=(0)*(0)
Y=(0)*(6)
Z=(-6)*(0)
Initializing normal (0, 0, -0)
Magnitude: 0
Vertex: (3, 6, -3)
Vertex: (3, 0, -3)
Vertex: (-3, 0, -3)
X=(3 - 3)*(3 - -3)
Y=(6 - 0)*(0 - 0)
Z=(-3 - -3)*(-3 - -3)
X=(0)*(6)
Y=(6)*(0)
Z=(0)*(0)
Initializing normal (0, 0, 0)
Magnitude: 0
Puzzler183 Wrote:Uh, color arrays? People still use those? Everyone I see now uses a material setting and a texture setting and that's it...
Sometimes they're useful. For the terrain engine in my game, if it's running on a card with only 2 texture units I use color arrays for the colormap/shadowmap and let the two texture units display a primary and detail texture. When running on a 4 texture unit card, it uses the RGB components of a colormap on tex unit 2 for color & shadow, and uses the alpha component as a mixmap for texture units 0 and 1; then I apply a detail texture on unit 3.
Color arrays can still be useful...
I see. The page I found info on never said the x in (A-B)x(B-C) was cross product so I assumed multiplication. I can't try it now, but I've got some code written down that I'll put in later today when I get home. Hopefully this will work.
Well I think I've got the normals but let me just make sure. Here's some output from my program. Do these figures look correct?
To explain a few things: the equation used for finding the normal is (A-B)x(B-C) so what I did was v1=v1-v2 and then v2=v2-v3. That's why there's a new v1 and new v2 in the output. Then the new v1 and v2 were changed into normals giving n1 and n2. The cross product of those (n1 and n2) was made into n3. Then I recalculated the magnitude for the normal giving the result. After that it shows the prenormalized and normalized version of that normal (normalized with equation Normal/Magnitude).
One more thing: the model I'm using is simply a cube (hence the simple vertices) so these are actually the polygon normals which I used for each of the four vertices on that particular polygon.
To explain a few things: the equation used for finding the normal is (A-B)x(B-C) so what I did was v1=v1-v2 and then v2=v2-v3. That's why there's a new v1 and new v2 in the output. Then the new v1 and v2 were changed into normals giving n1 and n2. The cross product of those (n1 and n2) was made into n3. Then I recalculated the magnitude for the normal giving the result. After that it shows the prenormalized and normalized version of that normal (normalized with equation Normal/Magnitude).
One more thing: the model I'm using is simply a cube (hence the simple vertices) so these are actually the polygon normals which I used for each of the four vertices on that particular polygon.
Code:
v1: Vertex: (18, 0, 3)
v2: Vertex: (18, 6, 3)
v3: Vertex: (18, 6, -3)
new v1: Vertex: (0, -6, 0)
new v2: Vertex: (0, 0, 6)
n1: Normal: (0, -6, 0). Magnitude: -6.28885e-29
n2: Normal: (0, 0, 6). Magnitude: -6.28885e-29
n3: Normal: (-36, 0, 0). Magnitude: -6.28885e-29
Result: Normal: (-36, 0, 0). Magnitude: 36
Prenormalized FNT: Normal: (-36, 0, 0). Magnitude: 36
Normalized FNT: Normal: (-1, 0, 0). Magnitude: 0
v1: Vertex: (12, 0, -3)
v2: Vertex: (18, 0, -3)
v3: Vertex: (18, 6, -3)
new v1: Vertex: (-6, 0, 0)
new v2: Vertex: (0, -6, 0)
n1: Normal: (-6, 0, 0). Magnitude: -6.28885e-29
n2: Normal: (0, -6, 0). Magnitude: -6.28885e-29
n3: Normal: (0, 0, 36). Magnitude: -6.28885e-29
Result: Normal: (0, 0, 36). Magnitude: 36
Prenormalized FNT: Normal: (0, 0, 36). Magnitude: 36
Normalized FNT: Normal: (0, 0, 1). Magnitude: 0
v1: Vertex: (12, 0, 3)
v2: Vertex: (18, 0, 3)
v3: Vertex: (18, 0, -3)
new v1: Vertex: (-6, 0, 0)
new v2: Vertex: (0, 0, 6)
n1: Normal: (-6, 0, 0). Magnitude: -6.28885e-29
n2: Normal: (0, 0, 6). Magnitude: -6.28885e-29
n3: Normal: (0, 36, -0). Magnitude: -6.28885e-29
Result: Normal: (0, 36, -0). Magnitude: 36
Prenormalized FNT: Normal: (0, 36, -0). Magnitude: 36
Normalized FNT: Normal: (0, 1, -0). Magnitude: 0
Some of the magnitude calculations look incorrect.
First of all, a normalized vector, is NOT necessarily a normal vector. In lay terms, a normal vector is a vector which is perpendicular to a surface. A normalized vector is a vector which has a magnitude of 1. These are completely different concepts. For OpenGL, I think that normal vectors have to be unit vectors, which means that they have to be normalized.
It may help you to know what the cross product does. Given two vectors that are NOT colinear, their cross product gives you a third vector that is perpendicular to BOTH of them. Think of it this way: two vectors define a plane that passes through both of them, the cross product then creates a vector which is perpendicular to both these vectors, and thus perpendicular to the plane. Why do we need to find the vector which is perpendicular to a plane? Because the shade of the plane depends on the angle at which light hits it, relative to the viewer. In other words, the normal (i.e. the vector perpendicular to the plane) is a way of measuring the orientation of the plane.
And how about vertex normals? Certain smooth shading techinques (most notably Phong) calculate a vertex normal (the average of the normals of all adjacent polygons) for each vertex of a polygon. Then as the polygon is rasterized, the shade of each pixel is determined by the incidence of light on the polygon relative to a "normal vector" which is an interpolation of all the vertex normals of the polygon.
First of all, a normalized vector, is NOT necessarily a normal vector. In lay terms, a normal vector is a vector which is perpendicular to a surface. A normalized vector is a vector which has a magnitude of 1. These are completely different concepts. For OpenGL, I think that normal vectors have to be unit vectors, which means that they have to be normalized.
It may help you to know what the cross product does. Given two vectors that are NOT colinear, their cross product gives you a third vector that is perpendicular to BOTH of them. Think of it this way: two vectors define a plane that passes through both of them, the cross product then creates a vector which is perpendicular to both these vectors, and thus perpendicular to the plane. Why do we need to find the vector which is perpendicular to a plane? Because the shade of the plane depends on the angle at which light hits it, relative to the viewer. In other words, the normal (i.e. the vector perpendicular to the plane) is a way of measuring the orientation of the plane.
And how about vertex normals? Certain smooth shading techinques (most notably Phong) calculate a vertex normal (the average of the normals of all adjacent polygons) for each vertex of a polygon. Then as the polygon is rasterized, the shade of each pixel is determined by the incidence of light on the polygon relative to a "normal vector" which is an interpolation of all the vertex normals of the polygon.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
Normals? | Quicksilver | 3 | 2,970 |
Jan 13, 2003 05:31 PM Last Post: henryj |