Skip to content

Commit dcbb239

Browse files
committed
More shader work
1 parent 96ef0c7 commit dcbb239

File tree

12 files changed

+302
-77
lines changed

12 files changed

+302
-77
lines changed

base/symbols_resort.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,6 +3034,7 @@ GXGetTevOrder__Q34nw4r3g3d6ResTevCF13_GXTevStageIDP13_GXTexCoordIDP11_GXTexMapID
30343034
GXSetTevOrder__Q34nw4r3g3d6ResTevF13_GXTevStageID13_GXTexCoordID11_GXTexMapID12_GXChannelID=0x8016dec0
30353035
CallDisplayList__Q34nw4r3g3d6ResTevCFb=0x8016dfe0
30363036
CopyTo__Q34nw4r3g3d6ResTevFPv=0x8016e040
3037+
DCStore__Q34nw4r3g3d6ResTevFb=0x8016e0b0
30373038
DCStore__Q34nw4r3g3d14ResMatTevColorFb=0x8016e110
30383039
DCStore__Q34nw4r3g3d20ResMatIndMtxAndScaleFb=0x8016e130
30393040
DCStore__Q34nw4r3g3d17ResMatTexCoordGenFb=0x8016e150
@@ -3050,6 +3051,7 @@ SetEffectMtx__Q34nw4r3g3d9ResTexSrtFUlPCQ34nw4r4math5MTX34=0x8016e610
30503051
GetEffectMtx__Q34nw4r3g3d9ResTexSrtCFUlPQ34nw4r4math5MTX34=0x8016e690
30513052
SetMapMode__Q34nw4r3g3d9ResTexSrtFUlUlii=0x8016e6e0
30523053
GetMapMode__Q34nw4r3g3d9ResTexSrtCFUlPUlPiPi=0x8016e760
3054+
GXSetNumTevStages__Q34nw4r3g3d10ResGenModeFUc=0x8016e800
30533055
CopyTo__Q34nw4r3g3d10ResGenModeCFPv=0x8016e860
30543056
GXGetZCompLoc__Q34nw4r3g3d10ResMatMiscCFv=0x8016e8a0
30553057
SetLightSetIdx__Q34nw4r3g3d10ResMatMiscFi=0x8016e8c0

include/Pack/RPGraphics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <RPGraphics/RPGrpModelBoundingInfo.h>
88
#include <RPGraphics/RPGrpModelG3D.h>
99
#include <RPGraphics/RPGrpModelManager.h>
10+
#include <RPGraphics/RPGrpModelMaterial.h>
1011
#include <RPGraphics/RPGrpModelResManager.h>
1112
#include <RPGraphics/RPGrpRenderer.h>
1213
#include <RPGraphics/RPGrpScreen.h>

include/Pack/RPGraphics/RPGrpModel.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,28 @@
44

55
#include <egg/gfx/eggModelEx.h>
66

7+
class RPGrpModelMaterial;
8+
79
class RPGrpModel {
810
public:
911
EGG::ModelEx* GetModelEx() const {
1012
return mModelEx;
1113
}
1214

15+
RPGrpModelMaterial* GetMaterial(u32 id) const {
16+
return mppMaterials[id];
17+
}
18+
1319
private:
14-
char _00[0x40];
1520
#if defined(PACK_RESORT)
16-
char _40[0x4];
17-
#endif
21+
char _00[0x38];
22+
RPGrpModelMaterial** mppMaterials; // at 0x38
23+
char _3C[0x44 - 0x3C];
24+
EGG::ModelEx* mModelEx; // at 0x44
25+
#else
26+
char _00[0x40];
1827
EGG::ModelEx* mModelEx; // at 0x40
28+
#endif
1929
};
2030

2131
#endif
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef RP_GRAPHICS_MODEL_MATERIAL_H
2+
#define RP_GRAPHICS_MODEL_MATERIAL_H
3+
#include "RPTypes.h"
4+
5+
#include <nw4r/g3d.h>
6+
7+
class RPGrpModelMaterial {
8+
public:
9+
void SetTevKColor(GXTevKColorID id, GXColor color) {
10+
mTevKColors[id] = color;
11+
}
12+
void SetTevColor(GXTevRegID id, GXColorS10 color) {
13+
mTevColors[id - GX_TEVREG0] = color;
14+
}
15+
16+
nw4r::g3d::ScnMdl::CopiedMatAccess& GetCopiedMatAccess() {
17+
return mCopiedMatAccess;
18+
}
19+
20+
private:
21+
char _00[0xC];
22+
GXColor mTevKColors[GX_MAX_KCOLOR]; // at 0xC
23+
GXColorS10 mTevColors[GX_MAX_TEVREG - GX_TEVREG0]; // at 0x1C
24+
char _34[0x80 - 0x34];
25+
nw4r::g3d::ScnMdl::CopiedMatAccess mCopiedMatAccess; // at 0x80
26+
// . . .
27+
};
28+
29+
#endif

