@@ -1975,17 +1975,25 @@ void Model::glDraw(GLWidget *glWidget) const
19751975 return a < 255 ;
19761976 };
19771977
1978- // Two-pass rendering for correct alpha blending:
1979- // Pass 0 (opaque) — depth writes ON, draw entities with alpha == 255
1980- // Pass 1 (transparent) — depth writes OFF, draw entities with alpha < 255
1981- // Opaque geometry fills the depth buffer first so transparent surfaces
1982- // correctly blend against whatever is visible behind them.
1983- for (int pass = 0 ; pass < 2 ; pass++)
1984- {
1985- const bool transparentPass = (pass == 1 );
1986- if (transparentPass)
1978+ // Three-pass rendering for correct alpha blending with silver back-faces:
1979+ // Pass 0 — opaque (alpha=255): depth writes ON, normal cull state
1980+ // Pass 1 — transp. back faces: depth writes OFF, GL_FRONT culled → back faces drawn (silver)
1981+ // Pass 2 — transp. front faces: depth writes OFF, GL_BACK culled → front faces drawn (entity color)
1982+ // Drawing back faces before front faces gives correct layering for convex transparent shells
1983+ // without needing per-triangle depth sorting.
1984+ GLStateCache &stateCache = GLStateCache::instance ();
1985+ for (int pass = 0 ; pass < 3 ; pass++)
1986+ {
1987+ const bool transparentPass = (pass >= 1 );
1988+ if (pass == 1 )
19871989 {
19881990 GL_SAFE_CALL (glDepthMask (GL_FALSE));
1991+ stateCache.enableCullFace ();
1992+ stateCache.setCullFaceMode (GL_FRONT); // cull front → draw back (silver)
1993+ }
1994+ else if (pass == 2 )
1995+ {
1996+ stateCache.setCullFaceMode (GL_BACK); // cull back → draw front (entity color)
19891997 }
19901998
19911999 // Draw volume entities.
@@ -2087,11 +2095,12 @@ void Model::glDraw(GLWidget *glWidget) const
20872095 glIso.paint ();
20882096 }
20892097
2090- if (transparentPass )
2098+ if (pass == 2 )
20912099 {
20922100 GL_SAFE_CALL (glDepthMask (GL_TRUE));
2101+ stateCache.disableCullFace ();
20932102 }
2094- } // two -pass loop
2103+ } // three -pass loop
20952104
20962105 if (glWidget->getGLDisplayProperties ().getShowModelEdges ())
20972106 {
0 commit comments