I am using something similar to that answer linked by @RetoKoradi comment but I got double layered transparent models with textures (glass with both inner and outer surface) with fully solid machinery and stuff around.
For such scenes I am using also multi pass approach and the Z-sorting is done by sequence of setting front face.
- render all solid objects
-
render all transparent objects
This is the tricky part first I set
glGetIntegerv(GL_DEPTH_FUNC,&depth_funct); glDepthFunc(GL_ALWAYS); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE);
I got the geometry layers stored separately (inner outer) so The Z-sorting is done like this:
- Render outer layer back faces with
glFrontFace(GL_CW);
- Render inner layer back faces with
glFrontFace(GL_CW);
- Render inner layer front faces with
glFrontFace(GL_CCW);
- Render outer layer front faces with
glFrontFace(GL_CCW);
And lastly restore
glDisable(GL_BLEND); glDepthFunc(depth_funct);
- Render outer layer back faces with
-
render all solid objects again
It is far from perfect but enough for my purposes it looks like this: