From 537b637ccc20f189d7925857d343c455ff8ef402 Mon Sep 17 00:00:00 2001 From: jacob Date: Mon, 23 Feb 2026 21:34:59 -0600 Subject: [PATCH] backdrop testing --- src/platform/platform_win32/platform_win32.c | 11 ++- src/platform/platform_win32/platform_win32.h | 2 +- src/pp/pp_res/backdrop.ase | 3 + src/pp/pp_vis/pp_vis_core.c | 8 ++ src/pp/pp_vis/pp_vis_gpu.g | 81 +++++++++++++------- src/pp/pp_vis/pp_vis_shared.cgh | 3 + 6 files changed, 73 insertions(+), 35 deletions(-) create mode 100644 src/pp/pp_res/backdrop.ase diff --git a/src/platform/platform_win32/platform_win32.c b/src/platform/platform_win32/platform_win32.c index 539c6df5..7338e706 100644 --- a/src/platform/platform_win32/platform_win32.c +++ b/src/platform/platform_win32/platform_win32.c @@ -43,7 +43,7 @@ DateTime PLT_W32_DateTimeFromWin32SystemTime(SYSTEMTIME st) } //////////////////////////////////////////////////////////// -//~ Timer job +//~ Timer worker void PLT_W32_SyncTimerForever(WaveLaneCtx *lane) { @@ -56,7 +56,7 @@ void PLT_W32_SyncTimerForever(WaveLaneCtx *lane) Panic(Lit("Failed to create high resolution timer")); } - i32 periods_index = 0; + i32 period_idx = 0; i64 periods[PLT_W32_NumRollingTimerPeriods] = Zi; for (i32 i = 0; i < (i32)countof(periods); ++i) { @@ -64,7 +64,6 @@ void PLT_W32_SyncTimerForever(WaveLaneCtx *lane) } i64 prev_cycle_ns = 0; - // FIXME: shutdown for (;;) { { @@ -84,10 +83,10 @@ void PLT_W32_SyncTimerForever(WaveLaneCtx *lane) // Compute mean period { - periods[periods_index++] = period_ns; - if (periods_index == countof(periods)) + periods[period_idx++] = period_ns; + if (period_idx >= countof(periods)) { - periods_index = 0; + period_idx = 0; } f64 periods_sum_ns = 0; for (i32 i = 0; i < (i32)countof(periods); ++i) diff --git a/src/platform/platform_win32/platform_win32.h b/src/platform/platform_win32/platform_win32.h index 44a52d9a..e336b1e4 100644 --- a/src/platform/platform_win32/platform_win32.h +++ b/src/platform/platform_win32/platform_win32.h @@ -36,6 +36,6 @@ DWORD PLT_W32_CompressionAlgorithmFromLevel(PLT_CompressionLevel level); DateTime PLT_W32_DateTimeFromWin32SystemTime(SYSTEMTIME st); //////////////////////////////////////////////////////////// -//~ Timer job +//~ Timer worker void PLT_W32_SyncTimerForever(WaveLaneCtx *lane); diff --git a/src/pp/pp_res/backdrop.ase b/src/pp/pp_res/backdrop.ase new file mode 100644 index 00000000..77aaaa9b --- /dev/null +++ b/src/pp/pp_res/backdrop.ase @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ceffe48c980f3b984e489de79f4c58e7900295ce3f0c5884b5dca7ea7f530912 +size 4710 diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index d041882a..26bd9254 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -4753,6 +4753,14 @@ void V_TickForever(WaveLaneCtx *lane) ////////////////////////////// //- Build gpu data + // Backdrop + { + SPR_SheetKey sheet = SPR_SheetKeyFromResource(ResourceKeyFromStore(&P_Resources, Lit("backdrop.ase"))); + SPR_Sprite sprite = SPR_SpriteFromSheet(sheet, SPR_NilSpanKey, 0); + frame->backdrop = sprite.tex; + frame->backdrop_slice_uv = DivRng2Vec2(sprite.tex_rect, sprite.tex_dims); + } + // Tiles { for (P_TileKind tile_kind = 0; tile_kind < P_TileKind_COUNT; ++tile_kind) diff --git a/src/pp/pp_vis/pp_vis_gpu.g b/src/pp/pp_vis/pp_vis_gpu.g index 28adeb3a..d8bc3a43 100644 --- a/src/pp/pp_vis/pp_vis_gpu.g +++ b/src/pp/pp_vis/pp_vis_gpu.g @@ -600,19 +600,62 @@ ImplComputeShader2D(V_CompositeCS) Vec2 shade_pos = mul(frame.af.screen_to_shade, Vec3(screen_pos.xy, 1)); Vec2 tile_pos = mul(frame.af.world_to_tile, Vec3(world_pos, 1)); - Vec2 half_world_dims = Vec2(P_WorldPitch, P_WorldPitch) * 0.5; - Vec2 world_bounds_screen_p0 = mul(frame.af.world_to_screen, Vec3(-half_world_dims.xy, 1)); - Vec2 world_bounds_screen_p1 = mul(frame.af.world_to_screen, Vec3(half_world_dims.xy, 1)); + Rng2 world_bounds = { Vec2(-P_WorldPitch, -P_WorldPitch) * 0.5, Vec2(P_WorldPitch, P_WorldPitch) * 0.5 }; + Vec2 world_bounds_screen_p0 = mul(frame.af.world_to_screen, Vec3(world_bounds.p0, 1)); + Vec2 world_bounds_screen_p1 = mul(frame.af.world_to_screen, Vec3(world_bounds.p1, 1)); b32 is_in_world = IsInside(cell_pos, P_WorldCellsDims); b32 is_in_screen = IsInside(screen_pos, frame.screen_dims); P_TileKind tile = tiles[tile_pos]; P_TileKind equipped_tile = frame.equipped_tile; + ////////////////////////////// + //- Backdrop color + + Vec4 backdrop_color = Vec4(0.025, 0.025, 0.025, 1); + { + // if (!frame.is_editing) + if (1) + { + Texture2D backdrop_tex = G_Dereference(frame.backdrop); + + f32 parallax = 2; + Vec2 cam_center = frame.camera_pos + frame.screen_dims * 0.5; + Vec2 backdrop_pos = lerp(cam_center, world_pos, parallax); + + Vec2 samp_t = frac(abs(backdrop_pos - world_bounds.p0) / (world_bounds.p1 - world_bounds.p0)); + samp_t = clamp(samp_t, 0.00001, 1.0 - 0.00001); + + Vec2 samp_uv = lerp(frame.backdrop_slice_uv.p0, frame.backdrop_slice_uv.p1, samp_t); + backdrop_color = backdrop_tex.SampleLevel(sampler, samp_uv, 0); + } + else if (is_in_world) + { + // Checkered grid + i32 color_idx = 0; + Vec4 colors[2] = { + LinearFromSrgb(Vec4(0.30, 0.30, 0.30, 1)), + LinearFromSrgb(Vec4(0.15, 0.15, 0.15, 1)) + }; + Vec2 tile_pos_mod = fmod(abs(tile_pos), Vec2(2, 2)); + if (tile_pos_mod.x < 1) + { + color_idx = !color_idx; + } + if (tile_pos_mod.y < 1) + { + color_idx = !color_idx; + } + backdrop_color = colors[color_idx]; + } + + backdrop_color.rgb *= backdrop_color.a; + } + ////////////////////////////// //- World color - Vec4 world_color = Vec4(0.025, 0.025, 0.025, 1); + Vec4 world_color = 0; if (is_in_world) { ////////////////////////////// @@ -665,27 +708,8 @@ ImplComputeShader2D(V_CompositeCS) V_TileDesc tile_desc = frame.tile_descs[tile]; Texture2D tile_tex = G_Dereference(tile_desc.tex); Vec2 samp_t = clamp(frac(world_pos), 0.00001, 1.0 - 0.00001); - Vec2 tile_samp_uv = lerp(tile_desc.tex_slice_uv.p0, tile_desc.tex_slice_uv.p1, samp_t); - tile_color = tile_tex.SampleLevel(sampler, tile_samp_uv, 0); - } - else if (tile == P_TileKind_Empty) - { - // Checkered grid - i32 color_idx = 0; - Vec4 colors[2] = { - LinearFromSrgb(Vec4(0.30, 0.30, 0.30, 1)), - LinearFromSrgb(Vec4(0.15, 0.15, 0.15, 1)) - }; - Vec2 tile_pos_mod = fmod(abs(tile_pos), Vec2(2, 2)); - if (tile_pos_mod.x < 1) - { - color_idx = !color_idx; - } - if (tile_pos_mod.y < 1) - { - color_idx = !color_idx; - } - tile_color = colors[color_idx]; + Vec2 samp_uv = lerp(tile_desc.tex_slice_uv.p0, tile_desc.tex_slice_uv.p1, samp_t); + tile_color = tile_tex.SampleLevel(sampler, samp_uv, 0); } } @@ -796,10 +820,10 @@ ImplComputeShader2D(V_CompositeCS) Vec4 selection_color = 0; if ( + is_in_world && frame.is_editing && frame.edit_mode == V_EditMode_Tile && - frame.has_mouse_focus && - is_in_world + frame.has_mouse_focus ) { Vec4 border_color = LinearFromSrgb(Vec4(1, 1, 1, 1)); @@ -845,7 +869,7 @@ ImplComputeShader2D(V_CompositeCS) //- Grid Vec4 grid_color = 0; - if (is_in_world) + if (is_in_world && frame.is_editing) { b32 debug_draw = !!frame.show_console; @@ -943,6 +967,7 @@ ImplComputeShader2D(V_CompositeCS) //- Compose result Vec4 result = 0; + result = BlendPremul(backdrop_color, result); result = BlendPremul(world_color, result); result = BlendPremul(overlay_color, result); diff --git a/src/pp/pp_vis/pp_vis_shared.cgh b/src/pp/pp_vis/pp_vis_shared.cgh index 288ae9cc..6429d2d6 100644 --- a/src/pp/pp_vis/pp_vis_shared.cgh +++ b/src/pp/pp_vis/pp_vis_shared.cgh @@ -341,6 +341,9 @@ Struct(V_SharedFrame) G_SamplerStateRef basic_samplers[G_BasicSamplerKind_COUNT]; + G_Texture2DRef backdrop; + Rng2 backdrop_slice_uv; + V_TileDesc tile_descs[P_TileKind_COUNT]; G_Texture2DRef tiles;