Skip to content

Commit

Permalink
Change blending options for transparent background
Browse files Browse the repository at this point in the history
  • Loading branch information
nightuser committed May 27, 2019
1 parent 09ac8ea commit d397b8c
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions kitty/cell_fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ vec4 alpha_blend_premul(vec3 over, float over_alpha, vec3 under, float under_alp
float alpha = mix(under_alpha, 1.0f, over_alpha);
return vec4(premul_blend(over, over_alpha, under), alpha);
}

float max3(vec3 v) {
return max(max(v.r, v.g), v.b);
}

float rgb_to_grayscale(vec3 color) {
return dot(vec3(0.3, 0.59, 0.11), color);
}
// }}}

#ifdef NEEDS_FOREGROUND
Expand All @@ -71,7 +63,7 @@ vec4 calculate_foreground() {
#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 = rgb_to_grayscale(text_fg.rgb); // Grayscale looks much nicer than max3
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 text_alpha = mix(text_fg.a, alpha, subpixel);
Expand Down

0 comments on commit d397b8c

Please sign in to comment.