In the v0.6.0 update for Masteroid I overhauled all weapon sprites. As with most things in Masteroid, Weapons are mostly driven by data (JSON) and were originally dynamically colored at runtime using Modulate blending. Modulate color blending is sometimes called Multiply because it multiplies the component colors to get a final result. Modulate blending is relatively fast.

The simplest explanation for Modulate is that it colorizes the white parts of an image. This is perfect for space ships in Masteroid because they are all black with white cockpit windows. When you colorize them, the white portions of the sprite become the target color and the blacks stay black. But with weapon sprites this is undesirable because you want white tones in most weapons. To colorize a sprite but keep the white parts you have to do two steps: first blend the target color using Modulate with each sprite pixel to colorize it completely. Then, you have to blend the original sprite with the colorized sprite using Add blend mode. This colorizes the mid tones but leaves the white tones white. In Photoshop this is called the “Overlay” blend mode (Overlay is probably significantly more complex but Modulate + Add is a close approximation). Here’s an example of what a laser sprite might look like originally and with the two different blend modes:

Unfortunately, Overlay-style blending is far more “expensive”. Either I’d have to write a special shader or do a super hacky system of layered sprites with different blend modes. And switching blend modes causes a “render break” (a state change on the graphics card caused by switching textures, blend modes, etc). Lots of render breaks have a significant impact on performance. Given the number of shots on the screen in Masteroid at any given time, this would probably have a performance impact that outweighs the value of dynamic colorization.

Also note that neither of these options will work if you don’t want the sprite to be fully colorized. If you want other colors like a mix of blues and greens you can’t colorize a sprite at all (you could hue shift it but that’s different).

So, ultimately I decided to go with manually colored sprites at “art time” (versus runtime). This makes weapons much more unique and robust but its harder to add weapons on-the-fly through data alone.

Categories: GameDevMasteroid

Leave a Reply

Your email address will not be published. Required fields are marked *