View Full Version : Planar projected shadow matrix

Catman

03-03-2004, 11:13 AM

Hello! I'm writing a documentation about planar projected shadow algorithm. I have to write how I get the projection matrix from light position and the plane's equation, but I can't find any documentation that tells this. Can someone help me?

chemdog

03-06-2004, 01:25 AM

Well, the plane has a normal and offset(the plane equation) and the light source has a direction. So essentially, you want everything smushed onto the plane using the direction as the smushing direction. This is a 3D to 2D projection, so there are many possible correct answers.

Try doing this in 2D first, project some test points onto a line on the page, using a random direction vector. This would be the 2D to 1D projection. Extend what you've learned to the third coordinate.

OR if you want to cheat NeHe has a project on this, and its also in the back of the RedBook.

Catman

03-07-2004, 08:41 AM

Thanks for your help.

roffe

03-09-2004, 08:55 PM

For planar shadows you need to project a set of points(your mesh) onto a plane under a certain direction. This is the same as finding the intersection between a line and a plane.

For a point in space V0, you will find its projection point V1 on a plane P by solving the intersection between line l and P where v is the direction of projection.

l = V0 + v(t)

P = n.V1 + d

Intersection occurs when

V1 = V0 + v(t)

and V1 lies in P

n.V1 + d = 0

To solve, insert V0+v(t) into P and solve for t. This will give you an expression of t in V0. Then insert expression for t into V1 = V0 + v(t) and resolve into the form V1 = X*V0 where X will be your projection matrix.

Catman

03-12-2004, 05:01 AM

Thanks. I think I understand.

nodge

03-31-2004, 01:39 AM

This equation projects a point onto an arbitary plane:

s = v - ((n.v - d) / (n.l)) l

where v is a point in space

d is the plane's offset

n is the plane's normal

l is the projection direction

Resolving this into a matrix (with columns I, J, K and T) gives:

float dotInv = 1.0f / (n.x * l.x + n.y * l.y + n.z * l.z);

matrix.I.x = 1.0f - n.x * l.x * dotInv;

matrix.I.y = -n.x * l.y * dotInv;

matrix.I.z = -n.x * l.z * dotInv;

matrix.J.x = -n.y * l.x * dotInv;

matrix.J.y = 1.0f - n.y * l.y * dotInv;

matrix.J.z = -n.y * l.z * dotInv;

matrix.K.x = -n.z * l.x * dotInv;

matrix.K.y = -n.z * l.y * dotInv;

matrix.K.z = 1.0f - n.z * l.z * dotInv;

matrix.T.x = n.w * l.x * dotInv;

matrix.T.y = n.w * l.y * dotInv;

matrix.T.z = n * l.z * dotInv;

But you'd better check, since it's been a while since I tried this.

nodge

03-31-2004, 01:41 AM

Sorry, those last few lines should read

matrix.T.x = d * l.x * dotInv;

matrix.T.y = d * l.y * dotInv;

matrix.T.z = d * l.z * dotInv;

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.