MotionBlur.qml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2020 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of Qt Quick 3D.
  7. **
  8. ** $QT_BEGIN_LICENSE:GPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU
  19. ** General Public License version 3 or (at your option) any later version
  20. ** approved by the KDE Free Qt Foundation. The licenses are as published by
  21. ** the Free Software Foundation and appearing in the file LICENSE.GPL3
  22. ** included in the packaging of this file. Please review the following
  23. ** information to ensure the GNU General Public License requirements will
  24. ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
  25. **
  26. ** $QT_END_LICENSE$
  27. **
  28. ****************************************************************************/
  29. import QtQuick
  30. import QtQuick3D
  31. import QtQuick3D.Effects
  32. Effect {
  33. // there are only here to get the sampler2Ds declared in the shader
  34. readonly property TextureInput sprite: TextureInput {
  35. texture: Texture {}
  36. }
  37. readonly property TextureInput glowSampler: TextureInput {
  38. texture: Texture {}
  39. }
  40. property real fadeAmount: 0.25 // 0 - 1
  41. property real blurQuality: 0.25 // 0.1 - 1.0
  42. Shader {
  43. id: vblurVert
  44. stage: Shader.Vertex
  45. shader: "qrc:/qtquick3deffects/shaders/motionblurvertical.vert"
  46. }
  47. Shader {
  48. id: vblurFrag
  49. stage: Shader.Fragment
  50. shader: "qrc:/qtquick3deffects/shaders/motionblurvertical.frag"
  51. }
  52. Shader {
  53. id: hblurVert
  54. stage: Shader.Vertex
  55. shader: "qrc:/qtquick3deffects/shaders/motionblurhorizontal.vert"
  56. }
  57. Shader {
  58. id: hblurFrag
  59. stage: Shader.Fragment
  60. shader: "qrc:/qtquick3deffects/shaders/motionblurhorizontal.frag"
  61. }
  62. Shader {
  63. id: blend
  64. stage: Shader.Fragment
  65. shader: "qrc:/qtquick3deffects/shaders/blend.frag"
  66. }
  67. Buffer {
  68. id: glowBuffer
  69. name: "glowBuffer"
  70. format: Buffer.RGBA8
  71. textureFilterOperation: Buffer.Nearest
  72. textureCoordOperation: Buffer.ClampToEdge
  73. bufferFlags: Buffer.SceneLifetime
  74. sizeMultiplier: blurQuality
  75. }
  76. Buffer {
  77. id: tempBuffer
  78. name: "tempBuffer"
  79. format: Buffer.RGBA8
  80. textureFilterOperation: Buffer.Linear
  81. textureCoordOperation: Buffer.ClampToEdge
  82. bufferFlags: Buffer.None
  83. sizeMultiplier: blurQuality
  84. }
  85. passes: [
  86. Pass {
  87. shaders: [ hblurVert, hblurFrag ]
  88. commands: [
  89. BufferInput {
  90. // Expose the initially empty glowBuffer texture under the
  91. // sampler2D glowSampler in the shader. Note the
  92. // SceneLifetime and that the next pass writes to the same
  93. // texture (accumulate).
  94. sampler: "glowSampler"
  95. buffer: glowBuffer
  96. }
  97. ]
  98. output: tempBuffer
  99. },
  100. Pass {
  101. shaders: [ vblurVert, vblurFrag ]
  102. commands: [
  103. // the texture for tempBuffer will be INPUT in this pass
  104. BufferInput {
  105. buffer: tempBuffer
  106. }
  107. ]
  108. output: glowBuffer
  109. },
  110. Pass {
  111. shaders: blend
  112. commands: [
  113. // the texture for glowBuffer will be INPUT in this pass
  114. BufferInput {
  115. buffer: glowBuffer
  116. },
  117. // the input texture (that would normally be INPUT) for this pass is exposed to the shader as sprite
  118. BufferInput {
  119. sampler: "sprite"
  120. }
  121. ]
  122. }
  123. ]
  124. }