From 3ae489b1516ba7e90994e074d6b37f022673ed4b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 7 Jun 2023 16:23:30 +0530 Subject: [PATCH] Fix #6345 @m4rw3r this is fixing a bug in #6218. Seems fairly straightforward but since it's your code, please review. --- kitty/blit_fragment.glsl | 10 ++++++++++ kitty/cell_fragment.glsl | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/kitty/blit_fragment.glsl b/kitty/blit_fragment.glsl index e0a47ce60..74e243336 100644 --- a/kitty/blit_fragment.glsl +++ b/kitty/blit_fragment.glsl @@ -5,6 +5,16 @@ uniform sampler2D image; in vec2 texcoord; out vec4 color; +float linear2srgb(float x) { + // Linear to sRGB conversion. + float lower = 12.92 * x; + float upper = 1.055 * pow(x, 1.0f / 2.4f) - 0.055f; + + return mix(lower, upper, step(0.0031308f, x)); +} + + void main() { color = texture(image, texcoord); + color.a = linear2srgb(color.a); } diff --git a/kitty/cell_fragment.glsl b/kitty/cell_fragment.glsl index 8cdc388cf..2d2bec92c 100644 --- a/kitty/cell_fragment.glsl +++ b/kitty/cell_fragment.glsl @@ -240,9 +240,9 @@ void main() { #ifdef FOREGROUND final_color = calculate_foreground(); // pre-multiplied foreground - // This is the last pass, adjust alpha to compensate for gamma-incorrect - // blending in compositor: - final_color.a = linear2srgb(final_color.a); + // This is the last pass, called both with transparency and without but not in draw_cells_simple(). + // When transparent it is drawn into a framebuffer and linear2srgb() will be done + // when blitting that framebuffer. When not transparent there is not need to do linear2srgb() anyway. #endif }