include/nw4r/g3d/g3d_draw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ G3DState::IndMtxOp* GetIndMtxOp(ResMat mat, ResNode node, ResShp shp);
2424
} // namespace detail
2525

2626
struct DrawResMdlReplacement {
27+
#if defined(PACK_RESORT)
28+
u32 flag;
29+
#endif
2730
u8* visArray; // at 0x0
2831
ResTexObjData* texObjDataArray; // at 0x4
2932
ResTlutObjData* tlutObjDataArray; // at 0x8

include/nw4r/g3d/g3d_scnmdl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ class ScnMdl : public ScnMdlSimple {
159159
u32 mFlagVisBuffer; // at 0x13C
160160
u32* mpMatBufferDirtyFlag; // at 0x140
161161
DrawResMdlReplacement mReplacement; // at 0x144
162+
#if defined(PACK_RESORT)
163+
u32 mReplacementFlag; // at 0x184
164+
#endif
162165

163166
NW4R_G3D_RTTI_DECL_DERIVED(ScnMdl, ScnMdlSimple);
164167
};

include/nw4r/g3d/res/g3d_restev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class ResTev : public ResCommon<ResTevData> {
7979
void GXSetTevColorIn(GXTevStageID stage, GXTevColorArg a, GXTevColorArg b,
8080
GXTevColorArg c, GXTevColorArg d);
8181

82+
void GXSetTevColorOp(GXTevStageID stage, GXTevOp op, GXTevBias bias,
83+
GXTevScale scale, GXBool clamp, GXTevRegID output);
84+
8285
void CallDisplayList(bool sync) const;
8386

8487
ResTev CopyTo(void* pDst);

lib/libkiwi/core/kiwiColor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ Color Color::ToYuv() const {
1414
return Color(y, u, v, a);
1515
}
1616

17+
/**
18+
* @brief Converts RGB color to GX signed 10-bit format
19+
*/
20+
GXColorS10 Color::ToS10() const {
21+
const GXColorS10 color = {r, g, b, a};
22+
return color;
23+
}
24+
1725
/**
1826
* @brief Creates RGB color from HSV format
1927
*

lib/libkiwi/core/kiwiColor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ class Color : public nw4r::ut::Color {
8383
*/
8484
Color ToYuv() const;
8585

86+
/**
87+
* @brief Converts RGB color to GX signed 10-bit format
88+
*/
89+
GXColorS10 ToS10() const;
90+
8691
/**
8792
* @brief Converts HSV color to RGB format
8893
*
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#include <nw4r/g3d.h>
2+
3+
#include <libkiwi.h>
4+
5+
namespace nw4r {
6+
namespace g3d {
7+
8+
/******************************************************************************
9+
*
10+
* ResTev
11+
*
12+
******************************************************************************/
13+
void ResTev::GXSetTevColorIn(GXTevStageID stage, GXTevColorArg a,
14+
GXTevColorArg b, GXTevColorArg c,
15+
GXTevColorArg d) {
16+
17+
u8* pCmd = ref()
18+
.dl.dl.var[stage / TEV_STAGES_PER_DL]
19+
.dl.tevColorCalc[stage % TEV_STAGES_PER_DL];
20+
21+
// clang-format off
22+
detail::ResWriteBPCmd(pCmd,
23+
(d << GX_BP_TEVCOLORCOMBINER_D_SHIFT) |
24+
(c << GX_BP_TEVCOLORCOMBINER_C_SHIFT) |
25+
(b << GX_BP_TEVCOLORCOMBINER_B_SHIFT) |
26+
(a << GX_BP_TEVCOLORCOMBINER_A_SHIFT) |
27+
((GX_BP_REG_TEVCOLORCOMBINER0 + stage * 2)
28+
<< GX_BP_OPCODE_SHIFT),
29+
30+
~(GX_BP_TEVCOLORCOMBINER_DEST_MASK |
31+
GX_BP_TEVCOLORCOMBINER_SCALE_OR_COMPARE_MODE_MASK |
32+
GX_BP_TEVCOLORCOMBINER_CLAMP_MASK |
33+
GX_BP_TEVCOLORCOMBINER_OP_OR_COMPARISON_MASK |
34+
GX_BP_TEVCOLORCOMBINER_BIAS_MASK));
35+
// clang-format on
36+
}
37+
38+
void ResTev::GXSetTevColorOp(GXTevStageID stage, GXTevOp op, GXTevBias bias,
39+
GXTevScale scale, GXBool clamp,
40+
GXTevRegID output) {
41+
42+
u8* pCmd = ref()
43+
.dl.dl.var[stage / TEV_STAGES_PER_DL]
44+
.dl.tevColorCalc[stage % TEV_STAGES_PER_DL];
45+
46+
// Operation
47+
if (op <= GX_TEV_SUB) {
48+
// clang-format off
49+
detail::ResWriteBPCmd(pCmd,
50+
(bias << GX_BP_TEVCOLORCOMBINER_BIAS_SHIFT) |
51+
((op & 1) << GX_BP_TEVCOLORCOMBINER_OP_OR_COMPARISON_SHIFT) |
52+
(clamp << GX_BP_TEVCOLORCOMBINER_CLAMP_SHIFT) |
53+
(scale << GX_BP_TEVCOLORCOMBINER_SCALE_OR_COMPARE_MODE_SHIFT) |
54+
(output << GX_BP_TEVCOLORCOMBINER_DEST_SHIFT) |
55+
((GX_BP_REG_TEVCOLORCOMBINER0 + stage * 2)
56+
<< GX_BP_OPCODE_SHIFT),
57+
58+
~(GX_BP_TEVCOLORCOMBINER_D_MASK |
59+
GX_BP_TEVCOLORCOMBINER_C_MASK |
60+
GX_BP_TEVCOLORCOMBINER_B_MASK |
61+
GX_BP_TEVCOLORCOMBINER_A_MASK));
62+
// clang-format on
63+
}
64+
// Compare
65+
else {
66+
// clang-format off
67+
detail::ResWriteBPCmd(pCmd,
68+
((op & 1) << GX_BP_TEVCOLORCOMBINER_OP_OR_COMPARISON_SHIFT) |
69+
(GX_MAX_TEVBIAS << GX_BP_TEVCOLORCOMBINER_BIAS_SHIFT) |
70+
(clamp << GX_BP_TEVCOLORCOMBINER_CLAMP_SHIFT) |
71+
((op >> 1 & 3) << GX_BP_TEVCOLORCOMBINER_SCALE_OR_COMPARE_MODE_SHIFT) |
72+
(output << GX_BP_TEVCOLORCOMBINER_DEST_SHIFT) |
73+
((GX_BP_REG_TEVCOLORCOMBINER0 + stage * 2)
74+
<< GX_BP_OPCODE_SHIFT),
75+
76+
// op CONST clamp op output
77+
78+
~(GX_BP_TEVCOLORCOMBINER_D_MASK |
79+
GX_BP_TEVCOLORCOMBINER_C_MASK |
80+
GX_BP_TEVCOLORCOMBINER_B_MASK |
81+
GX_BP_TEVCOLORCOMBINER_A_MASK));
82+
// clang-format on
83+
}
84+
}
85+
86+
/******************************************************************************
87+
*
88+
* CopiedMatAccess
89+
*
90+
******************************************************************************/
91+
ResGenMode ScnMdl::CopiedMatAccess::GetResGenMode(bool markDirty) {
92+
if (mpScnMdl != NULL && mGenMode.IsValid()) {
93+
if (markDirty) {
94+
mpScnMdl->MatBufferDirty(mMatID, ScnMdl::BUFFER_RESGENMODE);
95+
}
96+
97+
return mGenMode;
98+
}
99+
100+
return ResGenMode(NULL);
101+
}
102+
103+
ResMatTevColor ScnMdl::CopiedMatAccess::GetResMatTevColor(bool markDirty) {
104+
if (mpScnMdl != NULL && mTevColor.IsValid()) {
105+
if (markDirty) {
106+
mpScnMdl->MatBufferDirty(mMatID, ScnMdl::BUFFER_RESTEVCOLOR);
107+
}
108+
109+
return mTevColor;
110+
}
111+
112+
return ResMatTevColor(NULL);
113+
}
114+
115+
ResTev ScnMdl::CopiedMatAccess::GetResTev(bool markDirty) {
116+
if (mpScnMdl != NULL && mTev.IsValid()) {
117+
if (markDirty) {
118+
mpScnMdl->MatBufferDirty(mMatID, ScnMdl::BUFFER_RESTEV);
119+
}
120+
121+
return mTev;
122+
}
123+
124+
return ResTev(NULL);
125+
}
126+
127+
} // namespace g3d
128+
} // namespace nw4r

0 commit comments

Comments
 (0)