Skip to main content

normals

Submitted by Triton on

I'm using the left handed system here

----2
---/---/----/-----1_______0

When creating the vectors from the vertices my sketchy research has found two different ways.

(p1-p0) x (p2-p1) This produces a normal -z (guess)
or
(p1-p0) x (p2-p0) This produces a normal +z (guess)

Hmmm ok, so i guess my question is what are normals used for? And do i want +z or -z.. or would you use both +z and -z for different things? Also, are either of the above equations right or wrong?

I really don't know what i'm talking about here so any help is appreciated.

Submitted by davidcoen on Thu, 09/12/04 - 2:08 AMPermalink

normals can be used for lighting, once normalised (if you make a vector(x,y,z) to be one unit long, it is said to be normalised)

if you want to find the normals of a triangle's vertices, then your cross product of (p1 - p0) x (p2 - p1) would give the un-normalised vertex normal....

Submitted by tachyon on Thu, 09/12/04 - 8:41 AMPermalink

a normal vector is the vector that is perpendicular to a surface. so, it basically describes which way a surface is pointing, which as davidcoen mentioned is very useful for lighting, especially when used something like normal mapping, can give the illusion of a complex surface from a simple surface. (basically, you have a texture with all the normal information, which can be applied to a surface)

Submitted by Triton on Thu, 09/12/04 - 9:31 AMPermalink

Yea i'm pretty sure i understand the concept behind it but i was having trouble choosing the right vertices to create the vectors. I was getting confused with the "winding order". Tutorials were saying it's important which order you choose your vectors, but i think it's the order which you set your vertices, clockwise counter-clockwise (at least with the example i was working with).

One tutorial i read from gametutorials.com said

quote:The winding order of the vertices determines how you want to create your vectors. If you winding order is clockwise, you want to create your vectors so that the head of the first vector touches the tail of the second vector with a clockwise turn and then cross the second vector with the first.

And then subtracted like this, p1-p0 and p2-p1. From what i gather it seemed to work. Yet everywhere else that i've read they subtracted from the one point e.g p1-p2 p3-p2.

I guess that's where i was getting confused, i think i've got it sorted now.

Thanks for the help though [:)]

Submitted by Daemin on Thu, 09/12/04 - 11:32 PMPermalink

It just depends where you want the normal to "face". As if you create the normal with the reverse winding order it will point in the opposite direction. Therefore it's just a matter of figuring out which direction you want to be the front face for the triangle.

Submitted by arcane on Fri, 10/12/04 - 12:25 PMPermalink

quote:Originally posted by Daemin

It just depends where you want the normal to "face". As if you create the normal with the reverse winding order it will point in the opposite direction. Therefore it's just a matter of figuring out which direction you want to be the front face for the triangle.

...and then keeping that consistent throughout the whole world data.

Submitted by mcdrewski on Fri, 10/12/04 - 7:03 PMPermalink

quote:Originally posted by Triton
[code]
----2
---/---/----/-----1_______0
[/code]

When creating the vectors from the vertices my sketchy research has found two different ways.

(p1-p0) x (p2-p1) This produces a normal -z (guess)
or
(p1-p0) x (p2-p0) This produces a normal +z (guess)

Hmmm ok, so i guess my question is what are normals used for?

Sorry for the kindy tute to all the gurus, but hopefully it'll explain something useful.

Well, in nice, simple cartesian (x,y,z) space, the cross product gives you a vector orthogonal to (at 90deg to) the two crossed vectors. If the two crossed vectors are already orthogonal, then the cross product gives you what's called an "orthogonal set" of vectors - ie: they're all orthogonal to each other. An 'n'-dimensional space requires 'n' orthogonal vectors to identify any point in it.

Now, any two vectors (*except two collinear ones) define a plane. The 'normal' to the plane (defined by the two vectors) is the cross product of those vectors.

This means that the normal is just the vector orthogonal to the two vectors you've chosen. In a triangle (the bread-and-butter of 3d graphics for this very reason) you have three vertices (0,1,2 in your diagram), hence three vectors clockwise (p1-p0 , p2-p1 , p0-p2), or three vectors anti-clockwise (p2-p0 , p0-p1 , p1-p2). However, the very concept of clockwise or anti-clockwise means that the triangle/poly you're talking about has a 'front'. The convention is that the normal should also point toward the 'front'.

So, two very simple cases in which it's used:

1) Flat shading. Take the normal generated by the two vectors attached to any vertex, and use that to work out how much light from our light source is reaching that face. Change your colour accordingly (i'm white, but 50% of red light is reaching me, I'll look pink)

2) Backface culling. If i'm looking at a polygon, and the normal is pointing 'away' from me, then I'm looking at the back of the polygon. In most cases, models are built so that backfaces can't be seen (ie: they're inside the sphere/helmet/orc), meaning that there's always a corresponding front-face which will be drawn over the back face. Hence, it makes your rendering faster because you don't need to do all the lighting calculations for back-faces.

Now, "normal maps" and the like are simply ways of saying "you think the normal here is blah, based on the polys, but I want you to pretend that the normal is actually like this. ie: pretend this nice big flat bit is actually pitted like a dried lemon skin. This affects the lighting, and hence the cool facter that we all want.

Please, feel free to correct me gurus :)

