From d0130c4810fbf8e5ffc1b2b04e9d96bb7781cc8c Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 2 Jan 2026 20:03:44 -0600 Subject: [PATCH] aim above 1.0 when easing palette in --- src/base/base_math.c | 17 +++++++++++++++++ src/base/base_math.h | 10 +++++++++- src/base/base_string.c | 9 ++------- src/gpu/gpu_dx12/gpu_dx12_core.c | 4 ++-- src/pp/pp_vis/pp_vis_core.c | 15 ++++++++++----- src/pp/pp_vis/pp_vis_core.h | 3 +-- src/ui/ui_core.c | 2 +- 7 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/base/base_math.c b/src/base/base_math.c index fd29a925..f5a96b7e 100644 --- a/src/base/base_math.c +++ b/src/base/base_math.c @@ -31,6 +31,15 @@ u64 ClampU64(u64 v, u64 min, u64 max) { return v < min ? min : v > max ? max : v i64 ClampI64(i64 v, i64 min, i64 max) { return v < min ? min : v > max ? max : v; } f64 ClampF64(f64 v, f64 min, f64 max) { return v < min ? min : v > max ? max : v; } + +//- Saturate +u32 SaturateU32(u32 v) { return v < 0 ? 0 : v > 1 ? 1 : v; } +i32 SaturateI32(i32 v) { return v < 0 ? 0 : v > 1 ? 1 : v; } +f32 SaturateF32(f32 v) { return v < 0 ? 0 : v > 1 ? 1 : v; } +u64 SaturateU64(u64 v) { return v < 0 ? 0 : v > 1 ? 1 : v; } +i64 SaturateI64(i64 v) { return v < 0 ? 0 : v > 1 ? 1 : v; } +f64 SaturateF64(f64 v) { return v < 0 ? 0 : v > 1 ? 1 : v; } + //////////////////////////////////////////////////////////// //~ Exponential ops @@ -400,6 +409,14 @@ Vec2 ClampVec2(Vec2 v, Rng2 r) return result; } +Vec2 SaturateVec2(Vec2 v) +{ + Vec2 result = Zi; + result.x = ClampF32(v.x, 0, 1); + result.y = ClampF32(v.y, 0, 1); + return result; +} + //- Dot f32 DotVec2(Vec2 a, Vec2 b) diff --git a/src/base/base_math.h b/src/base/base_math.h index fd4fa05d..960ea2be 100644 --- a/src/base/base_math.h +++ b/src/base/base_math.h @@ -217,6 +217,14 @@ u64 ClampU64(u64 v, u64 min, u64 max); i64 ClampI64(i64 v, i64 min, i64 max); f64 ClampF64(f64 v, f64 min, f64 max); +//- Saturate +u32 SaturateU32(u32 v); +i32 SaturateI32(i32 v); +f32 SaturateF32(f32 v); +u64 SaturateU64(u64 v); +i64 SaturateI64(i64 v); +f64 SaturateF64(f64 v); + //////////////////////////////////////////////////////////// //~ Float helpers @@ -304,7 +312,6 @@ Vec4 SrgbFromLinear(Vec4 lin); Vec4 PremulFromLinear(Vec4 lin); Vec4 PremulFromSrgb(Vec4 srgb); -// Vec4 LerpLinear(Vec4 v0, Vec4 v1, f32 t); Vec4 LerpSrgb(Vec4 v0, Vec4 v1, f32 t); //////////////////////////////////////////////////////////// @@ -336,6 +343,7 @@ Vec2 ClampVec2Len(Vec2 a, f32 max); //- Clamp Vec2 ClampVec2(Vec2 v, Rng2 r); +Vec2 SaturateVec2(Vec2 v); //- Dot f32 DotVec2(Vec2 a, Vec2 b); diff --git a/src/base/base_string.c b/src/base/base_string.c index f6f38be1..eb6b8473 100644 --- a/src/base/base_string.c +++ b/src/base/base_string.c @@ -33,6 +33,7 @@ String StringFromUint(Arena *arena, u64 n, u64 base, u64 zfill) n /= base; } while (n > 0); + // Fill zeroes while (result.len < zfill) { StringFromChar(scratch.arena, '0'); @@ -122,19 +123,13 @@ String StringFromFloat(Arena *arena, f64 src, u32 precision) { result.text = ArenaNext(arena, u8); - if (src < 0) - { - DEBUGBREAKABLE; - } - u64 p = PowU64(10, precision); f64 multiplied = RoundF64(src * p); - // f64 multiplied_rounded = RoundF64(multiplied); i32 sign = (src >= 0) - (src < 0); u64 part_whole = TruncF64(AbsF64(multiplied) / p); - u64 part_frac = TruncF64(AbsF64(AbsF64(src) - part_whole) * p); + u64 part_frac = RoundF64(AbsF64(AbsF64(src) - part_whole) * p); // Push sign if (sign < 0 && (part_whole != 0 || part_frac != 0)) diff --git a/src/gpu/gpu_dx12/gpu_dx12_core.c b/src/gpu/gpu_dx12/gpu_dx12_core.c index 0ef5076f..fa9867b8 100644 --- a/src/gpu/gpu_dx12/gpu_dx12_core.c +++ b/src/gpu/gpu_dx12/gpu_dx12_core.c @@ -1778,8 +1778,8 @@ i64 G_CommitCommandList(G_CommandListHandle cl_handle) slotted_constants[G_ShaderConst_PrintBufferRef] = queue->print_buffer_ref.v; } { - b32 tweak_b32 = TweakBool("GPU tweak-bool", 1); - f32 tweak_f32 = TweakFloat("GPU tweak-float", 1, 0, 1); + b32 tweak_b32 = TweakBool("Shader tweak-bool", 1); + f32 tweak_f32 = TweakFloat("Shader tweak-float", 1, 0, 1); slotted_constants[G_ShaderConst_TweakB32] = tweak_b32; slotted_constants[G_ShaderConst_TweakF32] = *(u32 *)&tweak_f32; } diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index 55c67b4a..c9794a52 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -103,7 +103,8 @@ V_WidgetTheme V_GetWidgetTheme(void) //- Colors theme.col.window_bg = Rgb32(0xff1a1d1e); theme.col.window_bd = Rgb32(0xff343a3b); - theme.col.divider = theme.col.window_bd; + + theme.col.divider = LerpSrgb(Color_Black, theme.col.window_bd, 0.6); theme.col.button = theme.col.window_bg; theme.col.button_hot = Rgb32(0x103c4c); @@ -1295,11 +1296,15 @@ void V_TickForever(WaveLaneCtx *lane) //- Build command palette V_Palette *palette = &frame->palette; + { - f32 palette_ease = TweakFloat("Debug palette ease", 30, 1, 100) * frame->dt; - palette->show = LerpF32(palette->show, palette->pref_show, palette_ease); + f32 ease_rate = TweakFloat("Debug palette ease rate", 20, 1, 100) * frame->dt; + f32 ease_in_target = TweakFloat("Debug palette ease-in target", 1.3, 0, 2); + f32 pref_show = palette->is_showing ? ease_in_target : 0; + palette->show = SaturateF32(LerpF32(palette->show, pref_show, ease_rate)); } - if (palette->show > 0.001) + + if (palette->is_showing || palette->show > 0.001) { palette->key = UI_KeyF("command palette"); UI_Checkpoint palette_cp = UI_PushCP(UI_NilKey); @@ -2044,7 +2049,7 @@ void V_TickForever(WaveLaneCtx *lane) case V_CmdKind_toggle_palette: { - frame->palette.pref_show = !frame->palette.pref_show; + frame->palette.is_showing = !frame->palette.is_showing; } break; case V_CmdKind_zoom_in: diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index 418d3987..186f6545 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -134,8 +134,7 @@ Struct(V_Palette) // Persistent state Vec2 pos; UI_Key key; - - f32 pref_show; + b32 is_showing; f32 show; }; diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index a7539b9c..cc7ecec6 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -1129,7 +1129,7 @@ void UI_EndFrame(UI_Frame *frame) box->solved_scale = MulVec2Vec2(parent->solved_scale, box->solved_scale); } - f32 scale_snap = TweakFloat("UI scale snap threshold", 0.0010, 0, 0.01, .precision = 6); + f32 scale_snap = TweakFloat("UI scale snap threshold", 0.0, 0, 0.01, .precision = 6); if (AbsF32(1.0 - box->solved_scale.x) < scale_snap) { box->solved_scale.x = 1;