aboutsummaryrefslogtreecommitdiffstats
path: root/src/effects/shaders/displace.frag
diff options
context:
space:
mode:
Diffstat (limited to 'src/effects/shaders/displace.frag')
-rw-r--r--src/effects/shaders/displace.frag27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/effects/shaders/displace.frag b/src/effects/shaders/displace.frag
new file mode 100644
index 0000000..e6ae990
--- /dev/null
+++ b/src/effects/shaders/displace.frag
@@ -0,0 +1,27 @@
+varying highp vec2 qt_TexCoord0;
+uniform highp float qt_Opacity;
+uniform lowp sampler2D source;
+uniform lowp sampler2D displacementSource;
+uniform highp float displacement;
+uniform highp float xPixel;
+uniform highp float yPixel;
+
+highp float linearstep(highp float e0, highp float e1, highp float x) {
+ return clamp((x - e0) / (e1 - e0), 0.0, 1.0);
+}
+
+void main() {
+ lowp vec4 offset = texture2D(displacementSource, qt_TexCoord0);
+ offset.xy -= vec2(0.5, 0.5);
+ offset.xy = offset.xy * step(vec2(1.0/256.0), abs(offset.xy));
+ highp vec2 tx = qt_TexCoord0 + (vec2(-offset.x, offset.y) * displacement);
+
+ lowp float e1 = linearstep(0.0, xPixel, tx.x);
+ lowp float e2 = linearstep(0.0, yPixel, tx.y);
+ lowp float e3 = 1.0 - linearstep(1.0, 1.0 + xPixel, tx.x);
+ lowp float e4 = 1.0 - linearstep(1.0, 1.0 + yPixel, tx.y);
+
+ lowp vec4 sample = texture2D(source, tx);
+ sample.rgb *= e1 * e2 * e3 * e4;
+ gl_FragColor = sample * qt_Opacity * offset.a;
+}