Jump to content
  • Advertisement
Sign in to follow this  
Dom_152

Direct3D 11 Alpha Blending

This topic is 2912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to perform some alpha blending between two sprites I'm drawing to the screen. This is the blend state structure I've filled out:


blendDesc.AlphaToCoverageEnable = false;
blendDesc.IndependentBlendEnable = false;
D3D11_RENDER_TARGET_BLEND_DESC rtBlendDesc;
rtBlendDesc.BlendEnable = true;
rtBlendDesc.BlendOp = D3D11_BLEND_OP_ADD;
rtBlendDesc.BlendOpAlpha = D3D11_BLEND_OP_ADD;
rtBlendDesc.DestBlend = D3D11_BLEND_ZERO;
rtBlendDesc.DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
rtBlendDesc.RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
rtBlendDesc.SrcBlend = D3D11_BLEND_ONE;
rtBlendDesc.SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
blendDesc.RenderTarget[0] = rtBlendDesc;




This doesn't do anything. I've run it through PIX I can see that the pixels that should be blended have an alpha component of 0 and yet they still appear as magenta. If I set Src/DestBlend to D3D11_BLEND_SRC/DEST_ALPHA the magenta pixels disappear but it messes up the colours of the "solid" pixels.

What do I need to do to allow pixels with an alpha component of 0 to not be rendered?

EDIT: I've got it working with this combination:


rtBlendDesc.BlendEnable = true;
rtBlendDesc.BlendOp = D3D11_BLEND_OP_ADD;
rtBlendDesc.BlendOpAlpha = D3D11_BLEND_OP_ADD;
rtBlendDesc.DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
rtBlendDesc.DestBlendAlpha = D3D11_BLEND_ZERO;
rtBlendDesc.RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
rtBlendDesc.SrcBlend = D3D11_BLEND_SRC_ALPHA;
rtBlendDesc.SrcBlendAlpha = D3D11_BLEND_ZERO;





[Edited by - Dom_152 on July 4, 2010 3:15:14 PM]

Share this post


Link to post
Share on other sites
Advertisement
The blend equation works like this:

finalColor.rgb = (srcColor.rgb * SrcBlend) (BlendOp) (destColor.rgb * DestBlend);
finalColor.a = (srcColor.a * SrcBlendAlpha) (BlendOpAlpha) (destColor.a * DestBlendAlpha);


So in your first version, you were doing this:

finalColor.rgb = (srcColor.rgb * 1) + (destColor.rgb * 0);
finalColor.a = (srcColor.a * srcColor.a) + (destColor.a * destColor.a);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!