Odd behavior with transparency

Not sure if this is a bug or just an obscure behavior I don’t understand.

I have a .bam file with a cube and a plane in it. The cube has inverted normals so that the camera sees inside it. If I create a bunch of untextured cards with transparency enabled, the texture on the plane gets messed up. If I remove the cube or remove the texture from the cube it doesn’t happen, and if I create fewer than 15 cards it doesn’t happen. If I disable transparency on the cards it also doesn’t happen.

Example: https://github.com/hpoggie/strange-panda3d-behavior

I am using panda3d==1.10.0.dev1837+deployng.244.

Screenshot with OK texture:

Screenshot with bad texture:

That looks to me to be a sorting issue.

In short, transparency can a tricky thing, and the results of this sort of transparency can depend heavily on the order in which the transparent objects are drawn. By default, I believe that Panda sorts transparent objects from farthest to nearest; in many cases, this works well. However, when objects overlap, or one is contained within another, this sorting may not be sufficient to get things drawn as expected.

Specifically, what I think that you’re seeing at the edges of the septagram is either the background clear-colour, or one of the other planes.

To start with, does the texture for your cube perhaps have an alpha channel? If so, perhaps remove that if you don’t intend for the cube to be transparent.

If this is the problem, you could perhaps fix it by explicitly setting the order in which the elements draw. You might do this by assigning them to the “fixed” culling-bin (via “NodePath.setBin”), and having the cube draw first, the septagram after, and the planes in whatever order makes sense. For more information, see here.

The manual has more information on blending here, I believe.

I’m not sure of why this only shows up when you have several planes, offhand; it’s very possible that my diagnosis above is incorrect.

Replacing the background color with cyan gives this:

So the lines around the outside are definitely background color.

I also tried making the planes offset from each other in the z direction; that caused the texture not to be messed up. This makes me think that you are correct and that this has to do with how Panda3d sorts transparent objects.

The original point of this was to create a skybox but I found out a better way to do it (parenting the cube to the camera and setting it to not depth-write). That fixes this issue.