blendfunction(3G) blendfunction(3G)
NAME
blendfunction - computes a blended color value for a pixel
C SPECIFICATION
void blendfunction(long sfactr, long dfactr)
PARAMETERS
sfactr is a symbolic constant taken from the list below. It identifies
the blending factor by which to scale contribution from source
pixel RGBA (red, green, blue, alpha) values.
BFZERO 0
BFONE 1
BFDC (destination RGBA)/255
BFMDC 1 - (destination RGBA)/255
BFSA (source alpha)/255
BFMSA 1 - (source alpha)/255
BFDA (destination alpha)/255
BFMDA 1 - (destination alpha)/255
BFMINSAMDA min(BFSA, BFMDA)
BFCC (constant RGBA)/255
BFMCC 1 - (constant RGBA)/255
BFCA (constant alpha)/255
BFMCA 1 - (constant alpha)/255
BFMIN min(1, destination RGBA/source RGBA)
BFMAX max(1, destination RGBA/source RGBA)
dfactr is a symbolic constant taken from the list below. It identifies
the blending factor by which to scale contribution from
destination pixel RGBA values.
BFZERO 0
BFONE 1
BFSC (source RGBA)/255
BFMSC 1 - (source RGBA)/255
BFSA (source alpha)/255
BFMSA 1 - (source alpha)/255
BFDA (destination alpha)/255
BFMDA 1 - (destination alpha)/255
BFCC (constant RGBA)/255
BFMCC 1 - (constant RGBA)/255
BFCA (constant alpha)/255
BFMCA 1 - (constant alpha)/255
A blending factor is obtained by evaluating a mathematical expression
over a source RGBA value, a destination RGBA value and a constant RGBA
value. The latter is provided with blendcolor.
Blending factors, except for BFMIN and BFMAX, use RGBA values converted
to fractions of the maximum value 255. To improve performance, these
conversion calculations are approximate. However, 0 converts exactly to
0.0, and 255 converts exactly to 1.0.
Page 1
blendfunction(3G) blendfunction(3G)
DESCRIPTION
In RGB mode, the system draws pixels using a function that blends the
incoming (source) RGBA values with the RGBA values that are already in
the framebuffer (the destination values). Most often, blending is
simple: the source RGBA values replace the destination RGBA values of the
pixel.
In some cases, however, simple replacement of framebuffer values is not
appropriate. Two such cases are transparency and antialiasing. To be
blended properly, transparent objects must be rendered back-to-front
(i.e. drawn in order from the farthest object to the nearest object) with
a blend function of (BFSA, BFMSA). As can be seen from the equations
below, this function scales the incoming color components by the incoming
alpha value, and scales the framebuffer contents by one minus the
incoming alpha value. Thus incoming (source) alpha is correctly thought
of as a material opacity, ranging from 1.0 (completely opaque) to 0.0
(completely transparent). Note that this transparency calculation does
not require the presence of alpha bitplanes in the framebuffer.
Suggestions for appropriate blend functions for antialiasing are given on
the pntsmooth and linesmooth manual pages. Other less obvious
applications are also possible. For example, if the red component in the
framebuffer is first cleared to all zeros, and then each primitive is
drawn with red set to 1 and a blend function of (BFONE, BFONE), the red
component of each pixel in the framebuffer will contain the count of the
number of times that pixel was drawn.
To determine the blended RGBA values of a pixel when drawing in RGB mode,
the system uses the following functions:
R = min (255, ((R * sfactr) + (R * dfactr)))
destination source destination
G = min (255, ((G * sfactr) + (G * dfactr)))
destination source destination
B = min (255, ((B * sfactr) + (B * dfactr)))
destination source destination
A = min (255, ((A * sfactr) + (A * dfactr)))
destination source destination
When the blend function is set to (BFONE, BFZERO), the default values,
the equations reduce to simple replacement:
R = R
destination source
G = G
destination source
B = B
destination source
Page 2
blendfunction(3G) blendfunction(3G)
A = A
destination source
Fill rate may be increased substantially when blending is disabled in
this manner.
Polygon antialiasing (see polysmooth) is sometimes optimized when the
blendfunction (BFMINSAMDA, BFONE) is used. Source factor
BFMINSAMDA, which should be used only with destination factor BFONE,
has the side effect of slightly modifying the blending arithmetic:
R = min (255, ((R * sfactr) + R ))
destination source destination
G = min (255, ((G * sfactr) + G ))
destination source destination
B = min (255, ((B * sfactr) + B ))
destination source destination
A = sfactr + A
destination destination
This special blend function accumulates pixel contributions until the
pixel is fully specified, then allows no further changes. Destination
alpha bitplanes, which must be present for this blend function to operate
correctly, store the accumulated coverage.
In order to store the smallest or the largest RGBA value among the source
RGBA and destination RGBA, simply use
blendfunction(BF_MIN, BF_ZERO);
or
blendfunction(BF_MAX, BF_ZERO);
respectively.
Blending is available with or without z-buffer mode. When blendfunction
is set to any value other than (BFONE, BFZERO), logicop is forced to
LOSRC.
SEE ALSO
cpack, linesmooth, logicop, pntsmooth, polysmooth, blendcolor
NOTES
Blending factors BFDA, BFMDA, and BFMINSAMDA are not supported on
machines without alpha bitplanes.
Page 3
blendfunction(3G) blendfunction(3G)
IRIS-4D G, GT, and GTX models, the Personal Iris, Indigo Entry, XS, XS24,
XZ, Elan and Extreme systems do not support blend factor BFMINSAMDA.
IRIS-4D G, GT, GTX, VGX, and VGXT models, the Personal Iris, Indigo
Entry, Indy, XL, XS, XS24, and Elan systems do not support blend factors
BFCC, BFMCC, BFCA, BFMCA, BFMIN and BFMAX.
IRIS-4D B and G models and the Personal Iris do not support this function
at all. Use getgdesc(GDBLEND) to determine whether blending hardware is
available.
BUGS
Blending works properly only in RGB mode. In color map mode, the results
are unpredictable.
On IRIS-4D G, GT, GTX, VGX, and VGXT models, the Personal Iris, Indigo
Entry, Indy, XL, XS, XS24, and Elan systems when multiple destination
buffers are specified (using frontbuffer, backbuffer, and zdraw ) only a
single location can be read and used as the destination value on the
right side of the above equations. As a result, the destination values
on the left and the right of the equations may not be taken from the same
framebuffer locations. By default, the destination RGBA values are read
from the front buffer in single buffer mode and from the back buffer in
double buffer mode. If the front buffer is not enabled in single buffer
mode, the RGBA values are taken from the z-buffer. If the back buffer is
not enabled in double buffer mode, the RGBA values are taken from the
front buffer (if possible) or from the z-buffer.
On some IRIS-4D GT and GTX models, while copying rectangles with blending
active, readsource also specifies the bank from which destination color
and alpha are read (overriding the blendfunction setting).
IRIS-4D VGX models do not clamp color values generated by the special
blending function BFMINSAMDA,BFONE to 255. Instead, color values are
allowed to wrap.
Page 4