Posted by Triton on

I'm using the left handed system here

----2
---/---/----/-----1_______0

When creating the vectors from the vertices my sketchy research has found two different ways.

(p1-p0) x (p2-p1) This produces a normal -z (guess)
or
(p1-p0) x (p2-p0) This produces a normal +z (guess)

Hmmm ok, so i guess my question is what are normals used for? And do i want +z or -z.. or would you use both +z and -z for different things? Also, are either of the above equations right or wrong?

I really don't know what i'm talking about here so any help is appreciated.


Submitted by davidcoen on Thu, 09/12/04 - 2:08 AMPermalink

normals can be used for lighting, once normalised (if you make a vector(x,y,z) to be one unit long, it is said to be normalised)

if you want to find the normals of a triangle's vertices, then your cross product of (p1 - p0) x (p2 - p1) would give the un-normalised vertex normal....

Submitted by tachyon on Thu, 09/12/04 - 8:41 AMPermalink

a normal vector is the vector that is perpendicular to a surface. so, it basically describes which way a surface is pointing, which as davidcoen mentioned is very useful for lighting, especially when used something like normal mapping, can give the illusion of a complex surface from a simple surface. (basically, you have a texture with all the normal information, which can be applied to a surface)

Submitted by Triton on Thu, 09/12/04 - 9:31 AMPermalink

Yea i'm pretty sure i understand the concept behind it but i was having trouble choosing the right vertices to create the vectors. I was getting confused with the "winding order". Tutorials were saying it's important which order you choose your vectors, but i think it's the order which you set your vertices, clockwise counter-clockwise (at least with the example i was working with).

One tutorial i read from gametutorials.com said

quote:The winding order of the vertices determines how you want to create your vectors. If you winding order is clockwise, you want to create your vectors so that the head of the first vector touches the tail of the second vector with a clockwise turn and then cross the second vector with the first.

And then subtracted like this, p1-p0 and p2-p1. From what i gather it seemed to work. Yet everywhere else that i've read they subtracted from the one point e.g p1-p2 p3-p2.

I guess that's where i was getting confused, i think i've got it sorted now.

Thanks for the help though [:)]

Submitted by Daemin on Thu, 09/12/04 - 11:32 PMPermalink

It just depends where you want the normal to "face". As if you create the normal with the reverse winding order it will point in the opposite direction. Therefore it's just a matter of figuring out which direction you want to be the front face for the triangle.

Submitted by arcane on Fri, 10/12/04 - 12:25 PMPermalink

quote:Originally posted by Daemin

It just depends where you want the normal to "face". As if you create the normal with the reverse winding order it will point in the opposite direction. Therefore it's just a matter of figuring out which direction you want to be the front face for the triangle.

...and then keeping that consistent throughout the whole world data.

Submitted by mcdrewski on Fri, 10/12/04 - 7:03 PMPermalink

quote:Originally posted by Triton
[code]
----2
---/---/----/-----1_______0
[/code]

When creating the vectors from the vertices my sketchy research has found two different ways.

(p1-p0) x (p2-p1) This produces a normal -z (guess)
or
(p1-p0) x (p2-p0) This produces a normal +z (guess)

Hmmm ok, so i guess my question is what are normals used for?

Sorry for the kindy tute to all the gurus, but hopefully it'll explain something useful.

Well, in nice, simple cartesian (x,y,z) space, the cross product gives you a vector orthogonal to (at 90deg to) the two crossed vectors. If the two crossed vectors are already orthogonal, then the cross product gives you what's called an "orthogonal set" of vectors - ie: they're all orthogonal to each other. An 'n'-dimensional space requires 'n' orthogonal vectors to identify any point in it.

Now, any two vectors (*except two collinear ones) define a plane. The 'normal' to the plane (defined by the two vectors) is the cross product of those vectors.

This means that the normal is just the vector orthogonal to the two vectors you've chosen. In a triangle (the bread-and-butter of 3d graphics for this very reason) you have three vertices (0,1,2 in your diagram), hence three vectors clockwise (p1-p0 , p2-p1 , p0-p2), or three vectors anti-clockwise (p2-p0 , p0-p1 , p1-p2). However, the very concept of clockwise or anti-clockwise means that the triangle/poly you're talking about has a 'front'. The convention is that the normal should also point toward the 'front'.

So, two very simple cases in which it's used:

1) Flat shading. Take the normal generated by the two vectors attached to any vertex, and use that to work out how much light from our light source is reaching that face. Change your colour accordingly (i'm white, but 50% of red light is reaching me, I'll look pink)

2) Backface culling. If i'm looking at a polygon, and the normal is pointing 'away' from me, then I'm looking at the back of the polygon. In most cases, models are built so that backfaces can't be seen (ie: they're inside the sphere/helmet/orc), meaning that there's always a corresponding front-face which will be drawn over the back face. Hence, it makes your rendering faster because you don't need to do all the lighting calculations for back-faces.

Now, "normal maps" and the like are simply ways of saying "you think the normal here is blah, based on the polys, but I want you to pretend that the normal is actually like this. ie: pretend this nice big flat bit is actually pitted like a dried lemon skin. This affects the lighting, and hence the cool facter that we all want.

Please, feel free to correct me gurus :)