summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-22 15:12:44 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-22 15:12:44 +1000
commit51d0535a8d49b72ab1e47acf30f654403a94c423 (patch)
treec8e8124c7a35c2fcfa7afa857b50ce0cdb15ba7c /examples
parent6fccac3372170153b59e829d11c6c0b0a5c2bc77 (diff)
wip: porting shadowmaps to RAL
Diffstat (limited to 'examples')
-rw-r--r--examples/shadow_maps/ex_shadow_maps.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/examples/shadow_maps/ex_shadow_maps.c b/examples/shadow_maps/ex_shadow_maps.c
index e69de29..1d40128 100644
--- a/examples/shadow_maps/ex_shadow_maps.c
+++ b/examples/shadow_maps/ex_shadow_maps.c
@@ -0,0 +1,81 @@
+#include "celeritas.h"
+#include "maths_types.h"
+#include "primitives.h"
+#include "ral.h"
+#include "render.h"
+#include "render_types.h"
+#include "renderpasses.h"
+
+extern core g_core;
+
+// Scene / light setup
+const vec3 pointlight_positions[4] = {
+ { -10.0, 10.0, 10.0 },
+ { 10.0, 10.0, 10.0 },
+ { -10.0, -10.0, 10.0 },
+ { 10.0, -10.0, 10.0 },
+};
+point_light point_lights[4];
+
+int main() {
+ core_bringup();
+ arena scratch = arena_create(malloc(1024 * 1024), 1024 * 1024);
+
+ vec3 camera_pos = vec3(2., 2., 2.);
+ vec3 camera_front = vec3_normalise(vec3_negate(camera_pos));
+ camera cam = camera_create(camera_pos, camera_front, VEC3_Y, deg_to_rad(45.0));
+
+ ren_shadowmaps shadows = { .width = 1000, .height = 1000 };
+ ren_shadowmaps_init(&shadows);
+
+ // Meshes
+ mesh cubes[4];
+ for (int i = 0; i < 4; i++) {
+ geometry_data geo = geo_create_cuboid(f32x3(2,2,2));
+ cubes[i] = mesh_create(&geo, true);
+ }
+
+ // Main loop
+ while (!should_exit(&g_core)) {
+ input_update(&g_core.input);
+
+ if (!gpu_backend_begin_frame()) {
+ continue;
+ }
+ gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder();
+
+ gpu_cmd_encoder_begin_render(enc, shadows.rpass);
+ encode_bind_pipeline(enc, PIPELINE_GRAPHICS, shadows.static_pipeline);
+ for (int i = 0; i < 4; i++) {
+ encode_set_vertex_buffer(enc, cubes[i].vertex_buffer);
+ encode_set_index_buffer(enc, cubes[i].index_buffer);
+ encode_draw_indexed(enc, cubes[i].geometry->indices->len);
+ }
+
+ gpu_cmd_encoder_end_render(enc);
+
+ gpu_cmd_encoder_begin_render(enc, static_opaque_rpass);
+
+ gpu_cmd_encoder_end_render(enc);
+ /*
+ Shadows
+
+ render scene into texture
+
+ begin_renderpass()
+ bind_pipeline()
+ upload shader data
+ for each object:
+ - set buffers
+ - draw call
+
+ end_renderpass()
+ */
+
+ gpu_backend_end_frame();
+ }
+
+ renderer_shutdown(&g_core.renderer);
+
+ return 0;
+}