From c534ed804869abd923f56a60eaa6f5005af3bafa Mon Sep 17 00:00:00 2001 From: myT Date: Fri, 6 Nov 2020 02:48:55 +0100 Subject: [PATCH] fixed the alpha channel blend factors in the D3D11 backend --- changelog.txt | 4 ++++ code/renderer/tr_backend_d3d11.cpp | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/changelog.txt b/changelog.txt index ec5e673..6d7a687 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 diff --git a/code/renderer/tr_backend_d3d11.cpp b/code/renderer/tr_backend_d3d11.cpp index 70ede57..60adea2 100644 --- a/code/renderer/tr_backend_d3d11.cpp +++ b/code/renderer/tr_backend_d3d11.cpp @@ -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));