cells.qml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import QtQuick 2.0
  2. Item {
  3. id: root
  4. Image {
  5. id: noiseImage
  6. source: "noise.png";
  7. visible: false
  8. }
  9. ShaderEffect {
  10. id: effect
  11. anchors.fill: parent
  12. property real time
  13. property real xRes: width
  14. property real yRes: height
  15. property real aspect: xRes / yRes
  16. property real cells: 15.0
  17. property real verticalCells: cells / aspect;
  18. property real yOffset: (verticalCells % 1.0) / verticalCells * 0.5;
  19. property variant noiseTexture: noiseImage
  20. NumberAnimation {
  21. target: effect
  22. property: "time"
  23. duration: 1000 * 60 * 5
  24. from: 0
  25. to: 60 * 5
  26. loops: Animation.Infinite
  27. running: true
  28. }
  29. fragmentShader: "
  30. #ifdef GL_ES
  31. precision highp float;
  32. precision lowp sampler2D;
  33. #endif
  34. uniform highp float xRes;
  35. uniform highp float yRes;
  36. uniform highp float time;
  37. varying highp vec2 qt_TexCoord0;
  38. uniform sampler2D noiseTexture;
  39. uniform float aspect;
  40. uniform float cells;
  41. uniform float verticalCells;
  42. uniform float yOffset;
  43. void main()
  44. {
  45. vec2 screenUv = qt_TexCoord0 - vec2(0.0, yOffset);
  46. vec2 t = screenUv * vec2(cells, verticalCells);
  47. vec2 cellUv = fract(t);
  48. vec2 cellCoord = t - cellUv;
  49. vec2 normalizedCellCoord = cellCoord / cells;
  50. float noise = texture2D(noiseTexture, normalizedCellCoord + vec2(0.11)).r;
  51. // float noise2 = texture2D(noiseTexture, normalizedCellCoord - vec2(0.13)).r;
  52. float angle = noise * 30.0 + time * (0.5 + noise);
  53. float scale = 1.0 + noise * 2.0;
  54. float ca = cos(angle) * scale;
  55. float sa = sin(angle) * scale;
  56. mat2 rotate = mat2(ca, -sa,
  57. sa, ca);
  58. vec2 rotatedCellUv = rotate * (cellUv - 0.5);
  59. rotatedCellUv.x = fract(rotatedCellUv.x);
  60. float sharpness = 20.0 * scale / xRes;
  61. float v = smoothstep(0.25 - sharpness, 0.25, rotatedCellUv.x) -
  62. smoothstep(0.75 - sharpness, 0.75, rotatedCellUv.x);
  63. float dim = 0.9 - pow(length(cellUv - 0.5), 3.2) * 2.5;
  64. float borderWidth = 0.04;
  65. if (cellUv.x > 1.0 - borderWidth || cellUv.y > 1.0 - borderWidth)
  66. dim = 0.0;
  67. if (cellUv.x < borderWidth || cellUv.y < borderWidth)
  68. dim = 0.0;
  69. v *= dim;
  70. gl_FragColor = vec4(v, v, v, 1.0);
  71. }"
  72. }
  73. }