12/14/04: DEEP THOUGHTS...CREATING WATER EFFECTS
IN THE SWIM OF THINGS
Since most city maps have lots of river, lake or ocean terrain, I needed a way to show a monster moving through various depths of water. Normally in a 3D game this isn't such a challenge -- you would clip the monster's polygons to a water plane, or have a semitransparent water plane obscuring the lower half of the model. But since our game engine is 2D sprite-based, I don't really have a good way of knowing what pixels are at what height. With a simple shape, one could perform a mapping of Y-height to Z-altitude in an isometric perspective, but when the shape gets more complex it's impossible to know if a given pixel is back and low vs. forward and high. A rough approximation can be made, but it really doesn't look good when applied to the 2D sprite. So I create a grayscale pixel map copy of each frame of the monster's animations by mapping a shadowless, fixed-scale gradient texture on the 3D model. This texture is rendered as part of the sprite output scripting, compressed, and then bundled with the sprite graphics as another meta-data chunk. This extra data gives me the Z-altitude of any pixel, which I can then use to cull pixels from the sprite as the monster becomes partially submerged. It's similar to a 3D depth Z-buffer, except it represents vertical height slices of the 2D pixels in 3D space.
The game maps contain water depth information for each water terrain tile, which allows me to know how deep the monster is. I add animated waves, ripples, splashes, etc. as the monster moves through the water. If the monster is completely submerged, you can only see surface bubbles. When completely underwater, the monster is hidden from the humans and generally safe from most attacks, although many monsters are airbreathers and can drown if they stay submerged for too long. Some monsters can also take damage from any contact with water, including decapitated fire hydrants. For example, Harry the Skeleton Warrior (being a supernatural creature like a vampire or ghost), dislikes running water. Water contact will also make the Tin Behemoth's batteries short out. -- Lars