use new nice rendering architecture to easily add shadowmap pass

This commit is contained in:
Tuomas Katajisto 2025-10-07 23:05:24 +03:00
parent 4cc52535fc
commit f86026b588
5 changed files with 45 additions and 5 deletions

View File

@ -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));

View File

@ -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 {

View File

@ -1,3 +1,5 @@
SHADOWMAP_SIZE :: 2000;
Pipeline_Binding :: struct {
pipeline : sg_pipeline;
bind : sg_bindings;
@ -6,6 +8,9 @@ Pipeline_Binding :: struct {
}
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;

View File

@ -7,7 +7,6 @@
*/
#load "groundplane.jai";
#load "tasks.jai";
#load "sky.jai";
#load "core.jai";

View File

@ -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;