Light position


I’m trying to implement a simple lighting shader with GLSL but i’m lost !

Before rendering the scene, I use glRotate() and glTranslate() to position the camera.
The rendering objects are in world space and I use the camera to move in the world.
I have a point light which is defined in world space.
I then pass the light position with glUniform3fvARB(). But i can’t get my lighting shader to work. I get suspect effect and i presume that light position is not handled the right way !

How must i transform the world light position to eye-space ?

PS: I used glLight() to pass light position in the shader in another project and all was working pretty good.

You need to multiply your view-matrix with the light coordinate. You can get this matrix by using glGetFloatv(GL_MODELVIEW_MATRIX) right after gluLookAt(…).

The following seems to work for me:
-set Light Position with glUniform
-gluLookAt() (use this instead of glTranslate and glRotate for Camera!)
-do what you want

Don’t forget to multiply gl_ModelViewMatrix with gl_Vertex and send this to the fragment shader as fragment position if you need this.

Thanks !

I now understand better how OpenGL manage matrix and lights.

I had to multiply light world position with the ModelView matrix right after my camera operations.

  • FenKz

Back up a second. If you set your modelview matrix with gluLookAt, and then specify a light position (in world space) with glLight, that light position will automagically be multiplied by the current modelview matrix before it gets sent to the shader. The shader will then receive the light position in view space.

So you don’t have to multiply your light position by your view matrix on your own; OpenGL will do it for you.

Yeah, i was using glLight() to position lights and so i didn’t need to multiply with view matrix, but i got strange results on ATI cards with multiple lights.

So, now, to be sure, i use glUniform3fvARB() to send light position and therefore i need to multiply myself.

If you think you found a bug, it would be good to report that to ATI. If your glLight positions really are getting messed up that would be a big problem for everybody.

Ok, i will try to repeat it and see what’s going on.
I thought that I was making an error, but yeah, it’s maybe an ATI bug :wink:

Actually I waws struggling with this same problem on a 6800 GT. Took me hours to work out it was buggy and just asking for the glLightPosition will mess up other totally unrelated variables. Its been reported to nVidia.

Hi!I wrote a simple program with per vertex lighting technique.I use Radeon 9600 Mobility and CATALYST 4.7 and 4.8.It’s seems to be ok with single light.But when I use multiple lights(2 and 3 lights) it displays incorrectly.The same program runs correctly on nVidia 5900.So I think it is the driver’s bug.Does anybody know how to report it to ATI?

Of course my first post in this thread was crap, sorry.
But are you totally shure that glLight makes a multiply with the current modelview matrix? Not only with the matrix set up by gluLookAt? (I know, should be the same if glLight is right after gluLookAt…)
I’m confused because i’m moving around a ball and the light seems to do that with me, and i’m using glLight now…

are you totally shure that glLight makes a multiply with the current modelview matrix

That’s what the OpenGL spec says. The light is multiplied by the modelview matrix in effect at the time you called glLightfv() with the light position/direction. (Note: it doesn’t get changed if you then change the modelview matrix – lighting is done in view space, so specify the light when your modelview equals exactly your camera transform).

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.