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