Untitled
Loading...
Searching...
No Matches
render.c
Go to the documentation of this file.
1#include <GL/glew.h>
2#include <assert.h>
3#include "SDL2/SDL_timer.h"
4#include "core/camera.h"
5#include "utilities/mathf.h"
6#include "load/init.h"
7#include "utilities/types.h"
8#include <float.h>
9#include <math.h>
10#include <stdio.h>
11#include <string.h>
12#include "ui/ui.h"
13#include "utilities/utilities.h"
14#include "render/render.h"
16#include "core/engine_types.h"
17#include "core/animation.h"
18#include "ui/fonts.h"
19
20
23
24
30
32{
33
34 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, VERTEX_SSBO);
35 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, TRI_SSBO);
36 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, MESH_SSBO);
37 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 7, MESH_BVH_SSBO);
38 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 8, SCENE_BVH_SSBO);
39 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 9, PROBE_SSBO);
40 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 10, RPROBE_SSBO);
41}
43{
44
45 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, GLOBAL_INSTANCE_SSBO);
46 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, INDIRECT_ARRAYS_COMMAND_BUFFER);
47 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, INDIRECT_ELEMENTS_COMMAND_BUFFER);
48 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 7, INSTANCE_SSBO);
49 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 8, TEXT_BOX_SSBO);
50 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 10, RPROBE_SSBO);
51 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 11, JOINT_SSBO);
52
53}
54
55
57{
58
59
60 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, MESH_LIGHT_SSBO);
61 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, MATERIAL_SSBO);
62 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, LIGHTMAP_SSBO);
63 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, GLOBAL_INSTANCE_SSBO);
64 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, INDIRECT_ARRAYS_COMMAND_BUFFER);
65 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, INDIRECT_ELEMENTS_COMMAND_BUFFER);
66 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 7, INSTANCE_SSBO);
67 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 8, TEXT_BOX_SSBO);
68 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 9, UI_SSBO);
69 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 10, RPROBE_SSBO);
70 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 11, JOINT_SSBO);
71 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 12, CLUSTER_AABB_SSBO);
72 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 13, GLOBAL_LIGHT_INDICES_SSBO);
73 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 14, CLUSTER_SSBO);
74 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 15, MESH_NODE_SSBO);
75
76}
77
78
79
80size_t fill_buffer_with_mesh_tri(Mesh * mesh, MainVertex * verts, size_t offset)
81{
82 MeshFace * tris = (MeshFace *)mesh->tris.buffer;
83 Point * pts = (Point*)mesh->vertices.buffer;
84 size_t count = 0;
85 if (mesh->static_mesh)
86 {
87
89 UVIsland * islands = CAST_VEC(ld->islands, UVIsland);
91 int current_offset = offset;
92 for (int i = 0; i < GLOBALS.mesh_nodes.count; i++)
93 {
94
95 if (mns[i].mesh != mesh->id || mns[i].free) continue;
96 MeshNode * mn = &mns[i];
97 int current_count = 0;
98 mn->offset = current_offset;
99 UVMapping * uv_map = mn->uv_map;
100 for (int j = 0; j < mesh->tris.count; j++)
101 {
102 MeshFace * tri = &tris[j];
103 TriangleAdjacency * tri_adj = mesh->tri_adjacency;
104 UVIsland * uvi = &islands[uv_map[j].uv_island];
105 LightmapUV * uv = &(uvi->uvs[uv_map[j].uv_idx]);
106
107
108 for (int p = 0; p < 3; p++)
109 {
110
111 verts[current_offset + j * 3 + p].pos = pts[tri->indices[p]].pos;
112 verts[current_offset + j * 3 + p].normal = pts[tri->indices[p]].normal;
113 verts[current_offset + j * 3 + p].joint_indices= pts[tri->indices[p]].joints;
114 verts[current_offset + j * 3 + p].weights = pts[tri->indices[p]].weights;
115 verts[current_offset + j * 3 + p].tangent = pts[tri->indices[p]].tangent;
116 verts[current_offset + j * 3 + p].uv = pts[tri->indices[p]].uv;
117 if (islands)
118 {
119
120 LIGHTMAP_DATA.uvs[current_offset + j * 3 + p].uv = (vec4){(*uv[p]).x, (*uv[p]).y, 0, 0};
121 }
122
123 count++;
124
125 current_count++;
126 }
127 }
128 mn->count = current_count;
129 current_offset += current_count;
130 }
131 }
132 else
133 {
134 for (int i = 0; i < mesh->tris.count; i++)
135 {
136 MeshFace * tri = &tris[i];
137 TriangleAdjacency * tri_adj = mesh->tri_adjacency;
138 for (int p = 0; p < 3; p++)
139 {
140
141 verts[offset + i * 3 + p].pos = pts[tri->indices[p]].pos;
142 verts[offset + i * 3 + p].normal = pts[tri->indices[p]].normal;
143 verts[offset + i * 3 + p].joint_indices = pts[tri->indices[p]].joints;
144 verts[offset + i * 3 + p].weights = pts[tri->indices[p]].weights;
145 verts[offset + i * 3 + p].tangent = pts[tri->indices[p]].tangent;
146 verts[offset + i * 3 + p].uv = pts[tri->indices[p]].uv;
147
148 count++;
149 }
150 }
151
152 }
153
154 return count;
155}
156size_t fill_vertex_buffer_mesh(Mesh * mesh, MainVertex * verts, size_t offset, size_t * lm_offset)
157{
158 MeshFace * tris = (MeshFace *)mesh->tris.buffer;
159 Point * pts = (Point*)mesh->vertices.buffer;
160
161 size_t current_lm_offset = *lm_offset;
162 size_t count = 0;
163 if (mesh->static_mesh)
164 {
165
167 UVIsland * islands = CAST_VEC(ld->islands, UVIsland);
169 int current_offset = offset;
170 current_lm_offset = current_offset;
171 SubMesh * sms = CAST_VEC(mesh->submeshes, SubMesh);
172
173 for (int j = 0; j < mesh->submeshes.count; j++)
174 {
175 SubMesh * sm = &sms[j];
176 sm->draw_offset = current_offset;
177
178 int current_count = 0;
179 sm->lm_offset = current_offset;
180
181 for (int k = 0; k < sm->index_count / 3; k++)
182 {
183 size_t idx = k + sm->first_index / 3;
184 MeshFace * tri = &tris[idx];
185 TriangleAdjacency * tri_adj = mesh->tri_adjacency;
186
187 for (int p = 0; p < 3; p++)
188 {
189
190 int index = tri->indices[p];
191
192 verts[current_offset].pos = pts[index].pos;
193 verts[current_offset].normal = pts[index].normal;
194 verts[current_offset].tangent = pts[index].tangent;
195 verts[current_offset].joint_indices = pts[index].joints;
196 verts[current_offset].weights = pts[index].weights;
197 verts[current_offset].uv = pts[index].uv;
198 count++;
199 current_count++;
200 current_offset++;
201 }
202 }
203 if (!islands) continue;
204 int mesh_count = 0;
205 for (int i = 0; i < GLOBALS.mesh_nodes.count; i++)
206 {
207
208 if (mns[i].mesh != mesh->id || mns[i].free || !mns[i].uv_map) continue;
209
210 MeshNode * mn = &mns[i];
211 UVMapping * uv_map = mn->uv_map;
212
213
214 for (int k = 0; k < sm->index_count / 3; k++)
215 {
216
217 size_t idx = k + sm->first_index / 3;
218 MeshFace * tri = &tris[idx];
219 TriangleAdjacency * tri_adj = mesh->tri_adjacency;
220
221 if (uv_map)
222 {
223
224 UVIsland * uvi = &islands[uv_map[idx].uv_island];
225 LightmapUV * uv = &uvi->uvs[uv_map[idx].uv_idx];
226
227 for (int p = 0; p < 3; p++)
228 {
229
230 LIGHTMAP_DATA.uvs[current_lm_offset + idx * 3 + p + mesh_count * sm->index_count].uv = (vec4){(*uv[p]).x, (*uv[p]).y, 0, 0};
231 }
232
233 }
234 }
235 mesh_count++;
236 }
237
238 }
239 }
240 else
241 {
242
243 for (int j = 0; j < mesh->vertices.count; j++)
244 {
245 verts[offset + j].pos = pts[j].pos;
246 verts[offset + j].normal = pts[j].normal;
247 verts[offset + j].tangent = pts[j].tangent;
248 verts[offset + j].joint_indices = pts[j].joints;
249 verts[offset + j].weights = pts[j].weights;
250 verts[offset + j].uv = pts[j].uv;
251
252 count++;
253 }
254 }
255
256 return count;
257}
258size_t fill_index_buffer_mesh(Mesh * mesh, uint32_t * indices, size_t vertex_offset, size_t offset, size_t * lm_uv_offset)
259{
260 size_t current_lm_offset = *lm_uv_offset;
261
262 MeshFace * tris = (MeshFace *)mesh->tris.buffer;
263 Point * pts = (Point*)mesh->vertices.buffer;
264 size_t count = 0;
265 if (!mesh->static_mesh)
266 {
267 SubMesh * sms = CAST_VEC(mesh->submeshes, SubMesh);
268
269 for (int j = 0; j < mesh->submeshes.count; j++)
270 {
271 SubMesh * sm = &sms[j];
272
273 sm->draw_offset = offset + count;
274 sm->lm_offset = 0;
275 for (int k = 0; k < sm->index_count / 3; k++)
276 {
277 size_t idx = k + sm->first_index / 3;
278 MeshFace * tri = &tris[idx];
279 TriangleAdjacency * tri_adj = mesh->tri_adjacency;
280 for (int p = 0; p < 3; p++)
281 {
282
283 indices[offset + count] = tri->indices[p] + vertex_offset;
284 count++;
285
286 }
287 }
288 }
289 }
290
291
292 *lm_uv_offset = current_lm_offset;
293
294 return count;
295 // }
296
297}
298
300{
301
303 if (m->static_mesh)
304 {
305 int count = 0;
306
307 for (int i = 0; i < GLOBALS.mesh_nodes.count; i++)
308 {
309 MeshNode * mn = &mns[i];
310
311
312 if (mns[i].mesh != m->id || mn->free) continue;
313 count++;
314
315 }
316 return m->tris.count * sizeof(MainVertex) * 3 * count;
317 }
318 else
319 {
320
321 return m->vertices.count * sizeof(MainVertex);
322 }
323
324}
326{
328 if (m->static_mesh)
329 {
330 int count = 0;
331 return 0;
332 }
333 else
334 {
335 return m->tris.count * sizeof(uint32_t) * 3;
336
337 }
338}
339
340size_t vsize = 0;
341size_t visize = 0;
342
344{
345
346 size_t * mesh_id = vector_expand(&layout->meshes, 1);
347 *mesh_id = m->id;
348
351 glBindBuffer(GL_ARRAY_BUFFER, layout->vbo);
352
353 layout->current_offset = 0;
354 layout->current_index_offset = 0;
355 size_t * ms = CAST_VEC(layout->meshes, size_t);
356 Mesh * meshes = CAST_VEC(GLOBALS.meshes, Mesh);
357 vsize = 0;
358 visize = 0;
359 for (int i = 0; i < layout->meshes.count; i++)
360 {
361 Mesh * m = &meshes[ms[i]];
362 vsize += calc_mesh_size(m);
364 }
365 layout->current_capacity = vsize * 2;
366 layout->current_index_capacity = visize * 2;
367
368 glBufferData(GL_ARRAY_BUFFER, layout->current_capacity, NULL, GL_DYNAMIC_DRAW);
369 MainVertex * verts = malloc(vsize);
370 uint32_t * indices = NULL;
371 if (visize)
372 {
373 indices = malloc(visize);
374 }
375
376 size_t offset = 0;
377 size_t index_offset = 0;
378 size_t lm_offset = 0;
379
380 for (int i = 0; i < layout->meshes.count; i++)
381 {
382 Mesh * m = &meshes[ms[i]];
383 m->offset = index_offset;
384 size_t current_offset = fill_vertex_buffer_mesh(m, verts, offset, &lm_offset);
385 index_offset += fill_index_buffer_mesh(m, indices, offset, index_offset, &lm_offset);
386 m->count = m->tris.count * 3;
387 offset += current_offset;
388 }
389
390
391 glBufferSubData(GL_ARRAY_BUFFER, 0, vsize, verts);
392 if (indices)
393 {
394 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, layout->ebo);
395 glBufferData(GL_ELEMENT_ARRAY_BUFFER, visize, indices, GL_DYNAMIC_DRAW);
396 }
397 layout->current_offset = vsize;
398 layout->current_index_offset = visize;
399
400 free(verts);
401 if (indices) free(indices);
402
403
404}
405
406
408{
409
410 Mesh * meshes = CAST_VEC(GLOBALS.meshes, Mesh);
412 size_t index_count = 0;
413 for (int i = 0; i < GLOBALS.meshes.count; i++)
414 {
415
416 Mesh * m = &meshes[i];
417 if (m->static_mesh)
418 {
419 for (int j = 0; j < GLOBALS.mesh_nodes.count; j++)
420 {
421
422 MeshNode * mn = &mns[j];
423 if (mn->mesh != i || mn->free) continue;
424
425 index_count += m->tris.count * 3;
426 }
427
428 }
429 else
430 {
431 index_count += m->tris.count * 3;
432 }
433 }
435 LIGHTMAP_DATA.uvs = calloc(index_count, sizeof(LightmapGPU));
436 return index_count;
437
438
439}
440
442{
443
444 Mesh * meshes = CAST_VEC(GLOBALS.meshes, Mesh);
446 size_t index_count = allocate_lightmap_ssbo();
447 if (layout->meshes.buffer) free(layout->meshes.buffer);
448 init_vector(&layout->meshes, 0, sizeof(size_t));
449
450 size_t lm_offset = 0;
451 for (int i = 0; i < GLOBALS.meshes.count; i++)
452 {
453 Mesh * m = &meshes[i];
454 if (m->vertices.count <= 0) continue;
455 bool add = false;
456 for (int j = 0; j < GLOBALS.mesh_nodes.count; j++)
457 {
458
459 MeshNode * mn = &mns[j];
460 if (mn->mesh != i || mn->free) continue;
461 add = true;
462
463 }
464 if (add) add_mesh_to_buffer(m, layout);
465
466 }
467
468 glBindBuffer(GL_SHADER_STORAGE_BUFFER, LIGHTMAP_SSBO);
469 glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(vec4) * index_count, LIGHTMAP_DATA.uvs, GL_STATIC_DRAW);
470 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, LIGHTMAP_SSBO);
471
472}
473
474
475void aabb_to_vertices(DebugVertex * out, AABB * aabb, vec3 offset)
476{
477
478
479 vec3 corners[8];
480 int count = 0;
481 for (int z = -1; z <= 1; z += 2){
482 for (int y = -1; y <= 1; y += 2){
483 for (int x = -1; x <= 1; x += 2){
484 corners[count++] = vec3_add(aabb->center, (vec3){x * aabb->extents.x, y * aabb->extents.y, z * aabb->extents.z});
485 }
486 }
487 }
488 out[0].pos = corners[1];
489 out[1].pos = corners[0];
490 out[2].pos = corners[3];
491 out[3].pos = corners[2];
492 out[4].pos = corners[5];
493 out[5].pos = corners[4];
494 out[6].pos = corners[7];
495 out[7].pos = corners[6];
496 out[8].pos = corners[0];
497 out[9].pos = corners[2];
498 out[10].pos = corners[1];
499 out[11].pos = corners[3];
500 out[12].pos = corners[4];
501 out[13].pos = corners[6];
502 out[14].pos = corners[5];
503 out[15].pos = corners[7];
504 out[16].pos = corners[1];
505 out[17].pos = corners[5];
506 out[18].pos = corners[0];
507 out[19].pos = corners[4];
508 out[20].pos = corners[3];
509 out[21].pos = corners[7];
510 out[22].pos = corners[2];
511 out[23].pos = corners[6];
512
513
514}
515
516
518{
519
521 Mesh * meshes = CAST_VEC(GLOBALS.meshes, Mesh);
522 if (mn->mesh != -1)
523 {
524 Mesh * m = &meshes[mn->mesh];
527 for (int j = 0; j < 24; j++)
528 {
530 }
531 DEBUG_LINE_COUNT += 24;
532
533 }
534
535
536 for (int i = 0; i < mn->child_count; i++)
537 {
538
540 }
541
542}
543
544
545
547{
548
549
550 vec3 axis_x = (vec3){obb->rot.a0, obb->rot.b0, obb->rot.c0};
551 vec3 axis_y = (vec3){obb->rot.a1, obb->rot.b1, obb->rot.c1};
552 vec3 axis_z = (vec3){obb->rot.a2, obb->rot.b2, obb->rot.c2};
553
554 vec3 corners[8];
555 int count = 0;
556 for (int z = -1; z <= 1; z += 2){
557 for (int y = -1; y <= 1; y += 2){
558 for (int x = -1; x <= 1; x += 2){
559 corners[count++] =
560 vec3_add(obb->center,
561 vec3_add(vec3_scale(axis_x, x * obb->extents.x),
562 vec3_add(vec3_scale(axis_y, y * obb->extents.y),
563 vec3_scale(axis_z, z * obb->extents.z))));
564 }
565 }
566 }
567 out[0].pos = corners[1];
568 out[1].pos = corners[0];
569 out[2].pos = corners[3];
570 out[3].pos = corners[2];
571 out[4].pos = corners[5];
572 out[5].pos = corners[4];
573 out[6].pos = corners[7];
574 out[7].pos = corners[6];
575 out[8].pos = corners[0];
576 out[9].pos = corners[2];
577 out[10].pos = corners[1];
578 out[11].pos = corners[3];
579 out[12].pos = corners[4];
580 out[13].pos = corners[6];
581 out[14].pos = corners[5];
582 out[15].pos = corners[7];
583 out[16].pos = corners[1];
584 out[17].pos = corners[5];
585 out[18].pos = corners[0];
586 out[19].pos = corners[4];
587 out[20].pos = corners[3];
588 out[21].pos = corners[7];
589 out[22].pos = corners[2];
590 out[23].pos = corners[6];
591
592
593}
594
595
596
597
598
601
603{
604
605 lgpu->dir = l->dir;
606 lgpu->pos= l->pos;
607 lgpu->entity_id= l->entity_id;
608 lgpu->dir= l->dir;
609 lgpu->rgb= l->rgb;
610 lgpu->intensity= l->intensity;
611 lgpu->light_type= l->light_type;
612
613
614 l->outer_angle = l->cone_angle * 0.5f;
615 l->inner_angle = l->outer_angle * (1 - l->penumbra);
616
617 lgpu->inner_angle= l->inner_angle;
618 lgpu->outer_angle= l->outer_angle;
619
620 float outer_cos = cosf(l->outer_angle);
621 float cos_diff = cosf(l->inner_angle) - outer_cos;
622 lgpu->outer_cos = outer_cos;
623 lgpu->cos_diff = 1.0f/cos_diff;
624
625 l->radius = sqrtf(l->intensity / l->threshold);
626 lgpu->radius = l->radius;
627 lgpu->layer = l->layer;
628 lgpu->mesh = l->mesh;
629 lgpu->tri = l->tri;
630 lgpu->area = l->surface_area;
631
632}
633
635{
636 gpu_light_count = 0;
637
638 Light * lights = CAST_VEC(GLOBALS.lights, Light);
639 for (int i = 0; i < GLOBALS.lights.count; i++)
640 {
641 Light * l = &lights[i];
643
645
646 }
647
648
649 size_t light_offset = current_frame * light_ssbo_size;
650
651 uint32_t * light_data = (uint32_t*)(light_ssbo_ptr + light_offset);
652 memcpy(light_data, GPU_LIGHTS, sizeof(LightGPU) * gpu_light_count);
653 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 0, LIGHT_SSBO, light_offset, light_ssbo_size);
654}
655
656
657
659{
660
661
662 Mesh * meshes = CAST_VEC(GLOBALS.meshes, Mesh);
664 Light * lights = CAST_VEC(GLOBALS.lights, Light);
665
666 int offset = 0;
667
668
669 for (int i = 0; i < GLOBALS.mesh_nodes.count; i++)
670 {
671
672 MeshNode * mn = &mns[i];
673 if (mn->mesh == -1 || mn->free) continue;
674
675 Mesh * m = &meshes[mn->mesh];
676
677 float closest[3][MAX_LIGHTS_PER_MESH] = {0.0f};
678 int closest_counts[3] = {0};
679 int closest_indices[3][MAX_LIGHTS_PER_MESH] = {0};
680 int total_count = 0;
681
682 for (int j = 0; j < GLOBALS.lights.count; j++)
683 {
684
685 Light * l = &lights[j];
686 if (l->light_type == POINT_LIGHT) continue;
687
688 vec3 dist = vec3_sub(l->pos, mn->translation);
689 float d2 = vec3_length(dist);
690 d2 *= d2;
691 LightType type = l->light_type;
692 if (type != DIRECTIONAL_LIGHT && l->intensity / d2 < MINIMUM_LIGHT_VISIBILITY_DIST) continue;
693 // cap directional light at 1
694 if (type == DIRECTIONAL_LIGHT)
695 {
696 if (closest_counts[DIRECTIONAL_LIGHT] >= MAX_DIRECTIONAL_LIGHTS) continue;
697 d2 = -INFINITY;
698 }
699
700 if (total_count >= MAX_LIGHTS_PER_MESH)
701 {
702 float highest_val = -INFINITY;
703 int highest_index = -1;
704 for (int k = 0; k < closest_counts[type]; k++)
705 {
706 if (closest[type][k] > highest_val)
707 {
708 highest_val = closest[type][k];
709 highest_index = k;
710 }
711 }
712 if (highest_val < d2)
713 {
714 closest_indices[type][highest_index] = j;
715 closest[type][highest_index] = d2;
716 }
717
718 }
719 else
720 {
721 closest_indices[type][closest_counts[type]] = j;
722 closest[type][closest_counts[type]++] = d2;
723 total_count++;
724 }
725
726 }
727
728 mn->point_light_offset = offset;
729 mn->point_light_count = closest_counts[POINT_LIGHT];
730 mn->directional_light_offset = offset + closest_counts[POINT_LIGHT];
731 mn->directional_light_count = closest_counts[DIRECTIONAL_LIGHT];
732 mn->spot_light_offset = offset + closest_counts[POINT_LIGHT] + closest_counts[DIRECTIONAL_LIGHT];
733 mn->spot_light_count = closest_counts[SPOT_LIGHT];
734
735 int current_offset = 0;
736 for (int i = 0; i < 3; i++)
737 {
738
739 for (int j = 0; j < closest_counts[i]; j++)
740 {
741 GLOBALS.mesh_light_indices[offset+current_offset] = closest_indices[i][j];
742 current_offset++;
743 }
744 }
745
746 offset += total_count;
747
748 }
749
750 size_t mesh_light_offset = current_frame * mesh_light_ssbo_size;
751
752 uint32_t * mesh_light_data = (uint32_t*)(mesh_light_ssbo_ptr + mesh_light_offset);
753 memcpy(mesh_light_data, GLOBALS.mesh_light_indices, sizeof(uint32_t) * offset);
754 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 1, MESH_LIGHT_SSBO, mesh_light_offset, mesh_light_ssbo_size);
755
756
757
758}
759
760
764{
765 joint_mat_count = 0;
767
769 for (int k = 0; k < MAX_ASSET_INSTANCES; k++)
770 {
771
773 if (AI->free) continue;
774 for (int i = 0; i < AI->skin_count; i++)
775 {
776
777 GLTFSkin * skin = &skins[AI->skin_indices[i]];
779 for (int j = 0; j < skin->joint_count; j++)
780 {
782 }
783 }
784 }
785
786 size_t joint_offset = current_frame * joint_ssbo_size;
787
788 mat4 * joint_data = (mat4*)(joint_ssbo_ptr + joint_offset);
789 memcpy(joint_data, JOINT_MATS, sizeof(mat4) * joint_mat_count);
790 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 11, JOINT_SSBO, joint_offset, joint_ssbo_size);
791
792
793}
794
795
796void update_node_global(MeshNode * nodes, int idx, mat4 parent) {
797
798 MeshNode *n = &nodes[idx];
799 n->local_matrix = compose_trs_from_mesh_node(n);
800
801 n->global_matrix = m4_mul(parent, n->local_matrix);
802
803 for (int c = 0; c < n->child_count; c++) {
804
805 update_node_global(nodes, n->children[c], n->global_matrix);
806
807 }
808}
809
811
812 mat4 identity = mat4_identity();
813
815 for (int i = 0; i < MAX_ASSET_INSTANCES; i++) {
817 if (AI->free) continue;
818 for (int n = 0; n < AI->node_count; n++){
819 MeshNode * mn = &mns[AI->node_indices[n]];
820 if (mn->parent == -1) {
822 mn->global_matrix = mn->local_matrix;
823 for (int c = 0; c < mn->child_count; c++) {
824 update_node_global(mns, mn->children[c], mn->global_matrix);
825 }
826 }
827 }
828 }
829}
830
832
835 for (int i = 0; i < MAX_ASSET_INSTANCES; i++) {
836
838 if (AI->free) continue;
839
840 for (int s = 0; s < AI->skin_count; s++) {
841
842 GLTFSkin * skin = &skins[AI->skin_indices[s]];
843
844 for (int j = 0; j < skin->joint_count; j++) {
845
846 MeshNode * node = &mns[AI->node_indices[skin->joints[j]]];
847 skin->final_mat[j] = m4_mul(node->global_matrix, skin->inverse_bind[j]);
848 }
849 }
850 }
851}
852
853
855{
856
857 int mat_count = 0;
859 Image * images = CAST_VEC(GLOBALS.images, Image);
860 for (int i = 0; i < GLOBALS.materials.count; i++)
861 {
862
863 Material * mat = &mats[i];
864 if (mat->diffuse_tex != -1)
865 {
867 }
868 else
869 {
871 }
872 if (mat->normal_tex != -1)
873 {
875 }
876 else
877 {
879 }
880 if (mat->arm_tex != -1 && !mat->override_arm)
881 {
882
884 }
885 else
886 {
888 }
889 if (mat->emissive_tex != -1)
890 {
892 }
893 else
894 {
896 }
903
904
913
914 }
915
916 glBindBuffer(GL_SHADER_STORAGE_BUFFER, MATERIAL_SSBO);
917
918 MaterialGPU * gpu_mapped_ptr = (MaterialGPU*)glMapBufferRange(
919 GL_SHADER_STORAGE_BUFFER,
920 0,
922 GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT
923 );
924
925 if (gpu_mapped_ptr)
926 {
927 memcpy(gpu_mapped_ptr, &MATERIAL_DATA, sizeof(MaterialGPU) * GLOBALS.materials.count);
928 glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
929 }
930 else
931 {
932 glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, sizeof(MaterialGPU) * GLOBALS.materials.count, &MATERIAL_DATA);
933 }
934}
935
936
937
938
939// unused old frustum culling code
940void
942 (
943 vec4 planes[6],
944 Camera * cam
945 )
946
947{
948
949
950
952
953 vec4 r0 = (vec4){VP.a0, VP.b0, VP.c0, VP.d0};
954 vec4 r1 = (vec4){VP.a1, VP.b1, VP.c1, VP.d1};
955 vec4 r2 = (vec4){VP.a2, VP.b2, VP.c2, VP.d2};
956 vec4 r3 = (vec4){VP.a3, VP.b3, VP.c3, VP.d3};
957 planes[0] = vec4_add(r3, r0);
958 planes[1] = vec4_sub(r3, r0);
959 planes[2] = vec4_add(r3, r1);
960 planes[3] = vec4_sub(r3, r1);
961 planes[4] = vec4_add(r3, r2);
962 planes[5] = vec4_sub(r3, r2);
963
964 for (int i = 0; i < 6; i++) {
965 float length = sqrtf(planes[i].x * planes[i].x + planes[i].y * planes[i].y + planes[i].z * planes[i].z);
966
967
968 if (length > 0.00001f) {
969 float inv_len = 1.0f / length;
970 planes[i].x *= inv_len;
971 planes[i].y *= inv_len;
972 planes[i].z *= inv_len;
973 planes[i].w *= inv_len;
974 }
975
976 }
977
978}
979
980
981
982bool
984 (
985 vec3 min,
986 vec3 max,
987 vec4 planes[6]
988 )
989
990{
991 for (int i = 0; i < 6; i++)
992 {
993 vec3 p = {
994 planes[i].x >= 0.0f ? max.x : min.x,
995 planes[i].y >= 0.0f ? max.y : min.y,
996 planes[i].z >= 0.0f ? max.z : min.z
997 };
998
999 if (vec3_dot((vec3){planes[i].x, planes[i].y, planes[i].z}, p) + planes[i].w < 0.0f)
1000 {
1001 return false;
1002 }
1003 }
1004
1005 return true;
1006}
1007
1008void determine_mesh_visibility(Camera * camera, size_t * meshes_frame, size_t * meshes_frame_cnt)
1009{
1010
1011 Mesh * meshes = CAST_VEC(GLOBALS.meshes, Mesh);
1013 *meshes_frame_cnt = 0;
1014 vec4 planes[6];
1015 get_view_planes(planes, camera);
1016
1017 for (int i = 0; i < GLOBALS.mesh_nodes.count; i++)
1018 {
1019
1020 MeshNode * mn = &mns[i];
1021 if (mn->mesh == -1 || mn->free) continue;
1022 Mesh * m = &meshes[mn->mesh];
1024 vec3 min = (vec3){aabb.min_x, aabb.min_y, aabb.min_z};
1025 vec3 max = (vec3){aabb.max_x, aabb.max_y, aabb.max_z};
1026
1027 meshes_frame[(*meshes_frame_cnt)++] = i;
1028 }
1029
1030}
1031
1032
1033void populate_draw_commands(DrawCommand * dcs, int * draw_command_cnt)
1034{
1035
1036 Mesh * meshes = CAST_VEC(GLOBALS.meshes, Mesh);
1038 *draw_command_cnt = 0;
1040
1042
1043 for (int i = 0; i < GLOBALS.mesh_nodes.count; i++)
1044 {
1045
1046 MeshNode * mn = &mns[i];
1047 if (mn->mesh == -1 || mn->free) continue;
1048
1049 Mesh * m = &meshes[mn->mesh];
1050 SubMesh * sms = CAST_VEC(m->submeshes, SubMesh);
1051
1052 for (int j = 0; j < m->submeshes.count; j++)
1053 {
1054
1055 DrawCommand * dc = &dcs[*draw_command_cnt];
1056
1057 if (sms[j].material == -1)
1058 {
1059 dc->material = 0;
1060 }
1061 else
1062 {
1063
1064 dc->material = sms[j].material;
1065 }
1066
1067 dc->start_index = sms[j].draw_offset;
1068 dc->fwd_shader = mats[dc->material].fwd_shader;
1069 dc->gbuffer_shader = mats[dc->material].gbuffer_shader;
1070 dc->index_count = sms[j].index_count;
1071 dc->lm_offset = sms[j].lm_offset;
1072 dc->matrix = mn->global_matrix;
1073 dc->static_mesh = m->static_mesh;
1074 dc->mesh_id = m->id;
1081 dc->sm_id = j;
1082 dc->mn_id = mn->id;
1083
1084
1085 if (mn->skin != -1)
1086 {
1087 dc->skin_offset = skins[mn->skin].ssbo_offset;
1088 }
1089 else
1090 {
1091 dc->skin_offset = 0;
1092 }
1093 if (mats[dc->material].override_transparent)
1094 {
1095 dc->opaque = 0;
1096 }
1097 else
1098 {
1099
1100 dc->opaque = (uint8_t)(mats[dc->material].kd.w * 255);
1101 }
1102
1103
1104 dc->sort_key = 0;
1105
1106 dc->sort_key |= ((uint64_t)(dc->opaque) << 56ULL);
1107 dc->sort_key |= ((uint64_t)(dc->mesh_id) << 40ULL);
1108 dc->sort_key |= ((uint64_t)(dc->material) << 24ULL);
1109 dc->sort_key |= ((uint64_t)(dc->static_mesh) << 16ULL);
1110 dc->sort_key |= ((uint64_t)(dc->fwd_shader) << 0ULL);
1111
1112 (*draw_command_cnt)++;
1113
1114 }
1115
1116 }
1117
1118}
1119
1120
1121int compare_draw_commands(const void * a, const void * b)
1122{
1123 DrawCommand * da = (DrawCommand *)a;
1124 DrawCommand * db = (DrawCommand *)b;
1125 if (da->sort_key < db->sort_key) return 1;
1126 if (da->sort_key > db->sort_key) return -1;
1127 return 0;
1128
1129}
1130
1131
1133{
1134 populate_draw_commands(dcs, dc_cnt);
1135
1136 qsort(dcs, *dc_cnt, sizeof(DrawCommand), compare_draw_commands);
1137}
1138
1139
1140
1141
1142
1143
1145float angle_tr = 0;
1146
1147
1148float compute_ui_scale(int base_w, int base_h, int target_w, int target_h){
1149 float x = (float)target_w / (float)base_w;
1150 float y = (float)target_h / (float)base_h;
1151 return fminf(x, y);
1152}
1153
1154void add_text_box(Vector * tvs, Vector * tis, TextBox * tb, int current_box)
1155{
1156
1157 if (tb->text == NULL) return;
1158 int len = strlen(tb->text);
1159
1160 float x = tb->start.x, y = tb->start.y;
1161 float scale = tb->text_size;
1162 Font * fonts = CAST_VEC(FONTS, Font);
1163 Font * f = &fonts[tb->font_id];
1164
1165 float max_x = 0;
1166 float max_y = 0;
1167 Glyph * glyphs = f->glyphs;
1168
1169 for (int i = 0; i < len; i++){
1170 char ch = tb->text[i];
1171
1172 Glyph *g = NULL;
1173 for (int j = 0; j < f->glyph_count; j++) {
1174 if (glyphs[j].id == ch) {
1175 g = &glyphs[j];
1176 break;
1177 }
1178 }
1179 if (!g) continue;
1180
1181 float x0 = x + g->xoffset * scale;
1182 float y0 = (y - 7 * scale) + g->yoffset * scale;
1183 float x1 = x0 + g->width * scale;
1184 float y1 = y0 + g->height * scale;
1185 float u0 = g->u0;
1186 float v0 = g->v0;
1187 float u1 = g->u1;
1188 float v1 = g->v1;
1189 vec2 center = (vec2){(x1-x0) / 2 + x0, (y1-y0)/2 + y0};
1190
1191 TextVertex * v = vector_expand(tvs, 4);
1192
1193 uint32_t * idx = vector_expand(tis, 6);
1194
1195 v[0] = (TextVertex){.pos = (vec2){x0, y0}, .uv = (vec2){u0, v0}, .center = center, .color = tb->color, .fill = tb->fill, .state = 0, .uID = current_box};
1196
1197 v[1] = (TextVertex){.pos = (vec2){x1, y0}, .uv = (vec2){u1, v0}, .center = center, .color = tb->color, .fill = tb->fill, .state = 0, .uID = current_box};
1198
1199 v[2] = (TextVertex){.pos = (vec2){x0, y1}, .uv = (vec2){u0, v1}, .center = center, .color = tb->color, .fill = tb->fill, .state = 0, .uID = current_box};
1200
1201 v[3] = (TextVertex){.pos = (vec2){x1, y1}, .uv = (vec2){u1, v1}, .center = center, .color = tb->color, .fill = tb->fill, .state = 0, .uID = current_box};
1202
1203 uint32_t i0 = tvs->count-4;
1204 uint32_t i1 = tvs->count-3;
1205 uint32_t i2 = tvs->count-2;
1206 uint32_t i3 = tvs->count-1;
1207
1208 idx[0] = i0;
1209 idx[1] = i1;
1210 idx[2] = i2;
1211 idx[3] = i2;
1212 idx[4] = i1;
1213 idx[5] = i3;
1214
1215
1216 x += g->xadvance * scale;
1217
1218 }
1219}
1221{
1222 TEXT_INDEX_COUNT = 0;
1223 Vector tvs;
1224 init_vector(&tvs, 0, sizeof(TextVertex));
1225
1226 Vector tis;
1227 init_vector(&tis, 0, sizeof(uint32_t));
1228
1229 UIMenu * ms = CAST_VEC(MENUS, UIMenu);
1230 int current_box = 0;
1231 for (int i = 0; i < MENUS.count; i++)
1232 {
1233
1234 UIMenu * m = &ms[i];
1235 TextBox * tbs = m->text_boxes;
1236
1237 for (int j = 0; j < MAX_TEXT_BOXES; j++)
1238 {
1239 if (tbs[j].free) continue;
1240 add_text_box(&tvs, &tis, &tbs[j], current_box);
1241 current_box++;
1242
1243 }
1244 }
1245
1246 glBindBuffer(GL_ARRAY_BUFFER, TEXT_VBO);
1247 glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(TextVertex) * tvs.count, tvs.buffer);
1248
1249 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, TEXT_EBO);
1250 glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(uint32_t) * tis.count, tis.buffer);
1251
1252 TEXT_INDEX_COUNT = tis.count;
1253
1254 if (tvs.buffer) free(tvs.buffer);
1255 if (tis.buffer) free(tis.buffer);
1256
1257}
1258
1259
1261{
1262
1263 int tb_count = *TC;
1264 float scale_x = (float)TEXT_WIDTH / UI_SCALE_WIDTH;
1265 float scale_y = (float)TEXT_HEIGHT / UI_SCALE_HEIGHT;
1266 float screen_scale_x = (float)SCREEN_WIDTH / UI_SCALE_WIDTH;
1267 float screen_scale_y = (float)SCREEN_HEIGHT / UI_SCALE_HEIGHT;
1268 vec2 text_tr = tb->translation;
1269 text_tr.x *= scale_x;
1270 text_tr.y *= scale_y;
1271 vec2 scale = tb->scale;
1272 mat4 mat = compose_2d_transform(text_tr, tb->angle, scale);
1273 uint32_t visible = tb->visible;
1274
1276 vec2 tr = tb->translation;
1277 tr.x *= screen_scale_x;
1278 tr.y *= screen_scale_y;
1279 vec2 tr_scale = tb->scale;
1280 tr_scale.x *= screen_scale_x;
1281 tr_scale.y *= screen_scale_y;
1282 mat4 mat_screen = compose_2d_transform(tr, tb->angle, tr_scale);
1283 uint32_t hovered = 0;
1284
1285 float w = tb->w;
1286 float h = tb->h;
1287 vec2 p0 = (vec2){-w/2, -h/2};
1288 vec2 p1 = (vec2){w/2, -h/2};
1289 vec2 p2 = (vec2){-w/2, h/2};
1290 vec2 p3 = (vec2){w/2, h/2};
1291 vec3 pos0 = mat4_mul_point(mat_screen, (vec3){p0.x, p0.y, 0.0});
1292 vec3 pos1 = mat4_mul_point(mat_screen, (vec3){p1.x, p1.y, 0.0});
1293 vec3 pos2 = mat4_mul_point(mat_screen, (vec3){p2.x, p2.y, 0.0});
1294 vec3 pos3 = mat4_mul_point(mat_screen, (vec3){p3.x, p3.y, 0.0});
1295 float min_x = MIN(MIN(MIN(pos0.x, pos1.x), pos2.x), pos3.x);
1296 float max_x = MAX(MAX(MAX(pos0.x, pos1.x), pos2.x), pos3.x);
1297 float min_y = MIN(MIN(MIN(pos0.y, pos1.y), pos2.y), pos3.y);
1298 float max_y = MAX(MAX(MAX(pos0.y, pos1.y), pos2.y), pos3.y);
1299
1300 if (MOUSE_X >= min_x && MOUSE_X <= max_x && MOUSE_Y >= min_y && MOUSE_Y <= max_y)
1301 {
1302
1303 TB_GPU[tb_count].hovered = 1;
1304 tb->hovered = true;
1305 }
1306 else
1307 {
1308
1309 tb->hovered = false;
1310 TB_GPU[tb_count].hovered = 0;
1311
1312 }
1313
1314 TB_GPU[tb_count].shadow = tb->shadow;
1315 TB_GPU[tb_count].shadow_dist = tb->shadow_dist;
1316 TB_GPU[tb_count].shadow_dir = tb->shadow_dir;
1317
1318 TB_GPU[tb_count].color = (vec4){0,0,0,0};
1319 TB_GPU[tb_count].fill = (vec4){0,0,0,0};
1320
1321 TB_GPU[tb_count].visible = visible;
1322 TB_GPU[tb_count].model = mat;
1324 {
1325 TB_GPU[tb_count].state = UISTATE_SELECTED;
1326 }
1327 else
1328 {
1329 TB_GPU[tb_count].state = tb->state;
1330 }
1331 (*TC)++;
1332}
1333
1335typedef struct UIUIDPair
1336{
1337
1338 uint32_t uid;
1339 uint32_t layer;
1340
1341} UIUIDPair;
1342
1343int compare_uid_pair(const void * a, const void * b)
1344{
1345
1346 UIUIDPair * da = (UIUIDPair *)a;
1347 UIUIDPair * db = (UIUIDPair *)b;
1348 if (da->layer > db->layer) return 1;
1349 if (da->layer < db->layer) return -1;
1350 return 0;
1351
1352}
1353
1354
1355
1356
1360
1361void GPU_upload_singular_element(UIContainer * cs, UIElement * el, int * ui_el_count, int * el_count)
1362{
1363 int ec = *el_count;
1364
1365 float scale_x = (float)TEXT_WIDTH / UI_SCALE_WIDTH;
1366 float scale_y = (float)TEXT_HEIGHT / UI_SCALE_HEIGHT;
1367 float screen_scale_x = (float)SCREEN_WIDTH / UI_SCALE_WIDTH;
1368 float screen_scale_y = (float)SCREEN_HEIGHT / UI_SCALE_HEIGHT;
1369 vec2 text_tr = el->translation;
1370 text_tr.x *= scale_x;
1371 text_tr.y *= scale_y;
1372 vec2 scale = el->scale;
1373 mat4 mat = compose_2d_transform(text_tr, el->angle, scale);
1374 uint32_t visible = el->visible;
1375
1377 vec2 tr = el->translation;
1378 tr.x *= screen_scale_x;
1379 tr.y *= screen_scale_y;
1380 vec2 tr_scale = el->scale;
1381 tr_scale.x *= screen_scale_x;
1382 tr_scale.y *= screen_scale_y;
1383 mat4 mat_screen = compose_2d_transform(tr, el->angle, tr_scale);
1384 uint32_t hovered = 0;
1385 vec2 local = vec2_sub((vec2){MOUSE_X, MOUSE_Y}, text_tr);
1386 local.x *= 1.0f/el->scale.x;
1387 local.y *= 1.0f/el->scale.y;
1388
1390 {
1392 }
1393 else
1394 {
1395 UI_GPU[ec].state = el->state;
1396 }
1397 UI_GPU[ec].shadow = el->shadow;
1398 UI_GPU[ec].shadow_dist = el->shadow_dist;
1399 UI_GPU[ec].shadow_dir = el->shadow_dir;
1400 UI_GPU[ec].color = el->color;
1401 UI_GPU[ec].fill = el->fill;
1402 UI_GPU[ec].visible = visible;
1403 UI_GPU[ec].model = mat;
1404 UI_GPU[ec].pos = el->center;
1405 UI_GPU[ec].type = el->type;
1406 UI_GPU[ec].size = el->size;
1407 UI_GPU[ec].radius = el->radius;
1408 UI_GPU[ec].translation = el->translation;
1409 UI_GPU[ec].scale = el->scale;
1411 {
1412 UIContainer * c = &cs[el->parent_container];
1413 UI_GPU[ec].masked = c->mask;
1414 }
1415 else
1416 {
1417 UI_GPU[ec].masked = false;
1418 }
1419 if (container_is_valid(el->container, el->menu))
1420 {
1421 UIContainer * c = &cs[el->container];
1422 UI_GPU[ec].padding = c->padding;
1423 }
1424
1425 UI_UIDS[ui_element_count].uid = *el_count;
1427
1429 (*el_count)++;
1430}
1431
1432int * container_ids = NULL;
1434
1435
1436void upload_parent_container(UIElement * el, UIContainer * cs, UIElement * els, int * el_count, size_t offset)
1437{
1439 {
1440 if (container_ids[el->parent_container + offset] == -1)
1441 {
1442
1443 UIContainer * pc = &cs[el->parent_container];
1444 UIElement * pel = &els[pc->element];
1445 upload_parent_container(pel, cs, els, el_count, offset);
1446
1447 container_ids[el->parent_container + offset] = *el_count;
1449 {
1450 UI_GPU[*el_count].container_id = container_ids[pel->parent_container + offset];
1451 }
1452 else
1453 {
1454 UI_GPU[*el_count].container_id = -1;
1455 }
1456 GPU_upload_singular_element(cs, pel, &ui_element_count, el_count);
1457
1458 }
1459 }
1460
1461}
1462
1464{
1465
1466 UIMenu * ms = CAST_VEC(MENUS, UIMenu);
1467 int el_count = 0;
1468 int tb_count = 0;
1469
1470 size_t container_count = 0;
1471 for (int i = 0; i < MENUS.count; i++)
1472 {
1473 for (int j = 0; j < MAX_UI_CONTAINERS; j++)
1474 {
1475
1476 if (ms[i].containers[j].free) continue;
1477 container_count++;
1478 }
1479 }
1480
1481 if (container_ids_cap < container_count)
1482 {
1483 int * new_cids = realloc(container_ids, sizeof(UIContainer) * container_count);
1484 container_ids_cap = container_count;
1485 if (new_cids)
1486 {
1487 container_ids = new_cids;
1488 }
1489 else
1490 {
1491 printf("Malloc Failed UI Ele\n");
1492 free(container_ids);
1493 container_ids = NULL;
1494 return;
1495 }
1496 }
1497 for (int i = 0; i < container_ids_cap; i++)
1498 {
1499 container_ids[i] = -1;
1500 }
1501
1502
1503 size_t offset = 0;
1504 ui_element_count = 0;
1505 for (int i = 0; i < MENUS.count; i++)
1506 {
1507
1508 if (!EDITOR_SETTINGS.UI && i != PERFORMANCE_OVERLAY_MENU) continue;
1509
1510 UIElement * els = ms[i].elements;
1511 TextBox * tbs = ms[i].text_boxes;
1512 UIContainer * cs = ms[i].containers;
1513 for (int j = 0; j < MAX_UI_ELEMENTS; j++)
1514 {
1515
1516 UIElement * el = &els[j];
1517 if (el->free) continue;
1518
1519 upload_parent_container(el, cs, els, &el_count, offset);
1521 {
1522 UI_GPU[el_count].container_id = container_ids[el->parent_container + offset];
1523 }
1524 else
1525 {
1526 UI_GPU[el_count].container_id = -1;
1527 }
1528 GPU_upload_singular_element(cs, el, &ui_element_count, &el_count);
1529 }
1530
1531 for (int j = 0; j < MAX_UI_ELEMENTS; j++)
1532 {
1533
1534 TextBox * tb = &tbs[j];
1535 if (tb->free) continue;
1536
1537 TB_GPU[tb_count].mask = 0;
1539 {
1540 TB_GPU[tb_count].container_id = container_ids[tb->parent_container + offset];
1541 if (cs[tb->parent_container].mask)
1542 {
1543 TB_GPU[tb_count].mask = 1;
1544 }
1545 }
1546 else
1547 {
1548 TB_GPU[tb_count].container_id = -1;
1549 }
1550 GPU_upload_singular_text_box(cs, tb, &tb_count);
1551 }
1552
1553 for (int j = 0; j < MAX_UI_CONTAINERS; j++)
1554 {
1555 if (ms[i].containers[j].free) continue;
1556 offset++;
1557 }
1558
1559 }
1560
1562 for (int i = 0; i < ui_element_count; i++)
1563 {
1564 UI_UID_OUT[i] = UI_UIDS[i].uid;
1565 }
1566
1567 size_t text_box_ssbo_offset = current_frame * text_box_ssbo_size;
1568 uint32_t * text_box_ssbo_data = (uint32_t*)(text_box_ssbo_ptr + text_box_ssbo_offset);
1569 memcpy(text_box_ssbo_data, TB_GPU, sizeof(TextBoxGPU) * tb_count);
1570 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 8, TEXT_BOX_SSBO, text_box_ssbo_offset, text_box_ssbo_size);
1571
1572 size_t ui_ssbo_offset = current_frame * ui_ssbo_size;
1573 uint8_t * ui_ssbo_data = (uint8_t*)(ui_ssbo_ptr + ui_ssbo_offset);
1574 memcpy(ui_ssbo_data, UI_GPU, sizeof(UIElementGPU) * el_count);
1575 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 9, UI_SSBO, ui_ssbo_offset, ui_ssbo_size);
1576
1577 size_t ui_instance_vbo_offset = current_frame * ui_instance_vbo_size;
1578 uint32_t * ui_instance_vbo_data = (uint32_t*)(ui_instance_vbo_ptr + ui_instance_vbo_offset);
1579 memcpy(ui_instance_vbo_data, UI_UID_OUT, sizeof(uint32_t) * ui_element_count);
1580
1581
1582
1583}
1584
1585
1586
1587
1588
1589void bind_dynamic_shader(int shader, bool probe_bake)
1590{
1591
1592 glUseProgram(DYNAMIC_SHADER[shader].program);
1594 Image * images = CAST_VEC(GLOBALS.images, Image);
1595
1596
1597 glActiveTexture(GL_TEXTURE1);
1598 glBindTexture(GL_TEXTURE_2D_ARRAY, SHADOW_MAP_FBO.depth_texture.i);
1599 glUniform1i(DYNAMIC_SHADER[shader].uniforms[4].location, 1);
1600 glActiveTexture(GL_TEXTURE2);
1601 glBindTexture(GL_TEXTURE_3D, LPV_TEXTURE);
1602 glUniform1i(DYNAMIC_SHADER[shader].uniforms[5].location, 2);
1603 glActiveTexture(GL_TEXTURE3);
1604 glBindTexture(GL_TEXTURE_CUBE_MAP, SKYBOX);
1605 glUniform1i(DYNAMIC_SHADER[shader].uniforms[6].location, 3);
1606 glActiveTexture(GL_TEXTURE4);
1607 glBindTexture(GL_TEXTURE_2D, BRDF_LUT);
1608 glUniform1i(DYNAMIC_SHADER[shader].uniforms[7].location, 4);
1609
1610 if (shader == 1)
1611 {
1612 glUniform1f(DYNAMIC_SHADER[shader].uniforms[8].location, time);
1613 }
1614
1615
1616 glActiveTexture(GL_TEXTURE5);
1617 glBindTexture(GL_TEXTURE_2D, DIRECTIONAL_MAP_TEXTURE);
1618 glUniform1i(DYNAMIC_SHADER[shader].uniforms[14].location, 5);
1619 if (!probe_bake)
1620 {
1621
1622 glActiveTexture(GL_TEXTURE6);
1623 glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, RPROBE_CUBE_MAP_ARRAY);
1624 glUniform1i(DYNAMIC_SHADER[shader].uniforms[9].location, 6);
1625 }
1626 glActiveTexture(GL_TEXTURE7);
1627 glBindTexture(GL_TEXTURE_2D, FBM_TEXTURE);
1628 glUniform1i(DYNAMIC_SHADER[shader].uniforms[10].location, 7);
1630 {
1631
1632 glActiveTexture(GL_TEXTURE8);
1633 glBindTexture(GL_TEXTURE_2D, SSAO_BLUR_FBO.texture[0].i);
1634 glUniform1i(DYNAMIC_SHADER[shader].uniforms[22].location, 8);
1635 }
1636 else
1637 {
1638 glActiveTexture(GL_TEXTURE8);
1639 glBindTexture(GL_TEXTURE_2D, DUMMY_LIGHTMAP);
1640 glUniform1i(DYNAMIC_SHADER[shader].uniforms[22].location, 8);
1641 }
1642 glActiveTexture(GL_TEXTURE9);
1643 glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, POINT_LIGHT_SHADOWS_FBO.depth_texture.i);
1644 glUniform1i(glGetUniformLocation(DYNAMIC_SHADER[shader].program, "uPLSCMA"), 9);
1645
1646 glActiveTexture(GL_TEXTURE10);
1647 glBindTexture(GL_TEXTURE_2D, SSR_FBO.texture[0].i);
1648 glUniform1i(glGetUniformLocation(DYNAMIC_SHADER[shader].program, "uSSR"), 10);
1649
1650
1651 glUniform1f(DYNAMIC_SHADER[shader].uniforms[15].location, GLOBALS.probe_spacing);
1652 glUniform3f(DYNAMIC_SHADER[shader].uniforms[16].location, GLOBALS.world_min.x, GLOBALS.world_min.y, GLOBALS.world_min.z);
1653 glUniform3i(DYNAMIC_SHADER[shader].uniforms[17].location, GLOBALS.probe_tex_size.x, GLOBALS.probe_tex_size.y, GLOBALS.probe_tex_size.z);
1654 glUniform1ui(DYNAMIC_SHADER[shader].uniforms[23].location, PROBE_VOLUME_DEPTH_PADDED);
1655 glUniform2f(glGetUniformLocation(DYNAMIC_SHADER[shader].program, "uScreenRes"), RENDER_WIDTH, RENDER_HEIGHT);
1656 glUniform3ui(glGetUniformLocation(DYNAMIC_SHADER[shader].program, "uGridSize"), GRID_X, GRID_Y, GRID_Z);
1657 glUniform1f(glGetUniformLocation(DYNAMIC_SHADER[shader].program, "uNear"), VIEW_NEAR);
1658 glUniform1f(glGetUniformLocation(DYNAMIC_SHADER[shader].program, "uFar"), VIEW_FAR);
1659 glUniform1f(glGetUniformLocation(DYNAMIC_SHADER[shader].program, "uLogScale"), GRID_Z / log2f(VIEW_FAR / VIEW_NEAR));
1660}
1661
1663{
1664 Image * images = CAST_VEC(GLOBALS.images, Image);
1665
1666 int shader = mat->fwd_shader;
1667 glActiveTexture(GL_TEXTURE11);
1668 if (mat->diffuse_tex == -1)
1669 {
1670
1671 glBindTexture(GL_TEXTURE_2D, images[DEFAULT_DIFFUSE].i);
1672 glUniform1i(DYNAMIC_SHADER[shader].uniforms[18].location, 11);
1673 }
1674 else
1675 {
1676 glBindTexture(GL_TEXTURE_2D, images[mat->diffuse_tex].i);
1677 glUniform1i(DYNAMIC_SHADER[shader].uniforms[18].location, 11);
1678
1679 }
1680 glActiveTexture(GL_TEXTURE12);
1681 if (mat->normal_tex == -1)
1682 {
1683
1684 glBindTexture(GL_TEXTURE_2D, images[DEFAULT_NORMAL].i);
1685 glUniform1i(DYNAMIC_SHADER[shader].uniforms[19].location, 12);
1686 }
1687 else
1688 {
1689 glBindTexture(GL_TEXTURE_2D, images[mat->normal_tex].i);
1690 glUniform1i(DYNAMIC_SHADER[shader].uniforms[19].location, 12);
1691
1692 }
1693 glActiveTexture(GL_TEXTURE13);
1694 if (mat->arm_tex == -1)
1695 {
1696
1697 glBindTexture(GL_TEXTURE_2D, images[DEFAULT_ARM].i);
1698 glUniform1i(DYNAMIC_SHADER[shader].uniforms[20].location, 13);
1699 }
1700 else
1701 {
1702 glBindTexture(GL_TEXTURE_2D, images[mat->arm_tex].i);
1703 glUniform1i(DYNAMIC_SHADER[shader].uniforms[20].location, 13);
1704
1705 }
1706
1707}
1708
1714
1720
1722
1723
1732void upload_instance_data(int * draw_calls, int * in_off, int dc_counts[MAX_DRAW_COMMANDS], int dc_off[MAX_DRAW_COMMANDS], int * draw_command_cnt, DrawCommand * dcs, MeshNodeSSBO * mn_data, uint8_t * instance_ptr, int current_frame_offset)
1733{
1734
1735 int i = 0;
1736 int current_mat = -1;
1737 *in_off = 0;
1738 *draw_calls = 0;
1739 Mesh * meshes = CAST_VEC(GLOBALS.meshes, Mesh);
1741 int offset = 0;
1742 array_offset = 0;
1743 element_offset = 0;
1744 transform_count = 0;
1745 int total_instance_count = 0;
1746 while (i < *draw_command_cnt)
1747 {
1748 DrawCommand * first_command = &dcs[i];
1749
1750 DrawCommand * current_command = first_command;
1751 int instance_count = 0;
1752 int arr = array_offset;
1753 int el = element_offset;
1754
1755 Mesh * m = &meshes[current_command->mesh_id];
1756 if (m->static_mesh)
1757 {
1758 arrays_indirect[array_offset].count = current_command->index_count;
1759 arrays_indirect[array_offset].first = current_command->start_index;
1762 array_offset++;
1763 }
1764 else
1765 {
1769 elements_indirect[element_offset].baseInstance = total_instance_count;
1772
1773 }
1774 mn_data->mns[offset].static_mesh = current_command->static_mesh;
1775 mn_data->mns[offset].lm_offset = current_command->lm_offset;
1776 mn_data->mns[offset].material = current_command->material;
1777 mn_data->mns[offset].first = current_command->start_index;
1778 mn_data->mns[offset].count = current_command->index_count;
1779 AABB aabb = meshes[current_command->mesh_id].aabb;
1780 mn_data->mns[offset].min = (vec4){aabb.min_x, aabb.min_y, aabb.min_z, 1.0};
1781 mn_data->mns[offset].max = (vec4){aabb.max_x, aabb.max_y, aabb.max_z, 1.0};
1782
1783 mn_data->mns[offset].center = (vec4){aabb.center.x, aabb.center.y, aabb.center.z, 1.0};
1784 mn_data->mns[offset].extents = (vec4){aabb.extents.x, aabb.extents.y, aabb.extents.z, 1.0};
1785
1786
1787
1788 while (i < *draw_command_cnt &&
1789 first_command->material == current_command->material &&
1790 first_command->static_mesh == current_command->static_mesh &&
1791 first_command->mesh_id == current_command->mesh_id &&
1792 first_command->sm_id == current_command->sm_id &&
1793 first_command->fwd_shader == current_command->fwd_shader &&
1794 i < MAX_INSTANCES)
1795 {
1796
1797
1798 int current_instance = i;
1799
1800 current_command->array_offset = arr;
1801 current_command->element_offset = el;
1802
1803 mns[current_command->mn_id].command_id[current_command->sm_id] = (m->static_mesh ? array_offset - 1 : element_offset - 1);
1804 mns[current_command->mn_id].mesh_data_id[current_command->sm_id] = offset;
1805 mns[current_command->mn_id].skin_offset = current_command->skin_offset;
1806
1807 total_instance_count++;
1808 i++;
1809 current_command = &dcs[i];
1810
1811 }
1812 mn_data->mns[offset].instance_count = instance_count;
1813 offset++;
1814
1815 }
1816
1817
1819 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, INDIRECT_ARRAYS_COMMAND_BUFFER);
1820
1822 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, INDIRECT_ELEMENTS_COMMAND_BUFFER);
1823
1824 size_t mesh_node_ssbo_offset = current_frame * mesh_node_ssbo_size;
1825
1826 uint32_t * mesh_node_ssbo_data = (uint32_t*)(mesh_node_ssbo_ptr + mesh_node_ssbo_offset);
1827 memcpy(mesh_node_ssbo_data, mn_data, sizeof(float) * 1 + sizeof(uint32_t) * 3 + sizeof(MeshNodeDataGPU) * *draw_command_cnt);
1828 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 15, MESH_NODE_SSBO, mesh_node_ssbo_offset, mesh_node_ssbo_size);
1829
1830
1831}
1832
1833#define MAX_MESHES_PER_PT_LIGHT_SHADOW 32
1834
1835
1836void draw_arrays_elements(ShaderProgram * s, int start_arr, size_t start_array_offset, uint32_t array_count, int start_ele, size_t start_element_offset, uint32_t element_count)
1837{
1838 if (array_count > 0)
1839 {
1840
1841 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, INDIRECT_ARRAYS_COMMAND_BUFFER_OUT);
1842 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, INDIRECT_ELEMENTS_COMMAND_BUFFER_OUT);
1843
1844 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, INDIRECT_ARRAYS_COMMAND_BUFFER_OUT);
1845 glUniform1ui(glGetUniformLocation(s->program, "uDynamicPass"), 0);
1846 glUniform1ui(glGetUniformLocation(s->program, "uStartArr"), start_arr);
1847 glMultiDrawArraysIndirect(GL_TRIANGLES, (void*)start_array_offset, array_count, sizeof(DrawArraysIndirectCommand));
1848 }
1849
1850 if (element_count > 0)
1851 {
1852 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, INDIRECT_ARRAYS_COMMAND_BUFFER_OUT);
1853
1854 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, INDIRECT_ELEMENTS_COMMAND_BUFFER_OUT);
1855 glUniform1ui(glGetUniformLocation(s->program, "uOffset"), array_offset);
1856 glUniform1ui(glGetUniformLocation(s->program, "uStartEle"), start_ele);
1857 glUniform1ui(glGetUniformLocation(s->program, "uDynamicPass"), 1);
1858 glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, (void*)start_element_offset, element_count, sizeof(DrawElementsIndirectCommand));
1859 }
1860}
1861
1862
1864{
1865 Light * lights = CAST_VEC(GLOBALS.lights, Light);
1867 Mesh * meshes = CAST_VEC(GLOBALS.meshes, Mesh);
1868
1869 float yaws[6] = {0, M_PI, M_PI, M_PI, M_PI / 2.0f + M_PI, M_PI / 2.0f};
1870 float pitches[6] = {0, 0, M_PI / 2.0f, -M_PI / 2.0f, 0, 0};
1871 vec3 flips[6];
1872 flips[0] = (vec3){0, 0, -1};
1873 flips[1] = (vec3){0, 0, -1};
1874 flips[2] = (vec3){0, -1, 0};
1875 flips[3] = (vec3){0, 1, 0};
1876 flips[4] = (vec3){0, 0, -1};
1877 flips[5] = (vec3){0, 0, -1};
1878
1879 glEnable(GL_DEPTH_TEST);
1880 glDepthMask(GL_TRUE);
1881 glDepthFunc(GL_LEQUAL);
1882 glBindFramebuffer(GL_FRAMEBUFFER, POINT_LIGHT_SHADOWS_FBO.fbo);
1884 glFramebufferTexture3D(
1885 GL_FRAMEBUFFER,
1886 GL_DEPTH_ATTACHMENT,
1887 GL_TEXTURE_CUBE_MAP_ARRAY,
1889 0,
1890 0
1891 );
1892 mat4 proj = make_projection(90, 1, 0.05f, 100.0f);
1893 for (int i = 0; i < GLOBALS.lights.count; i++)
1894 {
1895
1896 Light * l = &lights[i];
1897
1898 if (l->light_type != POINT_LIGHT || master_frame % 2 == 0) continue;
1899
1901
1902 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, INDIRECT_ARRAYS_COMMAND_BUFFER);
1903 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, INDIRECT_ELEMENTS_COMMAND_BUFFER);
1904
1905 glUniform3f(CULL_POINT_LIGHT_SHADOWS_SHADER.uniforms[0].location, l->pos.x, l->pos.y, l->pos.z);
1909
1910 glDispatchCompute((transform_count+63)/64, 1, 1);
1911
1912 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
1913
1914
1915 if (array_offset > 0)
1916 {
1917
1918 glUseProgram(INDIRECT_PREFIX_SHADER.program);
1919
1920 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, INDIRECT_ARRAYS_COMMAND_BUFFER_OUT);
1922
1923 glDispatchCompute((array_offset+127)/128, 1, 1);
1924 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
1925 }
1926
1927 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, INDIRECT_ELEMENTS_COMMAND_BUFFER);
1928 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, INDIRECT_ELEMENTS_COMMAND_BUFFER_OUT);
1929 if (element_offset > 0)
1930 {
1931
1932 glUseProgram(ELEMENTS_PREFIX_SHADER.program);
1933
1935
1936 glDispatchCompute((element_offset+127)/128, 1, 1);
1937 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
1938 }
1939
1940
1941 float clear_color = 1.0f;
1942 glClearTexSubImage(POINT_LIGHT_SHADOWS_FBO.depth_texture.i, 0, 0, 0, 6 * i, POINT_LIGHT_SHADOWS_FBO.w, POINT_LIGHT_SHADOWS_FBO.h, 6, GL_DEPTH_COMPONENT, GL_FLOAT, &clear_color);
1943
1944
1945 mat4 VPs[6];
1946 for (int j = 0; j < 6; j++)
1947 {
1948
1949 vec3 pos = l->pos;
1950 Camera sky_cam;
1951 sky_cam.cam_data.cam_pos = vec3_to_vec4(pos);
1952
1953 sky_cam.yaw = yaws[j];
1954 sky_cam.pitch = pitches[j];
1955
1956 compute_camera_basis(&sky_cam, sky_cam.yaw, sky_cam.pitch, 0, flips[j]);
1957
1958 vec3 target = vec3_add(
1959 pos,
1960 sky_cam.forward
1961 );
1962
1964 &sky_cam,
1965 pos
1966 );
1967 sky_cam.cam_data.view = view;
1968 sky_cam.cam_data.proj = proj;
1969
1970 mat4 VP = m4_mul(proj, view);
1971 VPs[j] = VP;
1972
1973 }
1974 glBindVertexArray(MAIN_VAO);
1975 glBindBuffer(GL_ARRAY_BUFFER, MAIN_VBO);
1976 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, MAIN_EBO);
1977 glBindBuffer(GL_ARRAY_BUFFER, INSTANCE_VBO);
1978 glUseProgram(POINT_LIGHT_SHADOW_SHADER.program);
1979 glUniformMatrix4fv(POINT_LIGHT_SHADOW_SHADER.uniforms[0].location, 6, GL_FALSE, (const GLfloat*)VPs);
1980 glUniform3f(POINT_LIGHT_SHADOW_SHADER.uniforms[1].location, l->pos.x, l->pos.y, l->pos.z);
1981 glUniform1f(POINT_LIGHT_SHADOW_SHADER.uniforms[2].location, 100.0f);
1982 glUniform1ui(POINT_LIGHT_SHADOW_SHADER.uniforms[3].location, 6 * i);
1983
1985
1986
1987 l->sm_dirty = false;
1988
1989 }
1990 glDisable(GL_CULL_FACE);
1991}
1992
1993
1994
1995
1997{
1998
1999 Mesh * meshes = CAST_VEC(GLOBALS.meshes, Mesh);
2002
2004
2005 transform_count = 0;
2006 static_count = 0;
2007 dynamic_count = 0;
2008
2009 for (int i = 0; i < draw_command_count; i++)
2010 {
2011
2012 DrawCommand * dc = &DRAW_COMMANDS[i];
2013
2014 MeshNode * mn = &mns[dc->mn_id];
2015 if (mn->mesh == -1 || mn->free) continue;
2016 Mesh * m = &meshes[mn->mesh];
2017 if (!m->static_mesh) continue;
2018 SubMesh * sms = CAST_VEC(m->submeshes, SubMesh);
2019 SubMesh * sm = &sms[dc->sm_id];
2020 if (mn->skin != -1)
2021 {
2022
2024 }
2025 else
2026 {
2028
2029 }
2030
2037
2039
2040 static_count++;
2041 }
2042
2043
2044 for (int i = 0; i < draw_command_count; i++)
2045 {
2046
2047 DrawCommand * dc = &DRAW_COMMANDS[i];
2048
2049 MeshNode * mn = &mns[dc->mn_id];
2050 if (mn->mesh == -1 || mn->free) continue;
2051 Mesh * m = &meshes[mn->mesh];
2052 if (m->static_mesh) continue;
2053 SubMesh * sms = CAST_VEC(m->submeshes, SubMesh);
2054 SubMesh * sm = &sms[dc->sm_id];
2055
2056 if (mn->skin != -1)
2057 {
2058
2060 }
2061 else
2062 {
2064
2065 }
2072
2074 dynamic_count++;
2075
2076 }
2077 size_t instance_ssbo_offset = current_frame * instance_ssbo_size;
2078
2079 uint32_t * instance_ssbo_data = (uint32_t*)(instance_ssbo_ptr + instance_ssbo_offset);
2080 memcpy(instance_ssbo_data, transforms, sizeof(TransformGPU) * transform_count);
2081 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 7, INSTANCE_SSBO, instance_ssbo_offset, instance_ssbo_size);
2082
2083
2084 size_t prev_instance_ssbo_offset = ((current_frame + (BUFFER_FRAMES - 1)) % BUFFER_FRAMES) * instance_ssbo_size;
2085 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 9, INSTANCE_SSBO, prev_instance_ssbo_offset, instance_ssbo_size);
2086
2087}
2088
2090{
2091
2092
2093 if (probe_bake)
2094 {
2095 glEnable(GL_DEPTH_TEST);
2096 glDepthMask(GL_TRUE);
2097 glDepthFunc(GL_LEQUAL);
2098 }
2099 else
2100 {
2101 glDepthFunc(GL_EQUAL);
2102 glDepthMask(GL_FALSE);
2103 }
2104 glBindVertexArray(MAIN_VAO);
2105 glBindBuffer(GL_ARRAY_BUFFER, MAIN_VBO);
2106 glBindBuffer(GL_ARRAY_BUFFER, INSTANCE_VBO);
2107 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, MAIN_EBO);
2108
2110 Image * images = CAST_VEC(GLOBALS.images, Image);
2111 int current_mat = 0;
2112 bool currently_static = false;
2113
2114 glEnable(GL_BLEND);
2115 glBlendEquation(GL_FUNC_ADD);
2116 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2117 glEnable(GL_CULL_FACE);
2118 glCullFace(GL_BACK);
2119 int shader = -1;
2121 {
2122
2125 if (probe_bake)
2126 {
2127 glUniform1i(DYNAMIC_SHADER[shader].uniforms[11].location, 1);
2128
2129 }
2130 else
2131 {
2132 glUniform1i(DYNAMIC_SHADER[shader].uniforms[11].location, 0);
2133
2134 }
2135 glActiveTexture(GL_TEXTURE0);
2136 glBindTexture(GL_TEXTURE_2D, GLOBALS.scene_data.lightmap_data.texture_id);
2137 glUniform1i(DYNAMIC_SHADER[shader].uniforms[0].location, 0);
2138 }
2139
2140 int i = 0;
2141 while (i < draw_command_count)
2142 {
2143 DrawCommand * first_command = &DRAW_COMMANDS[i];
2144 DrawCommand * current_command = first_command;
2145
2146 int starting_array_offset = first_command->array_offset;
2147 int starting_element_offset = first_command->element_offset;
2148 int arr = 0;
2149 int el = 0;
2150
2151 while
2152 (
2153 first_command->opaque == current_command->opaque &&
2154 first_command->fwd_shader == current_command->fwd_shader &&
2156 )
2157 {
2158
2159 if (current_command->static_mesh)
2160 {
2161 arr++;
2162 }
2163 else
2164 {
2165 el++;
2166 }
2167 i++;
2168 current_command = &DRAW_COMMANDS[i];
2169 }
2170
2171 if (
2173 (
2174 first_command->opaque != current_command->opaque ||
2175 first_command->fwd_shader != shader
2176 )
2177 )
2178 {
2179
2180 shader = first_command->fwd_shader;
2182 if (probe_bake)
2183 {
2184 glUniform1i(DYNAMIC_SHADER[shader].uniforms[11].location, 1);
2185
2186 }
2187 else
2188 {
2189 glUniform1i(DYNAMIC_SHADER[shader].uniforms[11].location, 0);
2190
2191 }
2192 glActiveTexture(GL_TEXTURE0);
2193 glBindTexture(GL_TEXTURE_2D, GLOBALS.scene_data.lightmap_data.texture_id);
2194 glUniform1i(DYNAMIC_SHADER[shader].uniforms[0].location, 0);
2195 }
2196
2197 size_t start_array_offset = (sizeof(DrawArraysIndirectCommand) * starting_array_offset);
2198 size_t start_element_offset = (sizeof(DrawElementsIndirectCommand) * starting_element_offset);
2199 uint32_t array_count = arr;
2200 uint32_t element_count = el;
2201
2202 if (first_command->opaque < 255)
2203 {
2204 glDepthFunc(GL_LEQUAL);
2205 glDepthMask(GL_FALSE);
2206 glEnable(GL_CULL_FACE);
2207 glCullFace(GL_FRONT);
2208 draw_arrays_elements(&DYNAMIC_SHADER[shader], starting_array_offset, start_array_offset, array_count, starting_element_offset, start_element_offset, element_count);
2209 glEnable(GL_CULL_FACE);
2210 glCullFace(GL_BACK);
2211 draw_arrays_elements(&DYNAMIC_SHADER[shader], starting_array_offset, start_array_offset, array_count, starting_element_offset, start_element_offset, element_count);
2212 glEnable(GL_CULL_FACE);
2213 glCullFace(GL_BACK);
2214 }
2215 else
2216 {
2217
2218 draw_arrays_elements(&DYNAMIC_SHADER[shader], starting_array_offset, start_array_offset, array_count, starting_element_offset, start_element_offset, element_count);
2219 }
2220 }
2221
2222}
2223
2224
2225
2226
2227
2228
2232{
2233
2234
2235
2237 float distances[MAX_RPROBES_PER_FRAME] = {INFINITY};
2238
2239 int num_probes = GLOBALS.scene_data.reflection_probes.count;
2240
2242 const float MAX_DIST = 20.0f;
2243 for (int i = 0; i < num_probes; i++)
2244 {
2245 ReflectionProbe * p = &rprobes[i];
2246
2247 float longest = -INFINITY;
2248 int longest_index = 0;
2250 {
2252 continue;
2253 }
2254
2255 for (int j = 0; j < RPROBE_UBO_DATA.probe_count; j++)
2256 {
2257 if (distances[j] > longest)
2258 {
2259 longest_index = j;
2260 longest = distances[j];
2261 }
2262 }
2263
2264 float current_dist = vec3_length(vec3_sub(CAM_POS, p->aabb.center));
2265 if (current_dist < longest)
2266 {
2267 RPROBE_UBO_DATA.probe_indices[longest_index].val = i;
2268 }
2269
2270
2271 }
2272
2273
2274}
2275
2277
2278void render_to_cubemap_face(Camera * rprobe_cam, GLuint render_fbo, int render_width, int render_height, bool probe_bake)
2279{
2280
2281 Mesh * meshes = CAST_VEC(GLOBALS.meshes, Mesh);
2283 glBeginQuery(GL_TIME_ELAPSED, cull_queries[current_query_frame]);
2286 upload_lights();
2287 GLOBALS.lights_dirty = false;
2288
2289
2291 {
2292
2293 glEnable(GL_MULTISAMPLE);
2294 }
2295 else
2296 {
2297
2298 glDisable(GL_MULTISAMPLE);
2299 }
2300
2301
2302 glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
2303 size_t cam_ubo_offset = current_frame * cam_ubo_padded;
2304 CamData* frame_cam_data = (CamData*)(cam_ubo_ptr + cam_ubo_offset);
2305 *frame_cam_data = rprobe_cam->cam_data;
2306 glBindBufferRange(GL_UNIFORM_BUFFER, 0, CAM_UBO, cam_ubo_offset, sizeof(CamData));
2307
2308
2309
2310 size_t light_cam_ubo_offset = current_frame * light_cam_ubo_padded;
2311 ShadowmapUBO* frame_light_cam_data = (ShadowmapUBO*)(light_cam_ubo_ptr + light_cam_ubo_offset);
2312
2313 for (int i = 0; i < DIRECTIONAL_LIGHT_COUNT; i++)
2314 {
2317 }
2318
2319
2320 *frame_light_cam_data = SHADOWMAP_FRAME_DATA;
2321
2322 glBindBufferRange(GL_UNIFORM_BUFFER, 2, LIGHT_CAM_UBO, light_cam_ubo_offset, sizeof(ShadowmapUBO));
2323
2324 size_t rprobe_ubo_offset = current_frame * rprobe_ubo_padded;
2325 RProbeUBO* frame_rprobe_data = (RProbeUBO*)(rprobe_ubo_ptr + rprobe_ubo_offset);
2326 *frame_rprobe_data = RPROBE_UBO_DATA;
2327 glBindBufferRange(GL_UNIFORM_BUFFER, 3, RPROBE_UBO, rprobe_ubo_offset, sizeof(RProbeUBO));
2328
2329 size_t prev_cam_ubo_offset = ((current_frame + (BUFFER_FRAMES-1)) % BUFFER_FRAMES) * cam_ubo_padded;
2330 glBindBufferRange(GL_UNIFORM_BUFFER, 4, CAM_UBO, prev_cam_ubo_offset, sizeof(CamData));
2331
2332 size_t probe_volume_ubo_offset = current_frame * probe_volume_ubo_padded;
2333 ProbeVolumeUBO* frame_probe_volume_data = (ProbeVolumeUBO*)(probe_volume_ubo_ptr + probe_volume_ubo_offset);
2334 ProbeVolumeUBO frame_pv_data = {0};
2336 for (int i = 0; i < LPV_SLOTS; i++)
2337 {
2338 if (!GLOBALS.scene_data.LOADED_LIGHTING_PV_FLAG[i]) continue;
2340 // frame_pv_data.loaded[i] = 1;
2341 frame_pv_data.obb[i].center = pv->obb.center;
2342 frame_pv_data.obb[i].extents = pv->obb.extents;
2343 frame_pv_data.obb[i].axis_x = (vec3){pv->obb.rot.a0, pv->obb.rot.a1, pv->obb.rot.a2};
2344 frame_pv_data.obb[i].axis_y = (vec3){pv->obb.rot.b0, pv->obb.rot.b1, pv->obb.rot.b2};
2345 frame_pv_data.obb[i].axis_z = (vec3){pv->obb.rot.c0, pv->obb.rot.c1, pv->obb.rot.c2};
2346 frame_pv_data.obb[i].loaded = 1;
2347
2348 }
2349
2350 *frame_probe_volume_data = frame_pv_data;
2351 glBindBufferRange(GL_UNIFORM_BUFFER, 6, PROBE_VOLUME_UBO, probe_volume_ubo_offset, sizeof(ProbeVolumeUBO));
2352
2354
2355 glUseProgram(CULL_CLUSTERS_SHADER.program);
2361
2362 glDispatchCompute(GRID_X, GRID_Y, GRID_Z);
2363 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
2364
2367
2368 if (draw_dirty)
2369 {
2372 draw_dirty = false;
2373
2374 }
2375
2377 glEndQuery(GL_TIME_ELAPSED);
2378 glBeginQuery(GL_TIME_ELAPSED, pl_queries[current_query_frame]);
2379
2380 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, GLOBAL_INSTANCE_SSBO);
2381 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, INDIRECT_ARRAYS_COMMAND_BUFFER);
2382 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, INDIRECT_ELEMENTS_COMMAND_BUFFER);
2384
2385 glEndQuery(GL_TIME_ELAPSED);
2386 glBeginQuery(GL_TIME_ELAPSED, sm_queries[current_query_frame]);
2387 glUseProgram(CULL_DRAW_CALLS_SHADER.program);
2388
2389 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, GLOBAL_INSTANCE_SSBO);
2390 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, INDIRECT_ARRAYS_COMMAND_BUFFER);
2391 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, INDIRECT_ELEMENTS_COMMAND_BUFFER);
2392
2394 vec4 planes[6];
2395 get_view_planes(planes, rprobe_cam);
2396 glUniform4fv(CULL_DRAW_CALLS_SHADER.uniforms[1].location, 6, (GLfloat*)planes);
2398
2399 glDispatchCompute((transform_count+63)/64, 1, 1);
2400 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
2401
2402
2403 if (array_offset > 0)
2404 {
2405
2406 glUseProgram(INDIRECT_PREFIX_SHADER.program);
2407
2408 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, INDIRECT_ARRAYS_COMMAND_BUFFER_OUT);
2410
2411 glDispatchCompute((array_offset+127)/128, 1, 1);
2412 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
2413
2414 }
2415
2416 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, INDIRECT_ELEMENTS_COMMAND_BUFFER);
2417 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, INDIRECT_ELEMENTS_COMMAND_BUFFER_OUT);
2418 if (element_offset > 0)
2419 {
2420
2421 glUseProgram(ELEMENTS_PREFIX_SHADER.program);
2422
2424
2425 glDispatchCompute((element_offset+127)/128, 1, 1);
2426 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
2427 }
2428
2429
2430 glBindFramebuffer(GL_FRAMEBUFFER, render_fbo);
2431 glViewport(0, 0, render_width, render_height);
2432 glClearColor(0, 0, 0, 1.0f);
2433 glClearDepth(1.0);
2434 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
2435
2436 glEnable(GL_DEPTH_TEST);
2437 glDepthMask(GL_TRUE);
2438 glDepthFunc(GL_LEQUAL);
2439
2440 glBindVertexArray(SKY_VAO);
2441 glBindBuffer(GL_ARRAY_BUFFER, SKY_VBO);
2442
2443
2444 glUseProgram(SKY_SHADER.program);
2445
2446 glActiveTexture(GL_TEXTURE0);
2447 glBindTexture(GL_TEXTURE_CUBE_MAP, SKYBOX);
2448 glUniform1i(SKY_SHADER.uniforms[0].location, 0);
2449
2450 glDrawArrays(GL_TRIANGLES, 0, 36);
2451
2452
2453 glBindFramebuffer(GL_FRAMEBUFFER, SHADOW_MAP_FBO.fbo);
2454 glViewport(0, 0, SHADOW_MAP_FBO.w, SHADOW_MAP_FBO.h);
2455 glClearColor(0, 0, 0, 1.0f);
2456 glClearDepth(1.0);
2457 glClear(GL_DEPTH_BUFFER_BIT);
2458 glBindVertexArray(MAIN_VAO);
2459 glBindBuffer(GL_ARRAY_BUFFER, MAIN_VBO);
2460 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, MAIN_EBO);
2461 glBindBuffer(GL_ARRAY_BUFFER, INSTANCE_VBO);
2462
2463 glUseProgram(SHADOW_MAP_SHADER.program);
2464 for (int i = 0; i < DIRECTIONAL_LIGHT_COUNT; i++)
2465 {
2466
2467 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, SHADOW_MAP_FBO.depth_texture.i, 0, i);
2468 glClear(GL_DEPTH_BUFFER_BIT);
2469
2470 glUniformMatrix4fv(SHADOW_MAP_SHADER.uniforms[0].location, 1, GL_FALSE, (const GLfloat*)&LIGHT_CAM[i].cam_data.proj);
2471 glUniformMatrix4fv(SHADOW_MAP_SHADER.uniforms[1].location, 1, GL_FALSE, (const GLfloat*)&LIGHT_CAM[i].cam_data.view);
2472
2473
2474
2475
2477 }
2478
2479
2480
2481
2482 glEndQuery(GL_TIME_ELAPSED);
2483 glDisable(GL_CULL_FACE);
2484
2485 glBeginQuery(GL_TIME_ELAPSED, gbuffer_queries[current_query_frame]);
2486
2487
2489 {
2490
2491 glBindFramebuffer(GL_FRAMEBUFFER, GBUFFER_FBO.fbo);
2492 glViewport(0, 0, GBUFFER_FBO.w, GBUFFER_FBO.h);
2493 }
2494 else
2495 {
2496
2497 glBindFramebuffer(GL_FRAMEBUFFER, GBUFFER_RESOLVE_FBO.fbo);
2498 glViewport(0, 0, GBUFFER_RESOLVE_FBO.w, GBUFFER_RESOLVE_FBO.h);
2499 }
2500
2501 glBindBuffer(GL_ARRAY_BUFFER, INSTANCE_VBO);
2502 glClearColor(0,0,0,1.0);
2503 glClearDepth(1.0);
2504 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2505 int i = 0;
2506 int shader = -1;
2507 while (i < draw_command_count)
2508 {
2509 DrawCommand * first_command = &DRAW_COMMANDS[i];
2510 DrawCommand * current_command = first_command;
2511
2512 int starting_array_offset = first_command->array_offset;
2513 int starting_element_offset = first_command->element_offset;
2514 int arr = 0;
2515 int el = 0;
2516
2517 while (
2518 first_command->opaque == current_command->opaque &&
2519 first_command->gbuffer_shader == current_command->gbuffer_shader &&
2521 {
2522
2523 // we are explicitly counting and this may become incorrectly phased in terms of the order of the actual draw commands on the gpu
2524 if (current_command->static_mesh)
2525 {
2526 arr++;
2527 }
2528 else
2529 {
2530 el++;
2531 }
2532 i++;
2533 current_command = &DRAW_COMMANDS[i];
2534 }
2535
2536 if (first_command->fwd_shader != shader)
2537 {
2538
2539 shader = first_command->gbuffer_shader;
2541 {
2542
2543 glUseProgram(DEPTH_PRE_PASS_SHADER_MSAA[shader].program);
2544 }
2545 else
2546 {
2547
2548 glUseProgram(DEPTH_PRE_PASS_SHADER[shader].program);
2549 }
2550
2551 }
2552 size_t start_array_offset = (sizeof(DrawArraysIndirectCommand) * starting_array_offset);
2553 size_t start_element_offset = (sizeof(DrawElementsIndirectCommand) * starting_element_offset);
2554 uint32_t array_count = arr;
2555 uint32_t element_count = el;
2556
2557
2559 {
2560
2561 draw_arrays_elements(&DEPTH_PRE_PASS_SHADER_MSAA[shader], starting_array_offset, start_array_offset, array_count, starting_element_offset, start_element_offset, element_count);
2562 }
2563 else
2564 {
2565
2566 draw_arrays_elements(&DEPTH_PRE_PASS_SHADER[shader], starting_array_offset, start_array_offset, array_count, starting_element_offset, start_element_offset, element_count);
2567 }
2568 }
2569
2571 {
2572 glBindFramebuffer(GL_READ_FRAMEBUFFER, GBUFFER_FBO.fbo);
2573 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, GBUFFER_RESOLVE_FBO.fbo);
2574 glBlitFramebuffer(0, 0, GBUFFER_FBO.w, GBUFFER_FBO.h,
2576 GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT,
2577 GL_NEAREST);
2578 }
2579
2580 glUseProgram(DEPTH_DOWNSAMPLE_SHADER.program);
2581 glBindFramebuffer(GL_FRAMEBUFFER, DEPTH_DOWNSAMPLE_FBO.fbo);
2582 glViewport(0, 0, DEPTH_DOWNSAMPLE_FBO.w, DEPTH_DOWNSAMPLE_FBO.h);
2583 glClearColor(0,0,0,1.0);
2584 glClearDepth(1.0);
2585 glClear(GL_DEPTH_BUFFER_BIT);
2586
2587 glActiveTexture(GL_TEXTURE9);
2588 // this will be pom depth since it's only used for screen space effects
2590 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2591 glUniform1i(DEPTH_DOWNSAMPLE_SHADER.uniforms[0].location, 9);
2592
2593 glDrawArrays(GL_TRIANGLES, 0, 3);
2594 glEndQuery(GL_TIME_ELAPSED);
2595
2596 glBeginQuery(GL_TIME_ELAPSED, dof_queries[current_query_frame]);
2597
2599 {
2600
2601 glBindFramebuffer(GL_FRAMEBUFFER, 0);
2602 glUseProgram(FOCAL_DISTANCE_SHADER.program);
2603
2604
2605 glActiveTexture(GL_TEXTURE10);
2606 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2607 glUniform1i(FOCAL_DISTANCE_SHADER.uniforms[0].location, 10);
2608
2612
2613 glDispatchCompute(1, 1, 1);
2614 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
2615 }
2616
2617 glEndQuery(GL_TIME_ELAPSED);
2618
2619 glBeginQuery(GL_TIME_ELAPSED, ssao_queries[current_query_frame]);
2621 {
2622
2623 glUseProgram(SSAO_SHADER.program);
2624 glBindFramebuffer(GL_FRAMEBUFFER, SSAO_FBO.fbo);
2625 glViewport(0, 0, SSAO_FBO.w, SSAO_FBO.h);
2626 glClearColor(0,0,0,1.0);
2627 glClear(GL_COLOR_BUFFER_BIT);
2628
2629 glActiveTexture(GL_TEXTURE9);
2630 if (SSAO_WIDTH == MAIN_FBO.w / 2 && SSAO_HEIGHT == MAIN_FBO.h / 2)
2631 {
2632
2633 glBindTexture(GL_TEXTURE_2D, DEPTH_DOWNSAMPLE_FBO.texture[0].i);
2634 }
2635 else
2636 {
2637 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2638 }
2639 glUniform1i(SSAO_SHADER.uniforms[0].location, 9);
2640 glActiveTexture(GL_TEXTURE10);
2641 glBindTexture(GL_TEXTURE_2D, SSAO_NOISE_TEXTURE);
2642 glUniform1i(SSAO_SHADER.uniforms[2].location, 10);
2643 glUniform2i(SSAO_SHADER.uniforms[3].location, SSAO_FBO.w, SSAO_FBO.h);
2644
2645 glDrawArrays(GL_TRIANGLES, 0, 3);
2646
2647 glUseProgram(SSAO_BLUR_SHADER.program);
2648 glBindFramebuffer(GL_FRAMEBUFFER, SSAO_BLUR_FBO.fbo);
2649 glViewport(0, 0, SSAO_BLUR_FBO.w, SSAO_BLUR_FBO.h);
2650 glClearColor(0,0,0,1.0);
2651 glClear(GL_COLOR_BUFFER_BIT);
2652
2653 glActiveTexture(GL_TEXTURE9);
2654 glBindTexture(GL_TEXTURE_2D, SSAO_FBO.texture[0].i);
2655 glUniform1i(SSAO_BLUR_SHADER.uniforms[0].location, 9);
2656 glActiveTexture(GL_TEXTURE10);
2657 if (SSAO_WIDTH == MAIN_FBO.w / 2 && SSAO_HEIGHT == MAIN_FBO.h / 2)
2658 {
2659
2660 glBindTexture(GL_TEXTURE_2D, DEPTH_DOWNSAMPLE_FBO.texture[0].i);
2661 }
2662 else
2663 {
2664 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2665 }
2666 glUniform1i(SSAO_BLUR_SHADER.uniforms[1].location, 10);
2667
2668 glDrawArrays(GL_TRIANGLES, 0, 3);
2669 }
2670
2671 glEndQuery(GL_TIME_ELAPSED);
2672
2673
2674 glBeginQuery(GL_TIME_ELAPSED, render_queries[current_query_frame]);
2675 glBindFramebuffer(GL_FRAMEBUFFER, render_fbo);
2676 glViewport(0, 0, render_width, render_height);
2677
2679
2680 glEndQuery(GL_TIME_ELAPSED);
2681
2682 glBeginQuery(GL_TIME_ELAPSED, ssr_queries[current_query_frame]);
2683 glBindFramebuffer(GL_FRAMEBUFFER, 0);
2684
2686 {
2687
2688 glBindFramebuffer(GL_READ_FRAMEBUFFER, MAIN_FBO.fbo);
2689
2690 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, MAIN_RESOLVE_FBO.fbo);
2691 glBlitFramebuffer(0, 0, MAIN_FBO.w, MAIN_FBO.h,
2693 GL_COLOR_BUFFER_BIT,
2694 GL_NEAREST);
2695 }
2696
2697
2699 {
2700
2701 glUseProgram(SSR_SHADER.program);
2702 glBindFramebuffer(GL_FRAMEBUFFER, SSR_FBO.fbo);
2703 glViewport(0, 0, SSR_FBO.w, SSR_FBO.h);
2704
2705 glClearColor(0,0,0,1.0);
2706 glClear(GL_COLOR_BUFFER_BIT);
2707
2708
2709 glActiveTexture(GL_TEXTURE9);
2710 glBindTexture(GL_TEXTURE_2D, GBUFFER_RESOLVE_FBO.texture[GNORMAL].i);
2711 glUniform1i(SSR_SHADER.uniforms[0].location, 9);
2712 glActiveTexture(GL_TEXTURE10);
2713 if (SSR_WIDTH == MAIN_FBO.w / 2 && SSR_HEIGHT == MAIN_FBO.h / 2)
2714 {
2715
2716 glBindTexture(GL_TEXTURE_2D, DEPTH_DOWNSAMPLE_FBO.texture[0].i);
2717 }
2718 else
2719 {
2720 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2721 }
2722 glUniform1i(SSR_SHADER.uniforms[1].location, 10);
2723 glActiveTexture(GL_TEXTURE11);
2724 glBindTexture(GL_TEXTURE_2D, GBUFFER_RESOLVE_FBO.texture[GALBEDO].i);
2725 glUniform1i(SSR_SHADER.uniforms[2].location, 11);
2726 glActiveTexture(GL_TEXTURE12);
2727 glBindTexture(GL_TEXTURE_2D, GBUFFER_RESOLVE_FBO.texture[GEXTRA].i);
2728 glUniform1i(SSR_SHADER.uniforms[3].location, 12);
2729 glActiveTexture(GL_TEXTURE13);
2730 glBindTexture(GL_TEXTURE_2D, MAIN_RESOLVE_FBO.texture[0].i);
2731 glUniform1i(SSR_SHADER.uniforms[4].location, 13);
2732 glUniform1f(SSR_SHADER.uniforms[5].location, time);
2733
2734 glDrawArrays(GL_TRIANGLES, 0, 3);
2735
2736 }
2737 glEndQuery(GL_TIME_ELAPSED);
2738
2739
2740
2741 glBeginQuery(GL_TIME_ELAPSED, taa_queries[current_query_frame]);
2743 {
2744
2745 glUseProgram(SSR_HISTORY_SHADER.program);
2746 glBindFramebuffer(GL_FRAMEBUFFER, TAA_FBO[cur_history].fbo);
2747 glViewport(0, 0, TAA_FBO[cur_history].w, TAA_FBO[cur_history].h);
2748 glClearColor(0,0,0,1.0);
2749 glClear(GL_COLOR_BUFFER_BIT);
2750 if (EDITOR_SETTINGS.SSR)
2751 {
2752
2753 glActiveTexture(GL_TEXTURE0);
2754 glBindTexture(GL_TEXTURE_2D, SSR_FBO.texture[0].i);
2755 }
2756 else
2757 {
2758 glActiveTexture(GL_TEXTURE0);
2759 glBindTexture(GL_TEXTURE_2D, 0);
2760
2761 }
2762 glUniform1i(SSR_HISTORY_SHADER.uniforms[0].location, 0);
2763 glActiveTexture(GL_TEXTURE3);
2764 glBindTexture(GL_TEXTURE_2D, MAIN_RESOLVE_FBO.texture[0].i);
2765 glUniform1i(SSR_HISTORY_SHADER.uniforms[1].location, 3);
2766 glActiveTexture(GL_TEXTURE1);
2767 glBindTexture(GL_TEXTURE_2D, TAA_FBO[cur_history ^ 1].texture[0].i);
2768 glUniform1i(SSR_HISTORY_SHADER.uniforms[2].location, 1);
2769 glActiveTexture(GL_TEXTURE2);
2770 glBindTexture(GL_TEXTURE_2D, GBUFFER_RESOLVE_FBO.texture[GVEL].i);
2771 glUniform1i(SSR_HISTORY_SHADER.uniforms[3].location, 2);
2772 glActiveTexture(GL_TEXTURE10);
2773 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2774 glUniform1i(SSR_HISTORY_SHADER.uniforms[4].location, 10);
2775 glUniform2f(SSR_HISTORY_SHADER.uniforms[5].location, JITTER_OFFSET.x * 0.5, JITTER_OFFSET.y * 0.5);
2776
2777 glDrawArrays(GL_TRIANGLES, 0, 3);
2778
2779 }
2780 glEndQuery(GL_TIME_ELAPSED);
2781 glDisable(GL_BLEND);
2782
2783
2784 glBeginQuery(GL_TIME_ELAPSED, dof_queries[current_query_frame]);
2786 {
2787
2788 glUseProgram(COC_SHADER.program);
2789 glBindFramebuffer(GL_FRAMEBUFFER, COC_FBO.fbo);
2790 glViewport(0, 0, COC_FBO.w, COC_FBO.h);
2791 glClearColor(0,0,0,1.0);
2792 glClear(GL_COLOR_BUFFER_BIT);
2793
2794 glActiveTexture(GL_TEXTURE0);
2795 if (DOF_WIDTH == MAIN_FBO.w / 2 && DOF_HEIGHT == MAIN_FBO.h / 2)
2796 {
2797
2798 glBindTexture(GL_TEXTURE_2D, DEPTH_DOWNSAMPLE_FBO.texture[0].i);
2799 }
2800 else
2801 {
2802 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2803 }
2804 glUniform1i(COC_SHADER.uniforms[0].location, 0);
2805 glActiveTexture(GL_TEXTURE1);
2806 if (EDITOR_SETTINGS.TAA)
2807 {
2808 glBindTexture(GL_TEXTURE_2D, TAA_FBO[cur_history].texture[0].i);
2809
2810 }
2811 else
2812 {
2813 glBindTexture(GL_TEXTURE_2D, MAIN_RESOLVE_FBO.texture[0].i);
2814
2815 }
2816 glUniform1i(COC_SHADER.uniforms[1].location, 1);
2821
2822 glDrawArrays(GL_TRIANGLES, 0, 3);
2823
2824 glUseProgram(BOKEH_SHADER.program);
2825 glBindFramebuffer(GL_FRAMEBUFFER, BOKEH_FBO.fbo);
2826 glViewport(0, 0, BOKEH_FBO.w, BOKEH_FBO.h);
2827 glClearColor(0,0,0,1.0);
2828 glClear(GL_COLOR_BUFFER_BIT);
2829
2830 glActiveTexture(GL_TEXTURE0);
2831 glBindTexture(GL_TEXTURE_2D, COC_FBO.texture[0].i);
2832 glUniform1i(BOKEH_SHADER.uniforms[0].location, 0);
2833 glUniform2f(BOKEH_SHADER.uniforms[1].location, 1.0f/DOF_WIDTH, 1.0f/DOF_HEIGHT);
2834
2835 glDrawArrays(GL_TRIANGLES, 0, 3);
2836
2837 }
2838
2839 glEndQuery(GL_TIME_ELAPSED);
2840 glBeginQuery(GL_TIME_ELAPSED, bloom_queries[current_query_frame]);
2842 {
2843 glUseProgram(BLOOM_SHADER.program);
2844 glBindFramebuffer(GL_FRAMEBUFFER, BLOOM_PYRAMID[0].fbo);
2845 glViewport(0, 0, BLOOM_PYRAMID[0].w, BLOOM_PYRAMID[0].h);
2846 glClearColor(0,0,0,1.0);
2847 glClear(GL_COLOR_BUFFER_BIT);
2848
2849 glActiveTexture(GL_TEXTURE0);
2850 if (EDITOR_SETTINGS.TAA)
2851 {
2852
2853 glBindTexture(GL_TEXTURE_2D, TAA_FBO[cur_history].texture[0].i);
2854 }
2855 else
2856 {
2857
2858 glBindTexture(GL_TEXTURE_2D, MAIN_RESOLVE_FBO.texture[0].i);
2859 }
2860 glUniform1i(BLOOM_SHADER.uniforms[0].location, 0);
2861
2862 glDrawArrays(GL_TRIANGLES, 0, 3);
2863
2864
2865 glDisable(GL_BLEND);
2866 glUseProgram(BLOOM_DOWNSCALE_SHADER.program);
2867 for (int i = 0; i < 5; i++)
2868 {
2869
2870 Framebuffer * src = &BLOOM_PYRAMID[i];
2871 Framebuffer * dst = &BLOOM_PYRAMID[i + 1];
2872
2873 glViewport(0, 0, dst->w, dst->h);
2874 glBindFramebuffer(GL_FRAMEBUFFER, dst->fbo);
2875
2876 glActiveTexture(GL_TEXTURE0);
2877 glBindTexture(GL_TEXTURE_2D, src->texture[0].i);
2878 glUniform1i(BLOOM_DOWNSCALE_SHADER.uniforms[0].location, 0);
2879
2880 glDrawArrays(GL_TRIANGLES, 0, 3);
2881
2882 }
2883
2884
2885 glEnable(GL_BLEND);
2886 glBlendFunc(GL_ONE, GL_ONE);
2887 glBlendEquation(GL_FUNC_ADD);
2888 glUseProgram(BLOOM_UPSCALE_SHADER.program);
2889
2890 for (int i = 4; i >= 0; i--)
2891 {
2892
2893 Framebuffer * src = &BLOOM_PYRAMID[i+1];
2894 Framebuffer * dst = &BLOOM_PYRAMID[i];
2895
2896 glViewport(0, 0, dst->w, dst->h);
2897 glBindFramebuffer(GL_FRAMEBUFFER, dst->fbo);
2898
2899 glActiveTexture(GL_TEXTURE0);
2900 glBindTexture(GL_TEXTURE_2D, src->texture[0].i);
2901 glUniform1i(BLOOM_UPSCALE_SHADER.uniforms[0].location, 0);
2902
2903 glUniform1f(BLOOM_UPSCALE_SHADER.uniforms[1].location, 0.005f);
2904
2905 glDrawArrays(GL_TRIANGLES, 0, 3);
2906
2907 }
2908 glDisable(GL_BLEND);
2909 }
2910
2911 glEndQuery(GL_TIME_ELAPSED);
2912}
2913
2914
2915int find_depth(BVHNode * nodes, BVHNode * node, int depth)
2916{
2917 int l = depth;
2918 if (node->left != -1)
2919 {
2920 l = find_depth(nodes, &nodes[node->left], depth + 1);
2921 }
2922 int r = depth;
2923 if (node->right != -1)
2924 {
2925 r = find_depth(nodes, &nodes[node->right], depth + 1);
2926 }
2927
2928 return MAX(l, r);
2929}
2930
2931void render_tree(BVHNode * nodes, BVHNode * node, mat4 tr, DebugVertex * points, int * count, int depth, int max_depth, vec3 start_color, vec3 end_color)
2932{
2933
2934
2935
2936 if (node->left == -1 && node->right == -1)
2937 {
2938
2939 DebugVertex * v = &points[*count];
2941 aabb_to_vertices(v, &a, (vec3){0,0,0});
2942 for (int j = 0; j < 24; j++)
2943 {
2944 v[j].color = vec3_lerp(start_color, end_color, (float)depth / max_depth);
2945 }
2946 *count += 24;
2947 }
2948
2949 if (node->left != -1)
2950 {
2951 render_tree(nodes, &nodes[node->left], tr, points, count, depth + 1, max_depth, start_color, end_color);
2952 }
2953 if (node->right != -1)
2954 {
2955 render_tree(nodes, &nodes[node->right], tr, points, count, depth + 1, max_depth, start_color, end_color);
2956 }
2957
2958}
2959
2960void render_bvh(BVHNode * nodes, int node_count, mat4 tr)
2961{
2962
2963 int depth = find_depth(nodes, nodes, 0);
2964
2965
2966 DebugVertex * points = malloc(sizeof(DebugVertex) * node_count * 24);
2967 int count = 0;
2968 render_tree(nodes, nodes, tr, points, &count, 0, depth, (vec3){0,0,1}, (vec3){1,0,0});
2969
2970 glBindBuffer(GL_ARRAY_BUFFER, WIREFRAME_VBO);
2971 glBufferData(GL_ARRAY_BUFFER, sizeof(DebugVertex) * count, points, GL_STREAM_DRAW);
2972 glDrawArrays(GL_LINES, 0, count);
2973
2974 free(points);
2975
2976}
2977
2978
2979void render_probe_volume(ProbeVolume * pv, bool audio)
2980{
2981
2982 OBB obb = pv->obb;
2984 for (int j = 0; j < 24; j++)
2985 {
2986 DEBUG_LINES[DEBUG_LINE_COUNT + j].color = (vec3){0,0,1};
2987 }
2988 DEBUG_LINE_COUNT += 24;
2990 {
2991 float dx = (obb.extents.x * 2) / (pv->resolution.x-1);
2992 float dy = (obb.extents.y * 2) / (pv->resolution.y-1);
2993 float dz = (obb.extents.z * 2) / (pv->resolution.z-1);
2994
2995 vec3 fwd = {obb.rot.a0, obb.rot.b0, obb.rot.c0};
2996 vec3 right = {obb.rot.a1, obb.rot.b1, obb.rot.c1};
2997 vec3 up = {obb.rot.a2, obb.rot.b2, obb.rot.c2};
2998
2999 vec3 step_x, step_y, step_z;
3000 step_x.x = fwd.x * dx;
3001 step_x.y = fwd.y * dx;
3002 step_x.z = fwd.z * dx;
3003
3004 step_y.x = right.x * dy;
3005 step_y.y = right.y * dy;
3006 step_y.z = right.z * dy;
3007
3008 step_z.x = up.x * dz;
3009 step_z.y = up.y * dz;
3010 step_z.z = up.z * dz;
3011
3012 vec3 pos = vec3_add(obb.center,
3013 vec3_add(vec3_scale(fwd, -obb.extents.x),
3014 vec3_add(vec3_scale(right, -obb.extents.y),
3015 vec3_scale(up, -obb.extents.z))));
3016
3017 vec3 current_pos = pos;
3018 for (int z = 0; z < pv->resolution.z; z++)
3019 {
3020 for (int y = 0; y < pv->resolution.y; y++)
3021 {
3022
3023 for (int x = 0; x < pv->resolution.x; x++)
3024 {
3025
3026 int index = z * pv->resolution.y * pv->resolution.x + y * pv->resolution.x + x;
3027 vec3 color = {0.3, 0.3, 0};
3028 if (index == DEBUG_CURRENT_APROBE)
3029 {
3030 color = (vec3){1,1,1};
3031 }
3032 if (index == 0)
3033 {
3034 color = (vec3){1,0,0};
3035 }
3036 current_pos.x = pos.x + x * step_x.x + y * step_y.x + z * step_z.x;
3037 current_pos.y = pos.y + x * step_x.y + y * step_y.y + z * step_z.y;
3038 current_pos.z = pos.z + x * step_x.z + y * step_y.z + z * step_z.z;
3039 AABB aabb;
3040 aabb.center = current_pos;
3042 if (DEBUG_LINE_COUNT + 24 >= DEBUG_LINES_MAX) break;
3044 for (int j = 0; j < 24; j++)
3045 {
3046
3048 }
3049 DEBUG_LINE_COUNT += 24;
3050 }
3051 }
3052 }
3053 }
3054}
3055
3056
3058{
3059
3060 master_frame++;
3061
3062
3063 if (RENDER_FENCE[current_frame] != NULL)
3064 {
3065 GLenum waitReturn = glClientWaitSync(RENDER_FENCE[current_frame], GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED);
3066
3067 glDeleteSync(RENDER_FENCE[current_frame]);
3069
3070 }
3071
3072 Animation * anim = find_animation("Shrieker_Walk", 0);
3073 if (anim)
3074 {
3075 bool still_has_time = (time <= animation_length(anim));
3076 play_animation(anim, time, 0);
3077 time += frame_time;
3078 if (!still_has_time) time = 0;
3079 }
3080
3081
3082 Light * lights = CAST_VEC(GLOBALS.lights, Light);
3083
3084
3086 {
3087
3089 }
3090 else
3091 {
3093
3094 }
3095
3096 glBeginQuery(GL_TIME_ELAPSED, main_queries[current_query_frame]);
3097
3098
3099 glDisable(GL_DEPTH_TEST);
3100
3101 glDisable(GL_CULL_FACE);
3102
3104
3105 glUseProgram(UI_SHADER.program);
3106 glBindFramebuffer(GL_FRAMEBUFFER, TEXT_FBO.fbo);
3107 glViewport(0, 0, TEXT_FBO.w, TEXT_FBO.h);
3108 glClearColor(0.0,0.0,0.0,0.0);
3109 glClear(GL_COLOR_BUFFER_BIT);
3110 glBindVertexArray(UI_VAO);
3111 mat4 text_ortho = make_ortho(0, TEXT_FBO.w, TEXT_FBO.h, 0, -1.0f, 1.0f);
3112
3113 glUniformMatrix4fv(UI_SHADER.uniforms[0].location, 1, GL_FALSE, (GLfloat*)&text_ortho);
3114
3115 glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 6, ui_element_count, current_frame * MAX_UI_ELEMENTS);
3116
3117
3118
3119
3120 glUseProgram(TEXT_SHADER.program);
3121 glBindFramebuffer(GL_FRAMEBUFFER, TEXT_FBO.fbo);
3122 glViewport(0, 0, TEXT_FBO.w, TEXT_FBO.h);
3123 glBindVertexArray(TEXT_VAO);
3124 glBindBuffer(GL_ARRAY_BUFFER, TEXT_VBO);
3125 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, TEXT_EBO);
3126
3127 glUniformMatrix4fv(TEXT_SHADER.uniforms[0].location, 1, GL_FALSE, (GLfloat*)&text_ortho);
3128
3129 Image * images = CAST_VEC(GLOBALS.images, Image);
3130 Font * fonts = CAST_VEC(FONTS, Font);
3131 Font * font = &fonts[0];
3132 Image * image = &images[font->texture];
3133
3134 glActiveTexture(GL_TEXTURE0);
3135 glBindTexture(GL_TEXTURE_2D, image->i);
3136 glUniform1i(TEXT_SHADER.uniforms[1].location, 0);
3137 glUniform1ui(TEXT_SHADER.uniforms[2].location, 1);
3138
3139
3140 glDrawElements(GL_TRIANGLES, TEXT_INDEX_COUNT, GL_UNSIGNED_INT, (void*)0);
3141
3142 glUniform1ui(TEXT_SHADER.uniforms[2].location, 0);
3143 glDrawElements(GL_TRIANGLES, TEXT_INDEX_COUNT, GL_UNSIGNED_INT, (void*)0);
3144
3145
3146 glBindVertexArray(WIREFRAME_VAO);
3147 glBindBuffer(GL_ARRAY_BUFFER, WIREFRAME_VBO);
3149 {
3150
3151 glUseProgram(WIREFRAME_SHADER.program);
3154 BVHNode * nodes = CAST_VEC(sd->bvh_nodes, BVHNode);
3155
3156 Mesh * meshes = CAST_VEC(GLOBALS.meshes, Mesh);
3158
3160
3161
3162 UVIsland * islands = CAST_VEC(ld->islands, UVIsland);
3163 Vector points;
3164
3166 {
3167
3169
3170 DEBUG_LINES[DEBUG_LINE_COUNT + 0].color = (vec3){1,0.6,0};
3172 DEBUG_LINES[DEBUG_LINE_COUNT + 1].color = (vec3){1,0.2,1};
3174
3175 DEBUG_LINE_COUNT += 2;
3176
3177 }
3178
3180 {
3181
3182
3184 for (int i = 0; i < GLOBALS.audio_portals.count; i++)
3185 {
3186
3187 AudioPortal * p = &portals[i];
3188 AABB aabb;
3189 aabb.center = p->pos;
3191 if (DEBUG_LINE_COUNT + 24 >= DEBUG_LINES_MAX) break;
3193 for (int j = 0; j < 24; j++)
3194 {
3195 DEBUG_LINES[DEBUG_LINE_COUNT + j].color = (vec3){0.2,0.6,1.0};
3196 }
3197 DEBUG_LINE_COUNT += 24;
3198 }
3199
3200 }
3201
3203 {
3204
3205 for (int i = 0; i < MAX_AUDIO_EMITTERS; i++)
3206 {
3207 if (AUDIO_EMITTERS[i].free) continue;
3208 AudioEmitter * e = &AUDIO_EMITTERS[i];
3209 AABB aabb;
3210 aabb.center = e->pos;
3212 if (DEBUG_LINE_COUNT + 24 >= DEBUG_LINES_MAX) break;
3214 for (int j = 0; j < 24; j++)
3215 {
3216 DEBUG_LINES[DEBUG_LINE_COUNT + j].color = (vec3){1,0.6,0.7};
3217 }
3218 DEBUG_LINE_COUNT += 24;
3219 }
3220 }
3221
3246
3247
3248
3249 for (int i = 0; i < GLOBALS.lights.count; i++)
3250 {
3251 Light * l = &lights[i];
3252 AABB aabb;
3253 aabb.center = l->pos;
3255 if (DEBUG_LINE_COUNT + 24 >= DEBUG_LINES_MAX) break;
3257 for (int j = 0; j < 24; j++)
3258 {
3260 }
3261 DEBUG_LINE_COUNT += 24;
3262 }
3264 for (int i = 0; i < GLOBALS.scene_data.reflection_probes.count; i++)
3265 {
3266
3267 ReflectionProbe * probe = &probes[i];
3268 AABB aabb = probe->aabb;
3269 if (DEBUG_LINE_COUNT + 24 >= DEBUG_LINES_MAX) break;
3271 for (int j = 0; j < 24; j++)
3272 {
3273 DEBUG_LINES[DEBUG_LINE_COUNT + j].color = (vec3){0,1,0};
3274 }
3275 DEBUG_LINE_COUNT += 24;
3276
3277 AABB cap_pos;
3278 aabb.center = probe->capture_pos;
3280 if (DEBUG_LINE_COUNT + 24 >= DEBUG_LINES_MAX) break;
3282 for (int j = 0; j < 24; j++)
3283 {
3284 DEBUG_LINES[DEBUG_LINE_COUNT + j].color = (vec3){0,1,1};
3285 }
3286 DEBUG_LINE_COUNT += 24;
3287
3288 }
3289
3290 // for now only displaying audio probe volumes
3292 for (int i = 0; i < GLOBALS.scene_data.audio_probe_volumes.count; i++)
3293 {
3294 if (DEBUG_LINE_COUNT + 24 >= DEBUG_LINES_MAX) break;
3295 render_probe_volume(&pvs[i], true);
3296
3297 }
3299 for (int i = 0; i < GLOBALS.scene_data.lighting_probe_volumes.count; i++)
3300 {
3301 if (DEBUG_LINE_COUNT + 24 >= DEBUG_LINES_MAX) break;
3302 render_probe_volume(&lpvs[i], false);
3303 }
3304
3305
3306 glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(DebugVertex) * DEBUG_LINE_COUNT, DEBUG_LINES);
3307 glDrawArrays(GL_LINES, 0, DEBUG_LINE_COUNT);
3308 }
3309
3310
3311 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3312 glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
3313 glClearColor(0, 0, 0, 1.0f);
3314 glClearDepth(1.0);
3315 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3316
3317
3318 int pp_shader_idx = -1;
3319
3321 {
3322
3323 uint32_t pp_perm = 0;
3325 {
3326
3327 pp_perm |= (1 << PP_MBLUR);
3328 }
3329 if (EDITOR_SETTINGS.DOF)
3330 {
3331
3332 pp_perm |= (1 << PP_DOF);
3333 }
3335 {
3336
3337 pp_perm |= (1 << PP_BLOOM);
3338 }
3340 {
3341 pp_perm |= (1 << PP_NOISE);
3342 }
3344 {
3345 pp_perm |= (1 << PP_ACES);
3346 }
3347 if (EDITOR_SETTINGS.LUT)
3348 {
3349 pp_perm |= (1 << PP_LUT);
3350 }
3351 for (int i = 0; i < PP_SHADER_VERSIONS; i++)
3352 {
3353 if (pp_perm == POSTPROCESS_SHADER[i].perm)
3354 {
3355 pp_shader_idx = i;
3356 break;
3357 }
3358 }
3359 if (pp_shader_idx == -1)
3360 {
3361 printf("ERROR: PP SHADER NOT FOUND\n");
3362 pp_shader_idx = 0;
3363 }
3364 }
3365 else
3366 {
3367 pp_shader_idx = PP_SHADER_VERSIONS + EDITOR_SETTINGS.pp_dview - 1;
3368 }
3369
3370
3371 ShaderProgram * pp_shader = &POSTPROCESS_SHADER[pp_shader_idx];
3372
3373 glUseProgram(pp_shader->program);
3374
3375 glActiveTexture(GL_TEXTURE0);
3376 glBindTexture(GL_TEXTURE_2D, MAIN_RESOLVE_FBO.texture[0].i);
3377
3378 glUniform1i(pp_shader->uniforms[0].location, 0);
3379 glActiveTexture(GL_TEXTURE1);
3380 glBindTexture(GL_TEXTURE_2D, HISTORY_TEXTURE[cur_history]);
3381 glUniform1i(pp_shader->uniforms[1].location, 1);
3382 glUniform1f(pp_shader->uniforms[2].location, time);
3383 glUniform1ui(pp_shader->uniforms[3].location, EDITOR_SETTINGS.MBLUR);
3384 glUniform1ui(pp_shader->uniforms[4].location, EDITOR_SETTINGS.TAA);
3385 glUniform1ui(pp_shader->uniforms[13].location, EDITOR_SETTINGS.DOF);
3386 glActiveTexture(GL_TEXTURE7);
3387 glBindTexture(GL_TEXTURE_2D, FBM_TEXTURE);
3388 glUniform1i(pp_shader->uniforms[5].location, 7);
3389 glActiveTexture(GL_TEXTURE8);
3390 glBindTexture(GL_TEXTURE_2D, GBUFFER_RESOLVE_FBO.depth_texture.i);
3391 glUniform1i(pp_shader->uniforms[6].location, 8);
3392 glActiveTexture(GL_TEXTURE2);
3393 glBindTexture(GL_TEXTURE_2D, TEXT_FBO.texture[0].i);
3394 glUniform1i(pp_shader->uniforms[7].location, 2);
3395 if (EDITOR_SETTINGS.TAA)
3396 {
3397
3398 glActiveTexture(GL_TEXTURE10);
3399 glBindTexture(GL_TEXTURE_2D, TAA_FBO[cur_history].texture[0].i);
3400 glGenerateMipmap(GL_TEXTURE_2D);
3401 glUniform1i(pp_shader->uniforms[8].location, 10);
3402 }
3403 else
3404 {
3405
3406 glActiveTexture(GL_TEXTURE10);
3407 glBindTexture(GL_TEXTURE_2D, MAIN_RESOLVE_FBO.texture[0].i);
3408 glUniform1i(pp_shader->uniforms[8].location, 10);
3409 }
3410 glActiveTexture(GL_TEXTURE11);
3411 // we aren't blurring ssr?
3412 glBindTexture(GL_TEXTURE_2D, SSR_FBO.texture[0].i);
3413 glUniform1i(pp_shader->uniforms[9].location, 11);
3414 glActiveTexture(GL_TEXTURE3);
3415 glBindTexture(GL_TEXTURE_2D, GBUFFER_RESOLVE_FBO.texture[GVEL].i);
3416 glUniform1i(pp_shader->uniforms[10].location, 3);
3417 glActiveTexture(GL_TEXTURE4);
3418 glBindTexture(GL_TEXTURE_2D, BOKEH_FBO.texture[0].i);
3419 glUniform1i(pp_shader->uniforms[11].location, 4);
3420 glActiveTexture(GL_TEXTURE5);
3421 glBindTexture(GL_TEXTURE_2D, COC_FBO.texture[0].i);
3422 glUniform1i(pp_shader->uniforms[12].location, 5);
3423 glActiveTexture(GL_TEXTURE6);
3424 glBindTexture(GL_TEXTURE_2D, BLOOM_PYRAMID[0].texture[0].i);
3425 glUniform1i(pp_shader->uniforms[14].location, 6);
3426 glActiveTexture(GL_TEXTURE9);
3427 glBindTexture(GL_TEXTURE_3D, COLOR_GRADE_LUT);
3428 glUniform1i(pp_shader->uniforms[15].location, 9);
3429 glActiveTexture(GL_TEXTURE12);
3430 glBindTexture(GL_TEXTURE_2D, GLOBALS.scene_data.lightmap_data.texture_id);
3431 glUniform1i(pp_shader->uniforms[20].location, 12);
3432 glUniform1f(glGetUniformLocation(pp_shader->program, "uPhysicsFramerate"), 60);
3433 glUniform1f(glGetUniformLocation(pp_shader->program, "uRenderFramerate"), EDITOR_SETTINGS.render_framerate_target);
3434 glUniform1ui(glGetUniformLocation(pp_shader->program, "uWireframeToggled"), EDITOR_SETTINGS.wireframe_toggled);
3435 glUniform1f(pp_shader->uniforms[16].location, EDITOR_SETTINGS.DOF_focal_length);
3436 glUniform1f(pp_shader->uniforms[17].location, EDITOR_SETTINGS.DOF_fstop);
3437 glUniform1f(pp_shader->uniforms[18].location, EDITOR_SETTINGS.DOF_sensor_height);
3438 glUniform1f(pp_shader->uniforms[19].location, EDITOR_SETTINGS.DOF_max_blur_radius);
3439
3440 glDrawArrays(GL_TRIANGLES, 0, 3);
3441
3442 glEndQuery(GL_TIME_ELAPSED);
3443
3444
3445
3446 RENDER_FENCE[current_frame] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
3447
3449 cur_history ^= 1;
3450 if (master_frame % 2000 == 0)
3451 {
3452 printf("FINISHING\n");
3453 glFinish();
3454 }
3455
3456}
3457
3458
3459
void play_animation(Animation *anim, float time, int asset_instance)
Plays an animation at a certain time value.
Definition animation.c:68
Animation * find_animation(const char *name, int asset_instance)
Finds an animation via name.
Definition animation.c:91
float animation_length(Animation *anim)
Finds the length of an animation.
Definition animation.c:10
Skeletal animation and animation component playback and management.
layout(local_size_x=16, local_size_y=16) in
mat4 make_ortho(float left, float right, float bottom, float top, float near, float far)
Makes an 4x4 orthographic matrix.
Definition camera.c:179
void compute_camera_basis(Camera *cam, float yaw, float pitch, float roll, vec3 world_up)
Computes camera vectors based on yaw, pitch, and roll.
Definition camera.c:136
mat4 make_look_at(Camera *cam, vec3 eye)
Makes a 4x4 view matrix using camera vectors.
Definition camera.c:258
mat4 make_projection(float fov_deg, float aspect, float near, float far)
Makes an 4x4 projection matrix.
Definition camera.c:221
Functions for camera.
Camera cam
This is currently the player cam.
Definition main.c:322
bool aabb_in_frustum(vec3 min, vec3 max)
uniform vec4 planes[6]
AABBBounds transform_aabb_by_model_matrix(MeshNode mn, mat4 mat)
uniform int index_offset
Definition dynamic.frag:234
uniform int probe_bake
Definition dynamic.frag:235
uniform int material
Definition dynamic.frag:215
uniform uint n
DrawArraysIndirect commands are used for non-static meshes.
Engine specific types and defines.
uint8_t static_mesh
If it is a static mesh.
AABB aabb
Bounding box of area.
int joint_count
The amount of joints.
bool lights_dirty
If lights need to be reuploaded.
uint32_t array_offset
The offset into INDIRECT_ARRAYS_COMMAND_BUFFER.
uint32_t static_mesh
vec3 p_right
The current right foot position.
uint16_t spot_light_offset
ivec4 joint_indices
The indices for each joint matrix (skeletal animations).
vec2 LightmapUV[3]
The lightmap UVs stored on UVIslands per MeshFace.
Vector mesh_nodes
MeshNodes.
bool free
Indicates an empty slot in ASSET_INSTANCES.
size_t lm_offset
The starting index in LIGHTMAP_DATA that this SubMesh points to.
#define MAX_LIGHTS_PER_CLUSTER
LightType
Enum for types of Lights.
@ POINT_LIGHT
@ SPOT_LIGHT
@ DIRECTIONAL_LIGHT
vec3 right_hip_pos
The right hip pos, offset by right_leg_offset.
GLuint texture_id
The texture ID for the current lightmap.
uint32_t start_index
Where the indices / vertices start for this SubMesh in MAIN_VBO.
LightmapUV * uvs
The uvs for each MeshFace on this islands.
float absorption_coefficients[6]
SceneData scene_data
SceneData that is more-so scene specific.
mat4 tr
The Transform's matrix.
uint32_t alpha_mode
uint8_t material
The Material ID into Globals.materials.
#define GRID_Z
uint32_t mesh
LightmapGPU * uvs
uint16_t directional_light_count
mat4 matrix
The transformation matrix of the MeshNode.
Vector bvh_nodes
GLuint i
The image handle for this texture.
ivec3 probe_tex_size
The texture size for lighting probes.
#define MAX_RPROBES_PER_FRAME
Max ReflectionProbes to push to UBOs per frame (for sizing).
#define MAX_DRAW_COMMANDS
Maxmimum amount of draw commands to push to the gpu.
uint32_t probe_count
uint32_t mn_id
The MeshNode this belongs to.
@ PP_MBLUR
@ PP_LUT
@ PP_BLOOM
@ PP_DOF
@ PP_ACES
@ PP_NOISE
size_t skin_count
The amount of GLTFSkins in this instance.
uvec2 spot_lights
Spot Lights count and offset.
#define MINIMUM_LIGHT_VISIBILITY_DIST
Light visibility dist used for culling (only used for spot Lights(?) now).
vec3 extents
uint64_t albedo_handle
Skeleton skeleton
Player Skeleton.
vec3 capture_pos
The position to capture the cubemap from.
vec3 p_left
The current left foot position.
uint32_t lm_offset
Lightmap offset into LIGHTMAP_DATA / LIGHTMAP_SSBO.
float outer_cos
Precomputed when uploading to the GPU for SPOT_LIGHTs.
size_t index_count
The amount of indices that this SubMesh refers to: Mesh.tris -> MeshFace.indices.
vec3 pos
The position.
Mesh mesh
The Mesh for the ConvexHull used for collisions (an AABB).
#define LPV_SLOTS
MeshNodeDataGPU mns[1024]
Vector audio_portals
AudioPortals.
uint32_t loaded
vec4 weights
The weights each joint is multiplied by.
uint32_t command_id
The DrawCommand this refers to.
Vector meshes
Meshes.
GLuint program
Program handle.
uint32_t mn_id
The MeshNode.
float cos_diff
Precomputed when uploading to the GPU for SPOT_LIGHTs.
vec2 uv
The texture coordinates.
uint8_t fwd_shader
The shader in DYNAMIC_SHADER.
int h
Dimensions.
#define MAX_DIRECTIONAL_LIGHTS
Maxmimum directional Lights at one time (used for shadowmap sizing).
uint32_t material
The Material ID for this submesh.
#define VIEW_NEAR
Near plane for player.
vec3 axis_z
mat4 * inverse_bind
The inverse_bind that is computed on load_gltf().
uint16_t spot_light_count
#define MAX_LIGHTS
Maximum amount of Lights to be pushed per frame (used for SSBO sizing).
vec3 world_min
Unused but uploaded to main shader.
Globals GLOBALS
Engine Globals.
Definition main.c:310
size_t * node_indices
The indices of MeshNodes spawned from this instance inside of Globals.mesh_nodes.
size_t first_index
The first index that this SubMesh refers to (Mesh.tris count * 3).
uint64_t arm_handle
int * joints
The joints for skeletal animating.
vec3 axis_y
GLTexture depth_texture
The normal depth texture, if there is one.
LPV LOADED_LIGHTING_PV[6]
Load slots for lighting ProbeVolumes.
Vector reflection_probes
ReflectionProbes in the scene.
Vector lights
Lights.
int ssbo_offset
The offset into JOINT_SSBO.
float probe_spacing
The spacing between lighting probes.
vec3 forward
uint8_t opaque
How opaque a Material is.
uint32_t * mesh_light_indices
Buffer used when calling determine_light_visibility_per_mesh.
vec3 q_right
The current knee position for right leg.
Camera LIGHT_CAM[4]
DIRECTIONAL_LIGHT Cameras for shadowmaps
Definition main.c:323
uint16_t mesh_id
The Mesh.
Vector lighting_probe_volumes
All of the lighting probe volumes, regardless of if they have been loaded yet.
struct RProbeUBO::Align16 probe_indices[4]
#define MAX_LIGHTS_PER_MESH
Max directional + spot Lights to push at one time for a Mesh.
MaterialGPU materials[256]
Vector audio_probe_volumes
All of the AudioProbe% volumes, regardless of if they have been loaded yet.
uint64_t sort_key
The key that is sorted in create_and_sort_draw_commands().
uint32_t double_sided
size_t node_count
The amount of MeshNodes in this instance.
size_t material
The Material.
vec3 normal
The normal.
GLTexture texture[6]
The textures bound to this fbo.
uint16_t point_light_offset
Vector images
Images.
vec3 q_left
The current knee position for left leg.
@ PPDVIEW_DEFAULT
vec3 center
uvec2 directional_lights
Directional Lights count and offset.
size_t uv_island
What island inside of LightmapData.islands that this MeshFace refers to.
uint16_t skin_offset
The offset into JOINT_SSBO.
mat4 view
The view matrix.
float pitch
Vector materials
Materials.
@ DVIEW_DEFAULT
mat4 * final_mat
The transformation after update_skin_matrices().
#define VIEW_FAR
Far plane for player.
GLuint64 handle
The handle for the bindless texture.
uint32_t sm_id
The SubMesh.
GLuint i
The handle for the texture.
LightType light_type
#define MAX_JOINT_MATRICES
Maximum joints in a scene (used for SSBO sizing).
uint32_t instance_count
Used to be used to find the instance being rendered, but now that's on the transform data itself.
uint32_t lm_offset
The lightmap offset into LIGHTMAP_SSBO where this mesh node starts.
uint32_t skin_offset
The GLTFSkin matrix offset for this transform.
#define BUFFER_FRAMES
Triple buffer count.
int pv_id
The ProbeVolume in SceneData.lighting_probe_volume.
float inner_angle
bool LOADED_LIGHTING_PV_FLAG[6]
Flags that indicate if the slot is loaded.
float scattering_coefficients[6]
uint32_t element_offset
The offset into INDIRECT_ELEMENTS_COMMAND_BUFFER.
uint64_t normal_handle
Vector skins
GLTFSkins.
GLuint fbo
The handle for this fbo.
uint16_t directional_light_offset
#define MAX_INSTANCES
Maximum amount of TransformGPU instances to push in one frame (used for SSBO sizing).
float yaw
uint32_t entity_id
float intensity
#define GRID_Y
float outer_angle
uint32_t index_count
How many indices in this SubMesh.
@ GNORMAL
@ GPOMDEPTH
@ GVEL
@ GALBEDO
@ GEXTRA
#define MAX_MESH_NODES
Maximum MeshNodes in a scene (used for SSBO sizing).
GLuint location
mat4 proj
The projection matrix.
uint32_t layer
#define PROBE_VOLUME_DEPTH_PADDED
Padding to avoid leaking on edges in Z.
uint8_t gbuffer_shader
The shader for the DEPTH_PRE_PASS_SHADER.
CamData cam_data
vec3 left_hip_pos
The left hip pos, offset by left_leg_offset.
uint64_t emissive_handle
uint32_t tri
size_t draw_offset
Currently the same index as SubMesh.lm_offset.
LightmapData lightmap_data
The loaded lightmap and lightmap configuration for the scene.
vec3 axis_x
uint16_t point_light_count
vec4 tangent
The tangent for TBN construction.
#define GRID_X
Vector islands
The UVIslands on the current lightmap.
Uniform uniforms[32]
Uniforms for shader data.
vec4 cam_pos
The position of the Camera (padded).
size_t * skin_indices
The indices of GLTFSkins spawned from this instance inside of Globals.skins.
float emissive_strength
The structure of an Skeletatal Animation loaded in from GLTFAnimation.
A instance of an Asset that retains its node structure but can be duplicated into multiple instances ...
The structure uploaded to the GPU for providing render data for a Camera.
The camera structure for players and entities.
The structure used for debug wireframes.
The structure used to sort unique submeshes by materials, and shaders in the main render pass.
The abstraction for a framebuffer in OpenGL.
The structure of an Skeletatal Animation loaded in from GLTFAnimation.
Where Material textures are saved upon loading from file.
Simply the size we use to allocate the INSTANCE_VBO (unused).
The GPU side structure for Lights padded for GPU.
The metadata for the lightmap settings.
The structure that stores lightmap uvs.
Main rendering vertex.
The GPU side padded structure for Materials.
MeshNode structure padded for GPU (MESH_NODE_SSBO).
MeshNode buffer structure for MESH_NODE_SSBO.
GPU side structure for an OBB UBO.
The UBO structure for pushing the closest ReflectionProbes to the main shader.
ReflectionProbes used for parallax corrected cubemaps.
The data for the current scene.
OpenGL ShaderPrograms: vertex, fragment, geometry, and compute.
The structure used for uploading matrices for directional Lights used when rendering shadowmaps.
Sections of Meshes that are divided based on Material for batching and DrawCommand ordering purposes.
The structure used for rendering TextBoxes.
TransformGPU buffer structure for INSTANCE_SSBO.
Adjacent triangles for each MeshFace on a Mesh.
The UVIslands that are generated from contiguous MeshFaces with similar planes for UV lightmapping.
This bridges from MeshNode's MeshFaces to their respective UVIslands.
An unused abstraction for VertexLayouts.
mat4 compose_trs_from_mesh_node(MeshNode *mn)
Vector FONTS
All loaded Fonts.
Definition fonts.c:14
Functions that modify TextBoxes and load Fonts.
in vec2 uv
ivec3 resolution
The resolution in X, Y, Z.
OBB obb
The OBB that defines the size.
#define AUDIO_NUM_BANDS
The amount of bands to use for audio probe baking.
The ProbeVolumes for APVs and LPVs, controlled by OBBs.
vec3 pos
The position of the AudioEmitter .
vec3 pos
The position of the AudioPortal.
#define MAX_AUDIO_EMITTERS
The maximum amount of AudioEmitters.
An AudioEmitter that plays audio possibily from a certain position or at a certain time.
AudioPortals used for determining paths to transmit sound when emitter and listener are occluded.
DebugView current_debug_view
float DOF_sensor_height
float DOF_max_blur_radius
float render_framerate_target
The target framerate for rendering and processing ui events (a cap).
bool lighting_probe_volume_overlay
bool wireframe_toggled
Shows wireframes around many structures: Lights, ReflectionProbes, AudioProbes, AudioPortals,...
PostprocessDView pp_dview
vec3 rotation_axis
The rotation axis for rotation operations in the editor.
bool audio_probe_volume_overlay
#define EDITOR_AUDIO_EMITTER_SIZE
#define EDITOR_APROBE_SIZE
#define EDITOR_LIGHT_SIZE
#define EDITOR_APORTAL_SIZE
Convex Hulls that are generated via incremental hull for non-static meshes.
uint32_t command_id[32]
float intensity
The intensity of the Light.
int fwd_shader
The corresponding forward rendering shader branch in DYNAMIC_SHADER.
size_t id
The ID inside of Globals.mesh_nodes.
vec3 pos
Position of light.
vec3 translation
int skin
The GLTFSkin it controls.
vec3 extents
Definition dynamic.frag:23
uint32_t layer
Which layer a DIRECTIONAL_LIGHT corresponds to in the SHADOW_MAP_FBO.
size_t spot_light_count
LightType light_type
The type of Light.
float normal_scale
Unused - Used to determine how much of the texture normal to use.
sampler2D emissive_tex
vec3 center
Definition dynamic.frag:15
size_t offset
Offset into the MAIN_VBO.
size_t directional_light_count
bool override_transparent
If we are overriding transparency of this Material.
uint32_t skin_offset
The offset into the JOINT_SSBO, comes from DrawCommand.
vec3 dir
Direction for lights that are not POINT_LIGHTs.
float inner_angle
Starting angle for SPOT_LIGHTs.
float surface_area
The surface area of the triangle.
bool sm_dirty
If a point light needs a new shadowmap.
int tri
The MeshFace this corresponds to.
float outer_angle
Outer angle for SPOT_LIGHTs.
vec4 ka
Ambient.
size_t point_light_offset
size_t directional_light_offset
bool free
If the MeshNode can be replaced.
int children[128]
The children to this node, a global index into Globals.mesh_nodes.
float cone_angle
Cone angle for SPOT_LIGHTs.
float penumbra
Penumbra (opening) for SPOT_LIGHTs.
mat4 local_matrix
float emissive_strength
vec4 ke
Emissive.
int mesh
The Mesh it references.
int parent
The parent to this node, a global index into Globals.mesh_nodes.
float radius
The radius of the Light.
int mesh
The MeshNode this corresponds to.
bool override_arm
If we override the ARM texture and bind a dummy instead.
int child_count
The amount of children.
mat3 rot
Definition types.h:49
sampler2D arm_tex
size_t spot_light_offset
sampler2D normal_tex
vec3 rgb
Color of the light.
UVMapping * uv_map
The mapping between MeshNodes and UVIslands for uv lightmapping.
vec4 ks
Specular (unused).
uint32_t mesh_data_id[32]
float threshold
The threshold (how far a light reaches).
size_t count
Count of vertices pushed into the MAIN_VBO.
int gbuffer_shader
The corresponding gbuffer rendering shader branch in DEPTH_PRE_PASS_SHADER or DEPTH_PRE_PASS_SHADER_M...
uint32_t entity_id
Entity ID into ENTITIES.
float alpha_cutoff
Used to discard transparent Materials.
size_t point_light_count
float absorption_coefficients[6]
How much audio is absorbed when hitting this Material.
vec4 kd
Diffuse.
float scattering_coefficients[6]
How much audio specularly reflects when hitting this Material.
DrawArraysIndirect commands are used for static meshes (eg.
The CPU side structure for Lights.
The Materials parsed in from scene files that determine rendering pipeline setup, uploads,...
MeshNodes that describe the position of Meshes, GLTF nodes for GLTFAnimations, or hold references to ...
Oriented Bounding Boxes.
Definition dynamic.frag:14
uint state
Definition text.vert:40
uint hovered
Definition text.vert:8
float shadow_dist
Definition ui.h:100
uint32_t visible
Definition ui.h:123
uint32_t shadow
Definition ui.h:99
uint type
Definition text.vert:41
bool mask
If the UIElements and TextBoxes contained should not be rendered if outside.
Definition ui.h:236
float h
The height of the box after pseudo-rendering in determine_text_box_dimensions().
Definition ui.h:269
vec2 size
Definition ui.h:128
float v0
.
Definition ui.h:56
uint32_t container_id
Definition ui.h:139
float angle
Angle of rotation.
Definition ui.h:523
uint32_t state
Definition ui.h:130
uint shadow
Definition text.vert:35
float w
The width of the box after pseudo-rendering in determine_text_box_dimensions().
Definition ui.h:268
uint32_t mask
Definition ui.h:102
float angle
The angle to transform this box to.
Definition ui.h:279
int xadvance
How much the x advances when it is typed.
Definition ui.h:63
vec4 fill
Definition ui.h:109
vec2 translation
Definition ui.h:135
int font_id
The Font ID inside of FONTS.
Definition ui.h:262
float v1
.
Definition ui.h:58
int container
The UIContainer this UIElement may control.
Definition ui.h:539
TextBox text_boxes[1024]
The TextBoxes.
Definition ui.h:567
uint32_t masked
Definition ui.h:138
float shadow_dist
Unused.
Definition text.vert:36
vec4 color
Definition ui.h:108
uint32_t visible
Definition ui.h:97
vec4 color
Definition ui.h:132
mat4 model
Definition ui.h:110
vec2 size
Size of the SDF.
Definition text.vert:38
vec4 padding
Definition ui.h:134
vec4 fill
Definition ui.h:133
vec2 start
The start of the text in relation to .
Definition ui.h:284
mat4 model
Definition ui.h:141
UIElement elements[1024]
The UIElements.
Definition ui.h:566
Glyph * glyphs
Glyphs for each character.
Definition ui.h:78
float radius
Definition ui.h:137
vec2 translation
X and Y coords where Y+ is down.
Definition text.vert:45
vec2 translation
Where to place the center of the TextBox on the GPU.
Definition ui.h:278
vec4 padding
The padding before UIElements and TextBoxes are wrapped or masked.
Definition ui.h:235
uint32_t container_id
Definition ui.h:101
vec2 shadow_dir
Which direction to offset the drop shadow in.
Definition text.vert:13
int parent_container
The UIContainer that contains this UIElement.
Definition ui.h:540
int menu
The UIMenu this UIElement is inside.
Definition ui.h:538
vec4 color
The color of the text.
Definition text.vert:18
int height
.
Definition ui.h:60
uint32_t type
Definition ui.h:131
vec2 scale
Scale.
Definition text.vert:46
uint32_t layer
The layer of the UIElement.
Definition ui.h:532
UIContainer containers[1024]
The UIContainers.
Definition ui.h:568
vec2 center
The center.
Definition ui.h:527
int xoffset
The x offset before the character.
Definition ui.h:61
int parent_container
The UIContainer that contains this TextBox.
Definition ui.h:290
vec2 shadow_dir
Definition ui.h:103
int yoffset
The y offset before the character.
Definition ui.h:62
int width
.
Definition ui.h:59
uint32_t uID
The ID inside of UIMenu.text_boxes.
Definition ui.h:263
char * text
The characters to render.
Definition ui.h:265
vec4 fill
The fill of the text.
Definition text.vert:19
size_t glyph_count
The amount of Glyphs.
Definition ui.h:79
vec4 fill
Unused.
Definition text.vert:43
uint state
Definition text.vert:14
int element
Which UIElement owns this UIContainer.
Definition ui.h:243
vec2 scale
The scale for this box on the GPU.
Definition ui.h:280
vec2 scale
Definition ui.h:136
vec2 shadow_dir
Definition ui.h:129
bool free
If this TextBox is empty and can be overwritten.
Definition ui.h:261
bool free
If the UIElement can be replaced or is empty.
Definition ui.h:512
uint32_t uID
The ID inside of UIMenu.
Definition ui.h:514
size_t texture
The Image ID.
Definition ui.h:77
uint visible
Definition text.vert:33
int menu
The UIMenu that this box is within.
Definition ui.h:289
uint shadow
Definition text.vert:9
float u0
.
Definition ui.h:55
vec2 shadow_dir
Unused.
Definition text.vert:39
float radius
The radius of the circle OR the radius of a rectangle's corners.
Definition text.vert:47
vec2 pos
Definition ui.h:127
uint32_t hovered
Definition ui.h:98
uint32_t state
Definition ui.h:104
float text_size
The size to render the Font.
Definition ui.h:267
uint visible
Definition text.vert:7
vec4 color
Color of the shape.
Definition text.vert:42
uint32_t shadow
Definition ui.h:125
float shadow_dist
How far the drop shadow is.
Definition text.vert:10
float shadow_dist
Definition ui.h:126
float u1
.
Definition ui.h:57
#define MAX_UI_ELEMENTS
Definition ui.h:33
#define MAX_TEXT_BOXES
Definition ui.h:37
#define MAX_UI_CONTAINERS
Definition ui.h:34
Vector MENUS
All UIMenus.
Definition ui.c:13
int TEXT_HEIGHT
Definition ui.c:12
#define UI_SCALE_HEIGHT
Definition ui.h:36
#define UI_SCALE_WIDTH
Definition ui.h:35
int TEXT_WIDTH
Definition ui.c:11
bool container_is_valid(int container, int menu)
Checks if a UIContainer and UIMenu ID pairing is valid.
Definition ui.h:905
@ UISTATE_SELECTED
If the UIElement is selected in the Editor.
Definition ui.h:191
A Font and its Glyphs used for rendering TextBoxes.
Definition ui.h:74
A single Glyph in a Font.
Definition ui.h:52
A structure holding a Font ID and text to be rendered and transformed with its properties.
Definition text.vert:5
The GPU-side representation of a TextBox.
Definition ui.h:95
UIContainer that contains both TextBoxes and UIElements and can mask and scroll them.
Definition ui.h:225
UIElements that are contained within a UIMenu that may receive events, be contained within UIContaine...
Definition text.vert:31
The GPU-side representation of a UIElement.
Definition ui.h:121
The top-most UI structure that contains UIElements, TextBoxes, and UIContainers.
Definition ui.h:562
Important globals for the entire engine and initialization functions that are mainly called on engine...
#define MAX_ASSET_INSTANCES
Definition init.h:442
size_t meshes_in_frame[MAX_MESH_NODES]
Definition render.c:26
int current_frame
Definition render.c:25
#define DEBUG_LINES_MAX
Definition init.h:347
uint32_t TEXT_INDEX_COUNT
Definition fonts.c:16
size_t meshes_this_frame
Definition render.c:27
int master_frame
Definition render.c:21
Vector hulls
The ConvexHulls generated if this Mesh is dynamic.
TriangleAdjacency * tri_adjacency
Adjacent triangles allocated per MeshFace.
size_t id
The ID into Globals.meshes.
bool static_mesh
This Mesh is static and must create a BVH or if not it must perform incremental_hull.
AABB aabb
The AABB of the mesh.
size_t count
The count pushed into MAIN_VBO.
Vector submeshes
The SubMeshes split via Materials.
size_t offset
The offset into MAIN_VBO.
Vector tris
The MeshFaces.
Vector vertices
The Points.
A Mesh with geometry data that is either initialized as static or dynamic and split into SubMeshes.
int MOUSE_X
Definition main.c:183
ShaderProgram INDIRECT_PREFIX_SHADER
render/indirect_prefix.comp
Definition main.c:122
GLuint gbuffer_queries[QUERY_FRAMES]
Definition main.c:511
GLuint INDIRECT_ARRAYS_COMMAND_BUFFER
Definition main.c:167
GLuint PROBE_SSBO
Definition main.c:159
uint8_t * rprobe_ubo_ptr
Definition main.c:339
uint8_t * light_ssbo_ptr
Definition main.c:345
uint8_t * indirect_elements_ptr
Definition main.c:367
GLuint LPV_TEXTURE
Definition main.c:268
GLuint LIGHTMAP_SSBO
Definition main.c:153
GLuint DIRECTIONAL_MAP_TEXTURE
Definition main.c:222
Framebuffer MAIN_FBO
Definition main.c:90
ShaderProgram TEXT_SHADER
ui/text.vert ui/text.frag
Definition main.c:131
LightmapSSBO LIGHTMAP_DATA
Definition main.c:193
ShaderProgram SSAO_BLUR_SHADER
render/ssao_blur.frag
Definition main.c:106
GLuint MESH_SSBO
Instances (Transforms): Needs the Model Matrix, Inverse Model Matrix (crucial for transforming rays i...
Definition main.c:156
Framebuffer GBUFFER_RESOLVE_FBO
Definition main.c:94
GLuint INDIRECT_ARRAYS_COMMAND_BUFFER_OUT
Definition main.c:168
GLuint INSTANCE_VBO
Definition main.c:239
uint8_t * ui_ssbo_ptr
Definition main.c:380
int DEFAULT_NORMAL
Definition main.c:197
size_t mesh_light_ssbo_size
Definition main.c:347
int SSAO_HEIGHT
Definition main.c:88
GLuint CLUSTER_AABB_SSBO
Definition main.c:162
int RENDER_HEIGHT
Definition main.c:80
int DIRECTIONAL_LIGHT_COUNT
Definition main.c:324
GLuint GLOBAL_INSTANCE_SSBO
Definition main.c:166
uint8_t * probe_volume_ubo_ptr
Definition main.c:342
int DUMMY_LIGHTMAP
Definition main.c:201
size_t instance_ssbo_size
Definition main.c:374
uint8_t * mesh_light_ssbo_ptr
Definition main.c:348
DrawCommand DRAW_COMMANDS[512]
Definition main.c:259
AudioEmitter AUDIO_EMITTERS[1024]
Definition main.c:67
int current_query_frame
Definition main.c:517
GLuint MAIN_EBO
Definition main.c:237
GLuint UI_SSBO
Definition main.c:173
Framebuffer GBUFFER_FBO
Definition main.c:93
Framebuffer SSAO_FBO
Definition main.c:97
GLuint RPROBE_CUBE_MAP_ARRAY
Definition main.c:305
uint8_t * cam_ubo_ptr
Definition main.c:333
size_t ui_instance_vbo_size
Definition main.c:385
ShaderProgram UI_SHADER
ui/ui.vert ui/ui.frag
Definition main.c:132
GLuint CLUSTER_SSBO
Definition main.c:164
GLuint bloom_queries[QUERY_FRAMES]
Definition main.c:516
GLuint COLOR_GRADE_LUT
Definition main.c:146
GLuint MESH_NODE_SSBO
Definition main.c:165
size_t ui_ssbo_size
Definition main.c:379
GLuint HISTORY_TEXTURE[2]
Definition main.c:209
GLuint MAIN_VBO
Definition main.c:236
ShaderProgram COC_SHADER
render/coc.frag
Definition main.c:110
GLuint RPROBE_UBO
Definition main.c:138
double time_since_last_render
Computes the dot product or discrete sum over an array range.
Definition main.c:505
GLuint BRDF_LUT
Definition main.c:203
GLuint render_queries[QUERY_FRAMES]
Definition main.c:509
int RENDER_WIDTH
Definition main.c:79
GLuint ssao_queries[QUERY_FRAMES]
Definition main.c:513
GLsync RENDER_FENCE[3]
Definition main.c:293
float frame_time
The actual frame time in s.
Definition main.c:300
int SSR_WIDTH
Definition main.c:85
GLuint MATERIAL_SSBO
Material Data: Roughness, emission multipliers, albedo colors for each instance.
Definition main.c:152
ShaderProgram DEPTH_PRE_PASS_SHADER[1]
render/depth_pre_pass.vert render/depth_pre_pass.frag
Definition main.c:116
GLuint GLOBAL_LIGHT_INDICES_SSBO
Definition main.c:163
GLuint MAIN_VAO
Definition main.c:238
GLuint RPROBE_SSBO
Definition main.c:160
GLuint INDIRECT_ELEMENTS_COMMAND_BUFFER
Definition main.c:169
vec2 JITTER_OFFSET
Definition main.c:181
size_t probe_volume_ubo_padded
Definition main.c:341
ShaderProgram CULL_DRAW_CALLS_SHADER
render/cull_draw_calls.comp
Definition main.c:121
ShaderProgram POSTPROCESS_SHADER[128]
render/postprocess.vert render/postprocess.frag
Definition main.c:119
int MOUSE_Y
Definition main.c:183
int SCREEN_WIDTH
Definition main.c:77
GLuint MESH_BVH_SSBO
Mesh BVH Nodes: Flattened array of nodes.
Definition main.c:157
size_t mesh_node_ssbo_size
Definition main.c:358
uint8_t * ui_instance_vbo_ptr
Definition main.c:386
size_t text_box_ssbo_size
Definition main.c:371
EditorSettings EDITOR_SETTINGS
Definition main.c:330
int DEFAULT_DIFFUSE
Definition main.c:196
ShaderProgram CULL_POINT_LIGHT_SHADOWS_SHADER
render/cull_point_light_shadows.comp
Definition main.c:124
ShaderProgram DEPTH_DOWNSAMPLE_SHADER
render/depth_downsample.frag
Definition main.c:133
int SSAO_WIDTH
Definition main.c:87
GLuint WIREFRAME_VBO
Definition main.c:242
size_t rprobe_ubo_padded
Definition main.c:338
GLuint TEXT_VAO
Definition main.c:250
uint8_t * text_box_ssbo_ptr
Definition main.c:372
uint8_t * joint_ssbo_ptr
Definition main.c:351
GLuint WIREFRAME_VAO
Definition main.c:243
int DEBUG_LINE_COUNT
Definition main.c:282
int PERFORMANCE_OVERLAY_MENU
Definition main.c:247
size_t light_ssbo_size
Definition main.c:344
ShaderProgram SKY_SHADER
render/sky.vert render/sky.frag
Definition main.c:127
GLuint TEXT_BOX_SSBO
Definition main.c:172
int DEFAULT_ARM
Definition main.c:198
GLuint INSTANCE_SSBO
Definition main.c:171
Framebuffer SSR_FBO
Definition main.c:95
float time
The frame time but wrapping at 1.0.
Definition main.c:320
GLuint taa_queries[QUERY_FRAMES]
Definition main.c:514
size_t joint_ssbo_size
Definition main.c:350
uint32_t PP_SHADER_VERSIONS
Definition main.c:272
GLuint SKY_VBO
Definition main.c:304
GLuint LIGHT_CAM_UBO
Definition main.c:137
GLuint SKY_VAO
Definition main.c:303
ShaderProgram SSR_HISTORY_SHADER
Definition main.c:109
GLuint JOINT_SSBO
Definition main.c:161
ShaderProgram CULL_CLUSTERS_SHADER
render/cull_clusters.comp
Definition main.c:120
int DEFAULT_EMISSIVE
Definition main.c:199
GLuint FBM_TEXTURE
Definition main.c:177
uint8_t * indirect_arrays_ptr
Definition main.c:361
Framebuffer BLOOM_PYRAMID[6]
Definition main.c:102
ShaderProgram BLOOM_DOWNSCALE_SHADER
render/bloom_downscale.frag
Definition main.c:125
GLuint PROBE_VOLUME_UBO
Definition main.c:140
int draw_command_count
Definition main.c:260
GLuint pl_queries[QUERY_FRAMES]
Definition main.c:507
GLuint MESH_LIGHT_SSBO
Definition main.c:151
ShaderProgram SHADOW_MAP_SHADER
render/shadow.vert render/shadow.frag
Definition main.c:115
GLuint TRI_SSBO
Indices (Tris): uvec3 for triangle lookups.
Definition main.c:155
ShaderProgram POINT_LIGHT_SHADOW_SHADER
render/point_light_shadows.vert render/point_light_shadows.geom render/point_light_shadows....
Definition main.c:130
GLuint SSAO_NOISE_TEXTURE
Definition main.c:176
GLuint INDIRECT_ELEMENTS_COMMAND_BUFFER_OUT
Definition main.c:170
bool draw_dirty
If we need to reupload and resort transforms in create_and_sort_draw_commands() and upload_instance_d...
Definition main.c:388
GLuint sm_queries[QUERY_FRAMES]
Definition main.c:508
Framebuffer TAA_FBO[2]
Definition main.c:99
int SSR_HEIGHT
Definition main.c:86
uint8_t * instance_vbo_ptr
Definition main.c:354
int DOF_WIDTH
Definition main.c:83
GLuint cull_queries[QUERY_FRAMES]
Definition main.c:510
GLuint main_queries[QUERY_FRAMES]
Definition main.c:506
GLuint TEXT_EBO
Definition main.c:252
Framebuffer COC_FBO
Definition main.c:100
AssetInstance ASSET_INSTANCES[MAX_ASSET_INSTANCES]
Definition main.c:313
ShaderProgram WIREFRAME_SHADER
render/wireframe.vert render/wireframe.frag
Definition main.c:118
ShaderProgram ELEMENTS_PREFIX_SHADER
render/elements_prefix.comp
Definition main.c:123
ShaderProgram BLOOM_SHADER
render/bloom.frag
Definition main.c:112
Framebuffer SSAO_BLUR_FBO
Definition main.c:98
uint8_t * light_cam_ubo_ptr
Definition main.c:336
GLuint SCENE_BVH_SSBO
Scene BVH Nodes (TLAS): Same structure as above, but pointing to instances instead of triangles.
Definition main.c:158
GLuint CAM_UBO
Definition main.c:135
Framebuffer DEPTH_DOWNSAMPLE_FBO
Definition main.c:275
ShaderProgram BLOOM_UPSCALE_SHADER
render/bloom_upscale.frag
Definition main.c:126
ShaderProgram SSAO_SHADER
render/ssao.frag
Definition main.c:105
size_t cam_ubo_padded
Definition main.c:332
Framebuffer SHADOW_MAP_FBO
Definition main.c:92
GLuint ssr_queries[QUERY_FRAMES]
Definition main.c:515
vec3 CAM_POS
Shorthand variable for the camera position.
Definition main.c:205
Framebuffer TEXT_FBO
Definition main.c:103
GLuint TEXT_VBO
Definition main.c:251
GLuint UI_VAO
Definition main.c:254
GLuint SKYBOX
Definition main.c:302
ShaderProgram SSR_SHADER
Definition main.c:107
uint8_t * instance_ssbo_ptr
Definition main.c:375
Framebuffer MAIN_RESOLVE_FBO
Definition main.c:91
ShaderProgram DYNAMIC_SHADER[32]
render/dynamic.vert render/dynamic.frag
Definition main.c:114
Framebuffer BOKEH_FBO
Definition main.c:101
DebugVertex DEBUG_LINES[DEBUG_LINES_MAX]
Definition main.c:281
GLuint dof_queries[QUERY_FRAMES]
Definition main.c:512
size_t light_cam_ubo_padded
Definition main.c:335
int SCREEN_HEIGHT
Definition main.c:78
int DOF_HEIGHT
Definition main.c:84
uint8_t * mesh_node_ssbo_ptr
Definition main.c:359
Player player
The Player data.
Definition main.c:287
ShaderProgram DEPTH_PRE_PASS_SHADER_MSAA[1]
render/depth_pre_pass_no_gbuffer.vert render/depth_pre_pass_no_gbuffer.frag
Definition main.c:117
int DEBUG_CURRENT_APROBE
Definition main.c:54
MaterialData MATERIAL_DATA
Definition main.c:194
GLuint VERTEX_SSBO
Vertices: vec4 (x, y, z, padding) or just float arrays.
Definition main.c:154
GLuint LIGHT_SSBO
Definition main.c:150
Framebuffer POINT_LIGHT_SHADOWS_FBO
Definition main.c:307
ShaderProgram BOKEH_SHADER
render/bokeh.frag
Definition main.c:111
ShaderProgram FOCAL_DISTANCE_SHADER
render/focal_distance.comp
Definition main.c:308
vec3 vec3_lerp(vec3 a, vec3 b, float t)
Definition mathf.h:375
float vec3_dot(vec3 a, vec3 b)
Definition mathf.h:322
vec4 vec4_add(vec4 a, vec4 b)
Definition mathf.h:290
#define MIN(a, b)
Definition mathf.h:435
mat4 m4_mul(mat4 a, mat4 b)
Definition mathf.h:401
vec3 vec3_scale(vec3 a, float b)
Definition mathf.h:248
vec4 vec4_sub(vec4 a, vec4 b)
Definition mathf.h:294
vec3 vec3_sub(vec3 a, vec3 b)
Definition mathf.h:266
vec3 vec3_add(vec3 a, vec3 b)
Definition mathf.h:286
vec2 vec2_sub(vec2 a, vec2 b)
Definition mathf.h:270
float vec3_length(vec3 v)
Definition mathf.h:328
#define MAX(a, b)
Definition mathf.h:433
int right
Right child.
AABB aabb
The bounding box of all of this node's children.
int left
Left child.
Nodes for the acceleration structures of BVHs.
void update_scene_nodes()
Definition render.c:810
void create_and_sort_draw_commands(int *dc_cnt, DrawCommand *dcs)
Creates all DrawCommands based on unique SubMeshes and sorts them via DrawCommand....
Definition render.c:1132
void obb_to_vertices(DebugVertex *out, OBB *obb)
Definition render.c:546
size_t fill_buffer_with_mesh_tri(Mesh *mesh, MainVertex *verts, size_t offset)
Definition render.c:80
int static_count
Definition render.c:1730
void render_mesh_aabbs_from_root(MeshNode *mn)
Adds Mesh AABBs for each MeshNode child recursively to DEBUG_LINES.
Definition render.c:517
int shadow_draw_call_count
Definition render.c:1718
void write_point_light_shadows()
Definition render.c:1863
ShadowmapUBO SHADOWMAP_FRAME_DATA
Definition render.c:2276
int element_offset
Definition render.c:1727
void add_text_box(Vector *tvs, Vector *tis, TextBox *tb, int current_box)
Adds a TextBox to a vertex and index buffer, to be uploaded to TEXT_VBO and TEXT_EBO.
Definition render.c:1154
int draw_command_offsets[MAX_DRAW_COMMANDS]
Definition render.c:1710
void upload_parent_container(UIElement *el, UIContainer *cs, UIElement *els, int *el_count, size_t offset)
Definition render.c:1436
size_t shadow_meshes_this_frame
Definition render.c:29
void update_node_global(MeshNode *nodes, int idx, mat4 parent)
Definition render.c:796
int shadow_draw_command_counts[MAX_DRAW_COMMANDS]
Definition render.c:1717
int array_offset
Definition render.c:1725
size_t allocate_lightmap_ssbo()
Definition render.c:407
void render_bvh(BVHNode *nodes, int node_count, mat4 tr)
Definition render.c:2960
void upload_lights()
Uploads all current Lights inside of Globals.lights to the GPU in a triple buffered LIGHT_SSBO.
Definition render.c:634
LightGPU GPU_LIGHTS[MAX_LIGHTS]
Definition render.c:599
int * container_ids
Definition render.c:1432
void bind_baking_ssbos()
Binds SSBOs required for baking.
Definition render.c:31
uint32_t layer
Definition render.c:1339
void upload_instance_data(int *draw_calls, int *in_off, int dc_counts[MAX_DRAW_COMMANDS], int dc_off[MAX_DRAW_COMMANDS], int *draw_command_cnt, DrawCommand *dcs, MeshNodeSSBO *mn_data, uint8_t *instance_ptr, int current_frame_offset)
Definition render.c:1732
size_t visize
Definition render.c:341
int RPROBE_COUNT
Definition render.c:2230
uint32_t uid
Definition render.c:1338
InstanceData shadow_instance_matrices[MAX_INSTANCES]
Definition render.c:1715
void bind_dynamic_shader(int shader, bool probe_bake)
Definition render.c:1589
int compare_draw_commands(const void *a, const void *b)
Definition render.c:1121
void GPU_upload_ui_elements()
Definition render.c:1463
size_t calc_mesh_index_size(Mesh *m)
Definition render.c:325
int shadow_draw_command_offsets[MAX_DRAW_COMMANDS]
Definition render.c:1716
int transform_count
Definition render.c:1729
int dynamic_count
Definition render.c:1731
int joint_mat_count
Definition render.c:762
int compare_uid_pair(const void *a, const void *b)
Definition render.c:1343
void bind_material(Material *mat)
Definition render.c:1662
void determine_light_visibility_per_mesh()
Definition render.c:658
void get_view_planes(vec4 planes[6], Camera *cam)
Definition render.c:942
void render_all_draw_commands(bool probe_bake)
Definition render.c:2089
DrawElementsIndirectCommand elements_indirect[MAX_MESH_NODES]
Definition render.c:1726
float angle_tr
Definition render.c:1145
int cur_history
Definition render.c:22
int draw_command_counts[MAX_DRAW_COMMANDS]
Definition render.c:1711
void render()
The main render pass.
Definition render.c:3057
int draw_call_count
Definition render.c:1712
uint32_t UI_UID_OUT[MAX_UI_ELEMENTS]
Definition render.c:1358
size_t calc_mesh_size(Mesh *m)
Definition render.c:299
void render_tree(BVHNode *nodes, BVHNode *node, mat4 tr, DebugVertex *points, int *count, int depth, int max_depth, vec3 start_color, vec3 end_color)
Definition render.c:2931
void unbind_baking_ssbos()
Unbinds SSBOs required for baking.
Definition render.c:42
void determine_mesh_visibility(Camera *camera, size_t *meshes_frame, size_t *meshes_frame_cnt)
Definition render.c:1008
void upload_instances()
Definition render.c:1996
size_t shadow_meshes_in_frame[MAX_MESH_NODES]
Definition render.c:28
void upload_material_data()
Uploads Material data to the GPU as MaterialGPU.
Definition render.c:854
UIUIDPair UI_UIDS[MAX_UI_ELEMENTS]
Definition render.c:1357
void copy_light_to_gpu_light(LightGPU *lgpu, Light *l)
Transfers a Light to a LightGPU.
Definition render.c:602
void determine_closest_rprobes()
Definition render.c:2231
size_t vsize
Definition render.c:340
void GPU_upload_singular_element(UIContainer *cs, UIElement *el, int *ui_el_count, int *el_count)
Definition render.c:1361
float compute_ui_scale(int base_w, int base_h, int target_w, int target_h)
Definition render.c:1148
void add_mesh_to_buffer(Mesh *m, VertexLayout *layout)
Adds a single Mesh to the MAIN_VBO.
Definition render.c:343
void bind_render_ssbos()
Binds SSBOs required for rendering.
Definition render.c:56
void upload_joint_matrices()
Definition render.c:763
RProbeUBO RPROBE_UBO_DATA
Definition render.c:2229
size_t fill_vertex_buffer_mesh(Mesh *mesh, MainVertex *verts, size_t offset, size_t *lm_offset)
Definition render.c:156
TransformGPU transforms[MAX_MESH_NODES *MAX_INSTANCES]
Definition render.c:1728
void render_probe_volume(ProbeVolume *pv, bool audio)
Definition render.c:2979
TextBoxGPU TB_GPU[MAX_TEXT_BOXES]
Definition render.c:1144
MeshNodeSSBO mesh_node_data_gpu
Definition render.c:1721
void populate_draw_commands(DrawCommand *dcs, int *draw_command_cnt)
Definition render.c:1033
DrawArraysIndirectCommand arrays_indirect[MAX_MESH_NODES]
Definition render.c:1724
void aabb_to_vertices(DebugVertex *out, AABB *aabb, vec3 offset)
Transfers an AABB to DebufVertex for a wireframe (GL_LINES).
Definition render.c:475
int gpu_light_count
Definition render.c:600
void add_all_text_boxes_to_draw_buffer()
Adds all TextBoxes to TEXT_VBO and iterates through each character to push indices to TEXT_EBO.
Definition render.c:1220
int instance_offset
Definition render.c:1713
InstanceData instance_matrices[MAX_INSTANCES]
Definition render.c:1709
void GPU_upload_singular_text_box(UIContainer *cs, TextBox *tb, int *TC)
Definition render.c:1260
int shadow_instance_offset
Definition render.c:1719
void render_to_cubemap_face(Camera *rprobe_cam, GLuint render_fbo, int render_width, int render_height, bool probe_bake)
Uploads per-frame data to GPU and renders main render pass to a target FBO (omits Text,...
Definition render.c:2278
int find_depth(BVHNode *nodes, BVHNode *node, int depth)
Definition render.c:2915
size_t container_ids_cap
Definition render.c:1433
mat4 JOINT_MATS[MAX_JOINT_MATRICES]
Definition render.c:761
size_t fill_index_buffer_mesh(Mesh *mesh, uint32_t *indices, size_t vertex_offset, size_t offset, size_t *lm_uv_offset)
Definition render.c:258
UIElementGPU UI_GPU[MAX_UI_ELEMENTS]
Definition render.c:1334
void draw_arrays_elements(ShaderProgram *s, int start_arr, size_t start_array_offset, uint32_t array_count, int start_ele, size_t start_element_offset, uint32_t element_count)
Definition render.c:1836
int ui_element_count
Definition render.c:1359
void add_all_meshes_to_buffer(VertexLayout *layout)
Adds all Meshes that have valid MeshNodes.
Definition render.c:441
void update_skin_matrices()
Definition render.c:831
The main render pass, data GPU uploads, and SSBO management.
uniform mat4 view
Definition shadow.vert:16
float x
Definition types.h:11
float a1
Definition types.h:21
float w
Definition types.h:13
float c2
Definition types.h:20
float a0
Definition types.h:20
float z
Definition types.h:13
vec4 weights
Definition types.h:227
float d3
Definition types.h:21
float c2
Definition types.h:21
float a1
Definition types.h:20
float b0
Definition types.h:21
float c1
Definition types.h:21
float x
Definition types.h:13
float c0
Definition types.h:20
float a2
Definition types.h:21
float x
Definition types.h:12
float b0
Definition types.h:20
float max_z
Definition types.h:39
float b1
Definition types.h:20
int y
Definition types.h:15
float min_x
Definition types.h:37
ivec4 joints
Definition types.h:226
float max_y
Definition types.h:38
float b3
Definition types.h:21
float y
Definition types.h:11
float y
Definition types.h:13
size_t indices[3]
Definition types.h:283
float y
Definition types.h:12
float d1
Definition types.h:21
float a3
Definition types.h:21
int z
Definition types.h:15
float c0
Definition types.h:21
vec3 pos
Definition types.h:220
float z
Definition types.h:12
size_t count
Definition types.h:209
float min_z
Definition types.h:39
int x
Definition types.h:15
float b2
Definition types.h:21
float d0
Definition types.h:21
float min_y
Definition types.h:38
vec4 tangent
Definition types.h:222
float b2
Definition types.h:20
void * buffer
Definition types.h:210
float a2
Definition types.h:20
vec2 uv
Definition types.h:224
vec3 normal
Definition types.h:221
float a0
Definition types.h:21
float c3
Definition types.h:21
float c1
Definition types.h:20
float b1
Definition types.h:21
float d2
Definition types.h:21
float max_x
Definition types.h:37
Definition types.h:218
Definition types.h:21
Definition types.h:17
Definition types.h:11
Definition types.h:12
Definition types.h:13
The standalone UI library that controls text rendering, ui rendering, and events.
void init_vector(Vector *v, size_t i, size_t type_size)
Definition utilities.c:74
vec4 perm(vec4 x)
Definition utilities.c:139
void * vector_expand(Vector *v, size_t i)
Definition utilities.c:49
mat4 compose_2d_transform(vec2 transform, float angle, vec2 scale)
Definition utilities.c:97
vec4 vec3_to_vec4(vec3 v)
Definition utilities.h:166
#define CAST_VEC(vec, type)
Definition utilities.h:134
vec3 mat4_mul_point(mat4 m, vec3 v)
Definition utilities.h:313
mat4 mat4_identity()
Definition utilities.h:430
#define M_PI
Definition utilities.h:52
uniform vec3 color
Definition wireframe.frag:6