Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
The alpha value of a color controls its transparency. Enabling alpha blending allows colors, materials, and textures on a surface to be blended with transparency onto another surface.
For more information, see Alpha Texture Blendingand Multiple Texture Blending.
Applications use the D3DMRS_ALPHABLENDENABLE render state (see D3DMRENDERSTATETYPE) to enable alpha transparency blending. The Microsoft® Direct3D Mobile® API allows many types of alpha blending. However, it is important to note the user's 3-D hardware might not support all the blending states allowed by Direct3D Mobile.
The type of alpha blending that is done depends on the D3DMRS_SRCBLEND and D3DMRS_DESTBLENDrender states. Source and destination blend states are used in pairs. The following code example demonstrates how the source blend state is set to D3DMBLEND_SRCCOLOR and the destination blend state is set to D3DMBLEND_INVSRCCOLOR.
Copy Code | |
---|---|
// This code example assumes that d3dmDevice is a // valid pointer to an IDirect3DMobileDevice interface. // Set the source blend state. d3dmDevice->SetRenderState(D3DMRS_SRCBLEND, D3DMBLEND_SRCCOLOR); // Set the destination blend state. d3dmDevice->SetRenderState(D3DMRS_DESTBLEND, D3DMBLEND_INVSRCCOLOR); |
As a result of the calls in the preceding code example, Direct3D Mobile performs a linear blend between the source color — the color of the primitive that is rendered at the current location — and the destination color — the color at the current location in the frame buffer. This gives an appearance similar to tinted glass. Some of the color of the destination object seems to be transmitted through the source object. The rest of the color appears to be absorbed.
Altering the source and destination blend states can give the appearance of emissive objects in a foggy or dusty atmosphere. For instance, if your application models flames, force fields, plasma beams, or similarly radiant objects in a foggy environment, set the source and destination blend states to D3DBLEND_ONE (see D3DMBLEND).
Another application of alpha blending is to control the lighting in a 3-D scene, also called light mapping. Setting the source blend state to D3DMBLEND_ZERO and the destination blend state to D3DMBLEND_SRCALPHA darkens a scene according to the source alpha information. The source primitive is used as a light mapthat scales the contents of the frame buffer to darken it when appropriate. This produces monochrome light mapping.
You can achieve color light mapping by setting the source alpha blending state to D3DMBLEND_ZERO and the destination blend state to D3DMBLEND_SRCCOLOR.