PDA

View Full Version : More problems with projective shadows

dunken69
03-19-2003, 04:31 PM
Hi!
I am trying to figure out how projective shadows work, have read some tutorials, and so far everything works fine.
However, the basic algorithm that you find everywhere only seems to work if the plane you want to project your shadow onto goes through the origin (ie. the D of the plane equation is 0). If it doesn't the shadow is not projected correctly.
I'm afraid I can't explain the problem any better, but if anyone has an idea what is going wrong, I'd appreciate if you could help me out!

Thanks,
Dunken

oliii
03-19-2003, 05:24 PM
here is the code for a shadow matrix.

works for any plane, and pointlight and directional light.

{

GLfloat dot;
const int X = 0;
const int Y = 1;
const int Z = 2;
const int W = 3;
/* Find dot product between light position vector and ground plane normal. */
dot = groundplane[X] * lightpos[X] +
groundplane[Y] * lightpos[Y] +
groundplane[Z] * lightpos[Z] +
groundplane[W] * lightpos[W];
shadowMat[0][0] = dot - lightpos[X] * groundplane[X];
shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y];
shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z];
shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W];
shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X];
shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y];
shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z];
shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W];
shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X];
shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y];
shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z];
shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W];
shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X];
shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y];
shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z];
shadowMat[3][3] = dot - lightpos[W] * groundplane[W];

}

{
GLfloat groundplane[4] = { 0, 1, 0, 0 };
GLfloat lightpos [4] = { 0, 100, 0, 1 };

glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(-0.1f, 0.0f);

glPushMatrix();
glColor4f (0.0f, 0.0f, 0.0f, 1.0f);
glTranslatef (P.x, P.y, P.z);
glScalef (S.x, S.y, S.z);
glutSolidCube (1.0f);
glPopMatrix();
glDisable(GL_POLYGON_OFFSET_FILL);
}

void Render(void) const
{
Matrix M;
M.SetAxis(Matrix::eX, A);
M.SetAxis(Matrix::eY, B);
M.SetAxis(Matrix::eZ, C);

glPushMatrix();
glTranslatef (P.x, P.y, P.z);
glScalef (S.x, S.y, S.z);
glColor4f (1.0f, 0.0f, 0.0f, 0.4f);
glutSolidCube (1.0f);
glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
glutWireCube (1.0f);
glPopMatrix();
}

[This message has been edited by oliii (edited 03-19-2003).]