@woosh/meep-engine 3.65.0 → 3.68.0

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 (350) hide show
  1. package/package.json +1 -1
  2. package/src/engine/graphics3/GraphicsEngine.d.ts.map +1 -1
  3. package/src/engine/graphics3/GraphicsEngine.js +4 -9
  4. package/src/engine/graphics3/load_cube_environment.js +3 -3
  5. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  6. package/src/format/lut/cube/CubeLut.d.ts +38 -0
  7. package/src/format/lut/cube/CubeLut.d.ts.map +1 -0
  8. package/src/format/lut/cube/CubeLut.js +23 -0
  9. package/src/format/lut/cube/cube_read.d.ts +23 -0
  10. package/src/format/lut/cube/cube_read.d.ts.map +1 -0
  11. package/src/format/lut/cube/cube_read.js +199 -0
  12. package/src/format/lut/cube/cube_write.d.ts +15 -0
  13. package/src/format/lut/cube/cube_write.d.ts.map +1 -0
  14. package/src/format/lut/cube/cube_write.js +90 -0
  15. package/src/shade/playground/probe_clipmap/README.md +1 -0
  16. package/src/shade/playground/probe_clipmap/index.html +48 -0
  17. package/src/shade/playground/probe_clipmap/main.d.ts.map +1 -1
  18. package/src/shade/playground/probe_clipmap/main.js +36 -0
  19. package/src/shade/renderer/Renderer.d.ts +7 -0
  20. package/src/shade/renderer/Renderer.d.ts.map +1 -1
  21. package/src/shade/renderer/Renderer.js +225 -27
  22. package/src/shade/renderer/ShadeIndirectLightingMode.d.ts +1 -0
  23. package/src/shade/renderer/ShadeIndirectLightingMode.js +9 -0
  24. package/src/shade/renderer/atmosphere/ATMOSPHERE_PARAMETERS_STRUCT.d.ts +22 -0
  25. package/src/shade/renderer/atmosphere/ATMOSPHERE_PARAMETERS_STRUCT.d.ts.map +1 -0
  26. package/src/shade/renderer/atmosphere/ATMOSPHERE_PARAMETERS_STRUCT.js +160 -0
  27. package/src/shade/renderer/atmosphere/ATMOSPHERE_UNIT_SCALE.d.ts +45 -0
  28. package/src/shade/renderer/atmosphere/ATMOSPHERE_UNIT_SCALE.d.ts.map +1 -0
  29. package/src/shade/renderer/atmosphere/ATMOSPHERE_UNIT_SCALE.js +57 -0
  30. package/src/shade/renderer/atmosphere/GPUSky.d.ts +23 -8
  31. package/src/shade/renderer/atmosphere/GPUSky.d.ts.map +1 -1
  32. package/src/shade/renderer/atmosphere/GPUSky.js +91 -34
  33. package/src/shade/renderer/atmosphere/SAMPLER_SKY_LUT.d.ts +17 -0
  34. package/src/shade/renderer/atmosphere/SAMPLER_SKY_LUT.d.ts.map +1 -1
  35. package/src/shade/renderer/atmosphere/SAMPLER_SKY_LUT.js +55 -25
  36. package/src/shade/renderer/atmosphere/SceneAtmosphere.d.ts +164 -0
  37. package/src/shade/renderer/atmosphere/SceneAtmosphere.d.ts.map +1 -0
  38. package/src/shade/renderer/atmosphere/SceneAtmosphere.js +308 -0
  39. package/src/shade/renderer/atmosphere/chunk_get_multiscatter_values.d.ts +3 -12
  40. package/src/shade/renderer/atmosphere/chunk_get_multiscatter_values.d.ts.map +1 -1
  41. package/src/shade/renderer/atmosphere/chunk_get_multiscatter_values.js +52 -89
  42. package/src/shade/renderer/atmosphere/chunk_raymarch_sky_scattering.d.ts +14 -0
  43. package/src/shade/renderer/atmosphere/chunk_raymarch_sky_scattering.d.ts.map +1 -0
  44. package/src/shade/renderer/atmosphere/chunk_raymarch_sky_scattering.js +103 -0
  45. package/src/shade/renderer/atmosphere/chunk_sample_multiscatter_lut.d.ts +10 -4
  46. package/src/shade/renderer/atmosphere/chunk_sample_multiscatter_lut.d.ts.map +1 -1
  47. package/src/shade/renderer/atmosphere/chunk_sample_multiscatter_lut.js +95 -57
  48. package/src/shade/renderer/atmosphere/chunk_sample_transmittance_lut.d.ts +10 -14
  49. package/src/shade/renderer/atmosphere/chunk_sample_transmittance_lut.d.ts.map +1 -1
  50. package/src/shade/renderer/atmosphere/chunk_sample_transmittance_lut.js +97 -69
  51. package/src/shade/renderer/atmosphere/chunk_sky_irradiance_lut_encode_uv.d.ts +17 -0
  52. package/src/shade/renderer/atmosphere/chunk_sky_irradiance_lut_encode_uv.d.ts.map +1 -1
  53. package/src/shade/renderer/atmosphere/chunk_sky_irradiance_lut_encode_uv.js +117 -48
  54. package/src/shade/renderer/atmosphere/chunk_sky_lut_compute_uv.d.ts +8 -0
  55. package/src/shade/renderer/atmosphere/chunk_sky_lut_compute_uv.d.ts.map +1 -1
  56. package/src/shade/renderer/atmosphere/chunk_sky_lut_compute_uv.js +65 -35
  57. package/src/shade/renderer/atmosphere/compute_mie_absorption.d.ts +2 -1
  58. package/src/shade/renderer/atmosphere/compute_mie_absorption.d.ts.map +1 -1
  59. package/src/shade/renderer/atmosphere/compute_mie_absorption.js +6 -6
  60. package/src/shade/renderer/atmosphere/resolve_atmosphere_sun.d.ts +41 -0
  61. package/src/shade/renderer/atmosphere/resolve_atmosphere_sun.d.ts.map +1 -0
  62. package/src/shade/renderer/atmosphere/resolve_atmosphere_sun.js +123 -0
  63. package/src/shade/renderer/atmosphere/shader_multiscatter_lut.d.ts.map +1 -1
  64. package/src/shade/renderer/atmosphere/shader_multiscatter_lut.js +21 -64
  65. package/src/shade/renderer/atmosphere/shader_sky_irradiance_lut.d.ts +6 -2
  66. package/src/shade/renderer/atmosphere/shader_sky_irradiance_lut.d.ts.map +1 -1
  67. package/src/shade/renderer/atmosphere/shader_sky_irradiance_lut.js +55 -179
  68. package/src/shade/renderer/atmosphere/shader_sky_view_lut.d.ts +7 -0
  69. package/src/shade/renderer/atmosphere/shader_sky_view_lut.d.ts.map +1 -0
  70. package/src/shade/renderer/atmosphere/shader_sky_view_lut.js +111 -0
  71. package/src/shade/renderer/atmosphere/shader_transmittance_lut.d.ts +0 -1
  72. package/src/shade/renderer/atmosphere/shader_transmittance_lut.d.ts.map +1 -1
  73. package/src/shade/renderer/atmosphere/shader_transmittance_lut.js +68 -79
  74. package/src/shade/renderer/deferred/shader_background.js +1 -1
  75. package/src/shade/renderer/deferred/shader_background_sky.d.ts +5 -0
  76. package/src/shade/renderer/deferred/shader_background_sky.d.ts.map +1 -0
  77. package/src/shade/renderer/deferred/shader_background_sky.js +130 -0
  78. package/src/shade/renderer/deferred/tonemap/ColorGrade.d.ts +73 -4
  79. package/src/shade/renderer/deferred/tonemap/ColorGrade.d.ts.map +1 -1
  80. package/src/shade/renderer/deferred/tonemap/ColorGrade.js +113 -7
  81. package/src/shade/renderer/deferred/tonemap/TONEMAP_PURKINJE_SHIFT.d.ts +12 -0
  82. package/src/shade/renderer/deferred/tonemap/TONEMAP_PURKINJE_SHIFT.d.ts.map +1 -0
  83. package/src/shade/renderer/deferred/tonemap/TONEMAP_PURKINJE_SHIFT.js +12 -0
  84. package/src/shade/renderer/deferred/tonemap/ToneMapper.d.ts +15 -1
  85. package/src/shade/renderer/deferred/tonemap/ToneMapper.d.ts.map +1 -1
  86. package/src/shade/renderer/deferred/tonemap/ToneMapper.js +31 -3
  87. package/src/shade/renderer/deferred/tonemap/chunk_tonemap_purkinje.d.ts +26 -0
  88. package/src/shade/renderer/deferred/tonemap/chunk_tonemap_purkinje.d.ts.map +1 -0
  89. package/src/shade/renderer/deferred/tonemap/chunk_tonemap_purkinje.js +55 -0
  90. package/src/shade/renderer/deferred/tonemap/shader_tonemap_HDR_lut.d.ts +2 -2
  91. package/src/shade/renderer/deferred/tonemap/shader_tonemap_HDR_lut.d.ts.map +1 -1
  92. package/src/shade/renderer/deferred/tonemap/shader_tonemap_HDR_lut.js +6 -3
  93. package/src/shade/renderer/deferred/tonemap/shader_tonemap_LDR_lut.d.ts +3 -2
  94. package/src/shade/renderer/deferred/tonemap/shader_tonemap_LDR_lut.d.ts.map +1 -1
  95. package/src/shade/renderer/deferred/tonemap/shader_tonemap_LDR_lut.js +7 -3
  96. package/src/shade/renderer/extension/ViewTextures.d.ts +3 -2
  97. package/src/shade/renderer/extension/ViewTextures.d.ts.map +1 -1
  98. package/src/shade/renderer/extension/ViewTextures.js +3 -2
  99. package/src/shade/renderer/fluid/GPUFluidCascade.d.ts +3 -3
  100. package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +1 -1
  101. package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts +6 -6
  102. package/src/shade/renderer/fluid/pressure/GPUFluidPressureSolve.d.ts +1 -1
  103. package/src/shade/renderer/fluid/query/GPUFluidQueries.d.ts +1 -1
  104. package/src/shade/renderer/global_illumination/probe/octahedral/shader_lpv_build_gbuffer.js +1 -1
  105. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts +20 -1
  106. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts.map +1 -1
  107. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.js +29 -0
  108. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_hit_light.d.ts +47 -0
  109. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_hit_light.d.ts.map +1 -0
  110. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_hit_light.js +246 -0
  111. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_light.d.ts +4 -15
  112. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_light.d.ts.map +1 -1
  113. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_light.js +8 -148
  114. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace.d.ts +4 -9
  115. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace.d.ts.map +1 -1
  116. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace.js +9 -58
  117. package/src/shade/renderer/global_illumination/screen_probe/GPUScreenProbeGI.d.ts +142 -0
  118. package/src/shade/renderer/global_illumination/screen_probe/GPUScreenProbeGI.d.ts.map +1 -0
  119. package/src/shade/renderer/global_illumination/screen_probe/GPUScreenProbeGI.js +938 -0
  120. package/src/shade/renderer/global_illumination/screen_probe/SCREEN_PROBE.d.ts +192 -0
  121. package/src/shade/renderer/global_illumination/screen_probe/SCREEN_PROBE.d.ts.map +1 -0
  122. package/src/shade/renderer/global_illumination/screen_probe/SCREEN_PROBE.js +231 -0
  123. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeDebugView.d.ts +11 -0
  124. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeDebugView.d.ts.map +1 -0
  125. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeDebugView.js +25 -0
  126. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeSettings.d.ts +110 -0
  127. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeSettings.d.ts.map +1 -0
  128. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeSettings.js +197 -0
  129. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe.d.ts +150 -0
  130. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe.d.ts.map +1 -0
  131. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe.js +408 -0
  132. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_brdf_density.d.ts +23 -0
  133. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_brdf_density.d.ts.map +1 -0
  134. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_brdf_density.js +63 -0
  135. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_brick_origin.d.ts +24 -0
  136. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_brick_origin.d.ts.map +1 -0
  137. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_brick_origin.js +61 -0
  138. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_interpolate.d.ts +39 -0
  139. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_interpolate.d.ts.map +1 -0
  140. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_interpolate.js +126 -0
  141. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_lighting_history.d.ts +21 -0
  142. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_lighting_history.d.ts.map +1 -0
  143. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_lighting_history.js +74 -0
  144. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_march_distance.d.ts +20 -0
  145. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_march_distance.d.ts.map +1 -0
  146. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_march_distance.js +26 -0
  147. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_ray_sort.d.ts +24 -0
  148. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_ray_sort.d.ts.map +1 -0
  149. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_ray_sort.js +57 -0
  150. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_screen_march.d.ts +22 -0
  151. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_screen_march.d.ts.map +1 -0
  152. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_screen_march.js +53 -0
  153. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_surface.d.ts +62 -0
  154. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_surface.d.ts.map +1 -0
  155. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_surface.js +156 -0
  156. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_workgroup_sum.d.ts +18 -0
  157. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_workgroup_sum.d.ts.map +1 -0
  158. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_workgroup_sum.js +50 -0
  159. package/src/shade/renderer/global_illumination/screen_probe/graph_screen_probe_debug_view.d.ts +21 -0
  160. package/src/shade/renderer/global_illumination/screen_probe/graph_screen_probe_debug_view.d.ts.map +1 -0
  161. package/src/shade/renderer/global_illumination/screen_probe/graph_screen_probe_debug_view.js +54 -0
  162. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_brick.d.ts +67 -0
  163. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_brick.d.ts.map +1 -0
  164. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_brick.js +509 -0
  165. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_debug.d.ts +20 -0
  166. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_debug.d.ts.map +1 -0
  167. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_debug.js +128 -0
  168. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_gather.d.ts +62 -0
  169. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_gather.d.ts.map +1 -0
  170. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_gather.js +478 -0
  171. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_importance.d.ts +69 -0
  172. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_importance.d.ts.map +1 -0
  173. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_importance.js +457 -0
  174. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_indirect_lighting.d.ts +27 -0
  175. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_indirect_lighting.d.ts.map +1 -0
  176. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_indirect_lighting.js +219 -0
  177. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_pick.d.ts +22 -0
  178. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_pick.d.ts.map +1 -0
  179. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_pick.js +151 -0
  180. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_place.d.ts +66 -0
  181. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_place.d.ts.map +1 -0
  182. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_place.js +301 -0
  183. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_resolve.d.ts +59 -0
  184. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_resolve.d.ts.map +1 -0
  185. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_resolve.js +364 -0
  186. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_trace_screen.d.ts +40 -0
  187. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_trace_screen.d.ts.map +1 -0
  188. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_trace_screen.js +275 -0
  189. package/src/shade/renderer/grass/blade/GPUGrassBlades.d.ts.map +1 -1
  190. package/src/shade/renderer/grass/blade/GPUGrassBlades.js +17 -2
  191. package/src/shade/renderer/grass/blade/grass_blade_resolve.d.ts +18 -8
  192. package/src/shade/renderer/grass/blade/grass_blade_resolve.d.ts.map +1 -1
  193. package/src/shade/renderer/grass/blade/grass_blade_resolve.js +114 -32
  194. package/src/shade/renderer/light/GPULightCollection.d.ts +1 -1
  195. package/src/shade/renderer/light/GPULightCollection.d.ts.map +1 -1
  196. package/src/shade/renderer/light/GPULightCollection.js +213 -80
  197. package/src/shade/renderer/{atmosphere → light/environment}/chunk_sample_environment_color.d.ts +1 -2
  198. package/src/shade/renderer/light/environment/chunk_sample_environment_color.d.ts.map +1 -0
  199. package/src/shade/renderer/{atmosphere → light/environment}/chunk_sample_environment_color.js +3 -4
  200. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
  201. package/src/shade/renderer/path_tracer/shader/chunk_render_trace_path.js +1 -1
  202. package/src/shade/renderer/postprocess/denoise/debug/graph_pass_debug_reprojection.js +1 -1
  203. package/src/shade/renderer/postprocess/eye/GPUCameraExposureManager.d.ts +35 -9
  204. package/src/shade/renderer/postprocess/eye/GPUCameraExposureManager.d.ts.map +1 -1
  205. package/src/shade/renderer/postprocess/eye/GPUCameraExposureManager.js +81 -11
  206. package/src/shade/renderer/postprocess/eye/shader_autoexposure_adapt.d.ts.map +1 -1
  207. package/src/shade/renderer/postprocess/eye/shader_autoexposure_adapt.js +4 -1
  208. package/src/shade/renderer/postprocess/motion_blur/MotionBlur.d.ts +1 -1
  209. package/src/shade/renderer/postprocess/motion_blur/MotionBlur.js +1 -1
  210. package/src/shade/renderer/postprocess/motion_blur/graph_postprocess_motion_blur.d.ts +1 -1
  211. package/src/shade/renderer/postprocess/motion_blur/graph_postprocess_motion_blur.js +1 -1
  212. package/src/shade/renderer/postprocess/motion_blur/shader_motion_blur_reconstruct.js +1 -1
  213. package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
  214. package/src/shade/renderer/postprocess/ssr/resolve/chunk_ssr_add_hit_irradiance.js +2 -0
  215. package/src/shade/renderer/postprocess/ssr/resolve/chunk_ssr_sample_radiance.js +2 -0
  216. package/src/shade/renderer/postprocess/taa/chunk_fsr2_compute_depth_clip.d.ts +6 -0
  217. package/src/shade/renderer/postprocess/taa/chunk_fsr2_compute_depth_clip.d.ts.map +1 -1
  218. package/src/shade/renderer/postprocess/taa/chunk_fsr2_compute_depth_clip.js +9 -1
  219. package/src/shade/renderer/postprocess/taa/shader_depth_occlusion_clip.d.ts.map +1 -1
  220. package/src/shade/renderer/postprocess/taa/shader_depth_occlusion_clip.js +4 -3
  221. package/src/shade/renderer/postprocess/velocity/VELOCITY_BUFFER.d.ts +17 -0
  222. package/src/shade/renderer/postprocess/velocity/VELOCITY_BUFFER.d.ts.map +1 -0
  223. package/src/shade/renderer/postprocess/velocity/VELOCITY_BUFFER.js +16 -0
  224. package/src/shade/renderer/postprocess/velocity/chunk_velocity_texel.d.ts +21 -0
  225. package/src/shade/renderer/postprocess/velocity/chunk_velocity_texel.d.ts.map +1 -0
  226. package/src/shade/renderer/postprocess/velocity/chunk_velocity_texel.js +30 -0
  227. package/src/shade/renderer/postprocess/velocity/graph_add_per_object_velocity.d.ts +7 -5
  228. package/src/shade/renderer/postprocess/velocity/graph_add_per_object_velocity.d.ts.map +1 -1
  229. package/src/shade/renderer/postprocess/velocity/graph_add_per_object_velocity.js +19 -17
  230. package/src/shade/renderer/rasterize/forward/chunk_forward_sample_indirect.js +2 -0
  231. package/src/shade/renderer/scene/GPUSceneContext.d.ts.map +1 -1
  232. package/src/shade/renderer/scene/GPUSceneContext.js +2 -1
  233. package/src/shade/renderer/scene/Scene.d.ts +9 -2
  234. package/src/shade/renderer/scene/Scene.d.ts.map +1 -1
  235. package/src/shade/renderer/scene/Scene.js +10 -2
  236. package/src/shade/renderer/shader/ImageShader.d.ts +24 -12
  237. package/src/shade/renderer/shader/ImageShader.d.ts.map +1 -1
  238. package/src/shade/renderer/shader/ImageShader.js +11 -8
  239. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_HEIGHT_DECLARATION.d.ts +3 -1
  240. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_HEIGHT_DECLARATION.d.ts.map +1 -1
  241. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_HEIGHT_DECLARATION.js +11 -3
  242. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_RADII_DECLARATION.d.ts +2 -11
  243. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_RADII_DECLARATION.d.ts.map +1 -1
  244. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_RADII_DECLARATION.js +23 -32
  245. package/src/shade/renderer/shader/chunk/atmosphere/PLANET_RADIUS_DECLARATION.d.ts +6 -0
  246. package/src/shade/renderer/shader/chunk/atmosphere/PLANET_RADIUS_DECLARATION.d.ts.map +1 -1
  247. package/src/shade/renderer/shader/chunk/atmosphere/PLANET_RADIUS_DECLARATION.js +14 -2
  248. package/src/shade/renderer/shader/chunk/atmosphere/chunk_atmosphere_height.d.ts.map +1 -1
  249. package/src/shade/renderer/shader/chunk/atmosphere/chunk_atmosphere_height.js +4 -2
  250. package/src/shade/renderer/shader/chunk/atmosphere/chunk_atmosphere_intersection.d.ts.map +1 -1
  251. package/src/shade/renderer/shader/chunk/atmosphere/chunk_atmosphere_intersection.js +11 -3
  252. package/src/shade/renderer/shader/chunk/atmosphere/chunk_atmosphere_ray_bounds.d.ts.map +1 -1
  253. package/src/shade/renderer/shader/chunk/atmosphere/chunk_atmosphere_ray_bounds.js +68 -69
  254. package/src/shade/renderer/shader/chunk/atmosphere/chunk_get_sun_transmittance.d.ts +4 -1
  255. package/src/shade/renderer/shader/chunk/atmosphere/chunk_get_sun_transmittance.d.ts.map +1 -1
  256. package/src/shade/renderer/shader/chunk/atmosphere/chunk_get_sun_transmittance.js +46 -39
  257. package/src/shade/renderer/shader/chunk/atmosphere/chunk_position_relative_to_planet_center.d.ts.map +1 -1
  258. package/src/shade/renderer/shader/chunk/atmosphere/chunk_position_relative_to_planet_center.js +5 -3
  259. package/src/shade/renderer/shader/chunk/color/conversion/chunk_CRM_REC709_AP1.d.ts +6 -0
  260. package/src/shade/renderer/shader/chunk/color/conversion/chunk_CRM_REC709_AP1.d.ts.map +1 -1
  261. package/src/shade/renderer/shader/chunk/color/conversion/chunk_CRM_REC709_AP1.js +7 -0
  262. package/src/shade/renderer/shader/chunk/color/grade/chunk_color_grade.d.ts +4 -4
  263. package/src/shade/renderer/shader/chunk/color/grade/chunk_color_grade.d.ts.map +1 -1
  264. package/src/shade/renderer/shader/chunk/color/grade/chunk_color_grade.js +86 -5
  265. package/src/shade/renderer/shader/chunk/color/tonemap/purkinje/chunk_apply_purkinje_shift.d.ts +73 -0
  266. package/src/shade/renderer/shader/chunk/color/tonemap/purkinje/chunk_apply_purkinje_shift.d.ts.map +1 -0
  267. package/src/shade/renderer/shader/chunk/color/tonemap/purkinje/chunk_apply_purkinje_shift.js +139 -0
  268. package/src/shade/renderer/shader/chunk/depth/chunk_get_device_depth.d.ts +14 -0
  269. package/src/shade/renderer/shader/chunk/depth/chunk_get_device_depth.d.ts.map +1 -0
  270. package/src/shade/renderer/shader/chunk/depth/chunk_get_device_depth.js +30 -0
  271. package/src/shade/renderer/shader/chunk/geometry/octahedron/chunk_uv_equal_area_sphere.d.ts +21 -0
  272. package/src/shade/renderer/shader/chunk/geometry/octahedron/chunk_uv_equal_area_sphere.d.ts.map +1 -0
  273. package/src/shade/renderer/shader/chunk/geometry/octahedron/chunk_uv_equal_area_sphere.js +60 -0
  274. package/src/shade/renderer/shader/chunk/light/{sky/chunk_sample_sky_color.d.ts → io/chunk_light_get_sun.d.ts} +3 -6
  275. package/src/shade/renderer/shader/chunk/light/io/chunk_light_get_sun.d.ts.map +1 -0
  276. package/src/shade/renderer/shader/chunk/light/{sky/chunk_sample_sky_color.js → io/chunk_light_get_sun.js} +6 -26
  277. package/src/shade/renderer/shadow/sdf/cascade/shader_scene_sdf_soft_shadows.js +1 -1
  278. package/src/shade/renderer/volumetrics/GPUViewVolumetrics.d.ts +3 -1
  279. package/src/shade/renderer/volumetrics/GPUViewVolumetrics.d.ts.map +1 -1
  280. package/src/shade/renderer/volumetrics/GPUViewVolumetrics.js +4 -2
  281. package/src/shade/renderer/volumetrics/graph_build_volumetrics.d.ts.map +1 -1
  282. package/src/shade/renderer/volumetrics/graph_build_volumetrics.js +743 -739
  283. package/src/shade/renderer/volumetrics/irradiance_clipmap/chunk_irradiance_clipmap_gi_sample.js +2 -0
  284. package/src/shade/renderer/volumetrics/shader_volumetrics_build_lighting.d.ts.map +1 -1
  285. package/src/shade/renderer/volumetrics/shader_volumetrics_build_lighting.js +19 -17
  286. package/src/shade/renderer/volumetrics/shader_volumetrics_build_scattering_lut.d.ts.map +1 -1
  287. package/src/shade/renderer/volumetrics/shader_volumetrics_build_scattering_lut.js +5 -3
  288. package/src/shade/renderer/water/chunk_water_gi.js +2 -0
  289. package/src/shade/renderer/water/query/GPUWaterQueries.d.ts +1 -1
  290. package/src/shade/renderer/wind/GPUSceneWind.d.ts +1 -1
  291. package/src/engine/graphics/sh3/path_tracer/make_sky_hosek.d.ts +0 -2
  292. package/src/engine/graphics/sh3/path_tracer/make_sky_hosek.d.ts.map +0 -1
  293. package/src/engine/graphics/sh3/path_tracer/make_sky_hosek.js +0 -45
  294. package/src/engine/graphics/sh3/path_tracer/make_sky_rtiw.d.ts +0 -2
  295. package/src/engine/graphics/sh3/path_tracer/make_sky_rtiw.d.ts.map +0 -1
  296. package/src/engine/graphics/sh3/path_tracer/make_sky_rtiw.js +0 -17
  297. package/src/engine/graphics/sh3/sky/hosek/README.md +0 -4
  298. package/src/engine/graphics/sh3/sky/hosek/data.d.ts +0 -17
  299. package/src/engine/graphics/sh3/sky/hosek/data.d.ts.map +0 -1
  300. package/src/engine/graphics/sh3/sky/hosek/data.js +0 -3744
  301. package/src/engine/graphics/sh3/sky/hosek/prototype_hosek.d.ts +0 -2
  302. package/src/engine/graphics/sh3/sky/hosek/prototype_hosek.d.ts.map +0 -1
  303. package/src/engine/graphics/sh3/sky/hosek/prototype_hosek.js +0 -71
  304. package/src/engine/graphics/sh3/sky/hosek/render_hosek_sky_to_equirectangular.d.ts +0 -26
  305. package/src/engine/graphics/sh3/sky/hosek/render_hosek_sky_to_equirectangular.d.ts.map +0 -1
  306. package/src/engine/graphics/sh3/sky/hosek/render_hosek_sky_to_equirectangular.js +0 -70
  307. package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.d.ts +0 -22
  308. package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.d.ts.map +0 -1
  309. package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.js +0 -388
  310. package/src/engine/graphics3/make_default_environment.d.ts +0 -15
  311. package/src/engine/graphics3/make_default_environment.d.ts.map +0 -1
  312. package/src/engine/graphics3/make_default_environment.js +0 -111
  313. package/src/shade/renderer/atmosphere/MIE_G.d.ts +0 -6
  314. package/src/shade/renderer/atmosphere/MIE_G.d.ts.map +0 -1
  315. package/src/shade/renderer/atmosphere/MIE_G.js +0 -5
  316. package/src/shade/renderer/atmosphere/chunk_sample_environment_color.d.ts.map +0 -1
  317. package/src/shade/renderer/atmosphere/hillaire/ATMOSPHERE_EARTH.d.ts +0 -4
  318. package/src/shade/renderer/atmosphere/hillaire/ATMOSPHERE_EARTH.d.ts.map +0 -1
  319. package/src/shade/renderer/atmosphere/hillaire/ATMOSPHERE_EARTH.js +0 -44
  320. package/src/shade/renderer/atmosphere/hillaire/ATMOSPHERE_PARAMETERS_STRUCT.d.ts +0 -2
  321. package/src/shade/renderer/atmosphere/hillaire/ATMOSPHERE_PARAMETERS_STRUCT.d.ts.map +0 -1
  322. package/src/shade/renderer/atmosphere/hillaire/ATMOSPHERE_PARAMETERS_STRUCT.js +0 -43
  323. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_DENSITY_DECLARATION.d.ts +0 -3
  324. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_DENSITY_DECLARATION.d.ts.map +0 -1
  325. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_DENSITY_DECLARATION.js +0 -6
  326. package/src/shade/renderer/shader/chunk/atmosphere/chunk_absorb.d.ts +0 -3
  327. package/src/shade/renderer/shader/chunk/atmosphere/chunk_absorb.d.ts.map +0 -1
  328. package/src/shade/renderer/shader/chunk/atmosphere/chunk_absorb.js +0 -18
  329. package/src/shade/renderer/shader/chunk/atmosphere/chunk_integrate_optical_depth.d.ts +0 -14
  330. package/src/shade/renderer/shader/chunk/atmosphere/chunk_integrate_optical_depth.d.ts.map +0 -1
  331. package/src/shade/renderer/shader/chunk/atmosphere/chunk_integrate_optical_depth.js +0 -86
  332. package/src/shade/renderer/shader/chunk/atmosphere/chunk_integrate_scattering.d.ts +0 -8
  333. package/src/shade/renderer/shader/chunk/atmosphere/chunk_integrate_scattering.d.ts.map +0 -1
  334. package/src/shade/renderer/shader/chunk/atmosphere/chunk_integrate_scattering.js +0 -125
  335. package/src/shade/renderer/shader/chunk/atmosphere/chunk_planet_intersection.d.ts +0 -3
  336. package/src/shade/renderer/shader/chunk/atmosphere/chunk_planet_intersection.d.ts.map +0 -1
  337. package/src/shade/renderer/shader/chunk/atmosphere/chunk_planet_intersection.js +0 -17
  338. package/src/shade/renderer/shader/chunk/atmosphere/chunk_sphere_intersection_nearest.d.ts +0 -3
  339. package/src/shade/renderer/shader/chunk/atmosphere/chunk_sphere_intersection_nearest.d.ts.map +0 -1
  340. package/src/shade/renderer/shader/chunk/atmosphere/chunk_sphere_intersection_nearest.js +0 -38
  341. package/src/shade/renderer/shader/chunk/atmosphere/hillaire/DENSITY_PROFILE_LAYER_STRUCT.d.ts +0 -16
  342. package/src/shade/renderer/shader/chunk/atmosphere/hillaire/DENSITY_PROFILE_LAYER_STRUCT.d.ts.map +0 -1
  343. package/src/shade/renderer/shader/chunk/atmosphere/hillaire/DENSITY_PROFILE_LAYER_STRUCT.js +0 -28
  344. package/src/shade/renderer/shader/chunk/color/tonemap/purkinjie/chunk_apply_purkinjie_shift.d.ts +0 -11
  345. package/src/shade/renderer/shader/chunk/color/tonemap/purkinjie/chunk_apply_purkinjie_shift.d.ts.map +0 -1
  346. package/src/shade/renderer/shader/chunk/color/tonemap/purkinjie/chunk_apply_purkinjie_shift.js +0 -56
  347. package/src/shade/renderer/shader/chunk/light/sky/chunk_sample_sky_color.d.ts.map +0 -1
  348. package/src/shade/renderer/view/GPUViewSkyContext.d.ts +0 -26
  349. package/src/shade/renderer/view/GPUViewSkyContext.d.ts.map +0 -1
  350. package/src/shade/renderer/view/GPUViewSkyContext.js +0 -170
