20121206 - Sorted Transparency or Discard


If one pre-sorts objects in this rough order, {first opaque front to back then append non-opaque back to front}, then compares performance of rendering all those objects in one draw call with depth test+write on and (a.) discard used in the shader vs (b.) alpha blending on: (b.) is much faster by default. Discard turns off early Z test (slow), while alpha blending does not. Also the hardware is optimized for cases like "glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)" with alpha=0.0 (no write or read in ROP) and alpha=1.0 (no read in ROP). So turning on alpha blending and then not using it by rendering everything with alpha=1.0 is not a performance hit. To improve performance in this case with discard and everything sorted back to front, one can turn back on early Z test via "layout(early_fragment_tests) in;" in GLSL.