Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
underwater.c File Reference

Go to the source code of this file.

Functions

void underwater_init (EffectInstance *effect)
 
void underwater_update (EffectInstance *effect)
 
void underwater_render (EffectInstance *effect)
 
void underwater_appendGfx (void *effect)
 
EffectInstanceunderwater_main (s32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, s32 arg5)
 
void func_E00BA618 (void)
 

Variables

Vtx D_09000428_3B9E98 []
 
Gfx D_09000528_3B9F98 []
 
Gfx D_09000570_3B9FE0 []
 

Function Documentation

◆ underwater_init()

void underwater_init ( EffectInstance * effect)

Definition at line 63 of file underwater.c.

63 {
64}

Referenced by underwater_main().

◆ underwater_update()

void underwater_update ( EffectInstance * effect)

Definition at line 66 of file underwater.c.

66 {
67 UnderwaterFXData* data = effect->data.underwater;
68 s32 timeLeft;
69 s32 lifeTime;
70 s32 alpha;
71 f32 factor;
72 s32 i;
73 s32 j;
74
75 if (effect->flags & FX_INSTANCE_FLAG_DISMISS) {
76 effect->flags &= ~FX_INSTANCE_FLAG_DISMISS;
77 data->timeLeft = 32;
78 }
79
80 if (data->timeLeft < 1000) {
81 data->timeLeft--;
82 }
83
84 data->lifeTime++;
85
86 if (data->timeLeft < 0) {
87 remove_effect(effect);
88 return;
89 }
90
91 timeLeft = data->timeLeft;
92 lifeTime = data->lifeTime;
93
94 alpha = 255;
95 if (timeLeft < 32) {
96 alpha = timeLeft * 8;
97 }
98 if (lifeTime < 16) {
99 alpha = lifeTime * 16 + 15;
100 }
101
102 data->waterColor.a = (f32) alpha;
103 factor = (f32) alpha / 255.0f;
104
105 for (i = 1; i < ARRAY_COUNT(data->unk_23) - 1; i++) {
106 data->unk_23[i][6] = sin_deg(-((lifeTime - i) * 20)) * -64.0f * factor;
107 }
108
109 for (i = 1; i < ARRAY_COUNT(data->unk_23) - 1; i++) {
110 for (j = 1; j < ARRAY_COUNT(data->unk_23[0]) - 1; j++) {
111 f32 m11 = data->unk_23[i][j] * 4.0f;
112 f32 m21 = data->unk_23[i + 1][j];
113 f32 m01 = data->unk_23[i - 1][j];
114 f32 m12 = data->unk_23[i][j + 1];
115 f32 m10 = data->unk_23[i][j - 1];
116 f32 m22 = data->unk_23[i + 1][j + 1];
117 f32 m02 = data->unk_23[i - 1][j + 1];
118 f32 m20 = data->unk_23[i + 1][j - 1];
119 f32 m00 = data->unk_23[i - 1][j - 1];
120 f32 temp1 = m21 + m01 + m12 + m10 - m11;
121 f32 temp2 = (m22 + m02 + m20 + m00) * 0.5;
122
123 data->unk_11A[i][j] += temp1 + temp2 - m11 * 0.7;
124 data->unk_11A[i][j] *= 0.98;
125
126 if (timeLeft < 32) {
127 data->unk_23[i][j] *= factor;
128 }
129 }
130 }
131
132 for (i = 1; i < ARRAY_COUNT(data->unk_23) - 1; i++) {
133 for (j = 1; j < ARRAY_COUNT(data->unk_23[0]) - 1; j++) {
134 data->unk_23[i][j] += data->unk_11A[i][j] * 0.02;
135 }
136 }
137}
#define sin_deg
#define remove_effect
s16 unk_11A[19][13]
Definition effects.h:1608
Color_RGBA8 waterColor
Definition effects.h:1605
struct UnderwaterFXData * underwater
Definition effects.h:2557
EffectData data
Definition effects.h:2605
s8 unk_23[19][13]
Definition effects.h:1607
@ FX_INSTANCE_FLAG_DISMISS
Definition enums.h:3517
#define ARRAY_COUNT(arr)
Definition macros.h:40

