From 861a78a44674c7d1a0851f71186ec24ca5f74449 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 16 Mar 2025 01:39:17 +0100 Subject: [PATCH] PostEffectBase almost --- config/SOUE01/splits.txt | 4 + config/SOUE01/symbols.txt | 44 ++++----- include/egg/gfx/eggDrawGX.h | 49 +++++++++- include/egg/gfx/eggDrawPathDOF.h | 5 +- include/egg/gfx/eggFrustum.h | 34 +++++++ include/egg/gfx/eggPostEffectBase.h | 20 +++- include/egg/gfx/eggScreen.h | 1 + src/egg/gfx/eggPostEffectBase.cpp | 140 +++++++++++++++++++++++++++- 8 files changed, 266 insertions(+), 31 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index db75cf74..ff5d9aef 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -2257,6 +2257,10 @@ egg/gfx/eggModelEx.cpp: egg/gfx/eggPostEffectBase.cpp: .text start:0x804AEC20 end:0x804AF4B4 + .data start:0x8056F120 end:0x8056F170 + .sbss start:0x80576860 end:0x80576870 + .sdata2 start:0x8057F720 end:0x8057F750 + .bss start:0x80674EF0 end:0x80674F00 egg/gfx/eggPostEffectBlur.cpp: .text start:0x804AF4C0 end:0x804AFC04 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index c032f17e..cdb9304c 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -678,7 +678,7 @@ fn_8001D420 = .text:0x8001D420; // type:function size:0x58 fn_8001D480 = .text:0x8001D480; // type:function size:0x58 fn_8001D4E0 = .text:0x8001D4E0; // type:function size:0x6C fn_8001D550 = .text:0x8001D550; // type:function size:0x40 -fn_8001D590 = .text:0x8001D590; // type:function size:0x40 +__dt__Q23EGG14PostEffectBaseFv = .text:0x8001D590; // type:function size:0x40 fn_8001D5D0 = .text:0x8001D5D0; // type:function size:0x30 fn_8001D600 = .text:0x8001D600; // type:function size:0x38 fn_8001D640 = .text:0x8001D640; // type:function size:0xE4 @@ -9792,7 +9792,7 @@ fn_80174130 = .text:0x80174130; // type:function size:0x1D8 fn_80174310 = .text:0x80174310; // type:function size:0x5F0 internalResetForDraw__Q23EGG12DrawPathBaseFv = .text:0x80174900; // type:function size:0x4 fn_80174910 = .text:0x80174910; // type:function size:0x8 -fn_80174920 = .text:0x80174920; // type:function size:0x4 +setMaterialInternal__Q23EGG14PostEffectBaseFv = .text:0x80174920; // type:function size:0x4 fn_80174930 = .text:0x80174930; // type:function size:0x8 fn_80174940 = .text:0x80174940; // type:function size:0x14 fn_80174960 = .text:0x80174960; // type:function size:0x8 @@ -10655,7 +10655,7 @@ fn_8019C260 = .text:0x8019C260; // type:function size:0x4 fn_8019C270 = .text:0x8019C270; // type:function size:0x4 fn_8019C280 = .text:0x8019C280; // type:function size:0x4 fn_8019C290 = .text:0x8019C290; // type:function size:0x8 -fn_8019C2A0 = .text:0x8019C2A0; // type:function size:0x8 +getNumStep__Q23EGG11DrawPathDOFCFv = .text:0x8019C2A0; // type:function size:0x8 build__27sFStateFct_c<11dStageMgr_c>FRC12sStateIDIf_c = .text:0x8019C2B0; // type:function size:0x60 dispose__27sFStateFct_c<11dStageMgr_c>FRP10sStateIf_c = .text:0x8019C310; // type:function size:0xC initialize__24sFState_c<11dStageMgr_c>Fv = .text:0x8019C320; // type:function size:0x1C @@ -10674,7 +10674,7 @@ hasReachedEnd__22sFPhase<11dStageMgr_c>CFv = .text:0x8019C430; // type:function fn_8019C460 = .text:0x8019C460; // type:function size:0x10 fn_8019C470 = .text:0x8019C470; // type:function size:0x10 SetBinary__Q23EGG19IBinaryFPCv = .text:0x8019C480; // type:function size:0x10 -fn_8019C490 = .text:0x8019C490; // type:function size:0x8 +GetBinarySize__Q23EGG28IBinaryCFv = .text:0x8019C490; // type:function size:0x8 fn_8019C4A0 = .text:0x8019C4A0; // type:function size:0x10 fn_8019C4B0 = .text:0x8019C4B0; // type:function size:0x8 fn_8019C4C0 = .text:0x8019C4C0; // type:function size:0x10 @@ -10686,9 +10686,9 @@ __dt__26sFStateID_c<11dStageMgr_c>Fv = .text:0x8019CDE0; // type:function size:0 isSameName__26sFStateID_c<11dStageMgr_c>CFPCc = .text:0x8019CE40; // type:function size:0x88 fn_8019CED0 = .text:0x8019CED0; // type:function size:0x8 fn_8019CEE0 = .text:0x8019CEE0; // type:function size:0x8 -fn_8019CEF0 = .text:0x8019CEF0; // type:function size:0x8 -fn_8019CF00 = .text:0x8019CF00; // type:function size:0x8 -fn_8019CF10 = .text:0x8019CF10; // type:function size:0x8 +@24@SetBinaryInner__Q23EGG11DrawPathDOFFRCQ33EGG28IBinary3Bin = .text:0x8019CEF0; // type:function size:0x8 +@24@SetBinaryInner__Q23EGG11DrawPathDOFFRCQ33EGG28IBinary3BinRCQ33EGG28IBinary3Binf = .text:0x8019CF00; // type:function size:0x8 +@24@GetBinaryInner__Q23EGG11DrawPathDOFCFPQ33EGG28IBinary3Bin = .text:0x8019CF10; // type:function size:0x8 fn_8019CF20 = .text:0x8019CF20; // type:function size:0x8 fn_8019CF30 = .text:0x8019CF30; // type:function size:0x8 fn_8019CF40 = .text:0x8019CF40; // type:function size:0x8 @@ -26498,22 +26498,22 @@ FUN_804a2960 = .text:0x804A2960; // type:function size:0x28 fn_804A2990 = .text:0x804A2990; // type:function size:0x8 fn_804A29A0 = .text:0x804A29A0; // type:function size:0x8 fn_804A29B0 = .text:0x804A29B0; // type:function size:0x8 -EGG__DrawPathDOF____ct = .text:0x804A29C0; // type:function size:0x164 -EGG__DrawPathDOF____dt = .text:0x804A2B30; // type:function size:0x104 +__ct__Q23EGG11DrawPathDOFFv = .text:0x804A29C0; // type:function size:0x164 +__dt__Q23EGG11DrawPathDOFFv = .text:0x804A2B30; // type:function size:0x104 fn_804A2C40 = .text:0x804A2C40; // type:function size:0x40 fn_804A2C80 = .text:0x804A2C80; // type:function size:0x9C -FUN_804a2d20 = .text:0x804A2D20; // type:function size:0x324 -FUN_804a3050 = .text:0x804A3050; // type:function size:0xCC +internalResetForDraw__Q23EGG11DrawPathDOFFv = .text:0x804A2D20; // type:function size:0x324 +internalDraw__Q23EGG11DrawPathDOFFv = .text:0x804A3050; // type:function size:0xCC FUN_804a3120 = .text:0x804A3120; // type:function size:0x9A4 EGG__DrawPathDOF__internalDraw = .text:0x804A3AD0; // type:function size:0x648 FUN_804a4120 = .text:0x804A4120; // type:function size:0x224 FUN_804a4350 = .text:0x804A4350; // type:function size:0xDC -EGG__DrawPathDOF__SetBinaryInner = .text:0x804A4430; // type:function size:0x238 -EGG__DrawPathDOF__GetBinaryInner = .text:0x804A4670; // type:function size:0xD8 -EGG__DrawPathDOF__SetBinaryInner2 = .text:0x804A4750; // type:function size:0x464 -EGG__DrawPathDOF___8_dt = .text:0x804A4BC0; // type:function size:0x8 -EGG__DrawPathDOF___20_dt = .text:0x804A4BD0; // type:function size:0x8 -EGG__DrawPathDOF___24_dt = .text:0x804A4BE0; // type:function size:0x8 +SetBinaryInner__Q23EGG11DrawPathDOFFRCQ33EGG28IBinary3Bin = .text:0x804A4430; // type:function size:0x238 +GetBinaryInner__Q23EGG11DrawPathDOFCFPQ33EGG28IBinary3Bin = .text:0x804A4670; // type:function size:0xD8 +SetBinaryInner__Q23EGG11DrawPathDOFFRCQ33EGG28IBinary3BinRCQ33EGG28IBinary3Binf = .text:0x804A4750; // type:function size:0x464 +@8@__dt__Q23EGG11DrawPathDOFFv = .text:0x804A4BC0; // type:function size:0x8 +@20@__dt__Q23EGG11DrawPathDOFFv = .text:0x804A4BD0; // type:function size:0x8 +@24@__dt__Q23EGG11DrawPathDOFFv = .text:0x804A4BE0; // type:function size:0x8 EGG__DrawPathShadowVolume____ct = .text:0x804A4BF0; // type:function size:0x7C FUN_804a4c70 = .text:0x804A4C70; // type:function size:0x3C EGG__DrawPathShadowVolume__internalDraw = .text:0x804A4CB0; // type:function size:0x7B4 @@ -26690,7 +26690,7 @@ EGG__ModelEx__getResMdl = .text:0x804AEB40; // type:function size:0x48 EGG__ModelEx__getResShp = .text:0x804AEB90; // type:function size:0x90 __ct__Q23EGG14PostEffectBaseFv = .text:0x804AEC20; // type:function size:0x5C draw__Q23EGG14PostEffectBaseFff = .text:0x804AEC80; // type:function size:0x94 -setMaterialInternal__Q23EGG14PostEffectBaseFv = .text:0x804AED20; // type:function size:0x60 +fn_804AED20__Q23EGG14PostEffectBaseFv = .text:0x804AED20; // type:function size:0x60 setVtxState__Q23EGG14PostEffectBaseFv = .text:0x804AED80; // type:function size:0x8 drawScreenInternal__Q23EGG14PostEffectBaseFffff = .text:0x804AED90; // type:function size:0x8C loadTextureInternal__Q23EGG14PostEffectBaseFv = .text:0x804AEE20; // type:function size:0x48 @@ -37375,7 +37375,7 @@ EGG__LightTexture__vtable = .data:0x8056F0B8; // type:object size:0x38 EGG__LightTextureManager__vtable = .data:0x8056F0F0; // type:object size:0x20 lbl_8056F110 = .data:0x8056F110; // type:object size:0x10 jumptable_8056F120 = .data:0x8056F120; // type:object size:0x30 scope:local -lbl_8056F150 = .data:0x8056F150; // type:object size:0x20 +__vt__Q23EGG14PostEffectBase = .data:0x8056F150; // type:object size:0x1C lbl_8056F170 = .data:0x8056F170; // type:object size:0x20 lbl_8056F190 = .data:0x8056F190; // type:object size:0x20 lbl_8056F1B0 = .data:0x8056F1B0; // type:object size:0x20 @@ -41171,7 +41171,7 @@ lbl_80576858 = .sbss:0x80576858; // type:object size:0x4 data:4byte lbl_8057685C = .sbss:0x8057685C; // type:object size:0x1 data:byte lbl_80576860 = .sbss:0x80576860; // type:object size:0x1 data:byte lbl_80576861 = .sbss:0x80576861; // type:object size:0x7 data:byte -lbl_80576868 = .sbss:0x80576868; // type:object size:0x4 data:float +lbl_80576868 = .sbss:0x80576868; // type:object size:0x8 data:float sTVMode__Q23EGG6Screen = .sbss:0x80576870; // type:object size:0x4 data:4byte lbl_80576874 = .sbss:0x80576874; // type:object size:0x4 data:4byte lbl_80576878 = .sbss:0x80576878; // type:object size:0x4 data:4byte @@ -49797,13 +49797,13 @@ ex__Q23EGG8Vector3f = .bss:0x80674C3C; // type:object size:0xC data:float ey__Q23EGG8Vector3f = .bss:0x80674C48; // type:object size:0xC data:float ez__Q23EGG8Vector3f = .bss:0x80674C54; // type:object size:0xC data:float buf__Q23EGG6Assert = .bss:0x80674C60; // type:object size:0x104 -lbl_80674D68 = .bss:0x80674D68; // type:object size:0x90 +s_DL__Q23EGG6DrawGX = .bss:0x80674D68; // type:object size:0x90 sCameraMtx = .bss:0x80674DF8; // type:object size:0x30 data:float lbl_80674E28 = .bss:0x80674E28; // type:object size:0x20 sMtx__Q23EGG15GlobalDrawState = .bss:0x80674E48; // type:object size:0x30 CPU_TEX_ARR = .bss:0x80674E78; // type:object size:0x48 data:4byte lbl_80674EC0 = .bss:0x80674EC0; // type:object size:0x30 data:float -lbl_80674EF0 = .bss:0x80674EF0; // type:object size:0x10 data:float +lbl_80674EF0 = .bss:0x80674EF0; // type:object size:0xC data:float lbl_80674F00 = .bss:0x80674F00; // type:object size:0x88 data:4byte sScreen__Q23EGG16ScreenEffectBase = .bss:0x80674F88; // type:object size:0x88 lbl_80675010 = .bss:0x80675010; // type:object size:0x30 diff --git a/include/egg/gfx/eggDrawGX.h b/include/egg/gfx/eggDrawGX.h index 1fc4f6b8..6fe69326 100644 --- a/include/egg/gfx/eggDrawGX.h +++ b/include/egg/gfx/eggDrawGX.h @@ -5,13 +5,19 @@ #include "egg/core/eggHeap.h" #include "egg/gfx/eggTexture.h" #include "egg/math/eggMatrix.h" -#include "rvl/GX.h" // IWYU pragma: export +#include "rvl/GX.h" // IWYU pragma: export namespace EGG { class DrawGX { public: + // made up + struct DLData { + void *mpList; + u32 mLen; + }; + enum DL { DL_0, DL_1, @@ -35,16 +41,55 @@ public: DL_MAX }; + enum VtxType { + VTX_TYPE_0, + VTX_TYPE_1, + VTX_TYPE_2, + VTX_TYPE_3, + VTX_TYPE_4, + VTX_TYPE_5, + VTX_TYPE_6, + VTX_TYPE_7, + VTX_TYPE_8, + VTX_TYPE_9, + VTX_TYPE_10, + VTX_TYPE_11, + VTX_TYPE_12, + VTX_TYPE_13 + }; + + enum Blend { + BLEND_0, + BLEND_1, + BLEND_2, + BLEND_3, + BLEND_4, + BLEND_5, + BLEND_6, + BLEND_7, + BLEND_8, + BLEND_9, + BLEND_10, + BLEND_11, + BLEND_12, + BLEND_13, + BLEND_14, + + BLEND_MAX + }; + static void Initialize(Heap *); static GXTexMapID GetTexMapDefault(); static void LoadTexture(const EGG::ResTIMG *, GXTexMapID); static void BeginDrawScreen(bool, bool, bool); static void DrawDL(enum DL, const nw4r::math::MTX34 &, GXColor); + static void SetVtxState(enum VtxType); + static void SetBlendMode(enum Blend); // TODO MORE - /* static ?? s_DL */ + static DLData s_DL[DL_MAX]; static Matrix34f s_cameraMtx; diff --git a/include/egg/gfx/eggDrawPathDOF.h b/include/egg/gfx/eggDrawPathDOF.h index 84a15f6a..3e523d45 100644 --- a/include/egg/gfx/eggDrawPathDOF.h +++ b/include/egg/gfx/eggDrawPathDOF.h @@ -1,8 +1,8 @@ #ifndef EGG_DRAW_PATH_DOF_H #define EGG_DRAW_PATH_DOF_H -#include "egg/prim/eggBinary.h" #include "egg/gfx/eggDrawPathBase.h" +#include "egg/prim/eggBinary.h" namespace EGG { @@ -14,7 +14,7 @@ public: DrawPathDOF(); virtual ~DrawPathDOF(); - virtual u16 getNumStep() { + virtual u16 getNumStep() const override { return 3; } virtual void internalResetForDraw() override; @@ -23,6 +23,7 @@ public: virtual void SetBinaryInner(const Bin &) override; virtual void GetBinaryInner(Bin *) const override; virtual void SetBinaryInner(const Bin &, const Bin &, f32) override; + private: void *IHaveMembers; }; diff --git a/include/egg/gfx/eggFrustum.h b/include/egg/gfx/eggFrustum.h index 568b6d73..01c93063 100644 --- a/include/egg/gfx/eggFrustum.h +++ b/include/egg/gfx/eggFrustum.h @@ -10,12 +10,19 @@ namespace EGG { class Frustum { public: enum CanvasMode { + CANVAS_0, + CANVAS_1, }; enum ProjectionType { PROJ_ORTHO, PROJ_PERSP }; + enum Flag { + FLAG_DIRTY = (1 << 0), + FLAG_0x40 = 0x40, + }; + private: /* 0x00 */ ProjectionType mProjType; /* 0x04 */ CanvasMode mCanvasMode; @@ -41,6 +48,33 @@ public: mProjType = type; } + void SetDirty(bool dirty) const { + if (dirty) { + mFlags |= FLAG_DIRTY; + } else { + mFlags &= ~FLAG_DIRTY; + } + } + + void SetFlag(Flag f) const { + mFlags |= f; + } + + CanvasMode GetCanvasMode() const { + return mCanvasMode; + } + void SetCanvasMode(CanvasMode mode) { + if (mCanvasMode != mode) { + SetDirty(true); + mCanvasMode = mode; + } + } + + void SetNearFar(f32 near, f32 far) { + mNearZ = near; + mFarZ = far; + } + void ResetOrthographic(f32, f32, f32, f32, f32, f32); void SetScale(const nw4r::math::VEC3 &scale) { diff --git a/include/egg/gfx/eggPostEffectBase.h b/include/egg/gfx/eggPostEffectBase.h index 2133c646..d35a1efb 100644 --- a/include/egg/gfx/eggPostEffectBase.h +++ b/include/egg/gfx/eggPostEffectBase.h @@ -24,11 +24,23 @@ protected: PostEffectBase(); virtual ~PostEffectBase() {} // at 0x8 + void fn_804AED20(); + + void setVtxState(); + void setMatColorChannel(); + void setMatInd(); + void setMatPE(); + void setBlendModeInternal(); + static void fn_804AF040(GXColor &, const GXColor &, bool, f32); + static void fn_804AF1B0(GXColor &, const GXColor &, const GXColor &, f32); + void getBaseTexMtx(nw4r::math::MTX34 *mtx) const; + static void setProjection(const EGG::Screen &screen); + protected: - virtual void draw(f32, f32); // at 0xC - virtual void setMaterialInternal(); // at 0x10 - virtual void loadTextureInternal(); // at 0x14 - virtual void drawScreenInternal(f32, f32, f32, f32); // at 0x18 + virtual void draw(f32 width, f32 height); // at 0xC + virtual void setMaterialInternal() {} // at 0x10 + virtual void loadTextureInternal(); // at 0x14 + virtual void drawScreenInternal(f32 offsetX, f32 offsetY, f32 width, f32 height); // at 0x18 }; } // namespace EGG diff --git a/include/egg/gfx/eggScreen.h b/include/egg/gfx/eggScreen.h index 12a5fa1a..699df321 100644 --- a/include/egg/gfx/eggScreen.h +++ b/include/egg/gfx/eggScreen.h @@ -10,6 +10,7 @@ namespace EGG { class Screen : public Frustum { public: Screen(); + Screen(const Screen &other); Screen(f32, f32, f32, f32, Screen *, CanvasMode); virtual ~Screen() {} diff --git a/src/egg/gfx/eggPostEffectBase.cpp b/src/egg/gfx/eggPostEffectBase.cpp index 4dd44128..8f0e3368 100644 --- a/src/egg/gfx/eggPostEffectBase.cpp +++ b/src/egg/gfx/eggPostEffectBase.cpp @@ -1,7 +1,18 @@ #include "egg/gfx/eggPostEffectBase.h" #include "common.h" +#include "egg/gfx/eggDrawGX.h" +#include "egg/gfx/eggScreen.h" +#include "egg/math/eggVector.h" +#include "math.h" +#include "nw4r/math/math_triangular.h" +#include "nw4r/math/math_types.h" +#include "rvl/GX/GXBump.h" +#include "rvl/GX/GXDisplayList.h" +#include "rvl/GX/GXLight.h" +#include "rvl/GX/GXTransform.h" #include "rvl/GX/GXTypes.h" +#include "rvl/MTX/mtx.h" namespace EGG { @@ -18,8 +29,135 @@ PostEffectBase::PostEffectBase() { field_0x24 = 0.0f; } +void PostEffectBase::draw(f32 width, f32 height) { + setMaterialInternal(); + setVtxState(); + drawScreenInternal(mOffsetX, mOffsetY, mScaleX * width, mScaleY * height); +} + +void PostEffectBase::fn_804AED20() { + draw(mpCapTexture->getWidth(), mpCapTexture->getHeight()); +} + +void PostEffectBase::setVtxState() { + DrawGX::SetVtxState(DrawGX::VTX_TYPE_11); +} + +void PostEffectBase::drawScreenInternal(f32 offsetX, f32 offsetY, f32 width, f32 height) { + nw4r::math::MTX34 mtx; + PSMTXScale(mtx, width, height, 1.0f); + mtx._03 = offsetX; + mtx._13 = offsetY; + mtx._23 = 0.0f; + GXLoadPosMtxImm(mtx, 0); + GXCallDisplayList(DrawGX::s_DL[DrawGX::DL_16].mpList, DrawGX::s_DL[DrawGX::DL_16].mLen); +} + void PostEffectBase::loadTextureInternal() { - mpCapTexture; + mpCapTexture->load(mTexMapId); + if (mpCapTexture2 != nullptr) { + mpCapTexture2->load(mTexMapId2); + } +} + +void PostEffectBase::setMatColorChannel() { + GXSetNumChans(0); + GXSetChanCtrl(GX_COLOR0A0, false, GX_SRC_REG, GX_SRC_REG, GX_LIGHT_NULL, GX_DF_SIGN, GX_AF_NONE); + GXSetChanCtrl(GX_COLOR1A1, false, GX_SRC_REG, GX_SRC_REG, GX_LIGHT_NULL, GX_DF_SIGN, GX_AF_NONE); + GXSetCullMode(GX_CULL_BACK); +} + +void PostEffectBase::setMatInd() { + GXSetNumIndStages(0); +} + +void PostEffectBase::setMatPE() { + GXSetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0); + GXSetZMode(false, GX_ALWAYS, false); + static const GXColor black = {0, 0, 0, 0xFF}; + GXSetFog(GX_FOG_NONE, black, 0.0, 1.0, 0.0, 1.0); + setBlendModeInternal(); +} + +void PostEffectBase::setBlendModeInternal() { + switch (field_0x00) { + case 0: DrawGX::SetBlendMode(DrawGX::BLEND_14); break; + case 1: DrawGX::SetBlendMode(DrawGX::BLEND_0); break; + case 2: DrawGX::SetBlendMode(DrawGX::BLEND_2); break; + case 3: DrawGX::SetBlendMode(DrawGX::BLEND_4); break; + case 4: GXSetBlendMode(GX_BM_BLEND, GX_BL_DSTCLR, GX_BL_INVDSTCLR, GX_LO_CLEAR); break; + case 5: DrawGX::SetBlendMode(DrawGX::BLEND_5); break; + case 6: GXSetBlendMode(GX_BM_BLEND, GX_BL_INVSRCCLR, GX_BL_INVSRCCLR, GX_LO_CLEAR); break; + case 7: DrawGX::SetBlendMode(DrawGX::BLEND_3); break; + case 8: GXSetBlendMode(GX_BM_BLEND, GX_BL_INVSRCALPHA, GX_BL_ONE, GX_LO_CLEAR); break; + case 9: GXSetBlendMode(GX_BM_SUBTRACT, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); break; + case 10: DrawGX::SetBlendMode(DrawGX::BLEND_7); break; + case 11: GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_ZERO, GX_LO_CLEAR); break; + } +} + +void PostEffectBase::fn_804AF040(GXColor &out, const GXColor &c, bool bClamp, f32 amount) { + f32 fs[4]; + fs[0] = c.r * amount; + fs[1] = c.g * amount; + fs[2] = c.b * amount; + fs[3] = c.a * amount; + + if (bClamp) { + out.r = fs[0] < 255.0f ? fs[0] : 255.0f; + out.g = fs[1] < 255.0f ? fs[1] : 255.0f; + out.b = fs[2] < 255.0f ? fs[2] : 255.0f; + out.a = fs[3] < 255.0f ? fs[3] : 255.0f; + } else { + out.r = fs[0]; + out.g = fs[1]; + out.b = fs[2]; + out.a = fs[3]; + } +} + +void PostEffectBase::fn_804AF1B0(GXColor &out, const GXColor &c1, const GXColor &c2, f32 amount) { + out.r = c1.r + amount * (c2.r - c1.r); + out.g = c1.g + amount * (c2.g - c1.g); + out.b = c1.b + amount * (c2.b - c1.b); + out.a = c1.a + amount * (c2.a - c1.a); +} + +void PostEffectBase::getBaseTexMtx(nw4r::math::MTX34 *mtx) const { + f32 sin, cos; + nw4r::math::SinCosRad(&sin, &cos, field_0x24 * M_PI); + f32 zero = 0.0f; + f32 scale = 1.0f; + f32 f8 = zero - 0.5f; + + mtx->_00 = scale * cos; + mtx->_01 = scale * sin; + mtx->_02 = ((f8 * cos) - (sin * (f8 + scale))) + 0.5f; + + mtx->_10 = -scale * sin; + mtx->_11 = scale * cos; + mtx->_12 = ((-f8 * sin) - (cos * (f8 + scale))) + 0.5f; + + mtx->_23 = zero; + mtx->_21 = zero; + mtx->_20 = zero; + mtx->_13 = zero; + mtx->_03 = zero; + mtx->_22 = scale; +} + +void PostEffectBase::setProjection(const Screen &screen) { + static Vector3f sScale(1.0f, 1.0f, 1.0f); + static Vector2f sOffset(0.0f, 0.0f); + + Screen screenCpy(screen); + screenCpy.SetFlag(Screen::FLAG_0x40); + screenCpy.SetCanvasMode(Screen::CANVAS_1); + screenCpy.SetProjectionType(Screen::PROJ_ORTHO); + screenCpy.SetNearFar(0.0f, 1.0f); + screenCpy.SetScale(sScale); + screenCpy.SetOffset(sOffset); + screenCpy.SetProjectionGX(); } } // namespace EGG