Results 1 to 4 of 4

Thread: glClear alpha vs geometry alpha -- blending result confusin

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    5

    glClear alpha vs geometry alpha -- blending result confusin

    There are a couple threads on *nearly* this topic, but they are either divergent or died out.

    I have a framebuffer that I have to have a meaningful alpha plane in. The image gets rendered and then gets blended based on reulting alpha per pixel in the framebuffer (hardware combiner)

    So I do a
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    Draw the geometry which has some transparent components.
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


    Since I have cleared with opaque black clear color, I expect the results to be opaque. But they are the alpha of the geometry rendered over it - SRC_ALPHA.

    Huh?

    In other cases I will NEED to render the SRC_ALPHA into the framebuffer - to "cut a hole" in the scene.

    So what little dance do I need to do to control when the SRC_ALPHA goes straight to the framebuffer (or FBO) from the SRC in order to "cut through" the scene and when it blends with the existing background to be "more opaque" as layers get added?

    It has been a long day on this one.
    Any thoughts are greatly appreciated?

    Thanks,
    Jason

  2. #2
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: glClear alpha vs geometry alpha -- blending result conf

    Try to formulate what you want to achieve in terms of addition and multiplication of the RGB and alpha values, and it should quickly become clear what you need to do.

    Note that OpenGL ES 2.0 has glBlendFuncSeparate which lets you specify different factors for RGB and alpha.


    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) does not guarantee that the destination alpha value remains one. Assuming the default blend equation GL_FUNC_ADD, it means:
    dest.rgba = src.rgba * src.a + dest.rgba * (1-src.a)
    i.e. for alpha
    dest.a = src.a * src.a + dest.a * (1-src.a)

    This value will only be one if (src.a == 1) or (src.a == 0 and dest.a == 1).
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    5

    Re: glClear alpha vs geometry alpha -- blending result conf

    glBlendFuncSeparate

    News to me - beautiful! - That actually solves my next question as well.

    Many thanks,
    Jason

  4. #4
    Junior Member
    Join Date
    Jun 2011
    Posts
    5

    Re: glClear alpha vs geometry alpha -- blending result conf

    Another excellent solution that I'm going with was suggested by Steve Baker elsewhere - is to make use of -

    > glColorMask(1,1,1,0) to mask out the alpha plane
    > when I don't want to write into it.

    Very very handy stuff. Thanks all
    Jason

Similar Threads

  1. Source Alpha Blending without an Alpha Buffer
    By niallm in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 06-18-2009, 01:51 AM
  2. alpha blending problem
    By 0stress in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 10-06-2006, 09:14 AM
  3. alpha blending fluttering
    By 0stress in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 09-04-2006, 08:32 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
  •