Robotnik
10-29-2011, 02:00 AM
Right now I'm trying to implement shadow mapping into my engine, I thought I had problems with back projection, but it turn out that's not the issue here.
Right now I'm having what seems to be problems with the texture matrix I use to project my end-result textures, or the matrixes I use for projection and modelview when I render into my depth texture. When I render solely character models, their shadows display fine, but when I add the world to the shadow map, nothing displays at all, like everything was shadowed. I can't find the cause of this problem, but it's bound to be a problem with the projection/modelview matrix. I've tried hard to figure it out, but I can't find the reason. It seems like the depth values in my depth texture are somehow off, but I don't get how that is possible.
Here's how I set up projection and modelview:
float flSize = tan((M_PI/360) * m_pCurrentDynLight->cone_size);
float flFrustum[] = { 2/(flSize*2), 0, 0, 0, 0, 2/(flSize*2), 0, 0, 0, 0, -1, -1, 0, 0, -2, 0 };
int bReversed = IsPitchReversed(m_pCurrentDynLight->angles[PITCH]);
vec3_t vTarget = m_pCurrentDynLight->origin + (m_pCurrentDynLight->forward * m_pCurrentDynLight->radius);
// Set projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMultMatrixf(flFrustum);
// Set modelview
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
MyLookAt(m_pCurrentDynLight->origin[0], m_pCurrentDynLight->origin[1], m_pCurrentDynLight->origin[2], vTarget[0], vTarget[1], vTarget[2], 0, 0, bReversed ? -1 : 1);
This is how I set texture projection for the depth texture:
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_S, GL_EYE_PLANE, planeS);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_T, GL_EYE_PLANE, planeT);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_R, GL_EYE_PLANE, planeR);
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_Q, GL_EYE_PLANE, planeQ);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_Q);
// load texture projection matrix
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5, 0.5, 0.0);
glScalef(0.5, 0.5, 1.0);
glMultMatrixf(flFrustum);
MyLookAt(m_vCurDLightOrigin[0], m_vCurDLightOrigin[1], m_vCurDLightOrigin[2],
vTarget[0], vTarget[1], vTarget[2],
0, 0, bReversed ? -1 : 1);
glMatrixMode(GL_MODELVIEW);
I don't see the problem in this code, but maybe its my lack of understanding of how these matrixes work. I'd apprechiate any help.
Thanks.
Right now I'm having what seems to be problems with the texture matrix I use to project my end-result textures, or the matrixes I use for projection and modelview when I render into my depth texture. When I render solely character models, their shadows display fine, but when I add the world to the shadow map, nothing displays at all, like everything was shadowed. I can't find the cause of this problem, but it's bound to be a problem with the projection/modelview matrix. I've tried hard to figure it out, but I can't find the reason. It seems like the depth values in my depth texture are somehow off, but I don't get how that is possible.
Here's how I set up projection and modelview:
float flSize = tan((M_PI/360) * m_pCurrentDynLight->cone_size);
float flFrustum[] = { 2/(flSize*2), 0, 0, 0, 0, 2/(flSize*2), 0, 0, 0, 0, -1, -1, 0, 0, -2, 0 };
int bReversed = IsPitchReversed(m_pCurrentDynLight->angles[PITCH]);
vec3_t vTarget = m_pCurrentDynLight->origin + (m_pCurrentDynLight->forward * m_pCurrentDynLight->radius);
// Set projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMultMatrixf(flFrustum);
// Set modelview
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
MyLookAt(m_pCurrentDynLight->origin[0], m_pCurrentDynLight->origin[1], m_pCurrentDynLight->origin[2], vTarget[0], vTarget[1], vTarget[2], 0, 0, bReversed ? -1 : 1);
This is how I set texture projection for the depth texture:
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_S, GL_EYE_PLANE, planeS);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_T, GL_EYE_PLANE, planeT);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_R, GL_EYE_PLANE, planeR);
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_Q, GL_EYE_PLANE, planeQ);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_Q);
// load texture projection matrix
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5, 0.5, 0.0);
glScalef(0.5, 0.5, 1.0);
glMultMatrixf(flFrustum);
MyLookAt(m_vCurDLightOrigin[0], m_vCurDLightOrigin[1], m_vCurDLightOrigin[2],
vTarget[0], vTarget[1], vTarget[2],
0, 0, bReversed ? -1 : 1);
glMatrixMode(GL_MODELVIEW);
I don't see the problem in this code, but maybe its my lack of understanding of how these matrixes work. I'd apprechiate any help.
Thanks.