Hi, I’m trying to implement shadows. For some weird reason my shadows are revered. That is they look as if the light is shining from below and the plane on which the shadows are projected is at the top of the object…
Here’s my shadow calculating function:
void setShadowMatrix(GLfloat destMat[16], float lightPos[4], float plane[4]) {
GLfloat dot;
// dot product of plane and light position
dot = plane[0] * lightPos[0] + plane[1] * lightPos[1] + plane[1] * lightPos[2] + plane[3] * lightPos[3];
// first column
destMat[0] = dot - lightPos[0] * plane[0];
destMat[4] = 0.0f - lightPos[0] * plane[1];
destMat[8] = 0.0f - lightPos[0] * plane[2];
destMat[12] = 0.0f - lightPos[0] * plane[3];
// second column
destMat[1] = 0.0f - lightPos[1] * plane[0];
destMat[5] = dot - lightPos[1] * plane[1];
destMat[9] = 0.0f - lightPos[1] * plane[2];
destMat[13] = 0.0f - lightPos[1] * plane[3];
// third column
destMat[2] = 0.0f - lightPos[2] * plane[0];
destMat[6] = 0.0f - lightPos[2] * plane[1];
destMat[10] = dot - lightPos[2] * plane[2];
destMat[14] = 0.0f - lightPos[2] * plane[3];
// fourth column
destMat[3] = 0.0f - lightPos[3] * plane[0];
destMat[7] = 0.0f - lightPos[3] * plane[1];
destMat[11] = 0.0f - lightPos[3] * plane[2];
destMat[15] = dot - lightPos[3] * plane[3];
}
and my plane is:
float plane[4] = {0.0, 1.0, 0.0, 0.0 };
which I suppose is right for a ground plane?
Thank you,
Luke