.. _oit: Order independent transparency ============================== Met.3D provides two different order independent (OIT) transparency options, as well as traditional, sorted, alpha blending. This page will describe all of them. They are implemented inside ``oit.glsl``. Alpha blending (legacy) ----------------------- Met.3D traditionally used alpha blending for transparency. This is still supported, when the user deactivates multi-sampling or the order independent transparency options. When alpha blending is used, the order of actors in the scene panel determines the order in which transparency is applied. This means, that actors that are rendered earlier, but that are in front of other actors, will occlude these and transparency will not be applied. This happens, because the actor rendered later will fail the depth test to the previous actor. Alpha blending is the most inaccurate of the methods implemented in Met.3D, but it will provide the clearest image. Simple OIT (Alpha-to-coverage) ------------------------------ The second option is simple OIT, which uses alpha-to-coverage and multi-sampling to achieve a somewhat accurate transparency. Essentially, the alpha value of a fragment is converted to a coverage mask of the samples inside the multi-sampled framebuffer. For example, when using 8 samples with 0.5 alpha value, 4 samples will be covered by the fragment. This means that occluding transparent surfaces can write to different samples inside the multi-sample buffer, no-longer occluding themselves. Once written, their alpha value is set to 1.0. This is necessary, as the multi-sample resolve will blend the colors stored in the samples. With alpha 1.0 this will result in approximately the correct color, otherwise the transparency would be applied twice. For example, we have 4 samples with red, and 4 samples with blue color, both 0.5 opacity. If the opacity is not set to 1.0, the resulting fragment will be slightly darker than it should be, as both colors are only of 0.5 opacity in half the samples, effectively making their opacity 0.25. A downside of this approach is the occlusion of surfaces of the same opacity. Using the example above, both surfaces would actually occupy the same samples, as the sample mask is deterministic. This means, that surfaces of the same opacity will always overwrite each other until the surface nearest to the camera wins. The upside of this approach is, that it can easily be applied to shadow maps as well. When rendering shadow maps, the different samples will store different depth values. When applying the shadow map, we sample all the depth values and simply count how many are closer to the light source, and therefore shadow our fragment. This makes the shadows seem transparent as-well. Stochastic transparency ----------------------- `Stochastic transparency`_ extends the simple OIT by selecting the samples of the fragment stochastically. This means, that two surfaces of same opacity no longer have to overwrite each other. On average, this version of transparency is accurate, but it will introduce noise into the view. .. _Stochastic transparency: https://research.nvidia.com/publication/2011-08_stochastic-transparency