yet another flattening problem

I just seem to have no luck with the nodepath.flatten commands…
This time, it seems that after I flattenstrong a bunch of nodes depending on the heading of the camera it will blend those nodes in different ways- the way I want which combines the transparent parts together and the way I don’t want which takes one of the nodes and renders it completely ontop of the others (even when the vertex alpha=0…). I am using vertex alpha on all of the nodes that are flattened and have the ColorAttrib.makeVertex() on them. When they are not flattened the nodes render properly.


Drawing objects using standard blending transparency requires first sorting those objects in order from farthest to nearest. Panda can do this easily when each object is its own Geom. However, once you have called flattenStrong() on the lot of them, they are now all in a single Geom, and must be sent to the graphics card in a single call.

This is, of course, the whole reason for calling flatten: it means fewer independent calls to the graphics card, which translates to faster performance. However, it also means less flexibility on Panda’s part. Once they have flattened, they can no longer be sorted–the sort order is now permanently baked into the vertices. If you are lucky, they will happen to be sorted correctly, but if you are unlucky, they will be sorted incorrectly, and the nearest objects might therefore occlude the farthest objects.

There are several solutions. One is, of course, in this example to avoid the flatten call, and just accept that you have to pay the cost of having individual objects if you wish them to be sorted correctly.

A better solution might be to use a different kind of transparency that doesn’t require sorting. For instance, you might try:

node.setTransparency(TransparencyAttrib.MBinary, 1)

which works perfectly, regardless of the order in which geometry is rendered. However, this transparency mode only supports full-on or full-off pixels; there are no pixels that are 50% alpha. Depending on the effect you’re going for, this may be acceptable.

You might also try:

node.setTransparency(TransparencyAttrib.MDual, 1)

which is a compromise between MBinary and the default, MAlpha. Some antialiased edges are still occluded, but others will still be OK.

If you have full-screen antialiasing enabled, you might also have luck with MMultisample.