From 2a1b51ec94b57aecfede58af22f6896480e29417 Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Thu, 16 Jan 2025 22:28:22 -0500 Subject: [PATCH] fix(Metal): fix incorrect premultiplication of colors Also make sure to divide alpha out before applying gamma encoding back to text color when not using linear blending. --- src/renderer/shaders/cell.metal | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/renderer/shaders/cell.metal b/src/renderer/shaders/cell.metal index d4657ec28e..17f811a197 100644 --- a/src/renderer/shaders/cell.metal +++ b/src/renderer/shaders/cell.metal @@ -139,7 +139,7 @@ float4 load_color( // already have the correct color here and // can premultiply and return it. if (display_p3 && !linear) { - color *= color.a; + color.rgb *= color.a; return color; } @@ -167,7 +167,7 @@ float4 load_color( } // Premultiply our color by its alpha. - color *= color.a; + color.rgb *= color.a; return color; } @@ -503,12 +503,12 @@ fragment float4 cell_text_fragment( // If we're not doing linear blending, then we need to // re-apply the gamma encoding to our color manually. // - // We do it BEFORE premultiplying the alpha because - // we want to produce the effect of not linearizing - // it in the first place in order to match the look - // of software that never does this. + // Since the alpha is premultiplied, we need to divide + // it out before unlinearizing and re-multiply it after. if (!uniforms.use_linear_blending) { + color.rgb /= color.a; color = unlinearize(color); + color.rgb *= color.a; } // Fetch our alpha mask for this pixel.