Referenced by underwater_main().

◆ underwater_render()

void underwater_render ( EffectInstance * effect)

Definition at line 139 of file underwater.c.

139 {
140 RenderTask renderTask;
141 RenderTask* retTask;
142
143 renderTask.appendGfx = underwater_appendGfx;
144 renderTask.appendGfxArg = effect;
145 renderTask.dist = 100;
147
148 retTask = queue_render_task(&renderTask);
149}
#define queue_render_task
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
void * appendGfxArg
void(* appendGfx)(void *)
void underwater_appendGfx(void *effect)
Definition underwater.c:154

Referenced by underwater_main().

◆ underwater_appendGfx()

void underwater_appendGfx ( void * effect)

Definition at line 154 of file underwater.c.

154 {
155 UnderwaterFXData* data = ((EffectInstance*)effect)->data.underwater;
156 s32 alpha = data->waterColor.a;
157 s32 x, y;
158 s32 dxRight, dxLeft, dyTop, dyBottom;
159 s32 edgeX, edgeY;
160 s32 vtxIdx;
161 Matrix4f mtx;
162 Matrix4f unused_matrix;
163 s32 i, j;
164
165 gDPPipeSync(gMainGfxPos++);
166 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(((EffectInstance*)effect)->graphics->data));
167 gDPSetColorImage(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, nuGfxZBuffer);
168 gSPDisplayList(gMainGfxPos++, D_09000528_3B9F98);
169
170 // copy image from framebuffer to zbuffer
171 for (i = 0; i < 40; i++) {
172 gDPLoadTextureTile(
174 G_IM_FMT_RGBA, G_IM_SIZ_16b,
175 SCREEN_WIDTH, 6,
176 0, 0, SCREEN_WIDTH - 1, 5, 0,
177 G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP,
178 G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
179 gSPTextureRectangle(
180 gMainGfxPos++,
181 0 * 4, (i * 6) * 4,
182 (SCREEN_WIDTH - 1) * 4, (i * 6 + 5) * 4,
183 G_TX_RENDERTILE, 0, 0, 0x1000, 0x0400);
184 gDPPipeSync(gMainGfxPos++);
185 }
186
187 gDPSetColorImage(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, nuGfxCfb_ptr);
188 gDPSetPrimColor(gMainGfxPos++, 0, 0, data->waterColor.r, data->waterColor.g, data->waterColor.b, alpha >> 1);
189 gDPSetCycleType(gMainGfxPos++, G_CYC_1CYCLE);
190 gDPSetCombineMode(gMainGfxPos++, PM_CC_48, PM_CC_48);
191 gDPSetTextureImage(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, OS_K0_TO_PHYSICAL(nuGfxZBuffer));
192 gDPSetRenderMode(gMainGfxPos++, CVG_DST_SAVE | ZMODE_OPA | FORCE_BL | G_RM_PASS, CVG_DST_SAVE | ZMODE_OPA | FORCE_BL | GBL_c2(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1));
193 gDPSetTexturePersp(gMainGfxPos++, G_TP_PERSP);
194 gDPSetTextureFilter(gMainGfxPos++, G_TF_BILERP);
195
196 guFrustumF(mtx, -80.0f, 80.0f, 60.0f, -60.0f, 160.0f, 640.0f, 1.0f);
198 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
199 gSPClearGeometryMode(gMainGfxPos++, G_CULL_BOTH | G_LIGHTING);
200 gSPSetGeometryMode(gMainGfxPos++, G_SHADE | G_SHADING_SMOOTH);
201 gSPVertex(gMainGfxPos++, D_09000428_3B9E98, 16, 0);
202
203 for (j = 0; j < 12; j++) {
204 y = j * 16 + 24;
205 edgeY = FALSE;
206
207 if (j == 0) {
208 dyTop = -4;
209 edgeY = TRUE;
210 } else {
211 dyTop = 0;
212 }
213
214 if (j == 11) {
215 dyBottom = 4;
216 edgeY = TRUE;
217 } else {
218 dyBottom = 0;
219 }
220
221 for (i = 0; i < 18; i++) {
222 x = i * 16 + 16;
223 edgeX = FALSE;
224
225 if (i == 0) {
226 dxLeft = -4;
227 edgeX = TRUE;
228 } else {
229 dxLeft = 0;
230 }
231
232 if (i == 17) {
233 dxRight = 4;
234 edgeX = TRUE;
235 } else {
236 dxRight = 0;
237 }
238
239 gDPSetTile(
240 gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b,
241 (((((x + dxRight + 16) - (x + dxLeft)) + 1) * 2) + 7) >> 3, 0x0000,
242 G_TX_LOADTILE, 0,
243 G_TX_NOMIRROR | G_TX_CLAMP, 6, G_TX_NOLOD,
244 G_TX_NOMIRROR | G_TX_CLAMP, 6, G_TX_NOLOD);
245 gDPLoadSync(gMainGfxPos++);
246 gDPLoadTile(gMainGfxPos++, G_TX_LOADTILE,
247 (x + dxLeft) * 4,
248 (y + dyTop) * 4,
249 (x + dxRight + 16) * 4,
250 (y + dyBottom + 16) * 4);
251 gDPPipeSync(gMainGfxPos++);
252 gDPSetTile(
253 gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b,
254 (((((x + dxRight + 16) - (x + dxLeft)) + 1) * 2) + 7) >> 3, 0x0000,
255 G_TX_RENDERTILE, 0,
256 G_TX_NOMIRROR | G_TX_CLAMP, 6, G_TX_NOLOD,
257 G_TX_NOMIRROR | G_TX_CLAMP, 6, G_TX_NOLOD);
258 gDPSetTileSize(gMainGfxPos++, G_TX_RENDERTILE,
259 0, 0, (x + dxRight + 31) * 4, (y + dyBottom + 31) * 4);
260
261 if (edgeX && edgeY) {
262 vtxIdx = 12;
263 } else {
264 vtxIdx = 4;
265 if (!edgeX) {
266 if (!edgeY) {
267 vtxIdx = 0;
268 } else {
269 vtxIdx = 8;
270 }
271 }
272 }
273
274 gSPModifyVertex(gMainGfxPos++, vtxIdx , G_MWO_POINT_XYSCREEN, ((x + dxLeft ) << 0x12) | ((y + dyTop ) * 4 + data->unk_23[i ][j ]));
275 gSPModifyVertex(gMainGfxPos++, vtxIdx + 1, G_MWO_POINT_XYSCREEN, ((x + dxRight + 0x10) << 0x12) | ((y + dyTop ) * 4 + data->unk_23[i + 1][j ]));
276 gSPModifyVertex(gMainGfxPos++, vtxIdx + 2, G_MWO_POINT_XYSCREEN, ((x + dxLeft ) << 0x12) | ((y + dyBottom + 0x10) * 4 + data->unk_23[i ][j + 1]));
277 gSPModifyVertex(gMainGfxPos++, vtxIdx + 3, G_MWO_POINT_XYSCREEN, ((x + dxRight + 0x10) << 0x12) | ((y + dyBottom + 0x10) * 4 + data->unk_23[i + 1][j + 1]));
278 gSP2Triangles(gMainGfxPos++, vtxIdx, vtxIdx + 3, vtxIdx + 1, 0, vtxIdx, vtxIdx + 2, vtxIdx + 3, 0);
279 gDPPipeSync(gMainGfxPos++);
280 }
281 }
282
283 gDPSetColorImage(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, nuGfxZBuffer);
284 gSPDisplayList(gMainGfxPos++, D_09000570_3B9FE0);
285 gDPSetColorImage(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, nuGfxCfb_ptr);
286 gDPPipeSync(gMainGfxPos++);
287 gSPMatrix(gMainGfxPos++, &gDisplayContext->camPerspMatrix[gCurrentCameraID], G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
288 gDPPipeSync(gMainGfxPos++);
289}
u16 * nuGfxCfb_ptr
Definition cam_main.c:14
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define guMtxF2L
#define guFrustumF
u16 * nuGfxZBuffer
Definition main.c:46
#define SCREEN_WIDTH
Definition macros.h:105
#define PM_CC_48
Definition macros.h:476
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
Vtx D_09000428_3B9E98[]
Gfx D_09000570_3B9FE0[]
Gfx D_09000528_3B9F98[]
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
s32 gCurrentCameraID
Definition cam_math.c:4
DisplayContext * gDisplayContext
Definition cam_main.c:16

Referenced by underwater_render().

◆ underwater_main()

EffectInstance * underwater_main ( s32 arg0,
f32 arg1,
f32 arg2,
f32 arg3,
f32 arg4,
s32 arg5 )

Definition at line 14 of file underwater.c.

14 {
16 EffectInstance* effect;
17 UnderwaterFXData* data;
18 s32 numParts = 1;
19 s32 i;
20 s32 j;
21
25 bp.unk_00 = 0;
26 bp.renderUI = NULL;
27 bp.effectID = EFFECT_UNDERWATER;
28
29 effect = create_effect_instance(&bp);
30 effect->numParts = numParts;
31 data = effect->data.underwater = general_heap_malloc(numParts * sizeof(*data));
32 ASSERT(effect->data.underwater != NULL);
33
34 data->unk_00 = arg0;
35 data->lifeTime = 0;
36 if (arg5 <= 0) {
37 data->timeLeft = 1000;
38 } else {
39 data->timeLeft = arg5;
40 }
41 data->waterColor.a = 0;
42 data->unk_04 = arg1;
43 data->unk_08 = arg2;
44 data->unk_0C = arg3;
45 data->unk_18 = arg4;
46 data->waterColor.r = 10;
47 data->waterColor.g = 110;
48 data->waterColor.b = 255;
49 data->unk_20.r = 190;
50 data->unk_20.g = 220;
51 data->unk_20.b = 255;
52
53 for (i = 0; i < ARRAY_COUNT(data->unk_23); i++) {
54 for (j = 0; j < ARRAY_COUNT(data->unk_23[0]); j++) {
55 data->unk_23[i][j] = 0;
56 data->unk_11A[i][j] = 0;
57 }
58 }
59
60 return effect;
61}
#define general_heap_malloc
#define create_effect_instance
Color_RGB8 unk_20
Definition effects.h:1606
#define ASSERT(condition)
void(* renderUI)(EffectInstance *effectInst)
Definition effects.h:2655
void(* init)(EffectInstance *effectInst)
Definition effects.h:2652
void(* update)(EffectInstance *effectInst)
Definition effects.h:2653
void(* renderWorld)(EffectInstance *effectInst)
Definition effects.h:2654
void underwater_update(EffectInstance *effect)
Definition underwater.c:66
void underwater_render(EffectInstance *effect)
Definition underwater.c:139
void underwater_init(EffectInstance *effect)
Definition underwater.c:63

◆ func_E00BA618()

void func_E00BA618 ( void )

Definition at line 151 of file underwater.c.

151 {
152}

Variable Documentation

◆ D_09000428_3B9E98

Vtx D_09000428_3B9E98[]
extern

Referenced by underwater_appendGfx().

◆ D_09000528_3B9F98

Gfx D_09000528_3B9F98[]
extern

Referenced by underwater_appendGfx().

◆ D_09000570_3B9FE0

Gfx D_09000570_3B9FE0[]
extern

Referenced by underwater_appendGfx().