I am trying to shadowmap a large terrain, I position my light that it is always at the position of the player and looking at the player, the problem is that the shadows now move with the player creating a weird effect where it looks like the shadows are floating above the surface, I tried to just set the light at a fixed location which solved my issue however when the player walks out of this light there is no more shadow, I do not think I can fit the entire terrain onto the shadowmap because the terrain is so large, so how I am supposed to solve this? How do I make the shadowmap only follow the player without the shadows themselves moving with the camera?
Shadowmapping a big scene
Crossbones+ - Reputation: 2130
Posted 28 April 2013 - 02:21 PM
For directional lights you should use orthogonal matrices - at opengl-tutorial they have an article about how to setup shadow map for directional light (e.g. using orthogonal matrix) - http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/
For large scenes, you probably want to render shadows in distance, to achieve this you can use cascaded shadow maps - for more information read at least these 2 sources
And MJP's code (it's also commented and easy to understand) - http://mynameismjp.wordpress.com/2009/02/17/deferred-cascaded-shadow-maps/
... you can also google for "cascaded shadow maps" I'm sure that Microsoft's link is one of the first, and there is like a TON of others explaining more or less the same.
Also this paper http://visual-computing.intel-research.net/art/publications/sdsm/sdsmLauritzen_I3D2011.pdf from Andrew Lauritzen (I think he was even visiting this forums at some point, although I don't think he is still around...), explains how to further extend CSM (e.g. use better partitioning) to achieve really great results. I still haven't implemented this in my engine, but I've got it on my todo list .
My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com
Members - Reputation: 1373
Posted 28 April 2013 - 05:44 PM
You can combine two methods if your light doesn't rotate. You can generate the lightmap for static scene and use the shadow mapping using an ortho projection for dynamic objects. The best is SDSM, Vilem Otte gave the link of the paper, you can found the demo source who is Direct3D11 based. It's important to notice that SDSM needs compute shader, without compute shader you will need to read back a lot and you will lost performance.