From 22c88affd9b36ac70c52c9c59eb916dc9abe8ed2 Mon Sep 17 00:00:00 2001 From: ThirteenAG Date: Tue, 2 Jan 2024 13:54:55 +0800 Subject: [PATCH] set AA to draw instead of original postfx Co-Authored-By: RaphaelK12 <38438130+RaphaelK12@users.noreply.github.com> --- source/antialiasing.ixx | 6 ++++-- source/common.ixx | 7 +++++++ source/fusiondxhook.ixx | 5 ++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/source/antialiasing.ixx b/source/antialiasing.ixx index a28379cf..2638c0c4 100644 --- a/source/antialiasing.ixx +++ b/source/antialiasing.ixx @@ -196,7 +196,7 @@ public: doPostFxAA = true; }; - FusionFix::D3D9::onAfterDrawPrimitive() += [](LPDIRECT3DDEVICE9& pDevice, D3DPRIMITIVETYPE& PrimitiveType, UINT& StartVertex, UINT& PrimitiveCount) + FusionFix::D3D9::onBeforeDrawPrimitive() += [](LPDIRECT3DDEVICE9& pDevice, D3DPRIMITIVETYPE& PrimitiveType, UINT& StartVertex, UINT& PrimitiveCount) { static float vec4[4] = { 0.0f }; IDirect3DPixelShader9* pShader = nullptr; @@ -234,6 +234,7 @@ public: // FXAA: Works normally as the game's post-processing shader if (ShadersAA::FxaaPS && prefAA->get() == FusionFixSettings.AntialiasingText.eFXAA) { + FusionFix::D3D9::setInsteadDrawPrimitive(true); pDevice->SetRenderTarget(0, pHDRSurface2); pDevice->Clear(0, 0, D3DCLEAR_TARGET, 0, 0, 0); DrawPrimitiveOriginalPtr(pDevice, PrimitiveType, StartVertex, PrimitiveCount); @@ -252,8 +253,9 @@ public: // SMAA // need to use the drawprimitiveup function to correct texture coordinates, // which is different from the game's post-processing. - if (ShadersAA::resourcesFinishedLoading() && pHDRSurface2 && prefAA->get() == FusionFixSettings.AntialiasingText.eSMAA) + else if (ShadersAA::resourcesFinishedLoading() && pHDRSurface2 && prefAA->get() == FusionFixSettings.AntialiasingText.eSMAA) { + FusionFix::D3D9::setInsteadDrawPrimitive(true); vec4[0] = 1.0f / float(getWindowWidth() * (bUseSSAA ? 2 : 1)); vec4[1] = 1.0f / float(getWindowHeight() * (bUseSSAA ? 2 : 1)); vec4[2] = float(getWindowWidth() * (bUseSSAA ? 2 : 1)); diff --git a/source/common.ixx b/source/common.ixx index 10895a44..796ecbd5 100644 --- a/source/common.ixx +++ b/source/common.ixx @@ -180,6 +180,13 @@ public: static Event BeforeDrawPrimitive; return BeforeDrawPrimitive; } + static bool& isInsteadDrawPrimitive() { + static bool InsteadDrawPrimitive = false; + return InsteadDrawPrimitive; + } + static void setInsteadDrawPrimitive(bool set) { + isInsteadDrawPrimitive() = set; + } static Event& onAfterDrawPrimitive() { static Event AfterDrawPrimitive; return AfterDrawPrimitive; diff --git a/source/fusiondxhook.ixx b/source/fusiondxhook.ixx index 00b70d51..3f39a994 100644 --- a/source/fusiondxhook.ixx +++ b/source/fusiondxhook.ixx @@ -368,7 +368,10 @@ public: auto D3D9DrawPrimitive = [](LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) -> HRESULT { FusionFix::D3D9::onBeforeDrawPrimitive().executeAll(pDevice, PrimitiveType, StartVertex, PrimitiveCount); - auto hr = DrawPrimitiveOriginalPtr(pDevice, PrimitiveType, StartVertex, PrimitiveCount); + auto hr = S_OK; + if (!FusionFix::D3D9::isInsteadDrawPrimitive()) + hr = DrawPrimitiveOriginalPtr(pDevice, PrimitiveType, StartVertex, PrimitiveCount); + FusionFix::D3D9::setInsteadDrawPrimitive(false); FusionFix::D3D9::onAfterDrawPrimitive().executeAll(pDevice, PrimitiveType, StartVertex, PrimitiveCount); return hr; };