I fixed the Blending issue on dx11
it was due to all the fixed pipeline material renderers setting their blending property after setting the blend state wich ment their actual blendstate was only applied to the next node
Code: Select all
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
CD3D11MaterialRenderer::OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
if (material.MaterialType != lastMaterial.MaterialType ||
material.MaterialTypeParam != lastMaterial.MaterialTypeParam ||
resetAllRenderstates)
{
D3D11_BLEND_DESC& blendDesc = static_cast<CD3D11Driver*>(Driver)->getBlendDesc();
E_BLEND_FACTOR srcFact,dstFact;
E_MODULATE_FUNC modulate;
u32 alphaSource;
unpack_textureBlendFunc ( srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam );
if (srcFact == EBF_SRC_COLOR && dstFact == EBF_ZERO)
{
blendDesc.RenderTarget[0].BlendEnable = FALSE;
}
else
{
blendDesc.RenderTarget[0].BlendEnable = TRUE;
blendDesc.RenderTarget[0].SrcBlend = getD3DBlend ( srcFact );
blendDesc.RenderTarget[0].DestBlend = getD3DBlend ( dstFact );
blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
}
}
}
instead of doing this
Code: Select all
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
if (material.MaterialType != lastMaterial.MaterialType ||
material.MaterialTypeParam != lastMaterial.MaterialTypeParam ||
resetAllRenderstates)
{
D3D11_BLEND_DESC& blendDesc = static_cast<CD3D11Driver*>(Driver)->getBlendDesc();
E_BLEND_FACTOR srcFact,dstFact;
E_MODULATE_FUNC modulate;
u32 alphaSource;
unpack_textureBlendFunc ( srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam );
if (srcFact == EBF_SRC_COLOR && dstFact == EBF_ZERO)
{
blendDesc.RenderTarget[0].BlendEnable = FALSE;
}
else
{
blendDesc.RenderTarget[0].BlendEnable = TRUE;
blendDesc.RenderTarget[0].SrcBlend = getD3DBlend ( srcFact );
blendDesc.RenderTarget[0].DestBlend = getD3DBlend ( dstFact );
blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
}
}
CD3D11MaterialRenderer::OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
}
but upon digging I found an other issue
currently the default material renderer wich is the one you get when you create your own shaders looks like this
Code: Select all
void CD3D11MaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial,
bool resetAllRenderstates, video::IMaterialRendererServices* services)
{
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
if (BaseRenderer)
BaseRenderer->OnSetMaterial(material, material, resetAllRenderstates, services);
}
//let callback know used material
if (CallBack)
CallBack->OnSetMaterial(material);
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
notice the
Code: Select all
if (BaseRenderer)
BaseRenderer->OnSetMaterial(material, material, resetAllRenderstates, services);
wich in turn calls
Code: Select all
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
CD3D11MaterialRenderer::OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
if (material.MaterialType != lastMaterial.MaterialType ||
material.MaterialTypeParam != lastMaterial.MaterialTypeParam ||
resetAllRenderstates)
{
D3D11_BLEND_DESC& blendDesc = static_cast<CD3D11Driver*>(Driver)->getBlendDesc();
E_BLEND_FACTOR srcFact,dstFact;
E_MODULATE_FUNC modulate;
u32 alphaSource;
unpack_textureBlendFunc ( srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam );
if (srcFact == EBF_SRC_COLOR && dstFact == EBF_ZERO)
{
blendDesc.RenderTarget[0].BlendEnable = FALSE;
}
else
{
blendDesc.RenderTarget[0].BlendEnable = TRUE;
blendDesc.RenderTarget[0].SrcBlend = getD3DBlend ( srcFact );
blendDesc.RenderTarget[0].DestBlend = getD3DBlend ( dstFact );
blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
}
}
}
notice this here
Code: Select all
CD3D11MaterialRenderer::OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
guess what that's calling?
that self recursive calling isn't good at all we are looping back on our selves and setting the blend state twice and befor I caught it we were setting the blend state twice and not even for our current draw