From a85fb7c63ba10f6374eac3df3e42ff687cbb86ef Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 30 Sep 2023 14:09:53 -0700 Subject: [PATCH] J3DTevs, J3DMatBlock progress --- include/JSystem/J3DGraphBase/J3DGD.h | 40 +- include/JSystem/J3DGraphBase/J3DMatBlock.h | 140 +++---- include/JSystem/J3DGraphBase/J3DStruct.h | 31 +- include/JSystem/J3DGraphBase/J3DTexture.h | 4 +- src/JSystem/J3DGraphBase/J3DMatBlock.cpp | 415 +++++++++++++++++---- src/JSystem/J3DGraphBase/J3DTevs.cpp | 108 +++--- 6 files changed, 509 insertions(+), 229 deletions(-) diff --git a/include/JSystem/J3DGraphBase/J3DGD.h b/include/JSystem/J3DGraphBase/J3DGD.h index 505245955..b4a0bb60a 100644 --- a/include/JSystem/J3DGraphBase/J3DGD.h +++ b/include/JSystem/J3DGraphBase/J3DGD.h @@ -82,26 +82,42 @@ inline void J3DGDSetNumTexGens(u8 numTexGens) { J3DGDWriteXFCmd(0x103f, numTexGens); } -inline void J3DGDSetAlphaCompare(GXCompare param_0, u8 param_1, GXAlphaOp param_2, GXCompare param_3, u8 param_4) { - J3DGDWriteBPCmd(param_2 << 22 | param_3 << 19 | param_0 << 16 | param_4 << 8 | param_1 | 0xF3000000); +inline void J3DGDSetAlphaCompare(GXCompare cmp0, u8 ref0, GXAlphaOp op, GXCompare cmp1, u8 ref1) { + J3DGDWriteBPCmd(ref0 | ref1 << 8 | cmp0 << 16 | cmp1 << 19 | op << 22 | 0xF3 << 24); } -inline void J3DGDSetBlendMode(GXBlendMode param_0, GXBlendFactor param_1, GXBlendFactor param_2, GXLogicOp param_3) { +inline void J3DGDSetBlendMode(GXBlendMode mode, GXBlendFactor srcFactor, GXBlendFactor dstFactor, GXLogicOp logicOp) { J3DGDWriteBPCmd(0xFE001FE3); - bool r30 = true; - if (param_0 != GX_BM_BLEND && param_0 != GX_BM_SUBTRACT) { - r30 = false; - } - J3DGDWriteBPCmd(param_3 << 12 | (param_0 == GX_BM_LOGIC) << 11 | param_1 << 8 | param_2 << 5 | (param_0 == GX_BM_BLEND) << 1 | r30 | 0x41000000); + J3DGDWriteBPCmd( + (mode == GX_BM_BLEND || mode == GX_BM_SUBTRACT) << 0 | + (mode == GX_BM_LOGIC) << 1 | + dstFactor << 5 | + srcFactor << 8 | + (mode == GX_BM_SUBTRACT) << 11 | + logicOp << 12 | + 0x41 << 24); } -inline void J3DGDSetZMode(u8 param_0, GXCompare param_1, u8 param_2) { - J3DGDWriteBPCmd(param_2 << 4 | param_0 | param_1 << 1 | 0x40000000); +inline void J3DGDSetBlendMode(GXBlendMode mode, GXBlendFactor srcFactor, GXBlendFactor dstFactor, GXLogicOp logicOp, u8 ditherEnable) { + J3DGDWriteBPCmd(0xFE001FE7); + J3DGDWriteBPCmd( + (mode == GX_BM_BLEND || mode == GX_BM_SUBTRACT) << 0 | + (mode == GX_BM_LOGIC) << 1 | + ditherEnable << 2 | + dstFactor << 5 | + srcFactor << 8 | + (mode == GX_BM_SUBTRACT) << 11 | + logicOp << 12 | + 0x41 << 24); } -inline void J3DGDSetZCompLoc(u32 param_0) { +inline void J3DGDSetZMode(u8 compareEnable, GXCompare func, u8 writeEnable) { + J3DGDWriteBPCmd(compareEnable | func << 1 | writeEnable << 4 | 0x40 << 24); +} + +inline void J3DGDSetZCompLoc(u32 compLocEnable) { J3DGDWriteBPCmd(0xFE000040); - J3DGDWriteBPCmd(param_0 << 6 | 0x43000000); + J3DGDWriteBPCmd(compLocEnable << 6 | 0x43 << 24); } inline void J3DGDSetTevKonstantSel_SwapModeTable(GXTevStageID stage, GXTevKColorSel colorSel1, GXTevKAlphaSel alphaSel1, GXTevKColorSel colorSel2, GXTevKAlphaSel alphaSel2, GXTevColorChan chan1, GXTevColorChan chan2) { diff --git a/include/JSystem/J3DGraphBase/J3DMatBlock.h b/include/JSystem/J3DGraphBase/J3DMatBlock.h index 47cbc21eb..fb0b960f0 100644 --- a/include/JSystem/J3DGraphBase/J3DMatBlock.h +++ b/include/JSystem/J3DGraphBase/J3DMatBlock.h @@ -5,6 +5,7 @@ #include "JSystem/J3DGraphBase/J3DStruct.h" #include "JSystem/J3DGraphBase/J3DTevs.h" #include "JSystem/J3DGraphBase/J3DTexture.h" +#include "dolphin/gx/GXEnum.h" struct J3DGXColorS10 : public GXColorS10 { J3DGXColorS10() {} @@ -71,9 +72,9 @@ class J3DTexGenBlockPatched : public J3DTexGenBlock { protected: /* 0x04 */ u32 mTexGenNum; /* 0x08 */ J3DTexCoord mTexCoord[8]; - /* 0x38 */ J3DTexMtx* mTexMtx[8]; - /* 0x58 */ u32 mTexMtxOffset; -}; // Size: 0x5C + /* 0x28 */ J3DTexMtx* mTexMtx[8]; + /* 0x48 */ u32 mTexMtxOffset; +}; // Size: 0x4C class J3DTexGenBlockBasic : public J3DTexGenBlockPatched { public: @@ -91,8 +92,8 @@ class J3DTexGenBlockBasic : public J3DTexGenBlockPatched { virtual ~J3DTexGenBlockBasic() {} private: - /* 0x5C */ J3DNBTScale mNBTScale; -}; // Size: 0x6C + /* 0x4C */ J3DNBTScale mNBTScale; +}; // Size: 0x5C class J3DTexGenBlock4 : public J3DTexGenBlockPatched { public: @@ -110,8 +111,8 @@ class J3DTexGenBlock4 : public J3DTexGenBlockPatched { virtual ~J3DTexGenBlock4() {} private: - /* 0x5C */ J3DNBTScale mNBTScale; -}; // Size: 0x6C + /* 0x4C */ J3DNBTScale mNBTScale; +}; // Size: 0x5C class J3DTevBlock { public: @@ -529,28 +530,22 @@ inline u16 calcZModeID(u8 param_0, u8 param_1, u8 param_2) { return ((param_1 * 2) & 0x1FE) + (param_0 * 0x10) + param_2; } -struct J3DZModeInfo { - /* 0x0 */ u8 field_0x0; - /* 0x1 */ u8 field_0x1; - /* 0x2 */ u8 field_0x2; -}; +extern u8 j3dZModeTable[96]; struct J3DZMode { J3DZMode() { mZModeID = j3dDefaultZModeID; } - //u8 getCompareEnaable() const { return j3dZModeTable[mZModeID * 3]; } - //u8 getFunc() const { return j3dZModeTable[mZModeID * 3 + 1]; } - //u8 getUpdateEnable() const { return j3dZModeTable[mZModeID * 3 + 2]; } + u8 getCompareEnaable() const { return j3dZModeTable[mZModeID * 3]; } + u8 getFunc() const { return j3dZModeTable[mZModeID * 3 + 1]; } + u8 getUpdateEnable() const { return j3dZModeTable[mZModeID * 3 + 2]; } void setZModeInfo(const J3DZModeInfo& info) { - mZModeID = calcZModeID(info.field_0x0, info.field_0x1, info.field_0x2); + mZModeID = calcZModeID(info.mCompareEnable, info.mFunc, info.mUpdateEnable); } - /* void load() { J3DGDSetZMode(getCompareEnaable(), GXCompare(getFunc()), getUpdateEnable()); } - */ /* 0x0 */ u16 mZModeID; }; @@ -558,13 +553,13 @@ struct J3DZMode { struct J3DBlend : public J3DBlendInfo { J3DBlend() { *(J3DBlendInfo*)this = j3dDefaultBlendInfo; } - void load() { - J3DGDSetBlendMode( - GXBlendMode(mType), - GXBlendFactor(mSrcFactor), - GXBlendFactor(mDstFactor), - GXLogicOp(mOp) - ); + GXBlendMode getBlendMode() const { return (GXBlendMode)mBlendMode; } + GXBlendFactor getSrcFactor() const { return (GXBlendFactor)mSrcFactor; } + GXBlendFactor getDstFactor() const { return (GXBlendFactor)mDstFactor; } + GXLogicOp getLogicOp() const { return (GXLogicOp)mLogicOp; } + + void load(u8 ditherEnable) { + J3DGDSetBlendMode(getBlendMode(), getSrcFactor(), getDstFactor(), getLogicOp(), ditherEnable); } }; @@ -595,41 +590,30 @@ inline u32 calcAlphaCmpID(u32 param_1, u32 param_2, u32 param_3) { return ((param_1 & 0xff) << 5) + ((param_2 & 0xff) << 3) + (param_3 & 0xff); } +extern u8 j3dAlphaCmpTable[768]; + struct J3DAlphaComp { J3DAlphaComp() { - field_0x0 = j3dDefaultAlphaCmpID; + mAlphaCmpID = j3dDefaultAlphaCmpID; mRef0 = 0; mRef1 = 0; } - //u8 getComp0() { return j3dAlphaCmpTable[field_0x0 * 3]; } - //u8 getOp() { return j3dAlphaCmpTable[field_0x0 * 3 + 1]; } - //u8 getComp1() { return j3dAlphaCmpTable[field_0x0 * 3 + 2]; } - - void setAlphaCompInfo(const J3DAlphaCompInfo& param_1) { - mRef0 = param_1.field_0x1; - mRef1 = param_1.field_0x4; - u32 p1_mref1 = param_1.mRef1; - field_0x0 = calcAlphaCmpID(param_1.field_0x0, param_1.mRef0, p1_mref1); + GXCompare getComp0() const { return GXCompare(j3dAlphaCmpTable[mAlphaCmpID * 3]); } + GXAlphaOp getOp() const { return GXAlphaOp(j3dAlphaCmpTable[mAlphaCmpID * 3 + 1]); } + GXCompare getComp1() const { return GXCompare(j3dAlphaCmpTable[mAlphaCmpID * 3 + 2]); } + u8 getRef0() const { return mRef0; } + u8 getRef1() const { return mRef1; } - // this matches for `dKy_bg_MAxx_proc` but causes `addWarpMaterial` to fail, - // while the above matches for `addWarpMaterial` but causes `dKy_bg_MAxx_proc` to fail? - // field_0x0 = calcAlphaCmpID(param_1.field_0x0, param_1.mRef0, param_1.mRef1); + void setAlphaCompInfo(const J3DAlphaCompInfo& info) { + // mAlphaCmpID = calcAlphaCmpID(param_1, param_1.mRef0, param_1.mRef1); } - /* void load() { - J3DGDSetAlphaCompare( - GXCompare(getComp0()), - mRef0, - GXAlphaOp(getOp()), - GXCompare(getComp1()), - mRef1 - ); + J3DGDSetAlphaCompare(getComp0(), getRef0(), getOp(), getComp1(), getRef1()); } - */ - /* 0x00 */ u16 field_0x0; + /* 0x00 */ u16 mAlphaCmpID; /* 0x02 */ u8 mRef0; /* 0x03 */ u8 mRef1; }; // Size: 0x4 @@ -868,54 +852,40 @@ class J3DIndBlockNull : public J3DIndBlock { virtual ~J3DIndBlockNull(); }; -/* -inline u32 setChanCtrlMacro(u8 param_0, GXColorSrc param_1, GXColorSrc param_2, u32 param_3, GXDiffuseFn param_4, GXAttnFn param_5) { - GXDiffuseFn r31; - if (param_5 == GX_AF_SPEC) { - r31 = GX_DF_NONE; - } else { - r31 = param_4; - } +inline u32 setChanCtrlMacro(u8 enable, GXColorSrc ambSrc, GXColorSrc matSrc, u32 lightMask, GXDiffuseFn diffuseFn, GXAttnFn attnFn) { return - param_2 | - param_0 << 1 | - (param_3 & 0xf) << 2 | - param_1 << 6 | - r31 << 7 | - (param_5 != 2) << 9 | - (param_5 != 0) << 10 | - (param_3 >> 4 & 0x0f) << 11; + matSrc | + enable << 1 | + (lightMask & 0x0f) << 2 | + ambSrc << 6 | + ((attnFn == GX_AF_SPEC) ? GX_DF_NONE : diffuseFn) << 7 | + (attnFn != GX_AF_NONE) << 9 | + (attnFn != GX_AF_SPEC) << 10 | + (lightMask >> 4 & 0x0f) << 11; } -*/ struct J3DColorChan { J3DColorChan(); - /* - u8 getAttnFn() { - u8 local_8[4] = {0x20, 0x00, 0x02, 0x01}; - return local_8[(mColorChanID & 0x600) >> 9]; + GXAttnFn getAttnFn() { + // Need a way to put this in sdata2 without affecting every single TU ever... + + // static const u8 attnFnTbl[] = { GX_AF_NONE, GX_AF_SPEC, GX_AF_NONE, GX_AF_SPOT, }; + // return GXAttnFn(attnFnTbl[mColorChanID >> 9 & 0x03]); + return GXAttnFn(mColorChanID >> 9 & 0x03); } - */ - u8 getDiffuseFn() { return (mColorChanID & 0x180) >> 7; } - u8 getLightMask() { return (((mColorChanID & 0x7800) >> 7) | (mColorChanID & 0x3c) >> 2); } + GXDiffuseFn getDiffuseFn() { return GXDiffuseFn(mColorChanID >> 7 & 3); } + u8 getLightMask() { return ((mColorChanID >> 2 & 0x0f) | (mColorChanID >> 11 & 0x0f) << 4); } void setLightMask(u8 param_1) { - mColorChanID = (mColorChanID & ~0x3c) | ((param_1 & 0xf) << 2); + mColorChanID = (mColorChanID & ~0x3c) | ((param_1 & 0x0f) << 2); mColorChanID = (mColorChanID & ~0x7800) | ((param_1 & 0xf0) << 7); } - u8 getMatSrc() { return mColorChanID & 0x01; } - u8 getAmbSrc() { return (mColorChanID & 0x40) >> 6; } - u8 getEnable() { return (mColorChanID & 0x02) >> 1; } - /* + // bug? both enable and getMatSrc seem to use bit 0? enable should use bit 1 + GXColorSrc getMatSrc() { return GXColorSrc(mColorChanID >> 0 & 0x01); } + GXColorSrc getAmbSrc() { return GXColorSrc(mColorChanID >> 6 & 0x01); } + u8 getEnable() { return mColorChanID >> 0 & 0x01; } void load() { - u8 r26 = getAttnFn(); - u8 r27 = getDiffuseFn(); - u8 r28 = getLightMask(); - u8 r29 = getMatSrc(); - u8 r30 = getAmbSrc(); - u8 r31 = getEnable(); - J3DGDWrite_u32(setChanCtrlMacro(r31, GXColorSrc(r30), GXColorSrc(r29), r28, GXDiffuseFn(r27), GXAttnFn(r26))); + J3DGDWrite_u32(setChanCtrlMacro(getEnable(), getAmbSrc(), getMatSrc(), getLightMask(), getDiffuseFn(), getAttnFn())); } - */ /* 0x0 */ u16 mColorChanID; }; diff --git a/include/JSystem/J3DGraphBase/J3DStruct.h b/include/JSystem/J3DGraphBase/J3DStruct.h index d1a0c4035..d579ba6d7 100644 --- a/include/JSystem/J3DGraphBase/J3DStruct.h +++ b/include/JSystem/J3DGraphBase/J3DStruct.h @@ -8,7 +8,7 @@ class J3DLightInfo { public: - /* 803256C4 */ void operator=(J3DLightInfo const&); + void operator=(J3DLightInfo const&); /* 0x00 */ Vec mLightPosition; /* 0x0C */ Vec mLightDirection; @@ -25,9 +25,24 @@ struct J3DTextureSRTInfo { /* 0x10 */ f32 mTranslationY; }; // Size: 0x14 +enum J3DTexMtxMode { + J3DTexMtxMode_None, + J3DTexMtxMode_EnvmapBasic, + J3DTexMtxMode_ProjmapBasic, + J3DTexMtxMode_ViewProjmapBasic, + J3DTexMtxMode_Unknown4, + J3DTexMtxMode_Unknown5, + J3DTexMtxMode_EnvmapOld, + J3DTexMtxMode_Envmap, + J3DTexMtxMode_Projmap, + J3DTexMtxMode_ViewProjmap, + J3DTexMtxMode_EnvmapOldEffectMtx, + J3DTexMtxMode_EnvmapEffectMtx, +}; + struct J3DTexMtxInfo { - /* 80325718 */ void operator=(J3DTexMtxInfo const&); - /* 80325794 */ void setEffectMtx(Mtx); + void operator=(J3DTexMtxInfo const&); + void setEffectMtx(Mtx); /* 0x00 */ u8 mProjection; /* 0x01 */ u8 mInfo; @@ -129,10 +144,10 @@ struct J3DIndTexCoordScaleInfo { }; struct J3DBlendInfo { - /* 0x0 */ u8 mType; + /* 0x0 */ u8 mBlendMode; /* 0x1 */ u8 mSrcFactor; /* 0x2 */ u8 mDstFactor; - /* 0x3 */ u8 mOp; + /* 0x3 */ u8 mLogicOp; }; struct J3DTevOrderInfo { @@ -152,6 +167,12 @@ struct J3DColorChanInfo { /* 0x7 */ u8 field_0x7; }; +struct J3DZModeInfo { + /* 0x0 */ u8 mCompareEnable; + /* 0x1 */ u8 mFunc; + /* 0x2 */ u8 mUpdateEnable; +}; + STATIC_ASSERT(sizeof(J3DTevStageInfo) == 0x14); #endif /* J3DSTRUCT_H */ diff --git a/include/JSystem/J3DGraphBase/J3DTexture.h b/include/JSystem/J3DGraphBase/J3DTexture.h index dba348b2e..92bc64ed7 100644 --- a/include/JSystem/J3DGraphBase/J3DTexture.h +++ b/include/JSystem/J3DGraphBase/J3DTexture.h @@ -67,11 +67,13 @@ class J3DTexMtx { J3DTexMtxInfo& getTexMtxInfo() { return mTexMtxInfo; } Mtx& getMtx() { return mMtx; } void setEffectMtx(Mtx effectMtx) { mTexMtxInfo.setEffectMtx(effectMtx); } + Mtx& getViewMtx() { return mViewMtx; } + void setViewMtx(const Mtx viewMtx) { MTXCopy(viewMtx, mViewMtx); } private: /* 0x00 */ J3DTexMtxInfo mTexMtxInfo; /* 0x64 */ Mtx mMtx; - /* 0x94 */ Mtx field_0x94; + /* 0x94 */ Mtx mViewMtx; }; // Size: 0xc4 struct J3DTexCoord : public J3DTexCoordInfo { diff --git a/src/JSystem/J3DGraphBase/J3DMatBlock.cpp b/src/JSystem/J3DGraphBase/J3DMatBlock.cpp index 9b080f83e..6c125d748 100644 --- a/src/JSystem/J3DGraphBase/J3DMatBlock.cpp +++ b/src/JSystem/J3DGraphBase/J3DMatBlock.cpp @@ -7,10 +7,12 @@ #include "JSystem/J3DGraphBase/J3DTransform.h" #include "JSystem/J3DGraphBase/J3DMatBlock.h" #include "JSystem/J3DGraphBase/J3DSys.h" +#include "JSystem/J3DGraphBase/J3DStruct.h" #include "JSystem/J3DGraphBase/J3DTevs.h" #include "dolphin/gd/GDBase.h" -#include "dolphin/os/OSCache.h" +#include "dolphin/os/OS.h" #include "dolphin/types.h" +#include "MSL_C/string.h" extern bool isTexNoReg(void*); extern u16 getTexNoReg(void*); @@ -43,16 +45,16 @@ inline void loadTexCoordScale(GXTexCoordID coord, const J3DTexCoordScaleInfo& in J3DGDSetTexCoordScale2(coord, info.field_0x00, info.field_0x04 == 1, 0, info.field_0x02, info.field_0x06 == 1, 0); } -inline void loadTevColor(u32 param_1, const J3DGXColorS10& color) { - J3DGDSetTevColorS10(GXTevRegID(param_1 + 1), color); +inline void loadTevColor(u32 reg, const J3DGXColorS10& color) { + J3DGDSetTevColorS10(GXTevRegID(reg + 1), color); } -inline void loadTevKColor(u32 param_1, const J3DGXColor& color) { - J3DGDSetTevKColor(GXTevKColorID(param_1), color); +inline void loadTevKColor(u32 reg, const J3DGXColor& color) { + J3DGDSetTevKColor(GXTevKColorID(reg), color); } -inline void loadZCompLoc(u8 param_1) { - J3DGDSetZCompLoc(param_1); +inline void loadZCompLoc(u8 compLoc) { + J3DGDSetZCompLoc(compLoc); } /* 802DF794-802DF7E4 .text initialize__21J3DColorBlockLightOffFv */ @@ -228,7 +230,7 @@ void J3DIndBlockFull::initialize() { /* 802DFDFC-802DFE20 .text initialize__16J3DPEBlockFogOffFv */ void J3DPEBlockFogOff::initialize() { - mAlphaComp.field_0x0 = 0xFFFF; + mAlphaComp.mAlphaCmpID = 0xFFFF; mZMode.mZModeID = 0xFFFF; mZCompLoc = 0xFF; mDither = 1; @@ -237,7 +239,7 @@ void J3DPEBlockFogOff::initialize() { /* 802DFE20-802DFE50 .text initialize__14J3DPEBlockFullFv */ void J3DPEBlockFull::initialize() { mFog = NULL; - mAlphaComp.field_0x0 = 0xFFFF; + mAlphaComp.mAlphaCmpID = 0xFFFF; mZMode.mZModeID = 0xFFFF; mZCompLoc = 0xFF; mDither = 1; @@ -336,10 +338,10 @@ void J3DColorBlockLightOff::load() { loadMatColors((J3DGXColor*)mMatColor); mColorChanOffset = GDGetCurrOffset(); J3DGDWriteXFCmdHdr(0x100E, 4); - //mColorChan[0].load(); - //mColorChan[2].load(); - //mColorChan[1].load(); - //mColorChan[3].load(); + mColorChan[0].load(); + mColorChan[2].load(); + mColorChan[1].load(); + mColorChan[3].load(); /* Nonmatching */ } @@ -351,10 +353,10 @@ void J3DColorBlockAmbientOn::load() { loadAmbColors((J3DGXColor*)mAmbColor); mColorChanOffset = GDGetCurrOffset(); J3DGDWriteXFCmdHdr(0x100E, 4); - //mColorChan[0].load(); - //mColorChan[2].load(); - //mColorChan[1].load(); - //mColorChan[3].load(); + mColorChan[0].load(); + mColorChan[2].load(); + mColorChan[1].load(); + mColorChan[3].load(); /* Nonmatching */ } @@ -366,10 +368,10 @@ void J3DColorBlockLightOn::load() { loadAmbColors((J3DGXColor*)mAmbColor); mColorChanOffset = GDGetCurrOffset(); J3DGDWriteXFCmdHdr(0x100E, 4); - //mColorChan[0].load(); - //mColorChan[2].load(); - //mColorChan[1].load(); - //mColorChan[3].load(); + mColorChan[0].load(); + mColorChan[2].load(); + mColorChan[1].load(); + mColorChan[3].load(); for (u32 i = 0; i < 8; i++) { if (mLight[i]) { mLight[i]->load(i); @@ -400,10 +402,10 @@ void J3DColorBlockLightOff::patchLight() { u8* start = GDGetCurrPointer(); GDOverflowCheck(SizeOfLoadColorChans); J3DGDWriteXFCmdHdr(0x100E, 4); - //mColorChan[0].load(); - //mColorChan[2].load(); - //mColorChan[1].load(); - //mColorChan[3].load(); + mColorChan[0].load(); + mColorChan[2].load(); + mColorChan[1].load(); + mColorChan[3].load(); u8* end = GDGetCurrPointer(); DCFlushRange(start, end - start); /* Nonmatching */ @@ -432,10 +434,10 @@ void J3DColorBlockLightOn::patchLight() { u8* start = GDGetCurrPointer(); GDOverflowCheck(SizeOfLoadColorChans); J3DGDWriteXFCmdHdr(0x100E, 4); - //mColorChan[0].load(); - //mColorChan[2].load(); - //mColorChan[1].load(); - //mColorChan[3].load(); + mColorChan[0].load(); + mColorChan[2].load(); + mColorChan[1].load(); + mColorChan[3].load(); for (u32 i = 0; i < 8; i++) { if (mLight[i]) { mLight[i]->load(i); @@ -464,10 +466,10 @@ void J3DColorBlockLightOff::diffMatColor() { void J3DColorBlockLightOff::diffLight() { GDOverflowCheck(SizeOfLoadColorChans); J3DGDWriteXFCmdHdr(0x100E, 4); - //mColorChan[0].load(); - //mColorChan[2].load(); - //mColorChan[1].load(); - //mColorChan[3].load(); + mColorChan[0].load(); + mColorChan[2].load(); + mColorChan[1].load(); + mColorChan[3].load(); /* Nonmatching */ } @@ -487,7 +489,15 @@ void J3DColorBlockLightOn::diffMatColor() { /* 802E25F4-802E2A38 .text diffLight__20J3DColorBlockLightOnFv */ void J3DColorBlockLightOn::diffLight() { - /* Nonmatching */ + GDOverflowCheck(SizeOfLoadColorChans); + J3DGDWriteXFCmdHdr(0x100E, 4); + mColorChan[0].load(); + mColorChan[2].load(); + mColorChan[1].load(); + mColorChan[3].load(); + for (u32 i = 0; i < ARRAY_SIZE(mLight); i++) + if (mLight[i] != NULL) + mLight[i]->load(i); } /* 802E2A38-802E2ACC .text load__15J3DTexGenBlock4Fv */ @@ -1348,14 +1358,46 @@ void J3DTevBlock16::diffTexCoordScale() { } } +extern void patchTexNo_PtrToIdx(u32 texID, const u16& idx); + /* 802E603C-802E6120 .text ptrToIndex__13J3DTevBlock16Fv */ void J3DTevBlock16::ptrToIndex() { - /* Nonmatching */ + GDSetCurrOffset(mTexNoOffset); + u8* pStart = GDGetCurrPointer(); + + u32 offs = 0; + for (u32 i = 0; i < 8; i++) { + if (mTexNo[i] != 0xFFFF) { + GDSetCurrOffset(mTexNoOffset + offs); + patchTexNo_PtrToIdx(i, mTexNo[i]); + offs += 0x14; + if (j3dSys.getTexture()->getResTIMG(mTexNo[i])->indexTexture == 1) + offs += 0x23; + } + } + + u8 *pEnd = GDGetCurrPointer(); + DCFlushRange(pStart, pEnd - pStart); } /* 802E6120-802E6204 .text ptrToIndex__18J3DTevBlockPatchedFv */ void J3DTevBlockPatched::ptrToIndex() { - /* Nonmatching */ + GDSetCurrOffset(mTexNoOffset); + u8* pStart = GDGetCurrPointer(); + + u32 offs = 0; + for (u32 i = 0; i < 8; i++) { + if (mTexNo[i] != 0xFFFF) { + GDSetCurrOffset(mTexNoOffset + offs); + patchTexNo_PtrToIdx(i, mTexNo[i]); + offs += 0x14; + if (j3dSys.getTexture()->getResTIMG(mTexNo[i])->indexTexture == 1) + offs += 0x23; + } + } + + u8 *pEnd = GDGetCurrPointer(); + DCFlushRange(pStart, pEnd - pStart); } /* 802E6204-802E6298 .text indexToPtr_private__11J3DTevBlockFUl */ @@ -1451,7 +1493,7 @@ void J3DPEBlockOpa::load() { /* 802E683C-802E6B04 .text load__17J3DPEBlockTexEdgeFv */ void J3DPEBlockTexEdge::load() { GDOverflowCheck(0x1e); - J3DGDSetAlphaCompare(GX_GEQUAL, 0x80, GX_AOP_AND,GX_LEQUAL, 0xff); + J3DGDSetAlphaCompare(GX_GEQUAL, 0x80, GX_AOP_AND, GX_LEQUAL, 0xff); J3DGDSetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_COPY); J3DGDSetZMode(1, GX_LEQUAL, 1); J3DGDSetZCompLoc(0); @@ -1469,9 +1511,9 @@ void J3DPEBlockXlu::load() { /* 802E6DC8-802E7250 .text load__16J3DPEBlockFogOffFv */ void J3DPEBlockFogOff::load() { GDOverflowCheck(0x1e); - //mAlphaComp.load(); - mBlend.load(); - //mZMode.load(); + mAlphaComp.load(); + mBlend.load(mDither); + mZMode.load(); loadZCompLoc(mZCompLoc); /* Nonmatching */ } @@ -1479,8 +1521,8 @@ void J3DPEBlockFogOff::load() { /* 802E7250-802E7538 .text diffBlend__16J3DPEBlockFogOffFv */ void J3DPEBlockFogOff::diffBlend() { GDOverflowCheck(0xf); - mBlend.load(); - //mZMode.load(); + mBlend.load(mDither); + mZMode.load(); /* Nonmatching */ } @@ -1489,9 +1531,9 @@ void J3DPEBlockFull::load() { mFogOffset = GDGetCurrOffset(); GDOverflowCheck(0x55); mFog->load(); - //mAlphaComp.load(); - mBlend.load(); - //mZMode.load(); + mAlphaComp.load(); + mBlend.load(mDither); + mZMode.load(); loadZCompLoc(mZCompLoc); /* Nonmatching */ } @@ -1520,8 +1562,8 @@ void J3DPEBlockFull::diffFog() { /* 802E7B5C-802E7E44 .text diffBlend__14J3DPEBlockFullFv */ void J3DPEBlockFull::diffBlend() { GDOverflowCheck(0xf); - mBlend.load(); - //mZMode.load(); + mBlend.load(mDither); + mZMode.load(); /* Nonmatching */ } @@ -1534,78 +1576,296 @@ void J3DPEBlockFull::diff(u32 flag) { } /* 802E7EAC-802E7F88 .text reset__21J3DColorBlockLightOffFP13J3DColorBlock */ -void J3DColorBlockLightOff::reset(J3DColorBlock*) { - /* Nonmatching */ +void J3DColorBlockLightOff::reset(J3DColorBlock* pBlock) { + mColorChanNum = pBlock->getColorChanNum(); + + for (u32 i = 0; i < ARRAY_SIZE(mMatColor); i++) + mMatColor[i] = *pBlock->getMatColor(i); + for (u32 i = 0; i < ARRAY_SIZE(mColorChan); i++) + mColorChan[i] = *pBlock->getColorChan(i); } /* 802E7F88-802E80D8 .text reset__22J3DColorBlockAmbientOnFP13J3DColorBlock */ -void J3DColorBlockAmbientOn::reset(J3DColorBlock*) { - /* Nonmatching */ +void J3DColorBlockAmbientOn::reset(J3DColorBlock* pBlock) { + mColorChanNum = pBlock->getColorChanNum(); + + for (u32 i = 0; i < ARRAY_SIZE(mMatColor); i++) + mMatColor[i] = *pBlock->getMatColor(i); + for (u32 i = 0; i < ARRAY_SIZE(mColorChan); i++) + mColorChan[i] = *pBlock->getColorChan(i); + for (u32 i = 0; i < ARRAY_SIZE(mAmbColor); i++) + if (pBlock->getAmbColor(i) != NULL) + mAmbColor[i] = *pBlock->getAmbColor(i); } /* 802E80D8-802E8228 .text reset__20J3DColorBlockLightOnFP13J3DColorBlock */ -void J3DColorBlockLightOn::reset(J3DColorBlock*) { - /* Nonmatching */ +void J3DColorBlockLightOn::reset(J3DColorBlock* pBlock) { + mColorChanNum = pBlock->getColorChanNum(); + + for (u32 i = 0; i < ARRAY_SIZE(mMatColor); i++) + mMatColor[i] = *pBlock->getMatColor(i); + for (u32 i = 0; i < ARRAY_SIZE(mColorChan); i++) + mColorChan[i] = *pBlock->getColorChan(i); + for (u32 i = 0; i < ARRAY_SIZE(mAmbColor); i++) + if (pBlock->getAmbColor(i) != NULL) + mAmbColor[i] = *pBlock->getAmbColor(i); } /* 802E8228-802E8354 .text reset__21J3DTexGenBlockPatchedFP14J3DTexGenBlock */ -void J3DTexGenBlockPatched::reset(J3DTexGenBlock*) { - /* Nonmatching */ +void J3DTexGenBlockPatched::reset(J3DTexGenBlock* pBlock) { + mTexGenNum = pBlock->getTexGenNum(); + for (u32 i = 0; i < 8; i++) + mTexCoord[i] = *pBlock->getTexCoord(i); + for (u32 i = 0; i < 8; i++) { + if (pBlock->getTexMtx(i) != NULL) { + if (mTexMtx[i] != NULL) { + memcpy(mTexMtx[i], pBlock->getTexMtx(i), sizeof(*mTexMtx[i])); + DCStoreRange(mTexMtx[i], sizeof(*mTexMtx[i])); + } else { + OSReport("Error : TexMtx[%d] is Null.\n", i); + } + } + } } /* 802E8354-802E84B4 .text reset__15J3DTexGenBlock4FP14J3DTexGenBlock */ -void J3DTexGenBlock4::reset(J3DTexGenBlock*) { - /* Nonmatching */ +void J3DTexGenBlock4::reset(J3DTexGenBlock* pBlock) { + mTexGenNum = pBlock->getTexGenNum(); + for (u32 i = 0; i < 4; i++) + mTexCoord[i] = *pBlock->getTexCoord(i); + for (u32 i = 0; i < 4; i++) { + if (pBlock->getTexMtx(i) != NULL) { + if (mTexMtx[i] != NULL) { + memcpy(mTexMtx[i], pBlock->getTexMtx(i), sizeof(*mTexMtx[i])); + DCStoreRange(mTexMtx[i], sizeof(*mTexMtx[i])); + } else { + OSReport("Error : TexMtx[%d] is Null.\n", i); + } + } + } + + mNBTScale = *pBlock->getNBTScale(); } /* 802E84B4-802E8614 .text reset__19J3DTexGenBlockBasicFP14J3DTexGenBlock */ -void J3DTexGenBlockBasic::reset(J3DTexGenBlock*) { - /* Nonmatching */ +void J3DTexGenBlockBasic::reset(J3DTexGenBlock* pBlock) { + mTexGenNum = pBlock->getTexGenNum(); + for (u32 i = 0; i < 8; i++) + mTexCoord[i] = *pBlock->getTexCoord(i); + for (u32 i = 0; i < 8; i++) { + if (pBlock->getTexMtx(i) != NULL) { + if (mTexMtx[i] != NULL) { + memcpy(mTexMtx[i], pBlock->getTexMtx(i), sizeof(*mTexMtx[i])); + DCStoreRange(mTexMtx[i], sizeof(*mTexMtx[i])); + } else { + OSReport("Error : TexMtx[%d] is Null.\n", i); + } + } + } + + mNBTScale = *pBlock->getNBTScale(); } /* 802E8614-802E87D0 .text reset__18J3DTevBlockPatchedFP11J3DTevBlock */ -void J3DTevBlockPatched::reset(J3DTevBlock*) { - /* Nonmatching */ +void J3DTevBlockPatched::reset(J3DTevBlock* pBlock) { + mTevStageNum = pBlock->getTevStageNum(); + for (u32 i = 0; i < 8; i++) + mTexNo[i] = pBlock->getTexNo(i); + for (u32 i = 0; i < 4; i++) + mTevColor[i] = *pBlock->getTevColor(i); + for (u32 i = 0; i < 4; i++) + mTevKColor[i] = *pBlock->getTevKColor(i); + for (u32 i = 0; i < 8; i++) { + mTevStage[i] = *pBlock->getTevStage(i); + mIndTevStage[i] = *pBlock->getIndTevStage(i); + } } /* 802E87D0-802E88B8 .text reset__12J3DTevBlock1FP11J3DTevBlock */ -void J3DTevBlock1::reset(J3DTevBlock*) { - /* Nonmatching */ +void J3DTevBlock1::reset(J3DTevBlock* pBlock) { + mTexNo[0] = pBlock->getTexNo(0); + mTevOrder[0] = *pBlock->getTevOrder(0); + mTevStage[0] = *pBlock->getTevStage(0); + mIndTevStage[0] = *pBlock->getIndTevStage(0); } /* 802E88B8-802E8BB8 .text reset__12J3DTevBlock2FP11J3DTevBlock */ -void J3DTevBlock2::reset(J3DTevBlock*) { - /* Nonmatching */ +void J3DTevBlock2::reset(J3DTevBlock* pBlock) { + mTevStageNum = pBlock->getTevStageNum(); + mTexNo[0] = pBlock->getTexNo(0); + mTexNo[1] = pBlock->getTexNo(1); + mTevStage[0] = *pBlock->getTevStage(0); + mTevStage[1] = *pBlock->getTevStage(1); + mIndTevStage[0] = *pBlock->getIndTevStage(0); + mIndTevStage[1] = *pBlock->getIndTevStage(1); + mTevOrder[0] = *pBlock->getTevOrder(0); + mTevOrder[1] = *pBlock->getTevOrder(1); + mTevKColorSel[0] = pBlock->getTevKColorSel(0); + mTevKColorSel[1] = pBlock->getTevKColorSel(1); + mTevKAlphaSel[0] = pBlock->getTevKAlphaSel(0); + mTevKAlphaSel[1] = pBlock->getTevKAlphaSel(1); + for (u32 i = 0; i < 4; i++) + mTevColor[i] = *pBlock->getTevColor(i); + for (u32 i = 0; i < 4; i++) + mTevKColor[i] = *pBlock->getTevKColor(i); + for (u32 i = 0; i < 4; i++) + mTevSwapModeTable[i] = *pBlock->getTevSwapModeTable(i); } /* 802E8BB8-802E9090 .text reset__12J3DTevBlock4FP11J3DTevBlock */ -void J3DTevBlock4::reset(J3DTevBlock*) { - /* Nonmatching */ +void J3DTevBlock4::reset(J3DTevBlock* pBlock) { + mTevStageNum = pBlock->getTevStageNum(); + mTexNo[0] = pBlock->getTexNo(0); + mTexNo[1] = pBlock->getTexNo(1); + mTexNo[2] = pBlock->getTexNo(2); + mTexNo[3] = pBlock->getTexNo(3); + mTevStage[0] = *pBlock->getTevStage(0); + mTevStage[1] = *pBlock->getTevStage(1); + mTevStage[2] = *pBlock->getTevStage(2); + mTevStage[3] = *pBlock->getTevStage(3); + mIndTevStage[0] = *pBlock->getIndTevStage(0); + mIndTevStage[1] = *pBlock->getIndTevStage(1); + mIndTevStage[2] = *pBlock->getIndTevStage(2); + mIndTevStage[3] = *pBlock->getIndTevStage(3); + mTevOrder[0] = *pBlock->getTevOrder(0); + mTevOrder[1] = *pBlock->getTevOrder(1); + mTevOrder[2] = *pBlock->getTevOrder(2); + mTevOrder[3] = *pBlock->getTevOrder(3); + mTevKColorSel[0] = pBlock->getTevKColorSel(0); + mTevKColorSel[1] = pBlock->getTevKColorSel(1); + mTevKColorSel[2] = pBlock->getTevKColorSel(2); + mTevKColorSel[3] = pBlock->getTevKColorSel(3); + mTevKAlphaSel[0] = pBlock->getTevKAlphaSel(0); + mTevKAlphaSel[1] = pBlock->getTevKAlphaSel(1); + mTevKAlphaSel[2] = pBlock->getTevKAlphaSel(2); + mTevKAlphaSel[3] = pBlock->getTevKAlphaSel(3); + for (u32 i = 0; i < 4; i++) + mTevColor[i] = *pBlock->getTevColor(i); + for (u32 i = 0; i < 4; i++) + mTevKColor[i] = *pBlock->getTevKColor(i); + for (u32 i = 0; i < 4; i++) + mTevSwapModeTable[i] = *pBlock->getTevSwapModeTable(i); } /* 802E9090-802E932C .text reset__13J3DTevBlock16FP11J3DTevBlock */ -void J3DTevBlock16::reset(J3DTevBlock*) { - /* Nonmatching */ +void J3DTevBlock16::reset(J3DTevBlock* pBlock) { + mTevStageNum = pBlock->getTevStageNum(); + for (u32 i = 0; i < 8; i++) + mTexNo[i] = pBlock->getTexNo(i); + for (u32 i = 0; i < 16; i++) + mTevOrder[i] = *pBlock->getTevOrder(i); + for (u32 i = 0; i < 16; i++) { + mTevStage[i] = *pBlock->getTevStage(i); + mIndTevStage[i] = *pBlock->getIndTevStage(i); + } + for (u32 i = 0; i < 4; i++) + mTevColor[i] = *pBlock->getTevColor(i); + for (u32 i = 0; i < 4; i++) + mTevKColor[i] = *pBlock->getTevKColor(i); + for (u32 i = 0; i < 16; i++) + mTevKColorSel[i] = pBlock->getTevKColorSel(i); + for (u32 i = 0; i < 16; i++) + mTevKAlphaSel[i] = pBlock->getTevKAlphaSel(i); + for (u32 i = 0; i < 4; i++) + mTevSwapModeTable[i] = *pBlock->getTevSwapModeTable(i); } /* 802E932C-802E947C .text reset__15J3DIndBlockFullFP11J3DIndBlock */ -void J3DIndBlockFull::reset(J3DIndBlock*) { - /* Nonmatching */ +void J3DIndBlockFull::reset(J3DIndBlock* pBlock) { + mIndTexStageNum = pBlock->getIndTexStageNum(); + for (u32 i = 0; i < 4; i++) + mIndTexOrder[i] = *pBlock->getIndTexOrder(i); + for (u32 i = 0; i < 3; i++) + mIndTexMtx[i] = *pBlock->getIndTexMtx(i); + for (u32 i = 0; i < 4; i++) + mIndTexCoordScale[i] = *pBlock->getIndTexCoordScale(i); } /* 802E947C-802E957C .text reset__16J3DPEBlockFogOffFP10J3DPEBlock */ -void J3DPEBlockFogOff::reset(J3DPEBlock*) { - /* Nonmatching */ +void J3DPEBlockFogOff::reset(J3DPEBlock* pBlock) { + switch (pBlock->getType()) { + case 'PEFL': + case 'PEFG': + mAlphaComp = *pBlock->getAlphaComp(); + mBlend = *pBlock->getBlend(); + mZMode = *pBlock->getZMode(); + mZCompLoc = pBlock->getZCompLoc(); + break; + } } /* 802E957C-802E96C8 .text reset__14J3DPEBlockFullFP10J3DPEBlock */ -void J3DPEBlockFull::reset(J3DPEBlock*) { - /* Nonmatching */ +void J3DPEBlockFull::reset(J3DPEBlock* pBlock) { + if (pBlock->getFog() != NULL) { + memcpy(mFog, pBlock->getFog(), sizeof(*mFog)); + DCStoreRange(mFog, sizeof(*mFog)); + } + + switch (pBlock->getType()) { + case 'PEFL': + case 'PEFG': + mAlphaComp = *pBlock->getAlphaComp(); + mBlend = *pBlock->getBlend(); + mZMode = *pBlock->getZMode(); + mZCompLoc = pBlock->getZCompLoc(); + break; + } } /* 802E96C8-802E9920 .text calc__21J3DTexGenBlockPatchedFPA4_Cf */ -void J3DTexGenBlockPatched::calc(const Mtx) { - /* Nonmatching */ +void J3DTexGenBlockPatched::calc(const Mtx modelMtx) { + if (!((j3dSys.mFlags >> 2) & 0x01) || !j3dSys.checkFlag(J3DSysFlag_SkinNrmCpu)) { + for (s32 i = 0; i < (s32)ARRAY_SIZE(mTexMtx); i++) { + if (mTexMtx[i] == NULL) + continue; + + u32 mode = mTexMtx[i]->getTexMtxInfo().mInfo & 0x7F; + if (mode == J3DTexMtxMode_EnvmapOld || mode == J3DTexMtxMode_Envmap || mode == J3DTexMtxMode_EnvmapBasic) { + Mtx viewMtx; + MTXConcat(j3dSys.getViewMtx(), modelMtx, viewMtx); + viewMtx[0][3] = 0.0f; + viewMtx[1][3] = 0.0f; + viewMtx[2][3] = 0.0f; + mTexMtx[i]->setViewMtx(viewMtx); + } else if (mode == J3DTexMtxMode_Projmap || mode == J3DTexMtxMode_ProjmapBasic) { + mTexMtx[i]->setViewMtx(modelMtx); + } else if (mode == J3DTexMtxMode_ViewProjmap || mode == J3DTexMtxMode_ViewProjmapBasic) { + Mtx viewMtx; + MTXConcat(j3dSys.getViewMtx(), modelMtx, viewMtx); + mTexMtx[i]->setViewMtx(viewMtx); + } else if (mode == J3DTexMtxMode_EnvmapOldEffectMtx || mode == J3DTexMtxMode_EnvmapEffectMtx || mode == J3DTexMtxMode_Unknown5) { + mTexMtx[i]->setViewMtx(modelMtx); + mTexMtx[i]->getViewMtx()[0][3] = 0.0f; + mTexMtx[i]->getViewMtx()[1][3] = 0.0f; + mTexMtx[i]->getViewMtx()[2][3] = 0.0f; + } + + mTexMtx[i]->calc(); + } + } else { + for (s32 i = 0; i < (s32)ARRAY_SIZE(mTexMtx); i++) { + if (mTexMtx[i] == NULL) + continue; + + u32 mode = mTexMtx[i]->getTexMtxInfo().mInfo & 0x7F; + if (mode == J3DTexMtxMode_Envmap || mode == J3DTexMtxMode_EnvmapOld || mode == J3DTexMtxMode_EnvmapBasic) { + Mtx viewMtx; + MTXCopy(j3dSys.getViewMtx(), viewMtx); + viewMtx[0][3] = 0.0f; + viewMtx[1][3] = 0.0f; + viewMtx[2][3] = 0.0f; + mTexMtx[i]->setViewMtx(viewMtx); + } else if (mode == J3DTexMtxMode_Projmap || mode == J3DTexMtxMode_ProjmapBasic) { + mTexMtx[i]->setViewMtx(j3dDefaultMtx); + } else if (mode == J3DTexMtxMode_ViewProjmap || mode == J3DTexMtxMode_ViewProjmapBasic) { + mTexMtx[i]->setViewMtx(j3dSys.getViewMtx()); + } else if (mode == J3DTexMtxMode_EnvmapOldEffectMtx || mode == J3DTexMtxMode_EnvmapEffectMtx || mode == J3DTexMtxMode_Unknown5) { + mTexMtx[i]->setViewMtx(j3dDefaultMtx); + } + + mTexMtx[i]->calc(); + } + } } // BEGIN WEAK FUNCTIONS @@ -1697,7 +1957,6 @@ J3DNBTScale * J3DTexGenBlock4::getNBTScale() { /* 802EB50C-802EB510 .text load__21J3DTexGenBlockPatchedFv */ void J3DTexGenBlockPatched::load() { - /* Nonmatching */ } /* 802EB510-802EB51C .text getType__21J3DTexGenBlockPatchedFv */ diff --git a/src/JSystem/J3DGraphBase/J3DTevs.cpp b/src/JSystem/J3DGraphBase/J3DTevs.cpp index 640000af4..dc5caf6ec 100644 --- a/src/JSystem/J3DGraphBase/J3DTevs.cpp +++ b/src/JSystem/J3DGraphBase/J3DTevs.cpp @@ -9,28 +9,28 @@ #include "JSystem/J3DGraphBase/J3DTransform.h" /* 802EBC94-802EBD48 .text load__11J3DLightObjCFUl */ -void J3DLightObj::load(u32 param_0) const { +void J3DLightObj::load(u32 lightIdx) const { /* Nonmatching */ GDOverflowCheck(0x48); - J3DGDSetLightPos(GXLightID(param_0 * 2), mInfo.mLightPosition.x, mInfo.mLightPosition.y, mInfo.mLightPosition.z); - J3DGDSetLightAttn(GXLightID(param_0 * 2), mInfo.mCosAtten.x, mInfo.mCosAtten.y, mInfo.mCosAtten.z, mInfo.mDistAtten.x, mInfo.mDistAtten.y, mInfo.mDistAtten.z); - J3DGDSetLightColor(GXLightID(param_0 * 2), mInfo.mColor); - J3DGDSetLightDir(GXLightID(param_0 * 2), mInfo.mLightDirection.x, mInfo.mLightDirection.y, mInfo.mLightDirection.z); + J3DGDSetLightPos(GXLightID(1 << lightIdx), mInfo.mLightPosition.x, mInfo.mLightPosition.y, mInfo.mLightPosition.z); + J3DGDSetLightAttn(GXLightID(1 << lightIdx), mInfo.mCosAtten.x, mInfo.mCosAtten.y, mInfo.mCosAtten.z, mInfo.mDistAtten.x, mInfo.mDistAtten.y, mInfo.mDistAtten.z); + J3DGDSetLightColor(GXLightID(1 << lightIdx), mInfo.mColor); + J3DGDSetLightDir(GXLightID(1 << lightIdx), mInfo.mLightDirection.x, mInfo.mLightDirection.y, mInfo.mLightDirection.z); } /* 802EBD48-802EBF40 .text loadTexCoordGens__FUlP11J3DTexCoord */ -void loadTexCoordGens(u32 param_0, J3DTexCoord* param_1) { - GDOverflowCheck(param_0 * 8 + 10); - J3DGDWriteXFCmdHdr(0x1040, param_0); - for (int i = 0; i < param_0; i++) { +void loadTexCoordGens(u32 num, J3DTexCoord* pTexCoord) { + GDOverflowCheck(num * 8 + 10); + J3DGDWriteXFCmdHdr(0x1040, num); + for (int i = 0; i < num; i++) { J3DGDSetTexCoordGen( - GXTexGenType(param_1[i].getTexGenType()), - GXTexGenSrc(param_1[i].getTexGenSrc()) + GXTexGenType(pTexCoord[i].getTexGenType()), + GXTexGenSrc(pTexCoord[i].getTexGenSrc()) ); } static u32 dualReg = 61; - J3DGDWriteXFCmdHdr(0x1050, param_0); - for (int i = 0; i < param_0; i++) { + J3DGDWriteXFCmdHdr(0x1050, num); + for (int i = 0; i < num; i++) { J3DGDWrite_u32(dualReg); } } @@ -51,69 +51,69 @@ void J3DTexMtx::calc() { 0.0f, 0.0f, 1.0f, 0.0f, }; - u32 r28 = mTexMtxInfo.mInfo & 0x7f; - u32 r30 = (mTexMtxInfo.mInfo >> 7) & 1; + u32 mode = mTexMtxInfo.mInfo & 0x7f; + u32 extra = (mTexMtxInfo.mInfo >> 7) & 1; - if (r28 - 8 <= 1 || r28 == 0x0b) { - if (r30 == 0) { + if (mode == J3DTexMtxMode_Projmap || mode == J3DTexMtxMode_ViewProjmap || mode == J3DTexMtxMode_EnvmapEffectMtx) { + if (extra == 0) { J3DGetTextureMtx(mTexMtxInfo.mSRT, mTexMtxInfo.mCenter, mtx2); - } else if (r30 == 1) { + } else if (extra == 1) { J3DGetTextureMtxMaya(mTexMtxInfo.mSRT, mtx2); } MTXConcat(mtx2, qMtx, mtx2); J3DMtxProjConcat(mtx2, mTexMtxInfo.mEffectMtx, mtx1); - MTXConcat(mtx1, field_0x94, mMtx); - } else if (r28 == 7) { - if (r30 == 0) { + MTXConcat(mtx1, mViewMtx, mMtx); + } else if (mode == J3DTexMtxMode_Envmap) { + if (extra == 0) { J3DGetTextureMtx(mTexMtxInfo.mSRT, mTexMtxInfo.mCenter, mtx1); - } else if (r30 == 1) { + } else if (extra == 1) { J3DGetTextureMtxMaya(mTexMtxInfo.mSRT, mtx1); } MTXConcat(mtx1, qMtx, mtx1); - MTXConcat(mtx1, field_0x94, mMtx); - } else if (r28 == 10) { - if (r30 == 0) { + MTXConcat(mtx1, mViewMtx, mMtx); + } else if (mode == J3DTexMtxMode_EnvmapOldEffectMtx) { + if (extra == 0) { J3DGetTextureMtxOld(mTexMtxInfo.mSRT, mTexMtxInfo.mCenter, mtx2); - } else if (r30 == 1) { + } else if (extra == 1) { J3DGetTextureMtxMayaOld(mTexMtxInfo.mSRT, mtx2); } MTXConcat(mtx2, qMtx2, mtx2); J3DMtxProjConcat(mtx2, mTexMtxInfo.mEffectMtx, mtx1); - MTXConcat(mtx1, field_0x94, mMtx); - } else if (r28 == 6) { - if (r30 == 0) { + MTXConcat(mtx1, mViewMtx, mMtx); + } else if (mode == J3DTexMtxMode_EnvmapOld) { + if (extra == 0) { J3DGetTextureMtxOld(mTexMtxInfo.mSRT, mTexMtxInfo.mCenter, mtx1); - } else if (r30 == 1) { + } else if (extra == 1) { J3DGetTextureMtxMayaOld(mTexMtxInfo.mSRT, mtx1); } MTXConcat(mtx1, qMtx2, mtx1); - MTXConcat(mtx1, field_0x94, mMtx); - } else if (r28 == 1) { - if (r30 == 0) { + MTXConcat(mtx1, mViewMtx, mMtx); + } else if (mode == J3DTexMtxMode_EnvmapBasic) { + if (extra == 0) { J3DGetTextureMtxOld(mTexMtxInfo.mSRT, mTexMtxInfo.mCenter, mtx1); - } else if (r30 == 1) { + } else if (extra == 1) { J3DGetTextureMtxMayaOld(mTexMtxInfo.mSRT, mtx1); } - MTXConcat(mtx1, field_0x94, mMtx); - } else if (r28 - 2 <= 1 || r28 == 5) { - if (r30 == 0) { + MTXConcat(mtx1, mViewMtx, mMtx); + } else if (mode == J3DTexMtxMode_ProjmapBasic || mode == J3DTexMtxMode_ViewProjmapBasic || mode == J3DTexMtxMode_Unknown5) { + if (extra == 0) { J3DGetTextureMtxOld(mTexMtxInfo.mSRT, mTexMtxInfo.mCenter, mtx2); - } else if (r30 == 1) { + } else if (extra == 1) { J3DGetTextureMtxMayaOld(mTexMtxInfo.mSRT, mtx2); } J3DMtxProjConcat(mtx2, mTexMtxInfo.mEffectMtx, mtx1); - MTXConcat(mtx1, field_0x94, mMtx); - } else if (r28 == 4) { - if (r30 == 0) { + MTXConcat(mtx1, mViewMtx, mMtx); + } else if (mode == J3DTexMtxMode_Unknown4) { + if (extra == 0) { J3DGetTextureMtxOld(mTexMtxInfo.mSRT, mTexMtxInfo.mCenter, mtx2); - } else if (r30 == 1) { + } else if (extra == 1) { J3DGetTextureMtxMayaOld(mTexMtxInfo.mSRT, mtx2); } J3DMtxProjConcat(mtx2, mTexMtxInfo.mEffectMtx, mMtx); } else { - if (r30 == 0) { + if (extra == 0) { J3DGetTextureMtxOld(mTexMtxInfo.mSRT, mTexMtxInfo.mCenter, mMtx); - } else if (r30 == 1) { + } else if (extra == 1) { J3DGetTextureMtxMayaOld(mTexMtxInfo.mSRT, mMtx); } } @@ -219,16 +219,28 @@ static u8 j3dTexCoordTable[7623]; /* 802EC588-802EC630 .text makeTexCoordTable__Fv */ void makeTexCoordTable() { /* Nonmatching */ - u8 bytes[] = { 0x1e, 0x21, 0x24, 0x27, 0x2a, 0x2d, 0x30, 0x33, 0x36, 0x39, 0x3c }; + u8 texMtx[] = { + GX_TEXMTX0, + GX_TEXMTX1, + GX_TEXMTX2, + GX_TEXMTX3, + GX_TEXMTX4, + GX_TEXMTX5, + GX_TEXMTX6, + GX_TEXMTX7, + GX_TEXMTX8, + GX_TEXMTX9, + GX_IDENTITY, + }; u8* table = j3dTexCoordTable; for (u32 i = 0; i < 11; i++) { for (u32 j = 0; j < 21; j++) { - for (int k = 0; k < 11; k++) { + for (int k = 0; k < ARRAY_SIZE(texMtx); k++) { u32 idx = i * 0xe7 + j * 11 + k; - table[idx * 3] = i; + table[idx * 3 + 0] = i; table[idx * 3 + 1] = j; - table[idx * 3 + 2] = bytes[k]; + table[idx * 3 + 2] = texMtx[k]; } } }