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 8 of 8

Thread: Reverse projection and shadow maps

  1. #1
    Junior Member Newbie
    Join Date
    May 2001
    Location
    columbia, SC, USA
    Posts
    9

    Reverse projection and shadow maps

    I am building a scene with a mech walking around a hilly terrain at night. The mech has a spotlight shining on the ground in front of him. I am using shadow buffers to cast shadows from the spotlight onto the terrain. My problem is the reverse projection of the shadow buffer is hitting the hillside behind the mech. Does anyone know of a good way to eliminate this reverse projection? Ideally I would like to eliminate it at the stage where the shadow depth values are compared but I don't think I have that kind of flexibility.

    Thanks,
    Michael

  2. #2
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Lubbock, TX, USA
    Posts
    224

    Re: Reverse projection and shadow maps

    I'd say the simplest method is using a 2x1 1D texture in another texture unit (a black and a white pixel). Set up eye linear texture projection having S projected along the 'view vector' of the viewpoint that renders your shadow map. Use clamp or clamp_to_edge wrapping mode, and use the texel from the 1D fetch to modify the shadow mapping result - for example, generate your texture coordinates so that the black pixel is behind the light source and use the texel from the 1D texture as the alpha of the resulting fragment;
    if your shadowing pass modulates the frame buffer, map the 1D texture so that the white pixel is behind the light source and add the results from that texture stage to the shadowing stage (clampf(n + 1.0) = 1.0, modulating with which will not change the frame buffer).

    In simple words, project a 1D texture along the viewing direction of the light source's frustum, so that it eliminates contribution of your shadowing pass to the frame buffer behind the light source

  3. #3
    Junior Member Newbie
    Join Date
    May 2001
    Location
    columbia, SC, USA
    Posts
    9

    Re: Reverse projection and shadow maps

    Believe it or not I'm out of texture layers. I have a static light map layer, detail layer, shadow buffer, and a "spotlight cone edge smoothing" layer. It does sound like a good way to go though.

    -sechrest

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: Reverse projection and shadow maps

    if you want, you can replace your simple spotlightconemap with a cubemap. there you can define completely around the 360° how much light gets emitted in this direction.
    http://www.ronfrazier.net/apparition..._lighting.html

    here an implementation of it
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

  5. #5
    Junior Member Newbie
    Join Date
    May 2001
    Location
    columbia, SC, USA
    Posts
    9

    Re: Reverse projection and shadow maps

    I really like the cube map idea but I'm having a little trouble with appropriate texture coordinates. I'm loading the terrain model from a 3ds file via a library I have only limited control over; therefore I don't have a real good way to get explicit s, t, and r coordinates in the right texture layer. I really appreciate both suggestions but it looks like I'm going to have to brute force it.

    -sechrest

  6. #6
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Lubbock, TX, USA
    Posts
    224

    Re: Reverse projection and shadow maps

    You could set up the cube map independently of the 3ds file, using projective texturing to project the texture coordinates for the cube map out from the light source. That way you'd be independent of your 3ds library.

  7. #7
    Member Regular Contributor
    Join Date
    May 2000
    Posts
    454

    Re: Reverse projection and shadow maps

    Doing texgen for a spotlight cubemap is very easy. For every vertex, you just calculate (vertexpos-spotlightpos). If you want to adjust the frustum size of the spotlight dynamically you can do this with the texture matrix. My tutorial (which dave linked to) demonstrates how to do this (except that in the tutorial I do it without texgen and just pass through the vertex position instead).

    [This message has been edited by LordKronos (edited 06-25-2002).]
    Ron Frazier

  8. #8
    Junior Member Newbie
    Join Date
    May 2001
    Location
    columbia, SC, USA
    Posts
    9

    Re: Reverse projection and shadow maps

    Jackpot! The projected cube map solution is working like a champ. Thanks to everyone for their help. If anyone is interested in seeing some screen shots my company (www.idvinc.com) is about to release a demo (next 10 days or so) that will showcase the projected spotlight as part of a bigger scene. Thanks again!

    -sechrest

Posting Permissions

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