Friday, January 8, 2010

Nearly Free Shadows

Click the image for animation. Might not display correctly in Chrome.

Click the image for animation. Might not display correctly in Chrome.

I've been wanting levels shadows ever since I started adding blob shadows to all the objects, but didn't think of this solution until just now. This method uses vertex colors and vertex alpha so there's no texture used. I simply take the floor and cut out all the squares that are not touching any walls, and then reduce vertices. After that I select all the edge vertices and then just give them a 0% opacity and make them all gray in vertex color. In the editor I just apply a Mulitply material that all my other shadows use so they will all batch together requiring no extra draw calls.

This method probably wouldn't work so well if you weren't using grid built geometry but a lot of games do.


Danny Parks said...

Neat trick! I'm guessing this is something you do only after the level design is locked.
Are you using a texture atlas on this? Since it's using the vert color/alpha you should still be able to shift the UVs around without any trouble. Nice work!

Kristopher Peterson said...

Yeah, you'd probably want to wait till you were pretty sure of the final layout before doing this, especially if your level geometry was more complicated than this example.

Yes, I'm using texture atlases and since these shadows are totally separate geometry and don't use texture, I can do anything I want with the texture atlas and it won't affect them.