From 3b0b1df9c3ffda4da543ef92611528393ecec4bd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 15 Jan 2025 15:05:03 +0530 Subject: [PATCH] Use textFetch() for underline exclusion sampling Fixes sampling from non-bottom row --- kitty/cell_fragment.glsl | 6 ++++-- kitty/cell_vertex.glsl | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/kitty/cell_fragment.glsl b/kitty/cell_fragment.glsl index dc6a19e45..7d0ef3dc8 100644 --- a/kitty/cell_fragment.glsl +++ b/kitty/cell_fragment.glsl @@ -15,7 +15,7 @@ in vec3 sprite_pos; in vec3 underline_pos; in vec3 cursor_pos; in vec3 strike_pos; -in vec3 underline_exclusion_pos; +flat in uint underline_exclusion_pos; in vec3 foreground; in vec4 cursor_color_premult; in vec3 decoration_fg; @@ -128,8 +128,10 @@ vec4 load_text_foreground_color() { vec4 calculate_premul_foreground_from_sprites(vec4 text_fg) { // Return premul foreground color from decorations (cursor, underline, strikethrough) + ivec3 sz = textureSize(sprites, 0); float underline_alpha = texture(sprites, underline_pos).a; - float underline_exclusion = texture(sprites, underline_exclusion_pos).a; + float underline_exclusion = texelFetch(sprites, ivec3(int( + sprite_pos.x * float(sz.x)), int(underline_exclusion_pos), int(sprite_pos.z)), 0).a; underline_alpha *= 1.0f - underline_exclusion; float strike_alpha = texture(sprites, strike_pos).a; float cursor_alpha = texture(sprites, cursor_pos).a; diff --git a/kitty/cell_vertex.glsl b/kitty/cell_vertex.glsl index a567119e5..12eb28f27 100644 --- a/kitty/cell_vertex.glsl +++ b/kitty/cell_vertex.glsl @@ -52,7 +52,7 @@ out vec3 underline_pos; out vec3 cursor_pos; out vec4 cursor_color_premult; out vec3 strike_pos; -out vec3 underline_exclusion_pos; +flat out uint underline_exclusion_pos; out vec3 foreground; out vec3 decoration_fg; out float colored_sprite; @@ -121,10 +121,10 @@ vec3 to_sprite_pos(uvec2 pos, uint idx) { return vec3(s_xpos[pos.x], s_ypos[pos.y], c.z); } -vec3 to_underline_exclusion_pos(uvec2 pos, vec3 sprite_pos) { +uint to_underline_exclusion_pos() { uvec3 c = to_sprite_coords(sprite_idx[0]); - float y = (float(c.y) + 1.0f) * (1.0f / float(sprites_ynum)); - return vec3(sprite_pos.x, y, sprite_pos.z); + uint cell_top_px = c.y * (cell_height + 1u); + return cell_top_px + cell_height; } uint read_sprite_decorations_idx() { @@ -240,7 +240,7 @@ void main() { uvec2 decs = get_decorations_indices(uint(in_url), text_attrs); strike_pos = to_sprite_pos(cell_data.pos, decs[0]); underline_pos = to_sprite_pos(cell_data.pos, decs[1]); - underline_exclusion_pos = to_underline_exclusion_pos(cell_data.pos, sprite_pos); + underline_exclusion_pos = to_underline_exclusion_pos(); // Cursor cursor_color_premult = vec4(color_to_vec(cursor_bg) * cursor_opacity, cursor_opacity);