a problem on shadow mappping

I implemented shadow mapping by depth texture. it worked well for most situations. however, If some objects was above the horizon of the light’s view frustum, in theory their shadows should be projected to infinity(there was no sky box), but in fact the shadows were projected to the floor, against to light’s view direction. see the pictures below:
http://www.imageuploading.com/ims/pic.php?u=17027dShI2&i=107922
http://www.imageuploading.com/ims/pic.php?u=17027dShI2&i=107926

And I found you can easily repeat this bug in Paul’s tutorial(http://www.paulsprojects.net/tutorials/smt/smt.zip):

in scene.cpp, line 77: glutSolidCube(12.0f);
in main.cpp, line 29: VECTOR3D cameraPosition(-2.5f, 15.f,-2.5f);
in main.cpp, line 30: VECTOR3D lightPosition(1.0f, 0.6f,-1.0f);
in main.cpp, line 107: gluPerspective(45.0f, 1.0f, 0.1f, 10.0f);
in main.cpp, line 111: gluLookAt(lightPosition.x, lightPosition.y, lightPosition.z, 0.0f, 0.6f, 0.0f, 0.0f, 1.0f, 0.0f);

then you will find a obvious bug(shadow lies in the contrary direction of the light’s view):
http://www.imageuploading.com/ims/pic.php?u=17027dShI2&i=107930
I changed GL_CLAMP to be GL_CLAMP_TO_BORDER, but the result was not improved:
http://www.imageuploading.com/ims/pic.php?u=17027dShI2&i=107931
this is the view from light:
http://www.imageuploading.com/ims/pic.php?u=17027dShI2&i=107932

I hope some of you could help me with the problem. it has confused me for one week. any suggestion will be appreciated. thanks a lot!

the thing is in your first two pictures i can’t see any problem, your light source appears to be higher than any object and pointing down down into the ground and the shadows seems to confirm that

The last image looks like it’s taken from inside the red torus, so naturally it’s not gonna work that well.

Sorry for present some improper pictures. Now I select two appropriate viewpoints so you can see the problem clearly:

http://www.imageuploading.com/ims/pic.php?u=17027dShI2&i=107957
please note the cube in red circle. when you see it at the light’s view there is nothing behind it, so it should have no shadow at all.

http://www.imageuploading.com/ims/pic.php?u=17027dShI2&i=107956
but it has a shadow on the floor(in green circle), against to the light’s view frustum. it’s incorrect.

That’s normal, the shadowmap also projects in the reverse as it’s not the texture you project it’s the texture coordinates, but it doesn’t matter because in order to look decent and almost artifact free you need to multiply the shadow with the diffuse light, and that will remove the stuff behind the camera.

Thank you very much. if i want everything out of light to be in shadow, how can i do it? one method is to use GL_LIGHT_FALLOFF, but it doesn’t look very well at the edge of light’s view frustum.

there are 4 values you need to multiply together, the shadow, diffuse value, falloff and light texture, the last one uses the same texture coordinates as the depth texture and can be as simple as a white disc on a black background.
If you want you should also clip away everything behind the light.

Thanks, zeoverlord! How I can render a light texture? Could you explain it in detail?

You can draw the light texture in photoshop or paint if you want, it’s just to get a frame for the light and maybe some fading around the edges, it’s not needed if your using a cubemap, but it does give a bit of an “atmosphere”.

You do not have to use a “light texture”, which implies to me some lightmap or radiance cache anyway. I call it a “light mask”, but you can also compute it in your shader. It’s basically that a shadow mapped light represents the equivalent of a spot light. So if you look at the spot light falloff math in the lighthouse tutorials, or in the red book, you will get the idea. Basically everything that isn’t on the shadow map should not receive light.

The “light texture” or “light mask” has some advantages, because you can control the penumbra effect, etc. If you want to shadow map a point light, you will need 6 shadow maps.

Thanks, zeoverlord and Keith Z. Leonard. Now I get it!