blendfunction(3G)
blendfunction - computes a blended color value for a pixel
As shipped in IRIX 6.5. First release of IRIX 6.5.
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. BF_ZERO 0 BF_ONE 1 BF_DC (destination RGBA)/255 BF_MDC 1 - (destination RGBA)/255 BF_SA (source alpha)/255 BF_MSA 1 - (source alpha)/255 BF_DA (destination alpha)/255 BF_MDA 1 - (destination alpha)/255 BF_MIN_SA_MDA min(BF_SA, BF_MDA) BF_CC (constant RGBA)/255 BF_MCC 1 - (constant RGBA)/255 BF_CA (constant alpha)/255 BF_MCA 1 - (constant alpha)/255 BF_MIN min(1, destination RGBA/source RGBA) BF_MAX 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. BF_ZERO 0 BF_ONE 1 BF_SC (source RGBA)/255 BF_MSC 1 - (source RGBA)/255 BF_SA (source alpha)/255 BF_MSA 1 - (source alpha)/255 BF_DA (destination alpha)/255 BF_MDA 1 - (destination alpha)/255 BF_CC (constant RGBA)/255 BF_MCC 1 - (constant RGBA)/255 BF_CA (constant alpha)/255 BF_MCA 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 BF_MIN and BF_MAX, 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. 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 (BF_SA, BF_MSA). 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 (BF_ONE, BF_ONE), 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: Rdestination = min (255, ((Rsource * sfactr) + (Rdestination * dfactr))) Gdestination = min (255, ((Gsource * sfactr) + (Gdestination * dfactr))) Bdestination = min (255, ((Bsource * sfactr) + (Bdestination * dfactr))) Adestination = min (255, ((Asource * sfactr) + (Adestination * dfactr))) When the blend function is set to (BF_ONE, BF_ZERO), the default values, the equations reduce to simple replacement: Rdestination = Rsource Gdestination = Gsource Bdestination = Bsource Adestination = Asource Fill rate may be increased substantially when blending is disabled in this manner. Polygon antialiasing (see polysmooth) is sometimes optimized when the blendfunction (BF_MIN_SA_MDA, BF_ONE) is used. Source factor BF_MIN_SA_MDA, which should be used only with destination factor BF_ONE, has the side effect of slightly modifying the blending arithmetic: Rdestination = min (255, ((Rsource * sfactr) + Rdestination)) Gdestination = min (255, ((Gsource * sfactr) + Gdestination)) Bdestination = min (255, ((Bsource * sfactr) + Bdestination)) Adestination = sfactr + Adestination 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 (BF_ONE, BF_ZERO), logicop is forced to LO_SRC. SEE ALSO cpack, linesmooth, logicop, pntsmooth, polysmooth, blendcolor NOTES Blending factors BF_DA, BF_MDA, and BF_MIN_SA_MDA are not supported on machines without alpha bitplanes. IRIS-4D G, GT, and GTX models, the Personal Iris, Indigo Entry, XS, XS24, XZ, Elan and Extreme systems do not support blend factor BF_MIN_SA_MDA. 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 BF_CC, BF_MCC, BF_CA, BF_MCA, BF_MIN and BF_MAX. IRIS-4D B and G models and the Personal Iris do not support this function at all. Use getgdesc(GD_BLEND) 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 BF_MIN_SA_MDA,BF_ONE to 255. Instead, color values are allowed to wrap.