Writing to target alpha without changing colour

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:

  1. T1 is rendered to T2 with alpha set to 0.9
  2. draw B to T2.
  3. T2 is rendered to screen
  4. T2 is rendered to T1 with alpha set to 0.9
  5. draw B to T1
  6. T1 is rendered to screen
  7. return to 1)

notes:

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.

[edit] 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:

glBlendFunc(GL_ZERO, GL_SRC_COLOR);

that was easy :smiley:

glColorMask(false,false,false,true);

Heh, I could have sworn that existed, however after 15 minutes of googling for “opengl colour mask” and not finding it, I concluded that I was imagining things and it didn’t actually exist. I blame it on the wretched american spelling of colour. :stuck_out_tongue:

Anyway, thanks a lot. It doesn’t get much easier than that :slight_smile: