5Alpha Testing
The alpha test function is a technique for accepting or rejecting a pixel based on its alpha value. The incoming alpha value (the output from the alpha combine unit) is compared with a reference value and accepted or rejected based on a user-defined comparison function.
One application of the alpha compare function is billboarding: if you create a texture with some transparent and some opaque areas, you can indicate the degree of opacity with the alpha value. Set alpha to zero if the texel is transparent, and to one if it’s opaque. With a reference alpha value of .5 (or any number greater than 0) and a “greater than” comparison function, transparent texels will be rejected and the destination pixel will be displayed.
Incoming pixels can be rejected based on a comparison between their alpha values and a global alpha test reference value. The nature of the comparison is user definable through the function grAlphaTestFunction(). This is useful for some effects such as partially transparent texture maps. Also, alpha testing can prevent the depth buffer from being updated for nearly transparent pixels. To disable alpha testing, set the alpha test function to GR_CMP_ALWAYS. The global alpha test reference is set via a call to grAlphaTestReferenceValue(). Because alpha testing does not require alpha storage (i.e. an alpha buffer), it is always available regardless of the use of depth or triple buffering.
void grAlphaTestFunction( GrCmpFnc_t func )
The incoming alpha value is compared to the constant alpha test reference value using the function specified by func. The possible values for func are shown in Table Special Effects.3. The incoming alpha is the output of the alpha combine unit (see grAlphaCombine(), described earlier in this chapter). The reference value is set with grAlphaTestReferenceValue().
void grAlphaTestReferenceValue( GrAlpha_t value )
The incoming alpha value is compared to the value using the function specified by grAlphaTestFunction(). If the comparison fails, the pixel is not drawn.
Table Special Effects.3 Alpha test functions.
Alpha testing is a technique whereby the incoming alpha value is compared to a reference value and the pixel is discarded if the test fails. The test is user-selectable; the choices are shown below.
if func is
|
the comparison function
|
GR_CMP_NEVER
|
never passes
|
GR_CMP_LESS
|
passes if the a value produced by the alpha combine unit is less than the constant a reference value
|
GR_CMP_EQUAL
|
passes if the a value produced by the alpha combine unit is equal to the constant a reference value
|
GR_CMP_LEQUAL
|
passes if the a value is less than or equal to the constant a reference value
|
GR_CMP_GREATER
|
passes if the a value is greater than the constant a reference value
|
GR_CMP_NOTEQUAL
|
passes if the a value is not equal to the constant a reference value
|
GR_CMP_GEQUAL
|
passes if the a value is greater than or equal to the constant a reference value
|
GR_CMP_ALWAYS
|
always passes
|
Alpha testing is performed on all pixel writes, including those resulting from scan conversion of points, lines, and triangles, and from direct linear frame buffer writes. Alpha testing is implicitly disabled during linear frame buffer writes if the pixel pipeline is bypassed (see Chapter Chapter 11. ).
Share with your friends: |