Mesh bounding spheres (radii and center points) stored in the respective mesh structures can be used in real time to sort alpha-transparent meshes based on their current distances from the camera.
In order to let overlapping alpha-transparent materials blend correctly over one another, the most distant of them should be rendered the first, and the closest ones, the last.
Suppose we have a 3D model that comprises three semi-transparent gemstone meshes. When the model is loaded in the viewer, the order in which the meshes are going to be rendered is determined by the order in which they appear in the model file. Thus, if we look at the leftmost screenshot below, we can see that the blue gemstone mesh that appears in the model file the first is always rendered the first in all ObjReaders as well as in FBSL Objector if it has its runtime alpha sorting feature disabled. As a result, the gemstones appear opaque even though they are in fact transparent; wrong rendering order wouldn't allow OpenGL to read its depth buffer correctly when trying to blend the gemstone colors on the screen.
In order to correct this, Objector recalculates the distances between the camera and alpha-transparent mesh centers whenever the model is rotated and/or moved with the mouse. Based on the calculations, the alpha-transparent mesh indices in the mesh array are swapped according to the distances in such a way that the currently most distant alpha mesh would be rendered in the current render frame the first, and the closest one, the last.
The effect of runtime alpha sorting is shown in the rightmost screenshot below. Regardless of how the model is currently orientated with the mouse, the overlapping areas of semi-transparent gemstones will always be color-blended correctly.
The method has certain restrictions though. For example, it can't resolve transparent meshes that appear inside the other transparent meshes, like for example, a volume of beer inside a glass, or if some polygons of one transparent mesh are interleaved with the polygons of another transparent mesh, like for example, separate blades of grass. And also, like in all floating-pont comparisons that can only be so much precise, FPU inexactness can lead to occasional artifacts when OpenGL can't determine correctly exactly which mesh is the farthest, and which one, the closest.
A zip with short AVI sequences to illustrate the technique is also attached below.
(to be continued)