View Full Version : Reverse projection and shadow maps
06-24-2002, 12:19 PM
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.
06-24-2002, 01:19 PM
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 http://www.opengl.org/discussion_boards/ubb/wink.gif
06-24-2002, 01:27 PM
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.
06-24-2002, 10:24 PM
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.
here an implementation of it
06-25-2002, 09:17 AM
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.
06-25-2002, 09:37 AM
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.
06-25-2002, 10:09 AM
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).]
06-27-2002, 12:44 PM
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!
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.