When Direct3D renders a primitive, it generates a color for the primitive based on the primitive's material and lighting information. For details, see Lighting and Materials. If an application enables texture blending, Direct3D must then blend the texel colors of one or more textures with the primitive's current colors. Direct3D uses the following formula to determine the final color for each pixel in the primitive's image.
FinalColor = | TexelColor * SourceBlendFactor + |
PixelColor * DestBlendFactor |
In the preceding formula, FinalColor is the pixel color that is output to the target rendering surface. TexelColor stands for the color of the texel that corresponds to the current pixel. For details on how Direct3D maps pixels to texels, see Texture Filtering. SourceBlendFactor is a calculated value that Direct3D uses to determine the percentage of the texel color to apply to the final color. PixelColor is the color of the current pixel in the primitive's image. DestBlendFactor represents the percentage of the current pixel's color that will be used in the final color. The values of SourceBlendFactor and DestBlendFactor range from 0.0 or 1.0 inclusive.
As you can see from the preceding formula, a texture is not rendered as transparent at all if the SourceBlendFactor is 1.0 and the DestBlendFactor is 0.0. It is completely transparent if the SourceBlendFactor is 0.0 and the DestBlendFactor is 1.0. If an application sets these factors to any other values, the resulting texture will be blended with some degree of transparency.
Every texel in a texture has a red, a green, and a blue color value. By default, Direct3D uses the alpha values of texels as the SourceBlendFactor. Therefore, applications can control the transparency of textures by setting the alpha values in their textures.
Your application can control the blending factors with the D3DRENDERSTATE_SRCBLEND and D3DRENDERSTATE_DESTBLEND enumerated values. Invoke the IDirect3DDevice3::SetRenderState method and pass either D3DRENDERSTATE_SRCBLEND or D3DRENDERSTATE_DESTBLEND as the value of the first parameter. The second parameter must be a member of the D3DBLEND enumerated type.