next up previous contents index
Next: 4.1.7 Dithering Up: 4.1 Per-Fragment Operations Previous: 4.1.5 Depth buffer test

4.1.6 Blending

 

Blending combines the incoming fragment's R, G, B, and A values with the R, G, B, and A values stored in the framebuffer at the incoming fragment's location. This blending is dependent on the incoming fragment's alpha value and that of the corresponding currently stored pixel. Blending applies only in RGBA mode; in color index mode it is bypassed. Blending is enabled or disabled using Enable  or Disable  with the symbolic constant BLEND. If it is disabled, or if logical operation on color values is enabled (section 4.1.8), proceed to the next stage.

The command that controls blending is

void BlendFunc ( enum src, enum dst ) ;

src indicates how to compute a source blending factor, while dst indicates how to compute a destination factor. The possible arguments and their corresponding computed source and destination factors are summarized in Tables 4.1 and 4.2. In these tables a subscript of s indicates a value from an incoming fragment; one of d indicates the corresponding current framebuffer value. Division of a quadruplet by a scalar means dividing each element by that value. Addition or subtraction of quadruplets or triplets means adding or subtracting them component-wise.

The computations in Tables 4.1 and 4.2 are effectively carried out in floating-point and yield floating-point blending factors. Destination (framebuffer) components referred to in the tables are taken to be fixed-point values represented according to the scheme given in section 2.13.9 (Final Color Processing), as are source (fragment) components. Any implied conversion to floating-point must leave 0 and 1 invariant.

  
Table 4.1: Values controlling the source blending function and the source blending values they compute. .

  
Table 4.2: Values controlling the destination blending function and the destination blending values they compute.

The computed source and destination blending quadruplets are applied to the source and destination R, G, B, and A values to obtain a new set of values that are sent to the next operation. Let the source and destination blending quadruplets be S and D, respectively. Then a quadruplet of values is computed as

where multiplication of quadruplets means multiplying them component-wise. Then each value in this quadruplet is clamped to , where n is the number of bits allocated to that color component in the framebuffer, and the four values are sent to the next operation.

The state required is two integers indicating the source and destination blending functions and a bit indicating whether blending is enabled or disabled. The initial state of the blending functions is ONE for the source function and ZERO for the destination function; initially, blending is disabled.

Blending occurs once for each color buffer currently enabled for writing (section 4.2.1) using each buffer's color for . If a color buffer has no A value, then it is as if the destination A value is 1.



next up previous contents index
Next: 4.1.7 Dithering Up: 4.1 Per-Fragment Operations Previous: 4.1.5 Depth buffer test



David Blythe
Sat Mar 29 02:23:21 PST 1997