Shadow maps and field of view

Hi!

I’m implementing a shadow map algorithm (with ARB_DEPTH_TEXTURE and ARB_SHADOW) and have finally managed to get a shadowed scene However, I’m having trouble with the light’s field of view settings. I’m inexperienced with OpenGL and shadow-maps, so this may have an easy solution.

When the field of view is about 50 - my scene gets partially black (black where the light-view can’t see). But when I increase it, the shadows get really blocky (I use a 512x512 map).

Is there any way to show the areas the light view can’t see in the final scene, or is there another solution to this problem?

Thanks,

  • Monica

Hi,

So do you want to show the light’s fov in the scene so you get some feedback when adjusting it, or make the areas outside of it always lit?

For the first case there are lots of things you can do. You can, for example project a color texture on the scene instead of the shadowmap. Make the border different color than the rest of the texture and use GL_CLAMP, so the area the light sees will get a different color. Don’t use mipmaps, they’ll mess this up. This is propably the easiest thing for you to do, since you are already projecting textures on the scene.

For the other case the solution is pretty similar, just make sure that the border pixels of your shadow map present the biggest possible depths, then the pixels outside the map always pass the shadow test. You can do this by scissor testing or limiting the viewpoint to not allow drawing on the borders while making the shadow map.

-Ilkka

Hi!

I want the areas outside the light’s fov to be lit - the areas that does not get compared with the shadow map.

Originally posted by JustHanging:
[b]
just make sure that the border pixels of your shadow map present the biggest possible depths, then the pixels outside the map always pass the shadow test. You can do this by scissor testing or limiting the viewpoint to not allow drawing on the borders while making the shadow map.

-Ilkka[/b]

But why have the shadow map’s border pixels anything to do with this? (I’m a bit new to OpenGL) I believe most of the border pixels in the shadow maps in my test-scene actually have the biggest possible depths (there aren’t any occluders there)… (Only a few of my objects has shadow).

Maybe it’s something else that is wrong? Why are the areas that aren’t covered by the shadow map in shadow?

[This message has been edited by Monica (edited 03-06-2003).]

The border pixels matter because when a fragment falls outside the shadow map, it’s value gets sampled from the nearest border pixel. That is, if you use GL_CLAMP. If you make sure that all border pixels have maximum possible depth values, all pixels outside the light’s fov get the their lightspace depths compared to the maximum possible value always passing the shadow test.

There is a problem behind the lightsource, since the same shadowmap gets projected there too due to the way projective textures are implemented in opengl. But I think this gets fixed automatically with shadowmaps, since fragments behind the light get negative (clamped to 0) lightspace depths, also always passing the shadow test.

-Ilkka

Thank you so much! I used GL_CLAMP_TO_BORDER, but when I tried GL_CLAMP it worked!!!

I thought CLAMP_TO_BORDER (or TO_EDGE) was supposed to be better than just CLAMP (better shadows?)…? I don’t think I have understood this clamp-thing.

Thank you again! You have solved a big problem for me!

  • Monica

CLAMP_TO_BORDER clamps to the separately specified border color, if you haven’t explicitly uploaded a border into your texture. Since you’re saying you’re using 512x512, I believe you’re not using border texels, as such a texture would be sized 514x514.

CLAMP_TO_EDGE should be sufficient for you, assuming no objects shadow the edge texels of your shadow map.

You may wish to google for “perspective shadow maps” which add a technique that improves the quality of shadow mapping in many cases. Also, you may consider fading out shadows in the distance, in order to not have to cover screen pixels a kilometer away in shadow texels, which gets annoying quickly.