From 31728178d9d83de43cb1dfd9a1ff1f8cf568edd6 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 23 Mar 2025 21:01:17 -0400 Subject: [PATCH] More PostEffect Progress --- config/SOUE01/symbols.txt | 20 +++++----- configure.py | 2 +- include/egg/gfx/eggPostEffectBase.h | 21 +++++++---- include/egg/gfx/eggPostEffectMaskDOF.h | 6 +-- src/egg/gfx/eggPostEffectBase.cpp | 5 ++- src/egg/gfx/eggPostEffectBlur.cpp | 13 ++++--- src/egg/gfx/eggPostEffectMaskDOF.cpp | 51 +++++++++++++++++++++++++- 7 files changed, 88 insertions(+), 30 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index cd6d5f2a..e64d6945 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -26713,13 +26713,13 @@ draw__Q23EGG14PostEffectUnk2Fff = .text:0x804B0320; // type:function size:0x2D4 setMaterialInternal__Q23EGG14PostEffectUnk2Fv = .text:0x804B0600; // type:function size:0x4A4 __ct__Q23EGG14PostEffectMaskFv = .text:0x804B0AB0; // type:function size:0x64 setMaterialInternal__Q23EGG14PostEffectMaskFv = .text:0x804B0B20; // type:function size:0x440 -FUN_804b0f60 = .text:0x804B0F60; // type:function size:0x160 -FUN_804b10c0 = .text:0x804B10C0; // type:function size:0x330 -FUN_804b13f0 = .text:0x804B13F0; // type:function size:0x174 -FUN_804b1570 = .text:0x804B1570; // type:function size:0x64C -FUN_804b1bc0 = .text:0x804B1BC0; // type:function size:0x8 -FUN_804b1bd0 = .text:0x804B1BD0; // type:function size:0x8 -FUN_804b1be0 = .text:0x804B1BE0; // type:function size:0x8 +__ct__Q23EGG17PostEffectMaskDOFFv = .text:0x804B0F60; // type:function size:0x160 +setUpGradation__Q23EGG17PostEffectMaskDOFFv = .text:0x804B10C0; // type:function size:0x330 +draw__Q23EGG17PostEffectMaskDOFFff = .text:0x804B13F0; // type:function size:0x174 +setMaterialInternal__Q23EGG17PostEffectMaskDOFFv = .text:0x804B1570; // type:function size:0x64C +getNearColor__Q23EGG17PostEffectMaskDOFFv = .text:0x804B1BC0; // type:function size:0x8 +getFarColor__Q23EGG17PostEffectMaskDOFFv = .text:0x804B1BD0; // type:function size:0x8 +getCenterColor__Q23EGG17PostEffectMaskDOFFv = .text:0x804B1BE0; // type:function size:0x8 __ct__Q23EGG16PostEffectSimpleFv = .text:0x804B1BF0; // type:function size:0x5C setMaterialInternal__Q23EGG16PostEffectSimpleFv = .text:0x804B1C50; // type:function size:0x208 Initialize__Q23EGG6ScreenFPCUsPCUsPQ23EGG6Screen = .text:0x804B1E60; // type:function size:0x1DC @@ -37380,7 +37380,7 @@ __vt__Q23EGG14PostEffectBlur = .data:0x8056F170; // type:object size:0x1C __vt__Q23EGG20PostEffectBlurGather = .data:0x8056F190; // type:object size:0x1C __vt__Q23EGG14PostEffectUnk2 = .data:0x8056F1B0; // type:object size:0x1C __vt__Q23EGG14PostEffectMask = .data:0x8056F1D0; // type:object size:0x1C -lbl_8056F1F0 = .data:0x8056F1F0; // type:object size:0x1C +__vt__Q23EGG17PostEffectMaskDOF = .data:0x8056F1F0; // type:object size:0x1C __vt__Q23EGG16PostEffectSimple = .data:0x8056F210; // type:object size:0x1C sTVModeInfo__Q23EGG6Screen = .data:0x8056F230; // type:object size:0x24 data:2byte __vt__Q23EGG6Screen = .data:0x8056F254; // type:object size:0x14 @@ -48166,8 +48166,8 @@ lbl_8057F7BC = .sdata2:0x8057F7BC; // type:object size:0x4 data:float lbl_8057F7C0 = .sdata2:0x8057F7C0; // type:object size:0x4 data:float lbl_8057F7C8 = .sdata2:0x8057F7C8; // type:object size:0x4 data:float lbl_8057F7CC = .sdata2:0x8057F7CC; // type:object size:0x4 data:float -lbl_8057F7D0 = .sdata2:0x8057F7D0; // type:object size:0x4 -lbl_8057F7D4 = .sdata2:0x8057F7D4; // type:object size:0x4 +sColorNear__3EGG = .sdata2:0x8057F7D0; // type:object size:0x4 +sColorFar__3EGG = .sdata2:0x8057F7D4; // type:object size:0x4 lbl_8057F7D8 = .sdata2:0x8057F7D8; // type:object size:0x4 data:float lbl_8057F7DC = .sdata2:0x8057F7DC; // type:object size:0x4 data:float lbl_8057F7E0 = .sdata2:0x8057F7E0; // type:object size:0x4 data:float diff --git a/configure.py b/configure.py index 79cd5a4e..c681fdd7 100644 --- a/configure.py +++ b/configure.py @@ -890,7 +890,7 @@ config.libs = [ Object(NonMatching, "egg/gfx/eggLightTextureMgr.cpp"), Object(NonMatching, "egg/gfx/eggModelEx.cpp"), Object(Matching, "egg/gfx/eggPostEffectBase.cpp"), - Object(NonMatching, "egg/gfx/eggPostEffectBlur.cpp"), + Object(Matching, "egg/gfx/eggPostEffectBlur.cpp"), Object(Matching, "egg/gfx/eggPostEffectBlurGather.cpp"), Object(NonMatching, "egg/gfx/eggPostEffectUnk2.cpp"), # Unknown Object(Matching, "egg/gfx/eggPostEffectMask.cpp"), diff --git a/include/egg/gfx/eggPostEffectBase.h b/include/egg/gfx/eggPostEffectBase.h index 0e940200..7a2cfc0d 100644 --- a/include/egg/gfx/eggPostEffectBase.h +++ b/include/egg/gfx/eggPostEffectBase.h @@ -5,6 +5,7 @@ #include "egg/gfx/eggCapTexture.h" #include "egg/gfx/eggScreen.h" #include "egg/math/eggMath.h" +#include "egg/math/eggRotation.h" #include "nw4r/math/math_types.h" #include "rvl/GX/GXTypes.h" @@ -22,15 +23,19 @@ public: static void setProjection(const EGG::Screen &screen); + f32 getRot() const { + return mRotation; + } + protected: - u32 field_0x00; // at 0x0 - CapTextureWrapper mTex1; // at 0x4 - CapTextureWrapper mTex2; // at 0xC - f32 mOffsetX; // at 0x14 - f32 mOffsetY; // at 0x18 - f32 mScaleX; // at 0x1C - f32 mScaleY; // at 0x20 - f32 mRotation; // at 0x24 + u32 field_0x00; // at 0x0 + CapTextureWrapper mTex1; // at 0x4 + CapTextureWrapper mTex2; // at 0xC + f32 mOffsetX; // at 0x14 + f32 mOffsetY; // at 0x18 + f32 mScaleX; // at 0x1C + f32 mScaleY; // at 0x20 + EGG::Rotation mRotation; // at 0x24 PostEffectBase(); virtual ~PostEffectBase() {} // at 0x8 diff --git a/include/egg/gfx/eggPostEffectMaskDOF.h b/include/egg/gfx/eggPostEffectMaskDOF.h index 5faca35a..56ca76d1 100644 --- a/include/egg/gfx/eggPostEffectMaskDOF.h +++ b/include/egg/gfx/eggPostEffectMaskDOF.h @@ -16,9 +16,9 @@ public: virtual void setMaterialInternal() override; virtual ~PostEffectMaskDOF() {} - const GXColor &getNearColor(); - const GXColor &getFarColor(); - const GXColor &getCenterColor(); + static const GXColor &getNearColor(); + static const GXColor &getFarColor(); + static const GXColor &getCenterColor(); private: /* 0x2C */ u8 field_0x2C; diff --git a/src/egg/gfx/eggPostEffectBase.cpp b/src/egg/gfx/eggPostEffectBase.cpp index 2b2993d7..e7dbd1cb 100644 --- a/src/egg/gfx/eggPostEffectBase.cpp +++ b/src/egg/gfx/eggPostEffectBase.cpp @@ -122,8 +122,11 @@ void PostEffectBase::lerpColor(GXColor &out, const GXColor &c1, const GXColor &c } void PostEffectBase::getBaseTexMtx(nw4r::math::MTX34 *mtx) const { + // Feels wrong -> maybe an inline with rotation and pi + f32 rot = Math::pi(); f32 sin, cos; - nw4r::math::SinCosRad(&sin, &cos, mRotation * M_PI); + nw4r::math::SinCosRad(&sin, &cos, rot * mRotation); + f32 zero = 0.0f; f32 scale = 1.0f; f32 f8 = zero - 0.5f; diff --git a/src/egg/gfx/eggPostEffectBlur.cpp b/src/egg/gfx/eggPostEffectBlur.cpp index d94e0692..79d12e8a 100644 --- a/src/egg/gfx/eggPostEffectBlur.cpp +++ b/src/egg/gfx/eggPostEffectBlur.cpp @@ -50,11 +50,12 @@ void PostEffectBlur::drawInternal(u8 kernelIdx, u8 p2, f32 f1, f32 f2) { nw4r::math::MTX34 mtx; const Stage &k = field_0x38[kernelIdx]; - f32 f4 = k.field_0x0C * f1; - f32 f3 = k.field_0x0C * f2; - f32 rad1 = k.field_0x08 - mRotation * Math::pi(); + f32 tx = k.field_0x0C * f1; + f32 ty = k.field_0x0C * f2; + f32 rad1 = k.field_0x08 - Math::pi() * mRotation; + f32 abc = 2.f * Math::pi() / k.field_0x00; + int unk_00_scale = (p2 & 0x1F) * 8; - f32 abc = (2.f * Math::pi() / k.field_0x00); u8 numTexGens = k.field_0x00 - unk_00_scale; if (numTexGens > 8) { @@ -70,8 +71,8 @@ void PostEffectBlur::drawInternal(u8 kernelIdx, u8 p2, f32 f1, f32 f2) { nw4r::math::SinCosRad(&sin, &cos, rad1 + abc * unk_00_scale); nw4r::math::MTX34 m( // clang-format off - 1.0f, 0.0f, cos * f4, 0.0f, - 0.0f, 1.0f, sin * f3, 0.0f, + 1.0f, 0.0f, cos * tx, 0.0f, + 0.0f, 1.0f, sin * ty, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f // clang-format on ); diff --git a/src/egg/gfx/eggPostEffectMaskDOF.cpp b/src/egg/gfx/eggPostEffectMaskDOF.cpp index 7e9bc43a..fce42b94 100644 --- a/src/egg/gfx/eggPostEffectMaskDOF.cpp +++ b/src/egg/gfx/eggPostEffectMaskDOF.cpp @@ -39,7 +39,56 @@ PostEffectMaskDOF::PostEffectMaskDOF() field_0x00 = 0; } -void PostEffectMaskDOF::setUpGradation() {} +void PostEffectMaskDOF::setUpGradation() { + for (int i = 0; i < 3; i++) { + const u16 width = mpCpuTexArr[i]->getWidth(); + const int mid = width / 2; + for (u16 x = 0; x < mid; x++) { + f32 val = 1.f - (f32)x / (mid - 1); + + switch (i) { + case 1: val *= val; break; + case 2: + val *= val; + val *= val; + break; + } + + GXColor clr1, clr2; + lerpColor(clr1, getCenterColor(), getNearColor(), val); + lerpColor(clr2, getCenterColor(), getFarColor(), val); + + mpCpuTexArr[i]->setColor(x, 0, clr1); + mpCpuTexArr[i]->setColor(x, 1, clr1); + mpCpuTexArr[i]->setColor((width - 1) - x, 0, clr2); + mpCpuTexArr[i]->setColor((width - 1) - x, 1, clr2); + } + mpCpuTexArr[i]->flush(); + } + + const u16 width = mpCpuTex->getWidth() / 2; + for (u16 y = 0; y < mpCpuTex->getHeight(); y++) { + const f32 fy = ((f32)y / mpCpuTex->getHeight()); + for (u16 x = 0; x < width; x++) { + f32 fx = (f32)x / width; + f32 ratio = fx / (1.f - fy); + + if (ratio > 1.f) { + ratio = 1.f; + } else if (ratio < 0.f) { + ratio = 0.f; + } + ratio *= ratio; + ratio *= ratio; + GXColor clr1, clr2; + lerpColor(clr1, getCenterColor(), getNearColor(), ratio); + lerpColor(clr2, getCenterColor(), getFarColor(), ratio); + mpCpuTex->setColor((width - 1) - x, y, clr1); + mpCpuTex->setColor(width + x, y, clr2); + } + } + mpCpuTex->flush(); +} void PostEffectMaskDOF::draw(f32 width, f32 height) { setMaterialInternal();