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};

function call is myShadowMatrix(backPlane, lightPos);


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

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];

glMultMatrixf((const GLfloat *) shadowMat);
}
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
Read these:

* Projection Shadows (http://www.ia.hiof.no/~borres/cgraph/explain/shadow/p-shadow.html#Projection_shadows2142941168)
* Shadow Projection in OpenGL (http://www.devmaster.net/articles/shadowprojection/)

And in general use this google search to find what you want:

* planar projected shadow matrix (http://www.lmgtfy.com/?q=planar+projected+shadow+matrix)

darshan
05-21-2010, 08:07 AM
hi how does the calculation take place in those 4*4 matrix exactly ??why is that they are subtracting with the dot can u be more precise on the shadow matrix please??

Dark Photon
05-25-2010, 05:59 PM
hi how does the calculation take place in those 4*4 matrix exactly ??why is that they are subtracting with the dot can u be more precise on the shadow matrix please??
Well read the page, and just think about it. What are we doing geometrically? Intersection of a 3D line and a 3D plane, right? Write the equations, plug one into the other, solve, and there you go.