Alpha blending

From TrainzOnline
Jump to: navigation, search

Alpha blending is a technique where a model is rendered as partially transparent. Without alpha blending, each screen fragment affected by a given model is simply overwritten by the model's color at that location. With alpha blending, a blend occurs between the fragment's original coloration and the model's color at that location. This blend is controlled by an opacity strength value, known as "alpha".

There are two typical sources used to determine alpha while rendering; the first is a per-object alpha value set at runtime. The second is a per-texel value set in the albedo map. Each value ranges from 0.0 (fully transparent) to 1.0 (fully opaque.) These are multiplied together to give a per-fragment alpha value used for blending.

Alpha blending is order dependent. If two objects using 50% alpha are rendered over the same fragments, the result will include 25% of the original pixel color, 25% of the first object's color, and 50% of the second object's color. For this reason:

  • Alpha-blended objects are typically rendered last, after all opaque or alpha-masked objects have been rendered.
  • Alpha-blended objects which can be seen through other alpha-blended objects need to be alpha sorted in order of distance-from-observer to maintain correct visuals. (See. Painter's algorithm)
  • Alpha-blended polygons which intersect other alpha-blended polygons will always be rendered incorrectly as Trainz does not split polygons.
  • Alpha-blended objects are typically rendered without modifying the z-buffer. They still honor the z-buffer values written by opaque or alpha-masked objects.
Personal tools