-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEffectCoolCube.c
536 lines (430 loc) · 18.4 KB
/
EffectCoolCube.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
// Nordlicht demoparty
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <math.h>
#include "Tools.h"
#include <vshader_normalmapping_shbin.h>
#include <vshader_skybox_shbin.h>
#include "ModelCoolCube.h"
#include "stars_red_bin.h"
#include "stars_bin.h"
#include "tex_spacestation_color_bin.h"
#include "tex_spacestation_normals_bin.h"
#include "Font.h"
#include "MonoFont.h"
extern Font OL16;
#define SCROLLERTEXT " SVatG SVatG SVatG SVatG SVatG SVatG SVatG "
// k2
// TiTAN
// SunSpire
// Nuance
// cncd
// logicoma
// mercury
// spacepigs
// jvb
// dotUser
// Shader / textures
static C3D_AttrInfo* attrInfo;
static DVLB_s* vshader_dvlb;
static DVLB_s* vshader_skybox_dvlb;
static shaderProgram_s shaderProgram;
static shaderProgram_s shaderProgramSkybox;
static int uLocProjection;
static int uLocModelview;
static int uLocProjectionSkybox;
static int uLocModelviewSkybox;
static C3D_Tex skybox_tex;
static C3D_TexCube skybox_cube;
int skyboxVertCount;
int cometsStart;
int cometsVertCount;
#define TAIL_LEN 100
static Pixel* cubeColPixels;
static Bitmap cubeCol;
static C3D_Tex cubeColTex;
static Pixel* cubeNormPixels;
static Bitmap cubeNorm;
static C3D_Tex cubeNormTex;
static Pixel* cubeColAddPixels;
static Bitmap cubeColAdd;
static C3D_Tex cubeColAddTex;
// Lighting
static C3D_LightEnv lightEnv;
static C3D_Light light[3];
static C3D_LightLut lutShittyFresnel;
static C3D_LightLut lutPhong;
int initial = 1;
static const C3D_Material lightMaterial = {
{ 0.1f, 0.0f, 0.0f }, //ambient
{ 1.0f, 1.0f, 1.0f }, //diffuse
{ 0.4f, 0.4f, 0.4f }, //specular0
{ 0.0f, 0.0f, 0.0f }, //specular1
{ 0.0f, 0.0f, 0.0f }, //emission
};
// VBOs
#define VBO_SIZE 25000
static vertex2* vbo;
static C3D_BufInfo* bufInfo;
// Sync
const struct sync_track* sync_zoom;
const struct sync_track* sync_rotate;
const struct sync_track* sync_comets;
const struct sync_track* sync_scroll;
void effectCoolCubeInit() {
// initialize everything here
sync_zoom = sync_get_track(rocket, "cube.zoom");
sync_rotate = sync_get_track(rocket, "cube.rotate");
sync_comets = sync_get_track(rocket, "cube.comets");
sync_scroll = sync_get_track(rocket, "cube.scroller");
// Set up shaders and get uniform locations
vshader_skybox_dvlb = DVLB_ParseFile((u32*)vshader_skybox_shbin, vshader_skybox_shbin_size);
vshader_dvlb = DVLB_ParseFile((u32*)vshader_normalmapping_shbin, vshader_normalmapping_shbin_size);
shaderProgramInit(&shaderProgram);
shaderProgramSetVsh(&shaderProgram, &vshader_dvlb->DVLE[0]);
C3D_BindProgram(&shaderProgram);
uLocProjection = shaderInstanceGetUniformLocation(shaderProgram.vertexShader, "projection");
uLocModelview = shaderInstanceGetUniformLocation(shaderProgram.vertexShader, "modelView");
shaderProgramInit(&shaderProgramSkybox);
shaderProgramSetVsh(&shaderProgramSkybox, &vshader_skybox_dvlb->DVLE[0]);
C3D_BindProgram(&shaderProgramSkybox);
uLocProjectionSkybox = shaderInstanceGetUniformLocation(shaderProgramSkybox.vertexShader, "projection");
uLocModelviewSkybox = shaderInstanceGetUniformLocation(shaderProgramSkybox.vertexShader, "modelView");
// Allocate VBOs
vbo = (vertex2*)linearAlloc(sizeof(vertex2) * VBO_SIZE);
bufInfo = C3D_GetBufInfo();
BufInfo_Init(bufInfo);
BufInfo_Add(bufInfo, (void*)vbo, sizeof(vertex2), 4, 0x3210);
// Load statics
loadObject2(numFacesCoolCube, facesCoolCube, verticesCoolCube, normalsCoolCube, texcoordsCoolCube, &vbo[0]);
for(int i = 0; i < numFacesCoolCube * 3; i++) {
vbo[i].texcoord[1] *= 2.0;
}
skyboxVertCount = buildCube2(&vbo[(numFacesCoolCube) * 3], vec3(0, 0, 0), 29500.0, 0.0, 0.0);
cometsStart = (numFacesCoolCube) * 3 + skyboxVertCount;
// Load texture for the skybox
loadTex3DSMem(&skybox_tex, &skybox_cube, stars_red_bin, stars_red_bin_size);
C3D_TexSetFilter(&skybox_tex, GPU_LINEAR, GPU_LINEAR);
C3D_TexSetWrap(&skybox_tex, GPU_CLAMP_TO_EDGE, GPU_CLAMP_TO_EDGE);
// Cool Cube textures
cubeColPixels = (Pixel*)linearAlloc(512 * 256 * sizeof(Pixel));
InitialiseBitmap(&cubeCol, 512, 256, BytesPerRowForWidth(512), cubeColPixels);
C3D_TexInitVRAM(&cubeColTex, 512, 256, GPU_RGBA8);
C3D_TexSetFilter(&cubeColTex, GPU_LINEAR, GPU_NEAREST);
C3D_TexSetWrap(&cubeColTex, GPU_REPEAT, GPU_REPEAT);
cubeNormPixels = (Pixel*)linearAlloc(512 * 256 * sizeof(Pixel));
InitialiseBitmap(&cubeNorm, 512, 256, BytesPerRowForWidth(512), cubeNormPixels);
C3D_TexInitVRAM(&cubeNormTex, 512, 256, GPU_RGBA8);
C3D_TexSetFilter(&cubeNormTex, GPU_LINEAR, GPU_NEAREST);
C3D_TexSetWrap(&cubeNormTex, GPU_REPEAT, GPU_REPEAT);
cubeColAddPixels = (Pixel*)linearAlloc(512 * 256 * sizeof(Pixel));
InitialiseBitmap(&cubeColAdd, 512, 256, BytesPerRowForWidth(512), cubeColAddPixels);
C3D_TexInitVRAM(&cubeColAddTex, 512, 256, GPU_RGBA8);
C3D_TexSetFilter(&cubeColAddTex, GPU_LINEAR, GPU_NEAREST);
C3D_TexSetWrap(&cubeColAddTex, GPU_REPEAT, GPU_REPEAT);
initial = 1;
}
vec3_t sph_sinusoid(float a, float k, float n, float t) {
float cosnt = cos(n * t);
float norm = sqrt(1.0 + k * 2 + cosnt * cosnt);
float x = a * cos(t) / norm;
float y = a * sin(t) / norm;
float z = a * k * cosnt / norm;
return vec3(x, y, z);
}
void effectCoolCubeUpdate(float row) {
float sync_scroll_val = sync_get_val(sync_scroll, row);
// Render some 2D stuff
if(initial == 1) {
FillBitmap(&cubeCol, RGBAf(0.8, 0.8, 0.8, 1.0));
}
for(int i = 0; i < 19; i++) {
DrawHorizontalLine(&cubeCol, 0, i, 512, RGBAf(0.1, 0.1, 0.1, 0.3));
}
DrawSimpleString(&cubeCol, &OL16, sync_scroll_val, 1, RGBAf(1.0, 0.1, 0.2, 1.0), SCROLLERTEXT);
if(initial == 1) {
GSPGPU_FlushDataCache(cubeColPixels, 512 * 256 * sizeof(Pixel));
GX_DisplayTransfer((u32*)cubeColPixels, GX_BUFFER_DIM(512, 256), (u32*)cubeColTex.data, GX_BUFFER_DIM(512, 256), TEXTURE_TRANSFER_FLAGS);
}
else {
GSPGPU_FlushDataCache(cubeColPixels, 512 * 19 * sizeof(Pixel));
GX_DisplayTransfer((u32*)cubeColPixels, GX_BUFFER_DIM(512, 19), (u32*)cubeColTex.data, GX_BUFFER_DIM(512, 19), TEXTURE_TRANSFER_FLAGS);
}
gspWaitForPPF();
if(initial == 1) {
FillBitmap(&cubeColAdd, RGBAf(0.0, 0.0, 0.0, 0.0));
}
for(int i = 0; i < 19; i++) {
DrawHorizontalLine(&cubeColAdd, 0, i, 512, RGBAf(0.0, 0.0, 0.0, 0.0));
}
DrawSimpleString(&cubeColAdd, &OL16, sync_scroll_val, 1, RGBAf(1.0, 0.1, 0.2, 1.0), SCROLLERTEXT);
if(initial == 1) {
GSPGPU_FlushDataCache(cubeColAddPixels, 512 * 256 * sizeof(Pixel));
GX_DisplayTransfer((u32*)cubeColAddPixels, GX_BUFFER_DIM(512, 256), (u32*)cubeColAddTex.data, GX_BUFFER_DIM(512, 256), TEXTURE_TRANSFER_FLAGS);
}
else {
GSPGPU_FlushDataCache(cubeColAddPixels, 512 * 19 * sizeof(Pixel));
GX_DisplayTransfer((u32*)cubeColAddPixels, GX_BUFFER_DIM(512, 19), (u32*)cubeColAddTex.data, GX_BUFFER_DIM(512, 19), TEXTURE_TRANSFER_FLAGS);
}
gspWaitForPPF();
if(initial == 1) {
FillBitmap(&cubeNorm, RGBAf(0.5, 0.5, 1.0, 1.0));
}
DrawSimpleString(&cubeNorm, &OL16, sync_scroll_val + 1, 2, RGBAf(0.75, 0.45, 0.95, 1.0), SCROLLERTEXT);
DrawSimpleString(&cubeNorm, &OL16, sync_scroll_val - 1, 0, RGBAf(0.45, 0.75, 0.95, 1.0), SCROLLERTEXT);
DrawSimpleString(&cubeNorm, &OL16, sync_scroll_val, 1, RGBAf(0.5, 0.5, 1.0, 1.0), SCROLLERTEXT);
// TODO put an actual normal map here
if(initial == 1) {
for(int i = 32; i < 200; i += 64) {
for(int j = 0; j < 8; j++) {
DrawHorizontalLine(&cubeNorm, 0, i+j, 512, RGBAf(0.1, 0.1, 0.2, 1.0));
}
for(int j = 8; j < 16; j++) {
DrawHorizontalLine(&cubeNorm, 0, i+j, 512, RGBAf(0.5, 0.5, 1.0, 1.0));
}
}
}
if(initial == 1) {
GSPGPU_FlushDataCache(cubeNormPixels, 512 * 256 * sizeof(Pixel));
GX_DisplayTransfer((u32*)cubeNormPixels, GX_BUFFER_DIM(512, 256), (u32*)cubeNormTex.data, GX_BUFFER_DIM(512, 256), TEXTURE_TRANSFER_FLAGS);
}
else {
GSPGPU_FlushDataCache(cubeNormPixels, 512 * 19 * sizeof(Pixel));
GX_DisplayTransfer((u32*)cubeNormPixels, GX_BUFFER_DIM(512, 19), (u32*)cubeNormTex.data, GX_BUFFER_DIM(512, 19), TEXTURE_TRANSFER_FLAGS);
}
gspWaitForPPF();
initial = 0;
float sync_comets_val = sync_get_val(sync_comets, row);
cometsVertCount = 0;
for(int i = 0; i < 3; i++) {
for(int j = 0; j < TAIL_LEN; j++) {
float j_scale = 0.01;
float t = (i / 3.0) * 2.0 * 3.14152 + sync_comets_val + j_scale * j;
float jr = (float)(TAIL_LEN - j) / TAIL_LEN;
double size = -2.775558e-16 + 10.53333*jr - 35.06667*jr*jr + 39.46667*jr*jr*jr- 14.93333*jr*jr*jr*jr;
t = ((int)(t / j_scale)) * j_scale;
float rad = 11.0 + 0.5 * sin(t + 5.0 * i);
/*float x = sin(t) + 2.0 * sin(2.0 * t); // TODO
float y = cos(t) - 2.0 * cos(2.0 * t);
float z = -sin(3.0 * t);*/
vec3_t pos = sph_sinusoid(rad, 2 + i, 5, t);
if(i == 0) {
float temp = pos.x;
pos.x = pos.z;
pos.z = temp;
}
if(i == 1) {
float temp = pos.z;
pos.z = pos.y;
pos.y = temp;
}
// float st = t / j_scale;
// srand(st - fmod(st, j_scale));
srand(t / j_scale);
pos.x += (((rand() % 128) / 128.0) - 0.5) * 0.3;
pos.y += (((rand() % 128) / 128.0) - 0.5) * 0.3;
pos.z += (((rand() % 128) / 128.0) - 0.5) * 0.3;
cometsVertCount += buildCube2(&vbo[cometsStart + cometsVertCount], pos, 0.4 * size , 0.0, 0.0);
}
}
}
void effectCoolCubeDraw(float iod, float row) {
resetShadeEnv();
float sync_zoom_val = sync_get_val(sync_zoom, row);
float sync_rotate_val = sync_get_val(sync_rotate, row);
float sync_comets_val = sync_get_val(sync_comets, row);
// Projection matrix
C3D_Mtx projection;
Mtx_PerspStereoTilt(&projection, (45.0f) * M_PI / 180.0f, 400.0f / 240.0f, 0.2f, 70000.0f, iod, 2.0f, false);
// Modelview matrix
C3D_Mtx modelview;
Mtx_Identity(&modelview);
Mtx_Translate(&modelview, 0.0, 0.0, sync_zoom_val, true);
Mtx_RotateY(&modelview, sync_rotate_val, true);
Mtx_RotateZ(&modelview, sync_rotate_val * 0.1, true);
Mtx_RotateX(&modelview, 0.3 * sin(0.3 * sync_rotate_val), true);
C3D_Mtx modelviewSky = modelview;
Mtx_RotateY(&modelviewSky, 3.0, true);
// Skybox shader
C3D_BindProgram(&shaderProgramSkybox);
// GPU state for additive blend
C3D_DepthTest(false, GPU_GEQUAL, GPU_WRITE_COLOR);
C3D_AlphaBlend(GPU_BLEND_ADD, GPU_BLEND_ADD, GPU_ONE, GPU_ONE, GPU_ONE, GPU_ONE);
// Uniforms to shader
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLocProjectionSkybox, &projection);
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLocModelviewSkybox, &modelviewSky);
// Passthrough texenv and empty lightenv
C3D_LightEnvInit(&lightEnv);
C3D_LightEnvBind(&lightEnv);
C3D_TexEnv* env = C3D_GetTexEnv(0);
C3D_TexEnvInit(env);
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, 0, 0);
C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE);
// Lets draw a skybox
C3D_TexBind(0, &skybox_tex);
C3D_CullFace(GPU_CULL_FRONT_CCW);
C3D_DrawArrays(GPU_TRIANGLES, (numFacesCoolCube) * 3, skyboxVertCount);
// Normal drawing shader
C3D_BindProgram(&shaderProgram);
C3D_TexBind(0, &cubeColTex);
C3D_TexBind(1, &cubeNormTex);
// Drawing with texture, 2 lights, normal map
C3D_LightEnvInit(&lightEnv);
C3D_LightEnvBind(&lightEnv);
LightLut_Phong(&lutPhong, 100.0);
C3D_LightEnvLut(&lightEnv, GPU_LUT_D0, GPU_LUTINPUT_LN, false, &lutPhong);
LightLut_FromFunc(&lutShittyFresnel, badFresnel, 1.9, false);
C3D_LightEnvLut(&lightEnv, GPU_LUT_FR, GPU_LUTINPUT_NV, false, &lutShittyFresnel);
C3D_LightEnvFresnel(&lightEnv, GPU_PRI_SEC_ALPHA_FRESNEL);
C3D_LightLutDA daLut;
LightLutDA_Quadratic(&daLut, 1.0, 10.0, 0.01, 0.01);
for(int i = 0; i < 3; i++) {
float lightscale = 1.0;
float j_scale = 0.01;
float t = (i / 3.0) * 2.0 * 3.14152 + sync_comets_val + j_scale * 10;
float jr = (float)(TAIL_LEN - 10) / TAIL_LEN;
double size = -2.775558e-16 + 10.53333*jr - 35.06667*jr*jr + 39.46667*jr*jr*jr- 14.93333*jr*jr*jr*jr;
t = ((int)(t / j_scale)) * j_scale;
float rad = 11.0 + 0.5 * sin(t + 5.0 * i);
vec3_t pos = sph_sinusoid(rad, 2 + i, 5, t);
if(i == 0) {
float temp = pos.x;
pos.x = pos.z;
pos.z = temp;
}
if(i == 1) {
float temp = pos.z;
pos.z = pos.y;
pos.y = temp;
}
// TODO cooler function
// float t = (i / 3.0) * 2.0 * 3.14152 + sync_comets_val;
// float x = sin(t) + 2.0 * sin(2.0 * t);
// float y = cos(t) - 2.0 * cos(2.0 * t);
// float z = -sin(3.0 * t);
float r = i == 0 ? 1.0 : 0.7;
float g = i == 1 ? 1.0 : 0.7;
float b = i == 2 ? 1.0 : 0.7;
r = g = b = 1.0; // This looks better TODO
r *= lightscale;
g *= lightscale;
b *= lightscale;
C3D_FVec lightVec = FVec4_New(pos.x, pos.y, pos.z, 1.0);
C3D_LightInit(&light[i], &lightEnv);
C3D_LightDistAttnEnable(&light[i], true);
C3D_LightDistAttn(&light[i], &daLut);
C3D_LightColor(&light[i], r, g, b);
C3D_LightPosition(&light[i], &lightVec);
}
env = C3D_GetTexEnv(0);
C3D_TexEnvInit(env);
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_FRAGMENT_PRIMARY_COLOR, 0);
C3D_TexEnvFunc(env, C3D_RGB, GPU_MODULATE);
env = C3D_GetTexEnv(1);
C3D_TexEnvInit(env);
C3D_TexEnvSrc(env, C3D_Both, GPU_PREVIOUS, GPU_FRAGMENT_SECONDARY_COLOR, 0);
C3D_TexEnvFunc(env, C3D_RGB, GPU_ADD);
C3D_LightEnvBumpMode(&lightEnv, GPU_BUMP_AS_BUMP);
C3D_LightEnvBumpSel(&lightEnv, 1);
// GPU state for normal drawing
C3D_DepthTest(true, GPU_GEQUAL, GPU_WRITE_ALL);
C3D_AlphaBlend(GPU_BLEND_ADD, GPU_BLEND_ADD, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA);
// Uniforms to shader
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLocProjection, &projection);
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLocModelview, &modelview);
// Lets draw a cool cube
C3D_CullFace(GPU_CULL_NONE);
C3D_LightEnvMaterial(&lightEnv, &lightMaterial);
C3D_DrawArrays(GPU_TRIANGLES, 0, numFacesCoolCube * 3);
// Bumpmapping off
C3D_LightEnvBumpSel(&lightEnv, 0);
C3D_LightEnvBumpMode(&lightEnv, GPU_BUMP_NOT_USED);
// "Just shading" texenv and simple lightenv
resetShadeEnv();
C3D_TexBind(0, 0);
C3D_TexBind(1, 0);
C3D_LightEnvInit(&lightEnv);
C3D_LightEnvBind(&lightEnv);
C3D_LightEnvMaterial(&lightEnv, &lightMaterial);
LightLut_Phong(&lutPhong, 100.0);
C3D_LightEnvLut(&lightEnv, GPU_LUT_D0, GPU_LUTINPUT_LN, false, &lutPhong);
LightLut_FromFunc(&lutShittyFresnel, badFresnel, 1.9, false);
C3D_LightEnvLut(&lightEnv, GPU_LUT_FR, GPU_LUTINPUT_NV, false, &lutShittyFresnel);
C3D_LightEnvFresnel(&lightEnv, GPU_PRI_SEC_ALPHA_FRESNEL);
C3D_FVec lightVec = FVec4_New(0.0, 0.0, 0.0, 1.0);
C3D_LightInit(&light[0], &lightEnv);
C3D_LightColor(&light[0], 1.0, 1.0, 1.0);
C3D_LightPosition(&light[0], &lightVec);
env = C3D_GetTexEnv(0);
C3D_TexEnvSrc(env, C3D_RGB, GPU_FRAGMENT_PRIMARY_COLOR, GPU_FRAGMENT_SECONDARY_COLOR, 0);
C3D_TexEnvOpRgb(env, 0, 0, 0);
C3D_TexEnvFunc(env, C3D_RGB, GPU_REPLACE);
C3D_DrawArrays(GPU_TRIANGLES, cometsStart, cometsVertCount);
// And an additive pass to make the text shine
resetShadeEnv();
C3D_CullFace(GPU_CULL_BACK_CCW);
C3D_DepthTest(true, GPU_GEQUAL, GPU_WRITE_COLOR);
C3D_AlphaBlend(GPU_BLEND_ADD, GPU_BLEND_ADD, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA);
// Passthrough texenv and empty lightenv
C3D_LightEnvInit(&lightEnv);
C3D_LightEnvBind(&lightEnv);
env = C3D_GetTexEnv(0);
C3D_TexEnvInit(env);
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, 0, 0);
C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE);
C3D_TexBind(0, &cubeColAddTex);
C3D_DrawArrays(GPU_TRIANGLES, 0, numFacesCoolCube * 3);
}
void effectCoolCubeRender(C3D_RenderTarget* targetLeft, C3D_RenderTarget* targetRight, float iod, float row) {
// Update state
effectCoolCubeUpdate(row);
// Set up attribute info
attrInfo = C3D_GetAttrInfo();
AttrInfo_Init(attrInfo);
AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0 = position
AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 2); // v1 = texcoord
AttrInfo_AddLoader(attrInfo, 2, GPU_FLOAT, 3); // v2 = normal
AttrInfo_AddLoader(attrInfo, 3, GPU_FLOAT, 3); // v3 = tangent
// Start frame
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C3D_RenderTargetClear(targetLeft, C3D_CLEAR_ALL, 0, 0);
C3D_RenderTargetClear(targetRight, C3D_CLEAR_ALL, 0, 0);
// Left eye
C3D_FrameDrawOn(targetLeft);
effectCoolCubeDraw(-iod, row);
fade();
if(iod > 0.0) {
// Right eye
C3D_FrameDrawOn(targetRight);
effectCoolCubeDraw(iod, row);
fade();
}
// Ready to flip
C3D_FrameEnd(0);
//gspWaitForPPF();
}
void effectCoolCubeExit() {
gspWaitForPPF();
// Free textures
printf("tex free\n");
C3D_TexDelete(&skybox_tex);
C3D_TexDelete(&cubeColTex);
C3D_TexDelete(&cubeColAddTex);
C3D_TexDelete(&cubeNormTex);
// Free allocated memory
printf("vbo free\n");
linearFree(vbo);
linearFree(cubeColPixels);
linearFree(cubeColAddPixels);
linearFree(cubeNormPixels);
// Free the shaders
printf("shaders free\n");
shaderProgramFree(&shaderProgram);
DVLB_Free(vshader_dvlb);
shaderProgramFree(&shaderProgramSkybox);
DVLB_Free(vshader_skybox_dvlb);
printf("the problem is outside of this actually\n");
}