I am currently porting parts of my engine over to D3D11 from OpenGL and was trying to figure out how I would accomplish the following blending functions in D3D11.

glBlendFunc(GL_ONE, GL_ONE);

I believe it should be something like this:

D3D11_BLEND_DESC blendDesc;
ZeroMemory(&blendDesc, sizeof(blendDesc));

ZeroMemory(&rtbd, sizeof(rtbd));

rtbd.BlendEnable = true;
rtbd.SrcBlend = D3D11_BLEND_ONE;
rtbd.DestBlend = D3D11_BLEND_ONE;

rtbd.BlendOp = D3D11_BLEND_OP_ADD;
rtbd.SrcBlendAlpha = D3D11_BLEND_ONE;
rtbd.DestBlendAlpha = D3D11_BLEND_ONE;
rtbd.BlendOpAlpha = D3D11_BLEND_OP_ADD;
rtbd.RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
blendDesc.AlphaToCoverageEnable = true;
blendDesc.RenderTarget[0] = rtbd;

m_D3D->GetDevice()->CreateBlendState(&blendDesc, &m_blendMode);

However this does not work. How can I achieve the same effect as in the first code snippet?


  • \$\begingroup\$ Did you set the blend state in the device context? \$\endgroup\$ – jmegaffin Apr 21 '15 at 12:59
  • \$\begingroup\$ Yes, I set the blend state in the render method when it is used. m_D3D->GetDeviceContext()->OMSetBlendState(m_blendMode, blendFactor, 0xffffffff); \$\endgroup\$ – Nick Apr 21 '15 at 13:00
  • \$\begingroup\$ Three suggestions: One read this MSDN guide, make sure you have debug enabled, and check the result of every Direct3D function that returns an HRESULT for failure: hr = m_D3D->GetDevice()->CreateBlendState(&blendDesc, &m_blendMode); if ( FAILED(hr) ) ...` \$\endgroup\$ – Chuck Walbourn Apr 21 '15 at 18:02

This portion of your code is not technically blend state, but could be affecting the behavior here:

glDepthMask(FALSE) glDepthFunc(GL_EQUAL)

D3D11 does have corresponding state to this, and you can set it by creating and binding a ID3D11DepthStencilState object, in a similar way to what you're doing with the ID3D11BlendState.

See https://msdn.microsoft.com/en-us/library/windows/desktop/ff476506(v=vs.85).aspx for details.

Essentially you'd be filling out an D3D11_DEPTH_STENCIL_DESC descriptor to create that object, and given that descriptor 'desc':

  • desc.DepthWriteMask maps to glDepthMask value
  • desc.DepthEnable = true/false corresponds to glEnable(GL_DEPTH_TEST)/glDisable(GL_DEPTH_TEST) respectively
  • desc.DepthFunc maps to glDepthFunc value
  • only turn on stenciling and assign the rest of the fields if you're using stenciling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.