• Register

We would like to see this game being played by children who have a good life and a good education. Through this game we would like to make those children aware of the educational troubles in various regions of the world.

Post news Report RSS Shadows

For our newest update for edudrive, we have been adding shadows, using shadow maps.

Posted by on

First of all, we needed to render a shadow map, using a different camera (the view and projection of the light). Since it's supposed to represent sunlight, we're using a orthographic projection, simulating directional light.
We create the shadowmap by drawing every level element and simply returning a depthmap.
Shadowmap:

User Posted Image

By then looking up the depth of the elements in the pixel shader (in the normal draw) and comparing them to the depth stored in the depthmap, we can determine if the pixel is in shadow or not
result:

User Posted Image

Now we have 2 problems here:
1. the lookup isn't very accurate, because of some precision problems using floats
2. the edges of the shadows look too jaggy, we need to soften it a bit more.

The solution of the first problem: we have 4 channels (r,g,b,a) when we write to our shadow map, but we only use one of them. So, i splitted up the shadow depths in 3 parts, by first multiplying the value by 3; that way, we can use the channels like this:
red channel for the range (0-1)
green channel for the range(1-2)
blue channel for the range (2-3)

Then we get something like this:

User Posted Image

the second problem was solved by blurring the lookup of the shadow map this was done by taking the average of surrounding pixels instead of just one pixel

result:

User Posted Image

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: