Advertisement
tasuku

ShaderEffectItem のお勉強(2)

Aug 5th, 2011
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 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. Image {
  10. id: image
  11. anchors.fill: parent
  12. source: "http://food.foto.ne.jp/free/resize.php?image=images/images_big/fd401360.jpg"
  13. smooth: true
  14. fillMode: Image.PreserveAspectFit
  15. }
  16.  
  17. ShaderEffectItem {
  18. id: effect
  19. anchors.fill: parent
  20.  
  21. property variant source: ShaderEffectSource {
  22. sourceItem: image
  23. live: true
  24. hideSource: true
  25. }
  26.  
  27. MouseArea {
  28. anchors.fill: parent
  29. onPressed: effect.center = Qt.point(mouse.x / effect.width, 1.0 - mouse.y / effect.height)
  30. }
  31.  
  32. property variant center: Qt.point(-1.0, -1.0)
  33. property real radius: width * 0.00050
  34. property real amplitude
  35.  
  36. SequentialAnimation on amplitude {
  37. loops: Animation.Infinite
  38. NumberAnimation {
  39. easing.type: Easing.InOutSine
  40. from: 0.1
  41. to: -0.1
  42. }
  43. NumberAnimation {
  44. easing.type: Easing.InOutSine
  45. from: -0.1
  46. to: 0.1
  47. }
  48. }
  49.  
  50. fragmentShader: "
  51. varying highp vec2 qt_TexCoord0;
  52. uniform lowp sampler2D source;
  53. uniform highp vec2 center;
  54. uniform highp float radius;
  55. uniform highp float amplitude;
  56.  
  57. void main(void)
  58. {
  59. highp vec2 springTexCoord = qt_TexCoord0;
  60. 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);
  61.  
  62. if ( d < 1.0 ) {
  63. springTexCoord.t += amplitude * radius * (1.0 - d);
  64. }
  65. gl_FragColor = texture2D(source, springTexCoord.st);
  66. }
  67. "
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement