Shading

Started by
8 comments, last by messiah2k 21 years, 12 months ago
Hello in my opengl program I have some code that reads a 3ds file. I have calculated the normals and lit the scene. But the models look quite blocky. The polygons seem to only have one nuance of light. I think it''s called gouraud shading what I''m looking for. Does anybody know or know tutotials about this ? I would prefer some non glut stuff. //messiah2k
//Messiah
Advertisement
gouraud shading is with
glShadeModel( GL_SMOOTH )
does each vertice have a seperate normal!

http://uk.geocities.com/sloppyturds/gotterdammerung.html
hmmm... I have tested glShadeModel( GL_SMOOTH ) and I get the same blocky results. I''m not 100% sure that the normals are right... but if they where wrong I wouldn''t get any light at all. Could I do something else wrong ?

//messiah
//Messiah
wrong normals (non unit length, wrong direction) will mess up lighting, check that first.

Smooth the normals by making an average normal of all those being at that vertex. (and normalize it!)

Maybe your model simply is blocky ^^
check that with a free viewer.

-* So many things to do, so little time to spend. *-
-* So many things to do, so little time to spend. *-
Okey.. thanks... I checked my model in a differant viewer and it looks very smooth. But I don''t see what i should do with a normal that is the average of all the normals ?
//messiah
//Messiah

glEnable(GL_NORMALIZE);

...will tell OpenGL to normalise all normal vectors, you will probably need this, especially if you''re scaling the object.

If you''re only ever going to use uniform scaling i.e. same scale factor in each axis then you can use GL_RESCALE_NORMAL which can be faster in certain implementations.
The following is from the red book...

To find the normal for a flat polygon, take any three vertices v1, v2 and v3 of the polygon that do not lie in a straight line. The cross product

[v1-v2] x [v2-v3]

is perpendicular to the polygon (i.e. the normal).

Then you need to average the normals for adjoining faces.

e.g. if n1, n2, n3 and n4 are four quad polygons meeting at a point P then the normal for P would be the sum of the normals of n1..4. This would usually require normalisation, however if you have enabled GL_NORMALIZE as above then you don''t need to bother.

-----------
| | |
| n1 | n2 |
| | |
|----P----|
| | |
| n3 | n4 |
| | |
-----------

Hope this works for you...
I assume you''re handling the 3DS''s shading groups?

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
thanks for the response. Yes I am scaling the 3ds object but the same scale factor everywhere.... i just want it a bit smaler som i guess i need to glEnable(GL_NORMALIZE);. I have no clue about what the 3DS''s shading groups are so I guess I''m not handling them. I just read the verteces.

//Messiah
//Messiah
I posted my last message when I was in work, I''m at home now so I can type a more decent response.

All faces in a 3DS file belong to a shading group. The shading groups tell you which faces should have smooth shading to which other faces. That should kinda make sense if you have a 3DS file reference there. If not you should be able to get one at http://www.wotsit.org

Happy parsing :-)

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

This topic is closed to new replies.

Advertisement