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.
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.
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).