View Full Version : clamp for projected shadowmaps

05-18-2006, 01:07 AM
recently I added depthtextures and shadowmap projection, however there is a bit of a problem.

nvidia has its clamp_to_edge hack, and neither clamp nor clamp to border seem to use the border color for ati cards (border color works fine for regular color textures)

which means outside the shadow volume I get a nice black, or those streaks from clamp_to_edge.

how do you guys treat this problem ? the quickest hack I thought about is just not rendering into the full depth texture, but leave a manual border of 1 pixel (I use copytexsub) however that is more of an hack than a real solution.

05-18-2006, 01:12 AM
Do you actually light anything outside the light frustum used for the shadow map? If not, just use six clip planes to cut off everything outside the light frustum.

05-18-2006, 03:06 AM
I used hacking stuffs but shaders allow to avoid those hack stuffs by just testing the depth value, so avoiding the back projection.

05-18-2006, 06:38 AM

I do the projection just with multitexturing and fixed function. looks ugly yeah, but it is a start...

so where it lies outside the near plane (that corner to the right) it is normal again, but within the far/backplane range it is broken on the sides.

I assume everyone uses pixelshaders and just caps the texcoords himself or so. or makes sure all objects are fully within the frustum

05-18-2006, 08:58 AM
For a directional/area light, your shadowmap should encompass the viewable scene, including all relevant occluders/receivers (a subject unto itself), so that would solve your first problem. Back projection can be fixed in a shader, yes, but you could also modulate by a texture with texgen setup to pick off z values along the light's view axis. In this way positive values will modulate to zero behind the light.

By the way, for the WRAP issue, plain old CLAMP works fine for me on Nvidia hardware. But then again, for me, it's never really an issue to start with.

05-18-2006, 09:08 PM
nvidia has its clamp_to_edge hack, and neither clamp nor clamp to border seem to use the border color for ati cards (border color works fine for regular color texturesr u sure about this? im using CLAMP_TO_BORDER the following which works on my nvidia, so it wont work with ati cards?
GLfloat white[]= { 1,1,1,1 };
glTexParameterfv( texture_target, GL_TEXTURE_BORDER_COLOR, white );

fwiw ive used the 1pixel selfmade border before as well (gf2 etc dont support borders) and whilst not optimal aint to bad.

05-18-2006, 10:58 PM
clamp_to_border would work on nvidia, too. but it does not on ati in combination with depth texture (at least drivers I had, which are not the very latest but also not that old, will grab new one to check if the bug is gone)

thanks for the confirmation on the self-made border, will go for it now, although if I ever add an FBO path it would probably need working border clamp.

Zulfiqar Malik
05-19-2006, 01:17 AM
Apart from just rendering the geometry visible to the light pov, we got rid of the border issues using our attenuation formula. Quite simply the region outside the lit area was rendered black.