Archived

This topic is now archived and is closed to further replies.

Keeping the sun in position

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

Recommended Posts

I appear to be having some trouble properly lighting a scene: The sun''s position is fixed to the camera instead of the world, and thus the shadows are shifting all over the place whenever the player moves around. I have read in a few places that you fix this by setting the light position after applying the camera transformations. I can not get that working though, if i call glLightfv with GL_POSITION after setting up my camera transformations it just turns of lighting altogether, even if i glDisable the light first and then glEnable it again after changing the position. Can anyone see what goes wrong here? Any source code doing it right (moving the camera while keeping the light in place)? Marijn

Share on other sites
Here''s some pseude code from my project:
mainloop{  glLoadIdentity(); //Reset transformation matrix  gluLookAt(...);   //Set the camera  for(each.light)  {    glPushMatrix();  //Save transformation matrix        glTranlated(...);    glLightfv(light.name,GL_POSITION,{0,0,0,0});    glPopMatrix();  //Restore transformation matrix  }  for(each.object)  {    object.insert();  }}

Share on other sites
Allright, that is pretty much what i was doing so i guess something else goes wrong. The code that is supposed to pick the right GL_LIGHTX light-id is a little shady so maybe i do something wrong there. Any particular reason for tranlating to the light position and then setting it to 0,0,0,0 instead of using the light position right away? Isn''t 0,0,0,0 illegal anyway? How can a point at (0,0,0) lay at infinity? Confusing, some of this openGL stuff.

Marijn

Share on other sites
Yes, what you''re saying is true. My reason for doing this was that my light does not only have a position, but also a rotation. You can make the lights rotate about a certain point. Otherwise it''s fine to put the light at the position directly.

No, {0,0,0,0} is not elegal, but wrong in this case anyways. It should have been {0,0,0,1}.

{0,0,0,1} is a point at position {0,0,0}
{0,0,0,0} is a vector(!), pointing into the direction {0,0,0} (which is not a direction == null-vector).

A light at (1,0,0,1) is at position 1,0,0. If you change your position the light will remain there.

A light at (1,0,0,0) is coming from the direction of 1,0,0 (=above). If you change your position the light will still come from the same direction.

Share on other sites
Problem solved.
It turns out that moving the light did not turn off lighting, it just moved the light to a position where my whole scene (only a heightmap with not too much height difference) was lit very brightly without noticable shadows. When i did not reposition my light (properly) the light ended up on the horizon and thus more contrast was created, and the scene looked actually ''lit''. Doh!

• 10
• 18
• 14
• 18
• 15