Skip to content

Commit

Permalink
set AA to draw instead of original postfx
Browse files Browse the repository at this point in the history
Co-Authored-By: RaphaelK12 <[email protected]>
  • Loading branch information
ThirteenAG and RaphaelK12 committed Jan 2, 2024
1 parent 11d0e00 commit 22c88af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions source/antialiasing.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand Down
7 changes: 7 additions & 0 deletions source/common.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ public:
static Event<LPDIRECT3DDEVICE9&, D3DPRIMITIVETYPE&, UINT&, UINT&> BeforeDrawPrimitive;
return BeforeDrawPrimitive;
}
static bool& isInsteadDrawPrimitive() {
static bool InsteadDrawPrimitive = false;
return InsteadDrawPrimitive;
}
static void setInsteadDrawPrimitive(bool set) {
isInsteadDrawPrimitive() = set;
}
static Event<LPDIRECT3DDEVICE9&, D3DPRIMITIVETYPE&, UINT&, UINT&>& onAfterDrawPrimitive() {
static Event<LPDIRECT3DDEVICE9&, D3DPRIMITIVETYPE&, UINT&, UINT&> AfterDrawPrimitive;
return AfterDrawPrimitive;
Expand Down
5 changes: 4 additions & 1 deletion source/fusiondxhook.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 22c88af

Please sign in to comment.