Creating a retro-style palette swapping effect in OpenGL

Posted by Zack The Human on Game Development See other posts from Game Development or by Zack The Human
Published on 2012-11-07T00:23:29Z Indexed on 2012/11/07 5:16 UTC
Read the original article Hit count: 309

Filed under:
|
|

I'm working on a Megaman-like game where I need to change the color of certain pixels at runtime. For reference: in Megaman when you change your selected weapon then main character's palette changes to reflect the selected weapon. Not all of the sprite's colors change, only certain ones do.

This kind of effect was common and quite easy to do on the NES since the programmer had access to the palette and the logical mapping between pixels and palette indices. On modern hardware, though, this is a bit more challenging because the concept of palettes is not the same.

All of my textures are 32-bit and do not use palettes.

There are two ways I know of to achieve the effect I want, but I'm curious if there are better ways to achieve this effect easily. The two options I know of are:

  1. Use a shader and write some GLSL to perform the "palette swapping" behavior.
  2. If shaders are not available (say, because the graphics card doesn't support them) then it is possible to clone the "original" textures and generate different versions with the color changes pre-applied.

Ideally I would like to use a shader since it seems straightforward and requires little additional work opposed to the duplicated-texture method. I worry that duplicating textures just to change a color in them is wasting VRAM -- should I not worry about that?

© Game Development or respective owner

Related posts about opengl

Related posts about textures