Swirl.qml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2015 The Qt Company Ltd.
  4. ** Contact: http://www.qt-project.org/legal
  5. **
  6. ** This file is part of the examples of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:BSD$
  9. ** You may use this file under the terms of the BSD license as follows:
  10. **
  11. ** "Redistribution and use in source and binary forms, with or without
  12. ** modification, are permitted provided that the following conditions are
  13. ** met:
  14. ** * Redistributions of source code must retain the above copyright
  15. ** notice, this list of conditions and the following disclaimer.
  16. ** * Redistributions in binary form must reproduce the above copyright
  17. ** notice, this list of conditions and the following disclaimer in
  18. ** the documentation and/or other materials provided with the
  19. ** distribution.
  20. ** * Neither the name of The Qt Company Ltd nor the names of its
  21. ** contributors may be used to endorse or promote products derived
  22. ** from this software without specific prior written permission.
  23. **
  24. **
  25. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
  36. **
  37. ** $QT_END_LICENSE$
  38. **
  39. ****************************************************************************/
  40. import QtQuick 2.5
  41. ShaderEffect {
  42. id: shader
  43. width: 400
  44. height: 300
  45. property real speed: 1
  46. property color d: Qt.rgba(Math.random() * 0.7,
  47. Math.random() * 0.5,
  48. Math.random() * 0.7,
  49. Math.random() * 0.5)
  50. property real tx
  51. NumberAnimation on tx { from: 0; to: Math.PI * 2; duration: (Math.random() * 30 + 30) * 1000 / speed; loops: Animation.Infinite }
  52. property real ty
  53. NumberAnimation on ty { from: 0; to: Math.PI * 2; duration: (Math.random() * 30 + 30) * 1000 / speed; loops: Animation.Infinite }
  54. property real tz
  55. NumberAnimation on tz { from: 0; to: Math.PI * 2; duration: (Math.random() * 30 + 30) * 1000 / speed; loops: Animation.Infinite }
  56. property real tw
  57. NumberAnimation on tw { from: 0; to: Math.PI * 2; duration: (Math.random() * 30 + 30) * 1000 / speed; loops: Animation.Infinite }
  58. property real amplitude: height / 2
  59. property variant colorTable: ShaderEffectSource { sourceItem: Rectangle { width: 4; height: 4; color: "steelblue" } }
  60. fragmentShader: "
  61. uniform lowp float qt_Opacity;
  62. uniform lowp sampler2D colorTable;
  63. varying highp vec2 qt_TexCoord0;
  64. void main() {
  65. gl_FragColor = texture2D(colorTable, qt_TexCoord0);
  66. gl_FragColor.w *= qt_Opacity;
  67. }
  68. "
  69. vertexShader: "
  70. uniform lowp vec4 d;
  71. uniform highp float tx;
  72. uniform highp float ty;
  73. uniform highp float tz;
  74. uniform highp float tw;
  75. uniform highp float amplitude;
  76. uniform highp mat4 qt_Matrix;
  77. attribute highp vec4 qt_Vertex;
  78. attribute highp vec2 qt_MultiTexCoord0;
  79. varying highp vec2 qt_TexCoord0;
  80. void main() {
  81. highp vec4 pos = qt_Vertex;
  82. highp float y1 = sin(tx + d.x * qt_MultiTexCoord0.x * 17. + 2. * d.y) + sin(ty + d.z * qt_MultiTexCoord0.x * 11. + 5. * d.w);
  83. highp float y2 = sin(tz + d.w * qt_MultiTexCoord0.x * 7. + 3. * d.z) + sin(tw + d.y * qt_MultiTexCoord0.x * 19. + 3. * d.x);
  84. pos.y += mix(y1, y2, qt_MultiTexCoord0.y) * amplitude * 0.5;
  85. gl_Position = qt_Matrix * pos;
  86. qt_TexCoord0 = qt_MultiTexCoord0;
  87. }
  88. "
  89. mesh: GridMesh { resolution: Qt.size(width / 10, 4) }
  90. }