To maximize shadow resolution, I've got a shadow map that covers only the area closest to the camera. (I am aware of Cascading shadow maps, but for now, I am willing to simply lose shadows far away, in exchange for higher resolution near the camera.)
Specifically, I am rendering shadows of tree billboards, that are then cast on to a ground terrain.
First version worked great except for one issue. If a shadow is drawn that touches an edge of the shadow map, then that final row (or column) of pixels is REPEATED by the "Clamp" setting of the sampler. Result is a shadow "streak" that continues from the edge of map into the distance on the ground.
To eliminate those streaks, give full illumination when "outside" of shadow map, I added test to my lookup function to return full illumination (1.0) if UV outside of valid range:
if (texCoord.x < 0 || texCoord.x > 1 || texCoord.y < 0 || texCoord.y > 1) return 1.0f; ... followed by the code that looks up in shadow map, returns an illumination in range 0..1.
I have two questions about this:
Is there a more efficient way to test these 4 conditions, or to avoid the need to test?
Is there an efficient way to solve this when the shadow map is created?
The sampler is set to "clamp", so if the first and last row and column of map were all "untouched" (held the default depth value or illumination value, depending on the shadowing technique), then I would not need to do any special tests when using the map; "clamp" would retrieve an edge pixel, so if those all were "untouched" by shadows, I would get the desired result.
2.b. It just occurred to me that one solution to (2) is to write the default value back into the four edge rows/columns. [after all shadows are rendered] What is an efficient way to do that?