Use textFetch() for underline exclusion sampling

Fixes sampling from non-bottom row
This commit is contained in:
Kovid Goyal
2025-01-15 15:05:03 +05:30
parent 484155ca89
commit 3b0b1df9c3
2 changed files with 9 additions and 7 deletions

View File

@@ -15,7 +15,7 @@ in vec3 sprite_pos;
in vec3 underline_pos; in vec3 underline_pos;
in vec3 cursor_pos; in vec3 cursor_pos;
in vec3 strike_pos; in vec3 strike_pos;
in vec3 underline_exclusion_pos; flat in uint underline_exclusion_pos;
in vec3 foreground; in vec3 foreground;
in vec4 cursor_color_premult; in vec4 cursor_color_premult;
in vec3 decoration_fg; in vec3 decoration_fg;
@@ -128,8 +128,10 @@ vec4 load_text_foreground_color() {
vec4 calculate_premul_foreground_from_sprites(vec4 text_fg) { vec4 calculate_premul_foreground_from_sprites(vec4 text_fg) {
// Return premul foreground color from decorations (cursor, underline, strikethrough) // Return premul foreground color from decorations (cursor, underline, strikethrough)
ivec3 sz = textureSize(sprites, 0);
float underline_alpha = texture(sprites, underline_pos).a; 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; underline_alpha *= 1.0f - underline_exclusion;
float strike_alpha = texture(sprites, strike_pos).a; float strike_alpha = texture(sprites, strike_pos).a;
float cursor_alpha = texture(sprites, cursor_pos).a; float cursor_alpha = texture(sprites, cursor_pos).a;

View File

@@ -52,7 +52,7 @@ out vec3 underline_pos;
out vec3 cursor_pos; out vec3 cursor_pos;
out vec4 cursor_color_premult; out vec4 cursor_color_premult;
out vec3 strike_pos; out vec3 strike_pos;
out vec3 underline_exclusion_pos; flat out uint underline_exclusion_pos;
out vec3 foreground; out vec3 foreground;
out vec3 decoration_fg; out vec3 decoration_fg;
out float colored_sprite; 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); 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]); uvec3 c = to_sprite_coords(sprite_idx[0]);
float y = (float(c.y) + 1.0f) * (1.0f / float(sprites_ynum)); uint cell_top_px = c.y * (cell_height + 1u);
return vec3(sprite_pos.x, y, sprite_pos.z); return cell_top_px + cell_height;
} }
uint read_sprite_decorations_idx() { uint read_sprite_decorations_idx() {
@@ -240,7 +240,7 @@ void main() {
uvec2 decs = get_decorations_indices(uint(in_url), text_attrs); uvec2 decs = get_decorations_indices(uint(in_url), text_attrs);
strike_pos = to_sprite_pos(cell_data.pos, decs[0]); strike_pos = to_sprite_pos(cell_data.pos, decs[0]);
underline_pos = to_sprite_pos(cell_data.pos, decs[1]); 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
cursor_color_premult = vec4(color_to_vec(cursor_bg) * cursor_opacity, cursor_opacity); cursor_color_premult = vec4(color_to_vec(cursor_bg) * cursor_opacity, cursor_opacity);