How can I cast a sprite to white in XNA?

I donโ€™t think itโ€™s possible just by using the color setting in SpriteBatch, so Iโ€™m trying to develop a simple shader that will take every pixel and make it white, observing the alpha value of the pixel.

Joel Martinez's answer looked right, but how can I turn this on when I draw a sprite using SpriteBatch?

+6
c # xna shader
source share
5 answers

I think this is what you are 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 selected color from the texture, and then returns all white color using the alpha texture value.

+3
source share

I am attaching the documentation page from MS, and if you follow all the steps, you should quickly start and start it.

http://msdn.microsoft.com/en-us/library/bb203872(MSDN.9).aspx

To summarize - you need to create and use a file (in combination with the above code that really suits your purposes), add it to your project, and then load it into the source file and use it as shown in the link.

By the way: I donโ€™t quite remember SpriteBatch (since I decided to write my own, itโ€™s too restrictive), but as I remember, you may need to set the effect in the material that you send to the rendering. In any case - maybe you will find it here:

http://creators.xna.com/en-us/utilities/spritebatchshader

And the extended code if you want to get there:

http://creators.xna.com/en-us/sample/particle3d

Good luck

+1
source share

If you want to use custom shaders using SpriteBatch, check out this example:

http://creators.xna.com/en-us/sample/spriteeffects

+1
source share

Joel Martinez is really right, and you use it like this with SpriteBatch, loading the effect into tintWhiteEffect:

 spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None); tintWhiteEffect.Begin(); tintWhiteEffect.CurrentTechnique.Passes[0].Begin(); // DRAW SPRITES HERE USING SPRITEBATCH tintWhiteEffect.CurrentTechnique.Passes[0].End(); tintWhiteEffect.End(); spriteBatch.End(); 

SpriteSortMode.Immediate is the trick here, it allows you to change your default SpriteBatch shader. Using this, you will make the sprite drawing a little slower, since the sprites are not assembled into a single call to draw, but I donโ€™t think you will notice the difference.

+1
source share

I did not write my own pixel shaders, mostly modified samples from the network, what would you do is increase the value of the R, G, B components in the pixel, respectively, if they are less than 255, this would gradually change the color of the sprite to white. Hey, this is a rhyme.

0
source share

All Articles