Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
screen_render_util.c
Go to the documentation of this file.
1#include "common.h"
2#include "nu/nusys.h"
3
4Gfx D_8014ED90[] = {
5 gsSPEndDisplayList(),
6};
7
9 .vp = {
10 .vscale = { 128, 128, 511, 0 },
11 .vtrans = { 128, 128, 511, 0 }
12 }
13};
14
16 {{{ -16,-16, 0 }, 0, { 0x0000, 0x0000 }, { 0, 0, 0, 255 }}},
17 {{{ 16,-16, 0 }, 0, { 0x1000, 0x0000 }, { 0, 0, 0, 255 }}},
18 {{{ 16, 16, 0 }, 0, { 0x1000, 0x1000 }, { 0, 0, 0, 255 }}},
19 {{{ -16, 16, 0 }, 0, { 0x0000, 0x1000 }, { 0, 0, 0, 255 }}},
20};
21
23 gsSPVertex(Vtx_DarknessStencil, 4, 0),
24 gsSP2Triangles(0, 1, 2, 0, 0, 2, 3, 0),
25 gsDPPipeSync(),
26 gsSPEndDisplayList(),
27};
28
29void appendGfx_draw_prev_frame_buffer(s32 x1, s32 y1, s32 x2, s32 y2, f32 alpha) {
30 s32 stripY, extraY;
31 s32 i;
32 u16* prevGfxCfb = NULL;
33
34 // round the x positions
35 x1 = x1 - (x1 % 4);
36 x2 = x2 - (x2 % 4) + 4;
37 // can only load 6 rows of the color buffer at a time: 320*6*2 = 3840 bytes of the 4096 capacity
38 stripY = (y2 - y1) / 6;
39 extraY = (y2 - y1) % 6;
40
41 // get previous color buffer
42 for (i = 0; i < nuGfxCfbNum; i++) {
43 if (nuGfxCfb[i] == nuGfxCfb_ptr) {
44 prevGfxCfb = nuGfxCfb[(i + nuGfxCfbNum - 1) % nuGfxCfbNum];
45 }
46 }
47
48 gDPSetCycleType(gMainGfxPos++, G_CYC_1CYCLE);
49 gDPSetCombineMode(gMainGfxPos++, PM_CC_10, PM_CC_10);
50 gDPSetRenderMode(gMainGfxPos++, G_RM_CLD_SURF, G_RM_CLD_SURF2);
51 gDPSetColorDither(gMainGfxPos++, G_CD_DISABLE);
52 gDPSetAlphaDither(gMainGfxPos++, G_AD_NOISE);
53 gDPSetTextureFilter(gMainGfxPos++, G_TF_POINT);
54 gDPSetTexturePersp(gMainGfxPos++, G_TP_NONE);
55 gSPTexture(gMainGfxPos++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON);
56 gDPSetTextureLUT(gMainGfxPos++, G_TT_NONE);
57 gDPSetTextureDetail(gMainGfxPos++, G_TD_CLAMP);
58 gDPSetTextureLOD(gMainGfxPos++, G_TL_TILE);
59 gDPSetPrimColor(gMainGfxPos++, 0, 0, 255, 255, 255, alpha);
60
61 for (i = 0; i < stripY; i++) {
62 gDPLoadTextureTile(gMainGfxPos++, osVirtualToPhysical(prevGfxCfb), G_IM_FMT_RGBA, G_IM_SIZ_16b, 320, 6,
63 x1, y1 + i * 6, x2 - 1, y1 + i * 6 + 5, 0,
64 G_TX_WRAP, G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
65 gSPTextureRectangle(gMainGfxPos++, x1 * 4, (y1 + i * 6) * 4, x2 * 4, (y1 + i * 6 + 6) * 4,
66 G_TX_RENDERTILE, x1 * 32, (y1 + i * 6) * 32, 1024, 1024);
67 }
68
69 if (extraY != 0) {
70 gDPLoadTextureTile(gMainGfxPos++, osVirtualToPhysical(prevGfxCfb), G_IM_FMT_RGBA, G_IM_SIZ_16b, 320, extraY,
71 x1, y1 + i * 6, x2 - 1, y1 + i * 6 + extraY - 1, 0,
72 G_TX_WRAP, G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
73 gSPTextureRectangle(gMainGfxPos++, x1 * 4, (y1 + i * 6) * 4, x2 * 4, (y1 + i * 6 + extraY) * 4,
74 G_TX_RENDERTILE, x1 * 32, (y1 + i * 6) * 32, 1024, 1024);
75 }
76}
77
78void draw_prev_frame_buffer_at_screen_pos(s32 x1, s32 y1, s32 x2, s32 y2, f32 alpha) {
79 s32 minX;
80 s32 minY;
81 s32 maxX;
82 s32 maxY;
83
84 maxX = x2;
85 maxY = y2;
86 if (maxX < x1) {
87 minX = maxX;
88 maxX = x1;
89 } else {
90 minX = x1;
91 }
92 if (maxY < y1) {
93 minY = maxY;
94 maxY = y1;
95 } else {
96 minY = y1;
97 }
98 if (minX < maxX && minY < maxY) {
99 if (minX < 0) {
100 minX = 0;
101 }
102 if (minY < 0) {
103 minY = 0;
104 }
105 if (maxX < 0) {
106 maxX = 0;
107 }
108 if (maxY < 0) {
109 maxY = 0;
110 }
111 if (minX >= SCREEN_WIDTH) {
112 minX = SCREEN_WIDTH - 1;
113 }
114 if (minY >= SCREEN_HEIGHT) {
115 minY = SCREEN_HEIGHT - 1;
116 }
117 if (maxX >= SCREEN_WIDTH) {
118 maxX = SCREEN_WIDTH - 1;
119 }
120 if (maxY >= SCREEN_HEIGHT) {
121 maxY = SCREEN_HEIGHT - 1;
122 }
123 if (minX != maxX && minY != maxY) {
124 appendGfx_draw_prev_frame_buffer(minX, minY, maxX, maxY, alpha);
125 }
126 }
127}
128
129void appendGfx_darkness_stencil(b32 isWorld, s32 posX, s32 posY, f32 alpha, f32 progress) {
130 Camera* camera = &gCameras[gCurrentCameraID];
131 f32 texScale, f24;
132 s32 i;
133
134 if (alpha == 0.0f) {
135 return;
136 }
137
138 if (!isWorld) {
139 texScale = (255.0f - alpha) * 10.0f / 255.0f + 0.14;
140 } else {
141 texScale = 0.5f;
142 texScale = (255.0f - alpha) * 9.5f / 255.0f + texScale;
143 posX += (camera->viewportW / 2 - posX) * (255.0f - alpha) / 255.0f;
144 posY += (camera->viewportH / 2 - posY) * (255.0f - alpha) / 255.0f;
145 }
146
147 guOrtho(&gDisplayContext->matrixStack[gMatrixListPos], -16.0f, 0.0f, 0.0f, 16.0f, -1000.0f, 1000.0f, 1.0f);
148 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
149 gDPSetAlphaDither(gMainGfxPos++, G_AD_PATTERN);
150 gDPSetTextureFilter(gMainGfxPos++, G_TF_POINT);
151 gDPSetTexturePersp(gMainGfxPos++, G_TP_PERSP);
152 gDPSetColorImage(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_32b, 64, osVirtualToPhysical(nuGfxZBuffer));
153 gDPSetScissor(gMainGfxPos++, G_SC_NON_INTERLACE, 0, 0, 64, 64);
154 gSPViewport(gMainGfxPos++, &DarknessStencilViewport);
155 gDPSetCombineMode(gMainGfxPos++, PM_CC_CONST_1, PM_CC_CONST_1);
156 guRotate(&gDisplayContext->matrixStack[gMatrixListPos], 0.0f, 0.0f, 0.0f, 1.0f);
157 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
158 gSPDisplayList(gMainGfxPos++, Gfx_DarknessStencilQuad);
159 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
160 gDPPipeSync(gMainGfxPos++);
161 gDPSetCombineMode(gMainGfxPos++, PM_CC_56, PM_CC_56);
162
163 for (i = 0; i < 2; i++) {
164 f32 f20;
165 f32 f2;
166 s32 s0 = 255;
167
168 if (i == 0) {
169 f20 = 0.9 - sin_deg(gGameStatusPtr->frameCounter) * 0.05;
170 } else {
171 f20 = 0.9 - sin_deg(gGameStatusPtr->frameCounter * 2 + i * 40) * 0.07;
172 }
173 f2 = 0;
174 if (s0 > 255) {
175 s0 = 255;
176 }
177
178 gDPSetPrimColor(gMainGfxPos++, 0, 0, 255, 255, 255, s0);
179 guRotate(&gDisplayContext->matrixStack[gMatrixListPos], i * 70 + f2, 0.0f, 0.0f, 1.0f);
180 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
181 guScale(&gDisplayContext->matrixStack[gMatrixListPos], f20, f20, 1.0f);
182 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW);
183 gSPDisplayList(gMainGfxPos++, Gfx_DarknessStencilQuad);
184 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
185 }
186
187 gDPPipeSync(gMainGfxPos++);
188 gDPSetTexturePersp(gMainGfxPos++, G_TP_NONE);
189 gDPSetColorImage(gMainGfxPos++, G_IM_FMT_I, G_IM_SIZ_8b, 64, osVirtualToPhysical(nuGfxZBuffer));
190 gDPSetScissor(gMainGfxPos++, G_SC_NON_INTERLACE, 0, 0, 64, 64);
191 gDPSetCombineMode(gMainGfxPos++, PM_CC_0F, PM_CC_0F);
192
193 for (i = 0; i < 4; i++) {
194 gDPLoadTextureTile(gMainGfxPos++, osVirtualToPhysical(&nuGfxZBuffer[i * 2048]), G_IM_FMT_RGBA, G_IM_SIZ_32b, 64, 16, 0, 0, 63, 15, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
195 gDPPipeSync(gMainGfxPos++);
196 gSPTextureRectangle(gMainGfxPos++, 0, (i * 16) * 4, 64 * 4, (i * 16 + 16) * 4, G_TX_RENDERTILE, 0, 0, 0x400, 0x400);
197 gDPPipeSync(gMainGfxPos++);
198 }
199
200 gDPLoadTextureTile(gMainGfxPos++, osVirtualToPhysical(nuGfxZBuffer), G_IM_FMT_I, G_IM_SIZ_8b, 64, 64, 0, 0, 63, 63,
201 0, G_TX_MIRROR | G_TX_CLAMP, G_TX_MIRROR | G_TX_CLAMP, 6, 6, 15, 15);
202 gDPSetTileSize(gMainGfxPos++, G_TX_RENDERTILE, 0, 0, 0x01FC, 0x01FC);
203 gDPPipeSync(gMainGfxPos++);
204
205 gDPSetCycleType(gMainGfxPos++, G_CYC_FILL);
206 gDPSetRenderMode(gMainGfxPos++, G_RM_NOOP, G_RM_NOOP2);
207 gDPSetColorImage(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_32b, 64, osVirtualToPhysical(nuGfxZBuffer));
208 gDPSetFillColor(gMainGfxPos++, GPACK_ZDZ(G_MAXFBZ, 0)<<16 | GPACK_ZDZ(G_MAXFBZ, 0));
209 gDPFillRectangle(gMainGfxPos++, 0, 0, 63, 63);
210 gDPPipeSync(gMainGfxPos++);
211
212 gDPSetColorImage(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, osVirtualToPhysical(nuGfxCfb_ptr));
213 gDPSetScissor(gMainGfxPos++, G_SC_NON_INTERLACE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
214 gDPSetCycleType(gMainGfxPos++, G_CYC_1CYCLE);
215 gDPSetColorDither(gMainGfxPos++, G_CD_MAGICSQ);
216 gDPSetAlphaDither(gMainGfxPos++, G_AD_PATTERN);
217 gDPSetTextureFilter(gMainGfxPos++, G_TF_AVERAGE);
218 gDPSetRenderMode(gMainGfxPos++, G_RM_CLD_SURF, G_RM_CLD_SURF2);
219
220 if (alpha != 255.0f || isWorld == 1) {
221 gDPSetCombineMode(gMainGfxPos++, PM_CC_57, PM_CC_57);
222 } else {
223 gDPSetCombineMode(gMainGfxPos++, PM_CC_58, PM_CC_58);
224 }
225 alpha *= 0.5f;
226 gDPSetPrimColor(gMainGfxPos++, 0, 0, 0, 0, 0, alpha * 0.5f * progress / 255.0f);
227 gDPSetEnvColor(gMainGfxPos++, 255, 255, 255, (255.0f - alpha * 0.5f) * progress / 255.0f);
228
229 if (!isWorld) {
230 gSPTextureRectangle(gMainGfxPos++,
231 camera->viewportStartX * 4, camera->viewportStartY * 4,
232 (camera->viewportStartX + camera->viewportW) * 4, (camera->viewportStartY + camera->viewportH) * 4,
233 G_TX_RENDERTILE,
234 (12 - posX) * 32.0f / texScale + 16.0f + 1024.0f, (19 - posY) * 32.0f / texScale + 16.0f + 1024.0f,
235 1024.0f / texScale, 1024.0f / texScale);
236 } else {
237 gSPTextureRectangle(gMainGfxPos++,
238 camera->viewportStartX * 4, camera->viewportStartY * 4,
239 (camera->viewportStartX + camera->viewportW) * 4, (camera->viewportStartY + camera->viewportH) * 4,
240 G_TX_RENDERTILE,
241 (9 - posX) * 32.0f / texScale + 1024.0f, (32 - posY) * 32.0f / texScale + 1024.0f,
242 1024.0f / texScale, 1024.0f / texScale);
243 }
244}
245
246void appendGfx_screen_transition_stencil(s32 arg0, s32 arg1, f32 progress, s32 primR, s32 primG, s32 primB, s32 primA, s32 camID) {
247 s32 x1, y1, x2, y2, t5, t6;
248 f32 texScale;
249
250 if (camID >= 0) {
251 x1 = gCameras[camID].viewportStartX;
252 y1 = gCameras[camID].viewportStartY;
253 x2 = gCameras[camID].viewportStartX + gCameras[camID].viewportW;
254 y2 = gCameras[camID].viewportStartY + gCameras[camID].viewportH;
255 t5 = x1;
256 t6 = y1;
257 } else {
258 x1 = 0;
259 y1 = 0;
260 x2 = SCREEN_WIDTH;
261 y2 = SCREEN_HEIGHT;
262 t5 = 0;
263 t6 = 0;
264 }
265
266 if (progress == 0.0f) {
267 return;
268 }
269
270 gDPSetScissor(gMainGfxPos++, G_SC_NON_INTERLACE, x1, y1, x2, y2);
271 if (progress == 255.0f) {
273 }
274 gDPSetPrimColor(gMainGfxPos++, 0, 0, primR, primG, primB, primA);
275 texScale = (255.0f - progress) * 10.5f / 255.0f + 0.09; // range from
276 gSPTextureRectangle(gMainGfxPos++, x1 * 4, y1 * 4, x2 * 4, y2 * 4, G_TX_RENDERTILE,
277 (t5 - arg0) * 32.0f / texScale + 16.0f + 1024.0f, (t6 - arg1) * 32.0f / texScale + 16.0f + 1024.0f,
278 1024.0f / texScale, 1024.0f / texScale);
279 gDPPipeSync(gMainGfxPos++);
280}
u16 * nuGfxCfb_ptr
Definition cam_main.c:14
Mtx matrixStack[0x200]
s32 b32
#define sin_deg
#define draw_prev_frame_buffer_at_screen_pos
u16 * nuGfxZBuffer
Definition main.c:46
u16 ** nuGfxCfb
Definition main_loop.c:13
Vtx Vtx_DarknessStencil[]
Gfx Gfx_DarknessStencilQuad[]
void appendGfx_screen_transition_stencil(s32 arg0, s32 arg1, f32 progress, s32 primR, s32 primG, s32 primB, s32 primA, s32 camID)
void appendGfx_draw_prev_frame_buffer(s32 x1, s32 y1, s32 x2, s32 y2, f32 alpha)
void appendGfx_darkness_stencil(b32 isWorld, s32 posX, s32 posY, f32 alpha, f32 progress)
Gfx D_8014ED90[]
Vp DarknessStencilViewport
#define PM_CC_CONST_1
Definition macros.h:511
#define PM_CC_PRIM_FULL_ALPHA
Definition macros.h:283
#define SCREEN_WIDTH
Definition macros.h:105
#define SCREEN_HEIGHT
Definition macros.h:106
#define PM_CC_10
Definition macros.h:293
#define PM_CC_58
Definition macros.h:497
#define PM_CC_0F
Definition macros.h:292
#define PM_CC_57
Definition macros.h:496
#define PM_CC_56
Definition macros.h:495
s16 viewportStartX
s16 viewportStartY
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Camera gCameras[4]
Definition cam_main.c:17
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