Advertisement

lighting and normals

Started by October 14, 2003 01:48 PM
5 comments, last by coke_baby 21 years, 4 months ago
hola peeps firstly, thanks to nehe and everyone here for being a great help in my slow but steady progress in opengl...yay! i''m having a problem with lighting which i''m sure a few people have come across - only when i try to search at the minute i''m getting server errors of some sort..and nothing happens. right.. it seems to be an issue with the normals that i''m using. As you know, opengl needs to know the normals of each face in order to light everything properly (normals being unit vectors perpindicular to the face). background - i''m adding a little ASE file importer so that i can make files in 3ds max. At the minute it''s just a mod to tut 10 (i think - the one that imports a world.txt file) that imports one object from an .ase file. anyway, the ase file contains both face and vertex normals, and i''m sticking with only face normals for now. everything is drawn as triangles, and the wierd thing is that for some rectangles (made of two triangles) the two triangles that make it up are visible, as it would seem the normals are screwed on one triangle. so a cube will look like it''s got diagonal lines across it''s faces - and more complex objects (like a teapot) look chequered. I don''t know why this is, as i''ve tried both using normals i calculate from the vertex list myself and also the ones exported by 3ds max, with the same result... anyone got any ideas? thanks for any help you can offer!
This is perhaps because you are only using the face normals. When only using the face normals, the shading will appear flat. You should instead use the vertex normals, since you already have them in the file. This will give a smoother look to the surface, and probably eliminate the problem you were reffering to.
Advertisement
cheers- but it''s defintely not that. i know what you mean, that the most i should expect is flat surface shading, but the point is that two polygons (ie: triangles) that make up a face on the same plane (e.g: a rectangle) shouldn''t show any difference in lighting, as their normals should be identical. I''m getting differences in lighting on *the smae plane*, which is confusing me. and especially since they''r ebeing exported by 3dsmax, the figures should be correct...

btw.. if i was to use vertex normals, how would i use this as i draw triangles? if i set the normal as below, with vNOR[n] being the 3 components of the normal vector, can i actually set it per vertex? at the moment i set it after i''ve drawn the triangle..

glNormal3f( vNOR[0], vNOR[1], vNOR[2]);

cheers for your thoughts =)
chekered? maybe some of your faces are facing the other way? remember to always feed your vertices counter clockwise.
Enable back face culling, if some surfaces dont show, its because they are backwards.

Proud aedGUI developer.
i considered this but thought that the way the ase file is created should cover that - it has a list of vertices, then for each face, an index referring to the vertices to use in order. i would have thought that this would have been consistent, and if i''m reading from a random file there''s no way i can tell which direction the vertices should be ordered... i''ve researched the ase file a little, and nothings come up about there being consistency problems with vertex order. i know there are differences between xyz and xzy ordering, but i''ve taken that into account, and that shouldn''t affect the normals if the geometry is ok.

anyone else?
quote:
Original post by coke_baby
at the moment i set it after i''ve drawn the triangle..


That would be your problem then. You need to set it before you draw the triangle. Remember that openGL is a state machine. You set a state and all drawing commands use that state until the state is changed again. So:
glNormal3f(1, 0, 0);glVertex3f(2, 0, 0);glVertex3f(0, 2, 0);glNormal3f(0, 1, 0);glVertex3f(2, 2, 0);

will give you:
vertex at (2, 0, 0) with normal (1, 0, 0)vertex at (0, 2, 0) with normal (1, 0, 0)vertex at (2, 2, 0) with normal (0, 1, 0)

To use vertex normals you just set the normal immediately before you make each glVertex call.

Enigma
Advertisement
that seems to have fixed it - cheers! will definitely start using vertex normal too, if they''re that easy.
thanks a lot!!

This topic is closed to new replies.

Advertisement