vg2 port: build script and resource loading
[fishladder.git] / fishladder_resources.h
1 // TEXTURES
2 // ===========================================================================================================
3
4 vg_tex2d tex_tile_data = { .path = "textures/tileset.qoi" };
5 vg_tex2d tex_tile_glow = { .path = "textures/lineset.qoi" };
6 vg_tex2d tex_tile_detail = { .path = "textures/tile_overlays.qoi" };
7
8 vg_tex2d tex_tiles_wood = { .path = "textures/tile_wood.qoi" };
9 vg_tex2d tex_tiles_min = { .path = "textures/tile_minimal.qoi" };
10 vg_tex2d tex_tiles_lab = { .path = "textures/tile_lab.qoi" };
11
12 vg_tex2d tex_ball_noise = { .path = "textures/bnoise.qoi" };
13 vg_tex2d tex_unkown = { .path = "textures/unkown.qoi" };
14 vg_tex2d tex_buttons = { .path = "textures/buttons.qoi" };
15 vg_tex2d tex_sprites = { .path = "textures/autocombine.qoi" };
16
17 vg_tex2d *texture_list[] = {
18 &tex_tile_detail,
19 &tex_tile_data,
20 &tex_tile_glow,
21 &tex_tiles_wood,
22 &tex_tiles_min,
23 &tex_tiles_lab,
24 &tex_ball_noise,
25 &tex_unkown,
26 &tex_buttons,
27 &tex_sprites
28 };
29
30 #include "sprites_autocombine.h"
31
32 // AUDIO
33 // ===========================================================================================================
34
35 sfx_vol_control audio_volume_sfx = { .val = 1.0f, .name = "Sound effects" };
36 sfx_vol_control audio_volume_music = { .val = 1.0f, .name = "Music" };
37
38 sfx_system audio_system_sfx =
39 {
40 .vol = 1.f,
41 .ch = 1,
42 .vol_src = &audio_volume_sfx,
43 .name = "sfx"
44 };
45
46 sfx_set audio_tile_mod =
47 {
48 .sources = "\
49 sound/mod_01.ogg\0\
50 sound/mod_02.ogg\0\
51 sound/mod_03.ogg\0\
52 sound/mod_04.ogg\0\
53 sound/mod_05.ogg\0\
54 sound/mod_06.ogg\0",
55 .flags = 0
56 };
57
58 sfx_set audio_splitter =
59 {
60 .sources = "\
61 sound/splitter_01.ogg\0"
62 };
63
64 sfx_set audio_rolls =
65 {
66 .sources = "\
67 sound/rolling_01.ogg\0\
68 sound/rolling_02.ogg\0"
69 };
70
71 sfx_set audio_random =
72 {
73 .sources = "\
74 sound/random_01.ogg\0\
75 sound/random_02.ogg\0\
76 sound/random_03.ogg\0\
77 sound/random_04.ogg\0\
78 sound/random_05.ogg\0\
79 sound/random_06.ogg\0\
80 sound/random_07.ogg\0\
81 sound/random_08.ogg\0"
82 };
83
84 sfx_set audio_clicks =
85 {
86 .sources = "\
87 sound/click_a.ogg\0\
88 sound/click_b.ogg\0\
89 sound/click_c.ogg\0"
90 };
91
92 sfx_set audio_tones =
93 {
94 .sources = "\
95 sound/y0.ogg\0\
96 sound/y1.ogg\0\
97 sound/y2.ogg\0\
98 sound/y3.ogg\0\
99 sound/y4.ogg\0\
100 sound/y5.ogg\0\
101 sound/y6.ogg\0\
102 sound/y7.ogg\0\
103 sound/y8.ogg\0\
104 sound/win.ogg\0"
105 };
106
107 sfx_set audio_music =
108 {
109 .sources = "sound/mccompt2.ogg\0"
110 };
111
112 // One two or three layers of rolling noise
113 sfx_system audio_system_balls_rolling =
114 {
115 .vol = 0.7f, .ch = 1, .vol_src = &audio_volume_sfx,
116 .name = "Balls Rolling", .flags = SFX_FLAG_REPEAT | SFX_FLAG_PERSISTENT
117 };
118
119 // Various oneshots
120 sfx_system audio_system_balls_switching =
121 {
122 .vol = 0.2f, .ch = 1, .vol_src = &audio_volume_sfx,
123 .name = "Balls Switching"
124 };
125
126 // Gameplay critical sounds eg. splitter sound rocking
127 sfx_system audio_system_balls_important =
128 {
129 .vol = 1.f, .ch = 1, .vol_src = &audio_volume_sfx,
130 .name = "Balls Gameplay"
131 };
132
133 // Suplemental sounds
134 sfx_system audio_system_balls_extra =
135 {
136 .vol = 0.27f, .ch = 1, .vol_src = &audio_volume_sfx,
137 .name = "Balls Extra"
138 };
139
140 sfx_system audio_system_ui =
141 {
142 .vol = 1.f, .ch = 1, .vol_src = &audio_volume_sfx,
143 .name = "UI"
144 };
145
146 sfx_system audio_system_music =
147 {
148 .vol = 1.0f,
149 .ch = 2,
150 .vol_src = &audio_volume_music,
151 .name = "music",
152 .flags = SFX_FLAG_REPEAT | SFX_FLAG_PERSISTENT | SFX_FLAG_STEREO
153 };
154
155 static void *load_and_play_bgm( void *_inf )
156 {
157 sfx_set_init( &audio_music, NULL );
158 sfx_set_play( &audio_music, &audio_system_music, 0 );
159 return NULL;
160 }
161
162 static void resource_load_main(void)
163 {
164 // Textures // UI
165 vg_tex2d_init( texture_list, vg_list_size( texture_list ) );
166
167 // Audio
168 sfx_set_init( &audio_tile_mod, NULL );
169 sfx_set_init( &audio_splitter, NULL );
170 sfx_set_init( &audio_rolls, NULL );
171 sfx_set_init( &audio_random, NULL );
172 sfx_set_init( &audio_clicks, NULL );
173 sfx_set_init( &audio_tones, NULL );
174
175 vg_thread_run( load_and_play_bgm, NULL );
176 }
177
178 static void resource_free_main(void)
179 {
180 vg_tex2d_free( texture_list, vg_list_size( texture_list ) );
181
182 sfx_set_free( &audio_tile_mod );
183 sfx_set_free( &audio_splitter );
184 sfx_set_free( &audio_rolls );
185 sfx_set_free( &audio_random );
186 sfx_set_free( &audio_clicks );
187 sfx_set_free( &audio_tones );
188 }
189
190 // SHADERS
191 // ===========================================================================================================
192
193 SHADER_DEFINE( shader_tile_colour,
194
195 // VERTEX
196 "layout (location=0) in vec2 a_co;"
197 "uniform mat3 uPv;"
198 "uniform vec3 uOffset;"
199 ""
200 "void main()"
201 "{"
202 "gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );"
203 "}",
204
205 // FRAGMENT
206 "out vec4 FragColor;"
207 "uniform vec4 uColour;"
208 ""
209 "void main()"
210 "{"
211 "FragColor = uColour;"
212 "}"
213 ,
214 UNIFORMS({ "uPv", "uOffset", "uColour" })
215 )
216
217 SHADER_DEFINE( shader_ball,
218 // VERTEX
219 "layout (location=0) in vec2 a_co;"
220 "uniform vec3 uOffset;"
221 "uniform mat3 uPv;"
222 ""
223 "out vec4 aTexCoords;"
224 ""
225 "void main()"
226 "{"
227 // Vertex transform
228 "vec3 worldpos = vec3( (a_co * 0.5 - 0.25) * uOffset.z + uOffset.xy, 1.0 );"
229 "gl_Position = vec4( uPv * worldpos, 1.0 );"
230
231 // Create texture coords
232 "aTexCoords = vec4( a_co, worldpos.xy );"
233 "}",
234
235 // FRAGMENT
236 "out vec4 FragColor;"
237 ""
238 "uniform sampler2D uTexMain;"
239 "uniform vec3 uColour;"
240 "uniform vec2 uTexOffset;"
241 ""
242 "in vec4 aTexCoords;"
243 ""
244 "void main()"
245 "{"
246 "vec2 center_coords = aTexCoords.xy - 0.5;"
247 "vec2 center_coords_sqr = center_coords*center_coords;"
248 "float circle_factor = smoothstep( 0.07, 0.0625, center_coords_sqr.x+center_coords_sqr.y );"
249
250 "float bulge_amt = center_coords_sqr.x+center_coords_sqr.y;"
251 "vec2 warped_coords = aTexCoords.zw+uTexOffset - center_coords;"
252 "vec4 noise_sample = texture( uTexMain, warped_coords );"
253
254 "float rim_light = (center_coords_sqr.x+center_coords_sqr.y)*15.0;"
255
256 "vec2 shadow_coords = center_coords + vec2(0.02,0.07);"
257 "vec2 shadow_coords_sqr = shadow_coords*shadow_coords;"
258 "float shadow = exp(-((shadow_coords_sqr.x+shadow_coords_sqr.y)-0.0125)*15.0);"
259
260 "vec3 marble_comp = uColour*0.6 + (noise_sample.x*2.7+pow(rim_light,3.0)*2.0) * 0.1;"
261 //"vec4 colour_comp = mix( vec4(0.74,0.53,0.34,shadow), vec4(marble_comp,1.0), circle_factor );"
262 "vec4 colour_comp = mix( vec4(0.0,0.0,0.0,shadow), vec4(marble_comp,1.0), circle_factor );"
263
264 "FragColor = colour_comp;"
265 "}"
266 ,
267 UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv", "uTexOffset" })
268 )
269
270 SHADER_DEFINE( shader_tile_main,
271 // VERTEX
272 "layout (location=0) in vec2 a_co;"
273 "uniform vec4 uOffset;" // Tile x/y, uv x/y
274 "uniform mat3 uPv;"
275 "uniform mat2 uSubTransform;"
276 "uniform float uVisibility;"
277 ""
278 "out vec4 aTexCoords;"
279 "out vec2 aWorldCoords;"
280 ""
281 "vec2 hash22(vec2 p)"
282 "{"
283 "vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));"
284 "p3 += dot(p3, p3.yzx+33.33);"
285 "return fract((p3.xx+p3.yz)*p3.zy);"
286 "}"
287 ""
288 "void main()"
289 "{"
290 "vec2 hash_val = hash22(uOffset.xy);"
291 "float scaling_factor = smoothstep( hash_val.x, hash_val.x+1.0, uVisibility );"
292
293 // Vertex transform
294 "vec2 subtransform = uSubTransform * (a_co-0.5) * scaling_factor + 0.5;"
295 "vec3 worldpos = vec3( subtransform + uOffset.xy, 1.0 );"
296 "gl_Position = vec4( uPv * worldpos, 1.0 );"
297
298 // Create texture coords
299 "vec2 random_offset = floor(hash_val * 4.0) * 0.25;"
300 "vec2 edge_safe_coords = a_co * 0.98 + 0.01;"
301 "aTexCoords = vec4((edge_safe_coords + uOffset.zw) * 0.25, edge_safe_coords * 0.25 + random_offset );"
302 "aWorldCoords = worldpos.xy;"
303 "}",
304
305 // FRAGMENT
306 "out vec4 FragColor;"
307 ""
308 "uniform sampler2D uTexGlyphs;"
309 "uniform sampler2D uTexGlow;"
310 "uniform sampler2D uTexWood;"
311 "uniform float uGhost;"
312 "uniform float uForeground;"
313 "uniform vec2 uMousePos;"
314 "uniform vec4 uColour;"
315 "uniform vec3 uShadowing;"
316 "uniform vec3 uGlowA;"
317 "uniform vec3 uGlowB;"
318 ""
319 "in vec4 aTexCoords;"
320 "in vec2 aWorldCoords;"
321 ""
322 "void main()"
323 "{"
324 //"vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 ) * 0.97;"
325 //"vec3 shadowing_colour = vec3( 0.8, 0.8, 0.8 );"
326
327 "vec4 glyph = texture( uTexGlyphs, aTexCoords.xy );"
328 "vec4 glyph_glow = texture( uTexGlow, aTexCoords.xy );"
329 "vec4 wood = texture( uTexWood, aTexCoords.zw );"
330 "vec4 wood_secondary = texture( uTexWood, aTexCoords.zw + 0.25 );"
331 "vec3 wood_comp = mix( wood_secondary.rgb * uShadowing, wood.rgb, clamp( glyph.b*2.0-1.0, 0.0, 1.0 ) );"
332
333 //"vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
334 "vec3 shadows = mix( uShadowing, vec3(1.0,1.0,1.0), glyph.r );"
335
336 "vec4 output_regular = vec4( wood_comp * shadows, mix( glyph.a, glyph.b, uForeground ) );"
337
338 "float ghost_dist = clamp( 1.5 - distance(uMousePos, aWorldCoords), 0.0, 1.0 );"
339 "vec4 output_ghost = vec4( 1.0, 1.0, 1.0, glyph.g*ghost_dist );"
340 "vec4 glow_comp = vec4(glyph_glow.b*uGlowA+glyph_glow.g*uGlowB,0.0);"
341
342 "FragColor = mix( output_regular, output_ghost, uGhost )*uColour + glow_comp;"
343 "}"
344 ,
345 UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos",
346 "uColour", "uForeground", "uVisibility", "uShadowing", "uTexGlow",
347 "uGlowA", "uGlowB" })
348 )
349
350 SHADER_DEFINE( shader_background,
351 // VERTEX
352 "layout (location=0) in vec2 a_co;"
353 "uniform mat3 uPv;"
354 "uniform vec3 uOffset;"
355 ""
356 "out vec2 aTexCoords;"
357 ""
358 "void main()"
359 "{"
360 "vec2 world_pos = a_co * uOffset.z + uOffset.xy;"
361 "gl_Position = vec4( uPv * vec3( world_pos, 1.0 ), 1.0 );"
362 "aTexCoords = a_co;"
363 "}",
364
365 // FRAGMENT
366 "out vec4 FragColor;"
367 ""
368 "uniform sampler2D uTexMain;"
369 "uniform sampler2D uSamplerNoise;"
370 "uniform float uVariance;"
371 "uniform float uVisibility;"
372 ""
373 "in vec2 aTexCoords;"
374 ""
375 "void main()"
376 "{"
377 "vec4 data_this_tile = texture( uTexMain, aTexCoords );"
378
379 "float ao_accum = 0.0;"
380
381 "vec2 random_noise;"
382
383 "for( int i=0; i<10; ++i )"
384 "{"
385 "random_noise = (texture( uSamplerNoise, aTexCoords * 10.0 + float(i) * 0.2 ).xy - vec2( 0.5, 0.5 )) * uVariance;"
386 "vec4 background = texture( uTexMain, aTexCoords + random_noise );"
387 "float height_diff = min(data_this_tile.r - background.r,0.0);"
388
389 "ao_accum += height_diff * clamp((1.0 - length( random_noise )), 0.0, 1.0);"
390 "}"
391 "ao_accum *= 0.15;"
392
393 #if 0
394 "vec3 colour_main = mix( vec3( 0.369768, 0.3654, 0.42 ), vec3( 0.275, 0.388, 0.553 ), data_this_tile.g * uVisibility );"
395 #endif
396
397 "vec2 square_coords = fract( aTexCoords * 64.0 );"
398 "vec2 grid_coords = abs( square_coords - 0.5 );"
399 "float gridline = step( 0.49, max(grid_coords.x,grid_coords.y) );"
400
401 "vec3 colour_main = mix( vec3( 0.14 ) + random_noise.x*0.5, vec3( 0.1 ) + gridline*0.02, data_this_tile.g * uVisibility );"
402 "FragColor = vec4( colour_main + ao_accum*0.05, 1.0 );"
403 "}"
404 ,
405 UNIFORMS({ "uPv", "uOffset", "uTexMain", "uVariance", "uSamplerNoise", "uVisibility" })
406 )
407
408 SHADER_DEFINE( shader_wire,
409 // VERTEX
410 "layout (location=0) in vec2 a_co;"
411 "uniform vec3 uStart;"
412 "uniform vec3 uEnd;"
413 "uniform mat3 uPv;"
414 "uniform float uCurve;"
415 ""
416 "out vec2 aTexCoords;"
417 ""
418 "vec3 sample_curve_time( float t )"
419 "{"
420 "vec3 line_coord = mix( uStart, uEnd, t );"
421
422 "float curve_amt = 1.0-(pow((t*2.0-1.0),2.0));"
423 "return vec3( line_coord.x, line_coord.y - curve_amt*uCurve, line_coord.z );"
424 "}"
425 ""
426 "void main()"
427 "{"
428 // Vertex transform
429 "vec3 p0 = sample_curve_time( a_co.x );"
430 "vec3 p1 = sample_curve_time( a_co.x + 0.025 );"
431
432 "vec2 line_tangent = normalize(p1.xy-p0.xy);"
433 "vec2 line_normal = vec2( -line_tangent.y, line_tangent.x );"
434
435 "vec2 worldfinal = p0.xy + line_normal*a_co.y*p0.z;"
436
437 "gl_Position = vec4( uPv * vec3(worldfinal, 1.0), 1.0 );"
438
439 // Create texture coords (todo: include stretch adjusted coords?)
440 "aTexCoords = vec2( a_co.x, a_co.y + 0.5 );"
441 "}",
442
443 // FRAGMENT
444 "out vec4 FragColor;"
445 ""
446 "uniform sampler2D uTexMain;"
447 "uniform vec4 uColour;"
448 "uniform float uTime;"
449 "uniform float uGlow;"
450 ""
451 "in vec2 aTexCoords;"
452 ""
453 "void main()"
454 "{"
455 // Compute shadowing
456 "float shadow = 1.0 - abs(aTexCoords.y - 0.5) * 2.0;"
457 "float masking = smoothstep( 0.5, 0.8, shadow );"
458
459 "vec3 colour_comp = mix( vec3(0.0,0.0,0.0), uColour.rgb, masking );"
460
461 "float flow_thing = fract( aTexCoords.x + uTime );"
462 "vec3 final_comp = colour_comp + flow_thing * uGlow;"
463
464 "FragColor = vec4( final_comp, max( shadow* 0.2, masking ) * uColour.a );"
465 "}"
466 ,
467 UNIFORMS({ "uPv", "uColour", "uTexMain", "uStart", "uEnd", "uCurve", "uTime", "uGlow" })
468 )
469
470 SHADER_DEFINE( shader_buttons,
471 // VERTEX
472 "layout (location=0) in vec2 a_co;"
473 "uniform vec4 uOffset;" // Tile x/y, uv x/y
474 "uniform mat3 uPv;"
475 ""
476 "out vec2 aTexCoords;"
477 ""
478 "void main()"
479 "{"
480 // Vertex transform
481 "vec3 worldpos = vec3( a_co + uOffset.xy, 1.0 );"
482 "gl_Position = vec4( uPv * worldpos, 1.0 );"
483
484 // Create texture coords
485 "vec2 edge_safe_coords = a_co * 0.98 + 0.01;"
486 "aTexCoords = (edge_safe_coords + uOffset.zw) * 0.25;"
487 "}",
488
489 // FRAGMENT
490 "out vec4 FragColor;"
491 ""
492 "uniform sampler2D uTexMain;"
493 "uniform vec4 uColour;" // rgb, light amount
494 ""
495 "in vec2 aTexCoords;"
496 ""
497 "void main()"
498 "{"
499 "vec4 glyph = texture( uTexMain, aTexCoords.xy );"
500
501 "FragColor = vec4( uColour.rgb * (mix(glyph.r, glyph.g, uColour.a)+0.02)*2.6 + glyph.b * 0.4, glyph.a );"
502 "}"
503 ,
504 UNIFORMS({ "uPv", "uOffset", "uTexMain", "uColour" })
505 )
506
507 SHADER_DEFINE( shader_sprite,
508
509 // VERTEX
510 "layout (location=0) in vec2 a_co;" // quad mesh
511 "uniform vec4 uUv;"
512 "uniform vec3 uPos;"
513 ""
514 "uniform mat3 uPv;"
515 ""
516 "out vec2 aTexCoords;"
517 ""
518 "void main()"
519 "{"
520 "vec2 vertex_world = uUv.zw * (a_co-0.5) * uPos.z + uPos.xy;"
521 "gl_Position = vec4( uPv * vec3( vertex_world, 1.0 ), 1.0 );"
522 "aTexCoords = uUv.xy + a_co*uUv.zw;"
523 "}",
524
525 // FRAGMENT
526 "uniform sampler2D uTexMain;"
527 "out vec4 FragColor;"
528 ""
529 "in vec2 aTexCoords;"
530 ""
531 "void main()"
532 "{"
533 "vec4 texture_sample = texture( uTexMain, aTexCoords );"
534 "FragColor = texture_sample;"
535 "}"
536 ,
537 UNIFORMS({ "uPv", "uTexMain", "uUv", "uPos" })
538 )
539
540 SHADER_DEFINE( shader_post_darken,
541 "layout (location=0) in vec2 a_co;"
542 "out vec2 aTexCoords;"
543 ""
544 "void main()"
545 "{"
546 "gl_Position = vec4( a_co * 2.0 - 1.0, 0.0, 1.0 );"
547 "aTexCoords = a_co;"
548 "}",
549
550 "uniform sampler2D uTexMain;"
551 "out vec4 FragColor;"
552 ""
553 "in vec2 aTexCoords;"
554 ""
555 "void main()"
556 "{"
557 "vec4 texture_sample = texture( uTexMain, aTexCoords );"
558 "FragColor = vec4(pow(texture_sample.rgb,vec3(2.2)), 1.0);"
559 "}"
560 ,
561 UNIFORMS({"uTexMain"})
562 )
563
564 SHADER_DEFINE( shader_post_blur,
565 "layout (location=0) in vec2 a_co;"
566 "out vec2 aTexCoords;"
567 ""
568 "void main()"
569 "{"
570 "gl_Position = vec4( a_co * 2.0 - 1.0, 0.0, 1.0 );"
571 "aTexCoords = a_co;"
572 "}",
573
574 "uniform sampler2D uTexMain;"
575 "uniform vec2 uDir;"
576 "out vec4 FragColor;"
577 ""
578 "in vec2 aTexCoords;"
579 ""
580 "void main()"
581 "{"
582 "vec4 colour = vec4(0.0);"
583
584 "vec2 off1 = vec2(1.411764705882353) * uDir;"
585 "vec2 off2 = vec2(3.2941176470588234) * uDir;"
586 "vec2 off3 = vec2(5.176470588235294) * uDir;"
587 "colour += texture2D( uTexMain, aTexCoords ) * 0.1964825501511404;"
588 "colour += texture2D( uTexMain, aTexCoords + off1 ) * 0.2969069646728344;"
589 "colour += texture2D( uTexMain, aTexCoords - off1 ) * 0.2969069646728344;"
590 "colour += texture2D( uTexMain, aTexCoords + off2 ) * 0.09447039785044732;"
591 "colour += texture2D( uTexMain, aTexCoords - off2 ) * 0.09447039785044732;"
592 "colour += texture2D( uTexMain, aTexCoords + off3 ) * 0.010381362401148057;"
593 "colour += texture2D( uTexMain, aTexCoords - off3 ) * 0.010381362401148057;"
594 "FragColor = colour;"
595 "}"
596 ,
597 UNIFORMS({"uTexMain","uDir"})
598 )
599
600 SHADER_DEFINE( shader_post_comp,
601 "layout (location=0) in vec2 a_co;"
602 "out vec2 aTexCoords;"
603 ""
604 "void main()"
605 "{"
606 "gl_Position = vec4( a_co * 2.0 - 1.0, 0.0, 1.0 );"
607 "aTexCoords = a_co;"
608 "}",
609
610 "uniform sampler2D uTexMain;"
611 "uniform sampler2D uTexBloom;"
612 "uniform vec2 uComp;" /* x: bloom, y: vignette */
613 "out vec4 FragColor;"
614 ""
615 "in vec2 aTexCoords;"
616 ""
617 "void main()"
618 "{"
619 "vec4 texture_sample = texture( uTexMain, aTexCoords );"
620 "vec4 bloom_sample = texture( uTexBloom, aTexCoords );"
621
622 "vec2 vigCoord = aTexCoords - 0.5;"
623 "float vig = pow(1.0 - dot( vigCoord, vigCoord ), 2.0);"
624
625 "FragColor = (texture_sample + bloom_sample*0.3*uComp.x)"
626 " * max(uComp.y, vig);"
627 "}"
628 ,
629 UNIFORMS({"uTexMain", "uTexBloom", "uComp"})
630 )
631
632 void vg_register(void)
633 {
634 SHADER_INIT( shader_tile_colour );
635 SHADER_INIT( shader_tile_main );
636 SHADER_INIT( shader_ball );
637 SHADER_INIT( shader_background );
638 SHADER_INIT( shader_wire );
639 SHADER_INIT( shader_buttons );
640 SHADER_INIT( shader_sprite );
641 SHADER_INIT( shader_post_darken );
642 SHADER_INIT( shader_post_comp );
643 SHADER_INIT( shader_post_blur );
644 }
645
646 /*
647 0000 0 | 0001 1 | 0010 2 | 0011 3
648 | | | | |
649 X | X= | X | X=
650 | | |
651 0100 4 | 0101 5 | 0110 6 | 0111 7
652 | | | | |
653 =X | =X= | =X | =X=
654 | | |
655 1000 8 | 1001 9 | 1010 10 | 1011 11
656 | | | | |
657 X | X= | X | X=
658 | | | | | | |
659 1100 12 | 1101 13 | 1110 14 | 1111 15
660 | | | | |
661 =X | =X= | =X | =X=
662 | | | | | | |
663 */
664
665 struct cmp_level
666 {
667 // Basic info
668 int serial_id;
669
670 const char *map_name;
671 const char *title;
672 const char *description;
673
674 const char *achievement;
675
676 int _unlock, _linked; // When completed, unlock this level
677 int is_tutorial;
678
679 // Aesthetic
680 struct world_string
681 {
682 enum placement
683 {
684 k_placement_top,
685 k_placement_bottom
686 }
687 placement;
688
689 const char *str;
690 }
691 strings[2];
692
693 // Persistent stats
694 int unlocked;
695 int completed_score;
696
697 // Runtime
698 struct world_button btn;
699 struct cmp_level *unlock, *linked;
700
701 #ifdef VG_STEAM
702 SteamLeaderboard_t steam_leaderboard;
703 #endif
704 };
705
706 static struct cmp_level cmp_levels_tutorials[] =
707 {
708 {
709 0, "cmp_t01", "PRINCIPLE 1", "",
710 ._unlock = 1,
711 .is_tutorial = 1
712 },
713 {
714 1, "cmp_t02", "PRINCIPLE 2", "",
715 ._unlock = 2,
716 .is_tutorial = 1,
717 },
718 {
719 2, "cmp_t03", "PRINCIPLE 3", "",
720 ._unlock = 12,
721 .is_tutorial = 1
722 },
723 {
724 12, "cmp_t04", "PRINCIPLE 4", "",
725 ._unlock = 6,
726 .is_tutorial = 1,
727 .achievement = "TUTORIALS"
728 },
729 {
730 15, "cmp_b10", "PRINCIPLE 5", "",
731 ._unlock = 16,
732 .is_tutorial = 1
733 },
734 {
735 17, "cmp_b11", "PRINCIPLE 6", "(Right click)",
736 ._unlock = 18,
737 .is_tutorial = 1
738 },
739 {
740 26, "cmp_p7", "PRINCIPLE 7", "Emitters",
741 ._unlock = 27,
742 ._linked = 13,
743 .is_tutorial = 1
744 }
745 };
746
747 static struct cmp_level cmp_levels_basic[] =
748 {
749 {
750 6, "cmp_b04", "PATCH", "",
751 ._unlock = 7,
752 ._linked = 3
753 },
754 {
755 3, "cmp_b01", "SUBDIVISION 1", "",
756 ._linked = 4,
757 ._unlock = 5
758 },
759 {
760 4, "cmp_b02", "SUBDIVISION 2", "",
761 ._unlock = 7
762 },
763 {
764 5, "cmp_b03", "RESTRUCTURE", "",
765 ._unlock = 8,
766 ._linked = 31
767 },
768 {
769 31, "cmp_121", "1-2-1", "",
770 ._unlock = 8
771 },
772 {
773 7, "cmp_b05", "PATTERNS 1", "",
774 ._unlock = 15,
775 ._linked = 8
776 },
777 {
778 8, "cmp_b06", "PATTERNS 2", "",
779 ._unlock = 15
780 },
781 {
782 16, "cmp_routing", "ROUTING PROBLEM", "",
783 ._linked = 9
784 },
785 {
786 9, "cmp_b07", "MIGHTY CONSUMER", "",
787 ._linked = 10,
788 ._unlock = 11,
789 .achievement = "MIGHTY_CONSUMER"
790 },
791 {
792 10, "cmp_b08", "SHIFT", "",
793 ._unlock = 17
794 },
795 {
796 11, "cmp_b09", "REVERSE", "",
797 ._unlock = 17
798 },
799 {
800 18, "cmp_not", "NOT GATE", "",
801 ._linked = 19,
802 ._unlock = 20
803 },
804 {
805 19, "cmp_and", "AND GATE", "",
806 ._unlock = 20
807 },
808 {
809 20, "cmp_xor", "QUALIFICATION PROJECT", "",
810 ._unlock = 26,
811 .achievement = "GRADUATE"
812 },
813 {
814 27, "cmp_expander", "EXPAND", "",
815 ._unlock = 28
816 },
817 {
818 28, "cmp_pattern3", "PATTERNS 3", "",
819 ._linked = 29
820 },
821 {
822 29, "cmp_routing2", "ROUTING PROBLEM 2", "Spaghetti!",
823 ._linked = 30,
824 ._unlock = 32
825 },
826 {
827 30, "cmp_exact5", "EXACTLY 5", "",
828 ._unlock = 32
829 },
830 {
831 32, "cmp_3and2", "THREE AND FOUR", "",
832 ._linked = 34
833 },
834 {
835 34, "doublex2", "DOUBLE DOUBLE", "Delay & repeat",
836 ._linked = 35
837 },
838 {
839 35, "oddoreven", "ODD OR EVEN", ""
840 }
841 };
842
843 static struct cmp_level cmp_levels_grad[] =
844 {
845 {
846 13, "cmp_i01", "SORT", "",
847 ._linked = 14
848 },
849 {
850 14, "cmp_i02", "THIRDS", "",
851 ._linked = 21
852 },
853 {
854 21, "cmp_grad", "SIMPLE ADDITION", "",
855 ._linked = 22,
856 ._unlock = 23
857 },
858 {
859 22, "cmp_secret", "SECRET CODE", "",
860 ._unlock = 23
861 }
862 };
863
864 static struct cmp_level cmp_levels_computer[] =
865 {
866 {
867 23, "cmp_binary", "3 BIT BINARY", "Convert amount to binary",
868 ._unlock = 24,
869 .strings =
870 {
871 {
872 .placement = k_placement_bottom,
873 .str =
874 "\t\t\t\t\t\t\t\t\t\t\x83 \x84\n"
875 "\t\t\t\t\t\t\t\t\t\t\x83 \x84 Binary\n"
876 "\t\t\t\t\t\t\t\t\t\t\x83 4 2 1 \x84"
877 },
878 {
879 .placement = k_placement_top,
880 .str =
881 "\n"
882 "\t\t\t\t\t\t\t\t\t\t\t Count"
883 }
884 }
885 },
886 {
887 24, "cmp_add3b", "3 BIT ADDER", "Binary addition",
888 ._unlock = 25,
889 .strings =
890 {
891 {
892 .placement = k_placement_top,
893 //.str ="\t\t\t\t\t\t\t\t\t| NUMBER A | | NUMBER B |\n"
894 .str =""
895 "\t\t\t\t\t\t\t\t\t\x8A 4 2 1 \x8B \x8A 4 2 1 \x8B\n"
896 "\t\t\t\t\t\t\t\t\t\x83 \x84 add \x83 \x84\n"
897 "\t\t\t\t\t\t\t\t\t\x83 \x84 \x83 \x84"
898 },
899 {
900 .placement = k_placement_bottom,
901 .str =
902 "\t\t\t\x83 \x84\n"
903 "\t\t\t\x83 \x84 result a+b\n"
904 "\t\t\t\x83 8 4 2 1 \x84"
905 }
906 }
907 },
908 {
909 25, "cmp_plot3x3", "3x3 PLOT", "2 bit x/y",
910 ._unlock = 33,
911 .strings =
912 {
913 {
914 .placement = k_placement_top,
915 .str=
916 "\t\t\t\t\t\t\t\t\x8A 2 1 \x8B \x8A 2 1 \x8B\n"
917 "\t\t\t\t\t\t\t\t\x83 \x84 X Y \x83 \x84\n"
918 "\t\t\t\t\t\t\t\t\x83 \x84 \x83 \x84"
919 }
920 }
921 },
922 {
923 33, "compactxor", "Compact XOR", "",
924 .strings =
925 {
926 {
927 .placement = k_placement_top,
928 .str=
929 "\t\t\t\t\x8A \x8B \x8A \x8B\n"
930 "\t\t\t\t\x83 \x84""A B\x83 \x84\n"
931 "\t\t\t\t\x83 \x84 \x83 \x84"
932 },
933 {
934 .placement = k_placement_bottom,
935 .str =
936 "\t\t\t\x83 \x84\n"
937 "\t\t\t\x83 \x84 result a xor b\n"
938 "\t\t\t\x83 \x84"
939 }
940 }
941 }
942 };
943
944 #define NUM_CAMPAIGN_LEVELS (vg_list_size( cmp_levels_tutorials ) + vg_list_size( cmp_levels_basic ) + vg_list_size( cmp_levels_grad ) + vg_list_size( cmp_levels_computer ) )
945
946 static struct career_level_pack
947 {
948 struct cmp_level *pack;
949 const char *title;
950 int count;
951
952 v3f primary_colour;
953 v2i origin;
954 v2i dims;
955 }
956 career_packs[] =
957 {
958 {
959 .pack = cmp_levels_tutorials,
960 .title = "",
961 .count = vg_list_size( cmp_levels_tutorials ),
962 .primary_colour = { 0.204f, 0.345f, 0.553f },
963 .origin = { -4, -2 },
964 .dims = { 1, 7 }
965 },
966 {
967 .pack = cmp_levels_basic,
968 .title = "\x8C\x8D"" Core",
969 .count = vg_list_size( cmp_levels_basic ),
970 .primary_colour = { 0.304f, 0.245f, 0.553f },
971 .origin = { -3, -2 },
972 .dims = { 3, 7 }
973 },
974 {
975 .pack = cmp_levels_grad,
976 .title = "\x8C\x8E"" Challenge",
977 .count = vg_list_size( cmp_levels_grad ),
978 .primary_colour = { 0.75f, 0.23f, 0.39f },
979 .origin = { -4, 5 },
980 .dims = { 4, 1 }
981 },
982 {
983 .pack = cmp_levels_computer,
984 .title = "\x8C\x8F"" 3 Bit computer\n\n (preview)",
985 .count = vg_list_size( cmp_levels_computer ),
986 .primary_colour = { 0.75f, 0.14f, 0.1f },
987 .origin = { -4, 6 },
988 .dims = { 4, 1 }
989 }
990 };
991
992 // Setup pointers and that
993 static void career_local_data_init(void)
994 {
995 struct cmp_level *level_ptrs[ NUM_CAMPAIGN_LEVELS ];
996 for( int i = 0; i < NUM_CAMPAIGN_LEVELS; i ++ )
997 level_ptrs[i] = NULL;
998
999 // COllect pointers
1000 for( int i = 0; i < vg_list_size( career_packs ); i ++ )
1001 {
1002 struct career_level_pack *set = &career_packs[i];
1003
1004 for( int j = 0; j < set->count; j ++ )
1005 {
1006 int id = set->pack[j].serial_id;
1007
1008 if( level_ptrs[ id ] )
1009 vg_error( "Serial id %u already used!\n", id );
1010 else
1011 level_ptrs[ set->pack[j].serial_id ] = &set->pack[j];
1012 }
1013 }
1014
1015 // Apply
1016 for( int i = 0; i < vg_list_size( career_packs ); i ++ )
1017 {
1018 struct career_level_pack *set = &career_packs[i];
1019
1020 for( int j = 0; j < set->count; j ++ )
1021 {
1022 struct cmp_level *lvl = &set->pack[j];
1023
1024 if( lvl->_unlock >= NUM_CAMPAIGN_LEVELS ||
1025 lvl->_linked >= NUM_CAMPAIGN_LEVELS )
1026 {
1027 vg_error( "_unlock / _linked out of range (%d, %d)\n",
1028 lvl->_unlock, lvl->_linked );
1029 }
1030 else
1031 {
1032 lvl->unlock = lvl->_unlock? level_ptrs[ lvl->_unlock ]: NULL;
1033 lvl->linked = lvl->_linked? level_ptrs[ lvl->_linked ]: NULL;
1034 }
1035 }
1036 }
1037 }