Advertisement

Texture/Lighting tutorial (normals)

Started by December 25, 2000 03:50 PM
9 comments, last by kill 24 years, 1 month ago
I noticed that in tutorial 7 normals are specified per polygon. However, someone on this board told me that for smooth shading the normals should be specified for each vertex, not each face. I wonder if this information is correct and if NeHe knew about it and intentionally specified the normal for the face, not each vertex
quote:
Original post by kill

I noticed that in tutorial 7 normals are specified per polygon. However, someone on this board told me that for smooth shading the normals should be specified for each vertex, not each face. I wonder if this information is correct and if NeHe knew about it and intentionally specified the normal for the face, not each vertex


You can specify normals per vertex of each polygon but they would have to be the same vector if you want the polygon to be shaded correctly. If you use, for example, glNormal3f() function to specify a normal then that normal stays in effect until another call to the glNormal*() functions is made.

Using different normals with different vertices of the same polygon will cause unexpected results with shading. Actually, I read somewhere that you can use this to achieve some special effects but I can''t remember what it was...



------------------------------------------------
DaWizard
http://members.home.com/ahmadkabani
http://www.geocities.com/ahmadkabani
------------------------------------------------
------------------------------------------------DaWizardhttp://www.geocities.com/ahmadkabani------------------------------------------------
Advertisement
Everyone gives me different information


quote:
Original post by kill

Everyone gives me different information





If you''re not convinced, try a simple demo:
1. Enable Lighting and setup a light source.
2. Use glBegin(GL_QUAD), specify the same normal 4 times for the 4 vertices and see the result.
3. Use glBegin(GL_QUAD) again, but specify only one normal before specifying the 4 vertices. The result will be the same.

Get a hold of the Red Book. It explains the use of the normals and lighting in-depth.



------------------------------------------------
DaWizard
http://members.home.com/ahmadkabani
http://www.geocities.com/ahmadkabani
------------------------------------------------
------------------------------------------------DaWizardhttp://www.geocities.com/ahmadkabani------------------------------------------------
I''m sure the result will be the same, I understand what you mean. But as far as I know the vertex normal is calculated differently from the face normal. The vertex normal does not equal the face normal. I''m not sure how it''s calculated, I think it has something to do with averaging the normals of all faces that share this vertex. This is why I am asking my question. If the vertex normal would be equal to the face normal you would definetly be right...
quote:
Original post by kill

I''m sure the result will be the same, I understand what you mean. But as far as I know the vertex normal is calculated differently from the face normal. The vertex normal does not equal the face normal. I''m not sure how it''s calculated, I think it has something to do with averaging the normals of all faces that share this vertex. This is why I am asking my question. If the vertex normal would be equal to the face normal you would definetly be right...


Oh... and I thought you were talking about something else! I saw a similar thing somewhere. I guess you would simply calculate average of x values, average of y values and average of z values of all the normal vectors of all polygons that share that vertex. But then you''d end up doing extra calculations!

In my opinion, use the same normal vector for all vertices of one polygon and then a different normal vector for all vertices of a second polygon regardless of whether the two polygons share vertices. Its simple and it works.


------------------------------------------------
DaWizard
http://members.home.com/ahmadkabani
http://www.geocities.com/ahmadkabani
------------------------------------------------
------------------------------------------------DaWizardhttp://www.geocities.com/ahmadkabani------------------------------------------------
Advertisement
vertex normals are used for smooth shading
face normals for flatshading


for parametric surfaces(those that can be speicifed by equations), u can differentiate the equations at the vertex point n do some math to get the vertex normal.

for random meshes calculate face normals for all faces that share this vertex n then average them to get vertex normals.
the red||blue book has a very good appendix on normal calculations

...from my computer grfx course
So again, in OGL which way is the correct way of doing things for smooth shading? Specifying a normal for each face or specifying a normal for each vertex?
Ok.. to clear this up:

for Flat-Shading use 1 normal per polygon.


for Smooth-shading one per vertex, the thing is, that if you''ve got an mesh with polygons that share 1 vertex, you a approximate the vertex by adding all the normals of the faces that share that vertex and divide them by the number of normals you added. (a statistic middle). At least that''s the way i''d do it...
cya,
Phil


Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states
Visit Rarebyte! and no!, there are NO kangaroos in Austria (I got this question a few times over in the states ;) )
Take a look at here:

He has a tutorial that explains how to calculate vertex normals, and for what they are used for..

http://nate.scuzzy.net/normals/normals.html

hope it helps
Bruno

This topic is closed to new replies.

Advertisement