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

Go to the source code of this file.

Functions

void lens_flare_init (EffectInstance *effect)
 
void lens_flare_update (EffectInstance *effect)
 
void lens_flare_render (EffectInstance *effect)
 
void lens_flare_appendGfx (void *effect)
 
void lens_flare_main (s32 type, f32 posX, f32 posY, f32 posZ, s32 duration)
 

Variables

Gfx D_09000240_345420 []
 
Gfx D_090002E0_3454C0 []
 
Gfx * D_E0034780 [] = { D_090002E0_3454C0, D_090002E0_3454C0 }
 
Gfx * D_E0034788 [] = { D_09000240_345420, D_09000240_345420 }
 
u8 D_E0034790 []
 

Function Documentation

◆ lens_flare_init()

void lens_flare_init ( EffectInstance * effect)

Definition at line 65 of file lens_flare.c.

65 {
66}

Referenced by lens_flare_main().

◆ lens_flare_update()

void lens_flare_update ( EffectInstance * effect)

Definition at line 68 of file lens_flare.c.

68 {
69 LensFlareFXData* data = effect->data.lensFlare;
70 s32 time;
71
72 data->timeLeft--;
73 data->lifetime++;
74
75 if (data->timeLeft < 0) {
76 remove_effect(effect);
77 return;
78 }
79
80 time = data->timeLeft;
81
82 if (data->lifetime < 7) {
83 data->largeFlareAlpha += (218 - data->largeFlareAlpha) * 0.5;
84 } else {
85 data->largeFlareAlpha *= 0.78;
86 }
87
89 data->largeFlareScaleVel += 0.29;
90 data->largeFlareRot += data->largeFlareRotVel;
91 data->largeFlareRotVel *= 0.93;
92 data->smallFlareScale = sin_deg(time * 50) * 0.5 + 0.9;
93 data->smallFlareAlpha = sin_deg(time * 40) * 64.0f + 144.0f;
94}
#define sin_deg
#define remove_effect
f32 smallFlareScale
Definition effects.h:394
f32 largeFlareScale
Definition effects.h:392
f32 largeFlareScaleVel
Definition effects.h:393
f32 largeFlareRotVel
Definition effects.h:391
struct LensFlareFXData * lensFlare
Definition effects.h:2490
s32 largeFlareAlpha
Definition effects.h:395
EffectData data
Definition effects.h:2605
s32 smallFlareAlpha
Definition effects.h:396

Referenced by lens_flare_main().

◆ lens_flare_render()

void lens_flare_render ( EffectInstance * effect)

Definition at line 96 of file lens_flare.c.

96 {
97 RenderTask renderTask;
98 RenderTask* retTask;
99
100 renderTask.appendGfx = lens_flare_appendGfx;
101 renderTask.appendGfxArg = effect;
102 renderTask.dist = 20;
104
105 retTask = queue_render_task(&renderTask);
107}
#define queue_render_task
@ RENDER_TASK_FLAG_REFLECT_FLOOR
Definition enums.h:3318
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
void lens_flare_appendGfx(void *effect)
Definition lens_flare.c:109
void * appendGfxArg
void(* appendGfx)(void *)

Referenced by lens_flare_main().

◆ lens_flare_appendGfx()

void lens_flare_appendGfx ( void * effect)

Definition at line 109 of file lens_flare.c.

