Frame Buffer Alpha |
Frame buffer alpha blending is a bit different than vertex alpha, material alpha, and texture alpha. Vertex, material, and texture alpha set transparency values that are used only for the current primitive, and by themselves have no effect on other primitives. Frame buffer alpha blending controls how the current primitive is combined with existing pixels in the frame buffer to yield a final pixel color.
When performing alpha blending, two colors are being combined: a source color and a destination color. The source color is from the transparent object, and the destination color is the color already at the pixel location. The destination color is the result of rendering some other object that is behind the transparent object; that is, the object that will be visible through the transparent object. Alpha blending uses the following formula to control the ratio between the source and destination objects.
Final Color = ObjectColor * SourceBlendFactor + PixelColor * DestinationBlendFactor
ObjectColor is the contribution from the primitive being rendered at the current pixel location. PixelColor is the contribution from the frame buffer at the current pixel location.
The following set of blend factors can be used.
Blend mode factor | Description |
---|---|
Zero | (0, 0, 0, 0) |
One | (1, 1, 1, 1) |
SourceColor | (Rs,Gs,Bs,As) |
InvSourceColor | (1 - Rs, 1 - Gs, 1 - Bs, 1 - As) |
SourceAlpha | (As, As, As, As) |
InvSourceAlpha | (1 - As, 1 - As, 1 - As, 1 - As) |
DestinationAlpha | (Ad, Ad, Ad, Ad) |
InvDestinationAlpha | (1 - Ad, 1 - Ad, 1 - Ad, 1 - Ad) |
DestinationColor | (Rd, Gd, Bd, Ad) |
InvDestinationColor | (1 - Rd, 1 - Gd, 1 - Bd, 1 - Ad) |
SourceAlphaSat | (f, f, f, 1); f = min(As, 1 - Ad) |
BothSourceAlpha | Obsolete. To achieve the same effect, set the source and destination blend factors to SourceAlpha and InvSourceAlpha in separate calls. |
BothInvSourceAlpha | Obsolete. To achieve the same effect, set the source and destination blend factors to SourceAlpha and InvSourceAlpha in separate calls. Source blend factor is (1 - As, 1 - As, 1 - As, 1 - As), and destination blend factor is (As, As, As, As); the destination blend selection is overridden. This blend mode is supported only if the RenderStateManager.SourceBlend property is set to true. |
BlendFactor | Constant color blending factor used by the frame-buffer blender. Uses color.r, color.g, color.b, and color.a obtained from RenderStateManager.BlendFactor. This blend mode is supported only if the BlendCaps.SupportsBlendFactor property is set to true. |
InvBlendFactor | Inverted constant color blending factor used by the frame-buffer blender. Uses 1-color.r, 1-color.g, 1-color.b, and 1-color.a obtained from RenderStateManager.BlendFactor. This blend mode is supported only if the BlendCaps.SupportsBlendFactor property is set to true. |
Microsoft Direct3D uses RenderStateManager.AlphaBlendEnable to enable alpha transparency blending. The type of alpha blending that is done depends on the RenderStateManager.SourceBlend and RenderStateManager.DestBlend render states. Source and destination blend states are used in pairs. The following C# code fragment sets the source blend state to Blend.SourceColor and the destination blend state to Blend.InvSourceColor.
[C#]
// This code fragment assumes that device is a // valid Device object. // Enable alpha blending. device.RenderState.AlphaBlendEnable = true; // Set the source blend state. device.RenderState.SourceBlend = Blend.SourceColor; // Set the destination blend state. device.RenderState.DestBlend = Blend.InvSourceColor;
This code performs a linear blend between the source color (the color of the primitive being rendered at the current location) and the destination color (the color at the current location in the frame buffer). The resulting appearance is similar to tinted glass in that some of the color of the destination object seems to be transmitted through the source object; the rest of it appears to be absorbed.
Many of these blend factors require alpha values in the texture to operate correctly. Thus, when using vertex or material alpha, the application is restricted as to which modes produce interesting results.
Send comments about this topic to Microsoft. © Microsoft Corporation. All rights reserved.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center