Merge branch 'fix/6209-background_opacity_fringing' of https://github.com/m4rw3r/kitty
This commit is contained in:
commit
8ebe4084cc
@ -37,6 +37,22 @@ in float colored_sprite;
|
|||||||
out vec4 final_color;
|
out vec4 final_color;
|
||||||
|
|
||||||
// Util functions {{{
|
// Util functions {{{
|
||||||
|
float linear2srgb(float x) {
|
||||||
|
// Linear to sRGB conversion.
|
||||||
|
float lower = 12.92 * x;
|
||||||
|
float upper = 1.055 * pow(x, 1.0f / 2.4f) - 0.055f;
|
||||||
|
|
||||||
|
return mix(lower, upper, step(0.0031308f, x));
|
||||||
|
}
|
||||||
|
|
||||||
|
float srgb2linear(float x) {
|
||||||
|
// sRGB to linear conversion
|
||||||
|
float lower = x / 12.92;
|
||||||
|
float upper = pow((x + 0.055f) / 1.055f, 2.4f);
|
||||||
|
|
||||||
|
return mix(lower, upper, step(0.04045f, x));
|
||||||
|
}
|
||||||
|
|
||||||
vec4 alpha_blend(vec4 over, vec4 under) {
|
vec4 alpha_blend(vec4 over, vec4 under) {
|
||||||
// Alpha blend two colors returning the resulting color pre-multiplied by its alpha
|
// Alpha blend two colors returning the resulting color pre-multiplied by its alpha
|
||||||
// and its alpha.
|
// and its alpha.
|
||||||
@ -103,20 +119,9 @@ vec4 vec4_premul(vec4 rgba) {
|
|||||||
#ifdef NEEDS_FOREGROUND
|
#ifdef NEEDS_FOREGROUND
|
||||||
// sRGB luminance values
|
// sRGB luminance values
|
||||||
const vec3 Y = vec3(0.2126, 0.7152, 0.0722);
|
const vec3 Y = vec3(0.2126, 0.7152, 0.0722);
|
||||||
const float gamma_factor = 2.2;
|
|
||||||
// Scaling factor for the extra text-alpha adjustment for luminance-difference.
|
// Scaling factor for the extra text-alpha adjustment for luminance-difference.
|
||||||
const float text_gamma_scaling = 0.5;
|
const float text_gamma_scaling = 0.5;
|
||||||
|
|
||||||
float linear2srgb(float x) {
|
|
||||||
// Approximation of linear-to-sRGB conversion
|
|
||||||
return pow(x, 1.0 / gamma_factor);
|
|
||||||
}
|
|
||||||
|
|
||||||
float srgb2linear(float x) {
|
|
||||||
// Approximation of sRGB-to-linear conversion
|
|
||||||
return pow(x, gamma_factor);
|
|
||||||
}
|
|
||||||
|
|
||||||
float clamp_to_unit_float(float x) {
|
float clamp_to_unit_float(float x) {
|
||||||
// Clamp value to suitable output range
|
// Clamp value to suitable output range
|
||||||
return clamp(x, 0.0f, 1.0f);
|
return clamp(x, 0.0f, 1.0f);
|
||||||
@ -179,6 +184,12 @@ void main() {
|
|||||||
vec4 fg = calculate_foreground(background);
|
vec4 fg = calculate_foreground(background);
|
||||||
#ifdef TRANSPARENT
|
#ifdef TRANSPARENT
|
||||||
final_color = alpha_blend_premul(fg, vec4_premul(background, bg_alpha));
|
final_color = alpha_blend_premul(fg, vec4_premul(background, bg_alpha));
|
||||||
|
|
||||||
|
// Adjust the transparent alpha-channel to account for incorrect
|
||||||
|
// gamma-blending performed by the compositor (true for at least wlroots,
|
||||||
|
// picom, GNOME, MacOS).
|
||||||
|
// This is the last pass:
|
||||||
|
final_color.a = linear2srgb(final_color.a);
|
||||||
#else
|
#else
|
||||||
final_color = alpha_blend_premul(fg, background);
|
final_color = alpha_blend_premul(fg, background);
|
||||||
#endif
|
#endif
|
||||||
@ -193,7 +204,7 @@ void main() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BACKGROUND
|
#ifdef BACKGROUND
|
||||||
#if defined(TRANSPARENT)
|
#ifdef TRANSPARENT
|
||||||
final_color = vec4_premul(background, bg_alpha);
|
final_color = vec4_premul(background, bg_alpha);
|
||||||
#else
|
#else
|
||||||
final_color = vec4(background, draw_bg);
|
final_color = vec4(background, draw_bg);
|
||||||
@ -202,6 +213,10 @@ void main() {
|
|||||||
|
|
||||||
#ifdef FOREGROUND
|
#ifdef FOREGROUND
|
||||||
final_color = calculate_foreground(); // pre-multiplied foreground
|
final_color = calculate_foreground(); // pre-multiplied foreground
|
||||||
|
|
||||||
|
// This is the last pass, adjust alpha to compensate for gamma-incorrect
|
||||||
|
// blending in compositor:
|
||||||
|
final_color.a = linear2srgb(final_color.a);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user