So I finally got to working on the shadow mapping and making it a bit more sophisticated. Previously I was only casting shadows directly down from above and only casting onto surfaces which were fairly flat, which was nice and simple, but we can do better, so started working on doing it properly.
I have used the normal offset shadow approach rather than biasing for getting rid of the shadow acne, having seen that et1337 had great success with this in Lemma, It does actually work very well for my case as well. Shadow acne is now gone completely and it all looks pretty rock solid.
I literally just had to change my shadow pixel shader like this:[code=:0]vector pos = mul(input.vpos, worldviewproj);// tovector pos = mul(input.vpos + vector(input.normal * 0.4f, 0), worldviewproj);
input.normal is already transformed to world space in the vertex shader. 0.4f is just a fudge factor that can be tweaked to suit.
Coloured the shadows red in the shader here to make them easier to spot at a distance.
Next up, I added some per-pixel distance fog to the main pixel shader for rendering the level geometry and started playing around trying to get a good general matrix for the directional light casting. After much tweaking and fiddling, I have a matrix for the light that now draws shadows correctly on anything that is in the view frustrum and within the fog distance range.
I haven't really done this "properly", I understand you can transform the view frustrum corners into light space and do a fitting calculation like that, but I've found that if I just take a point in the middle of the view frustrum then offset a distance from this point with the light direction, that gives me an acceptable result.
Everything is working off a single value I set CPU side for the farClip. In the screenshots above we have a far clip of 200, and the fog starts at around 170 and the shadow quality is still acceptable. I can make the far clip larger, but the shadow quality degrades the further I make it, so all about finding a happy balance for each level here.
Casting shadows onto walls is sure a neat feature though and really adds to the game. I think the shadow quality is going to be less of an issue when proper detailed levels with normal and diffuse mapping are in place. Just very obvious at the moment as being projected onto flat colour surfaces. We'll see. Can always revisit the shadow matrix generation in the future, since there are a range of ways to improve this.
So if I now start to divide levels up into sectors, I can only render the sectors who would fall within the fog distance, and in theory can have very large levels now without performance suffering.
Thanks for reading.
It's quite peculiar that with all that articles and threads about shadow mapping one doesn't see this approach more often. I also learned about it thanks to et1337's blog post. Works even reasonably well if you offset in the vertex shader already.
Edit: [url="http://www.gamedev.net/topic/665740-cant-fix-shadow-acne-with-bias/?view=findpost&p=5210839"]There you are[/url]