Page 1 of 1

Normals

Posted: Wed Mar 10, 2010 9:46 am
by pin3
I`m trying to figure out how normals work. I`m using a custom scene node and the normal values in the c s n tutorial don`t make sense to me

Posted: Wed Mar 10, 2010 2:26 pm
by CuteAlien
Not sure what you need to know. A normal is a direction vector (an arrow showing you the direction) which is perpendicular to a surface. For example on the floor it would be straight up (or down). Don't confuse it with normalized vectors which is something different and just means that a vector as a length of exactly 1. You can calculate a normal if you have at least 2 edges on an area which are not parallel using the so called cross-product (just a formula). Maybe a little confusing can be vertex normals, because being at the corners between polygons they don't really have a surface to which they can be perpendicular. So usually people calculate for example the average of the normals of all adjacent polygons.

Posted: Wed Mar 10, 2010 3:40 pm
by arras
In computer graphics normals are used to calculate light on vertex. If normal and light vector are exactly opposite, maximum light is thrown on vertex ...vertex is facing light source. Bigger the angle between two, less light is on vertex and if light vector and normal are the same, no light is on vertex ...its facing opposite direction from incoming light.

So basically normal of vertex is used to express direction vertex is facing. Normals should be exactly one unit long.

Posted: Thu Mar 11, 2010 10:25 am
by pin3
I know it's a perpendicular line per corner/vertex problem is I've seen also three perpendicular lines per corner(in cubes)

Each corner / vertex unites three or four surfaces each with its own own inclination. Which of three/four potential normals do I choose

Posted: Thu Mar 11, 2010 11:46 am
by hybrid
The ones that match your face orientation. For a correct cube implementation, you need all three normals at the corners, for each of the three faces meeting at that corner.

Posted: Thu Mar 11, 2010 1:04 pm
by arras
That is because there are 3 vertices per each corner in this case. otherwise cube would not have sharp edges (sharp lighten).

Posted: Thu Mar 11, 2010 4:38 pm
by pin3
So you can only have a normal per vertex so If I use indices in a cube (to keep the vertex count low) then I can't have the cube properly lit because I can't have more than 8 normals?

Posted: Thu Mar 11, 2010 6:22 pm
by arras
Exactly. If you want to have sharp edge between faces (any faces) then you need to split vertices, rising their count. However polygon count remains the same and while vertex count do matter a little bit, its polycount which really kills performance.

Posted: Wed Sep 08, 2010 4:02 pm
by Bate
hybrid wrote:For a correct cube implementation, you need all three normals at the corners, for each of the three faces meeting at that corner.
arras wrote:That is because there are 3 vertices per each corner in this case. otherwise cube would not have sharp edges (sharp lighten).
Well, that means 24 vertices for a cube, right?
Then why does createCubeMesh only use 12?

Also, what about shared normals:
Image

Wouldn't 8 vertices suffice like that?

Posted: Fri Sep 10, 2010 9:33 am
by Kojack
Wouldn't 8 vertices suffice like that?
It would, if you don't have textures and don't want correct lighting.

createCubeMesh has 12 vertices because although it's normals are like in your pic (resulting in trying to light the cube like a sphere instead of a cube), you can't have just 8 vertices without some of the faces being textured wrong.

24 vertices allows you to have correct lighting and correct texturing.