Game Engine Alpha Blending

The alpha blending and sort in the game engine was revised and some bugs were fixed. New is the per texture face "Sort" option to indicate if a face will be sorted for drawing with alpha, whereas before it (ab)used the material "ZTransp" option. Additionaly, alpha sorting was optimized to be considerably faster. For clarity, here is an overview of alpha sorting in the game engine.

There are four transparency types in the game engine:

  • Opaque: solid, no transparency at all.
  • Alpha: transparency with values between 0-1, blends with faces behind it.
  • Add: like Alpha, but adds color rather than blends.
  • Clip Alpha: otherwise known as binary alpha, each pixel renders either completely opaque (when alpha > 0.5) or completely transparent (alpha <= 0.5).

Ideally one would not have to deal with such settings, but for good performance it is important to pick the right ones, since rendering with Alpha isn't as fast as Opaque. In many cases Clip Alpha can be used instead of Alpha while still being nearly as fast as Solid. For example for leaves one usually does not need partial transparency.

These settings can be set per face in the Texture Face panel. Note that for GLSL materials, the ZTransp setting must be used to enable any alpha, consistent with the internal render engine. The Alpha/Add/Clip Alpha settings can then be used to specify the exact blending type.

One important thing to know is that for rendering faces with Alpha and Add correct, the faces must be sorted before rendering in every frame. This is only supported in the game engine, not in the Blender viewport, which means that faces with alpha will draw incorrect in some cases there. Clip Alpha does not require sorting, which is useful since sorting objects with many polygons is slow.

Sorting has to be enabled with the Sort option in the Texture Face panel. The reason alpha sorting has to be set separately is because of the performance hit. Some objects might still render OK without sorting, so it is not enabled by default.