Drawing a scene with transparent and opaque objects correctly...

Hello.
In case I want to draw a scene having both transparent and opaque objects, should I do the following:

  1. Draw the opaque objects first, with Z-Buffer enabled.
  2. Specify alpha-blending function.
  3. Mask Z-Buffer (Z-Buffer is read, but not updated).
  4. Draw the transparent objects.

Am I right?

Thanks,
Heinrich

Yes :slight_smile:

Another solution is to use one Order Independent Transparency algo such as Dual Depth Peeling
http://www.google.fr/url?sa=t&rct=j&q=independant%20order%20transparency%20nvidia&source=web&cd=1&ved=0CE0QFjAA&url=http%3A%2F%2Fdeveloper.download.nvidia.com%2FSDK%2F10%2Fopengl%2Fsrc%2Fdual_depth_peeling%2Fdoc%2FDualDepthPeeling.pdf&ei=WWMhUJD9LOGw0QW0noHYBg&usg=AFQjCNEZIlvyNR0nvA8J7jk8J5BSGzqJCA&cad=rja

  1. Draw the transparent objects.
    Nitpick: for correct blending this should be “draw transparent objects from back to front”.

[QUOTE=The Little Body;1241177]Yes :slight_smile:

Another solution is to use one Order Independent Transparency algo such as Dual Depth Peeling
http://www.google.fr/url?sa=t&rct=j&q=independant%20order%20transparency%20nvidia&source=web&cd=1&ved=0CE0QFjAA&url=http%3A%2F%2Fdeveloper.download.nvidia.com%2FSDK%2F10%2Fopengl%2Fsrc%2Fdual_depth_peeling%2Fdoc%2FDualDepthPeeling.pdf&ei=WWMhUJD9LOGw0QW0noHYBg&usg=AFQjCNEZIlvyNR0nvA8J7jk8J5BSGzqJCA&cad=rja[/QUOTE]

Hi,
I am using the dual depth peeling algorithms in my application to render transparent primitives. I have 2 lists in my application, one consists of transparent primitives, and the other one of opaque primitives. I have observed that if I render any opaque primitives BEFORE rendering transparent primitives using one of the algorithms in the dual depth peeling demo, the opaque primitives do not get rendered.
On the contrary, If I draw the opaque primitives AFTER rendering transparent primitives using the algorithm, the order of rendering gets disturbed, and the output, consequently, does not come out as expected.

Is there any restriction while using the algorithm for rendering transparent and opaque primitives together that I’m not aware of/that I’ve missed? Please help me as I’m stuck with this for almost a week.

You should check your status.
There are two main way to blend transparent object. OVER and UNDER (and other less used method like MAX, MIN, ADDITIVE blending that always create artifact)
Over operator is the most popular, you have to render object from the farthest to the nearest with color = source * srcAlpha + dest * (1-srcAlpha)

With the under operator you draw object from the nearest to the farthest. You have to use the following operation color = destAlpha * (srcAlpha * srcColor) + destColor and alpha = (1-srcAlpha) * destAlpha
Cause this you have to clear the alpha to 1.0 then draw your alpha object with UNDER operator and then render opaque object with the same formula (but the alpha will alway be one).

The problem with under operation is that you always have blending enable. Otherwise you have to render alpha object on another buffer and the compose the buffer at the end.