1
$\begingroup$

I am trying to compose two rendering results into one, so that src texture is cut out by the alpha from destination texture(or buffer).

I prototyped the correct blending equation here. And tried to use it in my OpenGL program.

I expect to see result similar to this (the images are different though):

enter image description here

The green grass in a water is source,while empty circle is destination texture with transparent alpha around the circle area.

Here is how I do it in my OpenGL app. I omit the OpenGL code for actual drawing routines because I use a an API,which wraps pure GL method. There are no any errors there,and I run debug output + NVidia NSight to make sure there are no errors.

1.Set alpha blending mode:

glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

1.Use FBO A,clear its color buffer to zeros.

  1. Draw the object with texture that has alpha (premultiplied)

  2. Use FBO B,clear its color buffer(texture) to zeros.

  3. Draw the object with texture that has no alpha (like grass in a water)

  4. Blend pass. Use FBO A to render too.Bind texture from FBO B to sample from.

  5. Set blending mode to:

    glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ONE); glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_SUBTRACT);

  6. Draw full screen quad,where source is results from FBO B and destination is results from FBO A.

What I get is the content of FBO B, without alpha cutout.The results from FBO A completely disappeared. And it drives me mad,why it doesn't work. The target FBO contains alpha info from the first pass.So when I render into it content of FBO B,which is fully opaque,except the regions which were not covered with fragments during geometry pass,i expect the source image's alpha subtracted by the destination buffer's alpha,which must produce transparent areas where destination buffer's alpha is 1 and vice versa.

Now,I can solve this thing with programmatic blending in GLSL. But I want to understand why it doesn't work with hardware blending modes.

$\endgroup$
  • $\begingroup$ I wonder if this site should even exit. The answer rate here is too low. $\endgroup$ – Michael IV Feb 26 '18 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.