DeathCarrot
02-11-2008, 10:38 AM
So, here's what I'm doing:
Set projection matrix to light's gluPerspective
Set modelview matrix to light's gluLookAt
Render the scene geometry into a depth-only FBO
Set projection matrix to players's gluPerspective
Set modelview matrix to players's gluLookAt
Make texture matrix using:
(bias matrix) * (light's projection) * (light's modelview) * (camera's modelview inverse)
Render scene properly using the following shadow coordinates specified in the vert shader:
shadowCoord = gl_TextureMatrix[3] * gl_ModelViewMatrix * gl_Vertex + vec4(0.0,0.0,-0.004,0.0);
the offset is there to prevent z-fighting.
What is supposed to happen is the camera's modelview inverse in the texture matrix should cancel out the camera transformation in the gl_ModelViewMatrix in the vert shader leaving only the object transformation (I think).
This is what happens:
http://img165.imageshack.us/img165/6050/shadowbroken1pe5.jpg http://img521.imageshack.us/img521/1803/shadowbroken2aj6.jpg
However, if I place the gluLookAt for both the light and scene camera into the projection matrix, shadows are rendered correctly (but lighting breaks):
http://img521.imageshack.us/img521/5075/shadowworkingeh8.jpg
Am I missing out on a step? The drawing of the geometry includes calling glLightfv with GL_POSITION, but taking it out didn't help.
I'm not sure what other details might be requried, but here's the main bits.
Note: I also posted this on GameDev (http://www.gamedev.net/community/forums/topic.asp?topic_id=482156) last week.
Thanks.
Set projection matrix to light's gluPerspective
Set modelview matrix to light's gluLookAt
Render the scene geometry into a depth-only FBO
Set projection matrix to players's gluPerspective
Set modelview matrix to players's gluLookAt
Make texture matrix using:
(bias matrix) * (light's projection) * (light's modelview) * (camera's modelview inverse)
Render scene properly using the following shadow coordinates specified in the vert shader:
shadowCoord = gl_TextureMatrix[3] * gl_ModelViewMatrix * gl_Vertex + vec4(0.0,0.0,-0.004,0.0);
the offset is there to prevent z-fighting.
What is supposed to happen is the camera's modelview inverse in the texture matrix should cancel out the camera transformation in the gl_ModelViewMatrix in the vert shader leaving only the object transformation (I think).
This is what happens:
http://img165.imageshack.us/img165/6050/shadowbroken1pe5.jpg http://img521.imageshack.us/img521/1803/shadowbroken2aj6.jpg
However, if I place the gluLookAt for both the light and scene camera into the projection matrix, shadows are rendered correctly (but lighting breaks):
http://img521.imageshack.us/img521/5075/shadowworkingeh8.jpg
Am I missing out on a step? The drawing of the geometry includes calling glLightfv with GL_POSITION, but taking it out didn't help.
I'm not sure what other details might be requried, but here's the main bits.
Note: I also posted this on GameDev (http://www.gamedev.net/community/forums/topic.asp?topic_id=482156) last week.
Thanks.