From 94d507d9f24fafba92a7bdc6b706fe48be350c48 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 4 Aug 2020 10:59:27 +0200 Subject: Fix regression in antialiasing on outlined text After e8d9bc1bcada7d94af5a33d64a9afc860ede5b84, outline text would blend with the background rather than the fill color on the inner side of the outline. We should do the mix with the fill color like before this change, but for performance, we should still discard all pixels which are not part of the outline, which we do using step() instead of multiplying by 1.0 - a. Task-number: QTBUG-85514 Change-Id: I4b252bdbd9dae5ee599ba7c5d1cc3609fef61622 Reviewed-by: Lars Knoll Reviewed-by: Laszlo Agocs (cherry picked from commit 4da53ed1d6433730d0604b948ba3b5abeabd1eb0) --- .../scenegraph/shaders/distancefieldoutlinetext.frag | 3 ++- .../shaders/distancefieldoutlinetext_core.frag | 3 ++- src/quick/scenegraph/shaders/outlinedtext.frag | 2 +- src/quick/scenegraph/shaders/outlinedtext_core.frag | 2 +- .../shaders_ng/distancefieldoutlinetext.frag | 3 ++- .../shaders_ng/distancefieldoutlinetext.frag.qsb | Bin 1780 -> 1863 bytes .../shaders_ng/distancefieldoutlinetext_a.frag | 3 ++- .../shaders_ng/distancefieldoutlinetext_a.frag.qsb | Bin 1771 -> 1876 bytes src/quick/scenegraph/shaders_ng/outlinedtext.frag | 2 +- src/quick/scenegraph/shaders_ng/outlinedtext.frag.qsb | Bin 2067 -> 2174 bytes src/quick/scenegraph/shaders_ng/outlinedtext_a.frag | 2 +- .../scenegraph/shaders_ng/outlinedtext_a.frag.qsb | Bin 1357 -> 1437 bytes 12 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/quick/scenegraph/shaders/distancefieldoutlinetext.frag b/src/quick/scenegraph/shaders/distancefieldoutlinetext.frag index f7cdeb9064..7a063e0a9d 100644 --- a/src/quick/scenegraph/shaders/distancefieldoutlinetext.frag +++ b/src/quick/scenegraph/shaders/distancefieldoutlinetext.frag @@ -12,5 +12,6 @@ void main() { mediump float d = texture2D(_qt_texture, sampleCoord).a; mediump float a = smoothstep(alphaMin, alphaMax, d); - gl_FragColor = (1.0 - a) * styleColor * smoothstep(outlineAlphaMax0, outlineAlphaMax1, d); + gl_FragColor = step(1.0 - a, 1.0) * mix(styleColor, color, a) + * smoothstep(outlineAlphaMax0, outlineAlphaMax1, d); } diff --git a/src/quick/scenegraph/shaders/distancefieldoutlinetext_core.frag b/src/quick/scenegraph/shaders/distancefieldoutlinetext_core.frag index 622e353019..73cf9a1c29 100644 --- a/src/quick/scenegraph/shaders/distancefieldoutlinetext_core.frag +++ b/src/quick/scenegraph/shaders/distancefieldoutlinetext_core.frag @@ -16,5 +16,6 @@ void main() { float d = texture(_qt_texture, sampleCoord).r; float a = smoothstep(alphaMin, alphaMax, d); - fragColor = (1.0 - a) * styleColor * smoothstep(outlineAlphaMax0, outlineAlphaMax1, d); + fragColor = step(1.0 - a, 1.0) * mix(styleColor, color, a) + * smoothstep(outlineAlphaMax0, outlineAlphaMax1, d); } diff --git a/src/quick/scenegraph/shaders/outlinedtext.frag b/src/quick/scenegraph/shaders/outlinedtext.frag index 5fe2b14e24..1075261d5f 100644 --- a/src/quick/scenegraph/shaders/outlinedtext.frag +++ b/src/quick/scenegraph/shaders/outlinedtext.frag @@ -17,5 +17,5 @@ void main() texture2D(_qt_texture, sCoordRight).a, 0.0, 1.0) - glyph, 0.0, 1.0); - gl_FragColor = outline * styleColor; + gl_FragColor = outline * styleColor + step(1.0 - glyph, 1.0) * glyph * color; } diff --git a/src/quick/scenegraph/shaders/outlinedtext_core.frag b/src/quick/scenegraph/shaders/outlinedtext_core.frag index 4d7c614185..f3273cbdb6 100644 --- a/src/quick/scenegraph/shaders/outlinedtext_core.frag +++ b/src/quick/scenegraph/shaders/outlinedtext_core.frag @@ -21,5 +21,5 @@ void main() texture(_qt_texture, sCoordRight).r, 0.0, 1.0) - glyph, 0.0, 1.0); - fragColor = outline * styleColor; + fragColor = outline * styleColor + step(1.0 - glyph, 1.0) * glyph * color; } diff --git a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag index 945ef56fee..b1551d8ef4 100644 --- a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag +++ b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag @@ -21,5 +21,6 @@ void main() { float d = texture(_qt_texture, sampleCoord).r; float a = smoothstep(ubuf.alphaMin, ubuf.alphaMax, d); - fragColor = (1.0 - a) * ubuf.styleColor * smoothstep(ubuf.outlineAlphaMax0, ubuf.outlineAlphaMax1, d); + fragColor = step(1.0 - a, 1.0) * mix(ubuf.styleColor, ubuf.color, a) + * smoothstep(ubuf.outlineAlphaMax0, ubuf.outlineAlphaMax1, d); } diff --git a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag.qsb b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag.qsb index 942db41a5a..eae467fab0 100644 Binary files a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag.qsb and b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag.qsb differ diff --git a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag index 7ccd06610a..7c6bd9a493 100644 --- a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag +++ b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag @@ -21,5 +21,6 @@ void main() { float d = texture(_qt_texture, sampleCoord).a; float a = smoothstep(ubuf.alphaMin, ubuf.alphaMax, d); - fragColor = (1.0 - a) * ubuf.styleColor * smoothstep(ubuf.outlineAlphaMax0, ubuf.outlineAlphaMax1, d); + fragColor = step(1.0 - a, 1.0) * mix(ubuf.styleColor, ubuf.color, a) + * smoothstep(ubuf.outlineAlphaMax0, ubuf.outlineAlphaMax1, d); } diff --git a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag.qsb b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag.qsb index 00e0497248..d02e1d4c7f 100644 Binary files a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag.qsb and b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag.qsb differ diff --git a/src/quick/scenegraph/shaders_ng/outlinedtext.frag b/src/quick/scenegraph/shaders_ng/outlinedtext.frag index aac9e4bff8..947d161a50 100644 --- a/src/quick/scenegraph/shaders_ng/outlinedtext.frag +++ b/src/quick/scenegraph/shaders_ng/outlinedtext.frag @@ -29,5 +29,5 @@ void main() texture(_qt_texture, sCoordRight).r, 0.0, 1.0) - glyph, 0.0, 1.0); - fragColor = outline * ubuf.styleColor; + fragColor = outline * ubuf.styleColor + step(1.0 - glyph, 1.0) * glyph * ubuf.color; } diff --git a/src/quick/scenegraph/shaders_ng/outlinedtext.frag.qsb b/src/quick/scenegraph/shaders_ng/outlinedtext.frag.qsb index 95924de0c8..1756ee9d4b 100644 Binary files a/src/quick/scenegraph/shaders_ng/outlinedtext.frag.qsb and b/src/quick/scenegraph/shaders_ng/outlinedtext.frag.qsb differ diff --git a/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag b/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag index 481d8c94d0..5b7bd9ca82 100644 --- a/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag +++ b/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag @@ -29,5 +29,5 @@ void main() texture(_qt_texture, sCoordRight).a, 0.0, 1.0) - glyph, 0.0, 1.0); - fragColor = outline * ubuf.styleColor; + fragColor = outline * ubuf.styleColor + step(1.0 - glyph, 1.0) * glyph * ubuf.color; } diff --git a/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag.qsb b/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag.qsb index ddceb17a94..f44b92dc28 100644 Binary files a/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag.qsb and b/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag.qsb differ -- cgit v1.2.3