Sign in to follow this  

Strange lighting problem

This topic is 4093 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For some reason my objects are displaying almost-flat shaded. It doesn't matter where I put the light. It's not the normals (which were exported from max) -- the problem happens even when using a primitive like glutSolidSphere and I know that generates normals. What could be causing this? [img]http://img237.imageshack.us/img237/7010/lightingprobdz3.jpg[/img]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Yes, I am

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);

There IS lighting happening, and there IS shading happening...it's just not happening correctly.

I'm using the following material params, although, I have tried fussing with all these numbers and I get the same problems regardless of shininess, specularity, ambient, or diffuse lighting amts. The position of the light also does not make any difference. I have tried making the light follow the camera by only setting the lighting param once before the drawing func, or having it move by redrawing it on each frame...but regardless of whether or not I do this, and regardless of the values for light position, the light always seems to come from below, and from the back edges of objects...

GLfloat mat_specular[] = { .2, .2, .2, 1.0 };
GLfloat mat_shininess[] = { 0.5 };
GLfloat light_position[] = { -2.991, -25.599, 52.613 };
GLfloat light_pos_follow[] = { 0,0,0 };
GLfloat light_ambient[] = {0.0, 0.0, 0.0,0};
GLfloat light_diffuse[] = {0.1, 0.1, 0.05, .1};


glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_pos_follow);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);

Share this post


Link to post
Share on other sites
The jpg encoding made it difficult to understand what was happening, this should be a better image (why doesnt this forum display images?)

One of these might display...

[URL=http://imageshack.us][IMG]http://img98.imageshack.us/img98/3360/light2jw3.png[/IMG][/URL]

Image Hosted by ImageShack.us

http://img98.imageshack.us/img98/3360/light2jw3.png

Share this post


Link to post
Share on other sites
GLfloat light_position[] = { -2.991, -25.599, 52.613 };
GLfloat light_pos_follow[] = { 0,0,0 };


looks a little bit odd to me. The light array should have a size of 4. One component for each axis and a value for describing what type of light opengl is dealing with. If the last parameter is omitted you can't tell if it is a directional light or a point/spot-light. Directional lights are defined by 0, spot and point lights are 1.

Further reading...

Jouvieje OpenGL lighting tutorials

NeHe light tutorial

Share this post


Link to post
Share on other sites
Are your normal vectors set up properly? It looks like you are either using wrong normal vectors or they are pointing the wrong way. This may be caused by scaling, because the scene gets scaled, but the normal vectors don't. So, if you scale your scenes, you need to scale your normals too. The easiest way to do this is to enable GL_NORMALIZE.

-Riku

Share this post


Link to post
Share on other sites
Quote:
The light array should have a size of 4.


Ok. I added another 1 to the end. It didn't change anything.

Quote:
Are your normal vectors set up properly?


GL_NORMALIZE is already enabled, and I have the same problem if I try to use glutSolidSphere that comes with normals

Share this post


Link to post
Share on other sites

This topic is 4093 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this