Odd Normals and Lighting
the only transformation there is is when i move the camera. nothing else moves. im using gluLookAt() if that helps any.
quote:
Original post by MV
I solved some troubles with this
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
Dont really know what first line means... maybe some kind of ligth positioning viewer vs univers ?
Hope it will help
The first line
only matters if you are using specular lighting.. If this parameter is set to true, it will take the angle between the light and the polygon into account when calculating the specular highlight...
adam17,
python_regious is correct, I had the same problem. Add a line to position the light (i.e. glLightfv(GL_LIGHT0, GL_POSITION,LightPosition)) just after you''re GLULookAt(). This should make the light source stay in the position you wanted.
python_regious is correct, I had the same problem. Add a line to position the light (i.e. glLightfv(GL_LIGHT0, GL_POSITION,LightPosition)) just after you''re GLULookAt(). This should make the light source stay in the position you wanted.
let me get this straight. i need to call glLightfv.... on every loop through the drawing loop? doesnt that use a lot of power?
It needs to be called once per frame (just as GLULookAt should only need to be called once per frame). I haven''t noticed much difference in efficiency.
First of all let's get things straight here..
What kind of lighting location are you looking for? The reason is if you enable GL_LIGHT_MODEL_LOCAL_VIEWER, but fix your light source at a fix point in world coordinate system, you will get a very unrealistc look of specular reflection. Because what happens is that all your diffuse lightnings will be from a local lightning source while your specular lightning will be calculate from a light source that shot out right from your eyes. (Or the way OpenGL ref book puts it, the direction of the light will alway be the -z axis from the projection plane).
Obviously this makes absolutely no sense at all, I mean why in the heck would you have specular and diffuse lightining coming from 2 different light position?
However, from the problem you have described, you must have the light glued on your camera instead of fixing in a position in a space. I am not sure whether this is your true intention because to me in a 3D scene this kind of effect is usually less desirable (unless you are doing a scene where you are travelling in a mine and you are wearing a helmet with head lights).
As for the original problem, you have solved it using GL_LIGHT_MODEL_TWO_SIDE,. I don't believe GL_LIGHT_MODEL_LOCAL_VIEWER has anything to do with this problem. Now the reason why it's like this is your all the normals of your triangle must be facing front. Imagine the sphere you have actually has a lot of spikes coming out from the center. Then all those spikes will be the normals of your sphere. In another word, normals are the vectors that defines which way the polygons are facing. The thing is the normals of your triangles must be facing front, so when you bring your camera AND the light to the back, the OpenGL thinks that the entire triangle is facing the wrong way (since the polygons are facing away from the light, or in a more mathmatical way, the angle between the light vector and the normal vector is greater than 180 degrees). As a result, they will be completely dark. GL_LIGHT_MODEL_TWO_SIDE solves this problem because what happens is that whenthis mode being enabled, whenever OpenGL sees you have a normal that is facing away from the light vector (greater than 180 degrees), they will reverse it so they become less than 180 degrees. This allows it to apply light on them.
[edited by - Xenogear on July 20, 2003 6:16:17 PM]
What kind of lighting location are you looking for? The reason is if you enable GL_LIGHT_MODEL_LOCAL_VIEWER, but fix your light source at a fix point in world coordinate system, you will get a very unrealistc look of specular reflection. Because what happens is that all your diffuse lightnings will be from a local lightning source while your specular lightning will be calculate from a light source that shot out right from your eyes. (Or the way OpenGL ref book puts it, the direction of the light will alway be the -z axis from the projection plane).
Obviously this makes absolutely no sense at all, I mean why in the heck would you have specular and diffuse lightining coming from 2 different light position?
However, from the problem you have described, you must have the light glued on your camera instead of fixing in a position in a space. I am not sure whether this is your true intention because to me in a 3D scene this kind of effect is usually less desirable (unless you are doing a scene where you are travelling in a mine and you are wearing a helmet with head lights).
As for the original problem, you have solved it using GL_LIGHT_MODEL_TWO_SIDE,. I don't believe GL_LIGHT_MODEL_LOCAL_VIEWER has anything to do with this problem. Now the reason why it's like this is your all the normals of your triangle must be facing front. Imagine the sphere you have actually has a lot of spikes coming out from the center. Then all those spikes will be the normals of your sphere. In another word, normals are the vectors that defines which way the polygons are facing. The thing is the normals of your triangles must be facing front, so when you bring your camera AND the light to the back, the OpenGL thinks that the entire triangle is facing the wrong way (since the polygons are facing away from the light, or in a more mathmatical way, the angle between the light vector and the normal vector is greater than 180 degrees). As a result, they will be completely dark. GL_LIGHT_MODEL_TWO_SIDE solves this problem because what happens is that whenthis mode being enabled, whenever OpenGL sees you have a normal that is facing away from the light vector (greater than 180 degrees), they will reverse it so they become less than 180 degrees. This allows it to apply light on them.
[edited by - Xenogear on July 20, 2003 6:16:17 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement