summaryrefslogtreecommitdiffstats
path: root/res/effectlib/distancefieldtext.frag
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-10-07 08:44:06 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-10-08 06:10:25 +0200
commit4043a87ee65e9a2d01f56e8fd15a028fb30364bf (patch)
tree2d5d7b6f7f93088bd12eceb9e1234cfcb1e08d5e /res/effectlib/distancefieldtext.frag
parent8080e24c88e011f2bf953bf388d2eb16d7837143 (diff)
Fix excessive boldness on thin text
When the distance field curve is at 0.5, the fragment actually contains the edge of the glyph, so we shouldn't fill the pixel completely. The smooth range should rather be given by the area spanned by the fragment (approximated by the fwidth() function) and centered on the edge. The result was that glyphs would look bolder than they should, especially visible at low resolutions with thin outlines (thus it could be worked around by enabling SSAA, which would render the glyphs at a higher resolution). This is a fix for the boldness part of QT3DS-4175. For the glyph corruption, this is actually due to features of the glyphs being thinner than a pixel, in which case both fragments may sample outside the outline, and we do not get valid values back from fwidth(), which is a known draw-back of this antialiasing strategy. Task-number: QT3DS-4175 Change-Id: Ide8e190eed766d04fdccf203c4ecfedbb93c6247 Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io> Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'res/effectlib/distancefieldtext.frag')
-rw-r--r--res/effectlib/distancefieldtext.frag4
1 files changed, 2 insertions, 2 deletions
diff --git a/res/effectlib/distancefieldtext.frag b/res/effectlib/distancefieldtext.frag
index 1d83490..2236f9c 100644
--- a/res/effectlib/distancefieldtext.frag
+++ b/res/effectlib/distancefieldtext.frag
@@ -20,8 +20,8 @@ void main()
#ifdef use_fallback
highp float alpha = smoothstep(alphas.x, alphas.y, distance);
#else
- highp float f = fwidth(distance);
- highp float alpha = smoothstep(0.5 - f, 0.5, distance);
+ highp float f = fwidth(distance) * 0.5;
+ highp float alpha = smoothstep(0.5 - f, 0.5 + f, distance);
#endif
gl_FragColor = color * alpha;