
I suspect this is for compatibility reasons ( no one-dimensional textures in OpenGL ES). The above-quoted example uses two sampler2D, where it could actually use one sampler1D + one sampler2D.

Just reproduces the way retro-style palettes work. This is simply sampling in ColorTable (a palette in RGBA8), using MyIndexTexture (an 8 bits square texture in indexed colors). Vec4 texel = texture2D(ColorTable, myindex.xy) Vec4 myindex = texture2D(MyIndexTexture, TexCoord0) Uniform sampler2D ColorTable //256 x 1 pixels Hardware, you may use shaders to achieve that effect.

If you really need paletted textures on new Support for the EXT_paletted_texture extension has been dropped by the This put aside, if you start to accumulate tons of characters with tons of sprite animations in memory, maybe you could start using what's recommended by OpenGL, do-it-yourself palettes: Paletted textures (with different textures or different UV offsets if that fits) is the way to go: more flexible, data-driven, less impact on the code, less bugs, less worries. I wouldn't worry about wasting VRAM for a few character textures. This worked like a charm for achieving Megaman-like palette swapping! I use the source pixel's red channel as an index to the color table. Vec4 indexedColor = texture2D(colorTable, index) īoth textures are 32-bit, one texture is used as lookup table containing several palettes which are all the same size (in my case 6 colors). Vec2 index = vec2(color.r + paletteIndex, 0) I worry that duplicating textures just to change a color in them is wasting VRAM - should I not worry about that?Įdit: I ended up using the accepted answer's technique and here is my shader for reference. Ideally I would like to use a shader since it seems straightforward and requires little additional work opposed to the duplicated-texture method. 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.Use a shader and write some GLSL to perform the "palette swapping" behavior.

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. On modern hardware, though, this is a bit more challenging because the concept of palettes is not the same.Īll of my textures are 32-bit and do not use palettes. 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. Not all of the sprite's colors change, only certain ones do. For reference: in Megaman when you change your selected weapon then main character's palette changes to reflect the selected weapon. I'm working on a Megaman-like game where I need to change the color of certain pixels at runtime.
