summaryrefslogtreecommitdiffstats
path: root/src/Runtime/res/effectlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/Runtime/res/effectlib')
-rw-r--r--src/Runtime/res/effectlib/distancefieldtext.frag12
-rw-r--r--src/Runtime/res/effectlib/distancefieldtext.vert66
-rw-r--r--src/Runtime/res/effectlib/distancefieldtext_core.frag14
-rw-r--r--src/Runtime/res/effectlib/distancefieldtext_core.vert44
-rw-r--r--src/Runtime/res/effectlib/distancefieldtext_dropshadow.frag29
-rw-r--r--src/Runtime/res/effectlib/distancefieldtext_dropshadow.vert78
-rw-r--r--src/Runtime/res/effectlib/distancefieldtext_dropshadow_core.frag32
-rw-r--r--src/Runtime/res/effectlib/distancefieldtext_dropshadow_core.vert54
8 files changed, 329 insertions, 0 deletions
diff --git a/src/Runtime/res/effectlib/distancefieldtext.frag b/src/Runtime/res/effectlib/distancefieldtext.frag
new file mode 100644
index 00000000..efcf89e4
--- /dev/null
+++ b/src/Runtime/res/effectlib/distancefieldtext.frag
@@ -0,0 +1,12 @@
+varying highp vec2 sampleCoord;
+varying highp vec2 alphas;
+
+uniform sampler2D _qt_texture;
+uniform highp vec4 color;
+
+void main()
+{
+ gl_FragColor = color * smoothstep(alphas.x,
+ alphas.y,
+ texture2D(_qt_texture, sampleCoord).a);
+}
diff --git a/src/Runtime/res/effectlib/distancefieldtext.vert b/src/Runtime/res/effectlib/distancefieldtext.vert
new file mode 100644
index 00000000..a3feb378
--- /dev/null
+++ b/src/Runtime/res/effectlib/distancefieldtext.vert
@@ -0,0 +1,66 @@
+uniform highp mat4 mvp;
+uniform highp mat4 modelView;
+uniform highp float fontScale;
+uniform int textureWidth;
+uniform int textureHeight;
+
+attribute highp vec3 vCoord;
+attribute highp vec2 tCoord;
+
+varying highp vec2 sampleCoord;
+varying highp vec2 alphas;
+
+highp float thresholdFunc(highp float scale)
+{
+ highp float base = 0.5;
+ highp float baseDev = 0.065;
+ highp float devScaleMin = 0.15;
+ highp float devScaleMax = 0.3;
+ return base - ((clamp(scale, devScaleMin, devScaleMax) - devScaleMin)
+ / (devScaleMax - devScaleMin) * -baseDev + baseDev);
+}
+
+highp float spreadFunc(highp float scale)
+{
+ return 0.06 / scale;
+}
+
+highp vec2 alphaRange(highp float scale)
+{
+ highp float base = thresholdFunc(scale);
+ highp float range = spreadFunc(scale);
+ highp float alphaMin = max(0.0, base - range);
+ highp float alphaMax = min(base + range, 1.0);
+ return vec2(alphaMin, alphaMax);
+}
+
+highp float determinantOfSubmatrix(highp mat4 m, int col0, int col1, int row0, int row1)
+{
+ return m[col0][row0] * m[col1][row1] - m[col0][row1] * m[col1][row0];
+}
+
+highp float determinantOfSubmatrix(highp mat4 m, int col0, int col1, int col2,
+ int row0, int row1, int row2)
+{
+ highp float det = m[col0][row0] * determinantOfSubmatrix(m, col1, col2, row1, row2);
+ det -= m[col1][row0] * determinantOfSubmatrix(m, col0, col2, row1, row2);
+ det += m[col2][row0] * determinantOfSubmatrix(m, col0, col1, row1, row2);
+ return det;
+}
+
+highp float determinant(highp mat4 m)
+{
+ highp float det = m[0][0] * determinantOfSubmatrix(m, 1, 2, 3, 1, 2, 3);
+ det -= m[1][0] * determinantOfSubmatrix(m, 0, 2, 3, 1, 2, 3);
+ det += m[2][0] * determinantOfSubmatrix(m, 0, 1, 3, 1, 2, 3);
+ det -= m[3][0] * determinantOfSubmatrix(m, 0, 1, 2, 1, 2, 3);
+ return det;
+}
+
+void main()
+{
+ highp float scale = fontScale * sqrt(abs(determinant(modelView)));
+ alphas = alphaRange(scale);
+ sampleCoord = tCoord * vec2(1.0 / highp float(textureWidth), 1.0 / highp float(textureHeight));
+ gl_Position = mvp * vec4(vCoord, 1.0);
+}
diff --git a/src/Runtime/res/effectlib/distancefieldtext_core.frag b/src/Runtime/res/effectlib/distancefieldtext_core.frag
new file mode 100644
index 00000000..0f848bc1
--- /dev/null
+++ b/src/Runtime/res/effectlib/distancefieldtext_core.frag
@@ -0,0 +1,14 @@
+in vec2 sampleCoord;
+
+out vec4 fragColor;
+
+uniform sampler2D _qt_texture;
+uniform vec4 color;
+
+in vec2 alphas;
+
+void main()
+{
+ fragColor = color * smoothstep(alphas.x, alphas.y,
+ texture(_qt_texture, sampleCoord).r);
+}
diff --git a/src/Runtime/res/effectlib/distancefieldtext_core.vert b/src/Runtime/res/effectlib/distancefieldtext_core.vert
new file mode 100644
index 00000000..074a73ac
--- /dev/null
+++ b/src/Runtime/res/effectlib/distancefieldtext_core.vert
@@ -0,0 +1,44 @@
+in vec3 vCoord;
+in vec2 tCoord;
+
+out vec2 sampleCoord;
+
+out vec2 alphas;
+
+uniform mat4 mvp;
+uniform mat4 modelView;
+uniform int textureWidth;
+uniform int textureHeight;
+uniform float fontScale;
+
+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);
+ sampleCoord = tCoord * vec2(1.0 / textureWidth, 1.0 / textureHeight);
+ gl_Position = mvp * vec4(vCoord, 1.0);
+}
diff --git a/src/Runtime/res/effectlib/distancefieldtext_dropshadow.frag b/src/Runtime/res/effectlib/distancefieldtext_dropshadow.frag
new file mode 100644
index 00000000..da51c5c2
--- /dev/null
+++ b/src/Runtime/res/effectlib/distancefieldtext_dropshadow.frag
@@ -0,0 +1,29 @@
+varying highp vec2 sampleCoord;
+varying highp vec2 alphas;
+varying highp vec2 shadowSampleCoord;
+varying highp vec4 normalizedTextureBounds;
+
+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 vec4 shadowPixel = 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;
+
+ gl_FragColor = mix(shadowPixel, textPixel, textPixel.a);
+}
diff --git a/src/Runtime/res/effectlib/distancefieldtext_dropshadow.vert b/src/Runtime/res/effectlib/distancefieldtext_dropshadow.vert
new file mode 100644
index 00000000..f645eb8c
--- /dev/null
+++ b/src/Runtime/res/effectlib/distancefieldtext_dropshadow.vert
@@ -0,0 +1,78 @@
+uniform highp mat4 mvp;
+uniform highp mat4 modelView;
+uniform highp float fontScale;
+uniform int textureWidth;
+uniform int textureHeight;
+uniform highp vec2 shadowOffset;
+
+attribute highp vec3 vCoord;
+attribute highp vec2 tCoord;
+attribute highp vec4 textureBounds;
+
+varying highp vec2 sampleCoord;
+varying highp vec2 shadowSampleCoord;
+varying highp vec2 alphas;
+varying highp vec4 normalizedTextureBounds;
+
+highp float thresholdFunc(highp float scale)
+{
+ highp float base = 0.5;
+ highp float baseDev = 0.065;
+ highp float devScaleMin = 0.15;
+ highp float devScaleMax = 0.3;
+ return base - ((clamp(scale, devScaleMin, devScaleMax) - devScaleMin)
+ / (devScaleMax - devScaleMin) * -baseDev + baseDev);
+}
+
+highp float spreadFunc(highp float scale)
+{
+ return 0.06 / scale;
+}
+
+highp vec2 alphaRange(highp float scale)
+{
+ highp float base = thresholdFunc(scale);
+ highp float range = spreadFunc(scale);
+ highp float alphaMin = max(0.0, base - range);
+ highp float alphaMax = min(base + range, 1.0);
+ return vec2(alphaMin, alphaMax);
+}
+
+highp float determinantOfSubmatrix(highp mat4 m, int col0, int col1, int row0, int row1)
+{
+ return m[col0][row0] * m[col1][row1] - m[col0][row1] * m[col1][row0];
+}
+
+highp float determinantOfSubmatrix(highp mat4 m, int col0, int col1, int col2,
+ int row0, int row1, int row2)
+{
+ highp float det = m[col0][row0] * determinantOfSubmatrix(m, col1, col2, row1, row2);
+ det -= m[col1][row0] * determinantOfSubmatrix(m, col0, col2, row1, row2);
+ det += m[col2][row0] * determinantOfSubmatrix(m, col0, col1, row1, row2);
+ return det;
+}
+
+highp float determinant(highp mat4 m)
+{
+ highp float det = m[0][0] * determinantOfSubmatrix(m, 1, 2, 3, 1, 2, 3);
+ det -= m[1][0] * determinantOfSubmatrix(m, 0, 2, 3, 1, 2, 3);
+ det += m[2][0] * determinantOfSubmatrix(m, 0, 1, 3, 1, 2, 3);
+ det -= m[3][0] * determinantOfSubmatrix(m, 0, 1, 2, 1, 2, 3);
+ return det;
+}
+
+void main()
+{
+ highp float scale = fontScale * sqrt(abs(determinant(modelView)));
+ alphas = alphaRange(scale);
+
+ highp vec2 textureSizeMultiplier = vec2(1.0 / highp float(textureWidth),
+ 1.0 / float(textureHeight));
+
+ sampleCoord = tCoord * textureSizeMultiplier;
+ shadowSampleCoord = (tCoord - shadowOffset) * textureSizeMultiplier;
+ normalizedTextureBounds = highp vec4(textureBounds.xy * textureSizeMultiplier,
+ textureBounds.zw * textureSizeMultiplier);
+
+ gl_Position = mvp * vec4(vCoord, 1.0);
+}
diff --git a/src/Runtime/res/effectlib/distancefieldtext_dropshadow_core.frag b/src/Runtime/res/effectlib/distancefieldtext_dropshadow_core.frag
new file mode 100644
index 00000000..304b1874
--- /dev/null
+++ b/src/Runtime/res/effectlib/distancefieldtext_dropshadow_core.frag
@@ -0,0 +1,32 @@
+in vec2 sampleCoord;
+in vec2 shadowSampleCoord;
+in vec4 normalizedTextureBounds;
+
+out vec4 fragColor;
+
+uniform sampler2D _qt_texture;
+uniform vec4 color;
+uniform vec4 shadowColor;
+
+in vec2 alphas;
+
+void main()
+{
+ float shadowAlpha = smoothstep(alphas.x,
+ alphas.y,
+ texture(_qt_texture,
+ clamp(shadowSampleCoord,
+ normalizedTextureBounds.xy,
+ normalizedTextureBounds.zw)).r);
+ vec4 shadowPixel = shadowColor * shadowAlpha;
+
+ float textAlpha = smoothstep(alphas.x,
+ alphas.y,
+ texture(_qt_texture,
+ clamp(sampleCoord,
+ normalizedTextureBounds.xy,
+ normalizedTextureBounds.zw)).r);
+ vec4 textPixel = color * textAlpha;
+
+ fragColor = mix(shadowPixel, textPixel, textPixel.a);
+}
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);
+}