fixed the alpha channel blend factors in the D3D11 backend

This commit is contained in:
myT 2020-11-06 02:48:55 +01:00
parent c12f7e8541
commit c534ed8048
2 changed files with 18 additions and 2 deletions

View file

@ -25,6 +25,10 @@ chg: with r_backend GL3, depth fade with MSAA now requires GLSL 4.00 at a minimu
chg: with r_backend GL3, alpha to coverage now requires GLSL 4.00 at a minimum
fix: with r_backend D3D11, the alpha channel's blend factors now match the original Q3 behavior
this affects shaders that use the following blendFunc modes: GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA
examples: jumppads on cpm3a and cpmctf3, jumppad trims on q3wcp14, shiny walls on q3wcp9
fix: batched surfaces with "tcMod turb" would generate incorrect texture coordinates
fix: throwing a fatal error when com_soundMegs is too low to load a map instead of freezing

View file

@ -655,6 +655,18 @@ static D3D11_BLEND GetDestinationBlend(unsigned int stateBits)
}
}
static D3D11_BLEND GetAlphaBlendFromColorBlend(D3D11_BLEND colorBlend)
{
switch(colorBlend)
{
case D3D11_BLEND_SRC_COLOR: return D3D11_BLEND_SRC_ALPHA;
case D3D11_BLEND_INV_SRC_COLOR: return D3D11_BLEND_INV_SRC_ALPHA;
case D3D11_BLEND_DEST_COLOR: return D3D11_BLEND_DEST_ALPHA;
case D3D11_BLEND_INV_DEST_COLOR: return D3D11_BLEND_INV_DEST_ALPHA;
default: return colorBlend;
}
}
static DXGI_FORMAT GetRenderTargetColorFormat(int format)
{
switch(format)
@ -1561,8 +1573,8 @@ static qbool GAL_Init()
blendDesc.RenderTarget[0].SrcBlend = (D3D11_BLEND)s;
blendDesc.RenderTarget[0].DestBlend = (D3D11_BLEND)d;
blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blendDesc.RenderTarget[0].SrcBlendAlpha = GetAlphaBlendFromColorBlend((D3D11_BLEND)s);
blendDesc.RenderTarget[0].DestBlendAlpha = GetAlphaBlendFromColorBlend((D3D11_BLEND)d);
blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
hr = d3ds.device->CreateBlendState(&blendDesc, &blendState);
CheckAndName(hr, "CreateBlendState", blendState, va("blend state %03d", index));