PDA

View Full Version : shadow implementation

darshan
05-20-2010, 11:04 AM
i have a problem in understanding the implementation of the shadow any 1 who can help??

static float groundPlane[4] =
{0.0, 1.0, 0.0, 1.499};
static float backPlane[4] =
{0.0, 0.0, 1.0, 0.899};

and the function is defined as:
static void myShadowMatrix(float ground[4], float light[4])
{
float dot;

dot = ground[0] * light[0] +
ground[1] * light[1] +
ground[2] * light[2] +
ground[3] * light[3];

shadowMat[0][0] = dot - light[0] * ground[0];
shadowMat[1][0] = 0.0 - light[0] * ground[1];
shadowMat[2][0] = 0.0 - light[0] * ground[2];
shadowMat[3][0] = 0.0 - light[0] * ground[3];

shadowMat[0][1] = 0.0 - light[1] * ground[0];
shadowMat[1][1] = dot - light[1] * ground[1];
shadowMat[2][1] = 0.0 - light[1] * ground[2];
shadowMat[3][1] = 0.0 - light[1] * ground[3];

shadowMat[0][2] = 0.0 - light[2] * ground[0];
shadowMat[1][2] = 0.0 - light[2] * ground[1];
shadowMat[2][2] = dot - light[2] * ground[2];
shadowMat[3][2] = 0.0 - light[2] * ground[3];

shadowMat[0][3] = 0.0 - light[3] * ground[0];
shadowMat[1][3] = 0.0 - light[3] * ground[1];
shadowMat[2][3] = 0.0 - light[3] * ground[2];
shadowMat[3][3] = dot - light[3] * ground[3];

}
why is the matrix multiplied??how does the shadow gets projected

Yomboprime
05-20-2010, 11:48 AM
You call the function after setting the (inverse) matrix of the camera, and before any object transformation (rotation + translation). That's because the matrix is multiplied, to combine with the inverse of the camera.

This just projects the points of the objects to the plane. I also don't understand the maths because I copied it from the internet, but it works in my game.

Dark Photon
05-21-2010, 04:57 AM