server changes
[carveJwlIkooP6JGAAIwe30JlM.git] / world_routes.c
1 /*
2 * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved
3 */
4
5 #ifndef ROUTES_C
6 #define ROUTES_C
7
8 #include <time.h>
9 #include "world_routes.h"
10 #include "world_gate.h"
11 #include "world_load.h"
12 #include "highscores.h"
13
14 #include "font.h"
15 #include "pointcloud.h"
16 #include "gui.h"
17 #include "steam.h"
18
19 #include "shaders/scene_route.h"
20 #include "shaders/routeui.h"
21
22
23 VG_STATIC
24 void world_routes_local_set_record( world_instance *world, ent_route *route,
25 f64 lap_time )
26 {
27 vg_success( " NEW LAP TIME: %f\n", lap_time );
28
29 if( route->official_track_id != 0xffffffff ){
30 double time_centiseconds = lap_time * 100.0;
31 if( time_centiseconds > (float)0xfffe ) /* skill issue */
32 return;
33
34 highscore_record temp;
35 temp.trackid = route->official_track_id;
36 temp.datetime = time(NULL);
37 temp.playerid = 0;
38 temp.points = 0;
39 temp.time = time_centiseconds;
40 #if 0
41 highscores_push_record( &temp );
42 #endif
43
44 struct track_info *ti = &track_infos[ route->official_track_id ];
45 ti->push = 1;
46
47 if( ti->achievement_id ){
48 steam_set_achievement( ti->achievement_id );
49 steam_store_achievements();
50 }
51 }
52 else{
53 vg_warn( "There is no associated track for this record...\n" );
54 }
55 }
56
57
58 VG_STATIC void world_routes_clear( world_instance *world )
59 {
60 for( u32 i=0; i<mdl_arrcount( &world->ent_route ); i++ ){
61 ent_route *route = mdl_arritm( &world->ent_route, i );
62 route->active_checkpoint = 0xffff;
63 }
64
65 for( u32 i=0; i<mdl_arrcount( &world->ent_gate ); i++ ){
66 ent_gate *rg = mdl_arritm( &world->ent_gate, i );
67 rg->timing_version = 0;
68 rg->timing_time = 0.0;
69 }
70
71 world_static.current_run_version += 4;
72 world_static.last_use = 0.0;
73 }
74
75 VG_STATIC void world_routes_time_lap( world_instance *world, ent_route *route )
76 {
77 vg_info( "------- time lap %s -------\n",
78 mdl_pstr(&world->meta,route->pstr_name) );
79
80 double start_time = 0.0;
81 u32 last_version=0;
82
83 u32 valid_count=0;
84
85 for( u32 i=0; i<route->checkpoints_count; i++ ){
86 u32 cpid = (i+route->active_checkpoint) % route->checkpoints_count;
87 cpid += route->checkpoints_start;
88
89 ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, cpid );
90 ent_gate *rg = mdl_arritm( &world->ent_gate, cp->gate_index );
91 rg = mdl_arritm( &world->ent_gate, rg->target );
92
93 if( i == 1 ){
94 route->timing_base = rg->timing_time;
95 }
96
97 if( i == 0 )
98 start_time = rg->timing_time;
99 else{
100 if( last_version+1 == rg->timing_version ) valid_count ++;
101 else valid_count = 0;
102 }
103
104 last_version = rg->timing_version;
105 vg_info( "%u %f\n", rg->timing_version, rg->timing_time );
106 }
107
108 if( world_static.current_run_version == last_version+1 ){
109 valid_count ++;
110
111 if( route->checkpoints_count == 1 ){
112 route->timing_base = world_static.time;
113 }
114 }
115 else valid_count = 0;
116
117 vg_info( "%u %f\n", world_static.current_run_version, world_static.time );
118
119 if( valid_count==route->checkpoints_count ){
120 double lap_time = world_static.time - start_time;
121 world_routes_local_set_record( world, route, lap_time );
122 }
123
124 route->valid_checkpoints = valid_count+1;
125
126 vg_info( "valid: %u\n", valid_count );
127 vg_info( "----------------------------\n" );
128 }
129
130 /*
131 * When going through a gate this is called for bookkeeping purposes
132 */
133 VG_STATIC void world_routes_activate_entry_gate( world_instance *world,
134 ent_gate *rg )
135 {
136 world_static.last_use = world_static.time;
137
138 /* disable all routes and leave the world */
139 if( rg->type == k_gate_type_nonlocel ){
140 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
141 ent_route *route = mdl_arritm( &world->ent_route, i );
142 route->active_checkpoint = 0xffff;
143 }
144 return;
145 }
146
147 ent_gate *dest = mdl_arritm( &world->ent_gate, rg->target );
148
149 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
150 ent_route *route = mdl_arritm( &world->ent_route, i );
151
152 u32 active_prev = route->active_checkpoint;
153 route->active_checkpoint = 0xffff;
154
155 for( u32 j=0; j<4; j++ ){
156 if( dest->routes[j] == i ){
157 for( u32 k=0; k<route->checkpoints_count; k++ ){
158 ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint,
159 route->checkpoints_start+k );
160
161 ent_gate *gk = mdl_arritm( &world->ent_gate, cp->gate_index );
162 gk = mdl_arritm( &world->ent_gate, gk->target );
163 if( gk == dest ){
164 route->active_checkpoint = k;
165 world_routes_time_lap( world, route );
166 break;
167 }
168 }
169 break;
170 }
171 }
172 }
173
174 dest->timing_version = world_static.current_run_version;
175 dest->timing_time = world_static.time;
176
177 world_static.current_run_version ++;
178 }
179
180 /* draw lines along the paths */
181 VG_STATIC void world_routes_debug( world_instance *world )
182 {
183 for( u32 i=0; i<mdl_arrcount(&world->ent_route_node); i++ ){
184 ent_route_node *rn = mdl_arritm(&world->ent_route_node,i);
185 vg_line_pt3( rn->co, 0.25f, VG__WHITE );
186 }
187
188 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
189 ent_route *route = mdl_arritm(&world->ent_route, i);
190
191 u32 colours[] = { 0xfff58142, 0xff42cbf5, 0xff42f56c, 0xfff542b3,
192 0xff5442f5 };
193
194 u32 cc = 0xffcccccc;
195 if( route->active_checkpoint != 0xffff ){
196 cc = colours[i%vg_list_size(colours)];
197 }
198
199 for( int i=0; i<route->checkpoints_count; i++ ){
200 int i0 = route->checkpoints_start+i,
201 i1 = route->checkpoints_start+((i+1)%route->checkpoints_count);
202
203 ent_checkpoint *c0 = mdl_arritm(&world->ent_checkpoint, i0),
204 *c1 = mdl_arritm(&world->ent_checkpoint, i1);
205
206 ent_gate *start_gate = mdl_arritm( &world->ent_gate, c0->gate_index );
207 ent_gate *end_gate = mdl_arritm( &world->ent_gate, c1->gate_index );
208
209 v3f p0, p1;
210 v3_copy( start_gate->co[1], p0 );
211
212 for( int j=0; j<c0->path_count; j ++ ){
213 ent_path_index *index = mdl_arritm( &world->ent_path_index,
214 c0->path_start+j );
215
216 ent_route_node *rn = mdl_arritm( &world->ent_route_node,
217 index->index );
218
219 v3_copy( rn->co, p1 );
220 vg_line( p0, p1, cc );
221 v3_copy( p1, p0 );
222 }
223
224 v3_copy( end_gate->co[0], p1 );
225 vg_line( p0, p1, cc );
226 }
227 }
228 }
229
230 VG_STATIC
231 void world_routes_pointcloud_spot( world_instance *world,
232 pointcloud_buffer *pcbuf,
233 v3f co, f32 radius, u32 samples, v4f colour )
234 {
235 v3f inv_ext;
236 v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext );
237 v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext );
238
239 for( u32 j=0; j<samples; j++ ){
240 if( pcbuf->count >= pcbuf->max )
241 return;
242
243 pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ];
244
245 v3f sample, jitter, point;
246 vg_rand_sphere( jitter );
247 v3_muladds( co, jitter, radius, sample );
248
249 if( bh_closest_point( world->geo_bh, sample, point, radius*1.5f ) == -1 ){
250 v3_copy( sample, point );
251 }
252
253 v3f pos;
254 v3_sub( point, pcbuf->boundary[0], pos );
255 v3_mul( pos, inv_ext, pos );
256
257 for( u32 i=0; i<3; i++ ){
258 vert->pos[i] = (pos[i]-0.5f) * 32767.0f;
259 }
260
261 float dist = 1.0f-(v3_length(jitter));
262
263 for( u32 i=0; i<4; i++ ){
264 vert->colour[i] = colour[i] * 255.0f * dist*dist;
265 }
266 }
267 }
268
269 /*
270 * '
271 * .
272 * |
273 * |
274 * /#\
275 * -'###`-
276 */
277 VG_STATIC
278 void world_routes_pointcloud_tower( world_instance *world,
279 pointcloud_buffer *pcbuf,
280 v3f co, f32 radius, f32 height,
281 u32 samples, v4f colour )
282 {
283 v3f inv_ext;
284 v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext );
285 v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext );
286
287 for( u32 j=0; j<samples; j++ ){
288 if( pcbuf->count >= pcbuf->max )
289 return;
290
291 pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ];
292
293 v3f point;
294 point[0] = vg_randf64()*2.0f-1.0f;
295 point[1] = 0.0f;
296 point[2] = vg_randf64()*2.0f-1.0f;
297 v3_normalize( point );
298 v3_muls( point, sqrtf(vg_randf64()), point );
299
300 f32 h = vg_randf64();
301 point[1] = h*h*h*height;
302 point[0] *= radius;
303 point[2] *= radius;
304
305 v3_add( point, co, point );
306 v3_sub( point, pcbuf->boundary[0], point );
307 v3_mul( point, inv_ext, point );
308
309 /* TODO....... */
310 for( u32 i=0; i<3; i++ ){
311 vert->pos[i] = (point[i]-0.5f) * 32767.0f;
312 }
313
314 for( u32 i=0; i<4; i++ ){
315 vert->colour[i] = colour[i] * 255.0f;
316 }
317 }
318 }
319
320 VG_STATIC
321 void world_routes_place_curve( world_instance *world, ent_route *route,
322 v4f h[3], v3f n0, v3f n2, scene_context *scene,
323 pointcloud_buffer *pcbuf )
324 {
325 float t;
326 v3f p, pd;
327 int last_valid=0;
328
329 float total_length = 0.0f,
330 travel_length = 0.0;
331
332 v3f last;
333 v3_copy( h[0], last );
334 for( int it=0; it<128; it ++ ){
335 t = (float)(it+1) * (1.0f/128.0f);
336 eval_bezier3( h[0], h[1], h[2], t, p );
337 total_length += v3_dist( p, last );
338 v3_copy( p, last );
339 }
340
341 float patch_size = 4.0f,
342 patch_count = ceilf( total_length / patch_size );
343
344 t = 0.0f;
345 v3_copy( h[0], last );
346
347 for( int it=0; it<128; it ++ ){
348 float const k_sample_dist = 0.0025f,
349 k_line_width = 1.5f;
350
351 eval_bezier3( h[0], h[1], h[2], t, p );
352 eval_bezier3( h[0], h[1], h[2], t+k_sample_dist, pd );
353
354 travel_length += v3_dist( p, last );
355
356 float mod = k_sample_dist / v3_dist( p, pd );
357
358 v3f v0,up, right;
359
360 v3_muls( n0, -(1.0f-t), up );
361 v3_muladds( up, n2, -t, up );
362 v3_normalize( up );
363
364 v3_sub( pd,p,v0 );
365 v3_cross( up, v0, right );
366 v3_normalize( right );
367
368 float cur_x = (1.0f-t)*h[0][3] + t*h[2][3];
369
370 v3f sc, sa, sb, down;
371 v3_muladds( p, right, cur_x * k_line_width, sc );
372 v3_muladds( sc, up, 1.5f, sc );
373 v3_muladds( sc, right, k_line_width*0.95f, sa );
374 v3_muladds( sc, right, 0.0f, sb );
375 v3_muls( up, -1.0f, down );
376
377 ray_hit ha, hb;
378 ha.dist = 8.0f;
379 hb.dist = 8.0f;
380
381 int resa = ray_world( world, sa, down, &ha ),
382 resb = ray_world( world, sb, down, &hb );
383
384 if( pcbuf && resa ){
385 world_routes_pointcloud_spot( world, pcbuf, ha.pos,
386 12.0f, 10, route->colour );
387 }
388
389 if( resa && resb ){
390 struct world_surface *surfa = ray_hit_surface( world, &ha ),
391 *surfb = ray_hit_surface( world, &hb );
392
393 if( (surfa->info.flags & k_material_flag_skate_target) &&
394 (surfb->info.flags & k_material_flag_skate_target) )
395 {
396 scene_vert va, vb;
397
398 float gap = vg_fractf(cur_x*0.5f)*0.02f;
399
400 v3_muladds( ha.pos, up, 0.06f+gap, va.co );
401 v3_muladds( hb.pos, up, 0.06f+gap, vb.co );
402
403 scene_vert_pack_norm( &va, up );
404 scene_vert_pack_norm( &vb, up );
405
406 float t1 = (travel_length / total_length) * patch_count;
407 va.uv[0] = t1;
408 va.uv[1] = 0.0f;
409 vb.uv[0] = t1;
410 vb.uv[1] = 1.0f;
411
412 scene_push_vert( scene, &va );
413 scene_push_vert( scene, &vb );
414
415 if( last_valid ){
416 /* Connect them with triangles */
417 scene_push_tri( scene, (u32[3]){
418 last_valid+0-2, last_valid+1-2, last_valid+2-2} );
419 scene_push_tri( scene, (u32[3]){
420 last_valid+1-2, last_valid+3-2, last_valid+2-2} );
421 }
422
423 last_valid = scene->vertex_count;
424 }
425 else
426 last_valid = 0;
427 }
428 else
429 last_valid = 0;
430
431 if( t == 1.0f )
432 return;
433
434 t += 1.0f*mod;
435 if( t > 1.0f )
436 t = 1.0f;
437
438 v3_copy( p, last );
439 }
440 }
441
442 VG_STATIC void world_routes_gen_meshes( world_instance *world, u32 route_id,
443 scene_context *sc,
444 pointcloud_buffer *pcbuf )
445 {
446 ent_route *route = mdl_arritm( &world->ent_route, route_id );
447 u8 colour[4];
448 colour[0] = route->colour[0] * 255.0f;
449 colour[1] = route->colour[1] * 255.0f;
450 colour[2] = route->colour[2] * 255.0f;
451 colour[3] = route->colour[3] * 255.0f;
452
453 u32 last_valid = 0;
454
455 for( int i=0; i<route->checkpoints_count; i++ ){
456 int i0 = route->checkpoints_start+i,
457 i1 = route->checkpoints_start+((i+1)%route->checkpoints_count);
458
459 ent_checkpoint *c0 = mdl_arritm(&world->ent_checkpoint, i0),
460 *c1 = mdl_arritm(&world->ent_checkpoint, i1);
461
462 ent_gate *start_gate = mdl_arritm( &world->ent_gate, c0->gate_index );
463 start_gate = mdl_arritm( &world->ent_gate, start_gate->target );
464
465 ent_gate *end_gate = mdl_arritm( &world->ent_gate, c1->gate_index ),
466 *collector = mdl_arritm( &world->ent_gate, end_gate->target );
467
468 v4f p[3];
469
470 v3_add( (v3f){0.0f,0.1f,0.0f}, start_gate->co[0], p[0] );
471 p[0][3] = start_gate->ref_count;
472 p[0][3] -= (float)start_gate->route_count * 0.5f;
473 start_gate->ref_count ++;
474
475 if( !c0->path_count )
476 continue;
477
478 /* this is so that we get nice flow through the gates */
479 v3f temp_alignments[2];
480 ent_gate *both[] = { start_gate, end_gate };
481
482 for( int j=0; j<2; j++ ){
483 int pi = c0->path_start + ((j==1)? c0->path_count-1: 0);
484
485 ent_path_index *index = mdl_arritm( &world->ent_path_index, pi );
486 ent_route_node *rn = mdl_arritm( &world->ent_route_node,
487 index->index );
488 v3f v0;
489 v3_sub( rn->co, both[j]->co[0], v0 );
490 float d = v3_dot( v0, both[j]->to_world[2] );
491
492 v3_muladds( both[j]->co[0], both[j]->to_world[2], d,
493 temp_alignments[j] );
494 v3_add( (v3f){0.0f,0.1f,0.0f}, temp_alignments[j], temp_alignments[j]);
495 }
496
497
498 for( int j=0; j<c0->path_count; j ++ ){
499 ent_path_index *index = mdl_arritm( &world->ent_path_index,
500 c0->path_start+j );
501 ent_route_node *rn = mdl_arritm( &world->ent_route_node,
502 index->index );
503 if( j==0 || j==c0->path_count-1 )
504 if( j == 0 )
505 v3_copy( temp_alignments[0], p[1] );
506 else
507 v3_copy( temp_alignments[1], p[1] );
508 else
509 v3_copy( rn->co, p[1] );
510
511 p[1][3] = rn->ref_count;
512 p[1][3] -= (float)rn->ref_total * 0.5f;
513 rn->ref_count ++;
514
515 if( j+1 < c0->path_count ){
516 index = mdl_arritm( &world->ent_path_index,
517 c0->path_start+j+1 );
518 rn = mdl_arritm( &world->ent_route_node, index->index );
519
520 if( j+1 == c0->path_count-1 )
521 v3_lerp( p[1], temp_alignments[1], 0.5f, p[2] );
522 else
523 v3_lerp( p[1], rn->co, 0.5f, p[2] );
524
525 p[2][3] = rn->ref_count;
526 p[2][3] -= (float)rn->ref_total * 0.5f;
527 }
528 else{
529 v3_copy( end_gate->co[0], p[2] );
530 v3_add( (v3f){0.0f,0.1f,0.0f}, p[2], p[2] );
531 p[2][3] = collector->ref_count;
532
533 if( i == route->checkpoints_count-1)
534 p[2][3] -= 1.0f;
535
536 p[2][3] -= (float)collector->route_count * 0.5f;
537 //collector->ref_count ++;
538 }
539
540 /* p0,p1,p2 bezier patch is complete
541 * --------------------------------------*/
542 v3f surf0, surf2, n0, n2;
543
544 if( bh_closest_point( world->geo_bh, p[0], surf0, 5.0f ) == -1 )
545 v3_add( (v3f){0.0f,-0.1f,0.0f}, p[0], surf0 );
546
547 if( bh_closest_point( world->geo_bh, p[2], surf2, 5.0f ) == -1 )
548 v3_add( (v3f){0.0f,-0.1f,0.0f}, p[2], surf2 );
549
550 v3_sub( surf0, p[0], n0 );
551 v3_sub( surf2, p[2], n2 );
552 v3_normalize( n0 );
553 v3_normalize( n2 );
554
555 world_routes_place_curve( world, route, p, n0, n2, sc, pcbuf );
556
557 /* --- */
558 v4_copy( p[2], p[0] );
559 }
560 }
561
562 scene_copy_slice( sc, &route->sm );
563 }
564
565 VG_STATIC
566 struct world_surface *world_tri_index_surface( world_instance *world,
567 u32 index );
568
569 VG_STATIC f64 world_routes_scatter_surface_points( world_instance *world,
570 pointcloud_buffer *pcbuf,
571 f32 rate )
572 {
573 static f32 densities[] = {
574 [k_surface_prop_concrete] = 2.0f,
575 [k_surface_prop_grass] = 0.8f,
576 [k_surface_prop_metal] = 1.0f,
577 [k_surface_prop_wood] = 2.5f,
578 [k_surface_prop_tiles] = 4.0f
579 };
580
581 /* calculate total area */
582 f64 total_area = 0.0f;
583 for( u32 i=0; i<world->scene_geo.indice_count/3; i++ ){
584 u32 *tri = &world->scene_geo.arrindices[i*3];
585 struct world_surface *surf = world_tri_index_surface( world, tri[0] );
586
587 if( surf->info.shader == k_shader_boundary ||
588 surf->info.shader == k_shader_invisible ) continue;
589
590 if( !(surf->info.flags & k_material_flag_preview_visibile) ) continue;
591
592 scene_vert *va = &world->scene_geo.arrvertices[tri[0]],
593 *vb = &world->scene_geo.arrvertices[tri[1]],
594 *vc = &world->scene_geo.arrvertices[tri[2]];
595
596 v3f v0, v1, vn;
597 v3_sub( vb->co, va->co, v0 );
598 v3_sub( vc->co, va->co, v1 );
599 v3_cross( v0, v1, vn );
600 if( vn[1] < 0.0f ) continue;
601
602 f32 density = 1.0f;
603 if( surf->info.surface_prop < vg_list_size(densities) )
604 density = densities[surf->info.surface_prop];
605 total_area += v3_length(vn)*0.5f*density;
606 }
607
608 f32 accum = 0.0f;
609
610 u8 colour[] = { 80,80,80,255 };
611 v3f light_dir = {0.3f,0.8f,0.1f};
612 v3_normalize( light_dir );
613
614 v3f inv_ext;
615 v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext );
616 v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext );
617
618 for( u32 i=0; i<world->scene_geo.indice_count/3; i++ ){
619 u32 *tri = &world->scene_geo.arrindices[i*3];
620 struct world_surface *surf = world_tri_index_surface( world, tri[0] );
621
622 if( surf->info.shader == k_shader_boundary ||
623 surf->info.shader == k_shader_invisible ) continue;
624
625 if( !(surf->info.flags & k_material_flag_preview_visibile) ) continue;
626
627 scene_vert *va = &world->scene_geo.arrvertices[tri[0]],
628 *vb = &world->scene_geo.arrvertices[tri[1]],
629 *vc = &world->scene_geo.arrvertices[tri[2]];
630
631 v3f v0, v1, vn;
632 v3_sub( vb->co, va->co, v0 );
633 v3_sub( vc->co, va->co, v1 );
634 v3_cross( v0, v1, vn );
635 if( vn[1] < 0.0f ) continue;
636
637 f32 density = 1.0f;
638 if( surf->info.surface_prop < vg_list_size(densities) )
639 density = densities[surf->info.surface_prop];
640
641 f32 area = v3_length(vn)*0.5f*density;
642 accum += area;
643
644 v3_normalize( vn );
645
646 while( accum > rate ){
647 accum -= rate;
648
649 if( pcbuf->count >= pcbuf->max ) return total_area;
650
651 v2f co = { vg_randf64(), vg_randf64() };
652 if( v2_length2(co) > 0.5f ){
653 co[0] = 1.0f-co[0];
654 co[1] = 1.0f-co[1];
655 }
656
657 v3f pt;
658 v3_muls( v0, co[0], pt );
659 v3_muladds( pt, v1, co[1], pt );
660 v3_add( va->co, pt, pt );
661
662 if( pt[1] < world->water.height ) continue;
663 pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ];
664
665 v3f pos;
666 v3_sub( pt, pcbuf->boundary[0], pos );
667 v3_mul( pos, inv_ext, pos );
668
669 for( u32 i=0; i<3; i++ ){
670 vert->pos[i] = (pos[i]-0.5f) * 32767.0f;
671 }
672
673 static v4f colours[] = {
674 [k_surface_prop_concrete] = { 0.13, 0.15, 0.17, 1.0 },
675 [k_surface_prop_grass] = { 0.07, 0.1, 0.14, 1.0 },
676 [k_surface_prop_metal] = { 0.15, 0.19, 0.22, 1.0 },
677 [k_surface_prop_wood] = { 0.1, 0.13, 0.17, 1.0 },
678 [k_surface_prop_tiles] = { 0.05, 0.06, 0.07, 1.0 },
679 };
680
681 v4f col = {0.0f,0.0f,0.0f,0.0f};
682 if( surf->info.surface_prop < vg_list_size(colours) ){
683 v4_copy( colours[surf->info.surface_prop], col );
684 }
685
686 f32 brightness = v3_dot(vn,light_dir)*0.5f+0.5f;
687 v3_muls( col, brightness, col );
688
689 for( u32 j=0; j<4; j++ ){
690 vert->colour[j] = col[j] * 255.0f;
691 }
692 }
693 }
694
695 return total_area;
696 }
697
698 VG_STATIC void world_routes_surface_grid( world_instance *world,
699 pointcloud_buffer *pcbuf )
700 {
701 i32 const k_gridlines = 32,
702 k_gridres = 255;
703
704 v3f inv_ext;
705 v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext );
706 v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext );
707 v4f colour = {0.2f,0.2f,0.2f,1.0f};
708 v3f dir = {0.0f,-1.0f,0.0f};
709
710 for( u32 k=0; k<2; k++ ){
711 u32 a = k*2,
712 b = (k^0x1)*2;
713
714 for( i32 x=0; x<=k_gridlines; x++ ){
715 f32 t = (float)x / (float)k_gridlines,
716 px = vg_lerpf( pcbuf->boundary[0][a], pcbuf->boundary[1][a], t );
717
718 for( i32 z=0; z<=k_gridres; z++ ){
719 f32 tz = (float)z / (float)k_gridres,
720 pz = vg_lerpf(pcbuf->boundary[0][b],pcbuf->boundary[1][b], tz);
721
722 v3f ro, hit;
723 ro[a] = px;
724 ro[1] = 1000.0f;
725 ro[b] = pz;
726
727 bh_iter it;
728 bh_iter_init_ray( 0, &it, ro, dir, INFINITY );
729 i32 idx;
730
731 while( bh_next( world->geo_bh, &it, &idx ) ){
732 u32 *tri = &world->scene_geo.arrindices[ idx*3 ];
733 v3f vs[3];
734
735 for( u32 i=0; i<3; i++ ){
736 v3_copy( world->scene_geo.arrvertices[tri[i]].co, vs[i] );
737 }
738
739 f32 t;
740 if( ray_tri( vs, ro, dir, &t ) ){
741 v3_muladds( ro, dir, t, hit );
742 struct world_surface *m1 =
743 world_tri_index_surface( world, tri[0] );
744
745 if( !(m1->info.flags & k_material_flag_preview_visibile) )
746 continue;
747
748 if( world->water.enabled )
749 if( hit[1] < world->water.height )
750 continue;
751
752 if( pcbuf->count >= pcbuf->max ) return;
753
754 pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ];
755
756 v3f co;
757 v3_sub( hit, pcbuf->boundary[0], co );
758 v3_mul( co, inv_ext, co );
759
760 for( u32 i=0; i<3; i++ ){
761 vert->pos[i] = (co[i]-0.5f) * 32767.0f;
762 }
763
764 for( u32 i=0; i<4; i++ ){
765 vert->colour[i] = colour[i] * 255.0f;
766 }
767 }
768 }
769 }
770 }
771 }
772 }
773
774 /*
775 * Create the strips of colour that run through the world along course paths
776 */
777 VG_STATIC void world_gen_routes_generate(void)
778 {
779 world_instance *world = world_loading_instance();
780 vg_info( "Generating route meshes\n" );
781 vg_async_stall();
782
783 vg_rand_seed( 2000 );
784 vg_async_item *call_scene = scene_alloc_async( &world->scene_lines,
785 &world->mesh_route_lines,
786 200000, 300000 );
787
788 vg_async_item *call_pointcloud = NULL;
789 pointcloud_buffer *pcbuf = NULL;
790
791 if( world_loader.generate_point_cloud ){
792 call_pointcloud = vg_async_alloc(
793 sizeof(pointcloud_buffer) +
794 sizeof(pointcloud_vert)*POINTCLOUD_POINTS );
795 pcbuf = call_pointcloud->payload;
796 pcbuf->count = 0;
797 pcbuf->max = POINTCLOUD_POINTS;
798 pcbuf->op = k_pointcloud_op_clear;
799
800 v3f ext, mid, v0;
801 v3_sub( world->scene_geo.bbx[1], world->scene_geo.bbx[0], ext );
802 f32 maxe = v3_maxf( ext );
803 v3_fill( v0, maxe * 0.5f );
804 v3_muladds( world->scene_geo.bbx[0], ext, 0.5f, mid );
805 v3_add( mid, v0, pcbuf->boundary[1] );
806 v3_sub( mid, v0, pcbuf->boundary[0] );
807 }
808
809 for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ ){
810 ent_gate *gate = mdl_arritm( &world->ent_gate, i );
811 gate->ref_count = 0;
812 gate->route_count = 0;
813 }
814
815 for( u32 i=0; i<mdl_arrcount(&world->ent_route_node); i++ ){
816 ent_route_node *rn = mdl_arritm( &world->ent_route_node, i );
817 rn->ref_count = 0;
818 rn->ref_total = 0;
819 }
820
821 for( u32 k=0; k<mdl_arrcount(&world->ent_route); k++ ){
822 ent_route *route = mdl_arritm( &world->ent_route, k );
823
824 for( int i=0; i<route->checkpoints_count; i++ ){
825 int i0 = route->checkpoints_start+i,
826 i1 = route->checkpoints_start+((i+1)%route->checkpoints_count);
827
828 ent_checkpoint *c0 = mdl_arritm(&world->ent_checkpoint, i0),
829 *c1 = mdl_arritm(&world->ent_checkpoint, i1);
830
831 ent_gate *start_gate = mdl_arritm( &world->ent_gate, c0->gate_index );
832 start_gate = mdl_arritm( &world->ent_gate, start_gate->target );
833 start_gate->route_count ++;
834
835 if( !c0->path_count )
836 continue;
837
838 for( int j=0; j<c0->path_count; j ++ ){
839 ent_path_index *index = mdl_arritm( &world->ent_path_index,
840 c0->path_start+j );
841 ent_route_node *rn = mdl_arritm( &world->ent_route_node,
842 index->index );
843 rn->ref_total ++;
844 }
845 }
846 }
847
848 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
849 world_routes_gen_meshes( world, i, &world->scene_lines, pcbuf );
850 }
851
852 if( world_loader.generate_point_cloud ){
853 f64 area = 0.0;
854 area = world_routes_scatter_surface_points( world, pcbuf, 16.0f );
855 world_routes_surface_grid( world, pcbuf );
856
857 for( u32 i=0; i<mdl_arrcount( &world->ent_gate ); i++ ){
858 ent_gate *gate = mdl_arritm( &world->ent_gate, i );
859
860 world_routes_pointcloud_tower( world, pcbuf, gate->co[0],
861 2.0f, 50.0f, 128,
862 (v4f){0.2f,0.2f,0.2f,1.0f} );
863 }
864
865 vg_info( "Distrubuted %u points over %fkm^2!\n",
866 pcbuf->count, area/1e6f );
867
868 if( world_loader.location == k_world_load_type_local ){
869 char path_buf[4096];
870 vg_str path;
871 vg_strnull( &path, path_buf, 4096 );
872 vg_strcat( &path, "maps/" );
873 vg_strcat( &path, world_loader.name );
874 vg_strcat( &path, "/preview.bin" );
875
876 if( !vg_strgood( &path ) ) vg_fatal_error( "Path too long\n" );
877 FILE *fp = fopen( path_buf, "wb" );
878 if( !fp ) vg_fatal_error( "Cannot open '%s' for writing\n", path_buf );
879
880 fwrite( pcbuf, sizeof(pcbuf) +
881 sizeof(struct pointcloud_vert)*pcbuf->count, 1, fp );
882 fclose( fp );
883 }
884
885 vg_async_dispatch( call_pointcloud, async_pointcloud_sub );
886 }
887
888 vg_async_dispatch( call_scene, async_scene_upload );
889 world_routes_clear( world );
890 }
891
892 /* load all routes from model header */
893 VG_STATIC void world_gen_routes_ent_init(void)
894 {
895 world_instance *world = world_loading_instance();
896 vg_info( "Initializing routes\n" );
897
898 for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ ){
899 ent_gate *gate = mdl_arritm( &world->ent_gate, i );
900 for( u32 j=0; j<4; j++ ){
901 gate->routes[j] = 0xffff;
902 }
903 }
904
905 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
906 ent_route *route = mdl_arritm(&world->ent_route,i);
907 mdl_transform_m4x3( &route->transform, route->board_transform );
908
909 route->official_track_id = 0xffffffff;
910 for( u32 j=0; j<vg_list_size(track_infos); j ++ ){
911 if( !strcmp(track_infos[j].name,
912 mdl_pstr(&world->meta,route->pstr_name))){
913 route->official_track_id = j;
914 }
915 }
916
917 for( u32 j=0; j<route->checkpoints_count; j++ ){
918 u32 id = route->checkpoints_start + j;
919 ent_checkpoint *cp = mdl_arritm(&world->ent_checkpoint,id);
920
921 ent_gate *gate = mdl_arritm( &world->ent_gate, cp->gate_index );
922
923 for( u32 k=0; k<4; k++ ){
924 if( gate->routes[k] == 0xffff ){
925 gate->routes[k] = i;
926 break;
927 }
928 }
929
930 if( gate->type == k_gate_type_teleport ){
931 gate = mdl_arritm(&world->ent_gate, gate->target );
932
933 for( u32 k=0; k<4; k++ ){
934 if( gate->routes[k] == i ){
935 vg_error( "already assigned route to gate\n" );
936 break;
937 }
938 if( gate->routes[k] == 0xffff ){
939 gate->routes[k] = i;
940 break;
941 }
942 }
943 }
944 }
945 }
946
947 for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ ){
948 ent_gate *gate = mdl_arritm( &world->ent_gate, i );
949 }
950
951 world_routes_clear( world );
952 }
953
954 /*
955 * -----------------------------------------------------------------------------
956 * Events
957 * -----------------------------------------------------------------------------
958 */
959
960 VG_STATIC void world_routes_init(void)
961 {
962 world_static.current_run_version = 200;
963 world_static.time = 300.0;
964 world_static.last_use = 0.0;
965
966 shader_scene_route_register();
967 shader_routeui_register();
968 }
969
970 VG_STATIC void world_routes_update( world_instance *world )
971 {
972 world_static.time += vg.time_delta;
973
974 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
975 ent_route *route = mdl_arritm( &world->ent_route, i );
976
977 int target = route->active_checkpoint == 0xffff? 0: 1;
978 route->factive = vg_lerpf( route->factive, target, 0.6f*vg.time_delta );
979 }
980
981 for( u32 i=0; i<world_render.text_particle_count; i++ ){
982 struct text_particle *particle = &world_render.text_particles[i];
983 rb_object_debug( &particle->obj, VG__RED );
984 }
985 }
986
987 VG_STATIC void world_routes_fixedupdate( world_instance *world )
988 {
989 rb_solver_reset();
990
991 for( u32 i=0; i<world_render.text_particle_count; i++ ){
992 struct text_particle *particle = &world_render.text_particles[i];
993
994 if( rb_global_has_space() ){
995 rb_ct *buf = rb_global_buffer();
996
997 int l = rb_sphere__scene( particle->obj.rb.to_world,
998 &particle->obj.inf.sphere,
999 NULL, &world->rb_geo.inf.scene, buf );
1000
1001 for( int j=0; j<l; j++ ){
1002 buf[j].rba = &particle->obj.rb;
1003 buf[j].rbb = &world->rb_geo.rb;
1004 }
1005
1006 rb_contact_count += l;
1007 }
1008 }
1009
1010 rb_presolve_contacts( rb_contact_buffer, rb_contact_count );
1011
1012 for( int i=0; i<rb_contact_count; i++ ){
1013 rb_contact_restitution( rb_contact_buffer+i, vg_randf64() );
1014 }
1015
1016 for( int i=0; i<6; i++ ){
1017 rb_solve_contacts( rb_contact_buffer, rb_contact_count );
1018 }
1019
1020 for( u32 i=0; i<world_render.text_particle_count; i++ ){
1021 struct text_particle *particle = &world_render.text_particles[i];
1022 rb_iter( &particle->obj.rb );
1023 }
1024
1025 for( u32 i=0; i<world_render.text_particle_count; i++ ){
1026 struct text_particle *particle = &world_render.text_particles[i];
1027 rb_update_transform( &particle->obj.rb );
1028 }
1029 }
1030
1031 VG_STATIC void bind_terrain_noise(void);
1032 VG_STATIC void world_bind_light_array( world_instance *world,
1033 GLuint shader, GLuint location,
1034 int slot );
1035 VG_STATIC void world_bind_light_index( world_instance *world,
1036 GLuint shader, GLuint location,
1037 int slot );
1038
1039 VG_STATIC void world_routes_update_timer_texts( world_instance *world )
1040 {
1041 world_render.timer_text_count = 0;
1042
1043 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
1044 ent_route *route = mdl_arritm( &world->ent_route, i );
1045
1046 if( route->active_checkpoint != 0xffff ){
1047 u32 next = route->active_checkpoint+1;
1048 next = next % route->checkpoints_count;
1049 next += route->checkpoints_start;
1050
1051 ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, next );
1052 ent_gate *gate = mdl_arritm( &world->ent_gate, cp->gate_index );
1053 ent_gate *dest = mdl_arritm( &world->ent_gate, gate->target );
1054
1055 u32 j=0;
1056 for( ; j<4; j++ ){
1057 if( dest->routes[j] == i ){
1058 break;
1059 }
1060 }
1061
1062 float h0 = 0.8f,
1063 h1 = 1.2f,
1064 depth = 0.4f,
1065 size = 0.4f;
1066
1067 struct timer_text *text =
1068 &world_render.timer_texts[ world_render.timer_text_count ++ ];
1069
1070 text->gate = gate;
1071 text->route = route;
1072
1073 if( route->valid_checkpoints >= route->checkpoints_count ){
1074 double lap_time = world_static.time - route->timing_base,
1075 time_centiseconds = lap_time * 100.0;
1076
1077 if( time_centiseconds > (float)0xfffe ) time_centiseconds = 0.0;
1078
1079 u16 centiseconds = time_centiseconds,
1080 seconds = centiseconds / 100,
1081 minutes = seconds / 60;
1082
1083 centiseconds %= 100;
1084 seconds %= 60;
1085 minutes %= 60;
1086
1087 if( minutes > 9 ) minutes = 9;
1088
1089 int j=0;
1090 if( minutes ){
1091 highscore_intr( text->text, minutes, 1, ' ' ); j++;
1092 text->text[j++] = ':';
1093 }
1094
1095 if( seconds >= 10 || minutes ){
1096 highscore_intr( text->text+j, seconds, 2, '0' ); j+=2;
1097 }
1098 else{
1099 highscore_intr( text->text+j, seconds, 1, '0' ); j++;
1100 }
1101
1102 text->text[j++] = '.';
1103 highscore_intr( text->text+j, centiseconds, 1, '0' ); j++;
1104 text->text[j] = '\0';
1105 }
1106 else{
1107 highscore_intr( text->text, route->valid_checkpoints, 1, ' ' );
1108 text->text[1] = '/';
1109 highscore_intr( text->text+2, route->checkpoints_count+1, 1, ' ' );
1110 text->text[3] = '\0';
1111 }
1112
1113 float align_r = font3d_string_width( &gui.font, 0, text->text );
1114 align_r *= size;
1115
1116 v3f positions[] = {
1117 { -0.92f, h0, depth },
1118 { 0.92f - align_r, h0, depth },
1119 { -0.92f, h1, depth },
1120 { 0.92f - align_r, h1, depth },
1121 };
1122
1123 if( dest->route_count == 1 ){
1124 positions[0][0] = -align_r*0.5f;
1125 positions[0][1] = h1;
1126 }
1127
1128 m3x3_copy( gate->to_world, text->transform );
1129 float ratio = v3_length(text->transform[0]) /
1130 v3_length(text->transform[1]);
1131
1132 m3x3_scale( text->transform, (v3f){ size, size*ratio, 0.1f } );
1133 m4x3_mulv( gate->to_world, positions[j], text->transform[3] );
1134 }
1135 }
1136 }
1137
1138 VG_STATIC void world_routes_fracture( world_instance *world, ent_gate *gate,
1139 v3f imp_co, v3f imp_v )
1140 {
1141 world_render.text_particle_count = 0;
1142
1143 for( u32 i=0; i<world_render.timer_text_count; i++ ){
1144 struct timer_text *text = &world_render.timer_texts[i];
1145
1146 if( text->gate != gate ) continue;
1147
1148 m4x3f transform;
1149 m4x3_mul( gate->transport, text->transform, transform );
1150
1151 v3f co, s;
1152 v4f q;
1153 m4x3_decompose( transform, co, q, s );
1154
1155 v3f offset;
1156 v3_zero( offset );
1157
1158 v4f colour;
1159 float brightness = 0.3f + world->ub_lighting.g_day_phase;
1160 v3_muls( text->route->colour, brightness, colour );
1161 colour[3] = 1.0f-text->route->factive;
1162
1163 for( u32 j=0;; j++ ){
1164 char c = text->text[j];
1165 if( !c ) break;
1166
1167 ent_glyph *glyph = font3d_glyph( &gui.font, 0, c );
1168 if( !glyph ) continue;
1169
1170 if( c >= (u32)'0' && c <= (u32)'9' && glyph->indice_count ){
1171 struct text_particle *particle =
1172 &world_render.text_particles[world_render.text_particle_count++];
1173
1174 particle->glyph = glyph;
1175 v4_copy( colour, particle->colour );
1176
1177 v3f origin;
1178 v2_muls( glyph->size, 0.5f, origin );
1179 origin[2] = -0.5f;
1180
1181 v3f world_co;
1182
1183 v3_add( offset, origin, world_co );
1184 m4x3_mulv( transform, world_co, world_co );
1185
1186 float r = vg_maxf( s[0]*glyph->size[0], s[1]*glyph->size[1] )*0.5f;
1187
1188 m3x3_identity( particle->mlocal );
1189 m3x3_scale( particle->mlocal, s );
1190 origin[2] *= s[2];
1191 v3_muls( origin, -1.0f, particle->mlocal[3] );
1192
1193 v3_copy( world_co, particle->obj.rb.co );
1194 v3_muls( imp_v, 1.0f+vg_randf64(), particle->obj.rb.v );
1195 particle->obj.rb.v[1] += 2.0f;
1196
1197 v4_copy( q, particle->obj.rb.q );
1198 particle->obj.rb.w[0] = vg_randf64()*2.0f-1.0f;
1199 particle->obj.rb.w[1] = vg_randf64()*2.0f-1.0f;
1200 particle->obj.rb.w[2] = vg_randf64()*2.0f-1.0f;
1201
1202 particle->obj.type = k_rb_shape_sphere;
1203 particle->obj.inf.sphere.radius = r*0.6f;
1204
1205 rb_init_object( &particle->obj );
1206 }
1207 offset[0] += glyph->size[0];
1208 }
1209 }
1210 }
1211
1212 VG_STATIC void render_world_routes( world_instance *world, camera *cam,
1213 int layer_depth )
1214 {
1215 m4x3f identity_matrix;
1216 m4x3_identity( identity_matrix );
1217
1218 shader_scene_route_use();
1219 shader_scene_route_uTexGarbage(0);
1220 world_link_lighting_ub( world, _shader_scene_route.id );
1221 world_bind_position_texture( world, _shader_scene_route.id,
1222 _uniform_scene_route_g_world_depth, 2 );
1223 world_bind_light_array( world, _shader_scene_route.id,
1224 _uniform_scene_route_uLightsArray, 3 );
1225 world_bind_light_index( world, _shader_scene_route.id,
1226 _uniform_scene_route_uLightsIndex, 4 );
1227 bind_terrain_noise();
1228
1229 shader_scene_route_uPv( cam->mtx.pv );
1230 shader_scene_route_uPvmPrev( cam->mtx_prev.pv );
1231 shader_scene_route_uMdl( identity_matrix );
1232 shader_scene_route_uCamera( cam->transform[3] );
1233
1234 mesh_bind( &world->mesh_route_lines );
1235
1236 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
1237 ent_route *route = mdl_arritm( &world->ent_route, i );
1238
1239 v4f colour;
1240 v3_lerp( (v3f){0.7f,0.7f,0.7f}, route->colour, route->factive, colour );
1241 colour[3] = route->factive*0.2f;
1242
1243 shader_scene_route_uColour( colour );
1244 mdl_draw_submesh( &route->sm );
1245 }
1246
1247 /* timers
1248 * ---------------------------------------------------- */
1249 if( layer_depth == 0 ){
1250 font3d_bind( &gui.font, cam );
1251
1252 for( u32 i=0; i<world_render.timer_text_count; i++ ){
1253 struct timer_text *text = &world_render.timer_texts[i];
1254
1255 v4f colour;
1256 float brightness = 0.3f + world->ub_lighting.g_day_phase;
1257 v3_muls( text->route->colour, brightness, colour );
1258 colour[3] = 1.0f-text->route->factive;
1259
1260 shader_model_font_uColour( colour );
1261 font3d_simple_draw( &gui.font, 0, text->text, cam, text->transform );
1262 }
1263
1264 shader_model_font_uOffset( (v4f){0.0f,0.0f,0.0f,1.0f} );
1265
1266 for( u32 i=0; i<world_render.text_particle_count; i++ ){
1267 struct text_particle *particle = &world_render.text_particles[i];
1268
1269 m4x4f prev_mtx;
1270
1271 m4x3_expand( particle->mdl, prev_mtx );
1272 m4x4_mul( cam->mtx_prev.pv, prev_mtx, prev_mtx );
1273
1274 shader_model_font_uPvmPrev( prev_mtx );
1275
1276 v4f q;
1277 m4x3f model;
1278 rb_extrapolate( &particle->obj.rb, model[3], q );
1279 q_m3x3( q, model );
1280
1281 m4x3_mul( model, particle->mlocal, particle->mdl );
1282 shader_model_font_uMdl( particle->mdl );
1283 shader_model_font_uColour( particle->colour );
1284
1285 mesh_drawn( particle->glyph->indice_start,
1286 particle->glyph->indice_count );
1287 }
1288 }
1289
1290 /* gate markers
1291 * ---------------------------------------------------- */
1292
1293 shader_model_gate_use();
1294 shader_model_gate_uPv( cam->mtx.pv );
1295 shader_model_gate_uCam( cam->pos );
1296 shader_model_gate_uTime( vg.time*0.25f );
1297 shader_model_gate_uInvRes( (v2f){
1298 1.0f / (float)vg.window_x,
1299 1.0f / (float)vg.window_y });
1300
1301 mesh_bind( &world_gates.mesh );
1302
1303 /* skip writing into the motion vectors for this */
1304 glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } );
1305
1306 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
1307 ent_route *route = mdl_arritm( &world->ent_route, i );
1308
1309 if( route->active_checkpoint != 0xffff ){
1310 v4f colour;
1311 float brightness = 0.3f + world->ub_lighting.g_day_phase;
1312 v3_muls( route->colour, brightness, colour );
1313 colour[3] = 1.0f-route->factive;
1314
1315 shader_model_gate_uColour( colour );
1316
1317 u32 next = route->active_checkpoint+1+layer_depth;
1318 next = next % route->checkpoints_count;
1319 next += route->checkpoints_start;
1320
1321 ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, next );
1322 ent_gate *gate = mdl_arritm( &world->ent_gate, cp->gate_index );
1323 shader_model_gate_uMdl( gate->to_world );
1324
1325 for( u32 j=0; j<4; j++ ){
1326 if( gate->routes[j] == i ){
1327 mdl_draw_submesh( &world_gates.sm_marker[j] );
1328 break;
1329 }
1330 }
1331 }
1332 }
1333 glDrawBuffers( 2, (GLenum[]){ GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 } );
1334 }
1335
1336 #endif /* ROUTES_C */