PDA

View Full Version : Strange alpha Problem in simple scene



uwi2k2
02-16-2014, 06:37 AM
Hi all,

i am a bit ashamed that i cant solve this problem myself, mostly as i am a opengl trainer, but
i have learnd you can only get better when you are not afraid to ask !

so ... i am programming a opengl ( 3.1 ) game.
i am using shaders and right now i just render:
1. a skybox - star-field texture
2. planets with texture.

i realiced that alpha blending behaved strange so i did some testing and cant understand the results.

My opengl setup looks like this:

glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable( GL_TEXTURE_2D );
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0.01f, 0.01f, 0.02f, 1.0f);

to describe the problem i made 4 screen-shots with different fragment shader settings, after this lines nothing else happens.

Please take a look at the screen shots.

1232

http://apoon.de/xmas/problem.jpg

What am i doing wrong here ? what could be the reason that a alpha value of 0.01 looks like maybe 90% transparent ?
You need to look close, to see there is transperrency ...

thanx a lot
uwi

Dark Photon
02-16-2014, 07:02 PM
...
glEnable(GL_BLEND);
...
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
...

What am i doing wrong here ? what could be the reason that a alpha value of 0.01 looks like maybe 90% transparent ?
You need to look close, to see there is transperrency ...


Nothing here looks 90% transparent, or 99% transparent, nor should it.

You're using a premultiplied alpha blend function (1,1-alpha). This means that what you are applying on top of the framebuffer (the source) is added in at 100%. There's no dimming of it that happens as part of blending. The only thing blending is dimming is the background, and that should be dimmed to 1% of its original (in the FragColor.a = 0.01 case) or 0% of its original (in the FragColor.a = 0 case).

An assumption of premultiplied alpha blending is that you have already "premultipled" the source by its alpha value. Here it looks like you haven't.