PDA

View Full Version : Shadow



cwhite40
09-19-2000, 11:17 AM
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 http://www.opengl.org/discussion_boards/ubb/eek.gif... 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 =-(..

Divide Overflow
09-21-2000, 03:53 AM
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 http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Divide Overflow

"I'm fat, you're ugly, I can lose weight.."

cwhite40
09-21-2000, 04:59 AM
Yah, I got that general idea down but I need the code for it http://www.opengl.org/discussion_boards/ubb/frown.gif........


http://www.opengl.org/discussion_boards/ubb/eek.gif cwhite40 http://www.opengl.org/discussion_boards/ubb/eek.gif

newt
09-21-2000, 11:51 AM
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.

Roderic (Ingenu)
09-22-2000, 12:25 AM
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.

cwhite40
09-23-2000, 08:06 PM
Ok this really is not working. The glut code and nVida code are not well explained. I have no idea what to do here http://www.opengl.org/discussion_boards/ubb/frown.gif. Does anyone have well explained shadow code. I have tried this so many times I think I'm going to turn into a shadow http://www.opengl.org/discussion_boards/ubb/smile.gif.

http://www.opengl.org/discussion_boards/ubb/eek.gif cwhite40 http://www.opengl.org/discussion_boards/ubb/eek.gif http://www.opengl.org/discussion_boards/ubb/eek.gif http://www.opengl.org/discussion_boards/ubb/eek.gif http://www.opengl.org/discussion_boards/ubb/eek.gif

Gabriel
09-24-2000, 06:17 AM
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...

cwhite40
09-24-2000, 07:05 AM
Cool!!

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

Thank You http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif
http://www.opengl.org/discussion_boards/ubb/eek.gif cwhite40 http://www.opengl.org/discussion_boards/ubb/eek.gif

Gabriel
09-24-2000, 08:00 PM
the a,b & c parameters represent the plane normal the d parameter represent the lenght of this vector.