FastMaskedBlur.qml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2017 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the Qt Graphical Effects module.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  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 Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. import QtQuick 2.12
  40. import QtGraphicalEffects.private 1.12
  41. Item {
  42. id: rootItem
  43. property variant source
  44. property variant maskSource
  45. property real blur: 0.0
  46. property bool transparentBorder: false
  47. property bool cached: false
  48. SourceProxy {
  49. id: sourceProxy
  50. input: rootItem.source
  51. }
  52. SourceProxy {
  53. id: maskSourceProxy
  54. input: rootItem.maskSource
  55. }
  56. ShaderEffectSource {
  57. id: cacheItem
  58. anchors.fill: shaderItem
  59. visible: rootItem.cached
  60. sourceItem: shaderItem
  61. live: true
  62. hideSource: visible
  63. smooth: rootItem.blur > 0
  64. }
  65. property string __internalBlurVertexShader: "qrc:/qt-project.org/imports/QtGraphicalEffects/shaders/fastblur_internal.vert"
  66. property string __internalBlurFragmentShader: "qrc:/qt-project.org/imports/QtGraphicalEffects/shaders/fastblur_internal.frag"
  67. ShaderEffect {
  68. id: mask0
  69. property variant source: maskSourceProxy.output
  70. anchors.fill: parent
  71. visible: false
  72. smooth: true
  73. }
  74. ShaderEffectSource {
  75. id: masklevel1
  76. width: Math.ceil(shaderItem.width / 32) * 32
  77. height: Math.ceil(shaderItem.height / 32) * 32
  78. sourceItem: mask0
  79. hideSource: rootItem.visible
  80. sourceRect: transparentBorder ? Qt.rect(-64, -64, shaderItem.width, shaderItem.height) : Qt.rect(0, 0, 0, 0)
  81. visible: false
  82. smooth: rootItem.blur > 0
  83. }
  84. ShaderEffect {
  85. id: level0
  86. property variant source: sourceProxy.output
  87. anchors.fill: parent
  88. visible: false
  89. smooth: true
  90. }
  91. ShaderEffectSource {
  92. id: level1
  93. width: Math.ceil(shaderItem.width / 32) * 32
  94. height: Math.ceil(shaderItem.height / 32) * 32
  95. sourceItem: level0
  96. hideSource: rootItem.visible
  97. sourceRect: transparentBorder ? Qt.rect(-64, -64, shaderItem.width, shaderItem.height) : Qt.rect(0, 0, 0, 0)
  98. visible: false
  99. smooth: rootItem.blur > 0
  100. }
  101. ShaderEffect {
  102. id: effect1
  103. property variant source: level1
  104. property real yStep: 1/height
  105. property real xStep: 1/width
  106. anchors.fill: level2
  107. visible: false
  108. smooth: true
  109. vertexShader: __internalBlurVertexShader
  110. fragmentShader: __internalBlurFragmentShader
  111. }
  112. ShaderEffectSource {
  113. id: level2
  114. width: level1.width / 2
  115. height: level1.height / 2
  116. sourceItem: effect1
  117. hideSource: rootItem.visible
  118. visible: false
  119. smooth: true
  120. }
  121. ShaderEffect {
  122. id: effect2
  123. property variant source: level2
  124. property real yStep: 1/height
  125. property real xStep: 1/width
  126. anchors.fill: level3
  127. visible: false
  128. smooth: true
  129. vertexShader: __internalBlurVertexShader
  130. fragmentShader: __internalBlurFragmentShader
  131. }
  132. ShaderEffectSource {
  133. id: level3
  134. width: level2.width / 2
  135. height: level2.height / 2
  136. sourceItem: effect2
  137. hideSource: rootItem.visible
  138. visible: false
  139. smooth: true
  140. }
  141. ShaderEffect {
  142. id: effect3
  143. property variant source: level3
  144. property real yStep: 1/height
  145. property real xStep: 1/width
  146. anchors.fill: level4
  147. visible: false
  148. smooth: true
  149. vertexShader: __internalBlurVertexShader
  150. fragmentShader: __internalBlurFragmentShader
  151. }
  152. ShaderEffectSource {
  153. id: level4
  154. width: level3.width / 2
  155. height: level3.height / 2
  156. sourceItem: effect3
  157. hideSource: rootItem.visible
  158. visible: false
  159. smooth: true
  160. }
  161. ShaderEffect {
  162. id: effect4
  163. property variant source: level4
  164. property real yStep: 1/height
  165. property real xStep: 1/width
  166. anchors.fill: level5
  167. visible: false
  168. smooth: true
  169. vertexShader: __internalBlurVertexShader
  170. fragmentShader: __internalBlurFragmentShader
  171. }
  172. ShaderEffectSource {
  173. id: level5
  174. width: level4.width / 2
  175. height: level4.height / 2
  176. sourceItem: effect4
  177. hideSource: rootItem.visible
  178. visible: false
  179. smooth: true
  180. }
  181. ShaderEffect {
  182. id: effect5
  183. property variant source: level5
  184. property real yStep: 1/height
  185. property real xStep: 1/width
  186. anchors.fill: level6
  187. visible: false
  188. smooth: true
  189. vertexShader: __internalBlurVertexShader
  190. fragmentShader: __internalBlurFragmentShader
  191. }
  192. ShaderEffectSource {
  193. id: level6
  194. width: level5.width / 2
  195. height: level5.height / 2
  196. sourceItem: effect5
  197. hideSource: rootItem.visible
  198. visible: false
  199. smooth: true
  200. }
  201. ShaderEffect {
  202. id: shaderItem
  203. property variant mask: masklevel1
  204. property variant source1: level1
  205. property variant source2: level2
  206. property variant source3: level3
  207. property variant source4: level4
  208. property variant source5: level5
  209. property variant source6: level6
  210. property real lod: Math.sqrt(rootItem.blur) * 1.2 - 0.2
  211. property real weight1
  212. property real weight2
  213. property real weight3
  214. property real weight4
  215. property real weight5
  216. property real weight6
  217. x: transparentBorder ? -64 : 0
  218. y: transparentBorder ? -64 : 0
  219. width: transparentBorder ? parent.width + 128 : parent.width
  220. height: transparentBorder ? parent.height + 128 : parent.height
  221. fragmentShader: "qrc:/qt-project.org/imports/QtGraphicalEffects/shaders/fastmaskedblur.frag"
  222. }
  223. }