@@ -0,0 +1,938 @@
1
+ import { assert } from "../../../../core/assert.js";
2
+ import { hammersley_sequence_2d } from "../../../../core/math/statistics/hammersley_sequence_2d.js";
3
+ import { BufferDescriptor } from "../../../descriptor/buffer/BufferDescriptor.js";
4
+ import { TextureDescriptor } from "../../../descriptor/texture/TextureDescriptor.js";
5
+ import { graph_import_buffer } from "../../shader/graph/graph_import_buffer.js";
6
+ import { graph_import_texture } from "../../shader/graph/graph_import_texture.js";
7
+ import { GPUTextureContext } from "../../texture/GPUTextureContext.js";
8
+ import {
9
+ SCREEN_PROBE_FRAME_STRUCT,
10
+ SCREEN_PROBE_PICK_STRUCT,
11
+ SCREEN_PROBE_RAY_STRUCT,
12
+ SCREEN_PROBE_STRUCT
13
+ } from "./chunk_screen_probe.js";
14
+ import {
15
+ SCREEN_PROBE_COUNTER_WORDS,
16
+ screen_probe_adaptive_capacity,
17
+ screen_probe_adaptive_levels,
18
+ screen_probe_adaptive_tile_capacity,
19
+ SCREEN_PROBE_DISPATCH_BRICK_RAYS,
20
+ SCREEN_PROBE_DISPATCH_PROBES,
21
+ SCREEN_PROBE_DISPATCH_RAYS,
22
+ SCREEN_PROBE_DISPATCH_THREADS,
23
+ SCREEN_PROBE_DISPATCH_WORDS,
24
+ SCREEN_PROBE_JITTER_PERIOD,
25
+ SCREEN_PROBE_OCTAHEDRON_LIMIT,
26
+ SCREEN_PROBE_RAY_SLOT_BITS,
27
+ SCREEN_PROBE_TILE_WORKGROUP_SIZE
28
+ } from "./SCREEN_PROBE.js";
29
+ import {
30
+ shader_screen_probe_brick_bounce,
31
+ shader_screen_probe_brick_light,
32
+ shader_screen_probe_brick_shade,
33
+ shader_screen_probe_brick_trace,
34
+ shader_screen_probe_brick_want
35
+ } from "./shader_screen_probe_brick.js";
36
+ import {
37
+ shader_screen_probe_composite,
38
+ shader_screen_probe_filter,
39
+ shader_screen_probe_irradiance
40
+ } from "./shader_screen_probe_gather.js";
41
+ import {
42
+ shader_screen_probe_brdf_pdf,
43
+ shader_screen_probe_generate_rays,
44
+ shader_screen_probe_lighting_pdf
45
+ } from "./shader_screen_probe_importance.js";
46
+ import { shader_screen_probe_color_capture } from "./shader_screen_probe_indirect_lighting.js";
47
+ import { shader_screen_probe_pick } from "./shader_screen_probe_pick.js";
48
+ import {
49
+ shader_screen_probe_brick_command,
50
+ shader_screen_probe_command,
51
+ shader_screen_probe_place_adaptive,
52
+ shader_screen_probe_place_uniform
53
+ } from "./shader_screen_probe_place.js";
54
+ import { shader_screen_probe_integrate, shader_screen_probe_temporal } from "./shader_screen_probe_resolve.js";
55
+ import { shader_screen_probe_trace_screen } from "./shader_screen_probe_trace_screen.js";
56
+
57
+ /**
58
+ * @typedef {import("../../../../engine/graphics/render/frame_graph/FrameGraph.js").FrameGraph} FrameGraph
59
+ * @typedef {import("../../view/GPUViewContext.js").GPUViewContext} GPUViewContext
60
+ * @typedef {import("./ScreenProbeSettings.js").ScreenProbeSettings} ScreenProbeSettings
61
+ * @typedef {import("../probe_clipmap/GPUProbeClipmapGI.js").GPUProbeClipmapGI} GPUProbeClipmapGI
62
+ */
63
+
64
+ /**
65
+ * @param {string} name a field of the frame uniform
66
+ * @returns {number} its offset in words
67
+ */
68
+ const frame_word = name => SCREEN_PROBE_FRAME_STRUCT.get(name).offset >>> 2;
69
+
70
+ /**
71
+ * {@link ShadeIndirectLightingMode.ScreenProbes} for one view: Lumen's screen probe gather, over the world the probe
72
+ * clipmap holds (`GPUProbeClipmapGI`): its bricks, which rays traverse, its surface material, which hits read, its
73
+ * world light clusters, and its two sets of world-space probes, which stand in for what lies past a screen probe's reach
74
+ * and give a hit its next bounce.
75
+ *
76
+ * **A frame**, in three passes and a capture:
77
+ * 1. **Place** ({@link graph_update}): a uniform probe in every tile of `downsample_factor` pixels at the frame's
78
+ * jitter, then the adaptive levels, finest last, each placing a probe where the probes so far would not
79
+ * interpolate to a point of its grid; then the commands over the frame's probes.
80
+ * 2. **Trace**, after the world's bricks: each probe's world-space pick, reach and brick origin (and the world probes
81
+ * it wants); its BRDF and lighting densities and its rays, reassigned to where its light is; the screen trace; the
82
+ * bricks' trace, shade, local light and bounce of what the screen left; the hits' wants; the composite into each
83
+ * probe's radiance, the spatial filter's passes, and the probes' SH3.
84
+ * 3. **Resolve** ({@link graph_resolve}), once the bent normals exist: each pixel's irradiance from its probes, then
85
+ * the temporal filter into the frame's diffuse, which the deferred passes read.
86
+ * 4. **Capture** ({@link graph_capture}): the lit colour of the opaque surfaces, for the next frame's screen hits.
87
+ *
88
+ * **Its history**: last frame's probes (their records and filtered radiance, for the lighting density), its diffuse
89
+ * and frames (for the temporal filter) and its colour (for the screen hits) are kept while the structure and the view
90
+ * stay, until {@link reset_history}; any change starts it again. Nothing is allocated on a frame that changes neither: the adaptive probes' slots
91
+ * are made with the rest, as many as the uniform probes (`screen_probe_adaptive_capacity`), and a frame that would
92
+ * place more places no more.
93
+ */
94
+ export class GPUScreenProbeGI {
95
+ /** @type {GPUDevice} */
96
+ #device;
97
+
98
+ #destroyed = false;
99
+
100
+ /** The structure the resources were made for. */
101
+ #view_width = 0;
102
+ #view_height = 0;
103
+ #downsample_factor = 0;
104
+ #octahedron_resolution = 0;
105
+ #adaptive_min_downsample_factor = 0;
106
+
107
+ #downsample_shift = 0;
108
+ #octahedron_shift = 0;
109
+ #adaptive_levels = 0;
110
+ #adaptive_tile_capacity = 0;
111
+ #tiles_x = 0;
112
+ #tiles_y = 0;
113
+ #uniform_count = 0;
114
+ #adaptive_capacity = 0;
115
+
116
+ /** Whether the resources stand. */
117
+ #built = false;
118
+
119
+ /** @type {GPUBuffer|null} */
120
+ #frame_buffer = null;
121
+ #frame_data = new ArrayBuffer(SCREEN_PROBE_FRAME_STRUCT.size);
122
+ #frame_u32 = new Uint32Array(this.#frame_data);
123
+ #frame_f32 = new Float32Array(this.#frame_data);
124
+
125
+ /** This frame's and last frame's probes; {@link #parity} names this frame's. @type {GPUBuffer[]} */
126
+ #probes = [];
127
+ #parity = 0;
128
+
129
+ /** @type {GPUBuffer|null} */
130
+ #picks = null;
131
+ /** @type {GPUBuffer|null} */
132
+ #brdf = null;
133
+ /** @type {GPUBuffer|null} */
134
+ #moving = null;
135
+ /** @type {GPUBuffer|null} */
136
+ #sh = null;
137
+ /** @type {GPUBuffer|null} */
138
+ #tile_counts = null;
139
+ /** @type {GPUBuffer|null} */
140
+ #tile_probes = null;
141
+ /** @type {GPUBuffer|null} */
142
+ #rays = null;
143
+ #ray_capacity = 0;
144
+ /** @type {GPUBuffer|null} */
145
+ #dispatch = null;
146
+ /** @type {GPUBuffer|null} */
147
+ #counters = null;
148
+
149
+ /** @type {GPUTextureContext|null} */
150
+ #ray_info = null;
151
+ /** @type {GPUTextureContext|null} */
152
+ #trace_radiance = null;
153
+ /** @type {GPUTextureContext|null} */
154
+ #trace_hit = null;
155
+ /** @type {GPUTextureContext|null} */
156
+ #lighting_pdf = null;
157
+ /** Two radiance atlases the composite and the filter's passes trade; {@link #radiance_final} holds last frame's. @type {GPUTextureContext[]} */
158
+ #radiance = [];
159
+ #radiance_final = 0;
160
+ /** @type {GPUTextureContext|null} */
161
+ #integrated = null;
162
+ /** This frame's and last frame's diffuse and frames; {@link #temporal_parity} names this frame's. @type {GPUTextureContext[]} */
163
+ #diffuse = [];
164
+ /** @type {GPUTextureContext[]} */
165
+ #frames = [];
166
+ #temporal_parity = 0;
167
+ /** @type {GPUTextureContext|null} */
168
+ #color_history = null;
169
+ /** The exposure each of the last two frames pre-exposed its probes' radiance by; {@link #parity} names this frame's. @type {GPUBuffer[]} */
170
+ #exposure_history = [];
171
+
172
+ /** Frames recorded. */
173
+ #frame = 0;
174
+
175
+ /** Whether last frame's probes, radiance, diffuse and colour describe this structure and view. */
176
+ #history = false;
177
+
178
+ /** Whether a frame has been recorded since the resources were made, so the next frame has a last frame. */
179
+ #recorded = false;
180
+
181
+ /** The view the last frame was recorded for. */
182
+ #view_id = -1;
183
+
184
+ #jitter = new Float64Array(2);
185
+ #jitter_scratch = new Float64Array(2);
186
+ #previous_jitter = new Float64Array(2);
187
+
188
+ /** The frame's inputs, as {@link graph_update} took them. */
189
+ #view = null;
190
+ /** @type {ScreenProbeSettings|null} */
191
+ #settings = null;
192
+ /** @type {GPUProbeClipmapGI|null} */
193
+ #world = null;
194
+ #stbn = null;
195
+
196
+ #b = {};
197
+ #want = {};
198
+ #sets = {};
199
+
200
+ #adaptive_settings = { level: 0 };
201
+ #brick_command_settings = { capacity: 0 };
202
+ #trace_screen_settings = { capacity: 0 };
203
+
204
+ #place_data = {};
205
+ #trace_data = {};
206
+ #resolve_data = {};
207
+ #capture_data = {};
208
+
209
+ /** The graph handle of the frame's diffuse, as {@link graph_resolve} wrote it. */
210
+ #diffuse_handle = -1;
211
+
212
+ /**
213
+ * @param {GPUDevice} device
214
+ */
215
+ constructor(device) {
216
+ assert.defined(device, 'device');
217
+
218
+ this.#device = device;
219
+ }
220
+
221
+ /**
222
+ * Drop the history: the next frame takes nothing from the frames before it, as a first frame does. For a cut, or a
223
+ * change of scene or lighting the temporal filters must not blend across (`Renderer#indicate_view_change`).
224
+ */
225
+ reset_history() {
226
+ this.#recorded = false;
227
+ }
228
+
229
+ /**
230
+ * @returns {boolean} whether its resources stand: a frame of the mode has run and not been left since
231
+ */
232
+ get built() {
233
+ return this.#built;
234
+ }
235
+
236
+ /**
237
+ * @returns {number} uniform probes this frame's structure places
238
+ */
239
+ get uniform_count() {
240
+ return this.#uniform_count;
241
+ }
242
+
243
+ /**
244
+ * @returns {number} adaptive probe slots
245
+ */
246
+ get adaptive_capacity() {
247
+ return this.#adaptive_capacity;
248
+ }
249
+
250
+ /**
251
+ * @param {number} width
252
+ * @param {number} height
253
+ * @param {ScreenProbeSettings} settings
254
+ * @returns {boolean} whether the resources are made for this view's size and the settings' structure
255
+ */
256
+ #built_for(width, height, settings) {
257
+ return this.#built
258
+ && this.#view_width === width
259
+ && this.#view_height === height
260
+ && this.#downsample_factor === settings.downsample_factor
261
+ && this.#octahedron_resolution === settings.octahedron_resolution
262
+ && this.#adaptive_min_downsample_factor === settings.adaptive_min_downsample_factor;
263
+ }
264
+
265
+ /**
266
+ * Take the frame's placement and traces, after the world's update ({@link GPUProbeClipmapGI#graph_update}) in the
267
+ * same frame: make the resources for the view and the structure the settings describe, unless they already are,
268
+ * and record the place and trace passes. {@link graph_resolve} follows once the bent normals exist.
269
+ *
270
+ * @param {Object} options
271
+ * @param {FrameGraph} options.graph
272
+ * @param {GPUViewContext} options.view
273
+ * @param {ScreenProbeSettings} options.settings
274
+ * @param {GPUProbeClipmapGI} options.world the probe clipmap GI, updated this frame: the bricks, material, light
275
+ * clusters and world-space probes the screen probes trace and read
276
+ * @param {*} options.stbn the 2-channel spatio-temporal blue noise, `STATIC_GRAPHICS_ENGINE_ASSETS.stbn_vec2`
277
+ * @param {number} options.depth graph handle of the view's reverse-Z depth
278
+ * @param {number} options.normal graph handle of the G-buffer's shading normals
279
+ * @param {number} options.pbr graph handle of the G-buffer's PBR target, which holds the face normal
280
+ * @param {number} options.velocity graph handle of the frame's motion, internal pixels
281
+ * @param {number} options.occlusion graph handle of the TAA's history confidence (`shader_depth_occlusion_clip`)
282
+ * @param {number} options.hzb graph handle of the view's hierarchical Z buffer, from mip 1
283
+ * @param {number} options.exposure graph handle of the factor the display multiplies radiance by, as the last frame
284
+ * was shown
285
+ */
286
+ graph_update({ graph, view, settings, world, stbn, depth, normal, pbr, velocity, occlusion, hzb, exposure }) {
287
+ assert.defined(graph, 'graph');
288
+ assert.defined(view, 'view');
289
+ assert.defined(settings, 'settings');
290
+ assert.defined(world, 'world');
291
+ assert.ok(world.has_probes, 'world: the probe clipmap GI updated this frame');
292
+ assert.defined(stbn, 'stbn');
293
+ assert.isNonNegativeInteger(depth, 'depth');
294
+ assert.isNonNegativeInteger(normal, 'normal');
295
+ assert.isNonNegativeInteger(pbr, 'pbr');
296
+ assert.isNonNegativeInteger(velocity, 'velocity');
297
+ assert.isNonNegativeInteger(occlusion, 'occlusion');
298
+ assert.isNonNegativeInteger(hzb, 'hzb');
299
+ assert.isNonNegativeInteger(exposure, 'exposure');
300
+ assert.notOk(this.#destroyed, 'destroyed');
301
+
302
+ const width = view.resolution[0];
303
+ const height = view.resolution[1];
304
+
305
+ if (!this.#built_for(width, height, settings)) {
306
+ this.#build(width, height, settings);
307
+ }
308
+
309
+ this.#view = view;
310
+ this.#settings = settings;
311
+ this.#world = world;
312
+ this.#stbn = stbn;
313
+
314
+ // the probes' place in their tiles, a Hammersley set over the period
315
+ this.#previous_jitter.set(this.#jitter);
316
+
317
+ hammersley_sequence_2d(this.#jitter_scratch, 0, this.#frame % SCREEN_PROBE_JITTER_PERIOD, SCREEN_PROBE_JITTER_PERIOD);
318
+
319
+ this.#jitter[0] = Math.floor(this.#jitter_scratch[0] * this.#downsample_factor);
320
+ this.#jitter[1] = Math.floor(this.#jitter_scratch[1] * this.#downsample_factor);
321
+
322
+ this.#parity = 1 - this.#parity;
323
+ this.#temporal_parity = 1 - this.#temporal_parity;
324
+
325
+ // another view's frames are no history of this one
326
+ if (view.id !== this.#view_id) {
327
+ this.#recorded = false;
328
+ this.#view_id = view.id;
329
+ }
330
+
331
+ // last frame's probes, radiance, diffuse and colour are this structure's where a frame was recorded since it was made
332
+ this.#history = this.#recorded;
333
+
334
+ this.#write_frame(world.brick_clipmap, settings);
335
+
336
+ const counters = graph_import_buffer(graph, this.#counters, 'screen probe counters');
337
+
338
+ const place = this.#place_data;
339
+ const place_pass = graph.add("Screen Probe Place", place, this.#execute_place);
340
+
341
+ place.counters = place_pass.write(counters);
342
+ place.depth = place_pass.read(depth);
343
+ place.pbr = place_pass.read(pbr);
344
+ place.velocity = place_pass.read(velocity);
345
+
346
+ place_pass.make_side_effect();
347
+
348
+ const trace = this.#trace_data;
349
+ const trace_pass = graph.add("Screen Probe Trace", trace, this.#execute_trace);
350
+
351
+ trace.counters = trace_pass.write(place.counters);
352
+ trace.depth = trace_pass.read(depth);
353
+ trace.normal = trace_pass.read(normal);
354
+ trace.pbr = trace_pass.read(pbr);
355
+ trace.velocity = trace_pass.read(velocity);
356
+ trace.occlusion = trace_pass.read(occlusion);
357
+ trace.hzb = trace_pass.read(hzb);
358
+ trace.exposure = trace_pass.read(exposure);
359
+ trace.bricks = trace_pass.read(world.bricks);
360
+ trace.cluster_lookup = trace_pass.read(world.clusters.lookup);
361
+ trace.cluster_data = trace_pass.read(world.clusters.data);
362
+
363
+ trace_pass.make_side_effect();
364
+
365
+ this.#recorded = true;
366
+ this.#frame++;
367
+ }
368
+
369
+ /**
370
+ * Take the frame's resolve, once the bent normals exist: each pixel's irradiance from its probes, then the temporal
371
+ * filter into the frame's diffuse.
372
+ *
373
+ * @param {Object} options
374
+ * @param {FrameGraph} options.graph
375
+ * @param {number} options.depth graph handle of the view's reverse-Z depth
376
+ * @param {number} options.depth_previous graph handle of last frame's
377
+ * @param {number} options.pbr graph handle of the G-buffer's PBR target
378
+ * @param {number} options.velocity graph handle of the frame's motion
379
+ * @param {number} options.bent_normals graph handle of the bent normals (the shading normals where GTAO is off)
380
+ * @param {number} options.exposure graph handle of the factor the display multiplies radiance by, as the last frame
381
+ * was shown, the one {@link graph_update} took: what the probes' radiance is pre-exposed by
382
+ * @returns {number} graph handle of the frame's diffuse, `rgba16float`: E at the bent normal, before AO
383
+ */
384
+ graph_resolve({ graph, depth, depth_previous, pbr, velocity, bent_normals, exposure }) {
385
+ assert.ok(this.#built, 'graph_update() first');
386
+
387
+ const data = this.#resolve_data;
388
+ const pass = graph.add("Screen Probe Resolve", data, this.#execute_resolve);
389
+
390
+ data.depth = pass.read(depth);
391
+ data.depth_previous = pass.read(depth_previous);
392
+ data.pbr = pass.read(pbr);
393
+ data.velocity = pass.read(velocity);
394
+ data.bent_normals = pass.read(bent_normals);
395
+ data.exposure = pass.read(exposure);
396
+ data.diffuse = pass.write(graph_import_texture(graph, this.#diffuse[this.#temporal_parity], 'screen probe diffuse'));
397
+
398
+ pass.make_side_effect();
399
+
400
+ this.#diffuse_handle = data.diffuse;
401
+
402
+ return data.diffuse;
403
+ }
404
+
405
+ /**
406
+ * @returns {number} graph handle of the diffuse this frame's {@link graph_resolve} wrote
407
+ */
408
+ get diffuse_handle() {
409
+ return this.#diffuse_handle;
410
+ }
411
+
412
+ /**
413
+ * Put what the debug views read of the frame's probes into `bindings`: the frame uniform, the probes and their
414
+ * tiles' adaptive lists, the integration's output and the rays' hit words, as this frame left them.
415
+ *
416
+ * @param {Object} bindings
417
+ * @returns {Object} bindings
418
+ */
419
+ write_debug_bindings(bindings) {
420
+ bindings.screen_probe_frame = this.#frame_buffer;
421
+ bindings.screen_probes = this.#probes[this.#parity];
422
+ bindings.screen_probe_tile_counts = this.#tile_counts;
423
+ bindings.screen_probe_tile_probes = this.#tile_probes;
424
+ bindings.screen_probe_integrated = this.#integrated;
425
+ bindings.screen_probe_trace_hit = this.#trace_hit;
426
+
427
+ return bindings;
428
+ }
429
+
430
+ /**
431
+ * Keep the frame's lit colour of the opaque surfaces for the next frame's screen hits: once the indirect light is
432
+ * added, before fog and transparencies.
433
+ *
434
+ * @param {Object} options
435
+ * @param {FrameGraph} options.graph
436
+ * @param {number} options.color graph handle of the scene's colour, the view's size
437
+ */
438
+ graph_capture({ graph, color }) {
439
+ assert.ok(this.#built, 'graph_update() first');
440
+
441
+ const data = this.#capture_data;
442
+ const pass = graph.add("Screen Probe Capture", data, this.#execute_capture);
443
+
444
+ data.color = pass.read(color);
445
+
446
+ pass.make_side_effect();
447
+ }
448
+
449
+ /**
450
+ * The frame uniform, written as the frame is recorded.
451
+ *
452
+ * @param {import("../probe_clipmap/brick/GPUBrickClipmap.js").GPUBrickClipmap} bricks
453
+ * @param {ScreenProbeSettings} settings
454
+ */
455
+ #write_frame(bricks, settings) {
456
+ const u = this.#frame_u32;
457
+ const f = this.#frame_f32;
458
+ u[frame_word('view_size')] = this.#view_width;
459
+ u[frame_word('view_size') + 1] = this.#view_height;
460
+ u[frame_word('tile_count')] = this.#tiles_x;
461
+ u[frame_word('tile_count') + 1] = this.#tiles_y;
462
+ u[frame_word('jitter')] = this.#jitter[0];
463
+ u[frame_word('jitter') + 1] = this.#jitter[1];
464
+ u[frame_word('previous_jitter')] = this.#previous_jitter[0];
465
+ u[frame_word('previous_jitter') + 1] = this.#previous_jitter[1];
466
+ // the structure holds while the history does, so last frame's grid is this one's
467
+ u[frame_word('previous_tile_count')] = this.#tiles_x;
468
+ u[frame_word('previous_tile_count') + 1] = this.#tiles_y;
469
+ f[frame_word('tile_count_x_reciprocal')] = 1 / this.#tiles_x;
470
+ u[frame_word('downsample_shift')] = this.#downsample_shift;
471
+ u[frame_word('octahedron_resolution')] = this.#octahedron_resolution;
472
+ u[frame_word('octahedron_shift')] = this.#octahedron_shift;
473
+ u[frame_word('uniform_count')] = this.#uniform_count;
474
+ u[frame_word('adaptive_capacity')] = this.#adaptive_capacity;
475
+ u[frame_word('adaptive_tile_capacity')] = this.#adaptive_tile_capacity;
476
+ u[frame_word('frame_index')] = this.#frame;
477
+ u[frame_word('history')] = this.#history ? 1 : 0;
478
+
479
+ const coarsest = bricks.cascade_count - 1;
480
+
481
+ // past the coarsest window's far corner every ray has left the world
482
+ f[frame_word('brick_t_max')] = Math.sqrt(3) * bricks.resolution * bricks.cell_size(coarsest);
483
+ u[frame_word('importance_sampling')] = settings.importance_sampling && this.#octahedron_resolution <= SCREEN_PROBE_OCTAHEDRON_LIMIT ? 1 : 0;
484
+ u[frame_word('screen_traces')] = settings.screen_traces ? 1 : 0;
485
+ u[frame_word('brick_cascade_count')] = bricks.cascade_count;
486
+ u[frame_word('brick_atlas_shift')] = bricks.atlas_shift;
487
+ f[frame_word('temporal_frames')] = settings.temporal_frames;
488
+
489
+ this.#device.queue.writeBuffer(this.#frame_buffer, 0, this.#frame_data);
490
+
491
+ }
492
+
493
+ /**
494
+ * Make every resource for a view of `width` × `height` and the settings' structure, giving back what stood.
495
+ *
496
+ * @param {number} width
497
+ * @param {number} height
498
+ * @param {ScreenProbeSettings} settings
499
+ */
500
+ #build(width, height, settings) {
501
+ const D = settings.downsample_factor;
502
+ const n = settings.octahedron_resolution;
503
+ const limits = this.#device.limits;
504
+
505
+ const levels = screen_probe_adaptive_levels(D, settings.adaptive_min_downsample_factor);
506
+ const tile_capacity = screen_probe_adaptive_tile_capacity(levels);
507
+ const tiles_x = Math.ceil(width / D);
508
+ const tiles_y = Math.ceil(height / D);
509
+ const uniform_count = tiles_x * tiles_y;
510
+ const adaptive_capacity = screen_probe_adaptive_capacity(uniform_count, levels);
511
+ const probes = uniform_count + adaptive_capacity;
512
+ const rows = tiles_y + Math.ceil(adaptive_capacity / tiles_x);
513
+
514
+ // every limit before anything is given back or made, so a structure the device refuses leaves what stood
515
+ assert.lessThanOrEqual(n, SCREEN_PROBE_OCTAHEDRON_LIMIT, 'octahedron_resolution, what a probe\'s workgroup sorts and accumulates in its memory (SCREEN_PROBE_OCTAHEDRON_LIMIT)');
516
+ assert.lessThan(probes, 2 ** (32 - SCREEN_PROBE_RAY_SLOT_BITS), 'the frame\'s probes, a ray id\'s probe bits');
517
+ assert.lessThanOrEqual(tiles_x * n, limits.maxTextureDimension2D, 'the probes\' atlas width, the view over downsample_factor times octahedron_resolution, past maxTextureDimension2D');
518
+ assert.lessThanOrEqual(rows * n, limits.maxTextureDimension2D, 'the probes\' atlas height past maxTextureDimension2D');
519
+
520
+ const buffer_sizes = [
521
+ ['tile counts', 4 * uniform_count],
522
+ ['tile probes', 4 * uniform_count * tile_capacity],
523
+ ['probes', SCREEN_PROBE_STRUCT.size * probes],
524
+ ['picks', SCREEN_PROBE_PICK_STRUCT.size * probes],
525
+ ['brdf', 48 * probes],
526
+ ['moving', 4 * probes],
527
+ ['sh', 28 * probes],
528
+ ['rays', SCREEN_PROBE_RAY_STRUCT.size * probes * n * n],
529
+ ];
530
+
531
+ for (const [name, size] of buffer_sizes) {
532
+ assert.lessThanOrEqual(size, limits.maxStorageBufferBindingSize, `screen probe ${name} past maxStorageBufferBindingSize: fewer probes (a larger downsample_factor) or rays (a smaller octahedron_resolution)`);
533
+ assert.lessThanOrEqual(size, limits.maxBufferSize, `screen probe ${name} past maxBufferSize`);
534
+ }
535
+
536
+ this.release();
537
+
538
+ this.#view_width = width;
539
+ this.#view_height = height;
540
+ this.#downsample_factor = D;
541
+ this.#octahedron_resolution = n;
542
+ this.#adaptive_min_downsample_factor = settings.adaptive_min_downsample_factor;
543
+
544
+ this.#downsample_shift = Math.log2(D);
545
+ this.#octahedron_shift = Math.log2(n);
546
+ this.#adaptive_levels = levels;
547
+ this.#adaptive_tile_capacity = tile_capacity;
548
+
549
+ this.#tiles_x = tiles_x;
550
+ this.#tiles_y = tiles_y;
551
+ this.#uniform_count = uniform_count;
552
+ this.#adaptive_capacity = adaptive_capacity;
553
+
554
+ const device = this.#device;
555
+ const buffer = (name, size, usage = 0) => device.createBuffer(BufferDescriptor.fromJSON({
556
+ label: `Screen probe / ${name}`,
557
+ size: Math.max(16, size),
558
+ usage: GPUBufferUsage.STORAGE | usage,
559
+ }));
560
+
561
+ this.#frame_buffer = device.createBuffer(BufferDescriptor.fromJSON({
562
+ label: 'Screen probe / frame',
563
+ size: SCREEN_PROBE_FRAME_STRUCT.size,
564
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
565
+ }));
566
+
567
+ this.#tile_counts = buffer('tile counts', 4 * uniform_count);
568
+ this.#tile_probes = buffer('tile probes', 4 * uniform_count * tile_capacity);
569
+ this.#dispatch = buffer('dispatch', 4 * SCREEN_PROBE_DISPATCH_WORDS, GPUBufferUsage.INDIRECT);
570
+ this.#counters = buffer('counters', 4 * SCREEN_PROBE_COUNTER_WORDS, GPUBufferUsage.COPY_DST);
571
+
572
+ const view_texture = (name, format) => this.#texture(`screen probe ${name}`, [width, height], format);
573
+
574
+ this.#integrated = view_texture('integrated', 'rgba16float');
575
+ this.#diffuse = [view_texture('diffuse 0', 'rgba16float'), view_texture('diffuse 1', 'rgba16float')];
576
+ this.#frames = [view_texture('frames 0', 'r32uint'), view_texture('frames 1', 'r32uint')];
577
+ this.#color_history = view_texture('color history', 'rgba16float');
578
+
579
+ const exposure_slot = name => device.createBuffer(BufferDescriptor.fromJSON({
580
+ label: `Screen probe / ${name}`,
581
+ size: 16,
582
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
583
+ }));
584
+
585
+ this.#exposure_history = [exposure_slot('exposure 0'), exposure_slot('exposure 1')];
586
+
587
+ this.#probes = [buffer('probes 0', SCREEN_PROBE_STRUCT.size * probes), buffer('probes 1', SCREEN_PROBE_STRUCT.size * probes)];
588
+ this.#picks = buffer('picks', SCREEN_PROBE_PICK_STRUCT.size * probes);
589
+ this.#brdf = buffer('brdf', 48 * probes);
590
+ this.#moving = buffer('moving', 4 * probes);
591
+ this.#sh = buffer('sh', 28 * probes);
592
+
593
+ this.#ray_capacity = probes * n * n;
594
+ this.#rays = buffer('rays', SCREEN_PROBE_RAY_STRUCT.size * this.#ray_capacity);
595
+
596
+ const atlas = [tiles_x * n, rows * n];
597
+
598
+ this.#ray_info = this.#texture('screen probe ray info', atlas, 'r32uint');
599
+ this.#trace_radiance = this.#texture('screen probe trace radiance', atlas, 'rgba16float');
600
+ this.#trace_hit = this.#texture('screen probe trace hit', atlas, 'r32uint');
601
+ this.#lighting_pdf = this.#texture('screen probe lighting pdf', atlas, 'r32float');
602
+ this.#radiance = [this.#texture('screen probe radiance 0', atlas, 'rgba16float'), this.#texture('screen probe radiance 1', atlas, 'rgba16float')];
603
+
604
+ this.#brick_command_settings.capacity = this.#ray_capacity;
605
+ this.#trace_screen_settings.capacity = this.#ray_capacity;
606
+
607
+ this.#built = true;
608
+ this.#history = false;
609
+ this.#recorded = false;
610
+ }
611
+
612
+ /**
613
+ * @param {string} label
614
+ * @param {number[]} size
615
+ * @param {GPUTextureFormat} format
616
+ * @returns {GPUTextureContext}
617
+ */
618
+ #texture(label, size, format) {
619
+ const texture = new GPUTextureContext(this.#device);
620
+
621
+ texture.descriptor = TextureDescriptor.from({
622
+ label,
623
+ size,
624
+ format,
625
+ mipLevelCount: 1,
626
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.STORAGE_BINDING,
627
+ });
628
+
629
+ return texture;
630
+ }
631
+
632
+ #execute_place = (data, resources, context) => {
633
+ const encoder = context.encoder;
634
+ const b = this.#b;
635
+ const counters = resources.get(data.counters);
636
+
637
+ encoder.clearBuffer(counters);
638
+
639
+ b.screen_probe_frame = this.#frame_buffer;
640
+ b.camera = this.#view.camera.gpu_buffer;
641
+ b.camera_previous = this.#view.gpu_previous_camera_state.gpu_buffer;
642
+ b.tDepth = resources.get(data.depth);
643
+ b.tPBR = resources.get(data.pbr);
644
+ b.tVelocity = resources.get(data.velocity);
645
+ b.screen_probes = this.#probes[this.#parity];
646
+ b.screen_probe_tile_counts = this.#tile_counts;
647
+ b.screen_probe_tile_probes = this.#tile_probes;
648
+ b.screen_probe_counters = counters;
649
+ b.screen_probe_dispatch = this.#dispatch;
650
+
651
+ const groups = SCREEN_PROBE_TILE_WORKGROUP_SIZE;
652
+
653
+ shader_screen_probe_place_uniform.dispatch({
654
+ encoder,
655
+ bindings: b,
656
+ group_count_x: Math.ceil(this.#tiles_x / groups),
657
+ group_count_y: Math.ceil(this.#tiles_y / groups),
658
+ });
659
+
660
+ const settings = this.#adaptive_settings;
661
+
662
+ b.settings = settings;
663
+
664
+ for (let level = 1; level <= this.#adaptive_levels; level++) {
665
+ settings.level = level;
666
+
667
+ const spacing = this.#downsample_factor >>> level;
668
+
669
+ shader_screen_probe_place_adaptive.dispatch({
670
+ encoder,
671
+ bindings: b,
672
+ group_count_x: Math.ceil(Math.ceil(this.#view_width / spacing) / groups),
673
+ group_count_y: Math.ceil(Math.ceil(this.#view_height / spacing) / groups),
674
+ });
675
+ }
676
+
677
+ shader_screen_probe_command.dispatch({ encoder, bindings: b });
678
+ };
679
+
680
+ #execute_trace = (data, resources, context) => {
681
+ const encoder = context.encoder;
682
+ const b = this.#b;
683
+ const world = this.#world;
684
+ const view = this.#view;
685
+ const scene = view.scene;
686
+ const lights = scene.lights;
687
+ const dispatch = this.#dispatch;
688
+
689
+ const current = this.#probes[this.#parity];
690
+ const previous = this.#probes[1 - this.#parity];
691
+ const history_radiance = this.#radiance[this.#radiance_final];
692
+
693
+ b.screen_probe_frame = this.#frame_buffer;
694
+ b.camera = view.camera.gpu_buffer;
695
+ b.camera_previous = view.gpu_previous_camera_state.gpu_buffer;
696
+ b.screen_probes = current;
697
+ b.screen_probes_previous = previous;
698
+ b.screen_probe_picks = this.#picks;
699
+ b.screen_probe_dispatch = dispatch;
700
+ b.screen_probe_counters = resources.get(data.counters);
701
+ b.screen_probe_brdf = this.#brdf;
702
+ b.screen_probe_moving = this.#moving;
703
+ b.screen_probe_sh = this.#sh;
704
+ b.screen_probe_rays = this.#rays;
705
+ b.tSTBN_vec2 = this.#stbn;
706
+ b.tDepth = resources.get(data.depth);
707
+ b.tNormal = resources.get(data.normal);
708
+ b.tPBR = resources.get(data.pbr);
709
+ b.tVelocity = resources.get(data.velocity);
710
+ b.tOcclusion = resources.get(data.occlusion);
711
+ b.tHZB = resources.get(data.hzb);
712
+ b.screen_probe_exposure = resources.get(data.exposure);
713
+ b.screen_probe_exposure_previous = this.#exposure_history[1 - this.#parity];
714
+ b.screen_probe_color_history = this.#color_history.obtainView();
715
+ b.screen_probe_radiance_history = history_radiance.obtainView();
716
+ b.screen_probe_ray_info = this.#ray_info.obtainView();
717
+ b.screen_probe_trace_radiance = this.#trace_radiance.obtainView();
718
+ b.screen_probe_trace_hit = this.#trace_hit.obtainView();
719
+ b.screen_probe_lighting_pdf = this.#lighting_pdf.obtainView();
720
+
721
+ // the exposure this frame pre-exposes by, which next frame's lighting density brings last frame's radiance from
722
+ encoder.copyBufferToBuffer(b.screen_probe_exposure, 0, this.#exposure_history[this.#parity], 0, 4);
723
+
724
+ // the frustum's world-space probes: what the pick reads and the late set it wants into; the bricks' field, which
725
+ // places its rays' origin
726
+ world.probe_clipmap.write_sampling_bindings(b);
727
+ world.probe_clipmap.write_want_bindings(b);
728
+ world.brick_clipmap.write_bindings(b);
729
+
730
+ shader_screen_probe_pick.dispatchIndirect({ encoder, bindings: b, command: dispatch, command_offset: 4 * SCREEN_PROBE_DISPATCH_THREADS });
731
+
732
+ // the densities and the rays, a workgroup a probe
733
+ shader_screen_probe_brdf_pdf.dispatchIndirect({ encoder, bindings: b, command: dispatch, command_offset: 4 * SCREEN_PROBE_DISPATCH_PROBES });
734
+
735
+ if (this.#settings.importance_sampling) {
736
+ // the want pass's settings were the late set's; the pick's bindings stand for the radiance read here
737
+ world.probe_clipmap.write_sampling_bindings(b);
738
+
739
+ shader_screen_probe_lighting_pdf.dispatchIndirect({ encoder, bindings: b, command: dispatch, command_offset: 4 * SCREEN_PROBE_DISPATCH_PROBES });
740
+ }
741
+
742
+ shader_screen_probe_generate_rays.dispatchIndirect({ encoder, bindings: b, command: dispatch, command_offset: 4 * SCREEN_PROBE_DISPATCH_PROBES });
743
+
744
+ // the screen, then the bricks for what it left
745
+ b.settings = this.#trace_screen_settings;
746
+
747
+ shader_screen_probe_trace_screen.dispatchIndirect({ encoder, bindings: b, command: dispatch, command_offset: 4 * SCREEN_PROBE_DISPATCH_RAYS });
748
+
749
+ b.settings = this.#brick_command_settings;
750
+
751
+ shader_screen_probe_brick_command.dispatch({ encoder, bindings: b });
752
+
753
+ world.material.write_bindings(b);
754
+
755
+ b.light_data = lights.buffer_data;
756
+ b.tEnvironment = lights.environment.obtainView();
757
+ b.world_cluster_lookup = resources.get(data.cluster_lookup);
758
+ b.world_cluster_data = resources.get(data.cluster_data);
759
+
760
+ shader_screen_probe_brick_trace.dispatchIndirect({ encoder, bindings: b, command: dispatch, command_offset: 4 * SCREEN_PROBE_DISPATCH_BRICK_RAYS });
761
+
762
+ world.probe_clipmap.write_sampling_bindings(b);
763
+
764
+ shader_screen_probe_brick_shade.dispatchIndirect({ encoder, bindings: b, command: dispatch, command_offset: 4 * SCREEN_PROBE_DISPATCH_BRICK_RAYS });
765
+ shader_screen_probe_brick_light.dispatchIndirect({ encoder, bindings: b, command: dispatch, command_offset: 4 * SCREEN_PROBE_DISPATCH_BRICK_RAYS });
766
+
767
+ // the bounce from the frustum's world probes, the world cache's where they have none
768
+ const sets = this.#sets;
769
+
770
+ world.probe_clipmap.write_sampling_bindings(sets);
771
+ b.bounce_first_levels = sets.probe_levels;
772
+ b.bounce_first_sampling = sets.probe_sampling;
773
+ b.bounce_first_indirection = sets.probe_indirection;
774
+ b.bounce_first_states = sets.probe_states;
775
+ b.bounce_first_records = sets.probe_records;
776
+ b.bounce_first_depth = sets.probe_depth;
777
+
778
+ world.world_cache.write_sampling_bindings(sets);
779
+ b.bounce_fallback_levels = sets.probe_levels;
780
+ b.bounce_fallback_sampling = sets.probe_sampling;
781
+ b.bounce_fallback_indirection = sets.probe_indirection;
782
+ b.bounce_fallback_states = sets.probe_states;
783
+ b.bounce_fallback_records = sets.probe_records;
784
+ b.bounce_fallback_depth = sets.probe_depth;
785
+
786
+ shader_screen_probe_brick_bounce.dispatchIndirect({ encoder, bindings: b, command: dispatch, command_offset: 4 * SCREEN_PROBE_DISPATCH_BRICK_RAYS });
787
+
788
+ // the hits the frustum's probes did not serve want the world cache's
789
+ world.world_cache.write_want_bindings(b);
790
+
791
+ shader_screen_probe_brick_want.dispatchIndirect({ encoder, bindings: b, command: dispatch, command_offset: 4 * SCREEN_PROBE_DISPATCH_BRICK_RAYS });
792
+
793
+ // each probe's radiance from its rays, then the filter's passes trading the two atlases
794
+ const radiance = this.#radiance;
795
+ let write = 1 - this.#radiance_final;
796
+
797
+ b.screen_probe_radiance_out = radiance[write].obtainView();
798
+
799
+ shader_screen_probe_composite.dispatchIndirect({ encoder, bindings: b, command: dispatch, command_offset: 4 * SCREEN_PROBE_DISPATCH_PROBES });
800
+
801
+ for (let pass = 0; pass < this.#settings.spatial_filter_passes; pass++) {
802
+ b.screen_probe_radiance = radiance[write].obtainView();
803
+
804
+ write = 1 - write;
805
+
806
+ b.screen_probe_radiance_out = radiance[write].obtainView();
807
+
808
+ shader_screen_probe_filter.dispatchIndirect({ encoder, bindings: b, command: dispatch, command_offset: 4 * SCREEN_PROBE_DISPATCH_RAYS });
809
+ }
810
+
811
+ this.#radiance_final = write;
812
+
813
+ b.screen_probe_radiance = radiance[write].obtainView();
814
+
815
+ shader_screen_probe_irradiance.dispatchIndirect({ encoder, bindings: b, command: dispatch, command_offset: 4 * SCREEN_PROBE_DISPATCH_PROBES });
816
+ };
817
+
818
+ #execute_resolve = (data, resources, context) => {
819
+ const encoder = context.encoder;
820
+ const b = this.#b;
821
+ const groups = SCREEN_PROBE_TILE_WORKGROUP_SIZE;
822
+
823
+ b.screen_probe_frame = this.#frame_buffer;
824
+ b.camera = this.#view.camera.gpu_buffer;
825
+ b.camera_previous = this.#view.gpu_previous_camera_state.gpu_buffer;
826
+ b.screen_probes = this.#probes[this.#parity];
827
+ b.screen_probe_tile_counts = this.#tile_counts;
828
+ b.screen_probe_tile_probes = this.#tile_probes;
829
+ b.screen_probe_sh = this.#sh;
830
+ b.screen_probe_moving = this.#moving;
831
+ b.tSTBN_vec2 = this.#stbn;
832
+ b.tDepth = resources.get(data.depth);
833
+ b.tDepthPrevious = resources.get(data.depth_previous);
834
+ b.tPBR = resources.get(data.pbr);
835
+ b.tVelocity = resources.get(data.velocity);
836
+ b.tBentNormals = resources.get(data.bent_normals);
837
+ b.screen_probe_exposure = resources.get(data.exposure);
838
+ b.screen_probe_integrated = this.#integrated.obtainView();
839
+
840
+ const x = Math.ceil(this.#view_width / groups);
841
+ const y = Math.ceil(this.#view_height / groups);
842
+
843
+ shader_screen_probe_integrate.dispatch({ encoder, bindings: b, group_count_x: x, group_count_y: y });
844
+
845
+ const now = this.#temporal_parity;
846
+
847
+ b.screen_probe_diffuse_history = this.#diffuse[1 - now].obtainView();
848
+ b.screen_probe_frames_history = this.#frames[1 - now].obtainView();
849
+ b.screen_probe_diffuse = resources.get(data.diffuse);
850
+ b.screen_probe_frames = this.#frames[now].obtainView();
851
+
852
+ shader_screen_probe_temporal.dispatch({ encoder, bindings: b, group_count_x: x, group_count_y: y });
853
+ };
854
+
855
+ #execute_capture = (data, resources, context) => {
856
+ const b = this.#b;
857
+ const groups = SCREEN_PROBE_TILE_WORKGROUP_SIZE;
858
+
859
+ b.tColor = resources.get(data.color);
860
+ b.screen_probe_color_history = this.#color_history.obtainView();
861
+
862
+ shader_screen_probe_color_capture.dispatch({
863
+ encoder: context.encoder,
864
+ bindings: b,
865
+ group_count_x: Math.ceil(this.#view_width / groups),
866
+ group_count_y: Math.ceil(this.#view_height / groups),
867
+ });
868
+ };
869
+
870
+ #release_probe_resources() {
871
+ for (const buffer of [...this.#probes, this.#picks, this.#brdf, this.#moving, this.#sh, this.#rays]) {
872
+ buffer?.destroy();
873
+ }
874
+
875
+ for (const texture of [this.#ray_info, this.#trace_radiance, this.#trace_hit, this.#lighting_pdf, ...this.#radiance]) {
876
+ texture?.destroy();
877
+ }
878
+
879
+ this.#probes = [];
880
+ this.#picks = null;
881
+ this.#brdf = null;
882
+ this.#moving = null;
883
+ this.#sh = null;
884
+ this.#rays = null;
885
+ this.#ray_info = null;
886
+ this.#trace_radiance = null;
887
+ this.#trace_hit = null;
888
+ this.#lighting_pdf = null;
889
+ this.#radiance = [];
890
+ }
891
+
892
+ /**
893
+ * Give back every resource, as on the first frame out of the mode: the next {@link graph_update} starts again
894
+ * from nothing.
895
+ */
896
+ release() {
897
+ if (!this.#built) {
898
+ return;
899
+ }
900
+
901
+ this.#release_probe_resources();
902
+
903
+ for (const buffer of [this.#frame_buffer, this.#tile_counts, this.#tile_probes, this.#dispatch, this.#counters, ...this.#exposure_history]) {
904
+ buffer?.destroy();
905
+ }
906
+
907
+ for (const texture of [this.#integrated, ...this.#diffuse, ...this.#frames, this.#color_history]) {
908
+ texture?.destroy();
909
+ }
910
+
911
+ this.#frame_buffer = null;
912
+ this.#tile_counts = null;
913
+ this.#tile_probes = null;
914
+ this.#dispatch = null;
915
+ this.#counters = null;
916
+ this.#exposure_history = [];
917
+ this.#integrated = null;
918
+ this.#diffuse = [];
919
+ this.#frames = [];
920
+ this.#color_history = null;
921
+
922
+ this.#built = false;
923
+ this.#history = false;
924
+ this.#recorded = false;
925
+ this.#view = null;
926
+ this.#world = null;
927
+ }
928
+
929
+ destroy() {
930
+ if (this.#destroyed) {
931
+ return;
932
+ }
933
+
934
+ this.#destroyed = true;
935
+
936
+ this.release();
937
+ }
938
+ }