From 7a40b0bff2dd8b97f62e6f6901a3d1ce94d98d01 Mon Sep 17 00:00:00 2001 From: jacob Date: Tue, 16 Dec 2025 15:11:36 -0600 Subject: [PATCH] backdrop shader --- src/base/base_async.c | 1 + src/pp/pp_vis/pp_vis_core.c | 9 +++++-- src/pp/pp_vis/pp_vis_shaders.cgh | 5 ++++ src/pp/pp_vis/pp_vis_shaders.g | 44 ++++++++++++++++++++++++++++++++ src/pp/pp_vis/pp_vis_widgets.c | 1 + 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/base/base_async.c b/src/base/base_async.c index da83d3e5..61e90108 100644 --- a/src/base/base_async.c +++ b/src/base/base_async.c @@ -91,6 +91,7 @@ void AsyncWorkerEntryPoint(WaveLaneCtx *lane) //- End tick WaveSync(lane); + ResetArena(tick.arena); { Arena *tick_arena = tick.arena; diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index 9d8587c3..cb5d86d5 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -147,7 +147,7 @@ void V_TickForever(WaveLaneCtx *lane) ////////////////////////////// //- Spawn test ents - if (V.world->tick == 1) + if (frame->tick == 1) { S_Key child_key = S_RandKey(); S_Key camera_key = S_RandKey(); @@ -615,8 +615,13 @@ void V_TickForever(WaveLaneCtx *lane) params.target_ro = draw_target_ro; params.target_rw = draw_target_rw; params.shape_verts = dverts_ro; - params.world_to_draw_xf = world_to_draw_xf; params.target_cursor_pos = draw_cursor; + + params.background_color_a = LinearFromSrgb(VEC4(0.30, 0.30, 0.30, 1)); + params.background_color_b = LinearFromSrgb(VEC4(0.15, 0.15, 0.15, 1)); + + params.world_to_draw_xf = world_to_draw_xf; + params.draw_to_world_xf = draw_to_world_xf; } G_ResourceHandle params_buff = G_PushBufferFromString(frame->gpu_arena, frame->cl, StringFromStruct(¶ms)); G_StructuredBufferRef params_ro = G_PushStructuredBufferRef(frame->gpu_arena, params_buff, V_DParams); diff --git a/src/pp/pp_vis/pp_vis_shaders.cgh b/src/pp/pp_vis/pp_vis_shaders.cgh index cb322685..8a4af443 100644 --- a/src/pp/pp_vis/pp_vis_shaders.cgh +++ b/src/pp/pp_vis/pp_vis_shaders.cgh @@ -13,7 +13,12 @@ Struct(V_DParams) G_StructuredBufferRef shape_verts; Vec2 target_cursor_pos; + + Vec4 background_color_a; + Vec4 background_color_b; + Xform world_to_draw_xf; + Xform draw_to_world_xf; }; //////////////////////////////////////////////////////////// diff --git a/src/pp/pp_vis/pp_vis_shaders.g b/src/pp/pp_vis/pp_vis_shaders.g index 605ce78d..70a5cacc 100644 --- a/src/pp/pp_vis/pp_vis_shaders.g +++ b/src/pp/pp_vis/pp_vis_shaders.g @@ -12,6 +12,50 @@ ComputeShader2D(V_BackdropCS, 8, 8) { Vec4 result = Vec4(0.05, 0.05, 0.05, 1); + /* Checkered square color */ + { + i32 color_idx = 0; + Vec4 colors[2] = { + params.background_color_a, + params.background_color_b + }; + Vec2 world_pos = mul(params.draw_to_world_xf, Vec3(target_pos, 1)); + Vec2 world_pos_modded = fmod(abs(world_pos), Vec2(2, 2)); + if (world_pos_modded.x < 1) + { + color_idx = !color_idx; + } + if (world_pos_modded.y < 1) + { + color_idx = !color_idx; + } + if (world_pos.x < 0) + { + color_idx = !color_idx; + } + if (world_pos.y < 0) + { + color_idx = !color_idx; + } + result = colors[color_idx]; + } + + /* Axis color */ + { + f32 thickness = 2; + Vec2 zero_screen = mul(params.world_to_draw_xf, Vec3(0, 0, 1)); + f32 x_dist = abs(target_pos.x - zero_screen.x); + f32 y_dist = abs(target_pos.y - zero_screen.y); + if (y_dist <= (thickness * 0.5)) + { + result = Color_Red; + } + else if (x_dist <= (thickness * 0.5)) + { + result = Color_Green; + } + } + target[target_pos] = result; } } diff --git a/src/pp/pp_vis/pp_vis_widgets.c b/src/pp/pp_vis/pp_vis_widgets.c index 567cf8fe..6d0fdb89 100644 --- a/src/pp/pp_vis/pp_vis_widgets.c +++ b/src/pp/pp_vis/pp_vis_widgets.c @@ -54,6 +54,7 @@ String V_StringFromHotkey(Arena *arena, V_Hotkey hotkey) PushStringToList(scratch.arena, &parts, Lit("Shift")); } PushStringToList(scratch.arena, &parts, StringFromButton(hotkey.button)); + EndScratch(scratch); return StringFromList(arena, parts, Lit(" + ")); }