1

Ok, so here's the deal:

I've just gotten my hands dirty with deferred lighting. I won't go into details, but I've been using FBO's a lot and have run into a problem.

Throughout my rendering process I'm using glBlend:

GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA

to get the result I want. If I render my scene onto the "real" framebuffer (the back buffer?) I get proper result. The problem is that if I render something to an FBO first, then render that FBO into the "real" framebuffer, I get transparency issues.

It difficult to explain, but I'll give it a try. Say I render a pixel with RGBA (0.5,0.7,0.4,1.0) to the FBO, then, after, render a pixel (0.0,1.0,0.0,0.5) on top of that. The resulting alpha for that pixel should be 1.0, but guess what! the result is 0.5. Why is this? The final color is blended correctly, but the alpha is not 1.0. How, through either blendfunc or some other method can I get the resulting alpha to 1.0? I've tried clearing the buffer with different colors, different bend functions, etc. to no avail.

Jake
  • 843
  • 1
  • 7
  • 18
  • Sounds like it might be the same problem as http://stackoverflow.com/questions/24346585/opengl-render-to-texture-with-partial-transparancy-translucency-and-then-rende. – Reto Koradi Aug 15 '15 at 14:57

1 Answers1

2

Use glBlendFuncSeparate() instead of glBlendFunc() if you want to force the alpha in your FBO to always be 1.0.

Like this :

glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);

And of course make sure that you clear your FBO with a color for which alpha = 1.0.

Another solution is simply to use a FBO with no alpha at all like using R8G8B8 instead of R8G8B8A8 pixel format. A FBO does not need an alpha channel for blending to work when drawing into it ...

VB_overflow
  • 1,763
  • 11
  • 15