Model Transparency works only at specific angles?

I am currently taking a class on Panda 3d at a local college and we are 2 weeks in. I’m not a total noob with modeling/programming, but I am new to Panda 3d. I have done a lot of searching on this forum, and I have tried nearly everything that I could find, but I am still without a fix for something that should be pretty simple.

Our semester long assignment has us doing a space genre shmup. Our instructor has us placing a HUD outside of the player’s model to use for both aiming and as a reference point for vector math/movement. I’m trying to make my HUD a little prettier than the one he supplied by adding some transparency to it.

I have a good model for the HUD, but for the purposes of this post and to make everything easier to see, I am currently using a square plane that is red in color and alpha set to 0.3. The starfield is a skybox.

When I place the camera behind the player’s ship, the plane looks blue/gray and the starfield behind it is not visible:


When I rotate the camera around the ship so that the nearby planet model is behind the plane, it works as expected:


I continued to rotate the camera until it left the planet and as it touches starfield, it turns blue/gray again with any part over the planet looking as I would expect it to. I had a picture to show this, but the forum only allows me 3 uploads. As I continued to rotate around the model it suddenly works as expected over the starfield:


I have tried the following:

Model
Made a simple texture and opacity map to give it an alpha of 30%.
Removed texture and just made the diffuse color red with an alpha of 0.3.

The starfield’s size is 6000 on all sides. I have used a textured cube with

self.skybox.setTwoSided(True)

and have also used an inside-out cube with the texture just on the inside.

Programming
Changed the far clipping plane to beyond the starfield using

base.camLens.setFar(100000) # started at 5000 and increased the value from there

Used the following to set the transparency:

self.hud.setTransparency(TransparencyAttrib.MAlpha)
self.hud.setAlphaScale(0.3)

All of the above produces the same results. It works at some angles or over close objects (everything but the starfield unless I am nearly perpendicular to it), but not at all angles. Any help is appreciated…

I suspect that the problem is one of either drawing-order: Simply put, your HUD object is being drawn after the planet (allowing pixels produced by the planet to be incorporated, producing the transparency effect), but before the sky-box, thus preventing sky-box pixels from being used.

Since the HUD object does sometimes show the star-field behind it, I’m inclined to guess that both are being treated as transparent objects, and sorted back-to-front within the same render bin. Sometimes the centre of the star-field is further away than that of the HUD object, causing it to be drawn first and the transparency to work as expected, but more often the star-field is found to be closer, and thus drawn after the HUD object.

Now, opaque objects should be drawn before transparent ones, if I’m not much mistaken, so I’m inclined to ask: does the texture used for the sky-box have an alpha channel–even if it’s not being used? That is, if you examine the texture’s properties, is it shown to be an RGBA image, as opposed to an RGB image? If so, try removing the alpha channel–even if this doesn’t solve the problem, unused transparency may produce slightly lower performance.

Removing the alpha channel from the star-field texture may by itself solve the problem. If it doesn’t, however, try moving the star-field to the “background” render-bin, as described here.

This fixed it.

skybox.setBin("background", 10)

Thanks for pointing that link out to me!