diff --git a/src/base/base.h b/src/base/base.h index 83100a0d..ff2d547d 100644 --- a/src/base/base.h +++ b/src/base/base.h @@ -357,28 +357,22 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t); //////////////////////////////////////////////////////////// //~ Color helper macros -//- Rgba 32 bit helpers -#define Rgb32(r, g, b) Rgba32((r), (g), (b), 0xFF) -#define Rgba32(r, g, b, a) (u32)((u32)(r) | ((u32)(g) << 8) | ((u32)(b) << 16) | ((u32)(a) << 24)) -#define Bgr32(rgb) ((((rgb >> 0) & 0xFF) << 16) | (((rgb >> 8) & 0xFF) << 8) | (((rgb >> 16) & 0xFF) << 0)) +#define Rgba32(v) Vec4FromU32((u32)(v)) +#define Rgb32(v) Vec4FromU32((u32)(v) | (0xFF << 24)) +// #define Bgr32(rgb) ((((rgb >> 0) & 0xFF) << 16) | (((rgb >> 8) & 0xFF) << 8) | (((rgb >> 16) & 0xFF) << 0)) -//- Rgba 32 bit float float helpers -#define _Rgb32U8FromF(fl) ((u8)((fl * 255.0) + 0.5)) -#define Rgba32F(r, g, b, a) Rgba32(_Rgb32U8FromF((r)), _Rgb32U8FromF((g)), _Rgb32U8FromF((b)), _Rgb32U8FromF((a))) -#define Rgb32F(r, g, b) Rgba32F((r), (g), (b), 1.f) +#define Rgba(r, g, b, a) VEC4((r), (g), (b), (a)) +#define Rgb(r, g, b) VEC4((r), (g), (b), 1) -#define Alpha32F(color, a) ((color) & 0x00FFFFFF) | (_Rgb32U8FromF((a)) << 24) - -//- Pre-defined colors -#define Color_White Rgb32(0xFF, 0xFF, 0xFF) -#define Color_Black Rgb32(0x00, 0x00, 0x00) -#define Color_Red Rgb32(0xFF, 0x00, 0x00) -#define Color_Green Rgb32(0x00, 0xFF, 0x00) -#define Color_Blue Rgb32(0x00, 0x00, 0xFF) -#define Color_Yellow Rgb32(0xFF, 0xFF, 0x00) -#define Color_Orange Rgb32(0xFF, 0xA5, 0x00) -#define Color_Purple Rgb32(0xFF, 0x00, 0XFF) -#define Color_Cyan Rgb32(0x00, 0xFF, 0XFF) +#define Color_White Rgba32(0xFFFFFFFF) +#define Color_Black Rgba32(0xFF000000) +#define Color_Red Rgba32(0xFF0000FF) +#define Color_Green Rgba32(0xFF00FF00) +#define Color_Blue Rgba32(0xFFFF0000) +#define Color_Yellow Rgba32(0xFF00FFFF) +#define Color_Orange Rgba32(0xFF00A5FF) +#define Color_Purple Rgba32(0xFFFF00FF) +#define Color_Cyan Rgba32(0xFFFFFF00) //////////////////////////////////////////////////////////// //~ Intrinsic headers diff --git a/src/base/base_math.c b/src/base/base_math.c index c9fa6e73..323ad53b 100644 --- a/src/base/base_math.c +++ b/src/base/base_math.c @@ -800,35 +800,65 @@ i64 LerpU64(u64 val0, u64 val1, f64 t) //////////////////////////////////////////////////////////// //~ Color operations +f32 SrgbFromLinearF32(f32 lin) +{ + f32 result = 0; + if (lin <= 0.0031308f) + { + result = lin * 12.92f; + } + else + { + result = 1.055f * PowF32(lin, 1.0f/2.4f) - 0.055f; + } + return result; +} + +f32 LinearFromSrgbF32(f32 srgb) +{ + f32 result = 0; + if (srgb <= 0.04045f) + { + result = srgb / 12.92f; + } + else + { + result = PowF32((srgb + 0.055f) / 1.055f, 2.4f); + } + return result; +} + Vec4 LinearFromSrgb(Vec4 srgb) { Vec4 result = ZI; - result.x = PowF32(AbsF32(srgb.x), 2.2); - result.y = PowF32(AbsF32(srgb.y), 2.2); - result.z = PowF32(AbsF32(srgb.z), 2.2); + result.x = LinearFromSrgbF32(srgb.x); + result.y = LinearFromSrgbF32(srgb.y); + result.z = LinearFromSrgbF32(srgb.z); result.w = srgb.w; return result; } -Vec4 SrgbFromLinear(Vec4 linear) +Vec4 SrgbFromLinear(Vec4 lin) { Vec4 result = ZI; - result.x = PowF32(linear.x, 1.0 / 2.2); - result.y = PowF32(linear.y, 1.0 / 2.2); - result.z = PowF32(linear.z, 1.0 / 2.2); - result.w = linear.w; + result.x = SrgbFromLinearF32(lin.x); + result.y = SrgbFromLinearF32(lin.y); + result.z = SrgbFromLinearF32(lin.z); + result.w = lin.w; return result; } -Vec4 LinearFromSrgbU32(u32 srgb) +u32 LinearU32FromSrgb(Vec4 srgb) { - return LinearFromSrgb(Vec4NormFromU32(srgb)); + Vec4 lin = LinearFromSrgb(srgb); + u32 result = U32FromVec4(lin); + return result; } -u32 BlendSrgbU32(u32 v0, u32 v1, f32 t) +Vec4 BlendSrgb(Vec4 v0, Vec4 v1, f32 t) { - Vec4 v0_l = LinearFromSrgbU32(v0); - Vec4 v1_l = LinearFromSrgbU32(v1); + Vec4 v0_l = LinearFromSrgb(v0); + Vec4 v1_l = LinearFromSrgb(v1); Vec4 blend_l = ZI; { blend_l.x = LerpF32(v0_l.x, v1_l.x, t); @@ -836,8 +866,8 @@ u32 BlendSrgbU32(u32 v0, u32 v1, f32 t) blend_l.z = LerpF32(v0_l.z, v1_l.z, t); blend_l.w = LerpF32(v0_l.w, v1_l.w, t); } - Vec4 srgb_v4 = SrgbFromLinear(blend_l); - return Rgba32F(srgb_v4.x, srgb_v4.y, srgb_v4.z, srgb_v4.w); + Vec4 result = SrgbFromLinear(blend_l); + return result; } //////////////////////////////////////////////////////////// @@ -1092,9 +1122,9 @@ Vec2I32 SubVec2I32(Vec2I32 a, Vec2I32 b) //////////////////////////////////////////////////////////// //~ Vec4 operations -Vec4 Vec4NormFromU32(u32 v) +Vec4 Vec4FromU32(u32 v) { - Vec4 result; + Vec4 result = ZI; result.x = ((v >> 0) & 0xFF) / 255.0; result.y = ((v >> 8) & 0xFF) / 255.0; result.z = ((v >> 16) & 0xFF) / 255.0; @@ -1102,6 +1132,22 @@ Vec4 Vec4NormFromU32(u32 v) return result; } +u32 U32FromVec4(Vec4 v) +{ + u32 result = 0; + result |= (((u32)(v.x * 255.0)) & 0xFF) << 0; + result |= (((u32)(v.y * 255.0)) & 0xFF) << 8; + result |= (((u32)(v.z * 255.0)) & 0xFF) << 16; + result |= (((u32)(v.w * 255.0)) & 0xFF) << 24; + return result; +} + +PackedVec4 PackVec4(Vec4 v) +{ + PackedVec4 result = ZI; + return result; +} + //////////////////////////////////////////////////////////// //~ Xform operations diff --git a/src/base/base_math.h b/src/base/base_math.h index b52452bd..3950d02f 100644 --- a/src/base/base_math.h +++ b/src/base/base_math.h @@ -44,6 +44,8 @@ Struct(Vec2U32) { u32 x, y; }; Struct(Vec3U32) { u32 x, y, z; }; Struct(Vec4U32) { u32 x, y, z, w; }; +Struct(PackedVec4) { u32 hi; u32 lo; }; + Struct(Vec2Array) { Vec2 *points; @@ -259,10 +261,11 @@ i64 LerpU64(u64 val0, u64 val1, f64 t); //////////////////////////////////////////////////////////// //~ Color operations +f32 SrgbFromLinearF32(f32 lin); +f32 LinearFromSrgbF32(f32 srgb); Vec4 LinearFromSrgb(Vec4 srgb); -Vec4 SrgbFromLinear(Vec4 linear); -Vec4 LinearFromSrgbU32(u32 srgb); -u32 BlendSrgbU32(u32 v0, u32 v1, f32 t); +Vec4 SrgbFromLinear(Vec4 lin); +Vec4 BlendSrgb(Vec4 v0, Vec4 v1, f32 t); //////////////////////////////////////////////////////////// //~ Vec2 operations @@ -333,7 +336,9 @@ Vec2I32 SubVec2I32(Vec2I32 a, Vec2I32 b); //////////////////////////////////////////////////////////// //~ Vec4 operations -Vec4 Vec4NormFromU32(u32 v); +Vec4 Vec4FromU32(u32 v); +u32 U32FromVec4(Vec4 v); +PackedVec4 PackVec4(Vec4 v); //////////////////////////////////////////////////////////// //~ Xform operations diff --git a/src/base/base_math_gpu.h b/src/base/base_math_gpu.h index 8014ac54..f23c133a 100644 --- a/src/base/base_math_gpu.h +++ b/src/base/base_math_gpu.h @@ -17,6 +17,7 @@ typedef int4 Vec4I32; typedef uint2 Vec2U32; typedef uint3 Vec3U32; typedef uint4 Vec4U32; +typedef uint2 PackedVec4; typedef float2x3 Xform; typedef float4 Rect; typedef float4 ClipRect; @@ -25,9 +26,9 @@ typedef float4 Quad; typedef float4x4 Mat4x4; //////////////////////////////////////////////////////////// -//~ Integer -> float +//~ Color helpers -Vec4 Vec4NormFromU32(u32 v) +Vec4 Vec4FromU32(u32 v) { Vec4 result; result.r = ((v >> 0) & 0xFF) / 255.0; @@ -37,21 +38,6 @@ Vec4 Vec4NormFromU32(u32 v) return result; } -//////////////////////////////////////////////////////////// -//~ Srgb -> linear - -/* Linear color from normalized sRGB */ -Vec4 LinearFromSrgbVec4(Vec4 srgb) -{ - return Vec4(pow(abs(srgb.rgb), 2.2), srgb.a); -} - -/* Linear color from R8G8B8A8 sRGB */ -Vec4 LinearFromSrgbU32(u32 srgb32) -{ - return LinearFromSrgbVec4(Vec4NormFromU32(srgb32)); -} - //////////////////////////////////////////////////////////// //~ Vertex ID helpers diff --git a/src/proto/pp_widgets.c b/src/proto/pp_widgets.c index 9670832e..5bc2cfd3 100644 --- a/src/proto/pp_widgets.c +++ b/src/proto/pp_widgets.c @@ -5,8 +5,8 @@ PP_WidgetTheme PP_GetWidgetTheme(void) { PP_WidgetTheme theme = ZI; theme.font = ResourceKeyFromStore(&PP_Resources, Lit("font/fixedsys.ttf")); - theme.window_background_color = 0xff1a1d1e; - theme.window_border_color = 0xff343a3b; + theme.window_background_color = Rgb32(0xff1a1d1e); + theme.window_border_color = Rgb32(0xff343a3b); theme.window_border = 1; theme.window_width = 300; theme.window_padding = theme.window_border - 1; @@ -35,18 +35,18 @@ void PP_BeginListerWidget(PP_ListerWidget *lister) UI_Push(Tag, HashF("lister")); UI_Key titlebar_key = UI_KeyF("lister title bar"); - u32 window_background_color = theme.window_background_color; - u32 window_border_color = theme.window_border_color; - u32 titlebar_color = 0; - u32 titlebar_border_color = 0; - u32 divider_color = theme.divider_color; + Vec4 window_background_color = theme.window_background_color; + Vec4 window_border_color = theme.window_border_color; + Vec4 titlebar_color = ZI; + Vec4 titlebar_border_color = ZI; + Vec4 divider_color = theme.divider_color; { UI_Report rep = UI_ReportFromKey(titlebar_key); if (rep.m1_held) { lister->pos = SubVec2(cursor_pos, rep.last_m1_offset); } - window_border_color = BlendSrgbU32(window_border_color, Rgb32F(0.5, 0.5, 0.5), rep.hot); + window_border_color = BlendSrgb(window_border_color, Rgb(0.5, 0.5, 0.5), rep.hot); } UI_Push(BackgroundColor, window_background_color); @@ -118,18 +118,19 @@ UI_Report PP_BuildListerButton(PP_ListerWidget *lister, String text) UI_Key btn_key = UI_KeyF("btn%F", FmtSint(lister->num_buttons)); UI_Report rep = UI_ReportFromKey(btn_key); - u32 hovered_color = Rgb32(0x10, 0x3c, 0x4c); - u32 pressed_color = Alpha32F(hovered_color, 0.2); + Vec4 hovered_color = Rgb32(0x103c4c); + Vec4 pressed_color = hovered_color; + pressed_color.w = 0.2; f32 hot = rep.hot; f32 active = rep.active; f32 hovered = rep.hovered; - u32 color = theme.window_background_color; - u32 border_color = 0; - color = BlendSrgbU32(color, hovered_color, hot); - color = BlendSrgbU32(color, pressed_color, active * hovered); - border_color = BlendSrgbU32(border_color, Rgb32(0x00, 0x79, 0xa6), hot); + Vec4 color = theme.window_background_color; + Vec4 border_color = ZI; + color = BlendSrgb(color, hovered_color, hot); + color = BlendSrgb(color, pressed_color, active * hovered); + border_color = BlendSrgb(border_color, Rgb32(0x0078a6), hot); UI_SetNext(Rounding, 0); UI_SetNext(Tint, 0); @@ -180,23 +181,23 @@ UI_Box *PP_BuildDebugConsoleWidget(b32 minimized) // i32 console_level = minimized ? LogLevel_Success : LogLevel_Debug; i32 console_level = LogLevel_Debug; - u32 colors[LogLevel_Count][2] = ZI; + Vec4 colors[LogLevel_Count][2] = ZI; SetBytes(colors, 0xFF, sizeof(colors)); /* Debug colors */ - colors[LogLevel_Debug][0] = Rgb32F(0.4, 0.1, 0.4); - colors[LogLevel_Debug][1] = Rgb32F(0.5, 0.2, 0.5); + colors[LogLevel_Debug][0] = Rgb(0.4, 0.1, 0.4); + colors[LogLevel_Debug][1] = Rgb(0.5, 0.2, 0.5); /* Info colors */ - colors[LogLevel_Info][0] = Rgb32F(0.4, 0.4, 0.4); - colors[LogLevel_Info][1] = Rgb32F(0.5, 0.5, 0.5); + colors[LogLevel_Info][0] = Rgb(0.4, 0.4, 0.4); + colors[LogLevel_Info][1] = Rgb(0.5, 0.5, 0.5); /* Success colors */ - colors[LogLevel_Success][0] = Rgb32F(0.1, 0.3, 0.1); - colors[LogLevel_Success][1] = Rgb32F(0.2, 0.4, 0.2); + colors[LogLevel_Success][0] = Rgb(0.1, 0.3, 0.1); + colors[LogLevel_Success][1] = Rgb(0.2, 0.4, 0.2); /* Warning colors */ - colors[LogLevel_Warning][0] = Rgb32F(0.4, 0.4, 0.1); - colors[LogLevel_Warning][1] = Rgb32F(0.5, 0.5, 0.2); + colors[LogLevel_Warning][0] = Rgb(0.4, 0.4, 0.1); + colors[LogLevel_Warning][1] = Rgb(0.5, 0.5, 0.2); /* Error colors */ - colors[LogLevel_Error][0] = Rgb32F(0.4, 0.1, 0.1); - colors[LogLevel_Error][1] = Rgb32F(0.5, 0.2, 0.2); + colors[LogLevel_Error][0] = Rgb(0.4, 0.1, 0.1); + colors[LogLevel_Error][1] = Rgb(0.5, 0.2, 0.2); i64 max_time_ns = I64Max; i64 fade_time_ns = max_time_ns; @@ -219,7 +220,7 @@ UI_Box *PP_BuildDebugConsoleWidget(b32 minimized) } else { - UI_SetNext(BackgroundColor, Rgba32F(1, 1, 1, 0.02)); + UI_SetNext(BackgroundColor, Rgba(1, 1, 1, 0.02)); UI_SetNext(Width, UI_FILL(1, 0)); UI_SetNext(Height, UI_FIT(1)); } @@ -276,13 +277,14 @@ UI_Box *PP_BuildDebugConsoleWidget(b32 minimized) } UI_PushCP(0); { - UI_Push(Tint, Alpha32F(0xFFFFFFFF, opacity)); + Vec4 tint = VEC4(1, 1, 1, opacity); + UI_Push(Tint, tint); { - u32 color = colors[log.level][log.level_id % 2]; + Vec4 color = colors[log.level][log.level_id % 2]; UI_Push(BackgroundColor, color); UI_Push(Width, UI_FILL(1, 0)); UI_Push(Height, UI_FNT(1.5, 1)); - UI_Push(BorderColor, Rgba32F(0.25, 0.25, 0.25, 1)); + UI_Push(BorderColor, Rgb(0.25, 0.25, 0.25)); UI_Push(Rounding, UI_RPIX(0)); UI_Push(Border, 1); UI_Push(ChildAlignment, UI_Alignment_Left); diff --git a/src/proto/pp_widgets.h b/src/proto/pp_widgets.h index 84c93f9c..045e895a 100644 --- a/src/proto/pp_widgets.h +++ b/src/proto/pp_widgets.h @@ -7,14 +7,12 @@ Struct(PP_WidgetTheme) f32 font_size; f32 window_title_font_size; - u32 window_background_color; - u32 window_border_color; + Vec4 window_background_color; + Vec4 window_border_color; + Vec4 divider_color; f32 window_border; f32 window_padding; f32 window_width; - - - u32 divider_color; }; //////////////////////////////////////////////////////////// diff --git a/src/ttf/ttf_dwrite/ttf_dwrite.c b/src/ttf/ttf_dwrite/ttf_dwrite.c index 63aee6c2..2327d89c 100644 --- a/src/ttf/ttf_dwrite/ttf_dwrite.c +++ b/src/ttf/ttf_dwrite/ttf_dwrite.c @@ -42,8 +42,8 @@ TTF_Decoded TTF_Decode(Arena *arena, String encoded, f32 em_size, u32 *cache_cod { __prof; TTF_DW_SharedState *g = &TTF_DW_shared_state; - COLORREF bg_color = Rgb32(0, 0, 0); - COLORREF fg_color = Rgb32(255, 255, 255); + COLORREF bg_color = 0xFF000000; + COLORREF fg_color = 0xFFFFFFFF; IDWriteFactory5 *factory = g->factory; @@ -230,7 +230,7 @@ TTF_Decoded TTF_Decode(Arena *arena, String encoded, f32 em_size, u32 *cache_cod u64 in_x = (u64)bounding_box.left + x; u32 *out_pixel = out_data + (out_x + (out_y * atlas_w)); u32 *in_pixel = in_data + (in_x + (in_y * in_pitch)); - *out_pixel = Rgba32(0xFF, 0xFF, 0xFF, *in_pixel & 0xFF); + *out_pixel = 0x00FFFFFF | ((*in_pixel & 0xFF) << 24); } } out_offset_x += tex_w; diff --git a/src/ui/ui.lay b/src/ui/ui.lay index ff08a403..8e38790d 100644 --- a/src/ui/ui.lay +++ b/src/ui/ui.lay @@ -19,7 +19,6 @@ //- Shaders @VertexShader UI_RectVS @PixelShader UI_RectPS -@ComputeShader UI_PostCS //- Embeds @EmbedDir UI_Resources ui_res diff --git a/src/ui/ui_common.c b/src/ui/ui_common.c index f67475c3..61967177 100644 --- a/src/ui/ui_common.c +++ b/src/ui/ui_common.c @@ -5,7 +5,7 @@ UI_Box *UI_BuildLabel(String text) UI_Box *parent = UI_UseTop(Parent); ResourceKey font = UI_UseTop(Font); f32 font_size = UI_UseTop(FontSize); - u32 tint = UI_UseTop(Tint); + Vec4 tint = UI_UseTop(Tint); UI_Box *box = 0; UI_PushEmptyStack(); @@ -59,11 +59,11 @@ UI_Box *UI_BuildSpacer(UI_Size size) return box; } -UI_Box *UI_BuildDivider(UI_Size size, u32 color) +UI_Box *UI_BuildDivider(UI_Size size, Vec4 color) { UI_Box *box = 0; UI_Box *parent = UI_UseTop(Parent); - u32 tint = UI_UseTop(Tint); + Vec4 tint = UI_UseTop(Tint); Axis axis = parent->child_layout_axis; UI_PushEmptyStack(); { diff --git a/src/ui/ui_common.h b/src/ui/ui_common.h index 569fe073..75ee7ccc 100644 --- a/src/ui/ui_common.h +++ b/src/ui/ui_common.h @@ -9,7 +9,7 @@ UI_Box *UI_BuildLabelF_(char *fmt_cstr, ...); //~ Spacing helpers UI_Box *UI_BuildSpacer(UI_Size size); -UI_Box *UI_BuildDivider(UI_Size size, u32 color); +UI_Box *UI_BuildDivider(UI_Size size, Vec4 color); //////////////////////////////////////////////////////////// //~ Layout helpers diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 865eb1c6..99df4c88 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -191,9 +191,9 @@ void UI_PushEmptyStack(void) stack->style_tops[UI_StyleKind_Height]->style.Height = UI_FILL(1, 0); stack->style_tops[UI_StyleKind_Font]->style.Font = UI_GetDefaultFontResource(); stack->style_tops[UI_StyleKind_FontSize]->style.FontSize = 16.0f; - stack->style_tops[UI_StyleKind_Tint]->style.Tint = 0xFFFFFFFF; + stack->style_tops[UI_StyleKind_Tint]->style.Tint = Color_White; stack->style_tops[UI_StyleKind_Tag]->style.Tag = HashFnv64(Fnv64Basis, Lit("root")); - stack->style_tops[UI_StyleKind_DebugColor]->style.DebugColor = Rgba32F(1, 0, 1, 0.5); + stack->style_tops[UI_StyleKind_DebugColor]->style.DebugColor = Rgba(1, 0, 1, 0.5); } stack->next = g->top_stack; @@ -646,9 +646,9 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags) f32 target_hot = box == active_box || (box == hovered_box && (box == active_box || active_box == 0)); f32 target_active = box == active_box; f32 target_hovered = box == hovered_box; - f32 hot_blend_rate = target_hot == 1 ? 1 : (5 * dt); - f32 active_blend_rate = target_active == 1 ? 1 : (5 * dt); - f32 hovered_blend_rate = target_hovered == 1 ? 1 : (5 * dt); + f32 hot_blend_rate = target_hot == 1 ? 1 : (20 * dt); + f32 active_blend_rate = target_active == 1 ? 1 : (20 * dt); + f32 hovered_blend_rate = target_hovered == 1 ? 1 : (20 * dt); report->hot = LerpF32(report->hot, target_hot, hot_blend_rate); report->active = LerpF32(report->active, target_active, active_blend_rate); report->hovered = LerpF32(report->hovered, target_hovered, hovered_blend_rate); @@ -1174,7 +1174,7 @@ i64 UI_EndFrame(UI_Frame frame) { UI_Box *box = boxes_pre[pre_index]; b32 is_visible = 1; - is_visible = is_visible && ((box->tint & 0xFF000000) != 0); + is_visible = is_visible && (box->tint.w != 0); is_visible = is_visible && (box->p1.x > box->p0.x); is_visible = is_visible && (box->p1.y > box->p0.y); if (is_visible || AnyBit(g->frame_flags, UI_FrameFlag_Debug)) @@ -1187,10 +1187,10 @@ i64 UI_EndFrame(UI_Frame frame) rect->p1 = box->p1; rect->tex_uv0 = VEC2(0, 0); rect->tex_uv1 = VEC2(1, 1); - rect->background_srgb = box->background_color; - rect->border_srgb = box->border_color; - rect->debug_srgb = box->debug_color; - rect->tint_srgb = box->tint; + rect->background_lin = LinearFromSrgb(box->background_color); + rect->border_lin = LinearFromSrgb(box->border_color); + rect->debug_lin = LinearFromSrgb(box->debug_color); + rect->tint_lin = LinearFromSrgb(box->tint); rect->border = box->border; rect->tl_rounding = box->rounding_tl; rect->tr_rounding = box->rounding_tr; @@ -1322,8 +1322,8 @@ i64 UI_EndFrame(UI_Frame frame) rect->p0 = AddVec2(baseline, VEC2(rr.pos, 0)); rect->p0 = AddVec2(rect->p0, rr.offset); rect->p1 = AddVec2(rect->p0, glyph_size); - rect->debug_srgb = box->debug_color; - rect->tint_srgb = box->tint; + rect->debug_lin = LinearFromSrgb(box->debug_color); + rect->tint_lin = LinearFromSrgb(box->tint); rect->tex_uv0 = MulVec2Vec2(atlas_p0, inv_font_image_size); rect->tex_uv1 = MulVec2Vec2(atlas_p1, inv_font_image_size); rect->tex = tex_rid; @@ -1396,25 +1396,6 @@ i64 UI_EndFrame(UI_Frame frame) GPU_RasterizeMode_WireTriangleList); } } - -#if 0 - //- Prep post pass - { - GPU_TransitionToWritable(cl, g->render_target); - } - - //- Post pass - { - __profn("UI post"); - GPU_ProfN(cl, Lit("UI post")); - Vec2I32 viewport_size = RoundVec2ToVec2I32(render_viewport.size); - UI_PostSig sig = ZI; - sig.tex_size = viewport_size; - sig.tex = GPU_RWTexture2DRidFromResource(g->render_target); - sig.gamma = 2.2f; - GPU_Compute(cl, &sig, UI_PostCS, (viewport_size.x + 7) / 8, (viewport_size.y + 7) / 8, 1); - } -#endif } g->gpu_submit_fence_target = GPU_EndCommandList(cl); diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 3e5fa21d..dd50a4e8 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -100,10 +100,10 @@ Enum(UI_BoxFlag) x(ChildAlignmentY, UI_AxisAlignment) \ x(Width, UI_Size) \ x(Height, UI_Size) \ - x(BackgroundColor, u32) \ - x(BorderColor, u32) \ - x(DebugColor, u32) \ - x(Tint, u32) \ + x(BackgroundColor, Vec4) \ + x(BorderColor, Vec4) \ + x(DebugColor, Vec4) \ + x(Tint, Vec4) \ x(Border, f32) \ x(FloatingPos, Vec2) \ x(Rounding, UI_Round) \ @@ -221,11 +221,10 @@ Struct(UI_Box) UI_Size pref_size[Axis_CountXY]; UI_Round rounding; - u32 background_color; - u32 border_color; - u32 debug_color; - u32 text_color; - u32 tint; + Vec4 background_color; + Vec4 border_color; + Vec4 debug_color; + Vec4 tint; f32 border; Vec2 floating_pos; String text; diff --git a/src/ui/ui_draw.gpu b/src/ui/ui_draw.gpu index e14e81a5..5903be05 100644 --- a/src/ui/ui_draw.gpu +++ b/src/ui/ui_draw.gpu @@ -1,5 +1,4 @@ ConstantBuffer UI_rect_sig : register (b0); -ConstantBuffer UI_post_sig : register (b0); //////////////////////////////////////////////////////////// //~ Rect @@ -35,9 +34,9 @@ UI_RectPS_Input VSDef(UI_RectVS, Semantic(u32, sv_instanceid), Semantic(u32, sv_ UI_RectPS_Input result; result.sv_position = Vec4(NdcFromViewport(sig.viewport_size, screen_vert).xy, 0, 1); - result.background_lin = LinearFromSrgbU32(rect.background_srgb); - result.border_lin = LinearFromSrgbU32(rect.border_srgb); - result.tint_lin = LinearFromSrgbU32(rect.tint_srgb); + result.background_lin = rect.background_lin; + result.border_lin = rect.border_lin; + result.tint_lin = rect.tint_lin; result.rect_idx = sv_instanceid; result.rect_uv = rect_uv; result.tex_uv = tex_uv; @@ -132,31 +131,10 @@ UI_RectPS_Output PSDef(UI_RectPS, UI_RectPS_Input input) /* Debug color */ if (sig.debug_enabled) { - final_color = LinearFromSrgbU32(rect.debug_srgb); + final_color = rect.debug_lin; } UI_RectPS_Output output; output.sv_target0 = final_color; return output; } - -//////////////////////////////////////////////////////////// -//~ Post - -[numthreads(8, 8, 1)] -void CSDef(UI_PostCS, Semantic(Vec3U32, sv_dispatchthreadid)) -{ - ConstantBuffer sig = UI_post_sig; - Vec2U32 id = sv_dispatchthreadid.xy; - if (id.x < sig.tex_size.x && id.y < sig.tex_size.y) - { - SamplerState sampler = UniformSamplerFromRid(sig.sampler); - RWTexture2D tex = UniformResourceFromRid(sig.tex); - Vec4 pixel = tex[id]; - - /* Apply gamma correction */ - pixel = pow(abs(pixel), 1/sig.gamma); - - tex[id] = pixel; - } -} diff --git a/src/ui/ui_draw.h b/src/ui/ui_draw.h index b1b90efc..7076b874 100644 --- a/src/ui/ui_draw.h +++ b/src/ui/ui_draw.h @@ -27,10 +27,10 @@ Struct(UI_RectInstance) UI_RectFlag flags; Vec2 p0; Vec2 p1; - u32 tint_srgb; - u32 background_srgb; - u32 border_srgb; - u32 debug_srgb; + Vec4 tint_lin; + Vec4 background_lin; + Vec4 border_lin; + Vec4 debug_lin; f32 border; Vec2 tex_uv0; Vec2 tex_uv1; @@ -41,21 +41,3 @@ Struct(UI_RectInstance) f32 br_rounding; f32 bl_rounding; }; - -//////////////////////////////////////////////////////////// -//~ Post types - -Struct(UI_PostSig) -{ - /* ----------------------------------------------------- */ - Vec2I32 tex_size; /* 02 consts */ - RWTexture2DRid tex; /* 01 consts */ - f32 gamma; /* 01 consts */ - /* ----------------------------------------------------- */ - SamplerStateRid sampler; /* 01 consts */ - u32 _pad0; /* 01 consts (padding) */ - u32 _pad1; /* 01 consts (padding) */ - u32 _pad2; /* 01 consts (padding) */ - /* ----------------------------------------------------- */ -}; -AssertRootConst(UI_PostSig, 8);