From 8ece8957741b91c022f76842ccbcfb0f7913945a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Wernst=C3=A5l?= Date: Mon, 23 Jan 2023 19:23:46 +0100 Subject: [PATCH] feat: Use sRGB LUT for cells --- kitty/cell_vertex.glsl | 3 ++- kitty/shaders.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/kitty/cell_vertex.glsl b/kitty/cell_vertex.glsl index 799e1edcd..7cd1d30d8 100644 --- a/kitty/cell_vertex.glsl +++ b/kitty/cell_vertex.glsl @@ -29,6 +29,7 @@ uniform uint draw_bg_bitfield; layout(location=0) in uvec3 colors; layout(location=1) in uvec4 sprite_coords; layout(location=2) in uint is_selected; +uniform float gamma_lut[256]; const int fg_index_map[] = int[3](0, 1, 0); @@ -87,7 +88,7 @@ vec3 color_to_vec(uint c) { r = (c >> 16) & BYTE_MASK; g = (c >> 8) & BYTE_MASK; b = c & BYTE_MASK; - return vec3(float(r) / 255.0, float(g) / 255.0, float(b) / 255.0); + return vec3(gamma_lut[r], gamma_lut[g], gamma_lut[b]); } uint resolve_color(uint c, uint defval) { diff --git a/kitty/shaders.c b/kitty/shaders.c index f8f27cfc6..05bf279be 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -570,6 +570,10 @@ set_cell_uniforms(float current_inactive_text_alpha, bool force) { S(CELL_PROGRAM, dim_opacity, OPT(dim_opacity), 1f); S(CELL_FG_PROGRAM, dim_opacity, OPT(dim_opacity), 1f); S(CELL_BG_PROGRAM, defaultbg, OPT(background), 1f); #undef S +#define SV(prog, name, num, val, type) { bind_program(prog); glUniform##type(glGetUniformLocation(program_id(prog), #name), num, val); } + SV(CELL_PROGRAM, gamma_lut, 256, srgb_lut, 1fv); SV(CELL_FG_PROGRAM, gamma_lut, 256, srgb_lut, 1fv); + SV(CELL_BG_PROGRAM, gamma_lut, 256, srgb_lut, 1fv); SV(CELL_SPECIAL_PROGRAM, gamma_lut, 256, srgb_lut, 1fv); +#undef SV cell_uniform_data.constants_set = true; } if (current_inactive_text_alpha != cell_uniform_data.prev_inactive_text_alpha || force) {