MotionBlur.qml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright (C) 2020 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
  3. import QtQuick
  4. import QtQuick3D
  5. Effect {
  6. id: effectRoot
  7. // there are only here to get the sampler2Ds declared in the shader
  8. readonly property TextureInput sprite: TextureInput {
  9. texture: Texture {}
  10. }
  11. readonly property TextureInput glowSampler: TextureInput {
  12. texture: Texture {}
  13. }
  14. property real fadeAmount: 0.25 // 0 - 1
  15. property real blurQuality: 0.25 // 0.1 - 1.0
  16. Shader {
  17. id: vblurVert
  18. stage: Shader.Vertex
  19. shader: "qrc:/qtquick3deffects/shaders/motionblurvertical.vert"
  20. }
  21. Shader {
  22. id: vblurFrag
  23. stage: Shader.Fragment
  24. shader: "qrc:/qtquick3deffects/shaders/motionblurvertical.frag"
  25. }
  26. Shader {
  27. id: hblurVert
  28. stage: Shader.Vertex
  29. shader: "qrc:/qtquick3deffects/shaders/motionblurhorizontal.vert"
  30. }
  31. Shader {
  32. id: hblurFrag
  33. stage: Shader.Fragment
  34. shader: "qrc:/qtquick3deffects/shaders/motionblurhorizontal.frag"
  35. }
  36. Shader {
  37. id: blend
  38. stage: Shader.Fragment
  39. shader: "qrc:/qtquick3deffects/shaders/blend.frag"
  40. }
  41. Buffer {
  42. id: glowBuffer
  43. name: "glowBuffer"
  44. format: Buffer.RGBA8
  45. textureFilterOperation: Buffer.Nearest
  46. textureCoordOperation: Buffer.ClampToEdge
  47. bufferFlags: Buffer.SceneLifetime
  48. sizeMultiplier: effectRoot.blurQuality
  49. }
  50. Buffer {
  51. id: tempBuffer
  52. name: "tempBuffer"
  53. format: Buffer.RGBA8
  54. textureFilterOperation: Buffer.Linear
  55. textureCoordOperation: Buffer.ClampToEdge
  56. bufferFlags: Buffer.None
  57. sizeMultiplier: effectRoot.blurQuality
  58. }
  59. passes: [
  60. Pass {
  61. shaders: [ hblurVert, hblurFrag ]
  62. commands: [
  63. BufferInput {
  64. // Expose the initially empty glowBuffer texture under the
  65. // sampler2D glowSampler in the shader. Note the
  66. // SceneLifetime and that the next pass writes to the same
  67. // texture (accumulate).
  68. sampler: "glowSampler"
  69. buffer: glowBuffer
  70. }
  71. ]
  72. output: tempBuffer
  73. },
  74. Pass {
  75. shaders: [ vblurVert, vblurFrag ]
  76. commands: [
  77. // the texture for tempBuffer will be INPUT in this pass
  78. BufferInput {
  79. buffer: tempBuffer
  80. }
  81. ]
  82. output: glowBuffer
  83. },
  84. Pass {
  85. shaders: [ blend ]
  86. commands: [
  87. // the texture for glowBuffer will be INPUT in this pass
  88. BufferInput {
  89. buffer: glowBuffer
  90. },
  91. // the input texture (that would normally be INPUT) for this pass is exposed to the shader as sprite
  92. BufferInput {
  93. sampler: "sprite"
  94. }
  95. ]
  96. }
  97. ]
  98. }