Lighting problems, please help

Started by
3 comments, last by dpadam450 17 years, 5 months ago
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.
Advertisement
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
[size="1"]
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.
Ok first off, you need normals for lighting to work, 2nd why would you have specular lighting on terrain?
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.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement