Is it possible to change a specific color of a model to another?
Example:
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.
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityIs it possible to change a specific color of a model to another?
Example:
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.
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.
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];
t.GetData(data);
for (int x = 0; x < t.width * t.height) {
if (data[x] == Color.White) {
data[x] = Color.Blue;
}
}
newt.SetData(data);
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.