summaryrefslogtreecommitdiffstats
path: root/res
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
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')
-rw-r--r--res/effectlib/distancefieldtext.frag4
-rw-r--r--res/effectlib/distancefieldtext_core.frag4
-rw-r--r--res/effectlib/distancefieldtext_dropshadow.frag8
-rw-r--r--res/effectlib/distancefieldtext_dropshadow_core.frag8
4 files changed, 12 insertions, 12 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;
diff --git a/res/effectlib/distancefieldtext_core.frag b/res/effectlib/distancefieldtext_core.frag
index f11dcc1..a3a25a2 100644
--- a/res/effectlib/distancefieldtext_core.frag
+++ b/res/effectlib/distancefieldtext_core.frag
@@ -6,6 +6,6 @@ uniform vec4 color;
void main()
{
float distance = texture(_qt_texture, sampleCoord).r;
- float f = fwidth(distance);
- fragOutput = color * smoothstep(0.5 - f, 0.5, distance);
+ float f = fwidth(distance) * 0.5;
+ fragOutput = color * smoothstep(0.5 - f, 0.5 + f, distance);
}
diff --git a/res/effectlib/distancefieldtext_dropshadow.frag b/res/effectlib/distancefieldtext_dropshadow.frag
index fdb68ba..2f6c9be 100644
--- a/res/effectlib/distancefieldtext_dropshadow.frag
+++ b/res/effectlib/distancefieldtext_dropshadow.frag
@@ -25,8 +25,8 @@ void main()
#ifdef use_fallback
highp float shadowAlpha = smoothstep(alphas.x, alphas.y, shadowDistance);
#else
- highp float shadowDistanceD = fwidth(shadowDistance);
- highp float shadowAlpha = smoothstep(0.5 - shadowDistanceD, 0.5, shadowDistance);
+ highp float shadowDistanceD = fwidth(shadowDistance) * 0.5;
+ highp float shadowAlpha = smoothstep(0.5 - shadowDistanceD, 0.5 + shadowDistanceD, shadowDistance);
#endif
highp vec4 shadowPixel = color * shadowColor * shadowAlpha;
@@ -38,8 +38,8 @@ void main()
#ifdef use_fallback
highp float textAlpha = smoothstep(alphas.x, alphas.y, textDistance);
#else
- highp float textDistanceD = fwidth(textDistance);
- highp float textAlpha = smoothstep(0.5 - textDistanceD, 0.5, textDistance);
+ highp float textDistanceD = fwidth(textDistance) * 0.5;
+ highp float textAlpha = smoothstep(0.5 - textDistanceD, 0.5 + textDistanceD, textDistance);
#endif
highp vec4 textPixel = color * textAlpha;
diff --git a/res/effectlib/distancefieldtext_dropshadow_core.frag b/res/effectlib/distancefieldtext_dropshadow_core.frag
index e13182e..8e8c61d 100644
--- a/res/effectlib/distancefieldtext_dropshadow_core.frag
+++ b/res/effectlib/distancefieldtext_dropshadow_core.frag
@@ -12,16 +12,16 @@ void main()
clamp(shadowSampleCoord,
normalizedTextureBounds.xy,
normalizedTextureBounds.zw)).r;
- float shadowDistanceD = fwidth(shadowDistance);
- float shadowAlpha = smoothstep(0.5 - shadowDistanceD, 0.5, shadowDistance);
+ float shadowDistanceD = fwidth(shadowDistance) * 0.5;
+ float shadowAlpha = smoothstep(0.5 - shadowDistanceD, 0.5 + shadowDistanceD, shadowDistance);
vec4 shadowPixel = color * shadowColor * shadowAlpha;
float textDistance = texture(_qt_texture,
clamp(sampleCoord,
normalizedTextureBounds.xy,
normalizedTextureBounds.zw)).r;
- float textDistanceD = fwidth(textDistance);
- float textAlpha = smoothstep(0.5 - textDistanceD, 0.5, textDistance);
+ float textDistanceD = fwidth(textDistance) * 0.5;
+ float textAlpha = smoothstep(0.5 - textDistanceD, 0.5 + textDistanceD, textDistance);
vec4 textPixel = color * textAlpha;
fragOutput = mix(shadowPixel, textPixel, textPixel.a);