tasuku

ShaderEffectItem のお勉強(1)

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