Sign in to follow this  
pondwater

XNA How do I (permanently) decrement a Texture2D alpha to 0?

Recommended Posts

I need to permanently decrement a Texture2D object's alpha components to a possible value of 0 (as to leave no artifacts).

I've created a trail effect by rendering to a renderTarget and every frame i need to decrement the alpha component of each pixel. To avoid a costly getData setData for loop conversion I've just rendered the texture onto itself with a decreased alpha component but as you would guess this leaves alphablending artifacts.

What is an effective way to achieve this? It would be a bonus if I could be done in a linear rate.

Share this post


Link to post
Share on other sites
I'm not sure what you mean decrement it to 0? as in... not drawing it anymore? Apologies if this is a ridiculous question... if nothing else it's a premature bump :).

Share this post


Link to post
Share on other sites
Could you render it without blending it against *anything* and use a shader to modify the alpha directly? Or is that what you're doing?

What does it look like? Can you post a screenshot?

Share this post


Link to post
Share on other sites
I have a persistent render target. Every frame I add onto this target by drawing the current moveable entities with a semi transparent alpha component (new Color(255,255,255,225)).

In order to create the fading trail effect I need a way to efficiently lower the alpha of each pixel each frame. That way older images become more and more transparent, while the more recent images are more prominent.

At first i figured I could use getData/setData and manually decrement the alpha values by lets say 5 or 10 each frame. But this seems horribly inefficient because the texture is essentially the size of my back buffer and the loop would be 1 million+ iterations.

So what i've been doing is drawing onto blank renderTarget2D at a translucent alpha value (lets say 245) and then swapping it. Therefore every pixel every frame is drawn as 225/255 alpha of itself. This works wonders and the image fades gradually however my problem is that it never quite reaches 0 this way. It ends up a faint grey that never leaves.

I've been testing around with different blendStates and their properties, some fade better than others. What I find is depending on the alpa/color source/destination blend properties I get one of two results:

a) a nice gradual fade that leaves a faint 'stain' on the screen (ex AlphaBlend)
b) a very rapid fade that leaves no stain. (ex Additive)

I'm not very familiar with using custom shaders and if its possible to do this without them that would be optimal.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this