From f86026b588faad8b09052009250a5f29e6d6d255 Mon Sep 17 00:00:00 2001 From: Katajisto Date: Tue, 7 Oct 2025 23:05:24 +0300 Subject: [PATCH] use new nice rendering architecture to easily add shadowmap pass --- first.jai | 3 --- src/rendering/backend_sokol.jai | 7 +++++++ src/rendering/pipelines.jai | 37 ++++++++++++++++++++++++++++++++- src/rendering/rendering.jai | 1 - src/rendering/tasks.jai | 2 ++ 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/first.jai b/first.jai index e4e925e..f415eb3 100644 --- a/first.jai +++ b/first.jai @@ -36,10 +36,7 @@ Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM); set_build_options_dc(.{do_output = false}); make_directory_if_it_does_not_exist("dist", recursive = true); - - { - process_result, output, error := run_command("cp", "-r", "./resources", "./dist/", working_directory=tprint("%", #filepath)); diff --git a/src/rendering/backend_sokol.jai b/src/rendering/backend_sokol.jai index f045b63..1f22ede 100644 --- a/src/rendering/backend_sokol.jai +++ b/src/rendering/backend_sokol.jai @@ -160,7 +160,14 @@ backend_process_command_buckets :: () { backend_handle_command(it); } + // 2. Shadow pass + sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear, attachments = g_shadowmap_attachments})); + for render_command_buckets.shadow { + backend_handle_command(it); + } + sg_end_pass(); current_trile_offset_index = 0; // This is not optimal, but it is nice and simple. + // 2. Reflection pass sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear, attachments = gPipelines.plane.attachments})); for render_command_buckets.reflection { diff --git a/src/rendering/pipelines.jai b/src/rendering/pipelines.jai index 1420f32..9b7184a 100644 --- a/src/rendering/pipelines.jai +++ b/src/rendering/pipelines.jai @@ -1,3 +1,5 @@ +SHADOWMAP_SIZE :: 2000; + Pipeline_Binding :: struct { pipeline : sg_pipeline; bind : sg_bindings; @@ -5,7 +7,10 @@ Pipeline_Binding :: struct { pass_action : sg_pass_action; } -g_specular_lut : sg_image; +g_specular_lut : sg_image; +g_shadowmap : sg_image; +g_shadowmap_img : sg_image; // Apparently we are requried to have one of these, sigh... we don't use this. +g_shadowmap_attachments : sg_attachments; gPipelines : struct { @@ -28,12 +33,42 @@ gPipelines : struct { } +create_shadowmap_image :: () { + w : s32 = SHADOWMAP_SIZE; + h : s32 = SHADOWMAP_SIZE; + + if g_shadowmap.id != INVALID_ID then sg_destroy_image(g_shadowmap); + + depth_desc := sg_image_desc.{ + width = w, + height = h, + pixel_format = .DEPTH_STENCIL, + render_target = true, + }; + img_desc := sg_image_desc.{ + width = w, + height = h, + pixel_format = .RGBA8, + render_target = true, + }; + g_shadowmap = sg_make_image(*depth_desc); + g_shadowmap_img = sg_make_image(*img_desc); + attachmentsDesc : sg_attachments_desc; + attachmentsDesc = .{ + colors[0].image = g_shadowmap_img, + depth_stencil.image = g_shadowmap, + }; + sg_destroy_attachments(g_shadowmap_attachments); + g_shadowmap_attachments = sg_make_attachments(*attachmentsDesc); +} + create_pipelines :: () { create_arbtri_pipeline(); create_trixel_pipeline(); create_trile_pipeline(); create_sky_pipeline(); create_plane_pipeline(); + create_shadowmap_image(); } TRIXEL_SIZE_HALF : float : 1.0/32.0; diff --git a/src/rendering/rendering.jai b/src/rendering/rendering.jai index 11362ea..d5edcf5 100644 --- a/src/rendering/rendering.jai +++ b/src/rendering/rendering.jai @@ -7,7 +7,6 @@ */ -#load "groundplane.jai"; #load "tasks.jai"; #load "sky.jai"; #load "core.jai"; diff --git a/src/rendering/tasks.jai b/src/rendering/tasks.jai index 57c1550..05da6b5 100644 --- a/src/rendering/tasks.jai +++ b/src/rendering/tasks.jai @@ -76,6 +76,7 @@ tasks_to_commands :: () { // Currently no need to draw trixels anywhere but the editor so no // need for drawing them in the planar reflection pass... // array_add(*render_command_buckets.reflection, drawCommand); + case .TRILE; trileTask := (cast(*Rendering_Task_Trile)it); addPositionsCmd := New(Render_Command_Add_Trile_Positions,, temp); @@ -87,6 +88,7 @@ tasks_to_commands :: () { drawPositionsCmd.conf = trileTask.worldConf; array_add(*render_command_buckets.reflection, drawPositionsCmd); array_add(*render_command_buckets.main, drawPositionsCmd); + array_add(*render_command_buckets.shadow, drawPositionsCmd); case .SKY; command := New(Render_Command_Sky,, temp); command.worldConfig = (cast(*Rendering_Task_Sky)it).worldConfig;