This documentation is archived and is not being maintained.

RenderState.BlendFunction Property

Gets or sets a value to select the arithmetic operation to apply to the source and destination pixel components when AlphaBlendEnable is set to true. The default is BlendFunction.Add.

Namespace: Microsoft.Xna.Framework.Graphics
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

public BlendFunction BlendFunction { get; set; }

Property Value

The blending operation to set or get.

The alpha value of a color controls its transparency. Enabling alpha blending with AlphaBlendEnable allows colors, materials, and textures on a surface to be blended with transparency onto another surface.

Alpha blending is determined by the SourceBlend and DestinationBlend properties. With the default BlendFunction, the source pixel times the SourceBlend is added to the destination pixel (the pixel on the back buffer) times the DestinationBlend to produce a color that is a blend of the two pixel colors. The BlendFunction determines the operation used on the outcome of the source blend and destination blend components.

The following short code snippet sets the render state to use additive alpha blending prior to a draw call.

graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true;
graphics.GraphicsDevice.RenderState.SourceBlend = Blend.One;
graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One;
graphics.GraphicsDevice.RenderState.BlendFunction = BlendFunction.Add;

// TODO: Place the drawing calls that should be alpha blended here.

Xbox 360, Windows XP SP2, Windows Vista