I have a texture that is a render target which has an alpha channel. I’m trying to get an effect where objects leave a trail when drawn. The idea would be to render to a texture T, and then, instead of clearing T after each frame, simply reduce the alpha level across the entire texture.
T is then rendered to the screen, giving an awesome trail effect.
The problem is that I don’t know how to write to the alpha channel without affecting colour.
I can think of a work-around using texture swapping:
Suppose I have a texture B which I wish to draw leaving a trail, and I have two large (screen-sized) textures T1 and T2:
- T1 is rendered to T2 with alpha set to 0.9
- draw B to T2.
- T2 is rendered to screen
- T2 is rendered to T1 with alpha set to 0.9
- draw B to T1
- T1 is rendered to screen
- return to 1)
0.9 is some decay value, eg for very long trails, set it to 0.995
when rendering from T1 to T2 or T2 to T1, target blend function is ZERO so target data is ignored.
I’m pretty sure this would work, however it seems like a lot of work for something that really should be quite simple: all I want to do is reduce the texture render-target alpha values.
 ooh, on second thought, I think I may have solved the problem myself:
Render a white rectangle with alpha 0.9 to T with the following blend function:
that was easy