Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 1.0
- import Qt.labs.shaders 1.0 // http://labs.qt.nokia.com/2011/05/03/qml-shadereffectitem-on-qgraphicsview/
- Item {
- id: root
- width: 300
- height: 300
- Image {
- id: image
- anchors.fill: parent
- source: "http://food.foto.ne.jp/free/resize.php?image=images/images_big/fd401360.jpg"
- smooth: true
- fillMode: Image.PreserveAspectFit
- }
- ShaderEffectItem {
- id: effect
- anchors.fill: parent
- property variant source: ShaderEffectSource {
- sourceItem: image
- live: true
- hideSource: true
- }
- MouseArea {
- anchors.fill: parent
- onPressed: effect.center = Qt.point(mouse.x / effect.width, 1.0 - mouse.y / effect.height)
- }
- property variant center: Qt.point(-1.0, -1.0)
- property real radius: width * 0.00050
- property real amplitude
- SequentialAnimation on amplitude {
- loops: Animation.Infinite
- NumberAnimation {
- easing.type: Easing.InOutSine
- from: 0.1
- to: -0.1
- }
- NumberAnimation {
- easing.type: Easing.InOutSine
- from: -0.1
- to: 0.1
- }
- }
- fragmentShader: "
- varying highp vec2 qt_TexCoord0;
- uniform lowp sampler2D source;
- uniform highp vec2 center;
- uniform highp float radius;
- uniform highp float amplitude;
- void main(void)
- {
- highp vec2 springTexCoord = qt_TexCoord0;
- highp float d = ((qt_TexCoord0.s - center.x) * (qt_TexCoord0.s - center.x) + (qt_TexCoord0.t - center.y) * (qt_TexCoord0.t - center.y)) / (radius * radius);
- if ( d < 1.0 ) {
- springTexCoord.t += amplitude * radius * (1.0 - d);
- }
- gl_FragColor = texture2D(source, springTexCoord.st);
- }
- "
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement