DepthOfFieldBlur.qml 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (C) 2022 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
  3. import QtQuick
  4. import QtQuick3D
  5. import QtQuick3D.Helpers.impl
  6. DepthOfFieldEffect {
  7. readonly property TextureInput sourceSampler: TextureInput {
  8. texture: Texture {}
  9. }
  10. property real focusDistance: 600
  11. property real focusRange: 100
  12. property real blurAmount: 4
  13. Shader {
  14. id: downsampleVert
  15. stage: Shader.Vertex
  16. shader: "qrc:/qtquick3d_helpers/shaders/downsample.vert"
  17. }
  18. Shader {
  19. id: downsampleFrag
  20. stage: Shader.Fragment
  21. shader: "qrc:/qtquick3d_helpers/shaders/downsample.frag"
  22. }
  23. Shader {
  24. id: blurVert
  25. stage: Shader.Vertex
  26. shader: "qrc:/qtquick3d_helpers/shaders/depthoffieldblur.vert"
  27. }
  28. Shader {
  29. id: blurFrag
  30. stage: Shader.Fragment
  31. shader: "qrc:/qtquick3d_helpers/shaders/depthoffieldblur.frag"
  32. }
  33. Buffer {
  34. id: downsampleBuffer
  35. name: "downsampleBuffer"
  36. format: Buffer.RGBA16F
  37. textureFilterOperation: Buffer.Linear
  38. textureCoordOperation: Buffer.ClampToEdge
  39. sizeMultiplier: 0.5
  40. }
  41. passes: [
  42. Pass {
  43. shaders: [ downsampleVert, downsampleFrag ]
  44. output: downsampleBuffer
  45. },
  46. Pass {
  47. shaders: [ blurVert, blurFrag ]
  48. commands: [
  49. // INPUT is the texture for downsampleBuffer
  50. BufferInput {
  51. buffer: downsampleBuffer
  52. },
  53. // the actual input texture is exposed as sourceSampler
  54. BufferInput {
  55. sampler: "sourceSampler"
  56. }
  57. ]
  58. }
  59. ]
  60. }