Partager via


Alpha Texture Blending (Windows Embedded CE 6.0)

1/6/2010

When Microsoft® Direct3D® Mobile 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 Introduction to Lighting and Materials. If an application enables texture blending, Direct3D Mobile must then combine the color value of the processed polygon pixel with the pixel already stored in the frame buffer. Direct3D Mobile 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 Mobile maps texels to pixels, see Texture Filtering. SourceBlendFactor is a calculated value that Direct3D Mobile 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 D3DMBLEND_ONE and the DestBlendFactor is D3DMBLEND_ZERO (see D3DMBLEND). It is completely transparent if the SourceBlendFactor is D3DMBLEND_ZERO and the DestBlendFactor is D3DMBLEND_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 Mobile uses D3DMBLEND_SRCALPHA as the SourceBlendFactor and D3DMBLEND_INVSRCALPHA as the DestBlendFactor. Therefore, applications can control the transparency of processed pixels by setting the alpha values in textures.

An application controls the blending factors with the D3DMRS_SRCBLEND and D3DRS_DESTBLEND render states (see D3DMRENDERSTATETYPE). Invoke the IDirect3DMobileDevice::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.

See Also

Concepts

Texture Blending