OpenGL Alpha Blending - issue.. looking for advice

Im pretty sure im making a newb mistake but after trying to solve this for a while i thought i would ask the community…

Im trying to implement alpha blending but im getting a weird result.

I make two spheres and give them both 50% blending.
The first sphere doesnt appear to have any blending.
The 2nd one appears to have perfect blending…
but only when seen from the perspective of inside the 2nd sphere…
from outside the sphere both spheres appear like they are drawing every other triangle…

Here is a visual example of my exact situation. Any hints / tips would be greatly appreciated.

Ideally i would like transparency to work from both inside and outside the spheres as i hope to use this technique to create planets with atmosphere.

1qxGuH1l7Mw

adjusted youtube settings to make my demonstration video public… sorry about that.

j.

When rendering transparent objects in OpenGL (with alpha other than 1 or 0) you manually need to sort them based on what’s closer to the viewer.

Yeah, seriously.

by manual ordering… do you mean “I” have to ensure i draw the models in opengl from closest to furthest in relation to the camera ?

Yes:

Opaque (or Transparent) object = object consisting of pixels where the alpha is 0.0 or 1.0
Translucent (alpha/blended) object = object consisting of pixels where the alpha is between 0.0 and 1.0 exclusively

Drawing:

  1. Draw all opaque objects
  2. Sort translucent objects by their distance from the camera
  3. Draw translucent objects in determined order

If you have complex translucent objects that can cross over each other like this:

Good luck! Not possible!

k thank explains why one sphere doesnt appear to have any alpha blending.

any ideas why only one side of the sphere (in this case the inside) is blended… where the outside draws like a mesh of triangles?

When i dont use alpha the sphere is drawn properly both inside and out and the normals interact with the lighting as i would expect.

The one that doesn’t appear to have any alpha blending is the one being drawn first on the black background… it looks fine when it’s the one further in the distance… but when it’s the closest it’s still being drawn behind the other one, even though it’s in front (hence the need to order the drawing).