summaryrefslogtreecommitdiffstats
path: root/src/Runtime/res/effectlib/distancefieldtext_dropshadow.frag
diff options
context:
space:
mode:
authorJere Tuliniemi <jere.tuliniemi@qt.io>2019-05-20 13:12:37 +0300
committerJere Tuliniemi <jere.tuliniemi@qt.io>2019-05-20 14:12:47 +0300
commitd7bbf9d82e9f129877e6d304b527071155348c59 (patch)
tree361b362deb1752274112f63890d04c9ae8a0b6d0 /src/Runtime/res/effectlib/distancefieldtext_dropshadow.frag
parent52092eb06cb659f661d757ae6c2351e58ebbdc1b (diff)
Copy distance field shader changes to OpenGL runtime
Also fixes the OpenGL runtime to use alpha channel for the glyph texture when using ES2. Task-number: QT3DS-3343 Change-Id: Ia37c341802e504da21ebeaff6f3f1f5b50bd1bfe Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Antti Määttä <antti.maatta@qt.io>
Diffstat (limited to 'src/Runtime/res/effectlib/distancefieldtext_dropshadow.frag')
-rw-r--r--src/Runtime/res/effectlib/distancefieldtext_dropshadow.frag46
1 files changed, 32 insertions, 14 deletions
diff --git a/src/Runtime/res/effectlib/distancefieldtext_dropshadow.frag b/src/Runtime/res/effectlib/distancefieldtext_dropshadow.frag
index 94b277cd..fdb68bac 100644
--- a/src/Runtime/res/effectlib/distancefieldtext_dropshadow.frag
+++ b/src/Runtime/res/effectlib/distancefieldtext_dropshadow.frag
@@ -1,29 +1,47 @@
+#ifdef GL_OES_standard_derivatives
+# extension GL_OES_standard_derivatives : enable
+#else
+# define use_fallback
+#endif
+
varying highp vec2 sampleCoord;
-varying highp vec2 alphas;
varying highp vec2 shadowSampleCoord;
varying highp vec4 normalizedTextureBounds;
+#ifdef use_fallback
+varying highp vec2 alphas;
+#endif
+
uniform sampler2D _qt_texture;
uniform highp vec4 color;
uniform highp vec4 shadowColor;
void main()
{
- highp float shadowAlpha = smoothstep(alphas.x,
- alphas.y,
- texture2D(_qt_texture,
- clamp(shadowSampleCoord,
- normalizedTextureBounds.xy,
- normalizedTextureBounds.zw)).a);
+ highp float shadowDistance = texture2D(_qt_texture,
+ clamp(shadowSampleCoord,
+ normalizedTextureBounds.xy,
+ normalizedTextureBounds.zw)).a;
+#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);
+#endif
+
highp vec4 shadowPixel = color * shadowColor * shadowAlpha;
- highp float textAlpha = smoothstep(alphas.x,
- alphas.y,
- texture2D(_qt_texture,
- clamp(sampleCoord,
- normalizedTextureBounds.xy,
- normalizedTextureBounds.zw)).a);
- highp vec4 textPixel = color * textAlpha;
+ highp float textDistance = texture2D(_qt_texture,
+ clamp(sampleCoord,
+ normalizedTextureBounds.xy,
+ normalizedTextureBounds.zw)).a;
+#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);
+#endif
+ highp vec4 textPixel = color * textAlpha;
gl_FragColor = mix(shadowPixel, textPixel, textPixel.a);
}