View Full Version : Light position
07-26-2004, 10:31 AM
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.
07-26-2004, 01:56 PM
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(..).
07-26-2004, 11:44 PM
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.
07-27-2004, 01:26 AM
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.
07-28-2004, 05:21 PM
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.
07-29-2004, 01:07 AM
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.
07-29-2004, 04:43 AM
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.
07-29-2004, 10:34 AM
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 ;)
08-02-2004, 12:23 PM
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.
09-02-2004, 07:38 PM
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?
09-04-2004, 12:08 PM
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...
09-05-2004, 05:48 PM
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).
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.