# Thread: True transparency

1. ## True transparency

Hi All,

We have always believed that true transparency was an hard thing to code. Yesterdeay a coworker suggested the following trick:

Actually, in OpenGL rendering both opaque (alpha=1) and transparent
(alpha<1) objects in the same scene is quite easy: First you draw all the
opaque objects, with depth buffer in normal operation. Then you toggle the
depth buffer read-only (by glDepthMask(GL_FALSE)), draw the transparent
objects and make the depth buffer writable again afterwards
(glDepthMask(GL_TRUE)). There is should be no need for sorting objects by
their viewpoint distances.
What do you think?

Thanks,

Alberto

2. ## Re: True transparency

This "trick" is very old and used by a lot of people.
But it does not solve the order problems that can happen *between* translucent faces (between 2 convex objects or within 1 concave object).
That is where you need sorting. Or use order independent transparency, such as additive blending or darken etc.

3. ## Re: True transparency

Hi ZbuffeR,

As always, thanks for your help.

Can you give me more info (or point me to some resources) about additive blending, darken, etc.

Our customers are striving for a more realistic transparency.

Thanks so much again,

Alberto

4. ## Re: True transparency

ZbuffeR,

I want to be more clear, suppose to have a more complex scenario like the following:

Is it possible that the only solution is to skip objects' display lists and to sort triangles at each frame before drawing them? It looks so slow...

Can you please list all the OpenGL transparency approaches sorted from easy to complex to implement?

We need something more realistic but we are scared from the complexity that always turns out.

Thanks again,

Alberto

5. ## Re: True transparency

Transparency is a bitch.

To get it working, you can sort all triangles from back to front (for example using a BSP-Tree). That is computationally expensive and not fun to implement. I can't advise you to do so, though, with complex scenes this won't run fast enough.

Another solution is to to use "depth-peeling". However that method requires modern hardware and will still be quite slow, but at least you don't need to sort anything. However, from your other posts i suspect, that you need to support older hardware, so that's not really an option, either.

A third solution, is to only sort by "object" (e.g. group of triangles) and render them roughly from back to front. That's an approach taken very often, because it works well in many situations and isn't difficult to implement (usually). But there will always be situations where it doesn't work properly.

Looking at your screenshot, i find that your results look quite nice already. If you are not doing it already, you could add sorting by object, and leave it at that.

There are not really many options, when it comes to transparency. All completely correct solutions are complex and slow.

Jan.

6. ## Re: True transparency

You still need to depth sort the transparent objects.

As has been said it's an old trick, however it is flawed because transparent objects can occlude other transparent objects and can self-occlude.

You have a nice solution BUT transparency blend results are not order invariant.

If you have two 75% transparent objects and one occludes the other or vice versa the result will be highly dependent on drawing order. For it to be correct it needs to be sorted back to front.

Transparency occluding opaque objects in a zbuffered scene has never been a problem except for inexperienced graphics developers.

Sorting isn't a huge problem either although it can increase state changes etc, however the real problem is that object level sorting is not always sufficient to get it correct.

Picture two transparent interlocking tori (two chain links).

Which order do you draw them in as objects to get the correct result? There is no correct order in this scenario.

A simple object level sort is sufficient for most applications. Rather than a depth sort, try to insert a plane between them and decide which side of the plane the eye is on. Use this mechanism to sort for best object level results.

7. ## Re: True transparency

Originally Posted by Jan
There are not really many options, when it comes to transparency. All completely correct solutions are complex and slow.
Yes. Although some graphics hardware with deferred shading internals can handle it automatically (not avilable on mainstream platforms). At the application level there's a need to compromise for good performance.

8. ## Re: True transparency

Alpha-to-Coverage with MSAA can do the trick.

9. ## Re: True transparency

Hi Guys,

Thanks a lot for your thoughts, just a little clarification on the image: this was taken on the internet, it's from SolidWorks CAD application, it doesn't belong to us...

We already implemented object based sorting (using distances from centroid) but simply putting a semi-transparent box inside another semi-transparent box - with the same centroid - will give an incorrect result.

Can we say that all modern 3D applications are using "depth-peeling" and require high end hardware? I mean 3D Studio Max, LightWave3D, Maya, etc.

Where can we find very clear instructions on "depth-peeling"?

Thanks again,

Alberto

10. ## Re: True transparency

depth-peeling can be found in nVidia SDK, GPU Gems and ShaderX series.

Page 1 of 9 12345 ... Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•