PDA

View Full Version : Blending a Texture shows white.



t@nt@n
08-08-2013, 04:00 AM
Why does my texture shows white instead of transparent when i blend it on some background. My Shader is making the alpha factor of the fragments to zero.
So basically the texture after blending should have been completely transpartent.
The blendFunc that i am using is glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA).
I changed the BlendFunc to GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA, it was working fine. But i dont know what effect it could create because this blending function is being used by many other things also.

GClements
08-08-2013, 08:46 PM
Why does my texture shows white instead of transparent when i blend it on some background. My Shader is making the alpha factor of the fragments to zero.
So basically the texture after blending should have been completely transpartent.
The blendFunc that i am using is glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA).
I changed the BlendFunc to GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA, it was working fine. But i dont know what effect it could create because this blending function is being used by many other things also.

glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA).is correct if the shader output has pre-multiplied alpha (i.e. the R,G,B components contain R*A,G*A,B*A).
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) is correct if the output has un-multiplied alpha.

However, if you want to render into a framebuffer with an alpha channel, then subsequently blend the rendered image with another, only the former approach will work correctly (and will result in a framebuffer with pre-multiplied alpha), so either your textures must have pre-multiplied alpha or you must perform the multiplication in the shader, e.g.


gl_FragColor.rgb *= gl_FragColor.a;