109 {
110 LensFlareFXData* data = ((EffectInstance*)effect)->data.lensFlare;
111 s32 type = data->type;
112 s32 alpha;
113 s32 idx;
114 Matrix4f mtxTransform;
115 Matrix4f mtxTemp;
116 Matrix4f mtxShared;
117
118 gDPPipeSync(gMainGfxPos++);
119 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(((EffectInstance*)effect)->graphics->data));
120 gSPDisplayList(gMainGfxPos++, D_E0034788[type]);
121
122 guTranslateF(mtxTransform, data->pos.x, data->pos.y, data->pos.z);
123 guRotateF(mtxTemp, -gCameras[gCurrentCameraID].curYaw, 0.0f, 1.0f, 0.0f);
124 guMtxCatF(mtxTemp, mtxTransform, mtxShared);
125
126 alpha = data->smallFlareAlpha;
127 idx = data->lifetime * 3;
128
129 // small twinkling shine which changes color
130 if (type == 0) {
131 guScaleF(mtxTemp, data->smallFlareScale, data->smallFlareScale, data->smallFlareScale);
132 guMtxCatF(mtxTemp, mtxShared, mtxTransform);
134
135 idx %= ARRAY_COUNT(D_E0034790);
136
137 gDPSetPrimColor(gMainGfxPos++, 0, 0, D_E0034790[idx], D_E0034790[idx + 1], D_E0034790[idx + 2], alpha);
138 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
139 gSPDisplayList(gMainGfxPos++, D_E0034780[0]);
140 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
141 }
142
143 alpha = data->largeFlareAlpha;
144 if (alpha > 255) {
145 alpha = 255;
146 }
147
148 // large growing white shine
149 if (alpha > 0) {
150 guScaleF(mtxTemp, data->largeFlareScale, data->largeFlareScale, data->largeFlareScale);
151 guMtxCatF(mtxTemp, mtxShared, mtxTransform);
152 guRotateF(mtxTemp, data->largeFlareRot, 0.0f, 0.0f, 1.0f);
153 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
155
156 gDPSetPrimColor(gMainGfxPos++, 0, 0, D_E0034790[idx], D_E0034790[idx + 1], D_E0034790[idx + 2], alpha);
157 gDPSetPrimColor(gMainGfxPos++, 0, 0, 255, 255, 255, alpha);
158 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
159 gSPDisplayList(gMainGfxPos++, D_E0034780[type]);
160 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
161 }
162
163 gDPPipeSync(gMainGfxPos++);
164}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define guRotateF
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define guScaleF
Gfx * D_E0034780[]
Definition lens_flare.c:7
Gfx * D_E0034788[]
Definition lens_flare.c:8
u8 D_E0034790[]
Definition lens_flare.c:10
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
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

Referenced by lens_flare_render().

◆ lens_flare_main()

void lens_flare_main ( s32 type,
f32 posX,
f32 posY,
f32 posZ,
s32 duration )

Definition at line 26 of file lens_flare.c.

26 {
28 EffectInstance* effect;
29 LensFlareFXData* data;
30 s32 numParts = 1;
31
35 bp.unk_00 = 0;
36 bp.renderUI = NULL;
37 bp.effectID = EFFECT_LENS_FLARE;
38
39 effect = create_effect_instance(&bp);
40 effect->numParts = numParts;
41 data = effect->data.lensFlare = general_heap_malloc(numParts * sizeof(*data));
42 ASSERT(effect->data.lensFlare != NULL);
43
44 data->type = type;
45 data->pos.x = posX;
46 data->pos.y = posY;
47 data->pos.z = posZ;
48 data->timeLeft = duration;
49 data->lifetime = 0;
50
51 data->largeFlareAlpha = 0;
52 data->largeFlareRot = 0;
53 if (type == 0) {
54 data->largeFlareRotVel = 30.0f;
55 } else {
56 data->largeFlareRotVel = 0;
57 }
58 data->largeFlareScale = 0;
59 data->largeFlareScaleVel = 0.8f;
60
61 data->smallFlareAlpha = 0;
62 data->smallFlareScale = 0;
63}
#define general_heap_malloc
#define create_effect_instance
#define ASSERT(condition)
void lens_flare_update(EffectInstance *effect)
Definition lens_flare.c:68
void lens_flare_init(EffectInstance *effect)
Definition lens_flare.c:65
void lens_flare_render(EffectInstance *effect)
Definition lens_flare.c:96
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

Variable Documentation

◆ D_09000240_345420

Gfx D_09000240_345420[]
extern

◆ D_090002E0_3454C0

Gfx D_090002E0_3454C0[]
extern

◆ D_E0034780

Gfx* D_E0034780[] = { D_090002E0_3454C0, D_090002E0_3454C0 }

Definition at line 7 of file lens_flare.c.

Gfx D_090002E0_3454C0[]

Referenced by lens_flare_appendGfx().

◆ D_E0034788

Gfx* D_E0034788[] = { D_09000240_345420, D_09000240_345420 }

Definition at line 8 of file lens_flare.c.

Gfx D_09000240_345420[]

Referenced by lens_flare_appendGfx().

◆ D_E0034790

u8 D_E0034790[]
Initial value:
= {
255, 255, 82,
255, 255, 82,
181, 148, 0,
181, 148, 0,
255, 255, 214,
255, 255, 214,
181, 148, 0,
181, 148, 0
}

Definition at line 10 of file lens_flare.c.

10 {
11 255, 255, 82,
12 255, 255, 82,
13 181, 148, 0,
14 181, 148, 0,
15 255, 255, 214,
16 255, 255, 214,
17 181, 148, 0,
18 181, 148, 0
19};

Referenced by lens_flare_appendGfx().