Jump to content
  • entries
    743
  • comments
    1924
  • views
    583702

Me and my shadow...

Sign in to follow this  
Aardvajk

1838 views

distance2.jpg

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.

distance.jpg

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.
Sign in to follow this  


4 Comments


Recommended Comments

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] smile.png

Share this comment


Link to comment

Yes, its strange. I know some people have reported that it doesn't work for their cases but I can't personally see a) how it would fail or b) why anyone ever preferred using any other kind of biasing. This just seems like a common sense approach to me.

 

Perhaps I'll encounter more problems as I add more sophisticated geometry to the mix.

 

Good thought re adding in the VS rather than the PS, will have to give that a try.

Share this comment


Link to comment
Will see if I can dig up what I saw. Was just a comment in a piece giving an overview of various dynamic shadow techniques I think.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!