Lighting and shadows

Published May 20, 2008
Advertisement
I've never been entirely happy with the shadows in Rescue Squad - they can't be transparent since they're made from multiple sprites, and so would cause ugly double darkening when they overlapped. The solution to this is to make them solid black (as seen in this screenshot). This creates it's own set of problems however, as it means it'll obscure anything you're hovering over and trying to pick up. So the shadow gets placed on a separate layer behind the objects and water ripples, which is physically daft but generally looks ok.

So instead I figured it was time to do them properly, which is what I've added now. The basic idea is to render shadows into a texture, so that overlapping shadows don't double-darken but instead clamp to pure black. Then we draw this texture in the normal rendering but semi transparent so our black/white mask turns into a softer shadow.



As always there's a bunch of complications to deal with however - firstly combining the generated shadow/lightmap texture with the scene requires it to be projected over all the regular sprites. That's a pain to do so instead there's two render-to-texture passes - one that creates the lightmap and one that creates the scene at full brightness. These are then combined to the framebuffer in a final pass with a fullscreen quad and standard multitexturing.

The other main snag is that the shadow should be obscured if it goes behind buildings. So we also have to draw the buildings, rocks and over objects as occulders into the lightmap texture, but in pure white. To avoid having to have duplicate sprites in pure-white I use EXT_Secondary_Color to tint the existing sprite texture on the fly. As a bonus, the secondary colour can also be used to tint the shadows the correct shade of grey (rather than black) which simplifies the final pass to just regular multitexturing.

Render-to-texture uses FBOs where possible, but will fallback to copying from the framebuffer if not available, so the whole thing only needs the secondary colour extension and 2-texture multitexturing, which even the lousy intergrated intel chips have by now, so it'll work pretty much anywhere. [grin]
Previous Entry Rescue Squad 2 Tiles
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement