change certain colors in a texture?

Started by
3 comments, last by flashinpan 15 years, 5 months ago
I have some .PNG files that I am assigning to 2DTexture objects. Certain areas of these .PNG will be a certain color, say orange. Is it possible in XNA to say "change all pixels that are set to orange to red" What I am trying to accomplish is to make ONE set of animated sprites ... but have 2 sides using the same set ... one side will have orange coloring ... the other will have red coloring ... without having to make two seperate sets.
Advertisement
You have a pixel shader test for a certain colour and replace it with another colour. Something like:

float4 colour = tex2D(texture, coord);
if (colour == ORANGE) colour = gSideColour;

Another way is to have another texture or channel (if your alpha isn't used) to mark where to multiply, add or lerp another colour. This allows for a better visual effect, with gradients, instead of just one colour. For example (assuming alpha).

colour.rgb = lerp(colour.rgb, gSideColour, colour.a);
Quote:Original post by ET3D
You have a pixel shader test for a certain colour and replace it with another colour. Something like:

float4 colour = tex2D(texture, coord);
if (colour == ORANGE) colour = gSideColour;

Another way is to have another texture or channel (if your alpha isn't used) to mark where to multiply, add or lerp another colour. This allows for a better visual effect, with gradients, instead of just one colour. For example (assuming alpha).

colour.rgb = lerp(colour.rgb, gSideColour, colour.a);



I can't seem to find "float4" -- ???
I would go with color overlay like ET3D said using a pixel shader will be much slower.
Quote:Original post by Headkaze
I would go with color overlay like ET3D said using a pixel shader will be much slower.




Can you provide sample code? Total n00b at all of this.

This topic is closed to new replies.

Advertisement