Results 1 to 3 of 3

Thread: Writing to target alpha without changing colour

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2009
    Posts
    14

    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





  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,294

    Re: Writing to target alpha without changing colour

    glColorMask(false,false,false,true);

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2009
    Posts
    14

    Re: Writing to target alpha without changing colour

    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. :P

    Anyway, thanks a lot. It doesn't get much easier than that

Similar Threads

  1. MRT: Writing to a render target based on a condition that involves a uniform?
    By RealtimeSlave in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 09-19-2015, 12:18 PM
  2. FBO and changing the colour attachment
    By IneQuation.pl in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-15-2010, 05:38 PM
  3. Background Changing Colour and Images Messed Up
    By Salbris in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 07-11-2009, 03:16 PM
  4. Changing text colour half-way through?
    By RobertWebb in forum OpenGL: Advanced Coding
    Replies: 11
    Last Post: 02-22-2005, 08:30 AM
  5. Problem changing pixmap font colour
    By Adrian67 in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 05-02-2003, 06:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean