View Full Version : matrix hell
09-28-2005, 10:22 PM
okay, here is a summary of my problem :
when I draw my objects, the lighting move depending on the cameras position.
But I already update lights position once a frame after setting the camera modelview matrix.
but it begins to be strange when I see that :
If I use gluLookAt, using direction and position extracted from the "home made" camera matrix. then the lighting is okay (static)
If I directly use glLoadMatrix with the home made matrix, then the lighting is wrong.
When I do a glGetFloat and I get the gluLookAt generated modelview matrix, each factor of this matrix differe from less than 0.0001 in comparison with the "home made" matrix.
I just do not understand what happens.
PS: I'm under Linux with ATI proprietary drivers
thanks for reading, I hope I'm clear enough
09-28-2005, 10:28 PM
try transposing your home made matrix before calling glLoadMatrix.
09-28-2005, 10:47 PM
actually I use glLoadTransposeMatrix, and when I move the camera, the result is just fine with the two methods, just the lighting is wrong.
09-29-2005, 11:36 AM
Hmm... something is wrong here.
If you specify positions after you have the viewing matrix on the modelview stack then your lights should not be in eye space.
Loading inverse(transpose on afine) as you know is just because viewing matrices are the inverse of their model matrix counterparts and this is how model+view concatenation works.
If that was a problem you'd see the viewing matrix was obviously wrong.
Are you sure you specify the position etc. for the light? Make sure for spotlights that you also specify the orientation (just incase this is an issue). There's an outside chance this is a bug with the driver trying to be optimal but not realizing that the loadmatrix has dirtied the matrix, but I doubt it you may simply have a bug in your other code path.
In fact the more I think about it the more likely a bug in your code seems.
gluLookAt isn't magical, it just computes a viewing matrix based on the arguments and loads it (or multiplies it I forget which). You may want to try a multmatrix on an identity loaded matrix instead, just as a crazy test.
Make sure your own code is on the modelview matrix when you load the viewing transformation, if you had the wrong matrix and subsequently loaded concatenated matrices you'd never tell. Also try to use the pipeline's multmatrix with the viewing matrix and subsequent model matrix operations. This will preserve the same viewing matrix on the modelview matrix stack that you used for the lights and any problems with the viewing matrix will manifest themselves in the vertex transformation, not just the lighting so any issues will instantly obvious.
09-29-2005, 12:36 PM
Well, in fact it may be a ATI driver problem :
If I load the matrix via glLoadMatrix then the lights move.
If I use glLoadIdentity then glMultMatrix, then the lights do not move.
but If I do a glGetFloat, the matrix I get in both way is identical to the matrix I sended (which is generated the same way for the both method)
09-29-2005, 09:58 PM
be sure to set:
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
with the correct modelviewmatrix in your code. the light_position is directly transformaed by the current modelviewmatrix so it should be the same in both cases (glLoadMatrix or glLoadIdentity and then glMultMatrix) if you apply this command with the same modelviewmatrix .
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.