Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 1.0
- // http://labs.qt.nokia.com/2011/05/03/qml-shadereffectitem-on-qgraphicsview/
- import Qt.labs.shaders 1.0
- Item {
- id: root
- width: 300
- height: 300
- TextInput {
- id: url
- anchors {
- left: parent.left
- right: parent.right
- top: parent.top
- }
- height: 20
- font.pixelSize: 15
- text: "http://doc.qt.nokia.com/whitepapers/qt-whitepaper/wiki-images/demos-boxes.png"
- Keys.onReturnPressed: image.source = text
- }
- Image {
- id: image
- anchors {
- top: url.bottom
- left: parent.left
- right: parent.right
- bottom: parent.bottom
- }
- source: "http://doc.qt.nokia.com/whitepapers/qt-whitepaper/wiki-images/demos-boxes.png"
- smooth: true
- fillMode: Image.PreserveAspectFit
- }
- ShaderEffectItem {
- id: effect
- anchors.fill: image
- property variant center: Qt.point(0.5, 0.5)
- property real radius: 0.150
- property real amplitude: 0.0
- property variant source: ShaderEffectSource {
- sourceItem: image
- live: true
- hideSource: true
- smooth: true
- }
- 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
- }
- }
- MouseArea {
- anchors.fill: parent
- onPressed: effect.center = Qt.point(mouse.x / effect.width, 1.0 - mouse.y / effect.height)
- }
- 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