Sign in to follow this  

Lighting problems, please help

This topic is 4057 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

Hi, I was just making a terrain loading and rendering problem when I encountered a very annoying and puzzling(for me) problem. When I face down the z axis one direction, the terrain is perfectly lit. When I turn around 180 degrees it is dark. It does not matter where I am for x,y,z coordinates, this always happens. I have some pictures below. Facing one direction: Facing 180 degrees turned around Facing midway between I hope you understand what I mean. Please help me. Thanks.

Share this post


Link to post
Share on other sites
Where is the light? What direction is it facing? (assuming it's directional) Overall, how have you got your lighting set up? [smile]

I'm assuming you're using fixed function lighting for a start.

It's hard to tell exactly what you mean without seeing it moving. At a guess it's one of 3 things:

1) your specular contribution is massively outweighing your diffuse.
2) your light orientation is being set relative to your camera
3) your light pointing in the direction you face originally, and away from you when you've turned 180.

You should be able to work it out by a process of elimination.

It sounds like the brightness of the terrain is actually changing as you move, rather than just being darker on one side - if so eliminate possibility 3.

You can eliminate possibility 1 by looking at your parameters, or by observing if the brightness changes based on your angle to face normals. Looking again at your shots, I'd say probably not.

So (shirlock holmes hat on) I deduce that it's probably possibility number 2. You'll need to change the order you set the camera and the light position.

Hope that helps

Share this post


Link to post
Share on other sites
Thanks alot for that. Well, you said something about specular outweighing the difuse, and actually I did not even set diffuse, only specular. Also, I haven't calculated normals on the terrain(i guess that might be the problem). I'm not completely sure about what you mean in 2 and 3 but it seems that one of those could be a problem in my instance.

Here is my light definition arrays:

GLfloat lightdir[] = {0.0,1.0,0.0,1.0};
GLfloat sun[] = {.9,1.0,1.0,1.0};
GLfloat sunamb[] = {.15,.3,.3,1.0};

and the light def:

glEnable(GL_LIGHING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, lightdir);
glLightfv(GL_LIGHT0, GL_AMBIENT, sunamb);
glLightfv(GL_LIGHT0, GL_SPECULAR, sun);

and thats it. I hope that helps. Thanks again.

Share this post


Link to post
Share on other sites
I used to have the same problem. Heres the solution:

When you enable your light: also call your transforms that your terrain goes through.




glLoadIdentity();

enable light

glRotatef(up_angle, 1, 0, 0);
glRotatef(angle,0,1,0);
glTranslatef(-camera_xpos,-camera_ypos,-camera_zpos);



glLoadIdentity();
glRotatef(up_angle, 1, 0, 0);
glRotatef(angle,0,1,0);
glTranslatef(-camera_xpos,-camera_ypos,-camera_zpos);

DrawTerrain();

peace.

if you dont understand why you have to do that, then just repost.

Share this post


Link to post
Share on other sites

This topic is 4057 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