From e5ca283fddf9684362a3b0f841ae89b36edfd4dd Mon Sep 17 00:00:00 2001 From: Katajisto Date: Sun, 29 Mar 2026 18:15:59 +0300 Subject: [PATCH] improve RDM baking --- src/editor/level_editor.jai | 13 +++++++++++++ src/editor/tacoma.jai | 5 +++-- src/world.jai | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/editor/level_editor.jai b/src/editor/level_editor.jai index 0b34549..0f6ce29 100644 --- a/src/editor/level_editor.jai +++ b/src/editor/level_editor.jai @@ -252,6 +252,17 @@ draw_tacoma_tab :: (theme: *GR.Overall_Theme, total_r: GR.Rect) { if curworld.valid then rdm_bake_all_chunks(curworld.world, tacomaSamples, true); } r.y += r.h; + dirty_count := 0; + if curworld.valid for chunk: curworld.world.chunks if chunk.rdm_dirty dirty_count += 1; + if GR.button(r, tprint("Bake dirty chunks (%)", dirty_count), *t_button_selectable(theme, dirty_count > 0)) { + if curworld.valid && dirty_count > 0 { + dirty_keys : [..]Chunk_Key; + dirty_keys.allocator = temp; + for chunk, key: curworld.world.chunks if chunk.rdm_dirty array_add(*dirty_keys, key); + rdm_bake_chunks(dirty_keys, curworld.world, tacomaSamples, true); + } + } + r.y += r.h; if rdm_bake.active { total := cast(s32) rdm_bake.jobs.count; done := rdm_bake.current_job; @@ -469,6 +480,7 @@ add_trile :: (name: string, x: s32, y: s32, z: s32, orientation: u8 = 0) { group.trile_name = sprint("%", name); array_add(*group.instances, inst); array_add(*chunk.groups, group); + chunk.rdm_dirty = true; } @Command remove_trile :: (x: s32, y: s32, z: s32) { @@ -484,6 +496,7 @@ remove_trile :: (x: s32, y: s32, z: s32) { for inst, idx: group.instances { if inst.x == lx && inst.y == ly && inst.z == lz { array_unordered_remove_by_index(*group.instances, idx); + chunk.rdm_dirty = true; return; } } diff --git a/src/editor/tacoma.jai b/src/editor/tacoma.jai index 3bd3373..1b46063 100644 --- a/src/editor/tacoma.jai +++ b/src/editor/tacoma.jai @@ -231,10 +231,10 @@ rdm_bake_start :: (world: World, quality: s32, include_water: bool, chunk_keys: // Clean up any previous per-chunk bake data. rdm_cleanup_chunk_bakes(); - // Clean up any previous RDM results stored in chunks. + // Clear RDM results only for chunks that are being re-baked. curworld := get_current_world(); for *chunk: curworld.world.chunks { - if chunk.rdm_valid { + if chunk.rdm_valid && (bake_all || table_contains(*chunk_key_set, chunk.coord)) { sg_destroy_image(chunk.rdm_atlas); sg_destroy_image(chunk.rdm_lookup); chunk.rdm_valid = false; @@ -439,6 +439,7 @@ rdm_bake_finish :: () { chunk.rdm_atlas = atlas_image; chunk.rdm_lookup = lookup_image; chunk.rdm_valid = true; + chunk.rdm_dirty = false; } total_entries += cast(s64) bake.entries.count; diff --git a/src/world.jai b/src/world.jai index d14a90a..ec8ab44 100644 --- a/src/world.jai +++ b/src/world.jai @@ -55,6 +55,7 @@ Chunk :: struct { rdm_atlas: sg_image; rdm_lookup: sg_image; rdm_valid: bool; + rdm_dirty: bool; rdm_atlas_path: string; rdm_lookup_path: string; #if !FLAG_RELEASE_BUILD {