Blending issues.

I have a complex (and non-static) scene - there are typically many objects, some of which are varying levels of transparancy, some of which are opaque. I’m having problems with my blending.

I first draw all of the opaque objects, depth buffer writable. I switch to read-only depth-buffer, and draw the translucent objects with (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).

What shows up on the screen appears to be inside-out - that is, those polys on the back appear to be in the front and vice versa. I can set the alpha to .999 and get this really flaky effect, but set it to 1, and it switches to the original (depth-buffered) code and works fine.

I suspect that what I need to do is manually depth-sort the translucent polys (i.e. BSP), but I was hoping someone here would have better news for me :-).

Chris

Sorry, but sorting the translucent triangles is about the only way.

Just keep in mind than in some cases you can get away with very little calculations to get the necessary drawing order. For example, a BSP tree can help. If your scene consists of small objects spread out, then sort the objects, and then the triangles in these objects alone. Also, don’t make a complete resort every frame if you don’t have to. You can use the fact that the list between two frames is almost identical, and therefore you choose a sorting algorithm that is very fast for almost sorted lists, like insertion sort or bubble sort.

There are some tricks to sort a large list very efficiently if you know the list you want to sort.

what is BSP?

Binary Space Partitioning (Tree). It’s a data structure used to do front-to-back drawing. Try Graphics Gems V pp.121, or search this forum - there are about a trillion references to it.

Chris