?/TD>
Microsoft DirectX 9.0

Alpha Texture Blending


When Microsoft?Direct3D?renders a primitive, it generates a color for the primitive based on the primitive's material, or the colors of its vertices, and lighting information. For details, see Lights and Materials. If an application enables texture blending, Direct3D must then combine the color value of the processed polygon pixel with the pixel already stored in the frame buffer. Direct3D uses the following formula to determine the final color for each pixel in the primitive's image.

FinalColor = TexelColor ?SourceBlendFactor + PixelColor ?DestBlendFactor

In this formula, FinalColor is the final pixel color that is output to the target rendering surface. TexelColor represents the incoming color value, after texture filtering, that corresponds to the current pixel. For details on how Direct3D maps texels to pixels, see Texture Filtering. SourceBlendFactor is a calculated value that Direct3D uses to determine the percentage of the incoming color value to apply to the final color. PixelColor is the color of the pixel currently stored in the primitive's image. DestBlendFactor represents the percentage of the current pixel's color that will be used in the final rendered pixel. The values of SourceBlendFactor and DestBlendFactor range from 0.0 to 1.0 inclusive.

As you can see from the preceding formula, the final rendered pixel is not rendered as transparent if the SourceBlendFactor is D3DBLEND_ONE and the DestBlendFactor is D3DBLEND_ZERO. It is completely transparent if the SourceBlendFactor is D3DBLEND_ZERO and the DestBlendFactor is D3DBLEND_ONE. If an application sets these factors to any other values, the resulting final rendered pixel is blended with some degree of transparency.

After texture filtering, every pixel color value has red, green, and blue color values. By default, Direct3D uses D3DBLEND_SRCALPHA as the SourceBlendFactor and D3DBLEND_INVSRCALPHA as the DestBlendFactor. Therefore, applications can control the transparency of processed pixels by setting the alpha values in textures.

A C++ application controls the blending factors with the D3DRS_SRCBLEND and D3DRS_DESTBLEND render states. Invoke the IDirect3DDevice9::SetRenderState method and pass either render state value as the value of the first parameter. The second parameter must be a member of the D3DBLEND enumerated type.



© 2002 Microsoft Corporation. All rights reserved.