My scene is composed of layers that render to framebuffers. Within the framebuffers, elements are drawn back to front and are blended with ColorWithAlpha
or EraseWithAlpha
. Framebuffers are blended with the corresponding *WithPremultipliedAlpha versions. The following code controls blending:
switch (m_blendMode)
{
case BlendMode::ColorWithAlpha:
{
glBlendEquation(GL_FUNC_ADD);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
break;
}
case BlendMode::ColorWithPremultipliedSrcAlpha:
{
glBlendEquation(GL_FUNC_ADD);
glBlendFuncSeparate(GL_ONE, GL_ONE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
break;
}
case BlendMode::EraseWithAlpha:
{
glBlendEquation(GL_FUNC_ADD);
glBlendFuncSeparate(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
break;
}
case BlendMode::EraseWithPremultipliedSrcAlpha:
{
glBlendEquation(GL_FUNC_ADD);
glBlendFuncSeparate(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
break;
}
I'm struggling to get erasing working across frame buffer boundaries. Drawing all elements back to front into one framebuffer using ColorWithAlpha
is the equivalent of drawing all elements except one into one framebuffer and then drawing the final layer into a separate framebuffer using ColorWithAlpha
, and then blending the separate framebuffer into the original using ColorWithPremultipliedAlpha
. The same is not true for erasing. I've tried drawing layers back to front using ColorWithAlpha
and then EraseWithPremultipliedAlpha
to blend the target FBO with the dest FBO. This is unfortunately not equivalent to drawing all elements in the top FBO directly into the dest FBO with EraseWithAlpha
. Is it possible to make the erase blend mode associative, enabling the same setup as exists with the coloring modes? If not, is there a pseudo erase blend mode that is associative and could be swapped in here?