@woosh/meep-engine 3.60.5 → 3.60.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (376) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/build/bundle-worker-terrain.js +1 -1
  3. package/package.json +1 -1
  4. package/src/core/binary/BitSet.d.ts.map +1 -1
  5. package/src/core/binary/BitSet.js +2 -1
  6. package/src/{format/image/avif/av1/util → core/binary/operations}/ceil_log2.d.ts +2 -2
  7. package/src/core/binary/operations/ceil_log2.d.ts.map +1 -0
  8. package/src/{format/image/avif/av1/util → core/binary/operations}/ceil_log2.js +18 -18
  9. package/src/core/binary/zstd/ZstdReverseBitReader.d.ts.map +1 -1
  10. package/src/core/binary/zstd/ZstdReverseBitReader.js +225 -223
  11. package/src/core/binary/zstd/zstd_fse.d.ts.map +1 -1
  12. package/src/core/binary/zstd/zstd_fse.js +267 -265
  13. package/src/core/binary/zstd/zstd_huffman.d.ts.map +1 -1
  14. package/src/core/binary/zstd/zstd_huffman.js +246 -244
  15. package/src/core/bvh2/binary/2/BinaryUint32BVH.d.ts.map +1 -1
  16. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +8 -2
  17. package/src/core/bvh2/bvh3/ebvh_optimize_treelet.d.ts.map +1 -1
  18. package/src/core/bvh2/bvh3/ebvh_optimize_treelet.js +8 -7
  19. package/src/core/collection/PairUint32Map.d.ts.map +1 -1
  20. package/src/core/collection/PairUint32Map.js +2 -2
  21. package/src/core/collection/Uint32Map.d.ts.map +1 -1
  22. package/src/core/collection/Uint32Map.js +2 -4
  23. package/src/core/collection/heap/FibonacciHeap.d.ts.map +1 -1
  24. package/src/core/collection/heap/FibonacciHeap.js +2 -1
  25. package/src/core/geom/2d/r-tree/StaticR2Tree.d.ts.map +1 -1
  26. package/src/core/geom/2d/r-tree/StaticR2Tree.js +8 -2
  27. package/src/core/geom/3d/shape/util/mesh_compute_triangle_edge_flags.d.ts.map +1 -1
  28. package/src/core/geom/3d/shape/util/mesh_compute_triangle_edge_flags.js +2 -3
  29. package/src/engine/graphics/texture/atlas/TextureAtlas.d.ts.map +1 -1
  30. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -14
  31. package/src/engine/graphics/texture/atlas/sprite_atlas_border.d.ts.map +1 -1
  32. package/src/engine/graphics/texture/atlas/sprite_atlas_border.js +70 -69
  33. package/src/engine/graphics/texture/reflection/convolve_equirectangular_reflection.d.ts.map +1 -1
  34. package/src/engine/graphics/texture/reflection/convolve_equirectangular_reflection.js +2 -1
  35. package/src/engine/graphics3/GPUParticleEmitterSystem.d.ts.map +1 -1
  36. package/src/engine/graphics3/GPUParticleEmitterSystem.js +2 -1
  37. package/src/engine/graphics3/decal/GPUDecalRenderer.d.ts.map +1 -1
  38. package/src/engine/graphics3/decal/GPUDecalRenderer.js +2 -1
  39. package/src/engine/graphics3/decal/chunk_decal_record.d.ts +14 -0
  40. package/src/engine/graphics3/decal/chunk_decal_record.d.ts.map +1 -0
  41. package/src/engine/graphics3/decal/chunk_decal_record.js +44 -0
  42. package/src/engine/graphics3/decal/shader_cluster_assign_decals.d.ts.map +1 -1
  43. package/src/engine/graphics3/decal/shader_cluster_assign_decals.js +2 -15
  44. package/src/engine/graphics3/decal/shader_cull_decals_frustum.d.ts.map +1 -1
  45. package/src/engine/graphics3/decal/shader_cull_decals_frustum.js +3 -16
  46. package/src/engine/graphics3/decal/shader_decal_composite.d.ts.map +1 -1
  47. package/src/engine/graphics3/decal/shader_decal_composite.js +3 -23
  48. package/src/engine/graphics3/terrain/TERRAIN_MATERIAL_TEMPLATE.d.ts.map +1 -1
  49. package/src/engine/graphics3/terrain/TERRAIN_MATERIAL_TEMPLATE.js +2 -1
  50. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  51. package/src/engine/physics/queries/shape_cast.js +2 -2
  52. package/src/format/image/avif/av1/decode/decode_palette.js +442 -442
  53. package/src/format/image/avif/av1/entropy/SymbolWriter.d.ts.map +1 -1
  54. package/src/format/image/avif/av1/entropy/SymbolWriter.js +2 -1
  55. package/src/generation/foliage/material/foliage_tile.d.ts.map +1 -1
  56. package/src/generation/foliage/material/foliage_tile.js +2 -1
  57. package/src/shade/device/mock/SoftwareGPUDevice.d.ts.map +1 -1
  58. package/src/shade/device/mock/SoftwareGPUDevice.js +6 -13
  59. package/src/shade/playground/caldera/main.js +3 -2
  60. package/src/shade/playground/probe_clipmap/README.md +2 -1
  61. package/src/shade/playground/probe_clipmap/index.html +7 -2
  62. package/src/shade/playground/probe_clipmap/main.d.ts.map +1 -1
  63. package/src/shade/playground/probe_clipmap/main.js +17 -7
  64. package/src/shade/playground/sh_exponential/sh_exp_playground_shaders.d.ts.map +1 -1
  65. package/src/shade/playground/sh_exponential/sh_exp_playground_shaders.js +7 -13
  66. package/src/shade/playground/vgeo_scene/main.js +2 -1
  67. package/src/shade/playground/vsm/VSMDebugOverlay.d.ts.map +1 -1
  68. package/src/shade/playground/vsm/VSMDebugOverlay.js +3 -1
  69. package/src/shade/renderer/Renderer.d.ts +11 -0
  70. package/src/shade/renderer/Renderer.d.ts.map +1 -1
  71. package/src/shade/renderer/Renderer.js +43 -1
  72. package/src/shade/renderer/fluid/GPUFluidCascade.d.ts +3 -3
  73. package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +1 -1
  74. package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts +6 -6
  75. package/src/shade/renderer/fluid/pressure/GPUFluidPressureSolve.d.ts +1 -1
  76. package/src/shade/renderer/fluid/pressure/shader_fluid_mg_coarsest.d.ts.map +1 -1
  77. package/src/shade/renderer/fluid/pressure/shader_fluid_mg_coarsest.js +5 -4
  78. package/src/shade/renderer/fluid/pressure/shader_fluid_mg_residual_restrict.d.ts.map +1 -1
  79. package/src/shade/renderer/fluid/pressure/shader_fluid_mg_residual_restrict.js +168 -166
  80. package/src/shade/renderer/fluid/pressure/shader_fluid_mg_smooth.d.ts.map +1 -1
  81. package/src/shade/renderer/fluid/pressure/shader_fluid_mg_smooth.js +221 -219
  82. package/src/shade/renderer/fluid/query/GPUFluidQueries.d.ts +1 -1
  83. package/src/shade/renderer/fow/shader_fog_of_war.d.ts.map +1 -1
  84. package/src/shade/renderer/fow/shader_fog_of_war.js +8 -19
  85. package/src/shade/renderer/geometry/sdf/GPUGeometrySDFManager.d.ts +26 -43
  86. package/src/shade/renderer/geometry/sdf/GPUGeometrySDFManager.d.ts.map +1 -1
  87. package/src/shade/renderer/geometry/sdf/GPUGeometrySDFManager.js +115 -123
  88. package/src/shade/renderer/geometry/sdf/MeshSDFLayout.d.ts.map +1 -1
  89. package/src/shade/renderer/geometry/sdf/MeshSDFLayout.js +2 -1
  90. package/src/shade/renderer/geometry/sdf/cards/GPUMeshCardSets.d.ts +20 -2
  91. package/src/shade/renderer/geometry/sdf/cards/GPUMeshCardSets.d.ts.map +1 -1
  92. package/src/shade/renderer/geometry/sdf/cards/GPUMeshCardSets.js +66 -2
  93. package/src/shade/renderer/geometry/virtual/proxy/vgeo_proxy_triangle_limit.d.ts +19 -0
  94. package/src/shade/renderer/geometry/virtual/proxy/vgeo_proxy_triangle_limit.d.ts.map +1 -0
  95. package/src/shade/renderer/geometry/virtual/proxy/vgeo_proxy_triangle_limit.js +25 -0
  96. package/src/shade/renderer/geometry/virtual/runtime/GPUVirtualGeometryRuntime.d.ts.map +1 -1
  97. package/src/shade/renderer/geometry/virtual/runtime/GPUVirtualGeometryRuntime.js +2 -1
  98. package/src/shade/renderer/geometry/virtual/runtime/VGeoResidency.d.ts.map +1 -1
  99. package/src/shade/renderer/geometry/virtual/runtime/VGeoResidency.js +2 -1
  100. package/src/shade/renderer/geometry/virtual/runtime/VirtualGeometry.d.ts +15 -0
  101. package/src/shade/renderer/geometry/virtual/runtime/VirtualGeometry.d.ts.map +1 -1
  102. package/src/shade/renderer/geometry/virtual/runtime/VirtualGeometry.js +38 -0
  103. package/src/shade/renderer/geometry/virtual/sdf/VGeoSDFProxies.d.ts +28 -59
  104. package/src/shade/renderer/geometry/virtual/sdf/VGeoSDFProxies.d.ts.map +1 -1
  105. package/src/shade/renderer/geometry/virtual/sdf/VGeoSDFProxies.js +84 -789
  106. package/src/shade/renderer/global_illumination/brick4/gpu/encoding/v1/chunk_brick4_sh3_color_decode_from_storage.d.ts.map +1 -1
  107. package/src/shade/renderer/global_illumination/brick4/gpu/encoding/v1/chunk_brick4_sh3_color_decode_from_storage.js +10 -31
  108. package/src/shade/renderer/global_illumination/brick4/gpu/encoding/v1/chunk_brick4_sh3_color_encode_to_storage.d.ts.map +1 -1
  109. package/src/shade/renderer/global_illumination/brick4/gpu/encoding/v1/chunk_brick4_sh3_color_encode_to_storage.js +9 -15
  110. package/src/shade/renderer/global_illumination/clipmap/shader_debug_clipmap.d.ts +2 -1
  111. package/src/shade/renderer/global_illumination/clipmap/shader_debug_clipmap.d.ts.map +1 -1
  112. package/src/shade/renderer/global_illumination/clipmap/shader_debug_clipmap.js +6 -5
  113. package/src/shade/renderer/global_illumination/probe/octahedral/convolve/graph_reduce_atlas_to_sh.d.ts.map +1 -1
  114. package/src/shade/renderer/global_illumination/probe/octahedral/convolve/graph_reduce_atlas_to_sh.js +2 -1
  115. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts +15 -3
  116. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts.map +1 -1
  117. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.js +168 -18
  118. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSceneHolds.d.ts +2 -1
  119. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSceneHolds.d.ts.map +1 -1
  120. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSceneHolds.js +2 -1
  121. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.d.ts +98 -57
  122. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.d.ts.map +1 -1
  123. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.js +168 -77
  124. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUBrickClipmap.d.ts +4 -2
  125. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUBrickClipmap.d.ts.map +1 -1
  126. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUBrickClipmap.js +27 -12
  127. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap.d.ts.map +1 -1
  128. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap.js +12 -7
  129. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts.map +1 -1
  130. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.js +8 -2
  131. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/chunk_mesh_brick_instance.d.ts +2 -2
  132. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/chunk_mesh_brick_instance.js +2 -2
  133. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/chunk_mesh_brick_walk.d.ts.map +1 -1
  134. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/chunk_mesh_brick_walk.js +5 -2
  135. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/shader_mesh_brick_batch.js +1 -1
  136. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/shader_mesh_brick_gather.d.ts.map +1 -1
  137. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/shader_mesh_brick_gather.js +5 -3
  138. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/shader_mesh_brick_resolve.js +1 -1
  139. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_free.d.ts.map +1 -1
  140. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_free.js +1 -1
  141. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_movers_command.d.ts.map +1 -1
  142. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_movers_command.js +4 -2
  143. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_scroll.d.ts.map +1 -1
  144. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_scroll.js +1 -1
  145. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_store.d.ts.map +1 -1
  146. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_store.js +1 -1
  147. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_take.d.ts.map +1 -1
  148. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_take.js +3 -1
  149. package/src/shade/renderer/global_illumination/probe_clipmap/debug/graph_probe_clipmap_debug_mesh_cards.js +2 -2
  150. package/src/shade/renderer/global_illumination/probe_clipmap/probe/GPUProbeClipmap.d.ts +114 -41
  151. package/src/shade/renderer/global_illumination/probe_clipmap/probe/GPUProbeClipmap.d.ts.map +1 -1
  152. package/src/shade/renderer/global_illumination/probe_clipmap/probe/GPUProbeClipmap.js +424 -207
  153. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP.d.ts +34 -25
  154. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP.d.ts.map +1 -1
  155. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP.js +41 -31
  156. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP_RESAMPLING.d.ts +7 -5
  157. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP_RESAMPLING.d.ts.map +1 -1
  158. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP_RESAMPLING.js +7 -5
  159. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapHitWants.d.ts +47 -0
  160. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapHitWants.d.ts.map +1 -0
  161. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapHitWants.js +84 -0
  162. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapScreenWants.d.ts +48 -0
  163. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapScreenWants.d.ts.map +1 -0
  164. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapScreenWants.js +101 -0
  165. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap.d.ts +58 -4
  166. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap.d.ts.map +1 -1
  167. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap.js +127 -30
  168. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_cage.d.ts +18 -7
  169. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_cage.d.ts.map +1 -1
  170. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_cage.js +39 -13
  171. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_pick.d.ts +29 -8
  172. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_pick.d.ts.map +1 -1
  173. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_pick.js +112 -56
  174. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_resample.d.ts +19 -0
  175. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_resample.d.ts.map +1 -0
  176. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_resample.js +35 -0
  177. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_sample_radiance.d.ts.map +1 -1
  178. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_sample_radiance.js +9 -3
  179. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_want.d.ts +3 -3
  180. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_want.js +5 -5
  181. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_accumulate.d.ts +8 -12
  182. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_accumulate.d.ts.map +1 -1
  183. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_accumulate.js +23 -56
  184. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_admit.d.ts +0 -3
  185. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_admit.d.ts.map +1 -1
  186. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_admit.js +11 -15
  187. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_bounce.d.ts +26 -0
  188. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_bounce.d.ts.map +1 -0
  189. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_bounce.js +173 -0
  190. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_candidate.d.ts +32 -0
  191. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_candidate.d.ts.map +1 -0
  192. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_candidate.js +166 -0
  193. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_due.d.ts +3 -4
  194. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_due.d.ts.map +1 -1
  195. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_due.js +3 -4
  196. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_guide.d.ts.map +1 -1
  197. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_guide.js +3 -1
  198. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_light.d.ts +6 -12
  199. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_light.d.ts.map +1 -1
  200. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_light.js +15 -65
  201. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_order.d.ts.map +1 -1
  202. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_order.js +7 -2
  203. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_project.d.ts +4 -4
  204. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_project.d.ts.map +1 -1
  205. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_project.js +24 -17
  206. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_publish.d.ts +7 -5
  207. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_publish.d.ts.map +1 -1
  208. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_publish.js +18 -10
  209. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_ray_layout.d.ts +2 -2
  210. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_ray_layout.d.ts.map +1 -1
  211. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_ray_layout.js +9 -5
  212. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_relocate.d.ts +3 -0
  213. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_relocate.d.ts.map +1 -1
  214. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_relocate.js +9 -6
  215. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_resample.d.ts +1 -1
  216. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_resample.d.ts.map +1 -1
  217. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_resample.js +16 -16
  218. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_resample_rays.d.ts +36 -0
  219. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_resample_rays.d.ts.map +1 -0
  220. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_resample_rays.js +233 -0
  221. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_schedule.d.ts.map +1 -1
  222. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_schedule.js +7 -5
  223. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_shade.d.ts.map +1 -1
  224. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_shade.js +5 -3
  225. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace.d.ts.map +1 -1
  226. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace.js +10 -4
  227. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace_command.d.ts +2 -1
  228. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace_command.d.ts.map +1 -1
  229. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace_command.js +12 -6
  230. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want.d.ts +1 -2
  231. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want.d.ts.map +1 -1
  232. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want.js +5 -6
  233. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_hits.d.ts +14 -18
  234. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_hits.d.ts.map +1 -1
  235. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_hits.js +25 -35
  236. package/src/shade/renderer/gpu_primitive/WEBGPU_GUARANTEED_MAX_UNIFORM_BUFFER_BINDING_SIZE.d.ts +13 -0
  237. package/src/shade/renderer/gpu_primitive/WEBGPU_GUARANTEED_MAX_UNIFORM_BUFFER_BINDING_SIZE.d.ts.map +1 -0
  238. package/src/shade/renderer/gpu_primitive/WEBGPU_GUARANTEED_MAX_UNIFORM_BUFFER_BINDING_SIZE.js +12 -0
  239. package/src/shade/renderer/gpu_primitive/hash_table/cpu_build_hash_table.d.ts +27 -2
  240. package/src/shade/renderer/gpu_primitive/hash_table/cpu_build_hash_table.d.ts.map +1 -1
  241. package/src/shade/renderer/gpu_primitive/hash_table/cpu_build_hash_table.js +62 -6
  242. package/src/shade/renderer/gpu_primitive/indirect/IndirectComputeCommandBuildPass.d.ts.map +1 -1
  243. package/src/shade/renderer/gpu_primitive/indirect/IndirectComputeCommandBuildPass.js +10 -19
  244. package/src/shade/renderer/gpu_primitive/indirect/chunk_folded_dispatch.d.ts.map +1 -1
  245. package/src/shade/renderer/gpu_primitive/indirect/chunk_folded_dispatch.js +6 -3
  246. package/src/shade/renderer/hiz/hzb_pick_alignment.d.ts.map +1 -1
  247. package/src/shade/renderer/hiz/hzb_pick_alignment.js +149 -148
  248. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_environment_cells.d.ts.map +1 -1
  249. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_environment_cells.js +4 -2
  250. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_log_floor.d.ts.map +1 -1
  251. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_log_floor.js +6 -5
  252. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_project.d.ts.map +1 -1
  253. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_project.js +3 -1
  254. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_reference_reflectance.d.ts.map +1 -1
  255. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_reference_reflectance.js +3 -1
  256. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_solve.d.ts.map +1 -1
  257. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_solve.js +3 -1
  258. package/src/shade/renderer/light/world_cluster/WORLD_LIGHT_CLUSTER.d.ts +0 -5
  259. package/src/shade/renderer/light/world_cluster/WORLD_LIGHT_CLUSTER.d.ts.map +1 -1
  260. package/src/shade/renderer/light/world_cluster/WORLD_LIGHT_CLUSTER.js +0 -7
  261. package/src/shade/renderer/light/world_cluster/graph_build_world_light_clusters.d.ts +15 -2
  262. package/src/shade/renderer/light/world_cluster/graph_build_world_light_clusters.d.ts.map +1 -1
  263. package/src/shade/renderer/light/world_cluster/graph_build_world_light_clusters.js +51 -16
  264. package/src/shade/renderer/light/world_cluster/shader_world_cluster_assign_lights.d.ts.map +1 -1
  265. package/src/shade/renderer/light/world_cluster/shader_world_cluster_assign_lights.js +3 -2
  266. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
  267. package/src/shade/renderer/material/GPUMaterialManager.d.ts +4 -1
  268. package/src/shade/renderer/material/GPUMaterialManager.d.ts.map +1 -1
  269. package/src/shade/renderer/material/GPUMaterialManager.js +5 -8
  270. package/src/shade/renderer/postprocess/dof/raymarch/chunk_dof_lds_coc_cache.d.ts +17 -0
  271. package/src/shade/renderer/postprocess/dof/raymarch/chunk_dof_lds_coc_cache.d.ts.map +1 -0
  272. package/src/shade/renderer/postprocess/dof/raymarch/chunk_dof_lds_coc_cache.js +81 -0
  273. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_raymarch_compute.d.ts.map +1 -1
  274. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_raymarch_compute.js +5 -48
  275. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_slice_compute.d.ts.map +1 -1
  276. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_slice_compute.js +4 -44
  277. package/src/shade/renderer/postprocess/gtao/GTAO.d.ts +7 -3
  278. package/src/shade/renderer/postprocess/gtao/GTAO.d.ts.map +1 -1
  279. package/src/shade/renderer/postprocess/gtao/GTAO.js +26 -13
  280. package/src/shade/renderer/postprocess/gtao/ao_reproject_shader.d.ts +14 -0
  281. package/src/shade/renderer/postprocess/gtao/ao_reproject_shader.d.ts.map +1 -1
  282. package/src/shade/renderer/postprocess/gtao/ao_reproject_shader.js +196 -68
  283. package/src/shade/renderer/postprocess/gtao/chunk_integrate_lighting_sample.d.ts.map +1 -1
  284. package/src/shade/renderer/postprocess/gtao/chunk_integrate_lighting_sample.js +4 -1
  285. package/src/shade/renderer/postprocess/gtao/fragment_shader_gtao.d.ts.map +1 -1
  286. package/src/shade/renderer/postprocess/gtao/fragment_shader_gtao.js +42 -28
  287. package/src/shade/renderer/postprocess/gtao/fragment_shader_gtao_with_irradiance.d.ts.map +1 -1
  288. package/src/shade/renderer/postprocess/gtao/fragment_shader_gtao_with_irradiance.js +430 -414
  289. package/src/shade/renderer/postprocess/gtao/shader_gtao_spatial_denoise.d.ts +16 -0
  290. package/src/shade/renderer/postprocess/gtao/shader_gtao_spatial_denoise.d.ts.map +1 -0
  291. package/src/shade/renderer/postprocess/gtao/shader_gtao_spatial_denoise.js +156 -0
  292. package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
  293. package/src/shade/renderer/postprocess/nss/chunk_nss_luma_derivative.d.ts.map +1 -1
  294. package/src/shade/renderer/postprocess/nss/chunk_nss_luma_derivative.js +5 -7
  295. package/src/shade/renderer/postprocess/nss/chunk_nss_tonemap.d.ts +17 -0
  296. package/src/shade/renderer/postprocess/nss/chunk_nss_tonemap.d.ts.map +1 -0
  297. package/src/shade/renderer/postprocess/nss/chunk_nss_tonemap.js +56 -0
  298. package/src/shade/renderer/postprocess/nss/shader_nss_postprocess.d.ts.map +1 -1
  299. package/src/shade/renderer/postprocess/nss/shader_nss_postprocess.js +2 -22
  300. package/src/shade/renderer/postprocess/nss/shader_nss_preprocess.d.ts.map +1 -1
  301. package/src/shade/renderer/postprocess/nss/shader_nss_preprocess.js +2 -13
  302. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.d.ts.map +1 -1
  303. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.js +10 -13
  304. package/src/shade/renderer/rasterize/expand/bucket/RASTERIZATION_BUCKET_LIMIT.d.ts.map +1 -1
  305. package/src/shade/renderer/rasterize/expand/bucket/RASTERIZATION_BUCKET_LIMIT.js +39 -38
  306. package/src/shade/renderer/rasterize/expand/mesh/shader_prefix_sum_to_command.d.ts.map +1 -1
  307. package/src/shade/renderer/rasterize/expand/mesh/shader_prefix_sum_to_command.js +7 -12
  308. package/src/shade/renderer/scene/GPUSceneContext.d.ts +2 -2
  309. package/src/shade/renderer/scene/GPUSceneContext.js +5 -5
  310. package/src/shade/renderer/shader/chunk/clipmap/CLIPMAP_LEVEL_STRUCT.d.ts +8 -6
  311. package/src/shade/renderer/shader/chunk/clipmap/CLIPMAP_LEVEL_STRUCT.d.ts.map +1 -1
  312. package/src/shade/renderer/shader/chunk/clipmap/CLIPMAP_LEVEL_STRUCT.js +10 -7
  313. package/src/shade/renderer/shader/chunk/clipmap/chunk_clipmap_key.d.ts +16 -0
  314. package/src/shade/renderer/shader/chunk/clipmap/chunk_clipmap_key.d.ts.map +1 -0
  315. package/src/shade/renderer/shader/chunk/clipmap/chunk_clipmap_key.js +35 -0
  316. package/src/shade/renderer/shader/chunk/clipmap/chunk_clipmap_select_finest.d.ts +5 -2
  317. package/src/shade/renderer/shader/chunk/clipmap/chunk_clipmap_select_finest.d.ts.map +1 -1
  318. package/src/shade/renderer/shader/chunk/clipmap/chunk_clipmap_select_finest.js +27 -18
  319. package/src/shade/renderer/shader/chunk/spherical_harmonics/chunk_sh2_color_get_irradiance_at.d.ts.map +1 -1
  320. package/src/shade/renderer/shader/chunk/spherical_harmonics/chunk_sh2_color_get_irradiance_at.js +5 -15
  321. package/src/shade/renderer/shader/chunk/spherical_harmonics/chunk_sh3_convolve_with_cosine_kernel.d.ts.map +1 -1
  322. package/src/shade/renderer/shader/chunk/spherical_harmonics/chunk_sh3_convolve_with_cosine_kernel.js +5 -19
  323. package/src/shade/renderer/shader/chunk/spherical_harmonics/dering/chunk_sh3_windowing.d.ts.map +1 -1
  324. package/src/shade/renderer/shader/chunk/spherical_harmonics/dering/chunk_sh3_windowing.js +3 -22
  325. package/src/shade/renderer/shadow/map/ShadowmapDrawSelector.d.ts.map +1 -1
  326. package/src/shade/renderer/shadow/map/ShadowmapDrawSelector.js +2 -1
  327. package/src/shade/renderer/volumetrics/chunk_volumetrics_sun_shadow_group_list.d.ts.map +1 -1
  328. package/src/shade/renderer/volumetrics/chunk_volumetrics_sun_shadow_group_list.js +154 -152
  329. package/src/shade/renderer/volumetrics/irradiance_clipmap/GPUIrradianceClipmap.d.ts.map +1 -1
  330. package/src/shade/renderer/volumetrics/irradiance_clipmap/GPUIrradianceClipmap.js +2 -1
  331. package/src/shade/renderer/volumetrics/irradiance_clipmap/IRRADIANCE_CLIPMAP.d.ts +3 -1
  332. package/src/shade/renderer/volumetrics/irradiance_clipmap/IRRADIANCE_CLIPMAP.d.ts.map +1 -1
  333. package/src/shade/renderer/volumetrics/irradiance_clipmap/IRRADIANCE_CLIPMAP.js +4 -3
  334. package/src/shade/renderer/volumetrics/irradiance_clipmap/IRRADIANCE_CLIPMAP_STRUCT.d.ts +7 -1
  335. package/src/shade/renderer/volumetrics/irradiance_clipmap/IRRADIANCE_CLIPMAP_STRUCT.d.ts.map +1 -1
  336. package/src/shade/renderer/volumetrics/irradiance_clipmap/IRRADIANCE_CLIPMAP_STRUCT.js +54 -47
  337. package/src/shade/renderer/volumetrics/irradiance_clipmap/chunk_irradiance_clipmap_sample.d.ts.map +1 -1
  338. package/src/shade/renderer/volumetrics/irradiance_clipmap/chunk_irradiance_clipmap_sample.js +371 -370
  339. package/src/shade/renderer/water/GPUWaterRenderer.d.ts.map +1 -1
  340. package/src/shade/renderer/water/GPUWaterRenderer.js +2 -1
  341. package/src/shade/renderer/water/query/GPUWaterQueries.d.ts +1 -1
  342. package/src/shade/renderer/water/surface/lod/shader_water_lod.d.ts.map +1 -1
  343. package/src/shade/renderer/water/surface/lod/shader_water_lod.js +12 -14
  344. package/src/shade/renderer/water/surface/particles/GPUWaterParticles.d.ts.map +1 -1
  345. package/src/shade/renderer/water/surface/particles/GPUWaterParticles.js +2 -9
  346. package/src/shade/renderer/water/surface/particles/chunk_water_particle.d.ts.map +1 -1
  347. package/src/shade/renderer/water/surface/particles/chunk_water_particle.js +2 -1
  348. package/src/shade/renderer/wind/WIND_FIELD.d.ts +3 -1
  349. package/src/shade/renderer/wind/WIND_FIELD.d.ts.map +1 -1
  350. package/src/shade/renderer/wind/WIND_FIELD.js +4 -3
  351. package/src/shade/renderer/wind/WIND_FIELD_STRUCT.d.ts +8 -2
  352. package/src/shade/renderer/wind/WIND_FIELD_STRUCT.d.ts.map +1 -1
  353. package/src/shade/renderer/wind/WIND_FIELD_STRUCT.js +11 -4
  354. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.d.ts +2 -2
  355. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.d.ts.map +1 -1
  356. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.js +13 -4
  357. package/src/shade/util/texture_mip_extent.d.ts.map +1 -1
  358. package/src/shade/util/texture_mip_extent.js +88 -87
  359. package/src/shade/wgsl/emulator/WGSLLanguageCore.d.ts.map +1 -1
  360. package/src/shade/wgsl/emulator/WGSLLanguageCore.js +9 -7
  361. package/src/format/image/avif/av1/util/ceil_log2.d.ts.map +0 -1
  362. package/src/shade/renderer/geometry/virtual/sdf/VGEO_SDF.d.ts +0 -47
  363. package/src/shade/renderer/geometry/virtual/sdf/VGEO_SDF.d.ts.map +0 -1
  364. package/src/shade/renderer/geometry/virtual/sdf/VGEO_SDF.js +0 -80
  365. package/src/shade/renderer/geometry/virtual/sdf/shader_vgeo_sdf_collect.d.ts +0 -16
  366. package/src/shade/renderer/geometry/virtual/sdf/shader_vgeo_sdf_collect.d.ts.map +0 -1
  367. package/src/shade/renderer/geometry/virtual/sdf/shader_vgeo_sdf_collect.js +0 -67
  368. package/src/shade/renderer/geometry/virtual/sdf/shader_vgeo_sdf_decode.d.ts +0 -17
  369. package/src/shade/renderer/geometry/virtual/sdf/shader_vgeo_sdf_decode.d.ts.map +0 -1
  370. package/src/shade/renderer/geometry/virtual/sdf/shader_vgeo_sdf_decode.js +0 -145
  371. package/src/shade/renderer/geometry/virtual/sdf/shader_vgeo_sdf_traverse.d.ts +0 -12
  372. package/src/shade/renderer/geometry/virtual/sdf/shader_vgeo_sdf_traverse.d.ts.map +0 -1
  373. package/src/shade/renderer/geometry/virtual/sdf/shader_vgeo_sdf_traverse.js +0 -105
  374. package/src/shade/renderer/shader/chunk/color/chunk_hash_squirrel3.d.ts +0 -1
  375. package/src/shade/renderer/shader/chunk/color/chunk_hash_squirrel3.d.ts.map +0 -1
  376. package/src/shade/renderer/shader/chunk/color/chunk_hash_squirrel3.js +0 -0
