2
\$\begingroup\$

In OpenGL, I am using GL_SRGB8_ALPHA8 for the OpenGL internal texture format for my textures and render targets. This eliminated some banding I was seeing in dark opaque areas. However, in the following screenshot, you can see there is still some banding in the nearly-opaque black pixels on the left side. The render target is transparent in the areas where you see the checkerboard pattern.

Screenshot

Semitransparent pixels in SRGB formatted textures and render target textures appear too transparent when rendered to the screen, and pixels that are very nearly opaque (254, 253, 252 alpha) show noticeable banding as you can see in the sample image.

I've seen the issue with both SRGB formatted render target textures and ordinary textures with SRGB format.

The banding appears to go away if I don't call glEnable(GL_FRAMEBUFFER_SRGB).

I'm using premultiplied alpha, but I'm pretty sure I've eliminated that as a cause of the issue. I'm not doing anything to the sampled color in the pixel shader.

My blend functions:

// Non-premultipled alpha textures
glBlendFuncSeparate( GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA, 
                     GL_ONE,        GL_ONE_MINUS_SRC_ALPHA);

// Premultiplied alpha textures
glBlendFuncSeparate( GL_ONE,        GL_ONE_MINUS_SRC_ALPHA, 
                     GL_ONE,        GL_ONE_MINUS_SRC_ALPHA);

I tried exporting my render target to a PNG, and the true alpha values stored in the render target are increasing by 1 at each band. The texture appears much more opaque in image editors than it does in my app.

Any advice as to what could cause this kind of alpha banding?

\$\endgroup\$
  • 1
    \$\begingroup\$ The banding looks rather extreme so it might be some sort of shader or integer division issue. How does this look if you use linear color space. How does it look if you use only one color channel with 24 bit? Given that the texture seems to be only black and white that might be viable. \$\endgroup\$ – Nils Ole Timm Jul 27 '16 at 18:11
  • \$\begingroup\$ @NilsOleTimm I updated my question, the alpha issues go away when I don't call glEnable(GL_FRAMEBUFFER_SRGB). However, I need the SRGB framebuffer to get correct color blending. \$\endgroup\$ – Tim R. Nov 17 '16 at 0:25
  • 1
    \$\begingroup\$ Did you have a look at stackoverflow.com/questions/11386199/…? Might not be your fault there. \$\endgroup\$ – Leith Nov 18 '16 at 3:45

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.