PDA

View Full Version : About transparency in OpenGL



zhangjunyue
05-20-2004, 06:07 PM
When rendering transparency object, I select blend mode as follows:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

While rotating camera, I find some black patch on the transparency object.

After try other blend parameters, it seems that
glBlendFunc(GL_SRC_ALPHA, GL_ONE) work in the certain condition. But it will lost transparency object due to blend with background color.

miko
05-21-2004, 05:46 AM
are you rendering stuff from furthest to nearest and have z-buffer writing disabled?

05-22-2004, 12:23 AM
Yeah, transparency have 2 big problems :

1) order of drawing counts for most blending modes (i.e. substractive transparency)

2) z-buffer tests will prevent drawing a surface behind a transparent one.

So basically, drawing order counts twice :)
An easy way to solve 1) is to use additive transparency, with glBlendFunc(XXX, GL_ONE), as you found.
To solve 2) easily, you have to draw all opaque geometry first, then disable depth writes (but keep depth tests !) then draw transparent surfaces.

The most visually correct way to solve both 1 and 2 is to sort manually your transparent triangles and draw them from back to front. Depending of your case, you can only sort per object (i.e. for convex ones) or make other simplifications.

Hope it helps.