Hi, I'm having trouble with alpha blending in my engine. As you can see, the tree infront occludes the tree behind it. Why is this happening? I'm pretty sure this was working before but now this is it how it behaves. This can be fixed by changing the position of the trees but obviously this is not desirable especially with many blended meshes in the scene.

Secondly, meshes that are drawn with alpha blending enabled are not drawn to render targets above 0:

As you can see the two trees are not drawn to the sunray render target, meaning they do not occlude the rays. When I add a non alpha blended mesh to the scene, the rays are occluded as normall:

Here is the relevant code for how I draw alpha blended meshes:
// normal meshes
for (int i = 0; i < meshes.size(); i++) {
// draw mesh
}
}
// alpha meshes
m_D3D->TurnOnAlphaBlending();
for (int i = 0; i < blended_meshes.size(); i++) {
// draw mesh
}
}
m_D3D->TurnOffAlphaBlending();
Methods for enabling/disabling blending:
void sfD3D::TurnOffAlphaBlending()
{
float blendFactor[4];
// Setup the blend factor.
blendFactor[0] = 0.0f;
blendFactor[1] = 0.0f;
blendFactor[2] = 0.0f;
blendFactor[3] = 0.0f;
// Turn off the alpha blending.
m_deviceContext->OMSetBlendState(m_alphaDisableBlendingState, blendFactor, 0xffffffff);
return;
}
void sfD3D::TurnOnAlphaBlending()
{
float blendFactor[4];
// Setup the blend factor.
blendFactor[0] = 0.0f;
blendFactor[1] = 0.0f;
blendFactor[2] = 0.0f;
blendFactor[3] = 0.0f;
// Turn on the alpha blending.
m_deviceContext->OMSetBlendState(m_alphaEnableBlendingState, blendFactor, 0xffffffff);
return;
}
Blend state description:
blendStateDescription.RenderTarget[0].BlendEnable = TRUE;
blendStateDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
blendStateDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendStateDescription.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendStateDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendStateDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blendStateDescription.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendStateDescription.RenderTarget[0].RenderTargetWriteMask = 0x0f;
Thanks for your help!