@@ -1,414 +1,430 @@
1
- import { BlendState } from "../../../descriptor/blend/BlendState.js";
2
- import { CAMERA_UNIFORM_STRUCT } from "../../camera/CAMERA_UNIFORM_STRUCT.js";
3
- import { DEPTH_STENCIL_FOREGROUND_ONLY } from "../../depth/DEPTH_STENCIL_FOREGROUND_ONLY.js";
4
- import { chunk_direction_view_to_world } from "../../shader/chunk/camera/chunk_direction_view_to_world.js";
5
- import { chunk_direction_world_to_view } from "../../shader/chunk/camera/chunk_direction_world_to_view.js";
6
- import { chunk_project_position_from_depth } from "../../shader/chunk/camera/chunk_project_position_from_depth.js";
7
- import { chunk_rgbe9995_encode } from "../../shader/chunk/color/rgbe9995/chunk_rgbe9995_encode.js";
8
- import { chunk_get_view_space_depth } from "../../shader/chunk/depth/chunk_get_view_space_depth.js";
9
- import { chunk_mat4_extract_position } from "../../shader/chunk/geometry/mat4/chunk_mat4_extract_position.js";
10
- import { chunk_decode_g_buffer_normal } from "../../shader/chunk/geometry/normal/chunk_decode_g_buffer_normal.js";
11
- import { chunk_encode_g_buffer_normal } from "../../shader/chunk/geometry/normal/chunk_encode_g_buffer_normal.js";
12
- import { chunk_v3_matrix4_rotate } from "../../shader/chunk/geometry/vec3/chunk_v3_matrix4_rotate.js";
13
- import { chunk_fast_acos } from "../../shader/chunk/math/fast/chunk_fast_acos.js";
14
- import { PI_DECLARATION } from "../../shader/chunk/math/PI_DECLARATION.js";
15
- import { PI_HALF_DECLARATION } from "../../shader/chunk/math/PI_HALF_DECLARATION.js";
16
- import { chunk_spatio_temporal_noise_r2_64 } from "../../shader/chunk/noise/chunk_spatio_temporal_noise_r2_64.js";
17
- import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
18
- import { ImageShader } from "../../shader/ImageShader.js";
19
- import { ShaderResourceSetDescriptor } from "../../shader/resource/ShaderResourceSetDescriptor.js";
20
- import { ShaderDescriptor } from "../../shader/ShaderDescriptor.js";
21
- import { HILBERT_R2_INDEX_TEXTURE } from "../../texture/noise/HILBERT_R2_INDEX_TEXTURE.js";
22
- import { BLACK_PIXEL_TEXTURE } from "../../texture/util/BLACK_PIXEL_TEXTURE.js";
23
- import { SAMPLER_NEAREST } from "../../texture/SAMPLER_LINEAR_UPSCALE.js";
24
- import { chunk_is_background } from "../../shader/chunk/depth/chunk_is_background.js";
25
- import { chunk_gtao_compute_mip_level } from "./chunk_gtao_compute_mip_level.js";
26
- import { chunk_gtao_sample_depth } from "./chunk_gtao_sample_depth.js";
27
- import { chunk_integrate_bent_normal_fast } from "./chunk_integrate_bent_normal_fast.js";
28
- import { chunk_horizon_integrate_lighting_sample } from "./chunk_integrate_lighting_sample.js";
29
- import {
30
- GTAO_EFFECT_FALLOFF_RANGE,
31
- GTAO_EFFECT_RADIUS,
32
- GTAO_QUALITY_PROFILES,
33
- GTAO_QUALITY_TYPE
34
- } from "./GTAO_CONSTANTS.js";
35
- import { GTAO_RENDER_SETTINGS } from "./GTAO_RENDER_SETTINGS.js";
36
-
37
- const resources = new ShaderResourceSetDescriptor();
38
-
39
- // see fragment_shader_gtao — the same per-pass settings, carried as immediate data
40
- resources.setImmediate("settings", GTAO_RENDER_SETTINGS);
41
- resources.createGroup()
42
- .addTexture("tDepth")
43
- .addTexture("tHZB")
44
- .addSampler("sPoint", "non-filtering", SAMPLER_NEAREST)
45
- .addTexture("tNormal", "uint")
46
- .addTexture("tColor", "unfilterable-float", "2d", false, BLACK_PIXEL_TEXTURE)
47
- .addTexture("tNoise", "uint", "2d", false, HILBERT_R2_INDEX_TEXTURE)
48
- .addUniform("camera", CAMERA_UNIFORM_STRUCT)
49
- ;
50
-
51
- /**
52
- * One step below the AO-only shader's Medium, because every sample here also integrates incoming
53
- * radiance. A deliberate difference, unlike the ones this fork used to carry by accident.
54
- * @type {{slices:number,steps:number}}
55
- */
56
- const QUALITY_SETTINGS = GTAO_QUALITY_PROFILES[GTAO_QUALITY_TYPE.Low];
57
-
58
- // this is our own thickness heuristic that relies on sooner discarding samples behind the center
59
- const GTAO_DEFAULT_THIN_OCCLUDER_COMPENSATION = 0.0;
60
-
61
- /*
62
- based on https://github.com/GameTechDev/XeGTAO/tree/e7698f874e90f2516fca26c696ec3cd2c70e505a
63
- */
64
- const body = CodeChunk.from(
65
- //language=WGSL
66
- `
67
- const scale = 1.0;
68
-
69
- const thinOccluderCompensation = ${GTAO_DEFAULT_THIN_OCCLUDER_COMPENSATION};
70
-
71
- // small crevices more important than big surfaces
72
- const sampleDistributionPower = 2.0;
73
-
74
- const SLICE_COUNT = ${QUALITY_SETTINGS.slices};
75
-
76
- const STEPS = ${QUALITY_SETTINGS.steps};
77
-
78
- struct Output{
79
- @location(0) visibility: vec2<f32>, // first 2 moment
80
- @location(1) bent_normal: vec2<u32>, // octahedral encoding
81
- @location(2) irradiance: u32, // rgbe9995
82
- }
83
-
84
- @fragment
85
- fn main(
86
- @builtin(position) coord: vec4<f32>,
87
- @location(0) uv: vec2<f32>,
88
- ) -> Output {
89
-
90
- // fadeout precompute optimisation
91
- const falloffRange = ${GTAO_EFFECT_FALLOFF_RANGE} * ${GTAO_EFFECT_RADIUS};
92
-
93
- const falloffFrom = ${GTAO_EFFECT_RADIUS} * (1.0 - ${GTAO_EFFECT_FALLOFF_RANGE});
94
- const falloffMul = -1.0 / ( falloffRange );
95
- const falloffAdd = falloffFrom / ( falloffRange ) + 1.0;
96
-
97
- let texel_position_u32 = vec2<u32>(coord.xy);
98
-
99
- let ViewportSize = textureDimensions(tDepth);
100
- let ViewportPixelSize = 1. / vec2<f32>(ViewportSize);
101
-
102
- var device_depth = textureLoad(tDepth, texel_position_u32, 0).r;
103
-
104
- // NOTE: no need to reject based on depth, already handled via depthStencil
105
-
106
- var viewspaceZ = get_view_space_depth(device_depth, camera);
107
-
108
- // Move center pixel slightly towards camera to avoid imprecision artifacts due to depth buffer imprecision; offset depends on depth texture format used
109
- viewspaceZ *= 0.99999; // this is good for FP32 depth buffer
110
-
111
- let position_ws = project_position_from_depth(uv, device_depth, camera.view_projection_matrix_inverse );
112
- let view_position_ws = mat4_extract_position(camera.view_matrix_inverse);
113
- let view_direction_ws = normalize(view_position_ws - position_ws);
114
-
115
- let view_normal_ws = decode_g_buffer_normal(textureLoad(tNormal, texel_position_u32, 0).xy); // shading normal
116
- let view_normal_vs = direction_world_to_view(view_normal_ws, camera);
117
-
118
- let noiseTexel = spatio_temporal_noise_r2_64(texel_position_u32, settings.frame_index, tNoise);
119
-
120
- let noiseSample = noiseTexel.x;
121
- let noiseSlice = noiseTexel.y;
122
-
123
- // quality settings / tweaks / hacks
124
- const pixelTooCloseThreshold = 1.3; // if the offset is under approx pixel size (pixelTooCloseThreshold), push it out to the minimum distance
125
-
126
- // approx viewspace pixel size at pixCoord; approximation of NDCToViewspace( normalizedScreenPos.xy + consts.ViewportPixelSize.xy, pixCenterPos.z ).xy - pixCenterPos.xy;
127
- // device_depth_to_view_space.z = 1/a = aspect * tan(fovY/2) = tan(fovX/2), pairs with horizontal pixel size.
128
- // factor of 2 converts a single uv-step (= 1 pixel) into the matching ndc-step (range 2 wide).
129
- // This read .w — tan(fovY/2) — with no factor of 2, i.e. 2*aspect too small, 3.56x at 16:9, which
130
- // put every AO sample that much further out than the effect radius asked for.
131
- let NDCToViewMul_x_PixelSize = 2.0 * camera.device_depth_to_view_space.z * ViewportPixelSize.x;
132
- let pixelDirRBViewspaceSizeAtCenterZ = viewspaceZ * NDCToViewMul_x_PixelSize;
133
-
134
- let screenspaceRadius = abs( ${GTAO_EFFECT_RADIUS} / pixelDirRBViewspaceSizeAtCenterZ);
135
-
136
- // fade out for small screen radii
137
- var visibility = 0.0;
138
- var bent_normal:vec3<f32>;
139
- var lighting: vec3<f32>;
140
- var lighting_weight_total = 0.0;
141
-
142
- // this is the min distance to start sampling from to avoid sampling from the center pixel (no useful data obtained from sampling center pixel)
143
- let minS = pixelTooCloseThreshold / screenspaceRadius;
144
-
145
- const INV_SLICE_COUNT = 1.0 / f32(SLICE_COUNT);
146
-
147
- for (var slice = 0; slice < SLICE_COUNT; slice++) {
148
-
149
- let sliceK = ( f32(slice) + noiseSlice ) * INV_SLICE_COUNT;
150
-
151
- // lines 5,6 from the paper
152
- let phi = sliceK * PI; // slice angle
153
-
154
- let cosPhi = cos(phi);
155
- let sinPhi = sin(phi);
156
-
157
- let omega = vec2(cosPhi, -sinPhi) * screenspaceRadius;
158
-
159
- // line 8 from the paper
160
- let sliceViewDir = vec3(cosPhi, sinPhi, 0.0);
161
- let sliceWorldDir = v3_matrix4_rotate(sliceViewDir, camera.view_matrix_inverse);
162
-
163
- // line 9 from the paper
164
- // NOTE: optimized with FMA, readability suffers
165
- let orthoWorldDir = fma( vec3( -dot(sliceWorldDir, view_direction_ws) ), view_direction_ws, sliceWorldDir );
166
-
167
- // line 10 from the paper
168
- // axisVec is orthogonal to sliceViewDir and viewVec, used to define projectedNormal
169
- let axisVec = normalize( cross(orthoWorldDir, view_direction_ws) );
170
-
171
- // line 11 from paper
172
- let projectedWorldNormal = fma( -axisVec, vec3( dot(view_normal_ws, axisVec) ), view_normal_ws );
173
-
174
- // line 13 from the paper
175
- let signNorm = sign( dot( orthoWorldDir, projectedWorldNormal ) );
176
-
177
- // line 14 from the paper
178
- var projectedNormalVecLength = length(projectedWorldNormal);
179
- let norm_cos = saturate( dot( projectedWorldNormal, view_direction_ws ) / projectedNormalVecLength );
180
-
181
- // line 15 from the paper
182
- let n = signNorm * fast_acos(norm_cos);
183
-
184
- // this is a lower weight target; not using -1 as in the original paper because it is under horizon, so a 'weight' has different meaning based on the normal
185
- let lowHorizonCos0 = cos(n + PI_HALF);
186
- let lowHorizonCos1 = -lowHorizonCos0; // cos(n - PI_HALF);
187
-
188
- // lines 17, 18 from the paper, manually unrolled the 'side' loop
189
- var horizonCos0 = lowHorizonCos0; // -1
190
- var horizonCos1 = lowHorizonCos1; // -1
191
-
192
- const INV_STEPS = 1.0 / f32(STEPS);
193
-
194
- // Calculate lighting integrant factors correctly in view space.
195
- let light_integrant_front = 0.5 * vec2(dot(view_normal_vs.xy, sliceViewDir.xy), view_normal_vs.z);
196
- // The back-side integrant has a flipped X component because the slice direction is flipped.
197
- let light_integrant_back = vec2(-light_integrant_front.x, light_integrant_front.y);
198
-
199
- var sliceLighting: vec3<f32>;
200
-
201
- for (var step_index = 0; step_index < STEPS; step_index++) {
202
-
203
- // R1 sequence (http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/)
204
- // Standard multiplier is 0.6180339887498948482 = ( 1 / GOLDEN_RATION )
205
- let stepBaseNoise = f32(slice + step_index * STEPS) * 0.6180339887498948482;
206
-
207
- let stepNoise = fract(noiseSample + stepBaseNoise);
208
-
209
- // approx line 20 from the paper, with added noise
210
- var s = ( f32(step_index) + stepNoise ) * INV_STEPS;
211
-
212
- // additional distribution modifier
213
- s = pow( s, sampleDistributionPower );
214
-
215
- // avoid sampling center pixel
216
- s += minS;
217
-
218
- // approx lines 21-22 from the paper, unrolled
219
- var sampleOffset = s * omega;
220
-
221
- // omega = vec2(cosPhi, -sinPhi) * screenspaceRadius has length screenspaceRadius
222
- let sampleOffsetLength = s * screenspaceRadius;
223
- let mipLevel = gtao_compute_mip_level(sampleOffsetLength);
224
-
225
- // Snap to pixel center (more correct direction math, avoids artifacts due to sampling pos not matching depth texel center - messes up slope - but adds other
226
- // artifacts due to them being pushed off the slice). Also use full precision for high res cases.
227
- sampleOffset = round( sampleOffset ) * ViewportPixelSize;
228
-
229
- let sampleScreenPos0 = uv + sampleOffset;
230
-
231
- let SZ0 = gtao_sample_depth(sampleScreenPos0, mipLevel, camera);
232
- let samplePos0 = project_position_from_depth(sampleScreenPos0, SZ0, camera.view_projection_matrix_inverse);
233
-
234
- let sampleScreenPos1 = uv - sampleOffset;
235
- let SZ1 = gtao_sample_depth(sampleScreenPos1, mipLevel, camera);
236
- let samplePos1 = project_position_from_depth(sampleScreenPos1, SZ1, camera.view_projection_matrix_inverse);
237
-
238
- let sampleDelta0 = (samplePos0 - position_ws); // using lpfloat for sampleDelta causes precision issues
239
- let sampleDelta1 = (samplePos1 - position_ws); // using lpfloat for sampleDelta causes precision issues
240
-
241
- let sampleDist0 = length( sampleDelta0 );
242
- let sampleDist1 = length( sampleDelta1 );
243
-
244
- // approx lines 23, 24 from the paper, unrolled
245
- let sampleHorizonVec0 = sampleDelta0 / sampleDist0;
246
- let sampleHorizonVec1 = sampleDelta1 / sampleDist1;
247
-
248
- let weight0 = saturate( fma(sampleDist0, falloffMul, falloffAdd) );
249
- let weight1 = saturate( fma(sampleDist1, falloffMul, falloffAdd) );
250
-
251
- // sample horizon cos
252
- var shc0 = dot( sampleHorizonVec0, view_direction_ws );
253
- var shc1 = dot( sampleHorizonVec1, view_direction_ws );
254
-
255
- // discard unwanted samples
256
- shc0 = mix( lowHorizonCos0, shc0, weight0 ); // this would be more correct but too expensive: cos(lerp( acos(lowHorizonCos0), acos(shc0), weight0 ));
257
- shc1 = mix( lowHorizonCos1, shc1, weight1 ); // this would be more correct but too expensive: cos(lerp( acos(lowHorizonCos1), acos(shc1), weight1 ));
258
-
259
- if(shc0 > horizonCos0 && !is_background(SZ0) ){
260
-
261
- let s0 = horizon_integrate_lighting_sample(
262
- sampleScreenPos0,
263
- view_normal_ws, // ref_normal
264
- sampleHorizonVec0, // ref_direction
265
- horizonCos0, // h0 (previous horizon)
266
- shc0, // h1 (new horizon)
267
- light_integrant_back
268
- );
269
-
270
- sliceLighting += s0;
271
- }
272
-
273
- if(shc1 > horizonCos1 && !is_background(SZ1) ){
274
-
275
- let s1 = horizon_integrate_lighting_sample(
276
- sampleScreenPos1,
277
- view_normal_ws, // ref_normal
278
- sampleHorizonVec1, // ref_direction
279
- horizonCos1, // h0 (previous horizon)
280
- shc1, // h1 (new horizon)
281
- light_integrant_front
282
- );
283
-
284
- sliceLighting += s1;
285
- }
286
-
287
- // this is a version where thicknessHeuristic is completely disabled
288
- horizonCos0 = max( horizonCos0, shc0 );
289
- horizonCos1 = max( horizonCos1, shc1 );
290
-
291
- }
292
-
293
- // line ~27, unrolled
294
- let h0 = -fast_acos(horizonCos1);
295
- let h1 = fast_acos(horizonCos0);
296
-
297
- let norm_sin = sin(n);
298
- let norm_sin2 = 2.0 * norm_sin;
299
-
300
- let iarc0 = ( fma( h0 , norm_sin2, norm_cos ) - cos( fma( 2.0, h0, - n)) ) * 0.25;
301
- let iarc1 = ( fma( h1 , norm_sin2, norm_cos ) - cos( fma( 2.0, h1, - n)) ) * 0.25;
302
-
303
- // Slight overdarkening on high slopes is compensated by tilting projected length toward 1.
304
- // In the training set, 0.05 is close (PSNR 21.34) to disabled (PSNR 21.45).
305
- // Scoped to the visibility branch so bent normals keep their unfudged slice weighting — this
306
- // used to assign back into projectedNormalVecLength, so the bent-normal accumulation below got
307
- // the fudged weight too.
308
- let visibilityProjLength = mix( projectedNormalVecLength, 1, 0.05 );
309
-
310
- let localVisibility = visibilityProjLength * ( iarc0 + iarc1 );
311
-
312
- visibility += localVisibility;
313
-
314
- // unfudged, like the bent normal below: the fudge corrects the visibility integral only
315
- sliceLighting *= projectedNormalVecLength;
316
-
317
- lighting += sliceLighting;
318
-
319
- // see "Algorithm 2 Extension that computes bent normals b."
320
- let slice_tangent_ws = normalize(orthoWorldDir);
321
- let local_bent_ts = integrate_bent_normal(
322
- horizonCos1,
323
- horizonCos0,
324
- norm_cos,
325
- norm_sin,
326
- );
327
-
328
- let t0 = local_bent_ts.x;
329
- let t1 = local_bent_ts.y;
330
-
331
- var slice_bent_normal_ws = slice_tangent_ws * t0 + view_direction_ws * t1;
332
-
333
- bent_normal = fma(slice_bent_normal_ws, vec3(projectedNormalVecLength), bent_normal);
334
- }
335
-
336
- visibility *= INV_SLICE_COUNT;
337
-
338
- visibility = pow(visibility, scale);
339
-
340
- // disallow total occlusion (which wouldn't make any sense anyhow since pixel is visible but also helps with packing bent normals)
341
- visibility = max(0.03, visibility);
342
-
343
- bent_normal = normalize(bent_normal);
344
-
345
- lighting *= PI * INV_SLICE_COUNT;
346
-
347
- var out: Output;
348
- out.visibility = vec2(visibility, visibility * visibility);
349
- out.bent_normal = encode_g_buffer_normal( bent_normal );
350
- out.irradiance = rgbe9995_encode( lighting );
351
-
352
- return out;
353
- }
354
- `, [
355
- chunk_get_view_space_depth,
356
- PI_DECLARATION,
357
- PI_HALF_DECLARATION,
358
-
359
- chunk_decode_g_buffer_normal,
360
- chunk_encode_g_buffer_normal,
361
- chunk_spatio_temporal_noise_r2_64,
362
-
363
- chunk_fast_acos,
364
-
365
- chunk_direction_world_to_view,
366
- chunk_direction_view_to_world,
367
- chunk_is_background,
368
- chunk_mat4_extract_position,
369
- chunk_project_position_from_depth,
370
- chunk_v3_matrix4_rotate,
371
- chunk_integrate_bent_normal_fast,
372
- chunk_gtao_compute_mip_level,
373
- chunk_gtao_sample_depth,
374
-
375
- //
376
- chunk_rgbe9995_encode,
377
- chunk_horizon_integrate_lighting_sample,
378
- ]);
379
-
380
- export const fragment_shader_gtao_with_irradiance = new ImageShader({
381
- descriptor: ShaderDescriptor.from(
382
- {
383
- label: "GTAO",
384
- resources,
385
- body
386
- },
387
- ),
388
- depthStencil: DEPTH_STENCIL_FOREGROUND_ONLY,
389
- targets: [
390
- {
391
- label: "Occlusion",
392
- // first 2 moments of visibility
393
- format: "rg16float",
394
- clearValue: [1, 1], // Stores visibility, so 1 == not occluded
395
- blend: BlendState.from({
396
- color: {
397
- operation: "add",
398
- srcFactor: "one",
399
- dstFactor: "zero",
400
- }
401
- })
402
- },
403
- {
404
- label: "Bent Normals",
405
- // Direction is encoded with octahedral
406
- format: "rg16uint",
407
- },
408
- {
409
- label: "Irradiance",
410
- // encoded as RGBE9995
411
- format:"r32uint"
412
- }
413
- ]
414
- });
1
+ import { BlendState } from "../../../descriptor/blend/BlendState.js";
2
+ import { CAMERA_UNIFORM_STRUCT } from "../../camera/CAMERA_UNIFORM_STRUCT.js";
3
+ import { DEPTH_STENCIL_FOREGROUND_ONLY } from "../../depth/DEPTH_STENCIL_FOREGROUND_ONLY.js";
4
+ import { chunk_direction_view_to_world } from "../../shader/chunk/camera/chunk_direction_view_to_world.js";
5
+ import { chunk_project_position_from_depth } from "../../shader/chunk/camera/chunk_project_position_from_depth.js";
6
+ import { chunk_rgbe9995_encode } from "../../shader/chunk/color/rgbe9995/chunk_rgbe9995_encode.js";
7
+ import { chunk_get_view_space_depth } from "../../shader/chunk/depth/chunk_get_view_space_depth.js";
8
+ import { chunk_mat4_extract_position } from "../../shader/chunk/geometry/mat4/chunk_mat4_extract_position.js";
9
+ import { chunk_decode_g_buffer_normal } from "../../shader/chunk/geometry/normal/chunk_decode_g_buffer_normal.js";
10
+ import { chunk_encode_g_buffer_normal } from "../../shader/chunk/geometry/normal/chunk_encode_g_buffer_normal.js";
11
+ import { chunk_v3_matrix4_rotate } from "../../shader/chunk/geometry/vec3/chunk_v3_matrix4_rotate.js";
12
+ import { chunk_fast_acos } from "../../shader/chunk/math/fast/chunk_fast_acos.js";
13
+ import { PI_DECLARATION } from "../../shader/chunk/math/PI_DECLARATION.js";
14
+ import { PI_HALF_DECLARATION } from "../../shader/chunk/math/PI_HALF_DECLARATION.js";
15
+ import { chunk_spatio_temporal_noise_r2_64 } from "../../shader/chunk/noise/chunk_spatio_temporal_noise_r2_64.js";
16
+ import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
17
+ import { ImageShader } from "../../shader/ImageShader.js";
18
+ import { ShaderResourceSetDescriptor } from "../../shader/resource/ShaderResourceSetDescriptor.js";
19
+ import { ShaderDescriptor } from "../../shader/ShaderDescriptor.js";
20
+ import { HILBERT_R2_INDEX_TEXTURE } from "../../texture/noise/HILBERT_R2_INDEX_TEXTURE.js";
21
+ import { BLACK_PIXEL_TEXTURE } from "../../texture/util/BLACK_PIXEL_TEXTURE.js";
22
+ import { SAMPLER_NEAREST } from "../../texture/SAMPLER_LINEAR_UPSCALE.js";
23
+ import { chunk_is_background } from "../../shader/chunk/depth/chunk_is_background.js";
24
+ import { chunk_gtao_compute_mip_level } from "./chunk_gtao_compute_mip_level.js";
25
+ import { chunk_gtao_sample_depth } from "./chunk_gtao_sample_depth.js";
26
+ import { chunk_integrate_bent_normal_fast } from "./chunk_integrate_bent_normal_fast.js";
27
+ import { chunk_horizon_integrate_lighting_sample } from "./chunk_integrate_lighting_sample.js";
28
+ import {
29
+ GTAO_EFFECT_FALLOFF_RANGE,
30
+ GTAO_EFFECT_RADIUS,
31
+ GTAO_QUALITY_PROFILES,
32
+ GTAO_QUALITY_TYPE
33
+ } from "./GTAO_CONSTANTS.js";
34
+ import { GTAO_RENDER_SETTINGS } from "./GTAO_RENDER_SETTINGS.js";
35
+
36
+ const resources = new ShaderResourceSetDescriptor();
37
+
38
+ // see fragment_shader_gtao — the same per-pass settings, carried as immediate data
39
+ resources.setImmediate("settings", GTAO_RENDER_SETTINGS);
40
+ resources.createGroup()
41
+ .addTexture("tDepth")
42
+ .addTexture("tHZB")
43
+ .addSampler("sPoint", "non-filtering", SAMPLER_NEAREST)
44
+ .addTexture("tNormal", "uint")
45
+ .addTexture("tColor", "unfilterable-float", "2d", false, BLACK_PIXEL_TEXTURE)
46
+ .addTexture("tNoise", "uint", "2d", false, HILBERT_R2_INDEX_TEXTURE)
47
+ .addUniform("camera", CAMERA_UNIFORM_STRUCT)
48
+ ;
49
+
50
+ /**
51
+ * One step below the AO-only shader's Medium, because every sample here also integrates incoming
52
+ * radiance. A deliberate difference, unlike the ones this fork used to carry by accident.
53
+ * @type {{slices:number,steps:number}}
54
+ */
55
+ const QUALITY_SETTINGS = GTAO_QUALITY_PROFILES[GTAO_QUALITY_TYPE.Low];
56
+
57
+ // this is our own thickness heuristic that relies on sooner discarding samples behind the center
58
+ const GTAO_DEFAULT_THIN_OCCLUDER_COMPENSATION = 0.0;
59
+
60
+ /*
61
+ based on https://github.com/GameTechDev/XeGTAO/tree/e7698f874e90f2516fca26c696ec3cd2c70e505a
62
+ */
63
+ const body = CodeChunk.from(
64
+ //language=WGSL
65
+ `
66
+ const scale = 1.0;
67
+
68
+ const thinOccluderCompensation = ${GTAO_DEFAULT_THIN_OCCLUDER_COMPENSATION};
69
+
70
+ // small crevices more important than big surfaces
71
+ const sampleDistributionPower = 2.0;
72
+
73
+ const SLICE_COUNT = ${QUALITY_SETTINGS.slices};
74
+
75
+ const STEPS = ${QUALITY_SETTINGS.steps};
76
+
77
+ struct Output{
78
+ @location(0) visibility: vec2<f32>, // first 2 moment
79
+ @location(1) bent_normal: vec2<u32>, // octahedral encoding
80
+ @location(2) irradiance: u32, // rgbe9995
81
+ }
82
+
83
+ @fragment
84
+ fn main(
85
+ @builtin(position) coord: vec4<f32>,
86
+ @location(0) uv: vec2<f32>,
87
+ ) -> Output {
88
+
89
+ // fadeout precompute optimisation
90
+ const falloffRange = ${GTAO_EFFECT_FALLOFF_RANGE} * ${GTAO_EFFECT_RADIUS};
91
+
92
+ const falloffFrom = ${GTAO_EFFECT_RADIUS} * (1.0 - ${GTAO_EFFECT_FALLOFF_RANGE});
93
+ const falloffMul = -1.0 / ( falloffRange );
94
+ const falloffAdd = falloffFrom / ( falloffRange ) + 1.0;
95
+
96
+ let texel_position_u32 = vec2<u32>(coord.xy);
97
+
98
+ let ViewportSize = textureDimensions(tDepth);
99
+ let ViewportPixelSize = 1. / vec2<f32>(ViewportSize);
100
+
101
+ var device_depth = textureLoad(tDepth, texel_position_u32, 0).r;
102
+
103
+ // NOTE: no need to reject based on depth, already handled via depthStencil
104
+
105
+ var viewspaceZ = get_view_space_depth(device_depth, camera);
106
+
107
+ // Move center pixel slightly towards camera to avoid imprecision artifacts due to depth buffer imprecision; offset depends on depth texture format used
108
+ viewspaceZ *= 0.99999; // this is good for FP32 depth buffer
109
+
110
+ let position_ws = project_position_from_depth(uv, device_depth, camera.view_projection_matrix_inverse );
111
+ let view_position_ws = mat4_extract_position(camera.view_matrix_inverse);
112
+ let view_direction_ws = normalize(view_position_ws - position_ws);
113
+
114
+ let view_normal_ws = decode_g_buffer_normal(textureLoad(tNormal, texel_position_u32, 0).xy); // shading normal
115
+
116
+ let noiseTexel = spatio_temporal_noise_r2_64(texel_position_u32, settings.frame_index, tNoise);
117
+
118
+ let noiseSample = noiseTexel.x;
119
+ let noiseSlice = noiseTexel.y;
120
+
121
+ // quality settings / tweaks / hacks
122
+ const pixelTooCloseThreshold = 1.3; // if the offset is under approx pixel size (pixelTooCloseThreshold), push it out to the minimum distance
123
+
124
+ // approx viewspace pixel size at pixCoord; approximation of NDCToViewspace( normalizedScreenPos.xy + consts.ViewportPixelSize.xy, pixCenterPos.z ).xy - pixCenterPos.xy;
125
+ // device_depth_to_view_space.z = 1/a = aspect * tan(fovY/2) = tan(fovX/2), pairs with horizontal pixel size.
126
+ // factor of 2 converts a single uv-step (= 1 pixel) into the matching ndc-step (range 2 wide).
127
+ // This read .w — tan(fovY/2) — with no factor of 2, i.e. 2*aspect too small, 3.56x at 16:9, which
128
+ // put every AO sample that much further out than the effect radius asked for.
129
+ let NDCToViewMul_x_PixelSize = 2.0 * camera.device_depth_to_view_space.z * ViewportPixelSize.x;
130
+ let pixelDirRBViewspaceSizeAtCenterZ = viewspaceZ * NDCToViewMul_x_PixelSize;
131
+
132
+ let screenspaceRadius = abs( ${GTAO_EFFECT_RADIUS} / pixelDirRBViewspaceSizeAtCenterZ);
133
+
134
+ // fade out for small screen radii
135
+ var visibility = 0.0;
136
+ var bent_normal:vec3<f32>;
137
+ var lighting: vec3<f32>;
138
+ var lighting_weight_total = 0.0;
139
+
140
+ // this is the min distance to start sampling from to avoid sampling from the center pixel (no useful data obtained from sampling center pixel)
141
+ let minS = pixelTooCloseThreshold / screenspaceRadius;
142
+
143
+ // The slices' angle is measured around the view ray, from the camera's right made perpendicular to it: at
144
+ // the screen's centre that is the screen's own x, as the paper has it. The ray never runs along it inside a
145
+ // frustum. See fragment_shader_gtao, which this follows in world space.
146
+ let camera_right_ws = v3_matrix4_rotate(vec3(1.0, 0.0, 0.0), camera.view_matrix_inverse);
147
+ let slice_basis_x = normalize(fma(vec3(-dot(camera_right_ws, view_direction_ws)), view_direction_ws, camera_right_ws));
148
+ let slice_basis_y = cross(view_direction_ws, slice_basis_x);
149
+
150
+ let center_clip = camera.view_projection_matrix * vec4(position_ws, 1.0);
151
+
152
+ const INV_SLICE_COUNT = 1.0 / f32(SLICE_COUNT);
153
+
154
+ for (var slice = 0; slice < SLICE_COUNT; slice++) {
155
+
156
+ let sliceK = ( f32(slice) + noiseSlice ) * INV_SLICE_COUNT;
157
+
158
+ // lines 5,6 from the paper
159
+ let phi = sliceK * PI; // slice angle
160
+
161
+ let cosPhi = cos(phi);
162
+ let sinPhi = sin(phi);
163
+
164
+ // line 8 from the paper, with phi the slice's angle around this texel's own view ray: the integrals below
165
+ // are written in that angle. The paper takes phi on screen, which is the same angle only at the screen's
166
+ // centre; off it, slices spread evenly on screen bunch around the view ray, the two of a frame stop
167
+ // cancelling, and an open plane's bent normal leans by degrees towards the screen's edges.
168
+ let sliceWorldDir = cosPhi * slice_basis_x + sinPhi * slice_basis_y;
169
+
170
+ // The slice's plane holds the view ray, so on screen it is a line through this texel, along the
171
+ // projection's derivative in the slice's direction: (d(clip.xy) * clip.w - clip.xy * d(clip.w)) / clip.w^2,
172
+ // its scale dropped, into uv and then pixels.
173
+ let slice_clip = camera.view_projection_matrix * vec4(sliceWorldDir, 0.0);
174
+ let slice_screen = (slice_clip.xy * center_clip.w - center_clip.xy * slice_clip.w) * vec2(0.5, -0.5) * vec2<f32>(ViewportSize);
175
+ let omega = normalize(slice_screen) * screenspaceRadius;
176
+
177
+ // line 9 from the paper
178
+ // NOTE: optimized with FMA, readability suffers
179
+ let orthoWorldDir = fma( vec3( -dot(sliceWorldDir, view_direction_ws) ), view_direction_ws, sliceWorldDir );
180
+
181
+ // line 10 from the paper
182
+ // axisVec is orthogonal to sliceViewDir and viewVec, used to define projectedNormal
183
+ let axisVec = normalize( cross(orthoWorldDir, view_direction_ws) );
184
+
185
+ // line 11 from paper
186
+ let projectedWorldNormal = fma( -axisVec, vec3( dot(view_normal_ws, axisVec) ), view_normal_ws );
187
+
188
+ // line 13 from the paper
189
+ let signNorm = sign( dot( orthoWorldDir, projectedWorldNormal ) );
190
+
191
+ // line 14 from the paper
192
+ var projectedNormalVecLength = length(projectedWorldNormal);
193
+ let norm_cos = saturate( dot( projectedWorldNormal, view_direction_ws ) / projectedNormalVecLength );
194
+
195
+ // line 15 from the paper
196
+ let n = signNorm * fast_acos(norm_cos);
197
+
198
+ // this is a lower weight target; not using -1 as in the original paper because it is under horizon, so a 'weight' has different meaning based on the normal
199
+ let lowHorizonCos0 = cos(n + PI_HALF);
200
+ let lowHorizonCos1 = -lowHorizonCos0; // cos(n - PI_HALF);
201
+
202
+ // lines 17, 18 from the paper, manually unrolled the 'side' loop
203
+ var horizonCos0 = lowHorizonCos0; // -1
204
+ var horizonCos1 = lowHorizonCos1; // -1
205
+
206
+ const INV_STEPS = 1.0 / f32(STEPS);
207
+
208
+ // The lighting integrant's factors, in the slice's own frame: a direction in it is
209
+ // cos(theta) * view + sin(theta) * tangent, so N.w splits into N.tangent and N.view. At the screen's
210
+ // centre that is the view-space N.xy along the slice and N.z this read before the slices followed the ray.
211
+ let slice_tangent_ws = normalize(orthoWorldDir);
212
+ let light_integrant_front = 0.5 * vec2(dot(view_normal_ws, slice_tangent_ws), dot(view_normal_ws, view_direction_ws));
213
+ // Sample 0 lies along the tangent and sample 1 against it, so the back side, sample 1's, has the tangent's
214
+ // term flipped.
215
+ let light_integrant_back = vec2(-light_integrant_front.x, light_integrant_front.y);
216
+
217
+ var sliceLighting: vec3<f32>;
218
+
219
+ for (var step_index = 0; step_index < STEPS; step_index++) {
220
+
221
+ // R1 sequence (http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/)
222
+ // Standard multiplier is 0.6180339887498948482 = ( 1 / GOLDEN_RATION )
223
+ let stepBaseNoise = f32(slice + step_index * STEPS) * 0.6180339887498948482;
224
+
225
+ let stepNoise = fract(noiseSample + stepBaseNoise);
226
+
227
+ // approx line 20 from the paper, with added noise
228
+ var s = ( f32(step_index) + stepNoise ) * INV_STEPS;
229
+
230
+ // additional distribution modifier
231
+ s = pow( s, sampleDistributionPower );
232
+
233
+ // avoid sampling center pixel
234
+ s += minS;
235
+
236
+ // approx lines 21-22 from the paper, unrolled
237
+ var sampleOffset = s * omega;
238
+
239
+ // omega is a unit screen direction times screenspaceRadius, so has length screenspaceRadius
240
+ let sampleOffsetLength = s * screenspaceRadius;
241
+ let mipLevel = gtao_compute_mip_level(sampleOffsetLength);
242
+
243
+ // Snap to pixel center (more correct direction math, avoids artifacts due to sampling pos not matching depth texel center - messes up slope - but adds other
244
+ // artifacts due to them being pushed off the slice). Also use full precision for high res cases.
245
+ sampleOffset = round( sampleOffset ) * ViewportPixelSize;
246
+
247
+ let sampleScreenPos0 = uv + sampleOffset;
248
+
249
+ let SZ0 = gtao_sample_depth(sampleScreenPos0, mipLevel, camera);
250
+ let samplePos0 = project_position_from_depth(sampleScreenPos0, SZ0, camera.view_projection_matrix_inverse);
251
+
252
+ let sampleScreenPos1 = uv - sampleOffset;
253
+ let SZ1 = gtao_sample_depth(sampleScreenPos1, mipLevel, camera);
254
+ let samplePos1 = project_position_from_depth(sampleScreenPos1, SZ1, camera.view_projection_matrix_inverse);
255
+
256
+ let sampleDelta0 = (samplePos0 - position_ws); // using lpfloat for sampleDelta causes precision issues
257
+ let sampleDelta1 = (samplePos1 - position_ws); // using lpfloat for sampleDelta causes precision issues
258
+
259
+ let sampleDist0 = length( sampleDelta0 );
260
+ let sampleDist1 = length( sampleDelta1 );
261
+
262
+ // approx lines 23, 24 from the paper, unrolled
263
+ let sampleHorizonVec0 = sampleDelta0 / sampleDist0;
264
+ let sampleHorizonVec1 = sampleDelta1 / sampleDist1;
265
+
266
+ let weight0 = saturate( fma(sampleDist0, falloffMul, falloffAdd) );
267
+ let weight1 = saturate( fma(sampleDist1, falloffMul, falloffAdd) );
268
+
269
+ // sample horizon cos
270
+ var shc0 = dot( sampleHorizonVec0, view_direction_ws );
271
+ var shc1 = dot( sampleHorizonVec1, view_direction_ws );
272
+
273
+ // discard unwanted samples
274
+ shc0 = mix( lowHorizonCos0, shc0, weight0 ); // this would be more correct but too expensive: cos(lerp( acos(lowHorizonCos0), acos(shc0), weight0 ));
275
+ shc1 = mix( lowHorizonCos1, shc1, weight1 ); // this would be more correct but too expensive: cos(lerp( acos(lowHorizonCos1), acos(shc1), weight1 ));
276
+
277
+ if(shc0 > horizonCos0 && !is_background(SZ0) ){
278
+
279
+ let s0 = horizon_integrate_lighting_sample(
280
+ sampleScreenPos0,
281
+ view_normal_ws, // ref_normal
282
+ sampleHorizonVec0, // ref_direction
283
+ horizonCos0, // h0 (previous horizon)
284
+ shc0, // h1 (new horizon)
285
+ light_integrant_front
286
+ );
287
+
288
+ sliceLighting += s0;
289
+ }
290
+
291
+ if(shc1 > horizonCos1 && !is_background(SZ1) ){
292
+
293
+ let s1 = horizon_integrate_lighting_sample(
294
+ sampleScreenPos1,
295
+ view_normal_ws, // ref_normal
296
+ sampleHorizonVec1, // ref_direction
297
+ horizonCos1, // h0 (previous horizon)
298
+ shc1, // h1 (new horizon)
299
+ light_integrant_back
300
+ );
301
+
302
+ sliceLighting += s1;
303
+ }
304
+
305
+ // this is a version where thicknessHeuristic is completely disabled
306
+ horizonCos0 = max( horizonCos0, shc0 );
307
+ horizonCos1 = max( horizonCos1, shc1 );
308
+
309
+ }
310
+
311
+ // line ~27, unrolled
312
+ let h0 = -fast_acos(horizonCos1);
313
+ let h1 = fast_acos(horizonCos0);
314
+
315
+ let norm_sin = sin(n);
316
+ let norm_sin2 = 2.0 * norm_sin;
317
+
318
+ let iarc0 = ( fma( h0 , norm_sin2, norm_cos ) - cos( fma( 2.0, h0, - n)) ) * 0.25;
319
+ let iarc1 = ( fma( h1 , norm_sin2, norm_cos ) - cos( fma( 2.0, h1, - n)) ) * 0.25;
320
+
321
+ // Slight overdarkening on high slopes is compensated by tilting projected length toward 1.
322
+ // In the training set, 0.05 is close (PSNR 21.34) to disabled (PSNR 21.45).
323
+ // Scoped to the visibility branch so bent normals keep their unfudged slice weighting — this
324
+ // used to assign back into projectedNormalVecLength, so the bent-normal accumulation below got
325
+ // the fudged weight too.
326
+ let visibilityProjLength = mix( projectedNormalVecLength, 1, 0.05 );
327
+
328
+ let localVisibility = visibilityProjLength * ( iarc0 + iarc1 );
329
+
330
+ visibility += localVisibility;
331
+
332
+ // Not weighted by projectedNormalVecLength, as the visibility and the bent normal are: those integrate
333
+ // against the projected normal made unit, and put its length back. The lighting's integrant dots the
334
+ // whole normal with directions in the slice, which already is the projected normal, length and all.
335
+ lighting += sliceLighting;
336
+
337
+ // see "Algorithm 2 Extension that computes bent normals b."
338
+ let local_bent_ts = integrate_bent_normal(
339
+ horizonCos1,
340
+ horizonCos0,
341
+ norm_cos,
342
+ norm_sin,
343
+ );
344
+
345
+ let t0 = local_bent_ts.x;
346
+ let t1 = local_bent_ts.y;
347
+
348
+ var slice_bent_normal_ws = slice_tangent_ws * t0 + view_direction_ws * t1;
349
+
350
+ bent_normal = fma(slice_bent_normal_ws, vec3(projectedNormalVecLength), bent_normal);
351
+ }
352
+
353
+ visibility *= INV_SLICE_COUNT;
354
+
355
+ visibility = pow(visibility, scale);
356
+
357
+ // disallow total occlusion (which wouldn't make any sense anyhow since pixel is visible but also helps with packing bent normals)
358
+ visibility = max(0.03, visibility);
359
+
360
+ bent_normal = normalize(bent_normal);
361
+
362
+ lighting *= PI * INV_SLICE_COUNT;
363
+
364
+ var out: Output;
365
+ out.visibility = vec2(visibility, visibility * visibility);
366
+ out.bent_normal = encode_g_buffer_normal( bent_normal );
367
+ out.irradiance = rgbe9995_encode( lighting );
368
+
369
+ return out;
370
+ }
371
+ `, [
372
+ chunk_get_view_space_depth,
373
+ PI_DECLARATION,
374
+ PI_HALF_DECLARATION,
375
+
376
+ chunk_decode_g_buffer_normal,
377
+ chunk_encode_g_buffer_normal,
378
+ chunk_spatio_temporal_noise_r2_64,
379
+
380
+ chunk_fast_acos,
381
+
382
+ chunk_direction_view_to_world,
383
+ chunk_is_background,
384
+ chunk_mat4_extract_position,
385
+ chunk_project_position_from_depth,
386
+ chunk_v3_matrix4_rotate,
387
+ chunk_integrate_bent_normal_fast,
388
+ chunk_gtao_compute_mip_level,
389
+ chunk_gtao_sample_depth,
390
+
391
+ //
392
+ chunk_rgbe9995_encode,
393
+ chunk_horizon_integrate_lighting_sample,
394
+ ]);
395
+
396
+ export const fragment_shader_gtao_with_irradiance = new ImageShader({
397
+ descriptor: ShaderDescriptor.from(
398
+ {
399
+ label: "GTAO",
400
+ resources,
401
+ body
402
+ },
403
+ ),
404
+ depthStencil: DEPTH_STENCIL_FOREGROUND_ONLY,
405
+ targets: [
406
+ {
407
+ label: "Occlusion",
408
+ // first 2 moments of visibility
409
+ format: "rg16float",
410
+ clearValue: [1, 1], // Stores visibility, so 1 == not occluded
411
+ blend: BlendState.from({
412
+ color: {
413
+ operation: "add",
414
+ srcFactor: "one",
415
+ dstFactor: "zero",
416
+ }
417
+ })
418
+ },
419
+ {
420
+ label: "Bent Normals",
421
+ // Direction is encoded with octahedral
422
+ format: "rg16uint",
423
+ },
424
+ {
425
+ label: "Irradiance",
426
+ // encoded as RGBE9995
427
+ format:"r32uint"
428
+ }
429
+ ]
430
+ });