From 4be30565fd882fe412d8d40dc65c15f88a479f0f Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Mon, 29 Apr 2013 07:05:29 +0200 Subject: Another dissolve Change-Id: I2c05445a84723d742a43bca70a2a8073f9aa47e2 Reviewed-by: Gunnar Sletta --- .../Graphical Effects/effect_CustomDissolve.qml | 128 +++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 basicsuite/Graphical Effects/effect_CustomDissolve.qml (limited to 'basicsuite') diff --git a/basicsuite/Graphical Effects/effect_CustomDissolve.qml b/basicsuite/Graphical Effects/effect_CustomDissolve.qml new file mode 100644 index 0000000..ae92f9f --- /dev/null +++ b/basicsuite/Graphical Effects/effect_CustomDissolve.qml @@ -0,0 +1,128 @@ +import QtQuick 2.0 + +Item { + + + width: 700 + height: 600 + id: root + + property real inputX: 0.5; + property real feedbackX: inputX + property string nameX: "Displacement" + + property real inputY: 0.5; + property real feedbackY: effect.amplitude + property string nameY: "Amplitude" + + Rectangle { + id: sourceItem + anchors.centerIn: parent + width: text.width + 50 + height: text.height + 20 + gradient: Gradient { + GradientStop { position: 0; color: "steelblue" } + GradientStop { position: 1; color: "black" } + } + border.color: "lightsteelblue" + border.width: 2 + +//? color: "transparent" + + radius: 10 + + layer.enabled: true + layer.smooth: true + layer.sourceRect: Qt.rect(-1, -1, width + 2, height + 2); + + visible: false + + Text { + id: text + font.pixelSize: root.height * 0.08 + anchors.centerIn: parent; + text: "Code Less, Create More!" + color: "lightsteelblue" + style: Text.Raised + + } + } + + ShaderEffect { + + id: effect + + anchors.fill: sourceItem; + + property variant source: sourceItem; + + property real t: (1 + tlength) * (1 - root.inputX) - tlength; + property real tlength: 1.0 + property real amplitude: 2.0 * height * root.inputY; + + mesh: "40x4" + + vertexShader: + " + uniform highp mat4 qt_Matrix; + uniform lowp float t; + uniform lowp float tlength; + uniform highp float amplitude; + uniform lowp float qt_Opacity; + + attribute highp vec4 qt_Vertex; + attribute highp vec2 qt_MultiTexCoord0; + + varying highp vec2 vTexCoord; + varying lowp float vOpacity; + + void main() { + vTexCoord = qt_MultiTexCoord0; + + vec4 pos = qt_Vertex; + + lowp float tt = smoothstep(t, t+tlength, qt_MultiTexCoord0.x); + + vOpacity = 1.0 - tt; + + pos.y += (amplitude * (qt_MultiTexCoord0.y * 2.0 - 1.0) * (-2.0 * tt) + + 3.0 * amplitude * (qt_MultiTexCoord0.y * 2.0 - 1.0) + + amplitude * sin(0.0 + tt * 2.14152 * qt_MultiTexCoord0.x) + + amplitude * sin(0.0 + tt * 7.4567) + ) * tt; + + pos.x += amplitude * sin(6.0 + tt * 4.4567) * tt; + + gl_Position = qt_Matrix * pos; + } + " + fragmentShader: + " + uniform sampler2D source; + + uniform lowp float t; + uniform lowp float tlength; + + varying highp vec2 vTexCoord; + varying lowp float vOpacity; + + // Noise function from: http://stackoverflow.com/questions/4200224/random-noise-functions-for-glsl + float rand(vec2 n) { + return fract(sin(dot(n.xy, vec2(12.9898, 78.233))) * 43758.5453); + } + + void main() { + lowp vec4 tex = texture2D(source, vTexCoord); + + lowp float opacity = 1.0 - smoothstep(0.9, 1.0, vOpacity); + + float particlify = smoothstep(1.0 - vOpacity, 1.0, rand(vTexCoord)) * vOpacity; + + gl_FragColor = tex * mix(vOpacity, particlify, opacity); + } + + " + + } + +} -- cgit v1.2.3