Jump to content
  • Advertisement
Sign in to follow this  
snak_attack

Lighting seems relative to camera orientation?

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

I have what is I suspect a really noob question. I set up a global light, and use glLookAt to position & orient my camera. For the most part all is well. However, I notice that as I rotate the camera (changing not the location of the camera, just the look-at-target), polygons get lighter and darker. I thought maybe I was picking up some specular lighting, but I think I've disabled that. Here is the code (JOGL): gl.glEnable(GL.GL_LIGHTING); gl.glEnable(GL.GL_LIGHT1); gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, new float[] { .1f, .1f, .1f, 1f}, 0); gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, new float[] { 1, 1, 1, 1}, 0); gl.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, new float[] { 0, 0, 0, 0}, 0); float[] pos = new float[] { .866, .5, 0, 0 }; gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, pos, 0); Any idea what I am doing wrong? thanks snak

Share this post


Link to post
Share on other sites
Advertisement
Everytime you set the light position it is transformed by the current modelview matrix. To place it statically in the world set the light position every frame after you set the modelview matrix to the camera transformation.

Share this post


Link to post
Share on other sites
After the definition if the w part of a position of a light is 0 it is a directional light. If you want it to be a point light you have to specify the w with 1.

---> float[] pos = new float[] { .866, .5, 0, 1 }; <---

Everytime you move the camera you should also update the light position to get correct results.

Share this post


Link to post
Share on other sites
Thanks, that helped. It turned out that I was making my lighting calls every frame, but before the call to glLookAt. Once I changed the order it looks much better. Thanks again

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!