I am trying to do shadow mapping, using glsl shaders and I have a very strange problem.
In fact I need to get back modelview and projection matrices from the light point of view to assure the vertices’s coordinates transformation to shadowmap texture coordinates.
But In order to check if the projection and modelview matrices from the light point of view are correct, instead of use the glsl function ftransform to do the vertices transformations , I use the light’s projection and modelview matrices that I got back with glGetFloatv.
In theory The final render would be the same in the two case, but in practice I obtain two render completly different!!
I get back these matrice like that:
GLfloat LightModelViewMatrix; GLfloat LightProjectionMatrix;
glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45,1.0,1,10); glGetFloatv(GL_PROJECTION_MATRIX, LightProjectionMatrix);
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(LightPos,LightPos,LightPos, 0.0,0.0,0.0, 0.0f,1.0f,0.0f); glGetFloatv(GL_MODELVIEW_MATRIX, LightModelViewMatrix);
then I give these ones to the shader:
glUniformMatrix4fv(LightModelViewMatrixLoc, 1, 0, LightModelViewMatrix); glUniformMatrix4fv(LightProjectionMatrixLoc, 1, 0, LightProjectionMatrix);
There is no opengl error in the application.
I have looked at the matrices in a log file and they seems to be correct ( according to the shape )
But I don’t know how I could know if these matrices are really obtained by the shader in these variables:
uniform mat4 LightModelViewMatrix; uniform mat4 LightProjectionMatrix;
Of course at the shader initialization I get back the unform variable location with:
LightModelViewMatrixLoc = glGetUniformLocationARB(p,"LightModelViewMatrix"); LightProjectionMatrixLoc = glGetUniformLocationARB(p,"LightProjectionMatrix");
So when I do that in the vertex shader:
gl_Position = ftransform();
The render is what I expected.
But when I do that:
gl_Position = LightProjectionMatrix * LightModelViewMatrix * gl_Vertex;
I don’t obtain what I expected. It is very strange!
Thank you for your help!