I'm trying to setup blending state to perform some blending, but for some reason I can't understand how it works, it's always giving me troubles.
My pixel shader returns (0, 0, 0, x), where x is some amount of alpha, basically I just want to make some areas darker. Here's my current blend state setup:
D3D11_BLEND_DESC blendDesc; blendDesc.AlphaToCoverageEnable = FALSE; blendDesc.IndependentBlendEnable = FALSE; blendDesc.RenderTarget.BlendEnable = TRUE; blendDesc.RenderTarget.SrcBlend = D3D11_BLEND_SRC_COLOR; blendDesc.RenderTarget.DestBlend = D3D11_BLEND_DEST_COLOR; blendDesc.RenderTarget.BlendOp = D3D11_BLEND_OP_ADD; blendDesc.RenderTarget.SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA; blendDesc.RenderTarget.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; blendDesc.RenderTarget.BlendOpAlpha = D3D11_BLEND_OP_ADD; blendDesc.RenderTarget.RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;Why I setup it like this? Well I think SRC is new color, DEST is current render target color, so SrcBlend and DestBlend are set to use those colors, SrcBlendAlpha is set to use whatever alpha pixel shader returns, and DestBlendAlpha uses inverse of new alpha. Therefore I believe it'll end up like this:
rt_color = rt_color * (1 - new_color.a) + new_color * new_color.a;
But it doesn't seem to do that.
Could anyone explain me how blending states work and/or help setup it to get it to work like I need?
Thank you in advance.