Possible Duplicate:
How to colorize certain parts of a model - like RTS games have those team colors?

Ok, so here is my current situation. I have a player model, fully UV mapped, and textured. At first I made multiple bitmaps for the character representing multiple colors for each team in the game. (red, blue, green, yellow, etc) Well, as my player count build up, space lowers. So I needed to make a new method of keeping the game effecient, clean, and fast. So I thought of the idea of having a color mask (alpha map covering the areas to be colored). I am using OpenGL, and I just have NO idea on where to begin!

So I ask you, are there any libraries? methods? anything that could help me do this?

  • \$\begingroup\$ Are you doing this in fixed-function OpenGL or in shaders? \$\endgroup\$
    – ChrisE
    Apr 18, 2011 at 6:23

2 Answers 2


I recommend using the same idea that they use in movies - chroma key. Reserve one color that you don't otherwise use in your textures (e.g. green, blue, magenta). Let's call it the "reserved color." In the engine, make a matrix that rotates the "reserved color" onto the "player color" you wish to render at the moment.

Set this matrix as a pixel shader constant. In the pixel shader, compute the chroma of the pixel color and find its angle to the "reserved color's" chroma. Lerp the pixel color to the pixel color transformed by the matrix, according to how close the pixel's chroma is to the reserved color's chroma.

Why do this instead of using an alpha channel? Because when textures are DXT compressed, adding an alpha channel makes your texture 2x bigger. A matrix multiply and a little bit of trig in the pixel shader is a lot cheaper than reading 2x as much memory - and will become even cheaper as the years roll on.


you can make a model with some base color and replace that color with a shader.

color = texture_color(x,y);

if(color == base_color)
    color = team_color;