summaryrefslogtreecommitdiffstats
path: root/src/Runtime/res/effectlib/distancefieldtext_dropshadow_core.vert
diff options
context:
space:
mode:
authorJere Tuliniemi <jere.tuliniemi@qt.io>2019-04-01 15:08:11 +0300
committerJere Tuliniemi <jere.tuliniemi@qt.io>2019-04-16 09:16:37 +0000
commitc6edb9c7d15843e8ab965d365099ace29e2d2049 (patch)
tree0a24f87676d342c69254e9baeedadaaf4a70e5e5 /src/Runtime/res/effectlib/distancefieldtext_dropshadow_core.vert
parent156910d1df8d3f11b72664cf0bf6b7fe800b53cf (diff)
Add distance field rendering to OpenGL runtime
The old text rendering remains in the background and is used to render clipped text, since that feature is not yet implemented for distance field fonts. Building the runtime with Qt version older than 5.12.2 also causes a fallback to the old text rendering. Depth pass rendering also needs to be redone in the future to avoid another full render pass. Task-number: QT3DS-3210 Change-Id: Ib7666c437d23ae25e1872682f010df3721476a14 Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src/Runtime/res/effectlib/distancefieldtext_dropshadow_core.vert')
-rw-r--r--src/Runtime/res/effectlib/distancefieldtext_dropshadow_core.vert54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/Runtime/res/effectlib/distancefieldtext_dropshadow_core.vert b/src/Runtime/res/effectlib/distancefieldtext_dropshadow_core.vert
new file mode 100644
index 00000000..51190577
--- /dev/null
+++ b/src/Runtime/res/effectlib/distancefieldtext_dropshadow_core.vert
@@ -0,0 +1,54 @@
+in vec3 vCoord;
+in vec2 tCoord;
+in vec4 textureBounds;
+
+out vec2 sampleCoord;
+out vec2 shadowSampleCoord;
+
+out vec2 alphas;
+out vec4 normalizedTextureBounds;
+
+uniform mat4 mvp;
+uniform mat4 modelView;
+uniform int textureWidth;
+uniform int textureHeight;
+uniform float fontScale;
+uniform vec2 shadowOffset;
+
+float thresholdFunc(float scale)
+{
+ float base = 0.5;
+ float baseDev = 0.065;
+ float devScaleMin = 0.15;
+ float devScaleMax = 0.3;
+ return base - ((clamp(scale, devScaleMin, devScaleMax) - devScaleMin)
+ / (devScaleMax - devScaleMin) * -baseDev + baseDev);
+}
+
+float spreadFunc(float scale)
+{
+ return 0.06 / scale;
+}
+
+vec2 alphaRange(float scale)
+{
+ float base = thresholdFunc(scale);
+ float range = spreadFunc(scale);
+ float alphaMin = max(0.0, base - range);
+ float alphaMax = min(base + range, 1.0);
+ return vec2(alphaMin, alphaMax);
+}
+
+void main()
+{
+ float scale = fontScale * sqrt(abs(determinant(modelView)));
+ alphas = alphaRange(scale);
+
+ vec2 textureSizeMultiplier = vec2(1.0 / textureWidth, 1.0 / textureHeight);
+
+ sampleCoord = tCoord * textureSizeMultiplier;
+ shadowSampleCoord = (tCoord - shadowOffset) * textureSizeMultiplier;
+ normalizedTextureBounds = vec4(textureBounds.xy * textureSizeMultiplier,
+ textureBounds.zw * textureSizeMultiplier);
+ gl_Position = mvp * vec4(vCoord, 1.0);
+}