Advertisement
tasuku

ShaderEffectItem のお勉強(3)

Aug 5th, 2011
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. import QtQuick 1.0
  2. // http://labs.qt.nokia.com/2011/05/03/qml-shadereffectitem-on-qgraphicsview/
  3. import Qt.labs.shaders 1.0
  4.  
  5. Item {
  6. id: root
  7. width: 300
  8. height: 300
  9.  
  10. TextInput {
  11. id: url
  12. anchors {
  13. left: parent.left
  14. right: parent.right
  15. top: parent.top
  16. }
  17. height: 20
  18. font.pixelSize: 15
  19. text: "http://doc.qt.nokia.com/whitepapers/qt-whitepaper/wiki-images/demos-boxes.png"
  20. Keys.onReturnPressed: image.source = text
  21. }
  22.  
  23. Image {
  24. id: image
  25. anchors {
  26. top: url.bottom
  27. left: parent.left
  28. right: parent.right
  29. bottom: parent.bottom
  30. }
  31. source: "http://doc.qt.nokia.com/whitepapers/qt-whitepaper/wiki-images/demos-boxes.png"
  32. smooth: true
  33. fillMode: Image.PreserveAspectFit
  34. }
  35.  
  36. ShaderEffectItem {
  37. id: effect
  38. anchors.fill: image
  39.  
  40. property variant center: Qt.point(0.5, 0.5)
  41. property real radius: 0.150
  42. property real amplitude: 0.0
  43. property variant source: ShaderEffectSource {
  44. sourceItem: image
  45. live: true
  46. hideSource: true
  47. smooth: true
  48. }
  49.  
  50. SequentialAnimation on amplitude {
  51. loops: Animation.Infinite
  52. NumberAnimation {
  53. easing.type: Easing.InOutSine
  54. from: 0.1
  55. to: -0.1
  56. }
  57. NumberAnimation {
  58. easing.type: Easing.InOutSine
  59. from: -0.1
  60. to: 0.1
  61. }
  62. }
  63.  
  64. MouseArea {
  65. anchors.fill: parent
  66. onPressed: effect.center = Qt.point(mouse.x / effect.width, 1.0 - mouse.y / effect.height)
  67. }
  68.  
  69. fragmentShader: "
  70. varying highp vec2 qt_TexCoord0;
  71. uniform lowp sampler2D source;
  72. uniform highp vec2 center;
  73. uniform highp float radius;
  74. uniform highp float amplitude;
  75.  
  76. void main(void)
  77. {
  78. highp vec2 springTexCoord = qt_TexCoord0;
  79. 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);
  80.  
  81. if ( d < 1.0 ) {
  82. springTexCoord.t += amplitude * radius * (1.0 - d);
  83. }
  84. gl_FragColor = texture2D(source, springTexCoord.st);
  85. }
  86. "
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement