Rough outline for LightTexture

This commit is contained in:
robojumper
2025-03-16 12:42:34 +01:00
parent 861a78a446
commit f622030c71
13 changed files with 341 additions and 39 deletions
+5
View File
@@ -2248,6 +2248,11 @@ egg/gfx/eggLightObject.cpp:
egg/gfx/eggLightTexture.cpp:
.text start:0x804AB250 end:0x804AD448
.ctors start:0x804DB9A4 end:0x804DB9A8
.rodata start:0x804FBC98 end:0x804FBD08
.data start:0x8056F0B8 end:0x8056F0F0
.sdata start:0x80574F38 end:0x80574F48
.sdata2 start:0x8057F6C0 end:0x8057F708
.bss start:0x80674E78 end:0x80674EF0
egg/gfx/eggLightTextureMgr.cpp:
.text start:0x804AD450 end:0x804AE644
+10 -10
View File
@@ -26538,7 +26538,7 @@ CopyToG3D__Q23EGG10FogManagerCFPQ34nw4r3g3d7ScnRoot = .text:0x804A5B90; // type:
SetBinaryInner__Q23EGG10FogManagerFRCQ33EGG27IBinary<Q23EGG10FogManager>3Bin = .text:0x804A5C20; // type:function size:0x9C
SetBinaryInner__Q23EGG10FogManagerFRCQ33EGG27IBinary<Q23EGG10FogManager>3BinRCQ33EGG27IBinary<Q23EGG10FogManager>3Binf = .text:0x804A5CC0; // type:function size:0xA4
GetBinaryInner__Q23EGG10FogManagerCFPQ33EGG27IBinary<Q23EGG10FogManager>3Bin = .text:0x804A5D70; // type:function size:0x80
GetBinarySize__Q23EGG10FogManagerCFv = .text:0x804A5DF0; // type:function size:0x14
GetBinarySize__Q23EGG10FogManagerFv = .text:0x804A5DF0; // type:function size:0x14
GetBinary__Q23EGG19IBinary<Q23EGG3Fog>CFPv = .text:0x804A5E10; // type:function size:0x140
SetBinaryBlend__Q23EGG19IBinary<Q23EGG3Fog>FPCvPCvf = .text:0x804A5F50; // type:function size:0x10
__ct__Q23EGG7FrustumFQ33EGG7Frustum14ProjectionTypeRCQ34nw4r4math4VEC2ffQ33EGG7Frustum10CanvasMode = .text:0x804A5F60; // type:function size:0x64
@@ -26658,10 +26658,10 @@ GetBinaryInner__Q23EGG12LightTextureCFPQ33EGG29IBinary<Q23EGG12LightTexture>3Bin
GetBinarySize__Q23EGG12LightTextureCFv = .text:0x804AD390; // type:function size:0x14
SetBinaryInner__Q23EGG29IBinary<Q23EGG12LightTexture>FRCQ33EGG29IBinary<Q23EGG12LightTexture>3BinRCQ33EGG29IBinary<Q23EGG12LightTexture>3Binf = .text:0x804AD3B0; // type:function size:0x4
__sinit_\eggLightTexture_cpp = .text:0x804AD3C0; // type:function size:0x44 scope:local
@52@SetBinaryInner__Q23EGG12LightTextureFRCQ33EGG29IBinary<Q23EGG12LightTexture>3Bin = .text:0x804AD410; // type:function size:0x8
@52@GetBinaryInner__Q23EGG12LightTextureCFPQ33EGG29IBinary<Q23EGG12LightTexture>3Bin = .text:0x804AD420; // type:function size:0x8
@52@GetBinarySize__Q23EGG12LightTextureCFv = .text:0x804AD430; // type:function size:0x8
@52@__dt__Q23EGG12LightTextureFv = .text:0x804AD440; // type:function size:0x8
@44@SetBinaryInner__Q23EGG12LightTextureFRCQ33EGG29IBinary<Q23EGG12LightTexture>3Bin = .text:0x804AD410; // type:function size:0x8
@44@GetBinaryInner__Q23EGG12LightTextureCFPQ33EGG29IBinary<Q23EGG12LightTexture>3Bin = .text:0x804AD420; // type:function size:0x8
@44@GetBinarySize__Q23EGG12LightTextureCFv = .text:0x804AD430; // type:function size:0x8
@44@__dt__Q23EGG12LightTextureFv = .text:0x804AD440; // type:function size:0x8
__ct__Q23EGG19LightTextureManagerFPCQ23EGG12LightManager = .text:0x804AD450; // type:function size:0x1AC
__dt__Q23EGG19LightTextureManagerFv = .text:0x804AD600; // type:function size:0x90
createTexture__Q23EGG19LightTextureManagerFPCc = .text:0x804AD690; // type:function size:0x110
@@ -26698,8 +26698,8 @@ setMatColorChannel__Q23EGG14PostEffectBaseFv = .text:0x804AEE70; // type:functio
setMatInd__Q23EGG14PostEffectBaseFv = .text:0x804AEEE0; // type:function size:0x8
setMatPE__Q23EGG14PostEffectBaseFv = .text:0x804AEEF0; // type:function size:0x7C
setBlendModeInternal__Q23EGG14PostEffectBaseFv = .text:0x804AEF70; // type:function size:0xC4
FUN_804af040 = .text:0x804AF040; // type:function size:0x164
FUN_804af1b0 = .text:0x804AF1B0; // type:function size:0x120
fn_804AF040__Q23EGG14PostEffectBaseFR8_GXColorRC8_GXColorbf = .text:0x804AF040; // type:function size:0x164
fn_804AF1B0__Q23EGG14PostEffectBaseFR8_GXColorRC8_GXColorRC8_GXColorf = .text:0x804AF1B0; // type:function size:0x120
getBaseTexMtx__Q23EGG14PostEffectBaseCFPQ34nw4r4math5MTX34 = .text:0x804AF2D0; // type:function size:0xE4
setProjection__Q23EGG14PostEffectBaseFRCQ23EGG6Screen = .text:0x804AF3C0; // type:function size:0xF4
FUN_804af4c0 = .text:0x804AF4C0; // type:function size:0xE0
@@ -37371,7 +37371,7 @@ EGG__GfxEnginer__Configuration__vtable = .data:0x8056F048; // type:object size:0
__vt__Q23EGG8IScnProc = .data:0x8056F058; // type:object size:0x10
EGG__LightManager__vtable = .data:0x8056F068; // type:object size:0x30
EGG__LightObject__vtable = .data:0x8056F098; // type:object size:0x20
EGG__LightTexture__vtable = .data:0x8056F0B8; // type:object size:0x38
__vt__Q23EGG12LightTexture = .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
@@ -39829,7 +39829,7 @@ lbl_80574F20 = .sdata:0x80574F20; // type:object size:0x8
lbl_80574F28 = .sdata:0x80574F28; // type:object size:0x4
lbl_80574F2C = .sdata:0x80574F2C; // type:object size:0x4 data:4byte
lbl_80574F30 = .sdata:0x80574F30; // type:object size:0x8
lbl_80574F38 = .sdata:0x80574F38; // type:object size:0x2 data:2byte
sTextureSize__Q23EGG12LightTexture = .sdata:0x80574F38; // type:object size:0x2 data:2byte
lbl_80574F3A = .sdata:0x80574F3A; // type:object size:0x1 data:byte
lbl_80574F3C = .sdata:0x80574F3C; // type:object size:0xC
lbl_80574F48 = .sdata:0x80574F48; // type:object size:0x8 data:4byte
@@ -49802,7 +49802,7 @@ 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
sMtx__3EGG = .bss:0x80674EC0; // type:object size:0x30 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
+13
View File
@@ -10,10 +10,23 @@ struct CopyFilter {
};
class CapTexture : public CpuTexture {
public:
CapTexture() {}
CapTexture(u16 width, u16 height, GXTexFmt texFmt): CpuTexture(width, height, texFmt) {}
CapTexture(const GXTexObj *pObj): CpuTexture(pObj) {}
virtual void configure() override; // at 0xC
void capture(u16 x, u16 y, bool upscale, int format);
void setPixModeSync(bool enable) {
if (enable) {
mCapFlags |= 0x10;
} else {
mCapFlags &= ~0x10;
}
}
private:
/* 0x18 */ u8 mCapFlags;
/* 0x19 */ GXColor mClearColor;
+13 -1
View File
@@ -62,7 +62,8 @@ public:
u32 getTexBufferSize() const;
void buildHeader() const;
Header *initHeader();
void fillNormalMapSphere();
void fillNormalMapSphere(f32, f32);
void fillGradient(int op, int, u16, u16, const GXColor&, const GXColor&, bool, bool);
UNKTYPE func_80086C8C(UNKTYPE);
void allocTexBuffer();
void allocTexBufferAndHeader();
@@ -109,6 +110,17 @@ public:
void setWrapT(GXTexWrapMode wrap) {
mWrapT = wrap;
}
void setWrap(GXTexWrapMode wrapS, GXTexWrapMode wrapT) {
mWrapS = wrapS;
mWrapT = wrapT;
}
void setFilt(GXTexFilter min, GXTexFilter mag) {
mMinFilt = min;
mMagFilt = mag;
}
void setMinFilt(GXTexFilter filt) {
mMinFilt = filt;
}
+1 -20
View File
@@ -1,31 +1,12 @@
#ifndef EGG_LIGHT_H
#define EGG_LIGHT_H
#include "egg/core/eggHeap.h"
#include "egg/prim/eggBinary.h"
#include "nw4r/types_nw4r.h"
namespace EGG {
// TODO: Fill out more
class LightTexture {
public:
static void initialize(u16 textureSize, Heap *pHeap);
};
// TODO: Fill out more
class LightTextureManager : public IBinary<LightTextureManager> {
public:
struct BinData {};
virtual ~LightTextureManager();
virtual void SetBinaryInner(const Bin &) override;
virtual void GetBinaryInner(Bin *) const override;
virtual size_t GetBinarySize() const override;
virtual void SetBinaryInner(const Bin &, const Bin &, f32) override;
void replaceModelTextures(nw4r::g3d::ResMdl) const;
void drawAndCaptureTexture(f32, f32, f32, f32);
};
class LightTextureManager;
// TODO: Fill out more
class LightManager : public IBinary<LightManager> {
+81 -1
View File
@@ -1,6 +1,86 @@
#ifndef EGG_LIGHT_TEXTURE_H
#define EGG_LIGHT_TEXTURE_H
namespace EGG {} // namespace EGG
#include "common.h"
#include "egg/gfx/eggCapTexture.h"
#include "egg/math/eggVector.h"
#include "egg/prim/eggBinary.h"
namespace EGG {
class LightTextureManager;
class LightTexture : public CapTexture, public IBinary<LightTexture> {
public:
struct SubData {
/* 0x00 */ f32 mIntensity;
/* 0x04 */ u8 mGradientUsed;
/* 0x05 */ u8 field_0x05;
/* 0x06 */ u8 _0x06[2];
};
// Implicit +0x10 from BinHeader
struct BinData {
/* 0x00 */ u16 mNumEntries;
/* 0x02 */ u8 field_0x02;
/* 0x03 */ u8 field_0x03;
/* 0x04 */ char mName[32];
/* 0x24 */ u8 mType;
/* 0x25 */ u8 _0x25[7];
/* 0x2C */ f32 field_0x2C;
/* 0x30 */ u8 _0x30[4];
/* 0x34 */ char mName2[32];
/* 0x54 */ f32 field_0x54;
u8 _0x00[0x1D];
SubData mSubData[1];
};
LightTexture(const char *name, const LightTextureManager *mgr);
virtual ~LightTexture();
virtual void configure() override; // at 0xC
virtual void SetBinaryInner(const Bin &) override;
virtual void GetBinaryInner(Bin *) const override;
virtual size_t GetBinarySize() const override;
static void initialize(u16 textureSize, Heap *pHeap);
private:
f32 getFloat(u16 idx) const {
return mpFloatData[idx];
}
u8 getByte1(u16 idx) const {
return mpByteData1[idx];
}
u8 getByte2(u16 idx) const {
return mpByteData2[idx];
}
/* 0x30 */ const LightTextureManager *mpMgr;
/* 0x34 */ u8 mNumData;
/* 0x35 */ u8 field_0x35;
/* 0x36 */ u8 field_0x36;
/* 0x37 */ u8 mLightType;
/* 0x38 */ Vector3f field_0x38;
/* 0x44 */ f32 *mpFloatData;
/* 0x48 */ char *mpByteData1;
/* 0x4C */ char *mpByteData2;
/* 0x50 */ f32 field_0x50;
/* 0x54 */ char mName1[0x20];
/* 0x74 */ char mName2[0x20];
/* 0x94 */ u16 field_0x94;
/* 0x98 */ f32 field_0x98;
/* 0x9C */ u8 field_0x9C;
static u16 sTextureSize;
static CpuTexture *spNormalEnvironment;
};
} // namespace EGG
#endif
+26 -1
View File
@@ -1,6 +1,31 @@
#ifndef EGG_LIGHT_TEXTURE_MGR_H
#define EGG_LIGHT_TEXTURE_MGR_H
namespace EGG {} // namespace EGG
#include "egg/prim/eggBinary.h"
#include "nw4r/g3d/res/g3d_resmdl.h"
namespace EGG {
class LightTextureManager : public IBinary<LightTextureManager> {
public:
struct BinData {};
virtual ~LightTextureManager();
virtual void SetBinaryInner(const Bin &) override;
virtual void GetBinaryInner(Bin *) const override;
virtual size_t GetBinarySize() const override;
void replaceModelTextures(nw4r::g3d::ResMdl) const;
void drawAndCaptureTexture(f32, f32, f32, f32);
u16 getMaxNumLightTextures() const {
return mMaxNumTextures;
}
private:
/* 0x14 */ u16 mMaxNumTextures;
};
} // namespace EGG
#endif
+1 -1
View File
@@ -19,7 +19,7 @@ protected:
f32 mOffsetY; // at 0x18
f32 mScaleX; // at 0x1C
f32 mScaleY; // at 0x20
f32 field_0x24; // at 0x24
f32 mRotation; // at 0x24
PostEffectBase();
virtual ~PostEffectBase() {} // at 0x8
+1 -1
View File
@@ -40,7 +40,7 @@ protected:
return sizeof(Bin);
}
/** Load the object from binary, interpolating between values */
virtual void SetBinaryInner(const Bin &, const Bin &, f32) = 0;
virtual void SetBinaryInner(const Bin &, const Bin &, f32) {}
virtual ~IBinary() {}
+185 -1
View File
@@ -1,3 +1,187 @@
#include "egg/gfx/eggLightTexture.h"
namespace EGG {} // namespace EGG
#include "common.h"
#include "egg/core/eggHeap.h"
#include "egg/gfx/eggCapTexture.h"
#include "egg/gfx/eggCpuTexture.h"
#include "egg/gfx/eggDrawGX.h"
#include "egg/gfx/eggLightTextureMgr.h"
#include "rvl/GX/GXTypes.h"
#include <cstring>
namespace EGG {
#define NUM_CPU_TEX 18
static CpuTexture *sCpuTexArray[NUM_CPU_TEX];
static const int sCpuTexGradientOp[NUM_CPU_TEX] = {0, 0, 0, 1, 2, 3, 4, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0};
static nw4r::math::MTX34 sMtx(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
u16 LightTexture::sTextureSize;
CpuTexture *LightTexture::spNormalEnvironment;
static s8 lbl_80574F3A = 0xFE;
template <>
const char *IBinary<LightTexture>::GetBinaryType() {
return "LTEX";
}
template <>
int IBinary<LightTexture>::GetVersion() {
return 3;
}
void LightTexture::initialize(u16 textureSize, Heap *pHeap) {
if (pHeap == nullptr) {
pHeap = Heap::getCurrentHeap();
}
sTextureSize = textureSize;
for (int i = 0; i < NUM_CPU_TEX; i++) {
sCpuTexArray[i] = new (pHeap) CpuTexture(64, 4, i < 10 ? GX_TF_I8 : GX_TF_RGBA8);
CpuTexture *tex = sCpuTexArray[i];
tex->configure();
tex->setWrapS(GX_REPEAT);
tex->setWrapT(GX_REPEAT);
u16 a = 32;
u16 b = 64;
switch (i) {
case 1: a = 0; break;
case 2: a = 16; break;
case 7:
a = 4;
b = 36;
break;
case 8:
a = 10;
b = 42;
break;
case 9:
a = 13;
b = 45;
break;
}
tex->allocate(pHeap);
tex->fillGradient(sCpuTexGradientOp[i], 0x73, a + 1, b - 1, DrawGX::BLACK, DrawGX::WHITE, true, true);
}
if (sTextureSize == 0x100) {
lbl_80574F3A = 1;
} else if (sTextureSize == 0x80) {
lbl_80574F3A = 0;
} else if (sTextureSize == 0x40) {
lbl_80574F3A = -1;
} else if (sTextureSize == 0x20) {
lbl_80574F3A = -2;
} else if (sTextureSize == 0x10) {
lbl_80574F3A = -3;
} else if (sTextureSize == 0x8) {
lbl_80574F3A = -4;
} else if (sTextureSize == 0x4) {
lbl_80574F3A = -5;
}
spNormalEnvironment = new (pHeap) CpuTexture(sTextureSize, sTextureSize, GX_TF_RGBA8);
spNormalEnvironment->configure();
spNormalEnvironment->allocate(pHeap);
spNormalEnvironment->fillNormalMapSphere(1.0f, 0.5f);
spNormalEnvironment->setFilt(GX_NEAR, GX_NEAR);
spNormalEnvironment->setWrap(GX_REPEAT, GX_REPEAT);
}
LightTexture::LightTexture(const char *name, const LightTextureManager *mgr)
: CapTexture(sTextureSize, sTextureSize, GX_TF_RGBA8) {
mpMgr = mgr;
mNumData = mgr->getMaxNumLightTextures();
field_0x35 = 0;
field_0x36 = 0;
mLightType = 0;
field_0x38.set(0.0f, 0.0f, 0.0f);
mpFloatData = nullptr;
mpByteData1 = nullptr;
mpByteData2 = nullptr;
field_0x50 = 1.0f;
field_0x94 = 0;
field_0x98 = 1.0f;
size_t len = std::strlen(name);
if (len >= 0x1F) {
len = 0x1E;
}
int i = 0;
for (; i < len; i++) {
mName1[i] = name[i];
}
mName1[len] = '\0';
for (size_t i = 0; i < sizeof(mName2); i++) {
mName2[i] = '\0';
}
field_0x9C = 0;
mpFloatData = new float[mNumData];
mpByteData1 = new char[mNumData];
mpByteData2 = new char[mNumData];
for (int i = 0; i < mNumData; i++) {
mpByteData2[i] = 0;
mpFloatData[i] = 1.0f;
mpByteData1[i] = 0;
}
}
LightTexture::~LightTexture() {
delete[] mpFloatData;
delete[] mpByteData1;
delete[] mpByteData2;
}
extern "C" bool lbl_8057685C;
void LightTexture::configure() {
CapTexture::configure();
if (lbl_8057685C) {
allocWithHeaderDebug(nullptr);
} else {
allocate(nullptr);
}
setWrap(GX_CLAMP, GX_CLAMP);
setPixModeSync(false);
}
void LightTexture::SetBinaryInner(const Bin &bin) {
// Not bothering with version differences right now,
// since the game uses V3 and GetBinaryInner is enough
// for the structure
}
void LightTexture::GetBinaryInner(Bin *pOutBin) const {
pOutBin->mData.mType = mLightType;
pOutBin->mData.mNumEntries = mNumData;
std::strncpy(pOutBin->mData.mName, mName1, sizeof(mName1));
SubData *dat = pOutBin->mData.mSubData;
for (int i = 0; i < mNumData; i++) {
dat[i].field_0x05 = 0;
if (getByte1(i) & 1) {
dat[i].field_0x05 |= 1;
}
dat[i].mIntensity = getFloat(i);
dat[i].mGradientUsed = getByte2(i);
}
pOutBin->mData.field_0x02 = 0;
if (field_0x36 & 1) {
pOutBin->mData.field_0x02 |= 1;
}
if (field_0x36 & 2) {
pOutBin->mData.field_0x02 |= 2;
}
pOutBin->mData.field_0x03 = field_0x35;
pOutBin->mData.field_0x2C = field_0x50;
std::strcpy(pOutBin->mData.mName2, mName2);
pOutBin->mData.field_0x54 = field_0x98;
}
size_t LightTexture::GetBinarySize() const {
return sizeof(Bin) + (mNumData - 1) * sizeof(SubData);
}
} // namespace EGG
+2 -2
View File
@@ -26,7 +26,7 @@ PostEffectBase::PostEffectBase() {
mOffsetY = 0.0f;
mScaleX = 1.0f;
mScaleY = 1.0f;
field_0x24 = 0.0f;
mRotation = 0.0f;
}
void PostEffectBase::draw(f32 width, f32 height) {
@@ -125,7 +125,7 @@ void PostEffectBase::fn_804AF1B0(GXColor &out, const GXColor &c1, const GXColor
void PostEffectBase::getBaseTexMtx(nw4r::math::MTX34 *mtx) const {
f32 sin, cos;
nw4r::math::SinCosRad(&sin, &cos, field_0x24 * M_PI);
nw4r::math::SinCosRad(&sin, &cos, mRotation * M_PI);
f32 zero = 0.0f;
f32 scale = 1.0f;
f32 f8 = zero - 0.5f;
+2
View File
@@ -2,6 +2,8 @@
#include "egg/gfx/eggDrawGX.h"
#include "egg/gfx/eggGfxEngine.h"
#include "egg/gfx/eggLightTexture.h"
#include "egg/gfx/eggLightTextureMgr.h"
#include "egg/gfx/eggScreen.h"
#include "egg/gfx/eggStateGX.h"
#include "m/m_heap.h"
+1 -1
View File
@@ -1,7 +1,7 @@
#include "d/col/bg/d_bg_s.h"
#include "d/col/bg/d_bg_w_kcol.h"
#include "d/d_rawarchive.h"
#include "egg/gfx/eggLight.h"
#include "egg/gfx/eggLightTextureMgr.h"
#include "m/m3d/m3d.h"
#include "nw4r/g3d.h" // IWYU pragma: export
#include "toBeSorted/arc_managers/current_stage_arc_manager.h"