Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Planar projected shadow matrix

  1. #1
    Junior Member Regular Contributor
    Join Date
    Apr 2002
    Posts
    114

    Planar projected shadow matrix

    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?

  2. #2
    Intern Contributor
    Join Date
    Feb 2004
    Posts
    98

    Re: Planar projected shadow matrix

    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.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Apr 2002
    Posts
    114

    Re: Planar projected shadow matrix

    Thanks for your help.

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2002
    Posts
    366

    Re: Planar projected shadow matrix

    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.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Apr 2002
    Posts
    114

    Re: Planar projected shadow matrix

    Thanks. I think I understand.

  6. #6
    Junior Member Newbie
    Join Date
    Mar 2004
    Posts
    2

    Re: Planar projected shadow matrix

    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.

  7. #7
    Junior Member Newbie
    Join Date
    Mar 2004
    Posts
    2

    Re: Planar projected shadow matrix

    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;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •