Shadow

Ok so here I go, amateur me goes to learn how to do shadows… Oh man, OpenGL won’t do it for me… Ok so I go look for tutorials… Then we find the shadow matrix … Now I got smart and just figured, if that is the standard for shadowing in OpenGL, I can just copy and paste =-).

So here’s my problem. I have a sphere and a plane. I have a working shadowMatrix command and want to now: what variables, arrays and stuff that needs to go in the display code to get my shadows visible on the plane. I got reflections down and this is the only thing that hinders me =-(…

You’ll only need the shadow matrix. Render your scene. Determine the plane to render the shades on. Set the projection matrix, render in your favorite shade color

Divide Overflow

“I’m fat, you’re ugly, I can lose weight…”

Yah, I got that general idea down but I need the code for it

cwhite40

There’s a good description in the back of the red book. I think there’s even some example code in the glut distribution somewhere.

You should check nVidia web site, they have a projected shadow demo.

They are other infos about that on this web site, in the tutorial section.

Ok this really is not working. The glut code and nVida code are not well explained. I have no idea what to do here . Does anyone have well explained shadow code. I have tried this so many times I think I’m going to turn into a shadow .

cwhite40

I took the code form Mark Kilgard from nVidia corporation…

void ShadowMatrixf (float mat[16],
float pA, float pB, float pC, float pD,
float vX, float vY, float vZ, float vW)
{
float Dot = pA * vX +
pB * vY +
pC * vZ +
pD * vW;
mat[0] = Dot - vX * pA;
mat[1] = -vY * pA;
mat[2] = -vZ * pA;
mat[3] = -vW * pA;
mat[4] = -vX * pB;
mat[5] = Dot - vY * pB;
mat[6] = -vZ * pB;
mat[7] = -vW * pB;
mat[8] = -vX * pC;
mat[9] = -vY * pC;
mat[10] = Dot - vZ * pC;
mat[11] = -vW * pC;
mat[12] = -vX * pD;
mat[13] = -vY * pD;
mat[14] = -vZ * pD;
mat[15] = Dot - vW * pD;
}

Use this matrix this way:

float mat[16]; // This is the sahdow matrix

ShadowMatrixf (mat,
0.0, 1.0, 0.0, 0.0, // The plane
0.0, 10.0, 0.0, 1.0 ); // The light position

render some geometry…
glPushMatrix ();
glMultMatrixf (mat);
render the same geometry…
glPopMatrix ();

I hope this will help…

Cool!!

One more question though, what is the plane parameters supposed to be: vertices, points, normals?

Thank You
cwhite40

the a,b & c parameters represent the plane normal the d parameter represent the lenght of this vector.