Saturday, March 8, 2014

Casting a large shadow

Hey Everyone!


Glad you could come back to see my next blog! This blog will focus on the elements and techniques of how to do Shadow Mapping.


Well firstly I should answer the question that is floating around most peoples heads: "What is Shadow Mapping exactly?". Well that would be an excellent question, however the answer lies directly in the name of the technique. Shadow Mapping is literally mapping where a shadow would be placed in perspective to the light. Testing and seeing if each pixel that is on the terrain or surfaces is within shadow IE: If in the lights perspective the LIGHT Z coordinate isn't the same as the Z in our EYE space then yes the vertex is in shadow.

What I mean by that, is that we all see the world around us out of our eyes, in a game we see the world around us through a camera and a projection of that world. Well lets just think for a second, what casts shadows? Light! Exactly, so to find out if a shadow is going to show up in our projection (camera) eye space of the world, we need to see the world from the lights perspective first!

How do we do this? Well the answer to that is quite simple, we know for a fact that we can project the world through a camera, so we can see what is around us. What if we simply put the camera in the exact same spot as the light and made sure it would be oriented the exact same way the light is. Well then we could see if shadows were being cast couldn't we?

That brings me to a problem though, how do we get the camera there? Well we cant just translate it there and expect everything to work because we need to make sure that the vertex (point we are checking) is also the in the lights view.

I found this small little graphic that will hopefully help spread some light on the topic (punny)

So as you can see in the graphic the image place, is the camera, eye position and then we check the lights position as well, and for each surface we check if the Z of the light is equal to the Z of the camera. If not then the surface is not lit, and the color is changed to a darker version of what it was before.

In essence that is how we do shadow mapping. However there are some issues with shadow mapping that maybe you can get some ideas on how to fix by looking at a few more graphics that I found on the internet.

Basically because we are looking at individual pixels, and Z coordinates at the edges of objects their shadow will be boxy and not clear cut. Of course this is because when a surface is not lit we change the color to a darker one, however that color will be spread across that entire pixel, therefore we will always have pixels that are darker when they might be lit. Another issue along the same lines is that, often we will find pixels that are darker because they are in shadow and all of the sudden BANG! You have the pixel right next to it that is completely lit, which again contributes to the blocky shapes and artifacts on the outside of a shadow.

Knowing those pitfalls I want to show you guys those graphics that represent those issues, and if you do find a way to stop that from happening without actually changing the complete technique (Ie Choosing a new way of doing it). Then you might just be a genius because gaming companies have been trying to fix this issue for such a long time that they have now moved to a different standard technique :(. Anyhow here are those images.

In this image they have attempted to reduce the amount of artifacts in the right side by blurring it (Sometimes works but degrades the quality of the shadow).

This is a perfect example of what I am talking about, check this one out.

Alright! Well that is it for now on shadow mapping, now do remember I actually didn't go into detail on how to move the camera to the lights perspective, PLEASE do message me or comment here if you would like some MATHY stuff on that, I absolutely can oblige! 

Thanks for checking this blog out today guys!

Have a great one,
Until later,
Stephen Krieg








No comments:

Post a Comment