From 0401b0238132c92f9f1a2c70ff3db688c4598861 Mon Sep 17 00:00:00 2001 From: refractionpcsx2 Date: Mon, 11 Mar 2024 16:00:26 +0000 Subject: [PATCH] GS/HW: Further improve alpha calculation when alpha testing --- pcsx2/GS/GSState.cpp | 16 ++++++++-------- pcsx2/GS/Renderers/HW/GSRendererHW.cpp | 11 +++++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pcsx2/GS/GSState.cpp b/pcsx2/GS/GSState.cpp index 1ef8b7fc1fd27c..c098b9b7754853 100644 --- a/pcsx2/GS/GSState.cpp +++ b/pcsx2/GS/GSState.cpp @@ -3970,24 +3970,24 @@ void GSState::CorrectATEAlphaMinMax(const u32 atst, const int aref) switch (atst) { case ATST_LESS: - amax = std::min(amax, aref - 1); - amin = std::min(amin, amax); + amin = std::min(amin, std::max(aref - 1, amin)); + amax = std::min(amax, std::max(aref - 1, amin)); break; case ATST_LEQUAL: - amax = std::min(amax, aref); - amin = std::min(amin, aref); + amin = std::min(amin, std::max(aref, amin)); + amax = std::min(amax, std::max(aref, amin)); break; case ATST_EQUAL: amax = aref; amin = aref; break; case ATST_GEQUAL: - amax = std::max(amax, aref); - amin = std::max(amin, aref); + amax = std::max(amax, std::min(aref, amax)); + amin = std::max(amin, std::min(aref, amax)); break; case ATST_GREATER: - amax = std::max(amax, aref + 1); - amin = std::max(amin, aref + 1); + amax = std::max(amax, std::min(aref + 1, amax)); + amin = std::max(amin, std::min(aref + 1, amax)); break; default: break; diff --git a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp index f66959c07e44ff..1b4e579cd50697 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp +++ b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp @@ -5060,16 +5060,15 @@ __ri void GSRendererHW::DrawPrims(GSTextureCache::Target* rt, GSTextureCache::Ta } } + const int fail_type = m_cached_ctx.TEST.GetAFAIL(m_cached_ctx.FRAME.PSM); + const int aref = static_cast(m_cached_ctx.TEST.AREF); + if (m_cached_ctx.TEST.ATE && ((fail_type != AFAIL_FB_ONLY && fail_type != AFAIL_RGB_ONLY) || !PRIM->ABE || !IsUsingAsInBlend())) + CorrectATEAlphaMinMax(m_cached_ctx.TEST.ATST, aref); + // Blend int blend_alpha_min = 0, blend_alpha_max = 255; if (rt) { - { - const int fail_type = m_cached_ctx.TEST.GetAFAIL(m_cached_ctx.FRAME.PSM); - const int aref = static_cast(m_cached_ctx.TEST.AREF); - if (m_cached_ctx.TEST.ATE && ((fail_type != AFAIL_FB_ONLY) || ((fail_type == AFAIL_RGB_ONLY) && (m_conf.ps.dst_fmt != GSLocalMemory::PSM_FMT_32)))) - CorrectATEAlphaMinMax(m_cached_ctx.TEST.ATST, aref); - } blend_alpha_min = rt->m_alpha_min; blend_alpha_max = rt->m_alpha_max;