Thursday, 7 February 2013

The Case of the Square Shadow

Recently I have been working on getting shadows in our game. I was having this problem where my entire scene would be in shadow.  I zoomed the camera out and I discovered that the entire scene wasn’t in shadow but rather just a large square area of it.

At first I thought my depth map had to be incorrect but I displayed it to the screen and it looked alright to me.

Then I thought I wasn’t performing my space transformations correctly, but I went over the transformations time and time again and I was convinced there was nothing wrong with my math. So I decided to do something I should have done from the beginning, instead of rendering the depth I rendered the color. Nothing could have prepared me for what happened next…

That’s right, there is a floating floor in my light’s view. That probably explains the square shaped shadow. I have no idea why that floor is there. But when I saw that I just turned off my computer. I made this discovery a couple of weeks ago and I still don’t know why that floor is there.

There is a lesson to be learned here, if you are ever having problems with shadow mapping, make sure your depth map doesn’t have any artifacts in it. Remember, depth maps can be deceiving. In my depth map (pictured above) it looks normal but given how precise the values stored in a depth map are, just because you can’t see something doesn’t mean it isn’t there.