Skip to main content
gamedev.net
🔒 Locked

Lighting space

Started by space warp 2 replies 550+ views
Original Post
space warp
space warp
Hello, I have a large space scene in OpenGL and since the sun will be far away then all objects should have light comming from the same direction. But lights in OpenGL (as I know them) are relative to the camera but I want the light to always stay at the same place in global coordinates. Is this possible? Or is there a way to make directional lights in OpenGL? This would be ideal since it is that effect that I am looking for.
.sehkteeah erthyahr gahro
jouley
jouley
Quote:
Original post by space warp
Hello,
I have a large space scene in OpenGL and since the sun will be far away then all objects should have light comming from the same direction. But lights in OpenGL (as I know them) are relative to the camera but I want the light to always stay at the same place in global coordinates. Is this possible?

Actually, lights are not always relative to the camera. Light positions are subject to the same transformations that other (vertex, etc.) positions are. From the docs:
Quote:
Original post by OpenGL
The position is transformed by the modelview matrix when glLight is called (just as if it were a point), and it is stored in eye coordinates.

So, setting the position of a light and then transforming for the camera will leave the light in one position, regardless of the camera's transformations.
Quote:
Or is there a way to make directional lights in OpenGL? This would be ideal since it is that effect that I am looking for.

Yes there is, and yes it would be. From the same source:
Quote:
If the w component of the position is 0, the light is treated as a directional source. Diffuse and specular lighting calculations take the light's direction, but not its actual position, into account, and attenuation is disabled.

This all pertains to glLightfv and its parameters, for the record. Best of luck!
-jouley
jon723
jon723
For your purposes what you want is a directional light source. You can achieve by leaving the 4th component in the position '0.0', which it is by default. If you make the 4th component a 1 then the light is a positional light source.
www.lefthandinteractive.net
space warp
space warp
Setting the lights position after transforming the modelview workes fine. Thanks! :)
.sehkteeah erthyahr gahro

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.