Jump to content
  • Advertisement
Sign in to follow this  
flashinpan

change certain colors in a texture?

This topic is 3693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
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" -- ???

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!