Browse Source

Add Qt wobble effect to effect list

Change-Id: I8cd3abf8570b9afbd939a763720a30b230617f0f
Donald Carr 5 years ago
parent
commit
de45f68a33

+ 1 - 1
qml/3rdparty/effects/Effects.qml

@@ -3,7 +3,7 @@ pragma Singleton
 import QtQuick 2.5
 
 Item {
-    property var names: ["Emboss", "Billboard", "GaussianBlur"]
+    property var names: ["Emboss", "Billboard", "GaussianBlur", "Wobble"]
     property var components: []
     property string randomEffectText: "Random"
 

+ 9 - 0
qml/3rdparty/effects/Wobble.qml

@@ -0,0 +1,9 @@
+import QtQuick 2.8
+
+Effect {
+    property real amplitude: 0.04 * 0.05
+    property real frequency: 20
+    property real time: 0
+    NumberAnimation on time { loops: Animation.Infinite; from: 0; to: Math.PI * 2; duration: 600 }
+    fragmentShader: Qt.resolvedUrl("shaders/wobble.fsh")
+}

+ 21 - 0
qml/3rdparty/effects/shaders/wobble.fsh

@@ -0,0 +1,21 @@
+#ifdef GL_ES
+    precision mediump float;
+#else
+#   define lowp
+#   define mediump
+#   define highp
+#endif // GL_ES
+
+uniform lowp float qt_Opacity;
+uniform highp float amplitude;
+uniform highp float frequency;
+uniform highp float time;
+uniform sampler2D source;
+
+varying highp vec2 qt_TexCoord0;
+
+void main()
+{
+    highp vec2 p = sin(time + frequency * qt_TexCoord0);
+    gl_FragColor = texture2D(source, qt_TexCoord0 + amplitude * vec2(p.y, -p.x)) * qt_Opacity;
+}