Normals

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
pin3
Posts: 108
Joined: Fri Oct 06, 2006 8:50 pm
Contact:

Normals

Post 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
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post 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.
pin3
Posts: 108
Joined: Fri Oct 06, 2006 8:50 pm
Contact:

Post 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
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

That is because there are 3 vertices per each corner in this case. otherwise cube would not have sharp edges (sharp lighten).
pin3
Posts: 108
Joined: Fri Oct 06, 2006 8:50 pm
Contact:

Post 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?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post 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.
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post 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?
Never take advice from someone who likes to give advice, so take my advice and don't take it.
Kojack
Posts: 67
Joined: Sun Jan 20, 2008 2:39 am

Post 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.
Post Reply