Crystal Space 2.0.0: 4.13.2 Mixmodes and Blending

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 4.13.2 Mixmodes and Blending

The `‘mixmode’` controls how a source (usually a texture) is blended on top of the destination (usually a screen buffer). Typically mixmodes are set on mesh factories or objects to control transparency of some kind. There are various modes defined in `‘include/ivideo/graph3d.h’`.

In the explanation below we use the following terms: SRC is the source of the blend operation (usually the texture or material). DST is the destination of the blend operation (usually the screen buffer or texture on which you are rendering). `‘srcAlpha’` is the alpha component of the source buffer. `‘dstAlpha’` is the alpha component of the destination buffer. The following mixmodes are supported:

- `‘CS_FX_COPY’` Blending function: SRC. This mode is usually default. It simply copies the source to the destination without blending.
- `‘CS_FX_MULTIPLY’` Blending function: SRC*DST. This is a common blend mode to simulate lighting.
- `‘CS_FX_MULTIPLY2’` Blending function: 2*SRC*DST. This is a common blend mode to simulate brighter lighting.
- `‘CS_FX_ADD’` Blending function: SRC+DST. Add source and destination. This is a mode that allows for nice transparency effects. One of the big advantages (as opposed to `‘alpha’`) is that this mode doesn't require objects to be sorted from back to front.
- `‘CS_FX_ALPHA’` Blending function: `‘alpha’`*SRC + (1-`‘alpha’`)*DST. The `‘alpha’` used in this formula is a combination of the `‘srcAlpha’` and the alpha given in the alpha mask of the mixmode. But this depends on the actual shader that is being used.
- `‘CS_FX_SETALPHA(alpha)’` Convenience macro to set `‘CS_FX_ALPHA’` and set the alpha value to the alpha mask (value is between 0 and 1).
- `‘CS_FX_SETALPHA_INT(alpha)’` Convenience macro to set `‘CS_FX_ALPHA’` and set the alpha value to the alpha mask (value is between 0 and 255).
- `‘CS_FX_PREMULTALPHA’` Blending function: SRC + DST*(1-`‘srcAlpha’`). When the source alpha component was multoplied into the source color then this acts like normal alpha blending. If it was not then it acts like additive blending. So this mixmode can be used to do both additive and alpha blending on the same triangle and even interpolate between these two extremes by appropriate choice of the color and alpha values.
- `‘CS_FX_DESTALPHAADD’` Blending function: `‘dstAlpha’`*SRC + DST.
- `‘CS_FX_SRCALPHAADD’` Blending function: `‘srcAlpha’`*SRC + DST.
- `‘CS_FX_TRANSPARENT’` Blending function: DST. This mode will simply leave the destination unchanged (fully transparent) except that the z-buffer is modified!
- `‘CS_FX_MESH’` @@TODO
- `‘CS_MIXMODE_ALPHATEST_AUTO’` @@TODO
- `‘CS_MIXMODE_ALPHATEST_ENABLE’` @@TODO
- `‘CS_MIXMODE_ALPHATEST_DISABLE’` @@TODO

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated using texi2html 1.76.