Lighting and normals

Started by
4 comments, last by ykarj 21 years, 9 months ago
I believe this is a fairly easy issue to solve, I just can''t seem to do it myself I have some planes, each with a different slope and consisted of many polygons. I draw them without lighting and everything is fine. with lighting they seem to flicker and are ''animated'' (a different part is drawn every frame) when moved forward. anyway, since without lighting the model looks fine so I thought maybe my normals are wrong. and if not, I don''t know what''s wrong. any ideas? btw.. for the following triangle: v1 = -100, -68.8690, -87.4022 v2 = -90, -68.8690, -87.4022 v3 = -90, -70.8327, -99.7772 my normal is 0, 0.987643, -0.156720 which I believe is correct. Yuval Karjevski
Advertisement
remember that the position of a light is modified by the current model-veiw matrix. you are probably setting the position of the lightsource in a place where it is transformed by some altered matrix. make sure to define the position of the light source inside your draw loop but where it will not be effected by any transformed matrices.

-me
Palidine: the light is set up good, the problem is flickering of the polygons and not wrong light position.

I know that because I had hell with that too
well, my poligonal flickering was caused first by setting the position of my light outside of the draw loop (only in the init function). Then later on when i put it in the draw loop in a place where there was a transformed matrix that related to the position of my camera. as i moved the camera that matrix changed, and so did the position of the light source. so flickering from 2 different causes, both to do with matrix transforms.

the other flickering i have now has to do with z-buffering the draw screen, but that''s only at places where 2 meshes overlap closely.

the other thing to check for is to make sure that your normals aren''t getting messed with. it could be that something is transforming those too as you move around. if the normals end up being transformed (especially rotated) away from the direction of the light source, the poly will go black. what i ended up doing to solve that problem was creating a special drawNormals function that makes little red lines at each vertex representing the normals using GL_LINES. since it has to be in it''s own glBegin/glEnd i make a seperate loop through the objects, EXACTLY the same as the loop to draw them in the first place (make sure to push all the same rot matrices). then at every vertex call i make another vertex call like: glVertex3f(x + normal.x, y + normal.y, z + normal.z); where x,y,z are the poly''s vertex. and there''s your normal drawn....

bottom line, matrices screw with lighting....

-me
oohhh... Z buffering.
guess that''s something to look at.

btw: I took the code and ran it on my geforce3 at home, works fine. at work i ran it on an ati radeon 7000.
quote:Original post by ykarj
btw: I took the code and ran it on my geforce3 at home, works fine. at work i ran it on an ati radeon 7000.


meaning there is no flickering problem on the geforce3??

-me

This topic is closed to new replies.

Advertisement