From f8dac2c13619952bd6679db19fd5b49be1e744fb Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 26 Aug 2025 12:09:30 +0530 Subject: [PATCH] Write foreground output only at end of shader --- kitty/cell_fragment.glsl | 4 ++-- kitty/cell_vertex.glsl | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/kitty/cell_fragment.glsl b/kitty/cell_fragment.glsl index 88ba50b3d..877da11d0 100644 --- a/kitty/cell_fragment.glsl +++ b/kitty/cell_fragment.glsl @@ -16,7 +16,7 @@ in vec3 underline_pos; in vec3 cursor_pos; in vec3 strike_pos; flat in uint underline_exclusion_pos; -in vec3 foreground; +in vec3 cell_foreground; in vec4 cursor_color_premult; in vec3 decoration_fg; in float colored_sprite; @@ -62,7 +62,7 @@ vec4 load_text_foreground_color() { // For colored sprites use the color from the sprite rather than the text foreground // Return non-premultiplied foreground color vec4 text_fg = texture(sprites, sprite_pos); - return vec4(mix(foreground, text_fg.rgb, colored_sprite), text_fg.a); + return vec4(mix(cell_foreground, text_fg.rgb, colored_sprite), text_fg.a); } vec4 calculate_premul_foreground_from_sprites(vec4 text_fg) { diff --git a/kitty/cell_vertex.glsl b/kitty/cell_vertex.glsl index f35a5d3a8..043bca9a7 100644 --- a/kitty/cell_vertex.glsl +++ b/kitty/cell_vertex.glsl @@ -47,16 +47,16 @@ const uint cursor_shape_map[] = uint[5]( // maps cursor shape to foreground spr out vec3 background; out vec4 effective_background_premul; #ifndef ONLY_BACKGROUND +out float effective_text_alpha; out vec3 sprite_pos; out vec3 underline_pos; out vec3 cursor_pos; -out vec4 cursor_color_premult; out vec3 strike_pos; flat out uint underline_exclusion_pos; -out vec3 foreground; +out vec3 cell_foreground; +out vec4 cursor_color_premult; out vec3 decoration_fg; out float colored_sprite; -out float effective_text_alpha; #endif @@ -261,7 +261,7 @@ void main() { // Foreground {{{ #ifndef ONLY_BACKGROUND // background does not depend on foreground fg_as_uint = has_mark * color_table[NUM_COLORS + MARK_MASK + mark] + (ONE - has_mark) * fg_as_uint; - foreground = color_to_vec(fg_as_uint); + vec3 foreground = color_to_vec(fg_as_uint); float has_dim = float((text_attrs >> DIM_SHIFT) & ONE), has_blink = float((text_attrs >> BLINK_SHIFT) & ONE); effective_text_alpha = inactive_text_alpha * if_one_then(has_dim, dim_opacity, 1.0) * if_one_then( has_blink, blink_opacity, 1.0); @@ -320,4 +320,8 @@ void main() { bgpremul *= draw_bg; effective_background_premul = bgpremul; #endif + +#ifndef ONLY_BACKGROUND + cell_foreground = foreground; +#endif }