From 6c1bb9b7c9992712c7a48eea5f5a51013b7f7e90 Mon Sep 17 00:00:00 2001 From: nightuser <1827576+nightuser@users.noreply.github.com> Date: Tue, 4 Jun 2019 11:19:52 +0300 Subject: [PATCH] Use green channel as alpha for transparent background --- kitty/cell_fragment.glsl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kitty/cell_fragment.glsl b/kitty/cell_fragment.glsl index e928c082529..76818cb4068 100644 --- a/kitty/cell_fragment.glsl +++ b/kitty/cell_fragment.glsl @@ -97,11 +97,10 @@ vec4 calculate_foreground() { #ifdef SUBPIXEL vec3 unblended_fg = mix(foreground, text_fg.rgb, colored_sprite); #ifdef TRANSPARENT - // According to https://stackoverflow.com/questions/33507617/blending-text-rendered-by-freetype-in-color-and-alpha - // it's impossible to precisely blend it if we use RGBA. Hence, the following hack is used. - float alpha = text_fg.g; // TODO: Cairo uses green channel when converts FreeType's subpixel to ARGB - vec3 scaled_mask = mix(vec3(1.0), text_fg.rgb / alpha, bvec3(alpha > 0)); // TODO: May get not normalized values? - vec3 blended_fg = mix(background * bg_alpha * bg_alpha, foreground, scaled_mask); // TODO: Check whether we should multiply by bg_alpha + float alpha = text_fg.g; // Cairo uses green channel to convert FreeType's subpixel buffer to ARGB + float scale_coeff = mix(1, alpha, alpha > 0); + vec3 scaled_mask = text_fg.rgb / scale_coeff; + vec3 blended_fg = foreground * scaled_mask; float text_alpha = mix(text_fg.a, alpha, subpixel); #else vec3 blended_fg = mix(background, foreground, text_fg.rgb);