SsgiEffect.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Copyright (C) 2025 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. SsgiEnvEffect {
  7. id: ssgiEffect
  8. property bool indirectLightEnabled: true
  9. property real indirectLightBoost: 4.0 // 1 - 100
  10. property real bufferSizeFactor: 0.5 // 0 - 1 (leave it at 0.5, generally)
  11. property bool simulatedBounceEnabled: false
  12. property real simulatedBounceFactor: 0.5 // 0 - 1
  13. property int sampleCount: 4 // 1 - 16
  14. property real sampleRadius: 0.1 // 0.001 - 4
  15. property int sliceCount: 4 // 1 - 8
  16. property real hitThickness: 0.5 // 0.001 - 4
  17. property int debugMode: 0 // internal; needs uncommenting ENABLE_DEBUG_MODE in all the shaders
  18. readonly property TextureInput indirectAndAoSampler: TextureInput {
  19. texture: Texture {}
  20. }
  21. readonly property TextureInput blurredIndirectAndAoSampler: TextureInput {
  22. texture: Texture {}
  23. }
  24. Buffer {
  25. id: indirectAndAoBuffer
  26. name: "indirectAndAoBuffer"
  27. sizeMultiplier: ssgiEffect.bufferSizeFactor
  28. format: Buffer.RGBA16F
  29. }
  30. Buffer {
  31. id: blurredIndirectAndAoBuffer
  32. name: "blurredIndirectAndAoBuffer"
  33. sizeMultiplier: ssgiEffect.bufferSizeFactor
  34. bufferFlags: Buffer.SceneLifetime // for simulatedBounce
  35. format: Buffer.RGBA16F
  36. }
  37. Shader {
  38. id: ssgiMainShader
  39. stage: Shader.Fragment
  40. shader: "qrc:/qtquick3d_helpers/shaders/ssgi_ssilvb.frag"
  41. }
  42. Shader {
  43. id: ssgiBlurDownShader
  44. stage: Shader.Fragment
  45. shader: "qrc:/qtquick3d_helpers/shaders/ssgi_dualfilterblur_down.frag"
  46. }
  47. Shader {
  48. id: ssgiBlurUpShader
  49. stage: Shader.Fragment
  50. shader: "qrc:/qtquick3d_helpers/shaders/ssgi_dualfilterblur_up.frag"
  51. }
  52. Shader {
  53. id: ssgiComposeShader
  54. stage: Shader.Fragment
  55. shader: "qrc:/qtquick3d_helpers/shaders/ssgi_compose.frag"
  56. }
  57. Pass {
  58. id: ssaoAndIndirectPass
  59. output: indirectAndAoBuffer
  60. shaders: ssgiMainShader
  61. commands: [
  62. // for simulatedBounce
  63. BufferInput {
  64. // because it is SceneLifetime, so here this is the result from the previous frame
  65. buffer: blurredIndirectAndAoBuffer
  66. sampler: "blurredIndirectAndAoSampler"
  67. }
  68. ]
  69. }
  70. // Kawase / dual filter blur
  71. // https://community.arm.com/cfs-file/__key/communityserver-blogs-components-weblogfiles/00-00-00-20-66/siggraph2015_2D00_mmg_2D00_marius_2D00_notes.pdf
  72. Buffer {
  73. id: tempBuffer1
  74. name: "tempBuffer1"
  75. sizeMultiplier: ssgiEffect.bufferSizeFactor * 0.5
  76. format: Buffer.RGBA16F
  77. }
  78. Buffer {
  79. id: tempBuffer2
  80. name: "tempBuffer2"
  81. sizeMultiplier: ssgiEffect.bufferSizeFactor * 0.5 * 0.5
  82. format: Buffer.RGBA16F
  83. }
  84. Pass {
  85. id: indirectLightBufferBlurDownInputTo1
  86. output: tempBuffer1
  87. shaders: ssgiBlurDownShader
  88. commands: [
  89. BufferInput {
  90. buffer: indirectAndAoBuffer
  91. }
  92. ]
  93. }
  94. Pass {
  95. id: indirectLightBufferBlurDown1To2
  96. output: tempBuffer2
  97. shaders: ssgiBlurDownShader
  98. commands: [
  99. BufferInput {
  100. buffer: tempBuffer1
  101. }
  102. ]
  103. }
  104. Pass {
  105. id: indirectLightBufferBlurUp2To1
  106. output: tempBuffer1
  107. shaders: ssgiBlurUpShader
  108. commands: [
  109. BufferInput {
  110. buffer: tempBuffer2
  111. }
  112. ]
  113. }
  114. Pass {
  115. id: indirectLightBufferBlurUp1ToOutput
  116. output: blurredIndirectAndAoBuffer
  117. shaders: ssgiBlurUpShader
  118. commands: [
  119. BufferInput {
  120. buffer: tempBuffer1
  121. }
  122. ]
  123. }
  124. Pass {
  125. id: ssgiCompositionPass
  126. shaders: ssgiComposeShader
  127. commands: [
  128. BufferInput {
  129. buffer: blurredIndirectAndAoBuffer
  130. sampler: "blurredIndirectAndAoSampler"
  131. }
  132. ]
  133. }
  134. passes:
  135. [ ssaoAndIndirectPass,
  136. indirectLightBufferBlurDownInputTo1, indirectLightBufferBlurDown1To2,
  137. indirectLightBufferBlurUp2To1, indirectLightBufferBlurUp1ToOutput,
  138. ssgiCompositionPass
  139. ]
  140. }