Created
March 14, 2015 15:25
-
-
Save Gavin-Williams/0b60915fbf2781285443 to your computer and use it in GitHub Desktop.
Setting up BlendStates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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