Jump to content
  • Advertisement
Sign in to follow this  

Light following camera in OpenGL shader (problem)

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

So I'm trying to implement my own per-pixel light shader.  I'm using OpenGL


If I use gl_LightSource[0].position.xyz in my fragment shader everything works like it's suppose too.  I'm trying to send in the light position to a uniform variable, instead of using the gl_LightSource attribute.  I just can't seem to get it right.


In my Render Function (psuedo code)


setup projection

change to modelview and load idenity




for each object




 Bind Buffers







So using LightSouce[] position works when i set the position after the cameraMatrix before the FOR loop.


I'm trying to send the Light Position in eye Coordnates.  so I'm taking the light position and multiplying by the CameraMatix  (modelView).  Thats what I pass into the shader when setting shader uniforms.



So where did I go wrong when looking at this ?  Also, Should I be doing push/pop matrices with shaders?  If not, is there a better way to organize and send them to the shader?   But mostly, I want to know where I went wrong.


Thanks for any help, and those that took the time to read this.

Share this post

Link to post
Share on other sites

Can someone tell me if this might be the answer:


my CameraMatrix right now is the ModelViewMatrix.  The LightPosition is defined in world Space.  Should I be doing ViewMatrix * lightPosition to send it into eye space, instead of ModelViewMatrix * LightPosition?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!