# Best shadow mapping quality for semi-top-down view

## Recommended Posts

Well met!

I am struggeling with improving the quality of my shadows (for a directional lightsource).

What I am doing:
- Create a lightViewMatrix. For the lookAt, I pick the point on the terrain that intersects with the cameras viewDirection. For the look from, I go farPlane/2 units in negative lightDirection.
- Create an orthogonal lightProjectionMatrix. Near and farplane are obvious, and for the size I try to kinda guess a number from the camPosition.y, so that everything on screen is covert. (Obviously, this only works if camera doesn't rotate on any axis)

- Render all objects in my scene with this viewProjectionMatrix to a texture, using a pixelshader that outputs 1.0f if the depth is > 0.0f (otherwise 0.0f).
- Blurr the resulting texture
- Project the texture back onto the terrain, subtracting the value from the light-intensity (in the terrains pixel-shader)


Result

Result without blurr

The camera position and angle roughly reflect what I have in mind for the finished game.

LightDirection: float3(0.2f, -1.0f, 0.2f)

(high res, zoom in for details)

While it does not look all that bad, there are some obvious problems:

- Even with a big shadowMap (2000x2000 in the screenshots), the shadows have very little detail. This is the case because of large parts of the shadowmap beeing "off-screen".

- I can not do object-to-object projection, because if I have to have 1.0f/0.0f values to get a useable blurred image. I tried to work around this by using the .r channel of the texture for depth and the .g for blurr-factor. However, I ran into the problem of not beeing able to use the blurr-factor on parts that are not inside the original shadow, resulting in cut-off blurrs on the edges.

So, I went and tried to find something that could improve my shadowquality. I found Cascaded shadowmapping, but that seems overkill for this kind of camera angle. Also mentioned was perspective shadowmapping, but I could not figure out how to implement that, also it is supposed to produce a lot of artifacts (?).

The best thing I found was Unit Cube Clipping, but I do not have the slightest clue on how to implement that either.

Which method do you suggest? A few lines or a link on how to implement it would be greatly apprechiated.

I would like to be able to blurr the shadows and also do obj-to-obj projection (without drawing geometry a 3rd time).

Beeing able to tightly fit the shadow-map into the visible part of the terrain would be the most important step I guess.

As always, thanks for your time and help!

##### Share on other sites
ChrisChiu    306

Light-space Perspective Shadowmapping could solve this:

http://www.cg.tuwien.ac.at/~scherzer/files/papers/LispSM_survey.pdf

Though I think the main first improvement for you (which is also the first step in LispSM), if focusing your shadowmap on the area that is actually within the camera (meaning you don't render shadow map parts that are outside the visible camera). That is essentially done by reducing the size of the camera frustum of the shadowmap pass so that it tightly fits around the camera frustum of the regular render pass.