Skip to content

Instantly share code, notes, and snippets.

@Gavin-Williams
Created March 14, 2015 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gavin-Williams/0b60915fbf2781285443 to your computer and use it in GitHub Desktop.
Save Gavin-Williams/0b60915fbf2781285443 to your computer and use it in GitHub Desktop.
Setting up BlendStates
// blend supporting transparency using Premultiplied Alpha
BlendState blendStateTransparencyPMA = new BlendState(device3d,
new BlendStateDescription()
{
AlphaToCoverageEnable = false,
IndependentBlendEnable = false,
});
blendStateTransparencyPMA.Description.RenderTarget[0] = new RenderTargetBlendDescription()
{
AlphaBlendOperation = BlendOperation.Add,
IsBlendEnabled = true,
RenderTargetWriteMask = ColorWriteMaskFlags.All,
BlendOperation = BlendOperation.Add,
SourceBlend = BlendOption.One,
DestinationBlend = BlendOption.InverseSourceAlpha,
SourceAlphaBlend = BlendOption.One,
DestinationAlphaBlend = BlendOption.One
};
blendStateTransparencyPMA.DebugName = "TransparencyPMA";
this.Add(blendStateTransparencyPMA);
// blend supporting transparency
BlendState blendStateTransparency = new BlendState(device3d,
new BlendStateDescription()
{
AlphaToCoverageEnable = false,
IndependentBlendEnable = false,
});
blendStateTransparency.Description.RenderTarget[0] = new RenderTargetBlendDescription()
{
AlphaBlendOperation = BlendOperation.Add,
IsBlendEnabled = true,
RenderTargetWriteMask = ColorWriteMaskFlags.All,
BlendOperation = BlendOperation.Add,
SourceBlend = BlendOption.SourceAlpha,
DestinationBlend = BlendOption.InverseSourceAlpha,
SourceAlphaBlend = BlendOption.One,
DestinationAlphaBlend = BlendOption.One
};
blendStateTransparency.DebugName = "Transparency";
this.Add(blendStateTransparency);
// blend additive
BlendState blendStateAdditive = new BlendState(device3d,
new BlendStateDescription()
{
AlphaToCoverageEnable = false,
IndependentBlendEnable = false,
});
blendStateAdditive.Description.RenderTarget[0] = new RenderTargetBlendDescription()
{
AlphaBlendOperation = BlendOperation.Add,
IsBlendEnabled = true,
RenderTargetWriteMask = ColorWriteMaskFlags.All,
BlendOperation = BlendOperation.Add,
SourceBlend = BlendOption.One,
DestinationBlend = BlendOption.One,
SourceAlphaBlend = BlendOption.One,
DestinationAlphaBlend = BlendOption.One
};
blendStateAdditive.DebugName = "Additive";
this.Add(blendStateAdditive);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment