Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tint a sprite to white in XNA?

Tags:

c#

tint

shader

xna

I don't think this is possible just using the color setting in SpriteBatch, so I'm trying to work out a simple shader that would take every pixel and make it white, while respecting the alpha value of the pixel.

The answer Joel Martinez gave looks right, but how do I incorporate that when I draw the sprite with SpriteBatch?

like image 504
Iain Avatar asked Sep 17 '08 13:09

Iain


1 Answers

I think this is what you're looking for

sampler2D baseMap;

struct PS_INPUT 
{
   float2 Texcoord : TEXCOORD0;

};

float4 ps_main( PS_INPUT Input ) : COLOR0
{
   float4 color = tex2D( baseMap, Input.Texcoord );
   return float4(1.0f, 1.0f, 1.0f, color.w);
}

It's very simple, it just takes the sampled color from the texture, and then returns an all white color using the texture's alpha value.

like image 187
Joel Martinez Avatar answered Oct 19 '22 06:10

Joel Martinez