Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: GBuffer (color texture) with NORMAL and SPECULAR: Update only alpha

  1. #1
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    61

    Question GBuffer (color texture) with NORMAL and SPECULAR: Update only alpha

    Hello,

    I use a color texture as GBuffer to store in the RGB part a normal and in the A part a specular value.
    The GBuffer is bound as 2nd render target (MRT).

    Now I am wondering if it is possible to update only the alpha value using a specific glBlendFunc() setup?

    For example when my shader outputs this to the 2nd render target (DST)...

    Code :
    f_Color1 = vec4(0.0, 0.0, 0.0, Specular);

    ...then I would like to achieve two cases:

    1. In this case only the A part in DST should be overwritten with the value in "Specular". The RGB values in DST should stay untouched.

    2. In this case the value in "Specular" should be added to the A part in DST. The RGB values in DST should stay untouched.

    Help is really appreciated!
    ++i--;

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,008
    Now I am wondering if it is possible to update only the alpha value using a specific glBlendFunc() setup?
    You can use blending, but generally the way to handle case 1 is with an appropriate write mask:

    Code :
    glColorMaski​(X, GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);

    Where "X" is the color index of the draw buffer that represents your specular image buffer. Since you're doing deferred rendering, your FBO probably has multiple color buffers, so you need to specify in the write mask that you're referring to that particular color buffer.

    For case 2, you must use blending, since you're adding the values. Though using the write mask above is not a bad idea in addition to blending:

    Code :
    glEnablei(GL_BLEND, X);
    glBlendEquationSeparate​i(X, GL_FUNC_ADD​);
    glBlendFuncSeparatei(X, GL_ZERO​, GL_ONE, GL_ONE, GL_ONE);

    Where "X" has the same definition as above. Note that, while the indexed color mask (glColorMaski) has been core OpenGL functionality since GL 3.0, the indexed blend enable/equation/func requires 4.0 or ARB_draw_buffers_blend. If it's not available, you'll have to use the non-indexed forms.

  3. #3
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    61
    Thanks a lot! This is exactly what I need.
    ++i--;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •