aim above 1.0 when easing palette in

This commit is contained in:
jacob 2026-01-02 20:03:44 -06:00
parent 6a700c0863
commit d0130c4810
7 changed files with 42 additions and 18 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -134,8 +134,7 @@ Struct(V_Palette)
// Persistent state
Vec2 pos;
UI_Key key;
f32 pref_show;
b32 is_showing;
f32 show;
};

View File

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