From a8327ffc92eed8f5901a7dce08648de36fd50f6c Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Mon, 24 Mar 2025 21:28:54 -0400 Subject: [PATCH] Im tired --- include/egg/gfx/eggCapTexture.h | 4 ++ include/egg/gfx/eggCpuTexture.h | 4 ++ include/egg/gfx/eggPostEffectBase.h | 2 +- src/egg/gfx/eggPostEffectMaskDOF.cpp | 7 +-- src/egg/gfx/eggScreenEffectBlur.cpp | 64 +++++++++++++++++++++++++++- 5 files changed, 75 insertions(+), 6 deletions(-) diff --git a/include/egg/gfx/eggCapTexture.h b/include/egg/gfx/eggCapTexture.h index bf6d1f7b..955504eb 100644 --- a/include/egg/gfx/eggCapTexture.h +++ b/include/egg/gfx/eggCapTexture.h @@ -38,6 +38,10 @@ public: mClearColor = clr; } + void setCopyFilter(const CopyFilter &filt) { + mCopyFilterArg = filt; + } + private: /* 0x18 */ u8 mCapFlags; /* 0x19 */ GXColor mClearColor; diff --git a/include/egg/gfx/eggCpuTexture.h b/include/egg/gfx/eggCpuTexture.h index 11096550..a3e4db22 100644 --- a/include/egg/gfx/eggCpuTexture.h +++ b/include/egg/gfx/eggCpuTexture.h @@ -68,6 +68,10 @@ public: u16 getHeight() const { return mHeight; } + // Needed for PostEffectMaskDOF::setUpGradation + u16 getHeight2() { + return mHeight; + } void setHeight(u16 h) { mHeight = h; } diff --git a/include/egg/gfx/eggPostEffectBase.h b/include/egg/gfx/eggPostEffectBase.h index 7a2cfc0d..16f85642 100644 --- a/include/egg/gfx/eggPostEffectBase.h +++ b/include/egg/gfx/eggPostEffectBase.h @@ -27,7 +27,7 @@ public: return mRotation; } -protected: +public: u32 field_0x00; // at 0x0 CapTextureWrapper mTex1; // at 0x4 CapTextureWrapper mTex2; // at 0xC diff --git a/src/egg/gfx/eggPostEffectMaskDOF.cpp b/src/egg/gfx/eggPostEffectMaskDOF.cpp index fce42b94..59104d51 100644 --- a/src/egg/gfx/eggPostEffectMaskDOF.cpp +++ b/src/egg/gfx/eggPostEffectMaskDOF.cpp @@ -68,10 +68,11 @@ void PostEffectMaskDOF::setUpGradation() { const u16 width = mpCpuTex->getWidth() / 2; for (u16 y = 0; y < mpCpuTex->getHeight(); y++) { - const f32 fy = ((f32)y / mpCpuTex->getHeight()); + f32 fy = (f32)y / mpCpuTex->getHeight2(); for (u16 x = 0; x < width; x++) { - f32 fx = (f32)x / width; - f32 ratio = fx / (1.f - fy); + // Don't even have to use this one! + (void)(f32)width; + f32 ratio = ((f32)x / width) / (1.f - fy); if (ratio > 1.f) { ratio = 1.f; diff --git a/src/egg/gfx/eggScreenEffectBlur.cpp b/src/egg/gfx/eggScreenEffectBlur.cpp index c445b216..25b379a7 100644 --- a/src/egg/gfx/eggScreenEffectBlur.cpp +++ b/src/egg/gfx/eggScreenEffectBlur.cpp @@ -1,6 +1,7 @@ #include "egg/gfx/eggScreenEffectBlur.h" #include "common.h" +#include "egg/gfx/eggCpuTexture.h" #include "egg/gfx/eggDrawGX.h" #include "egg/gfx/eggPostEffectBase.h" #include "egg/gfx/eggPostEffectBlur.h" // IWYU pragma: keep @@ -12,6 +13,8 @@ #include "rvl/GX/GXTypes.h" #include "rvl/MTX/mtx.h" +#include + namespace EGG { static const GXColor sDefaultColor = {0, 0, 0, 0xFF}; @@ -41,9 +44,66 @@ ScreenEffectBlur::~ScreenEffectBlur() { delete mpUnk2; delete mpBlur; } - +static const CopyFilter copyFilter = { + {0x15, 0, 0, 0x16, 0, 0x15, 0} +}; void ScreenEffectBlur::fn_804B32B0() { - // Oh god + if (mFlag & 1) { + StateGX::invalidateTexAllGX(); + PostEffectBase::setProjection(GetScreen()); + const Screen::DataEfb &efb = GetScreen().GetDataEfb(); + u16 x1 = efb.vp.x1; + u16 y1 = efb.vp.y1; + f32 sizeX = (u16)sScreen.GetSize().x * field_0x10; + f32 sizeY = (u16)sScreen.GetSize().y * field_0x10; + u16 x2 = efb.vp.x2 * field_0x10; + u16 y2 = efb.vp.y2 * field_0x10; + + StateGX::ScopedColor _clr(true); + StateGX::ScopedAlpha _alpha(false); + StateGX::ScopedDither _dither(false); + TextureBuffer *pTex0 = NULL; + if (field_0x0C & 1) { + pTex0 = TextureBuffer::alloc(x2, y2, GX_TF_RGBA8); + pTex0->capture(x1, y1, 0, GX_TF_RGBA8); + } + TextureBuffer *pTex1 = TextureBuffer::alloc(x2, y2, GX_TF_IA8); + pTex1->setMinFilt(GX_NEAR); + pTex1->setMagFilt(GX_NEAR); + pTex1->capture(x1, y1, false, GX_TF_Z16); + + // . . . + if (field_0x0C & 2) { + TextureBuffer *pTex2 = TextureBuffer::alloc(x2, y2, GX_TF_RGBA8); + pTex2->onCapFlag(0x8); + pTex2->setCopyFilter(copyFilter); + pTex2->capture(x1, y1, false, GX_CTF_R8); + u8 val = field_0x18 * 255.f; + GXColor clr = {val, val, val, val}; + mpBlur->setStage0Color(clr); + mpBlur->setStage0F(field_0x1C); + mpBlur->mTex1 = (PostEffectBase::CapTextureWrapper){pTex2, GX_TEXMAP1}; + mpBlur->draw(sizeX * 1.0f, sizeY * 1.0f); + pTex2->free(); + } + // . . . + + mpCpuTexture = TextureBuffer::alloc(x2, y2, GX_TF_I8); + mpCpuTexture->onCapFlag(0x8); + mpCpuTexture->setCopyFilter(copyFilter); + mpCpuTexture->capture(x1, y1, false, GX_CTF_R8); + pTex1->free(); + + if (field_0x0C & 1) { + nw4r::math::MTX34 m; + PSMTXScale(m, sizeY, sizeY, 1.f); + pTex0->load(GX_TEXMAP0); + DrawGX::BeginDrawScreen(true, true, false); + DrawGX::SetBlendMode(DrawGX::BLEND_14); + DrawGX::DrawDL16(m, DrawGX::WHITE); + pTex0->free(); + } + } } void ScreenEffectBlur::fn_804B3710() {