From af5f740f51a034fae2ab6a9ae4962d5e2ffb9f55 Mon Sep 17 00:00:00 2001 From: Ubpa Date: Tue, 1 Sep 2020 13:30:59 +0800 Subject: [PATCH] fix bug: correct the blend function in DX12 formula 1. Result_alpha = Src_alpha + Dst_alpha * (1 - Src_alpha) 2. Result_rgb = Result_color * Result_alpha = Src_color * Src_alpha + Dst_color * Dst_alpha * (1 - Src_alpha) assume 1. Dst_rgb = Dst_color * Dst_alpha 2. texture (like fonts) is (Src_color, Src_alpha), not premultiplied alpha, so Src_rgb = Src_color then 1. Result_alpha = Src_alpha + Dst_alpha * (1 - Src_alpha) 2. Result_rgb = Result_color * Result_alpha = Src_rgb * Src_alpha + Dst_rgb * (1 - Src_alpha) so 1. SrcBlendAlpha = D3D12_BLEND_ONE 2. DestBlendAlpha = D3D12_BLEND_INV_SRC_ALPHA --- examples/imgui_impl_dx12.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index e9cd45c65ede..38ac7b8e6669 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -13,6 +13,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2020-09-01: DirectX12: Corrected the blend function. // 2019-10-18: DirectX12: *BREAKING CHANGE* Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function. // 2019-05-29: DirectX12: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag. // 2019-04-30: DirectX12: Added support for special ImDrawCallback_ResetRenderState callback to reset render state. @@ -552,8 +553,8 @@ bool ImGui_ImplDX12_CreateDeviceObjects() desc.RenderTarget[0].SrcBlend = D3D12_BLEND_SRC_ALPHA; desc.RenderTarget[0].DestBlend = D3D12_BLEND_INV_SRC_ALPHA; desc.RenderTarget[0].BlendOp = D3D12_BLEND_OP_ADD; - desc.RenderTarget[0].SrcBlendAlpha = D3D12_BLEND_INV_SRC_ALPHA; - desc.RenderTarget[0].DestBlendAlpha = D3D12_BLEND_ZERO; + desc.RenderTarget[0].SrcBlendAlpha = D3D12_BLEND_ONE; + desc.RenderTarget[0].DestBlendAlpha = D3D12_BLEND_INV_SRC_ALPHA; desc.RenderTarget[0].BlendOpAlpha = D3D12_BLEND_OP_ADD; desc.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL; }