Sign in to follow this  
wizardpc

Light following camera in OpenGL shader (problem)

Recommended Posts

wizardpc    282

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

glMultMatrix(cameraMatrix);

 

 

for each object

{

 glPushMatrix()

 SetShaderUniforms

 Bind Buffers

 GLDrawElements();

glPopMatrix()

}

 

//========================

 

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
wizardpc    282

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this