Is it possible to change a specific color of a model to another?


Everything that's blue should be red or something like that.

And is it possible to do this without the use of effects? I still want to use the basic effect.

  • 2
    \$\begingroup\$ Why the no effects limitation? There is an entire example dedicated to doing this, xbox.create.msdn.com/en-US/education/catalog/sample/… , but it uses shaders. \$\endgroup\$ Commented Apr 16, 2013 at 15:37
  • \$\begingroup\$ How are you calculating color information? Is your model texture mapped or are you using per-vertex color attributes? \$\endgroup\$
    – Mokosha
    Commented Apr 16, 2013 at 15:49
  • \$\begingroup\$ I'm using textures attached to the model with SketchUp. I don't want to use effects, because I want to use the basic effect. \$\endgroup\$ Commented Apr 16, 2013 at 16:33

2 Answers 2


Because you are unwilling to employ a non BasicEffect to accomplish this, here is your only other option. This is quoted from the description of the complete, free, and functional example project created by the developers of the XNA framework, Color Replacement.

When it's the Red Team versus the Blue Team, or when you want to drive a car painted with your favorite color, you either need to create a texture for each color or perform color replacement programmatically.

In this quote, the pragmatically refers to using an instance of Effect and a shader. So you can see what you are left with. (In case you would consider changing the model's data at runtime, don't forget that it is compiled into binary before the game ever runs.)

I strongly recommend that you reconsider your position about only using BasicEffect. Drawing models does not require it.

  • \$\begingroup\$ "the pragmatically refers to using an instance of Effect and a shader" Or you could clone the texture and edit the color array. \$\endgroup\$ Commented Apr 17, 2013 at 19:46
  • \$\begingroup\$ @ClassicThunder Yup. There are all kinds of memory- and CPU-intensive texture-swapping solutions. \$\endgroup\$ Commented Apr 17, 2013 at 19:55
  • \$\begingroup\$ Trading performance for a simplicity in regards to a one time operation in a homebrewed project may be perfectly acceptable in this situation. \$\endgroup\$ Commented Apr 17, 2013 at 19:58

You can create a texture of the same size, alter the colors programmatically, and then use it in place of the original. Then you can replace the altered texture using the BasicEffect.Texture property.

Texture2D newt = new Texture2D(graphicsDevice, t.width, t.height);

Color[] data = new Color[t.Width * t.Height];

for (int x = 0; x < t.width * t.height) {
    if (data[x] == Color.White) {
        data[x] = Color.Blue;


Note that this is much more memory intensive than using a shader to recolor the texture dynamically since you need as many textures as number models * active colors.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .