View Full Version : about shadow

tigeryhong

03-12-2003, 01:32 PM

Hi, buddy:

I have a problem about shadow. For example, if I have point light L(x,y,z), some point object V(v1,v2,v3), and any plane Ax+By+Cz+D=0, how can I find the shadow matrix, I mean the point V's shadow in the plane Ax+By+Cz+D=0.

Appreciate here.

MrShoe

03-12-2003, 02:34 PM

I dont remember off the top of my head, but if you goodle for "Shadow Projection Matrix" or just "Shadow Matrix", then you should get something.

man, use projective shadow mapping! ist way kewler!

The question has nothing to do with shadows, so looking for shadow mapping (projective or otherwise) won't be useful.

If you know the plane P, vertex v and light position l, then the point the question is talking about is the intersection of the line lv with the plane P.

if l and v are given in homogeneous coordinates then the line equation lv is (l-v)*lambda+l (where lambda is the scalar parameter).

The intersection of lv with P is given by

lv*p' = 0

and you have to solve for lambda.

However: what is probably more useful is to construct a matrix with l as the optical centre and P as the image plane. THis is.. er... more complicated to describe. The easiest way (I think) would be to compute n = the orthogonal vector from l to p and then transform the plane so n points down the negative z axis and then work out the range of your light source and construct the left/right/top/bottom planes by backprojecting the fov onto the transformed plane and using the LRTB parametrs to construct an opengl matrix.

I hope this helps

cheers,

John

oliii

03-13-2003, 06:56 PM

void shadowMatrix(GLfloat shadowMat[4][4], GLfloat groundplane[4], GLfloat lightpos[4])

{

GLfloat dot;

/* Find dot product between light position vector and ground plane normal. */

dot = groundplane[X] * lightpos[X] +

groundplane[Y] * lightpos[Y] +

groundplane[Z] * lightpos[Z] +

groundplane[W] * lightpos[W];

shadowMat[0][0] = dot - lightpos[X] * groundplane[X];

shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y];

shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z];

shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W];

shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X];

shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y];

shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z];

shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W];

shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X];

shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y];

shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z];

shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W];

shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X];

shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y];

shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z];

shadowMat[3][3] = dot - lightpos[W] * groundplane[W];

}

2 secs google search on "Shadow Matrix" http://www.opengl.org/discussion_boards/ubb/biggrin.gif

oliii

03-13-2003, 06:58 PM

looks like it works for both directional lights and point lights. I think http://www.opengl.org/discussion_boards/ubb/biggrin.gif Gonna try that myself

oliii

03-13-2003, 07:06 PM

yep, working. Brings my radeon 9700 to a crawl. http://www.opengl.org/discussion_boards/ubb/biggrin.gif Need to optimise my code....

X = 0, Y = 1, Z = 2, W = 3 BTW.

also, enable polygon offset or you'll get aliasing

[This message has been edited by oliii (edited 03-13-2003).]

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.