@pmndrs/vdb 0.0.0-stage → 0.2.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 (570) hide show
  1. package/CHANGELOG.md +727 -0
  2. package/LICENSE +21 -0
  3. package/README.md +496 -2
  4. package/THIRD_PARTY_NOTICES.md +315 -0
  5. package/dist/core/compute/atlas.d.ts +102 -0
  6. package/dist/core/compute/atlas.js +103 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/majorant-build.d.ts +45 -0
  12. package/dist/core/compute/majorant-build.js +193 -0
  13. package/dist/core/compute/majorant-build.js.map +1 -0
  14. package/dist/core/compute/multi-scale.d.ts +155 -0
  15. package/dist/core/compute/multi-scale.js +684 -0
  16. package/dist/core/compute/multi-scale.js.map +1 -0
  17. package/dist/core/compute/pyramid.d.ts +120 -0
  18. package/dist/core/compute/pyramid.js +468 -0
  19. package/dist/core/compute/pyramid.js.map +1 -0
  20. package/dist/core/compute/shared.d.ts +116 -0
  21. package/dist/core/compute/shared.js +211 -0
  22. package/dist/core/compute/shared.js.map +1 -0
  23. package/dist/core/compute/stats.d.ts +78 -0
  24. package/dist/core/compute/stats.js +193 -0
  25. package/dist/core/compute/stats.js.map +1 -0
  26. package/dist/core/compute/value-transform.d.ts +30 -0
  27. package/dist/core/compute/value-transform.js +64 -0
  28. package/dist/core/compute/value-transform.js.map +1 -0
  29. package/dist/core/errors.d.ts +21 -0
  30. package/dist/core/errors.js +17 -0
  31. package/dist/core/errors.js.map +1 -0
  32. package/dist/core/frame/emission.d.ts +85 -0
  33. package/dist/core/frame/emission.js +422 -0
  34. package/dist/core/frame/emission.js.map +1 -0
  35. package/dist/core/frame/environment.d.ts +47 -0
  36. package/dist/core/frame/environment.js +178 -0
  37. package/dist/core/frame/environment.js.map +1 -0
  38. package/dist/core/frame/index.d.ts +39 -0
  39. package/dist/core/frame/index.js +27 -0
  40. package/dist/core/frame/index.js.map +1 -0
  41. package/dist/core/frame/kernels.d.ts +115 -0
  42. package/dist/core/frame/kernels.js +496 -0
  43. package/dist/core/frame/kernels.js.map +1 -0
  44. package/dist/core/frame/limits.d.ts +67 -0
  45. package/dist/core/frame/limits.js +109 -0
  46. package/dist/core/frame/limits.js.map +1 -0
  47. package/dist/core/frame/phase.d.ts +17 -0
  48. package/dist/core/frame/phase.js +53 -0
  49. package/dist/core/frame/phase.js.map +1 -0
  50. package/dist/core/frame/pipelines.d.ts +49 -0
  51. package/dist/core/frame/pipelines.js +147 -0
  52. package/dist/core/frame/pipelines.js.map +1 -0
  53. package/dist/core/frame/renderer.d.ts +122 -0
  54. package/dist/core/frame/renderer.js +1712 -0
  55. package/dist/core/frame/renderer.js.map +1 -0
  56. package/dist/core/frame/resources.d.ts +71 -0
  57. package/dist/core/frame/resources.js +100 -0
  58. package/dist/core/frame/resources.js.map +1 -0
  59. package/dist/core/frame/scattering.d.ts +97 -0
  60. package/dist/core/frame/scattering.js +332 -0
  61. package/dist/core/frame/scattering.js.map +1 -0
  62. package/dist/core/frame/settings.d.ts +243 -0
  63. package/dist/core/frame/settings.js +67 -0
  64. package/dist/core/frame/settings.js.map +1 -0
  65. package/dist/core/frame/shadows.d.ts +55 -0
  66. package/dist/core/frame/shadows.js +460 -0
  67. package/dist/core/frame/shadows.js.map +1 -0
  68. package/dist/core/frame/types.d.ts +415 -0
  69. package/dist/core/frame/types.js +49 -0
  70. package/dist/core/frame/types.js.map +1 -0
  71. package/dist/core/frame/uniforms.d.ts +105 -0
  72. package/dist/core/frame/uniforms.js +276 -0
  73. package/dist/core/frame/uniforms.js.map +1 -0
  74. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  75. package/dist/core/frame/wgsl/chunks.js +728 -0
  76. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  77. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  78. package/dist/core/frame/wgsl/emission.js +353 -0
  79. package/dist/core/frame/wgsl/emission.js.map +1 -0
  80. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  81. package/dist/core/frame/wgsl/environment.js +711 -0
  82. package/dist/core/frame/wgsl/environment.js.map +1 -0
  83. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  84. package/dist/core/frame/wgsl/gather.js +850 -0
  85. package/dist/core/frame/wgsl/gather.js.map +1 -0
  86. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  87. package/dist/core/frame/wgsl/integrate.js +213 -0
  88. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  89. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  90. package/dist/core/frame/wgsl/lighting.js +1636 -0
  91. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  92. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  93. package/dist/core/frame/wgsl/occluders.js +95 -0
  94. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  95. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  96. package/dist/core/frame/wgsl/resolve.js +205 -0
  97. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  98. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  99. package/dist/core/frame/wgsl/shadows.js +328 -0
  100. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  101. package/dist/core/half.d.ts +11 -0
  102. package/dist/core/half.js +22 -0
  103. package/dist/core/half.js.map +1 -0
  104. package/dist/core/index.d.ts +52 -0
  105. package/dist/core/index.js +46 -0
  106. package/dist/core/index.js.map +1 -0
  107. package/dist/core/internal.d.ts +31 -0
  108. package/dist/core/internal.js +32 -0
  109. package/dist/core/internal.js.map +1 -0
  110. package/dist/core/pool/affine.d.ts +34 -0
  111. package/dist/core/pool/affine.js +100 -0
  112. package/dist/core/pool/affine.js.map +1 -0
  113. package/dist/core/pool/allocator.d.ts +32 -0
  114. package/dist/core/pool/allocator.js +81 -0
  115. package/dist/core/pool/allocator.js.map +1 -0
  116. package/dist/core/pool/image-header.d.ts +93 -0
  117. package/dist/core/pool/image-header.js +194 -0
  118. package/dist/core/pool/image-header.js.map +1 -0
  119. package/dist/core/pool/layout.d.ts +198 -0
  120. package/dist/core/pool/layout.js +316 -0
  121. package/dist/core/pool/layout.js.map +1 -0
  122. package/dist/core/pool/limits.d.ts +41 -0
  123. package/dist/core/pool/limits.js +80 -0
  124. package/dist/core/pool/limits.js.map +1 -0
  125. package/dist/core/pool/pool.d.ts +384 -0
  126. package/dist/core/pool/pool.js +1184 -0
  127. package/dist/core/pool/pool.js.map +1 -0
  128. package/dist/core/reference/index.d.ts +6 -0
  129. package/dist/core/reference/index.js +7 -0
  130. package/dist/core/reference/index.js.map +1 -0
  131. package/dist/core/reference/renderer.d.ts +105 -0
  132. package/dist/core/reference/renderer.js +474 -0
  133. package/dist/core/reference/renderer.js.map +1 -0
  134. package/dist/core/reference/wgsl.d.ts +65 -0
  135. package/dist/core/reference/wgsl.js +803 -0
  136. package/dist/core/reference/wgsl.js.map +1 -0
  137. package/dist/core/sequence.d.ts +347 -0
  138. package/dist/core/sequence.js +548 -0
  139. package/dist/core/sequence.js.map +1 -0
  140. package/dist/core/source/brick-cache.d.ts +165 -0
  141. package/dist/core/source/brick-cache.js +627 -0
  142. package/dist/core/source/brick-cache.js.map +1 -0
  143. package/dist/core/source/dense-fill.d.ts +53 -0
  144. package/dist/core/source/dense-fill.js +377 -0
  145. package/dist/core/source/dense-fill.js.map +1 -0
  146. package/dist/core/source/dense.d.ts +50 -0
  147. package/dist/core/source/dense.js +384 -0
  148. package/dist/core/source/dense.js.map +1 -0
  149. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  150. package/dist/core/source/sparse-wgsl.js +481 -0
  151. package/dist/core/source/sparse-wgsl.js.map +1 -0
  152. package/dist/core/source/sparse.d.ts +192 -0
  153. package/dist/core/source/sparse.js +762 -0
  154. package/dist/core/source/sparse.js.map +1 -0
  155. package/dist/core/source/types.d.ts +120 -0
  156. package/dist/core/source/types.js +9 -0
  157. package/dist/core/source/types.js.map +1 -0
  158. package/dist/core/surface/index.d.ts +10 -0
  159. package/dist/core/surface/index.js +9 -0
  160. package/dist/core/surface/index.js.map +1 -0
  161. package/dist/core/surface/level-set-pass.d.ts +140 -0
  162. package/dist/core/surface/level-set-pass.js +291 -0
  163. package/dist/core/surface/level-set-pass.js.map +1 -0
  164. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  165. package/dist/core/surface/level-set-wgsl.js +99 -0
  166. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  167. package/dist/core/surface/points.d.ts +109 -0
  168. package/dist/core/surface/points.js +226 -0
  169. package/dist/core/surface/points.js.map +1 -0
  170. package/dist/core/types.d.ts +37 -0
  171. package/dist/core/types.js +32 -0
  172. package/dist/core/types.js.map +1 -0
  173. package/dist/core/wgsl/api.d.ts +65 -0
  174. package/dist/core/wgsl/api.js +546 -0
  175. package/dist/core/wgsl/api.js.map +1 -0
  176. package/dist/core/wgsl/generate.d.ts +90 -0
  177. package/dist/core/wgsl/generate.js +678 -0
  178. package/dist/core/wgsl/generate.js.map +1 -0
  179. package/dist/core/wgsl/lean.d.ts +50 -0
  180. package/dist/core/wgsl/lean.js +327 -0
  181. package/dist/core/wgsl/lean.js.map +1 -0
  182. package/dist/core/wgsl/level-set.d.ts +58 -0
  183. package/dist/core/wgsl/level-set.js +200 -0
  184. package/dist/core/wgsl/level-set.js.map +1 -0
  185. package/dist/core/wgsl/majorant.d.ts +62 -0
  186. package/dist/core/wgsl/majorant.js +381 -0
  187. package/dist/core/wgsl/majorant.js.map +1 -0
  188. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  189. package/dist/core/wgsl/pnanovdb.chunks.generated.js +333 -0
  190. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  191. package/dist/core/wgsl/reserved.d.ts +9 -0
  192. package/dist/core/wgsl/reserved.js +26 -0
  193. package/dist/core/wgsl/reserved.js.map +1 -0
  194. package/dist/core/wgsl/types.d.ts +198 -0
  195. package/dist/core/wgsl/types.js +2 -0
  196. package/dist/core/wgsl/types.js.map +1 -0
  197. package/dist/three/coarse-first.d.ts +207 -0
  198. package/dist/three/coarse-first.js +205 -0
  199. package/dist/three/coarse-first.js.map +1 -0
  200. package/dist/three/compute.d.ts +73 -0
  201. package/dist/three/compute.js +66 -0
  202. package/dist/three/compute.js.map +1 -0
  203. package/dist/three/device.d.ts +66 -0
  204. package/dist/three/device.js +62 -0
  205. package/dist/three/device.js.map +1 -0
  206. package/dist/three/frame/core-environment.d.ts +38 -0
  207. package/dist/three/frame/core-environment.js +154 -0
  208. package/dist/three/frame/core-environment.js.map +1 -0
  209. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  210. package/dist/three/frame/core-integrate-material.js +162 -0
  211. package/dist/three/frame/core-integrate-material.js.map +1 -0
  212. package/dist/three/frame/core-occluders.d.ts +53 -0
  213. package/dist/three/frame/core-occluders.js +193 -0
  214. package/dist/three/frame/core-occluders.js.map +1 -0
  215. package/dist/three/frame/core-structs.d.ts +34 -0
  216. package/dist/three/frame/core-structs.js +61 -0
  217. package/dist/three/frame/core-structs.js.map +1 -0
  218. package/dist/three/frame/core-textures.d.ts +41 -0
  219. package/dist/three/frame/core-textures.js +114 -0
  220. package/dist/three/frame/core-textures.js.map +1 -0
  221. package/dist/three/frame/emission-light.d.ts +117 -0
  222. package/dist/three/frame/emission-light.js +276 -0
  223. package/dist/three/frame/emission-light.js.map +1 -0
  224. package/dist/three/frame/index.d.ts +19 -0
  225. package/dist/three/frame/index.js +15 -0
  226. package/dist/three/frame/index.js.map +1 -0
  227. package/dist/three/frame/medium.d.ts +33 -0
  228. package/dist/three/frame/medium.js +29 -0
  229. package/dist/three/frame/medium.js.map +1 -0
  230. package/dist/three/frame/renderer.d.ts +97 -0
  231. package/dist/three/frame/renderer.js +480 -0
  232. package/dist/three/frame/renderer.js.map +1 -0
  233. package/dist/three/frame/spectrum.d.ts +4 -0
  234. package/dist/three/frame/spectrum.js +15 -0
  235. package/dist/three/frame/spectrum.js.map +1 -0
  236. package/dist/three/frame/three-internals.d.ts +60 -0
  237. package/dist/three/frame/three-internals.js +152 -0
  238. package/dist/three/frame/three-internals.js.map +1 -0
  239. package/dist/three/frame/volume-shadows.d.ts +139 -0
  240. package/dist/three/frame/volume-shadows.js +403 -0
  241. package/dist/three/frame/volume-shadows.js.map +1 -0
  242. package/dist/three/frame/volume.d.ts +230 -0
  243. package/dist/three/frame/volume.js +268 -0
  244. package/dist/three/frame/volume.js.map +1 -0
  245. package/dist/three/grid-node.d.ts +229 -0
  246. package/dist/three/grid-node.js +545 -0
  247. package/dist/three/grid-node.js.map +1 -0
  248. package/dist/three/index.d.ts +52 -0
  249. package/dist/three/index.js +58 -0
  250. package/dist/three/index.js.map +1 -0
  251. package/dist/three/internal.d.ts +20 -0
  252. package/dist/three/internal.js +18 -0
  253. package/dist/three/internal.js.map +1 -0
  254. package/dist/three/level-set-material.d.ts +185 -0
  255. package/dist/three/level-set-material.js +241 -0
  256. package/dist/three/level-set-material.js.map +1 -0
  257. package/dist/three/level-set-physical-material.d.ts +154 -0
  258. package/dist/three/level-set-physical-material.js +253 -0
  259. package/dist/three/level-set-physical-material.js.map +1 -0
  260. package/dist/three/level-set-velocity.d.ts +94 -0
  261. package/dist/three/level-set-velocity.js +208 -0
  262. package/dist/three/level-set-velocity.js.map +1 -0
  263. package/dist/three/material.d.ts +324 -0
  264. package/dist/three/material.js +502 -0
  265. package/dist/three/material.js.map +1 -0
  266. package/dist/three/points.d.ts +140 -0
  267. package/dist/three/points.js +261 -0
  268. package/dist/three/points.js.map +1 -0
  269. package/dist/three/sparse-source.d.ts +165 -0
  270. package/dist/three/sparse-source.js +405 -0
  271. package/dist/three/sparse-source.js.map +1 -0
  272. package/dist/three/volume-source.d.ts +22 -0
  273. package/dist/three/volume-source.js +110 -0
  274. package/dist/three/volume-source.js.map +1 -0
  275. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  276. package/dist/tools/cpu/brick-atlas.js +129 -0
  277. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  278. package/dist/tools/cpu/compute.d.ts +116 -0
  279. package/dist/tools/cpu/compute.js +239 -0
  280. package/dist/tools/cpu/compute.js.map +1 -0
  281. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  282. package/dist/tools/cpu/lean-reads.js +262 -0
  283. package/dist/tools/cpu/lean-reads.js.map +1 -0
  284. package/dist/tools/cpu/level-set.d.ts +111 -0
  285. package/dist/tools/cpu/level-set.js +313 -0
  286. package/dist/tools/cpu/level-set.js.map +1 -0
  287. package/dist/tools/cpu/majorant.d.ts +265 -0
  288. package/dist/tools/cpu/majorant.js +541 -0
  289. package/dist/tools/cpu/majorant.js.map +1 -0
  290. package/dist/tools/cpu/march.d.ts +297 -0
  291. package/dist/tools/cpu/march.js +726 -0
  292. package/dist/tools/cpu/march.js.map +1 -0
  293. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  294. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  295. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  296. package/dist/tools/cpu/points.d.ts +29 -0
  297. package/dist/tools/cpu/points.js +38 -0
  298. package/dist/tools/cpu/points.js.map +1 -0
  299. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  300. package/dist/tools/cpu/probe-coords.js +116 -0
  301. package/dist/tools/cpu/probe-coords.js.map +1 -0
  302. package/dist/tools/cpu/read-value.d.ts +44 -0
  303. package/dist/tools/cpu/read-value.js +351 -0
  304. package/dist/tools/cpu/read-value.js.map +1 -0
  305. package/dist/tools/cpu/sample-trilinear.d.ts +43 -0
  306. package/dist/tools/cpu/sample-trilinear.js +168 -0
  307. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  308. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  309. package/dist/tools/cpu/stride-tables.generated.d.ts +1059 -0
  310. package/dist/tools/cpu/stride-tables.generated.js +1267 -0
  311. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  312. package/dist/tools/cpu/stride-tables.js +78 -0
  313. package/dist/tools/cpu/stride-tables.js.map +1 -0
  314. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  315. package/dist/tools/cpu/surface-nets.js +597 -0
  316. package/dist/tools/cpu/surface-nets.js.map +1 -0
  317. package/dist/tools/errors.d.ts +66 -0
  318. package/dist/tools/errors.js +67 -0
  319. package/dist/tools/errors.js.map +1 -0
  320. package/dist/tools/frame/ambient.d.ts +98 -0
  321. package/dist/tools/frame/ambient.js +274 -0
  322. package/dist/tools/frame/ambient.js.map +1 -0
  323. package/dist/tools/frame/blackbody.d.ts +57 -0
  324. package/dist/tools/frame/blackbody.js +151 -0
  325. package/dist/tools/frame/blackbody.js.map +1 -0
  326. package/dist/tools/frame/brick-cache.d.ts +165 -0
  327. package/dist/tools/frame/brick-cache.js +326 -0
  328. package/dist/tools/frame/brick-cache.js.map +1 -0
  329. package/dist/tools/frame/emission.d.ts +137 -0
  330. package/dist/tools/frame/emission.js +290 -0
  331. package/dist/tools/frame/emission.js.map +1 -0
  332. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  333. package/dist/tools/frame/environment-gpu.js +280 -0
  334. package/dist/tools/frame/environment-gpu.js.map +1 -0
  335. package/dist/tools/frame/environment.d.ts +106 -0
  336. package/dist/tools/frame/environment.js +272 -0
  337. package/dist/tools/frame/environment.js.map +1 -0
  338. package/dist/tools/frame/froxel.d.ts +58 -0
  339. package/dist/tools/frame/froxel.js +115 -0
  340. package/dist/tools/frame/froxel.js.map +1 -0
  341. package/dist/tools/frame/grid.d.ts +392 -0
  342. package/dist/tools/frame/grid.js +802 -0
  343. package/dist/tools/frame/grid.js.map +1 -0
  344. package/dist/tools/frame/index.d.ts +150 -0
  345. package/dist/tools/frame/index.js +389 -0
  346. package/dist/tools/frame/index.js.map +1 -0
  347. package/dist/tools/frame/medium.d.ts +77 -0
  348. package/dist/tools/frame/medium.js +101 -0
  349. package/dist/tools/frame/medium.js.map +1 -0
  350. package/dist/tools/frame/mie-table.d.ts +6 -0
  351. package/dist/tools/frame/mie-table.js +16 -0
  352. package/dist/tools/frame/mie-table.js.map +1 -0
  353. package/dist/tools/frame/mie.d.ts +63 -0
  354. package/dist/tools/frame/mie.js +194 -0
  355. package/dist/tools/frame/mie.js.map +1 -0
  356. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  357. package/dist/tools/frame/mlp-nn.js +159 -0
  358. package/dist/tools/frame/mlp-nn.js.map +1 -0
  359. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  360. package/dist/tools/frame/mlp-tza.js +186 -0
  361. package/dist/tools/frame/mlp-tza.js.map +1 -0
  362. package/dist/tools/frame/mlp.d.ts +183 -0
  363. package/dist/tools/frame/mlp.js +434 -0
  364. package/dist/tools/frame/mlp.js.map +1 -0
  365. package/dist/tools/frame/ms-exit.d.ts +42 -0
  366. package/dist/tools/frame/ms-exit.js +90 -0
  367. package/dist/tools/frame/ms-exit.js.map +1 -0
  368. package/dist/tools/frame/multi-scale.d.ts +152 -0
  369. package/dist/tools/frame/multi-scale.js +302 -0
  370. package/dist/tools/frame/multi-scale.js.map +1 -0
  371. package/dist/tools/frame/neural-weights.d.ts +10 -0
  372. package/dist/tools/frame/neural-weights.js +244 -0
  373. package/dist/tools/frame/neural-weights.js.map +1 -0
  374. package/dist/tools/frame/neural.d.ts +80 -0
  375. package/dist/tools/frame/neural.js +150 -0
  376. package/dist/tools/frame/neural.js.map +1 -0
  377. package/dist/tools/frame/occluders.d.ts +51 -0
  378. package/dist/tools/frame/occluders.js +72 -0
  379. package/dist/tools/frame/occluders.js.map +1 -0
  380. package/dist/tools/frame/pyramid-layout.d.ts +55 -0
  381. package/dist/tools/frame/pyramid-layout.js +100 -0
  382. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  383. package/dist/tools/frame/shadows.d.ts +190 -0
  384. package/dist/tools/frame/shadows.js +468 -0
  385. package/dist/tools/frame/shadows.js.map +1 -0
  386. package/dist/tools/frame/sparse.d.ts +147 -0
  387. package/dist/tools/frame/sparse.js +432 -0
  388. package/dist/tools/frame/sparse.js.map +1 -0
  389. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  390. package/dist/tools/frame/spectral-stack.js +391 -0
  391. package/dist/tools/frame/spectral-stack.js.map +1 -0
  392. package/dist/tools/frame/spectral.d.ts +222 -0
  393. package/dist/tools/frame/spectral.js +572 -0
  394. package/dist/tools/frame/spectral.js.map +1 -0
  395. package/dist/tools/frame/stack.d.ts +115 -0
  396. package/dist/tools/frame/stack.js +290 -0
  397. package/dist/tools/frame/stack.js.map +1 -0
  398. package/dist/tools/frame/view.d.ts +131 -0
  399. package/dist/tools/frame/view.js +337 -0
  400. package/dist/tools/frame/view.js.map +1 -0
  401. package/dist/tools/index.d.ts +157 -0
  402. package/dist/tools/index.js +132 -0
  403. package/dist/tools/index.js.map +1 -0
  404. package/dist/tools/internal.d.ts +87 -0
  405. package/dist/tools/internal.js +85 -0
  406. package/dist/tools/internal.js.map +1 -0
  407. package/dist/tools/nanovdb/build-from-vdb.d.ts +59 -0
  408. package/dist/tools/nanovdb/build-from-vdb.js +100 -0
  409. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  410. package/dist/tools/nanovdb/bytes.d.ts +233 -0
  411. package/dist/tools/nanovdb/bytes.js +388 -0
  412. package/dist/tools/nanovdb/bytes.js.map +1 -0
  413. package/dist/tools/nanovdb/coarse-first.d.ts +78 -0
  414. package/dist/tools/nanovdb/coarse-first.js +92 -0
  415. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  416. package/dist/tools/nanovdb/half.d.ts +22 -0
  417. package/dist/tools/nanovdb/half.js +73 -0
  418. package/dist/tools/nanovdb/half.js.map +1 -0
  419. package/dist/tools/nanovdb/index.d.ts +34 -0
  420. package/dist/tools/nanovdb/index.js +25 -0
  421. package/dist/tools/nanovdb/index.js.map +1 -0
  422. package/dist/tools/nanovdb/inspect.d.ts +33 -0
  423. package/dist/tools/nanovdb/inspect.js +70 -0
  424. package/dist/tools/nanovdb/inspect.js.map +1 -0
  425. package/dist/tools/nanovdb/leaf-codec.d.ts +119 -0
  426. package/dist/tools/nanovdb/leaf-codec.js +356 -0
  427. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  428. package/dist/tools/nanovdb/quantize.d.ts +72 -0
  429. package/dist/tools/nanovdb/quantize.js +329 -0
  430. package/dist/tools/nanovdb/quantize.js.map +1 -0
  431. package/dist/tools/nanovdb/resample.d.ts +177 -0
  432. package/dist/tools/nanovdb/resample.js +692 -0
  433. package/dist/tools/nanovdb/resample.js.map +1 -0
  434. package/dist/tools/nanovdb/serialize.d.ts +176 -0
  435. package/dist/tools/nanovdb/serialize.js +439 -0
  436. package/dist/tools/nanovdb/serialize.js.map +1 -0
  437. package/dist/tools/nanovdb/stats.d.ts +87 -0
  438. package/dist/tools/nanovdb/stats.js +225 -0
  439. package/dist/tools/nanovdb/stats.js.map +1 -0
  440. package/dist/tools/nanovdb/transform.d.ts +30 -0
  441. package/dist/tools/nanovdb/transform.js +94 -0
  442. package/dist/tools/nanovdb/transform.js.map +1 -0
  443. package/dist/tools/nanovdb/tree.d.ts +186 -0
  444. package/dist/tools/nanovdb/tree.js +530 -0
  445. package/dist/tools/nanovdb/tree.js.map +1 -0
  446. package/dist/tools/nanovdb/write-nvdb.d.ts +74 -0
  447. package/dist/tools/nanovdb/write-nvdb.js +290 -0
  448. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  449. package/dist/tools/nvdb-file.d.ts +265 -0
  450. package/dist/tools/nvdb-file.js +763 -0
  451. package/dist/tools/nvdb-file.js.map +1 -0
  452. package/dist/tools/nvdb-stream.d.ts +154 -0
  453. package/dist/tools/nvdb-stream.js +409 -0
  454. package/dist/tools/nvdb-stream.js.map +1 -0
  455. package/dist/tools/reference/analytic.d.ts +41 -0
  456. package/dist/tools/reference/analytic.js +95 -0
  457. package/dist/tools/reference/analytic.js.map +1 -0
  458. package/dist/tools/reference/environment.d.ts +62 -0
  459. package/dist/tools/reference/environment.js +154 -0
  460. package/dist/tools/reference/environment.js.map +1 -0
  461. package/dist/tools/reference/index.d.ts +12 -0
  462. package/dist/tools/reference/index.js +13 -0
  463. package/dist/tools/reference/index.js.map +1 -0
  464. package/dist/tools/reference/media.d.ts +14 -0
  465. package/dist/tools/reference/media.js +30 -0
  466. package/dist/tools/reference/media.js.map +1 -0
  467. package/dist/tools/reference/rng.d.ts +20 -0
  468. package/dist/tools/reference/rng.js +30 -0
  469. package/dist/tools/reference/rng.js.map +1 -0
  470. package/dist/tools/reference/scene.d.ts +312 -0
  471. package/dist/tools/reference/scene.js +169 -0
  472. package/dist/tools/reference/scene.js.map +1 -0
  473. package/dist/tools/reference/tables.d.ts +98 -0
  474. package/dist/tools/reference/tables.js +264 -0
  475. package/dist/tools/reference/tables.js.map +1 -0
  476. package/dist/tools/reference/trace.d.ts +160 -0
  477. package/dist/tools/reference/trace.js +497 -0
  478. package/dist/tools/reference/trace.js.map +1 -0
  479. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  480. package/dist/tools/vdb/bit-utils.js +42 -0
  481. package/dist/tools/vdb/bit-utils.js.map +1 -0
  482. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  483. package/dist/tools/vdb/blosc-write.js +197 -0
  484. package/dist/tools/vdb/blosc-write.js.map +1 -0
  485. package/dist/tools/vdb/blosc.d.ts +86 -0
  486. package/dist/tools/vdb/blosc.js +287 -0
  487. package/dist/tools/vdb/blosc.js.map +1 -0
  488. package/dist/tools/vdb/blosclz.d.ts +33 -0
  489. package/dist/tools/vdb/blosclz.js +112 -0
  490. package/dist/tools/vdb/blosclz.js.map +1 -0
  491. package/dist/tools/vdb/byte-reader.d.ts +50 -0
  492. package/dist/tools/vdb/byte-reader.js +161 -0
  493. package/dist/tools/vdb/byte-reader.js.map +1 -0
  494. package/dist/tools/vdb/compression.d.ts +81 -0
  495. package/dist/tools/vdb/compression.js +260 -0
  496. package/dist/tools/vdb/compression.js.map +1 -0
  497. package/dist/tools/vdb/errors.d.ts +10 -0
  498. package/dist/tools/vdb/errors.js +11 -0
  499. package/dist/tools/vdb/errors.js.map +1 -0
  500. package/dist/tools/vdb/grid.d.ts +37 -0
  501. package/dist/tools/vdb/grid.js +153 -0
  502. package/dist/tools/vdb/grid.js.map +1 -0
  503. package/dist/tools/vdb/half-float.d.ts +9 -0
  504. package/dist/tools/vdb/half-float.js +24 -0
  505. package/dist/tools/vdb/half-float.js.map +1 -0
  506. package/dist/tools/vdb/index.d.ts +4 -0
  507. package/dist/tools/vdb/index.js +3 -0
  508. package/dist/tools/vdb/index.js.map +1 -0
  509. package/dist/tools/vdb/inflate.d.ts +24 -0
  510. package/dist/tools/vdb/inflate.js +334 -0
  511. package/dist/tools/vdb/inflate.js.map +1 -0
  512. package/dist/tools/vdb/lz4.d.ts +30 -0
  513. package/dist/tools/vdb/lz4.js +228 -0
  514. package/dist/tools/vdb/lz4.js.map +1 -0
  515. package/dist/tools/vdb/metadata.d.ts +17 -0
  516. package/dist/tools/vdb/metadata.js +72 -0
  517. package/dist/tools/vdb/metadata.js.map +1 -0
  518. package/dist/tools/vdb/parse.d.ts +47 -0
  519. package/dist/tools/vdb/parse.js +241 -0
  520. package/dist/tools/vdb/parse.js.map +1 -0
  521. package/dist/tools/vdb/point-render-data.d.ts +79 -0
  522. package/dist/tools/vdb/point-render-data.js +137 -0
  523. package/dist/tools/vdb/point-render-data.js.map +1 -0
  524. package/dist/tools/vdb/points.d.ts +186 -0
  525. package/dist/tools/vdb/points.js +835 -0
  526. package/dist/tools/vdb/points.js.map +1 -0
  527. package/dist/tools/vdb/transform.d.ts +23 -0
  528. package/dist/tools/vdb/transform.js +54 -0
  529. package/dist/tools/vdb/transform.js.map +1 -0
  530. package/dist/tools/vdb/tree.d.ts +111 -0
  531. package/dist/tools/vdb/tree.js +228 -0
  532. package/dist/tools/vdb/tree.js.map +1 -0
  533. package/dist/tools/vdb/types.d.ts +195 -0
  534. package/dist/tools/vdb/types.js +3 -0
  535. package/dist/tools/vdb/types.js.map +1 -0
  536. package/dist/tools/wvdb/bake.d.ts +145 -0
  537. package/dist/tools/wvdb/bake.js +361 -0
  538. package/dist/tools/wvdb/bake.js.map +1 -0
  539. package/dist/tools/wvdb/dense.d.ts +191 -0
  540. package/dist/tools/wvdb/dense.js +368 -0
  541. package/dist/tools/wvdb/dense.js.map +1 -0
  542. package/dist/tools/wvdb/format.d.ts +220 -0
  543. package/dist/tools/wvdb/format.js +306 -0
  544. package/dist/tools/wvdb/format.js.map +1 -0
  545. package/dist/tools/wvdb/index.d.ts +14 -0
  546. package/dist/tools/wvdb/index.js +15 -0
  547. package/dist/tools/wvdb/index.js.map +1 -0
  548. package/dist/tools/wvdb/level-set.d.ts +56 -0
  549. package/dist/tools/wvdb/level-set.js +153 -0
  550. package/dist/tools/wvdb/level-set.js.map +1 -0
  551. package/dist/tools/wvdb/nanovdb.d.ts +59 -0
  552. package/dist/tools/wvdb/nanovdb.js +64 -0
  553. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  554. package/dist/tools/wvdb/partial.d.ts +74 -0
  555. package/dist/tools/wvdb/partial.js +233 -0
  556. package/dist/tools/wvdb/partial.js.map +1 -0
  557. package/dist/tools/wvdb/read.d.ts +336 -0
  558. package/dist/tools/wvdb/read.js +766 -0
  559. package/dist/tools/wvdb/read.js.map +1 -0
  560. package/dist/tools/wvdb/sha256.d.ts +7 -0
  561. package/dist/tools/wvdb/sha256.js +76 -0
  562. package/dist/tools/wvdb/sha256.js.map +1 -0
  563. package/dist/tools/wvdb/write.d.ts +149 -0
  564. package/dist/tools/wvdb/write.js +403 -0
  565. package/dist/tools/wvdb/write.js.map +1 -0
  566. package/package.json +83 -4
  567. package/vendor/LICENSE +201 -0
  568. package/vendor/NOTICE +19 -0
  569. package/vendor/VENDOR.md +100 -0
  570. package/vendor/pnanovdb.wgsl +1577 -0
@@ -0,0 +1,1712 @@
1
+ // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
2
+ // src/three-openvdb/frame/webgpu/FrameRenderer.js L715–1061 (updateTargets, renderFrame, updateFroxelArea,
3
+ // renderTemporal, renderInject: the per-frame order, jitter, temporal validity, previous matrices),
4
+ // L1476–1716 (light records and their slot order: directional, point, spot), frameShaderChunks.js L800–830
5
+ // (setVolumeUniforms); commits 4b5393d and 92421cc (v0.31.0, VDB-167 skyLightCount / frameSkyMarch, VDB-168 the
6
+ // release of turned-off targets and trimSpectralTransmittanceTargets).
7
+ // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
8
+ // Changes: an engine-free renderer on the host's device and encoder (D8, D34): plain-data inputs, compute
9
+ // kernels on 3D textures, explicit bind groups, a retire queue (design §2–§4). Divergences: DIVERGES.md
10
+ // (K6.1 rows).
11
+ /**
12
+ * `vdbCreateFrameRenderer(device, options)`: the core froxel renderer ('volume' lighting, K6.1; 'frame' lighting's
13
+ * shadow grid, transmittance and fused gather, K6.2; dense and sparse sources). Per frame:
14
+ *
15
+ * const enc = device.createCommandEncoder();
16
+ * const u = frame.update(enc, { frameId, camera, viewport, lights }); // gather per source group, resolve
17
+ * frame.render(enc, { color, size, depth, sceneColor }); // or vdbFrameIntegrate in your pass
18
+ * device.queue.submit([enc.finish()]);
19
+ *
20
+ * The renderer records, never submits; it frees only what it made (D8). One `update()` per submitted
21
+ * encoder (its uniforms go through `queue.writeBuffer`), submitted in the task that recorded it: a texture the renderer
22
+ * replaces is destroyed two updates later and never in the task that made it due (K6.10a), so a submit later in that
23
+ * task is safe.
24
+ */
25
+ import { VDBError } from "../errors.js";
26
+ import { vdbFrameAtlasLayout, vdbFrameClipCamera, vdbFrameClipRect, vdbFrameClipVolume, vdbFrameFroxelArea, vdbFrameFroxelRect, vdbFrameFroxelSize, vdbFrameVolumeSlices, vdbFroxelAreaUnion, vdbFroxelHeldSize, vdbMat4Invert, vdbMat4MaxScale, vdbMat4Multiply, vdbUnitBoxBounds, } from "../../tools/frame/view.js";
27
+ import { vdbFrameAdaptiveCellSize, vdbFrameAdaptiveGridResolution, vdbFrameGridCascades, vdbFrameGridSignatureState, vdbFrameUpdateGridSignatures, vdbSameValues } from "../../tools/frame/grid.js";
28
+ import { vdbFrameStackLayout } from "../../tools/frame/stack.js";
29
+ import { GATHER_BINDINGS, VDB_FRAME_GATHER_WORDS } from "./wgsl/gather.js";
30
+ import { FRAME_GATHER_BINDINGS, GRID_DENSITY_BINDINGS, TRANSMITTANCE_BINDINGS, VDB_FRAME_SPECTRAL_GRID_WORDS, VDB_FRAME_SUM_WORDS } from "./wgsl/lighting.js";
31
+ import { VDB_FRAME_COMPOSITE_ALPHA_BINDING } from "./wgsl/integrate.js";
32
+ import { vdbFrameExtinctionSpectrum, vdbFrameSpectralGroups } from "../../tools/frame/spectral.js";
33
+ import { RESOLVE_BINDINGS } from "./wgsl/resolve.js";
34
+ import { VDB_FRAME_OCCLUDER_BINDING } from "./wgsl/occluders.js";
35
+ import { ENV_GRID_BINDINGS } from "./wgsl/environment.js";
36
+ import { VDBFrameEnvironmentState } from "./environment.js";
37
+ import { vdbFrameCompositeSpec, vdbFrameEmissionDirectionSpec, vdbFrameEmissionProbeSpec, vdbFrameEmissionReduceSpec, vdbFrameEnvironmentGridSpec, vdbFrameGatherSpec, vdbFrameGridDensitySpec, vdbFrameGridMipSpec, vdbFrameResolveSpec, vdbFrameTransmittanceSpec, vdbFrameVolumeShadowSpec, SOURCE_SLOT, } from "./kernels.js";
38
+ import { VDBFrameShadowMaps } from "./shadows.js";
39
+ import { VDBFrameEmissionColors, VDBFrameEmissionProbeSet } from "./emission.js";
40
+ import { EMISSION_DIRECTION_BINDINGS, EMISSION_PROBE_BINDINGS, EMISSION_REDUCE_BINDINGS, VDB_FRAME_EMISSION_DIRECTIONS, VDB_FRAME_EMITTERS, VDB_FRAME_EMITTERS_STRIDE } from "./wgsl/emission.js";
41
+ import { computePipeline, prepareCompute, prepareRender, renderPipeline } from "./pipelines.js";
42
+ import { BUFFER_USAGE, createFroxelTexture, VDB_FRAME_RELEASE_UPDATES, VDBRetireQueue } from "./resources.js";
43
+ import { VDB_FRAME_DEFAULT_LIMITS, vdbFrameDipoleSettingsOn, vdbFrameFitGridResolution, vdbFrameStackTargets } from "./limits.js";
44
+ import { VDBFrameScattering } from "./scattering.js";
45
+ import { vdbFrameScatteringIsMlp } from "./wgsl/lighting.js";
46
+ import { vdbFrameMieLutWords } from "../../tools/frame/mie.js";
47
+ import { vdbFrameScatteringOctaves } from "../../tools/frame/index.js";
48
+ import { VDB_FRAME_AMBIENT_MAX_PAIRS, vdbFrameAmbientDipoleMatrix, vdbFrameAmbientDirections } from "../../tools/frame/ambient.js";
49
+ import { vdbFrameMlpFromNeural } from "../../tools/frame/mlp.js";
50
+ import { vdbFrameNeuralWeights } from "../../tools/frame/neural-weights.js";
51
+ import { vdbFrameMsExitCode } from "../../tools/frame/ms-exit.js";
52
+ import { vdbFrameDefaultInternalSettings } from "./settings.js";
53
+ import { vdbFrameMultipleScatteringValue, vdbFramePhaseSpectrum, vdbFramePhaseVector } from "./phase.js";
54
+ import { VDB_FRAME_GROUP, VDB_FRAME_GROUP_STRIDE, VDB_FRAME_LIGHTS, VDB_FRAME_MAX_CASCADES, VDB_FRAME_MAX_HEMISPHERE_LIGHTS, VDB_FRAME_MAX_LIGHTS, VDB_FRAME_MAX_OCCLUDERS, VDB_FRAME_MAX_VOLUMES, VDB_FRAME_OCCLUDER_LAYERS, VDB_FRAME_SHADOW_SLOTS, VDB_FRAME_SPECTRAL_GROUPS, VDB_FRAME_DIPOLE_ORIGIN, VDB_FRAME_UNIFORMS, VDB_FRAME_VOLUME, VDB_FRAME_VOLUME_BYTES, VDBUniformWriter, } from "./uniforms.js";
55
+ import { vdbFrameDefaultVolumeParams, } from "./types.js";
56
+ const IDENTITY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
57
+ /** Shadow inputs of an update with nothing to draw (the maps are freed or disabled). */
58
+ const EMPTY_SHADOWS = {
59
+ coarse: false,
60
+ steps: 1,
61
+ budget: 1,
62
+ cascades: 1,
63
+ castShadowDistance: 1,
64
+ camera: { view: IDENTITY, cameraWorld: IDENTITY, projectionInverse: IDENTITY, near: 1, far: 2, orthographic: false },
65
+ grid: null,
66
+ castVersion: 0,
67
+ };
68
+ const DEPTH_FORMATS = new Set(["depth16unorm", "depth24plus", "depth24plus-stencil8", "depth32float", "depth32float-stencil8"]);
69
+ const WRAP_CODE = { clamp: 0, repeat: 1, mirror: 2 };
70
+ class FrameVolume {
71
+ params;
72
+ visible = true;
73
+ castsShadow = true;
74
+ slot;
75
+ #owner;
76
+ constructor(owner, slot, params) {
77
+ this.#owner = owner;
78
+ this.slot = slot;
79
+ this.params = { ...vdbFrameDefaultVolumeParams(), ...params };
80
+ }
81
+ remove() {
82
+ this.#owner.removeVolume(this);
83
+ }
84
+ }
85
+ class FrameRenderer {
86
+ device;
87
+ settings;
88
+ redrawStats = {
89
+ shadowDensity: { drawn: 0, skipped: 0 },
90
+ transmittance: { drawn: 0, skipped: 0 },
91
+ environmentGrid: { drawn: 0, skipped: 0 },
92
+ volumeShadows: { drawn: 0, waiting: 0 },
93
+ };
94
+ shadowGridResolution = 0;
95
+ outputs;
96
+ #label;
97
+ #composite;
98
+ #maxVolumes;
99
+ #retire = new VDBRetireQueue();
100
+ #volumes = [];
101
+ #warned = new Set();
102
+ /** K6.10a: clamped shadow grid resolutions by (resolution, cascades, spectral); the limits do not change. */
103
+ #gridFits = new Map();
104
+ #held = vdbFroxelHeldSize();
105
+ #frameWriter = new VDBUniformWriter(VDB_FRAME_UNIFORMS.size);
106
+ #lightsWriter = new VDBUniformWriter(VDB_FRAME_LIGHTS.size);
107
+ #volumesWriter;
108
+ #frameBuffer;
109
+ #lightsBuffer;
110
+ #volumesBuffer;
111
+ #groupsBuffer;
112
+ #groupsWriter;
113
+ #linear;
114
+ #textures = null;
115
+ /** The rect each texture last held non-zero values in (the dispatch box also clears it). */
116
+ #written = new WeakMap();
117
+ #historyIndex = 0;
118
+ #historyValid = false;
119
+ #previous = null;
120
+ #group0 = null;
121
+ #sourceGroups = new WeakMap();
122
+ #recorded = false;
123
+ #disposed = false;
124
+ // K6.2 'frame' lighting: the grid textures, the cascade layout and his change signatures
125
+ #grid = null;
126
+ #gridState = vdbFrameGridSignatureState();
127
+ #gridMin = Array.from({ length: VDB_FRAME_MAX_CASCADES }, () => ({ x: 0, y: 0, z: 0 }));
128
+ #gridSize = Array.from({ length: VDB_FRAME_MAX_CASCADES }, () => ({ x: 0, y: 0, z: 0 }));
129
+ #gridVoxel = Array.from({ length: VDB_FRAME_MAX_CASCADES }, () => ({ x: 0, y: 0, z: 0 }));
130
+ /** The grid version the shadow grid texture holds (−1: none). */
131
+ #gridDrawn = -1;
132
+ /** K6.3: shadow grid draws so far (the scattered-light mips follow it). */
133
+ #gridDraws = 0;
134
+ #transmittanceSignature = [];
135
+ // K7.16: updates in a row that needed fewer spectral slot groups (and the most they needed), and that needed no grid or
136
+ // froxel partials
137
+ #groupsLow = { updates: 0, most: 0 };
138
+ #gridPartialsIdle = 0;
139
+ #froxelPartialsIdle = 0;
140
+ /** K6.Q1d-a: the stack holds the dipole targets, and the updates in a row that had the settings but no distant light. */
141
+ #dipoleHeld = false;
142
+ #dipoleIdle = 0;
143
+ /** K7.16a: updates in a row without froxel work (no visible volume in view) while the froxel textures exist. */
144
+ #froxelIdle = 0;
145
+ // K6.2b: the GPU environment (buffer, maps, kernels) and the environment grid's signature
146
+ #env;
147
+ #envGridSignature = [];
148
+ #sourceIds = new WeakMap();
149
+ #nextSourceId = 1;
150
+ // K6.5: volume shadow maps, emission colours (LUT, hooks) and the emission probes
151
+ #shadows;
152
+ #colors;
153
+ #probes;
154
+ // K6.3: the Lorenz-Mie LUT and the scattered-light term's resources ('mlp', 'multi-scale')
155
+ #mie;
156
+ #scattering;
157
+ /**
158
+ * K6.3 EXPERIMENTAL: the network of `multipleScattering: 'mlp'` (and `'neural'`) in 'frame' lighting, data for a
159
+ * generic MLP evaluator; default our trained weights (K6.N, D36). null: those modes run as 1D diffusion (warned).
160
+ */
161
+ mlp = vdbFrameMlpFromNeural(vdbFrameNeuralWeights);
162
+ /** K6.4: rg16float storage (`texture-formats-tier1`) for the spectral alpha prefix; else rgba16float. */
163
+ #tier1;
164
+ // K6.5b: this update's host occluder map views (slots 0–3) and the 1 × 1 placeholder of the empty slots
165
+ #occluderViews = [];
166
+ #occluderPlaceholder = null;
167
+ constructor(device, o) {
168
+ this.device = device;
169
+ this.#label = o.label ?? "vdb frame";
170
+ this.settings = { ...vdbFrameDefaultInternalSettings(), ...(o.settings ?? {}) };
171
+ this.#composite = o.composite ?? null;
172
+ this.#tier1 = o.features?.tier1 ?? !!device.features?.has?.("texture-formats-tier1");
173
+ this.#maxVolumes = Math.min(VDB_FRAME_MAX_VOLUMES, Math.floor((device.limits?.maxUniformBufferBindingSize ?? 65536) / VDB_FRAME_VOLUME_BYTES));
174
+ this.#frameBuffer = device.createBuffer({ label: `${this.#label} uniforms`, size: VDB_FRAME_UNIFORMS.size, usage: BUFFER_USAGE.UNIFORM | BUFFER_USAGE.COPY_DST });
175
+ this.#lightsBuffer = device.createBuffer({ label: `${this.#label} lights`, size: VDB_FRAME_LIGHTS.size, usage: BUFFER_USAGE.UNIFORM | BUFFER_USAGE.COPY_DST });
176
+ this.#volumesWriter = new VDBUniformWriter(this.#maxVolumes * VDB_FRAME_VOLUME_BYTES);
177
+ this.#volumesBuffer = device.createBuffer({ label: `${this.#label} volumes`, size: this.#maxVolumes * VDB_FRAME_VOLUME_BYTES, usage: BUFFER_USAGE.UNIFORM | BUFFER_USAGE.COPY_DST });
178
+ this.#groupsWriter = new VDBUniformWriter(4 * VDB_FRAME_GROUP_STRIDE);
179
+ this.#groupsBuffer = device.createBuffer({ label: `${this.#label} groups`, size: 4 * VDB_FRAME_GROUP_STRIDE, usage: BUFFER_USAGE.UNIFORM | BUFFER_USAGE.COPY_DST });
180
+ this.#linear = device.createSampler({
181
+ label: `${this.#label} linear clamp`,
182
+ magFilter: "linear",
183
+ minFilter: "linear",
184
+ mipmapFilter: "nearest",
185
+ addressModeU: "clamp-to-edge",
186
+ addressModeV: "clamp-to-edge",
187
+ addressModeW: "clamp-to-edge",
188
+ });
189
+ this.#env = new VDBFrameEnvironmentState(device, this.#label);
190
+ this.#shadows = new VDBFrameShadowMaps(device, this.#label, this.#retire, (key, message) => this.#warnOnce(key, message));
191
+ this.#colors = new VDBFrameEmissionColors(device, this.#label, this.#retire);
192
+ this.#probes = new VDBFrameEmissionProbeSet(device, this.#label, this.#retire);
193
+ // K6.3: the Lorenz-Mie phase tables as one LUT (V47: rgb 'lorenz-mie-rgb', a 'lorenz-mie'), group 0 binding 4
194
+ const mie = vdbFrameMieLutWords();
195
+ this.#mie = device.createBuffer({ label: `${this.#label} Lorenz-Mie table`, size: mie.byteLength, usage: BUFFER_USAGE.UNIFORM | BUFFER_USAGE.COPY_DST });
196
+ device.queue.writeBuffer(this.#mie, 0, mie.buffer);
197
+ this.#scattering = new VDBFrameScattering(device, this.#label, this.#retire, (key, message) => this.#warnOnce(key, message));
198
+ this.outputs = { version: 0, froxels: null, uniforms: this.#frameBuffer, volumeShadows: this.#shadows.maps, emissionProbes: null };
199
+ }
200
+ // ---------------------------------------------------------------- volumes
201
+ addVolume(slot, params = {}) {
202
+ this.#check();
203
+ if (!slot || !slot.source || typeof slot.source.wgsl !== "function" || !Number.isInteger(slot.v)) {
204
+ throw new VDBError("VDB_BAD_OPTION", "VDBFrameRenderer.addVolume: pass a VDBVolumeSlot ({ source, v }); a dense source from vdbDenseSource() is its own slot.");
205
+ }
206
+ const v = new FrameVolume(this, slot, params);
207
+ this.#volumes.push(v);
208
+ return v;
209
+ }
210
+ removeVolume(v) {
211
+ const i = this.#volumes.indexOf(v);
212
+ if (i >= 0)
213
+ this.#volumes.splice(i, 1);
214
+ }
215
+ // ---------------------------------------------------------------- pipelines
216
+ #compositeKey() {
217
+ if (!this.#composite)
218
+ return null;
219
+ return {
220
+ colorFormat: this.#composite.colorFormat,
221
+ depth: DEPTH_FORMATS.has(this.#composite.depthFormat) ? "depth" : "r32float",
222
+ srgb: this.settings.srgbBlending,
223
+ spectral: !!this.settings.spectral,
224
+ };
225
+ }
226
+ /** Issue #2 step 2: the internal `densityFilter` A/B setting (a gather pipeline key). */
227
+ #stochastic() {
228
+ return this.settings.densityFilter === "stochastic";
229
+ }
230
+ async prepare(options = {}) {
231
+ this.#check();
232
+ const modes = options.lighting ?? [this.settings.lighting];
233
+ // K6.5: the emission hooks validate first (a hook pipeline is built only once its hook is valid)
234
+ await this.#colors.settled(this.#volumes.map((v) => v.params.emissionColor));
235
+ const jobs = [];
236
+ const spectral = !!this.settings.spectral;
237
+ const sources = new Set(this.#volumes.map((v) => v.slot.source));
238
+ const shadows = modes.includes("frame") || this.settings.castShadows;
239
+ for (const source of sources) {
240
+ const hooks = new Set([null]);
241
+ if (source.channels.emission)
242
+ for (const v of this.#volumes)
243
+ if (v.slot.source === source)
244
+ hooks.add(this.#colors.codeOf(v.params.emissionColor).hook);
245
+ for (const hook of hooks) {
246
+ for (const multi of [false, true]) {
247
+ for (const lighting of modes)
248
+ jobs.push(prepareCompute(this.device, vdbFrameGatherSpec(source, { multi, maxVolumes: this.#maxVolumes, lighting, hook, spectral, stochastic: this.#stochastic() })));
249
+ }
250
+ if (source.channels.emission)
251
+ jobs.push(prepareCompute(this.device, vdbFrameEmissionDirectionSpec(source, { maxVolumes: this.#maxVolumes, hook })));
252
+ }
253
+ if (shadows)
254
+ for (const multi of [false, true])
255
+ jobs.push(prepareCompute(this.device, vdbFrameGridDensitySpec(source, { multi, maxVolumes: this.#maxVolumes, spectral })));
256
+ }
257
+ if (modes.includes("frame")) {
258
+ // K6.3: the transmittance variant of the scattered-light term ('mlp' also its feature mips; K7.4a: spectral too)
259
+ const scattering = this.#scattering.kind(this.settings, this.mlp);
260
+ jobs.push(prepareCompute(this.device, vdbFrameTransmittanceSpec({ scattering, spectral })), prepareCompute(this.device, vdbFrameEnvironmentGridSpec({ spectral })));
261
+ if (vdbFrameScatteringIsMlp(scattering))
262
+ jobs.push(prepareCompute(this.device, vdbFrameGridMipSpec({ first: true })), prepareCompute(this.device, vdbFrameGridMipSpec({ first: false })));
263
+ }
264
+ for (const spec of this.#env.specs(["equirect", "cube"]))
265
+ jobs.push(prepareCompute(this.device, spec));
266
+ if (this.settings.castShadows)
267
+ jobs.push(prepareCompute(this.device, vdbFrameVolumeShadowSpec({ spectral })));
268
+ if ([...sources].some((s) => s.channels.emission))
269
+ jobs.push(prepareCompute(this.device, vdbFrameEmissionReduceSpec()), prepareCompute(this.device, vdbFrameEmissionProbeSpec()));
270
+ jobs.push(prepareCompute(this.device, vdbFrameResolveSpec(this.#resolveKey())));
271
+ const key = this.#compositeKey();
272
+ if (key)
273
+ jobs.push(prepareRender(this.device, vdbFrameCompositeSpec(key)));
274
+ await Promise.all(jobs);
275
+ }
276
+ // ---------------------------------------------------------------- update
277
+ update(encoder, frame, options = {}) {
278
+ const t = options.timestampWrites;
279
+ if (t && t.beginningOfPassWriteIndex !== undefined)
280
+ encoder.beginComputePass({ label: `${this.#label} begin`, timestampWrites: { querySet: t.querySet, beginningOfPassWriteIndex: t.beginningOfPassWriteIndex } }).end();
281
+ const u = this.#update(encoder, frame, options);
282
+ if (t && t.endOfPassWriteIndex !== undefined)
283
+ encoder.beginComputePass({ label: `${this.#label} end`, timestampWrites: { querySet: t.querySet, endOfPassWriteIndex: t.endOfPassWriteIndex } }).end();
284
+ return u;
285
+ }
286
+ #update(encoder, frame, options) {
287
+ this.#check();
288
+ this.#retire.advance();
289
+ const s = this.settings;
290
+ const frameLighting = s.lighting === "frame";
291
+ // K6.4: spectral media (a pipeline key of every kernel with a spectral variant)
292
+ const spectral = !!s.spectral;
293
+ if (options.froxels === false && this.#textures)
294
+ return { outputs: this.outputs, recorded: this.#recorded, volumes: 0 };
295
+ // K7.16: the textures of features the settings turned off
296
+ this.#releaseUnused();
297
+ const versions = [this.#shadows.version, this.#probes.version];
298
+ // Froxel size (his getFroxelSize) and the textures
299
+ const size = vdbFrameFroxelSize(s, frame.viewport, this.#held);
300
+ const maxDim = this.device.limits?.maxTextureDimension3D ?? 2048;
301
+ let W = size.width;
302
+ let H = size.height;
303
+ let D = Math.max(1, Math.round(s.depth));
304
+ // multi-group partials stack 2 ('volume'; K6.4 spectral 3) or 8 ('frame') slices per froxel slice along z
305
+ const layers = frameLighting ? VDB_FRAME_SUM_WORDS : spectral ? VDB_FRAME_GATHER_WORDS.spectral : VDB_FRAME_GATHER_WORDS.grey;
306
+ if (W > maxDim || H > maxDim || D + 1 > maxDim || layers * D > maxDim) {
307
+ this.#warnOnce("size", `the froxel grid ${W}x${H}x${D} exceeds maxTextureDimension3D (${maxDim}); clamped.`);
308
+ W = Math.min(W, maxDim);
309
+ H = Math.min(H, maxDim);
310
+ D = Math.min(D, Math.floor(maxDim / layers));
311
+ }
312
+ // Collect and clip the visible volumes (his FrameVolumeCollector)
313
+ const cam = frame.camera;
314
+ const clip = vdbFrameClipCamera(cam.view, cam.projection, { coordinateSystem: "webgpu", reversedDepth: !!cam.reversedDepth });
315
+ let near = Infinity;
316
+ let far = 0;
317
+ const clipped = [];
318
+ for (const volume of this.#volumes) {
319
+ if (!volume.visible)
320
+ continue;
321
+ const c = vdbFrameClipVolume(clip, volume.params.matrixWorld);
322
+ if (!c)
323
+ continue;
324
+ clipped.push({ volume, c });
325
+ near = Math.min(near, c.viewNear);
326
+ far = Math.max(far, c.viewFar);
327
+ }
328
+ near = Math.max(near, s.near, cam.near);
329
+ far = Math.min(far, s.far, cam.far);
330
+ const inRange = clipped.length > 0 && far > near;
331
+ if (!inRange) {
332
+ near = cam.near;
333
+ far = cam.far;
334
+ }
335
+ far = Math.max(far, near * 1.0001);
336
+ const range = [near, far];
337
+ // Rects, slices and the froxel area (no froxel work without a volume in view)
338
+ let visible = [];
339
+ if (inRange) {
340
+ for (const { volume, c } of clipped) {
341
+ const rect = vdbFrameFroxelRect(c.localToView, cam.projection, W, H);
342
+ if (!rect)
343
+ continue;
344
+ const slices = vdbFrameVolumeSlices(c.viewNear, c.viewFar, range, D);
345
+ visible.push({ volume, localToView: c.localToView, viewToLocal: c.viewToLocal, worldToLocal: c.worldToLocal, rect, first: slices.first, count: slices.count, visible: true, caster: false, emitter: false });
346
+ }
347
+ }
348
+ if (visible.length > this.#maxVolumes) {
349
+ this.#warnOnce("volumes", `${visible.length} visible volumes exceed the ${this.#maxVolumes} a frame holds (uniform binding size); the rest are not drawn.`);
350
+ visible = visible.slice(0, this.#maxVolumes);
351
+ }
352
+ const area = visible.length > 0 ? vdbFrameFroxelArea(visible, W, H, D) : null;
353
+ const froxelWork = !!area && area.count > 0;
354
+ if (!froxelWork)
355
+ visible = [];
356
+ // K7.16a: the froxel textures go after VDB_FRAME_RELEASE_UPDATES updates in a row without froxel work
357
+ this.#releaseIdleFroxels(froxelWork);
358
+ // K6.5: volume shadow maps need the shadow grid even without froxel work; the emission light needs its emitters
359
+ const shadowsWanted = VDBFrameShadowMaps.wanted(frame.lights, s.castShadows);
360
+ const usesGrid = (frameLighting && froxelWork) || shadowsWanted;
361
+ const emissionLight = frame.emissionLight ?? null;
362
+ if (!froxelWork && !shadowsWanted && !emissionLight) {
363
+ this.#shadows.update({ ...EMPTY_SHADOWS, lights: frame.lights, castShadows: s.castShadows });
364
+ this.#probes.plan(null, [], [0, 0, 0], 1);
365
+ this.#syncOutputs(versions);
366
+ this.#recorded = false;
367
+ return { outputs: this.outputs, recorded: false, volumes: 0 };
368
+ }
369
+ for (const r of visible)
370
+ r.caster = usesGrid && r.volume.castsShadow;
371
+ // Casters out of view (or not drawn) still shadow (his collector); emitters out of view still light meshes
372
+ const extra = [];
373
+ const listed = new Set(visible.map((r) => r.volume));
374
+ for (const volume of this.#volumes) {
375
+ const caster = usesGrid && volume.castsShadow;
376
+ const emitter = !!emissionLight && volume.visible && !!volume.slot.channels.emission;
377
+ if (listed.has(volume)) {
378
+ if (emitter)
379
+ visible.find((r) => r.volume === volume).emitter = true;
380
+ continue;
381
+ }
382
+ if (!caster && !emitter)
383
+ continue;
384
+ const localToView = vdbMat4Multiply(cam.view, volume.params.matrixWorld);
385
+ extra.push({ volume, localToView, viewToLocal: vdbMat4Invert(localToView), worldToLocal: vdbMat4Invert(volume.params.matrixWorld), rect: [0, 0, 0, 0], first: 0, count: 0, visible: false, caster, emitter });
386
+ }
387
+ if (visible.length + extra.length > this.#maxVolumes) {
388
+ this.#warnOnce("casters", `${visible.length + extra.length} volumes, casters and emitters exceed the ${this.#maxVolumes} a frame holds; some are left out.`);
389
+ extra.length = Math.max(0, this.#maxVolumes - visible.length);
390
+ }
391
+ // Source groups, in first-appearance order; in a group the visible non-casters, the visible casters, the
392
+ // casters that are not drawn, then emitters that are neither (gather range: the visible ones; caster range: the casters)
393
+ const bySource = new Map();
394
+ for (const r of [...visible, ...extra]) {
395
+ const list = bySource.get(r.volume.slot.source);
396
+ if (list)
397
+ list.push(r);
398
+ else
399
+ bySource.set(r.volume.slot.source, [r]);
400
+ }
401
+ const groups = [];
402
+ const ordered = [];
403
+ for (const [source, list] of bySource) {
404
+ const sorted = [...list.filter((r) => r.visible && !r.caster), ...list.filter((r) => r.visible && r.caster), ...list.filter((r) => !r.visible && r.caster), ...list.filter((r) => !r.visible && !r.caster)];
405
+ const g = {
406
+ source,
407
+ records: sorted,
408
+ first: ordered.length,
409
+ visible: sorted.filter((r) => r.visible).length,
410
+ casterStart: sorted.findIndex((r) => r.caster),
411
+ casters: sorted.filter((r) => r.caster).length,
412
+ hook: null,
413
+ };
414
+ if (g.casterStart < 0)
415
+ g.casterStart = 0;
416
+ groups.push(g);
417
+ ordered.push(...sorted);
418
+ }
419
+ const gatherGroups = groups.filter((g) => g.visible > 0);
420
+ const casterGroups = groups.filter((g) => g.casters > 0);
421
+ const multi = gatherGroups.length > 1;
422
+ // K6.5 emission colour codes (LUT rows, validated hooks; one hook per source group)
423
+ const codes = ordered.map((r) => {
424
+ if (!r.volume.slot.channels.emission)
425
+ return 0;
426
+ const c = this.#colors.codeOf(r.volume.params.emissionColor);
427
+ const g = groups.find((x) => x.source === r.volume.slot.source);
428
+ if (c.hook) {
429
+ if (g.hook && g.hook !== c.hook)
430
+ throw new VDBError("VDB_BAD_OPTION", "VDBFrameRenderer: volumes of one source use two different emission colour hooks; one hook per source (a pipeline key).");
431
+ g.hook = c.hook;
432
+ }
433
+ return c.code;
434
+ });
435
+ const lut = this.#colors.texture();
436
+ // Textures (a new size or temporal / multi-group need retires the old ones and drops the history)
437
+ const tex = froxelWork ? this.#ensureTextures(W, H, D, s.temporal, multi, layers, spectral) : null;
438
+ // Temporal validity (his historyValid && historyCamera === camera; plus a consecutive frameId)
439
+ const prev = this.#previous;
440
+ const useHistory = s.temporal && this.#historyValid && !!prev && prev.cameraId === (cam.id ?? null) && frame.frameId === prev.frameId + 1;
441
+ if (!s.temporal)
442
+ this.#historyValid = false;
443
+ // The dispatch box: this area and every rect a texture this update writes still holds
444
+ const historyOut = tex?.history ? tex.history[1 - this.#historyIndex] : null;
445
+ let box = area ? { rect: [...area.rect], first: 0, count: D } : { rect: [0, 0, 0, 0], first: 0, count: D };
446
+ if (tex) {
447
+ for (const t of [tex.scatter, tex.integrated, historyOut, tex.spectral?.scatterAlpha, tex.spectral?.integratedAlpha]) {
448
+ const w = t && this.#written.get(t);
449
+ if (w)
450
+ box = vdbFroxelAreaUnion(box, w);
451
+ }
452
+ }
453
+ // Uniforms
454
+ const projectionInverse = vdbMat4Invert(cam.projection);
455
+ const cameraWorld = vdbMat4Invert(cam.view);
456
+ const fw = this.#frameWriter;
457
+ const U = VDB_FRAME_UNIFORMS;
458
+ fw.clear(0, U.size);
459
+ fw.set(U, 0, "cameraWorld", cameraWorld);
460
+ fw.set(U, 0, "projectionInverse", projectionInverse);
461
+ fw.set(U, 0, "previousView", prev?.view ?? cam.view);
462
+ fw.set(U, 0, "previousProjection", prev?.projection ?? cam.projection);
463
+ fw.set(U, 0, "grid", [W, H, D, vdbFrameAtlasLayout(W, H, D).columns]);
464
+ fw.set(U, 0, "range", [near, far, prev?.range[0] ?? near, prev?.range[1] ?? far]);
465
+ if (area) {
466
+ fw.set(U, 0, "areaRect", area.rect);
467
+ fw.set(U, 0, "areaSlices", [area.first, area.first + area.count]);
468
+ }
469
+ fw.set(U, 0, "dispatchBox", [box.rect[0], box.rect[1], box.rect[2] - box.rect[0], box.rect[3] - box.rect[1]]);
470
+ const jitter = s.jitter ? ((frame.frameId % 1024) * 0.618034) % 1.0 : -1.0;
471
+ const fade = Number.isFinite(s.fadeRadius) && s.fadeRadius > 0 ? s.fadeRadius : 0;
472
+ fw.set(U, 0, "jitterFade", [jitter, fade, Math.min(1, Math.max(0.01, s.temporalBlend)), useHistory ? 1 : 0]);
473
+ // w: the frame seed of the stochastic density filter (issue #2 step 2; read only by those kernels)
474
+ fw.set(U, 0, "flags", [Math.max(1, Math.round(s.subSteps)), s.temporal ? 1 : 0, (cam.reversedDepth ? 1 : 0) | (cam.orthographic ? 2 : 0), frame.frameId >>> 0]);
475
+ fw.set(U, 0, "camera", [cam.near, cam.far, 0, 0]);
476
+ // K6.3: octaves (count 0: off) and 'two-sided' for both lightings ('frame' rewrites lighting.xzw in #frameGrid)
477
+ fw.set(U, 0, "octaves", vdbFrameScatteringOctaves(s));
478
+ fw.set(U, 0, "lighting", [0, s.multipleScattering === "two-sided" ? 1 : 0, 0, 0]);
479
+ // K6.4: spectral, slot groups in use ('frame' rewrites the groups in #frameGrid)
480
+ fw.set(U, 0, "spectral", [spectral ? 1 : 0, spectral ? 1 : 0, vdbFrameMsExitCode(s.msExit), 0]);
481
+ // K6.2b: the environment kernels this update runs (reduced on the GPU; no readback)
482
+ this.#env.prepare(frame.environment, s);
483
+ // K6.Q1c (D37 (5)): the ambient ring is fixed (K6.Q1a turned it per frame with jitter + temporal)
484
+ const lightInfo = this.#packLights(frame.lights, s.occlusion ? (frame.occluders ?? []) : [], frameLighting && this.#env.present && this.#env.mode === "outward");
485
+ const grid = usesGrid ? this.#frameGrid(casterGroups, cameraWorld, lightInfo, jitter, frameLighting && froxelWork) : null;
486
+ this.device.queue.writeBuffer(this.#frameBuffer, 0, fw.buffer);
487
+ // K6.5: the volume shadow map pieces (budgeted) and the emission probe work
488
+ const last = grid && grid.count > 0 ? grid.count - 1 : -1;
489
+ this.#shadows.update({
490
+ lights: frame.lights,
491
+ castShadows: s.castShadows,
492
+ coarse: s.castShadowCoarse,
493
+ steps: s.castShadowSteps,
494
+ budget: s.castShadowUpdatesPerFrame,
495
+ cascades: s.castShadowCascades,
496
+ castShadowDistance: s.castShadowDistance,
497
+ camera: { view: cam.view, cameraWorld, projectionInverse, near: cam.near, far: cam.far, orthographic: !!cam.orthographic },
498
+ grid: last >= 0 ? { min: [this.#gridMin[last].x, this.#gridMin[last].y, this.#gridMin[last].z], size: [this.#gridSize[last].x, this.#gridSize[last].y, this.#gridSize[last].z] } : null,
499
+ castVersion: this.#gridState.castVersion,
500
+ spectral,
501
+ });
502
+ this.redrawStats.volumeShadows.drawn = this.#shadows.stats.drawn;
503
+ this.redrawStats.volumeShadows.waiting = this.#shadows.stats.waiting;
504
+ const emitters = [];
505
+ if (emissionLight) {
506
+ ordered.forEach((r, i) => {
507
+ if (!r.emitter)
508
+ return;
509
+ const p = r.volume.params;
510
+ const slot = r.volume.slot;
511
+ emitters.push({
512
+ record: i,
513
+ group: groups.findIndex((g) => g.source === slot.source),
514
+ matrixWorld: p.matrixWorld,
515
+ key: [this.#sourceId(slot.source), slot.v, slot.version, slot.revision ?? -1, this.#densityScaleOf(p, slot), p.densityCutoff, p.extinction, p.absorbance, p.emissiveIntensity, ...p.temperatureRange, ...p.offset3D, WRAP_CODE[p.wrap3D] ?? 0, p.mipmaps ? 1 : 0, emissionLight.steps ?? 24, codes[i], groups.find((g) => g.source === slot.source).hook ?? "", ...Array.from({ length: 16 }, (_, k) => p.matrixWorld[k])].join(","),
516
+ });
517
+ });
518
+ }
519
+ const emission = this.#probes.plan(emissionLight, emitters, [cameraWorld[12], cameraWorld[13], cameraWorld[14]], emissionLight?.steps ?? 24);
520
+ this.#packVolumes(ordered, codes, spectral);
521
+ this.#packGroups(groups, gatherGroups, casterGroups);
522
+ // Sparse sources (K6.7) record their own work after the host's pool.update(encoder); group 2 follows their version.
523
+ for (const g of groups)
524
+ g.source.update?.(encoder);
525
+ // Record: [shadow grid per caster group, volume shadow maps, transmittance], [emission], gather per source group,
526
+ // then resolve
527
+ let pass = encoder.beginComputePass({ label: `${this.#label} froxels` });
528
+ this.#env.record(pass);
529
+ const group0 = this.#group0Bind();
530
+ if (grid?.drawGrid) {
531
+ const gt = this.#grid;
532
+ const r = gt.resolution;
533
+ casterGroups.forEach((g) => {
534
+ const built = computePipeline(this.device, vdbFrameGridDensitySpec(g.source, { multi: casterGroups.length > 1, maxVolumes: this.#maxVolumes, spectral }));
535
+ pass.setPipeline(built.pipeline);
536
+ pass.setBindGroup(0, group0);
537
+ pass.setBindGroup(1, this.#gridDensityBind(built.layouts[1], gt, casterGroups.length > 1), [groups.indexOf(g) * VDB_FRAME_GROUP_STRIDE]);
538
+ pass.setBindGroup(2, this.#sourceBind(g.source, built.layouts[2]));
539
+ pass.dispatchWorkgroups(Math.ceil(r / 4), Math.ceil(r / 4), Math.ceil((r * grid.count) / 4));
540
+ });
541
+ }
542
+ if (this.#grid && grid && grid.count > 0)
543
+ this.#shadows.record(pass, computePipeline(this.device, vdbFrameVolumeShadowSpec({ spectral })), group0, this.#grid.shadow);
544
+ // K6.3: the scattered-light term's grid mips ('mlp': box mips in this pass; 'multi-scale': K7.3's own pass), redrawn
545
+ // with the shadow grid
546
+ if (grid?.drawTransmittance && grid.count > 0) {
547
+ const kind = grid.scattering;
548
+ const version = this.#gridDraws;
549
+ if (vdbFrameScatteringIsMlp(kind) && this.#scattering.mipsStale(kind, version))
550
+ this.#scattering.recordMips(pass, group0, this.#grid.shadow, version, spectral ? this.#grid.absorption : null);
551
+ if (kind === "multi-scale" && this.#scattering.mipsStale(kind, version)) {
552
+ pass.end();
553
+ // K7.4a-3 spectral: the absorption stack's chain too
554
+ this.#scattering.recordMultiScale(encoder, this.#grid.shadow, this.#grid.shadowLayout.origins[grid.count - 1], version, spectral ? this.#grid.absorption : null);
555
+ pass = encoder.beginComputePass({ label: `${this.#label} froxels (after the multi-scale mips)` });
556
+ }
557
+ }
558
+ if (grid?.drawTransmittance) {
559
+ const gt = this.#grid;
560
+ const r = gt.resolution;
561
+ const built = computePipeline(this.device, vdbFrameTransmittanceSpec({ scattering: grid.scattering, spectral }));
562
+ pass.setPipeline(built.pipeline);
563
+ pass.setBindGroup(0, group0);
564
+ pass.setBindGroup(1, this.#transmittanceBind(built.layouts[1], gt));
565
+ // K7.4a / K7.4a-3: spectral 'mlp' and 'multi-scale' bind group 2 too (absorption mips beside the extinction ones)
566
+ const group2 = this.#scattering.group2(grid.scattering, built.layouts[2]);
567
+ if (group2)
568
+ pass.setBindGroup(2, group2);
569
+ // K6.4 spectral: one dispatch over the cascades x the slot groups in use
570
+ pass.dispatchWorkgroups(Math.ceil(r / 4), Math.ceil(r / 4), Math.ceil((r * grid.count * (spectral ? grid.groups : 1)) / 4));
571
+ }
572
+ if (grid?.drawEnvironmentGrid) {
573
+ const gt = this.#grid;
574
+ const r = gt.resolution;
575
+ const built = computePipeline(this.device, vdbFrameEnvironmentGridSpec({ spectral }));
576
+ pass.setPipeline(built.pipeline);
577
+ pass.setBindGroup(0, group0);
578
+ pass.setBindGroup(1, this.#environmentGridBind(built.layouts[1], gt));
579
+ pass.dispatchWorkgroups(Math.ceil(r / 4), Math.ceil(r / 4), Math.ceil(r / 4));
580
+ }
581
+ if (emission)
582
+ this.#recordEmission(pass, group0, groups, emission, lut);
583
+ if (tex && area) {
584
+ gatherGroups.forEach((g) => {
585
+ const built = computePipeline(this.device, vdbFrameGatherSpec(g.source, { multi, maxVolumes: this.#maxVolumes, lighting: s.lighting, hook: g.hook, spectral, stochastic: this.#stochastic() }));
586
+ pass.setPipeline(built.pipeline);
587
+ pass.setBindGroup(0, group0);
588
+ pass.setBindGroup(1, this.#gatherBind(built.layouts[1], tex, multi, frameLighting, g.source.channels.emission ? lut : null), [groups.indexOf(g) * VDB_FRAME_GROUP_STRIDE]);
589
+ pass.setBindGroup(2, this.#sourceBind(g.source, built.layouts[2]));
590
+ pass.dispatchWorkgroups(Math.ceil((box.rect[2] - box.rect[0]) / 8), Math.ceil((box.rect[3] - box.rect[1]) / 8), D);
591
+ });
592
+ const resolve = computePipeline(this.device, vdbFrameResolveSpec(this.#resolveKey()));
593
+ pass.setPipeline(resolve.pipeline);
594
+ pass.setBindGroup(0, group0);
595
+ pass.setBindGroup(1, this.#resolveBind(resolve.layouts[1], tex, s.temporal));
596
+ pass.dispatchWorkgroups(Math.ceil((box.rect[2] - box.rect[0]) / 8), Math.ceil((box.rect[3] - box.rect[1]) / 8), 1);
597
+ }
598
+ pass.end();
599
+ this.#syncOutputs(versions);
600
+ if (!tex || !area) {
601
+ this.#recorded = false;
602
+ return { outputs: this.outputs, recorded: false, volumes: 0 };
603
+ }
604
+ // Book-keeping: what each texture holds, the history swap, the previous frame
605
+ for (const t of [tex.scatter, tex.integrated, historyOut, tex.spectral?.scatterAlpha, tex.spectral?.integratedAlpha])
606
+ if (t)
607
+ this.#written.set(t, area);
608
+ if (tex.history) {
609
+ this.#historyIndex = 1 - this.#historyIndex;
610
+ this.#historyValid = true;
611
+ }
612
+ this.#previous = { view: Float64Array.from(cam.view), projection: Float64Array.from(cam.projection), range, cameraId: cam.id ?? null, frameId: frame.frameId };
613
+ const layout = { width: W, height: H, depth: D, range, screenRect: vdbFrameClipRect(area.rect, W, H, 1) };
614
+ this.outputs.froxels = { integrated: tex.integrated, integratedAlpha: tex.spectral?.integratedAlpha ?? null, layout };
615
+ this.#recorded = true;
616
+ return { outputs: this.outputs, recorded: true, volumes: visible.length };
617
+ }
618
+ /** K6.5: the shadow maps and emission probes into the outputs (a new texture object bumps `outputs.version`). */
619
+ #syncOutputs(versions) {
620
+ if (this.#shadows.version !== versions[0] || this.#probes.version !== versions[1])
621
+ this.outputs.version++;
622
+ this.outputs.emissionProbes = this.#probes.outputs;
623
+ }
624
+ /** K6.5: the emission direction passes (per source group with changed emitters), the reduce and the probes. */
625
+ #recordEmission(pass, group0, groups, plan, lut) {
626
+ const P = this.#probes;
627
+ for (const [index, range] of plan.groups) {
628
+ const g = groups[index];
629
+ const built = computePipeline(this.device, vdbFrameEmissionDirectionSpec(g.source, { maxVolumes: this.#maxVolumes, hook: g.hook }));
630
+ const b = EMISSION_DIRECTION_BINDINGS;
631
+ pass.setPipeline(built.pipeline);
632
+ pass.setBindGroup(0, group0);
633
+ const group1 = this.#cached("emission-direction", [built.layouts[1], P.listBuffer, lut, P.directionTexture], () => this.device.createBindGroup({
634
+ label: `${this.#label} emission direction group 1`,
635
+ layout: built.layouts[1],
636
+ entries: [
637
+ { binding: b.volumes, resource: { buffer: this.#volumesBuffer } },
638
+ { binding: b.emitters, resource: { buffer: P.listBuffer, size: VDB_FRAME_EMITTERS.size } },
639
+ { binding: b.lut, resource: lut.createView() },
640
+ { binding: b.directions, resource: P.directionTexture.createView() },
641
+ ],
642
+ }));
643
+ pass.setBindGroup(1, group1, [range.segment * VDB_FRAME_EMITTERS_STRIDE]);
644
+ pass.setBindGroup(2, this.#sourceBind(g.source, built.layouts[2]));
645
+ pass.dispatchWorkgroups(VDB_FRAME_EMISSION_DIRECTIONS, range.count, 1);
646
+ }
647
+ if (plan.reduce) {
648
+ const built = computePipeline(this.device, vdbFrameEmissionReduceSpec());
649
+ const b = EMISSION_REDUCE_BINDINGS;
650
+ pass.setPipeline(built.pipeline);
651
+ pass.setBindGroup(0, group0);
652
+ pass.setBindGroup(1, this.#cached("emission-reduce", [built.layouts[1], P.listBuffer, P.directionTexture, P.emitterTexture], () => this.device.createBindGroup({
653
+ label: `${this.#label} emission reduce group 1`,
654
+ layout: built.layouts[1],
655
+ entries: [
656
+ { binding: b.emitters, resource: { buffer: P.listBuffer, size: VDB_FRAME_EMITTERS.size } },
657
+ { binding: b.directions, resource: P.directionTexture.createView() },
658
+ { binding: b.out, resource: P.emitterTexture.createView() },
659
+ ],
660
+ })));
661
+ pass.dispatchWorkgroups(Math.ceil(P.slots / 64), 1, 1);
662
+ }
663
+ if (plan.probes && P.outputs) {
664
+ const built = computePipeline(this.device, vdbFrameEmissionProbeSpec());
665
+ const b = EMISSION_PROBE_BINDINGS;
666
+ const r = P.outputs.state.resolution;
667
+ pass.setPipeline(built.pipeline);
668
+ pass.setBindGroup(0, group0);
669
+ pass.setBindGroup(1, this.#cached("emission-probes", [built.layouts[1], P.emitterTexture, P.probeTexture], () => this.device.createBindGroup({
670
+ label: `${this.#label} emission probes group 1`,
671
+ layout: built.layouts[1],
672
+ entries: [
673
+ { binding: b.grid, resource: { buffer: P.gridBuffer } },
674
+ { binding: b.emitters, resource: P.emitterTexture.createView() },
675
+ { binding: b.probes, resource: P.probeTexture.createView({ dimension: "3d" }) },
676
+ ],
677
+ })));
678
+ pass.dispatchWorkgroups(Math.ceil(r / 4), Math.ceil(r / 4), Math.ceil((r * P.outputs.state.count) / 4));
679
+ }
680
+ }
681
+ /** A stable number per source object (the caster signature's source identity). */
682
+ #sourceId(source) {
683
+ let id = this.#sourceIds.get(source);
684
+ if (id === undefined)
685
+ this.#sourceIds.set(source, (id = this.#nextSourceId++));
686
+ return id;
687
+ }
688
+ /**
689
+ * 'frame' lighting's CPU work (his updateGrid, updateGridSignatures, transmittanceUnchanged): the cascades around
690
+ * the casters and the camera, the grid textures, the grid uniforms, and which kernels must run.
691
+ */
692
+ #frameGrid(casterGroups, cameraWorld, lights, jitter, transmittance = true) {
693
+ const s = this.settings;
694
+ const fw = this.#frameWriter;
695
+ const U = VDB_FRAME_UNIFORMS;
696
+ const cascades = Math.min(VDB_FRAME_MAX_CASCADES, Math.max(1, Math.round(s.shadowCascades)));
697
+ const spectral = !!s.spectral;
698
+ const casters = casterGroups.flatMap((g) => g.records.filter((r) => r.caster));
699
+ const boxes = casters.map((r) => {
700
+ const b = vdbUnitBoxBounds(r.volume.params.matrixWorld);
701
+ return { min: { x: b.min[0], y: b.min[1], z: b.min[2] }, max: { x: b.max[0], y: b.max[1], z: b.max[2] } };
702
+ });
703
+ const base = Math.max(2, Math.round(s.shadowResolution));
704
+ // K6.Q1b: the size-adaptive grid (`shadowResolutionMax` above `shadowResolution`), from the casters' boxes and media
705
+ // K6.Q1d-a: the dipole targets exist only while a gather reads them (the lights say whether, `#packLights`)
706
+ const dipole = lights.dipoleTargets;
707
+ const resolution = this.#gridResolution(s.shadowResolutionMax > base ? this.#adaptiveResolution(casters, boxes, base) : base, cascades, spectral, dipole);
708
+ this.shadowGridResolution = resolution;
709
+ // K6.4: the slot groups in use (his getFrameSpectralGroups over the scene slots and the environment slot, set below)
710
+ const sceneSlotCount = Math.min(lights.sorted.length, VDB_FRAME_SHADOW_SLOTS);
711
+ const envSlotWanted = this.#env.present && this.#env.mode === "directional" && sceneSlotCount < VDB_FRAME_SHADOW_SLOTS && !(!!s.multipleScattering && s.multipleScattering !== "octaves");
712
+ const groups = spectral ? vdbFrameSpectralGroups(sceneSlotCount + (envSlotWanted ? 1 : 0)) : 0;
713
+ const gt = this.#ensureGrid(resolution, cascades, casterGroups.length > 1, spectral, groups, dipole, s.lighting === "frame");
714
+ const cameraPosition = { x: cameraWorld[12], y: cameraWorld[13], z: cameraWorld[14] };
715
+ const count = casters.length > 0 ? vdbFrameGridCascades(boxes, cameraPosition, s.shadowDistance, resolution, cascades, this.#gridMin, this.#gridSize, this.#gridVoxel) : 0;
716
+ vdbFrameUpdateGridSignatures(this.#gridState, count > 0 ? casters : [], count, resolution, false, this.#gridMin, this.#gridSize, (values, r) => {
717
+ const p = r.volume.params;
718
+ const slot = r.volume.slot;
719
+ for (let i = 0; i < 16; i++)
720
+ values.push(p.matrixWorld[i]);
721
+ // K4.22: `revision` too (a same-size dense replace keeps `version`: a sequence frame, a streamed page)
722
+ values.push(this.#sourceId(slot.source), slot.v, slot.version, slot.revision ?? -1, ...p.baseColor, this.#densityScaleOf(p, slot), p.densityCutoff, p.extinction, p.absorbance, p.mipmaps ? 1 : 0, WRAP_CODE[p.wrap3D] ?? 0, ...p.offset3D);
723
+ // K6.4: the spectral grid holds each channel's extinction
724
+ if (spectral)
725
+ values.push(...p.extinctionScale, p.angstromExponent);
726
+ });
727
+ const shadowSlots = Math.min(lights.sorted.length, VDB_FRAME_SHADOW_SLOTS);
728
+ const ms = vdbFrameMultipleScatteringValue(s.multipleScattering === "octaves" ? false : s.multipleScattering, this.#phaseOf(null));
729
+ const diffusion = !!s.multipleScattering && s.multipleScattering !== "octaves";
730
+ const phaseFields = this.#phaseOf(null);
731
+ const phase = vdbFramePhaseVector(phaseFields);
732
+ const twoSided = s.multipleScattering === "two-sided";
733
+ const octaves = vdbFrameScatteringOctaves(s);
734
+ const v = (a) => [a.x, a.y, a.z, 0];
735
+ for (let c = 0; c < VDB_FRAME_MAX_CASCADES; c++) {
736
+ const live = c < count;
737
+ if (!live)
738
+ continue;
739
+ const at = (name, value) => {
740
+ const slot = U.fields.get(name);
741
+ const base = (slot.offset + c * slot.stride) / 4;
742
+ for (let k = 0; k < value.length; k++)
743
+ fw.f32[base + k] = value[k];
744
+ };
745
+ at("gridMin", v(this.#gridMin[c]));
746
+ at("gridSize", v(this.#gridSize[c]));
747
+ at("gridVoxel", v(this.#gridVoxel[c]));
748
+ at("shadowOrigin", [...gt.shadowLayout.origins[c], 0]);
749
+ if (!spectral) {
750
+ for (let k = 0; k < 4; k++) {
751
+ const slot = U.fields.get("transmittanceOrigin");
752
+ const base = (slot.offset + (4 * c + k) * slot.stride) / 4;
753
+ const o = gt.transmittanceLayout.origins[4 * c + k];
754
+ fw.f32[base] = o[0];
755
+ fw.f32[base + 1] = o[1];
756
+ fw.f32[base + 2] = o[2];
757
+ }
758
+ }
759
+ // K6.Q1d: the pairs' dipole of cascade c at [VDB_FRAME_DIPOLE_ORIGIN + c] (spectral: + 3c + k, channel k), after
760
+ // the slot-group targets of the allocated cascades in the layout
761
+ if (gt.dipole) {
762
+ const slot = U.fields.get("transmittanceOrigin");
763
+ const perCascade = spectral ? 3 : 1;
764
+ const first = spectral ? 3 * gt.groups * gt.cascades : 4 * gt.cascades;
765
+ for (let k = 0; k < perCascade; k++) {
766
+ const base = (slot.offset + (VDB_FRAME_DIPOLE_ORIGIN + perCascade * c + k) * slot.stride) / 4;
767
+ const o = gt.transmittanceLayout.origins[first + perCascade * c + k];
768
+ fw.f32[base] = o[0];
769
+ fw.f32[base + 1] = o[1];
770
+ fw.f32[base + 2] = o[2];
771
+ }
772
+ }
773
+ }
774
+ // K6.4 spectral: target k of slot group g of cascade c at [3 (g count + c) + k]
775
+ if (spectral && count > 0) {
776
+ const slot = U.fields.get("transmittanceOrigin");
777
+ for (let g = 0; g < groups; g++)
778
+ for (let c = 0; c < count; c++)
779
+ for (let k = 0; k < 3; k++) {
780
+ const i = 3 * (g * count + c) + k;
781
+ const o = gt.transmittanceLayout.origins[i];
782
+ const base = (slot.offset + i * slot.stride) / 4;
783
+ fw.f32[base] = o[0];
784
+ fw.f32[base + 1] = o[1];
785
+ fw.f32[base + 2] = o[2];
786
+ }
787
+ }
788
+ fw.set(U, 0, "spectral", [spectral ? 1 : 0, spectral ? groups : 0, vdbFrameMsExitCode(s.msExit), 0]);
789
+ fw.set(U, 0, "gridLayout", [count, resolution, vdbFrameAtlasLayout(resolution, resolution, resolution * cascades).columns, shadowSlots]);
790
+ fw.set(U, 0, "lighting", [ms, twoSided ? 1 : 0, count > 0 ? 1 : 0, diffusion ? 1 : 0]);
791
+ fw.set(U, 0, "framePhase", phase);
792
+ fw.set(U, 0, "framePhaseSpectrum", [...vdbFramePhaseSpectrum(phaseFields), 0]);
793
+ // K6.2b: his light result. The dominant 'directional' environment light takes the next free slot (not with
794
+ // diffusion: then every environment light goes to the environment grid, opposite pairs get the same march);
795
+ // the environment grid holds the others. Its direction and colour are on the GPU only (the buffer).
796
+ const env = this.#env;
797
+ const envSlot = env.present && env.mode === "directional" && shadowSlots < VDB_FRAME_SHADOW_SLOTS && !diffusion;
798
+ const envGrid = env.present && env.mode !== "outward" && count > 0;
799
+ fw.set(U, 0, "environment", [envSlot ? 1 : 0, envSlot ? 1 : 0, envGrid ? 1 : 0, env.present ? 1 : 0]);
800
+ // His redraw skips: the grid when its version or texture changed; the transmittance when its signature did (a
801
+ // jittered grid is drawn every frame)
802
+ const drawGrid = count > 0 && (this.#gridDrawn !== this.#gridState.gridVersion);
803
+ if (count > 0) {
804
+ if (drawGrid) {
805
+ this.redrawStats.shadowDensity.drawn++;
806
+ this.#gridDraws++;
807
+ }
808
+ else
809
+ this.redrawStats.shadowDensity.skipped++;
810
+ this.#gridDrawn = this.#gridState.gridVersion;
811
+ }
812
+ // K6.5: the volume shadow maps alone ('volume' lighting, or no volume in view) need only the grid
813
+ if (!transmittance)
814
+ return { count, drawGrid, drawTransmittance: false, drawEnvironmentGrid: false, scattering: "none", groups };
815
+ // K6.3: the scattered-light term of the slots ('mlp', 'multi-scale' as a pipeline key; two-sided, octaves uniforms)
816
+ // K7.4a / K7.4a-3: spectral 'mlp' and 'multi-scale' run per channel
817
+ const scattering = count > 0 ? this.#scattering.kind(s, this.mlp) : "none";
818
+ const last = Math.max(0, count - 1);
819
+ const plan = count > 0
820
+ ? this.#scattering.plan(scattering, s, {
821
+ resolution,
822
+ min: v(this.#gridMin[last]),
823
+ size: v(this.#gridSize[last]),
824
+ voxel: v(this.#gridVoxel[last]),
825
+ origin: gt.shadowLayout.origins[last],
826
+ // K6.Nb: the casters' box size ('world' MLP reaches; the last cascade fits it)
827
+ extent: ["x", "y", "z"].map((a) => Math.max(...boxes.map((b) => b.max[a])) - Math.min(...boxes.map((b) => b.min[a]))),
828
+ }, ms,
829
+ // K6.Nb / K6.Nb2: the phase of an `extra` network's anisotropy inputs ('g', 'phase')
830
+ { phase, spectrum: vdbFramePhaseSpectrum(phaseFields) })
831
+ : { kind: scattering, signature: [] };
832
+ // K6.Q1: the shadowed ambient's pairs and directions
833
+ // K7.15: whether the sky up / down marches run (his frameSkyMarch is in his signature too)
834
+ const signature = [this.#gridDraws, gt.shadow, gt.transmittance, shadowSlots, ms, ...lights.sky, lights.skyMarch, envSlot, envSlot ? env.version : -1, twoSided, ...octaves, ...plan.signature, ...lights.ambient, spectral, groups, gt.dipole];
835
+ for (let i = 0; i < shadowSlots; i++)
836
+ signature.push(...lights.sorted[i].slice(0, 4));
837
+ // K6.5b: the slot lights' occluder maps (view, matrices, bias, flags, revision); a map without a revision changes
838
+ // every update
839
+ let occluderChanging = false;
840
+ for (let i = 0; i < shadowSlots; i++) {
841
+ const o = lights.occluderOf[i];
842
+ if (!o)
843
+ continue;
844
+ if (o.revision === undefined)
845
+ occluderChanging = true;
846
+ signature.push(i, o.depth, o.revision ?? -1, o.bias ?? 0, o.reversedDepth ? 1 : 0, o.filter ?? "bilinear", o.viewProjection.length);
847
+ for (const m of o.viewProjection)
848
+ for (let k = 0; k < 16; k++)
849
+ signature.push(m[k]);
850
+ }
851
+ const redraw = jitter >= 0 || occluderChanging;
852
+ const drawTransmittance = count > 0 && (redraw || !vdbSameValues(signature, this.#transmittanceSignature));
853
+ this.#transmittanceSignature = redraw ? [] : signature;
854
+ if (count > 0) {
855
+ if (drawTransmittance)
856
+ this.redrawStats.transmittance.drawn++;
857
+ else
858
+ this.redrawStats.transmittance.skipped++;
859
+ }
860
+ // his renderEnvironmentGrid signature: the grid (its version covers the cascades and casters), ms, the lights
861
+ const envSignature = [this.#gridDraws, gt.shadow, gt.environment, count, ms, envSlot, env.version, ...octaves, spectral];
862
+ const drawEnvironmentGrid = envGrid && !vdbSameValues(envSignature, this.#envGridSignature);
863
+ if (envGrid) {
864
+ if (drawEnvironmentGrid)
865
+ this.redrawStats.environmentGrid.drawn++;
866
+ else
867
+ this.redrawStats.environmentGrid.skipped++;
868
+ this.#envGridSignature = envSignature;
869
+ }
870
+ return { count, drawGrid, drawTransmittance, drawEnvironmentGrid, scattering: plan.kind, groups };
871
+ }
872
+ /**
873
+ * K6.Q1b: the size-adaptive shadow grid side for these casters (`vdbFrameAdaptiveGridResolution`): each caster's
874
+ * world box, voxels across it and the shadow grid's extinction at its mean density (absorbance included, as the grid
875
+ * density pass) give the cell size of the rule; the side covers the casters' box with it, within [base, max].
876
+ */
877
+ #adaptiveResolution(casters, boxes, base) {
878
+ const r = this.settings.shadowResolutionRule;
879
+ const rule = r === "voxels" || r === "optical" ? r : "both";
880
+ const inputs = casters.map((r, i) => {
881
+ const p = r.volume.params;
882
+ const slot = r.volume.slot;
883
+ const b = boxes[i];
884
+ const mean = p.densityMean ?? slot.stats.meanNonZero;
885
+ return {
886
+ size: [b.max.x - b.min.x, b.max.y - b.min.y, b.max.z - b.min.z],
887
+ texels: [...slot.texels],
888
+ meanExtinction: (mean * this.#densityScaleOf(p, slot) * p.extinction * p.absorbance) / Math.max(vdbMat4MaxScale(p.matrixWorld), 1e-30),
889
+ };
890
+ });
891
+ return vdbFrameAdaptiveGridResolution(boxes, vdbFrameAdaptiveCellSize(inputs, rule), base, Math.round(this.settings.shadowResolutionMax));
892
+ }
893
+ /**
894
+ * K6.8 / K6.10a: the shadow grid resolution the device can hold. The transmittance stack (4 rgba16float targets per
895
+ * cascade, 3 per slot group and cascade when spectral) is one texture that must tile in `maxTextureDimension3D`; Dawn
896
+ * zero-fills a new texture through one staging buffer of its size, so a stack larger than the device's
897
+ * `maxBufferSize` (256 MiB by default: R = 256 with one cascade is 512 MiB) fails the host's submit and the frame is
898
+ * lost. Clamp R so the stack tiles and fits (warned once; `vdbFrameFitGridResolution`).
899
+ */
900
+ #gridResolution(resolution, cascades, spectral, dipole) {
901
+ const key = `${resolution}-${cascades}-${spectral}-${dipole}`;
902
+ const cached = this.#gridFits.get(key);
903
+ if (cached !== undefined)
904
+ return cached;
905
+ const limits = this.device.limits ?? {};
906
+ const fit = vdbFrameFitGridResolution(resolution, cascades, spectral, limits, dipole);
907
+ if (fit.reason) {
908
+ const targets = vdbFrameStackTargets(cascades, spectral, dipole);
909
+ const maxDim = limits.maxTextureDimension3D ?? VDB_FRAME_DEFAULT_LIMITS.maxTextureDimension3D;
910
+ const maxMiB = Math.round((limits.maxBufferSize ?? VDB_FRAME_DEFAULT_LIMITS.maxBufferSize) / 1048576);
911
+ const why = fit.reason === "tile" ? `its ${targets} stack targets of ${resolution}³ do not tile in maxTextureDimension3D` : `its transmittance stack of ${Math.round((resolution ** 3 * targets * 8) / 1048576)} MiB exceeds maxBufferSize`;
912
+ this.#warnOnce(`grid-resolution-${key}`, `settings.shadowResolution ${resolution}: ${why} (the device: maxTextureDimension3D ${maxDim}, maxBufferSize ${maxMiB} MiB); clamped to ${fit.size}.`);
913
+ }
914
+ this.#gridFits.set(key, fit.size);
915
+ return fit.size;
916
+ }
917
+ /**
918
+ * The grid textures for this resolution and cascade count. A new shadow grid (resolution, cascades, grey / spectral)
919
+ * retires the old set and redraws everything. K7.16 (his VDB-168): the transmittance stack and the environment grid
920
+ * exist only with `lighting` ('frame' lighting; 'volume' lighting's volume shadow maps read the shadow grid alone); a
921
+ * new stack (another slot-group count, the K6.Q1d dipole targets coming or going, 'frame' lighting back on) redraws
922
+ * the transmittance only. Spectral slot groups grow at once and shrink after {@link VDB_FRAME_RELEASE_UPDATES} updates in a row that need
923
+ * fewer (his 120 lighting renders); the multi-group partials go after as many updates with one caster group.
924
+ */
925
+ #ensureGrid(resolution, cascades, multi, spectral = false, groups = 0, dipole = false, lighting = true) {
926
+ const maxDim = this.device.limits?.maxTextureDimension3D ?? 2048;
927
+ const transmittanceLayout = (keep, withDipole) => {
928
+ const dipoleTargets = withDipole ? (spectral ? 3 : 1) * cascades : 0;
929
+ return vdbFrameStackLayout(resolution, (spectral ? 3 * keep * cascades : 4 * cascades) + dipoleTargets, maxDim);
930
+ };
931
+ let g = this.#grid;
932
+ if (!g || g.resolution !== resolution || g.cascades !== cascades || !!g.absorption !== spectral) {
933
+ if (g)
934
+ this.#retireGrid(g);
935
+ const shadowLayout = vdbFrameStackLayout(resolution, cascades, maxDim);
936
+ const keep = spectral ? Math.min(VDB_FRAME_SPECTRAL_GROUPS, Math.max(1, groups)) : 0;
937
+ g = {
938
+ resolution,
939
+ cascades,
940
+ shadowLayout,
941
+ transmittanceLayout: transmittanceLayout(keep, dipole),
942
+ shadow: createFroxelTexture(this.device, `${this.#label} shadow grid`, shadowLayout.size, "rgba16float"),
943
+ transmittance: null,
944
+ partials: null,
945
+ environment: null,
946
+ absorption: spectral ? createFroxelTexture(this.device, `${this.#label} shadow grid absorption`, shadowLayout.size, "rgba16float") : null,
947
+ groups: keep,
948
+ dipole,
949
+ };
950
+ this.#grid = g;
951
+ this.#groupsLow = { updates: 0, most: 0 };
952
+ this.#gridPartialsIdle = 0;
953
+ // A new texture is empty: draw the grid again
954
+ this.#gridDrawn = -1;
955
+ }
956
+ // K6.4 / K7.16: the slot groups the stack keeps; K6.Q1d-a: the dipole targets come and go with their readers
957
+ const keep = spectral ? this.#keptGroups(g.groups, groups) : 0;
958
+ if (keep !== g.groups || dipole !== g.dipole) {
959
+ g.groups = keep;
960
+ g.dipole = dipole;
961
+ g.transmittanceLayout = transmittanceLayout(keep, dipole);
962
+ this.#retire.retire(g.transmittance);
963
+ g.transmittance = null;
964
+ }
965
+ if (lighting && !g.transmittance)
966
+ g.transmittance = createFroxelTexture(this.device, `${this.#label} transmittance`, g.transmittanceLayout.size, "rgba16float");
967
+ if (lighting && !g.environment)
968
+ g.environment = createFroxelTexture(this.device, `${this.#label} environment grid`, [resolution, resolution, resolution], "rgba16float");
969
+ if (!lighting)
970
+ this.#releaseLighting(g);
971
+ // spectral multi-group partials: 3 words per voxel (the stack depth × 3)
972
+ if (multi) {
973
+ this.#gridPartialsIdle = 0;
974
+ if (!g.partials) {
975
+ const size = g.shadowLayout.size;
976
+ g.partials = createFroxelTexture(this.device, `${this.#label} grid partials`, [size[0], size[1], size[2] * (spectral ? VDB_FRAME_SPECTRAL_GRID_WORDS : 1)], "r32uint", false);
977
+ }
978
+ }
979
+ else if (g.partials && ++this.#gridPartialsIdle >= VDB_FRAME_RELEASE_UPDATES) {
980
+ this.#retire.retire(g.partials);
981
+ g.partials = null;
982
+ this.#gridPartialsIdle = 0;
983
+ }
984
+ // A new transmittance or environment texture is empty (their signatures name the texture, so they draw again)
985
+ return g;
986
+ }
987
+ /**
988
+ * K7.16: the slot groups a spectral transmittance stack keeps when this update uses `groups`: more at once; fewer only
989
+ * after {@link VDB_FRAME_RELEASE_UPDATES} updates in a row that used fewer (then the most of them), so cameras or
990
+ * light sets that alternate do not reallocate the stack every frame (his `trimSpectralTransmittanceTargets`).
991
+ */
992
+ #keptGroups(current, groups) {
993
+ const want = Math.min(VDB_FRAME_SPECTRAL_GROUPS, Math.max(1, groups));
994
+ if (want >= current) {
995
+ this.#groupsLow = { updates: 0, most: 0 };
996
+ return want;
997
+ }
998
+ const low = this.#groupsLow;
999
+ low.updates++;
1000
+ low.most = Math.max(low.most, want);
1001
+ if (low.updates < VDB_FRAME_RELEASE_UPDATES)
1002
+ return current;
1003
+ const kept = low.most;
1004
+ this.#groupsLow = { updates: 0, most: 0 };
1005
+ return kept;
1006
+ }
1007
+ /** K7.16: retires the transmittance stack and the environment grid ('volume' lighting); 'frame' lighting makes them again. */
1008
+ #releaseLighting(g) {
1009
+ if (!g.transmittance && !g.environment)
1010
+ return;
1011
+ this.#retire.retire(g.transmittance);
1012
+ this.#retire.retire(g.environment);
1013
+ g.transmittance = null;
1014
+ g.environment = null;
1015
+ this.#transmittanceSignature = [];
1016
+ this.#envGridSignature = [];
1017
+ }
1018
+ /** Retires every grid texture. */
1019
+ #retireGrid(g) {
1020
+ for (const t of [g.shadow, g.transmittance, g.partials, g.environment, g.absorption])
1021
+ this.#retire.retire(t);
1022
+ this.#transmittanceSignature = [];
1023
+ this.#envGridSignature = [];
1024
+ }
1025
+ /**
1026
+ * K7.16 (his VDB-168): retires the textures of features the settings turned off, at the next update: the froxel history
1027
+ * (`temporal` off), the 'frame' lighting stacks ('volume' lighting; the whole grid without `castShadows` too) and the
1028
+ * scattered-light mips of the other multiple-scattering modes. Turning a feature on makes them again, empty: the
1029
+ * history is invalid and the redraw signatures name the new textures (the grid draws again from `#gridDrawn` −1).
1030
+ * Scene-driven needs (partials, slot groups, K7.16a the froxel textures themselves) wait for
1031
+ * {@link VDB_FRAME_RELEASE_UPDATES} updates in `#ensureGrid`, `#ensureTextures` and `#releaseIdleFroxels`.
1032
+ */
1033
+ #releaseUnused() {
1034
+ const s = this.settings;
1035
+ const t = this.#textures;
1036
+ if (t?.history && !s.temporal) {
1037
+ t.history.forEach((h) => this.#retire.retire(h));
1038
+ t.history = null;
1039
+ this.#historyValid = false;
1040
+ this.#historyIndex = 0;
1041
+ }
1042
+ const g = this.#grid;
1043
+ if (g && s.lighting !== "frame") {
1044
+ if (s.castShadows)
1045
+ this.#releaseLighting(g);
1046
+ else {
1047
+ this.#retireGrid(g);
1048
+ this.#grid = null;
1049
+ this.#gridDrawn = -1;
1050
+ }
1051
+ }
1052
+ // K7.4a-3: grey and spectral alike (K7.16 kept them for grey media only, so spectral 'neural' made new mips and redrew
1053
+ // the transmittance every update)
1054
+ const frame = s.lighting === "frame";
1055
+ const mode = s.multipleScattering;
1056
+ this.#scattering.release({ mlp: frame && (mode === "neural" || mode === "mlp"), multiScale: frame && mode === "multi-scale" });
1057
+ }
1058
+ /**
1059
+ * K7.16a: retires every froxel texture (scatter, integrated, the history pair, the multi-group partials, the spectral
1060
+ * alpha pair) after {@link VDB_FRAME_RELEASE_UPDATES} updates in a row without froxel work: no visible volume clipped
1061
+ * into the view (out of view, `visible = false`, or an empty froxel area). Shadow casters and emitters out of view are
1062
+ * not froxel work (the shadow grid, volume shadow maps and emission probes read no froxel texture). Any update with
1063
+ * froxel work restarts the count; `update(…, { froxels: false })` returns before it and leaves it as it is. The
1064
+ * outputs drop the froxels at once (`outputs.froxels` null, `outputs.version` + 1), so a host never binds a retired
1065
+ * texture; the next update with froxel work makes the textures again, empty, and the history invalid. A host that
1066
+ * passes a new `frameId` per update has no history at that frame anyway (the last froxel frame is 120 ids back), so it
1067
+ * renders as a renderer that kept them (the dispatch box of kept textures also clears their old rect: zeros either way).
1068
+ */
1069
+ #releaseIdleFroxels(froxelWork) {
1070
+ const t = this.#textures;
1071
+ if (froxelWork || !t) {
1072
+ this.#froxelIdle = 0;
1073
+ return;
1074
+ }
1075
+ if (++this.#froxelIdle < VDB_FRAME_RELEASE_UPDATES)
1076
+ return;
1077
+ for (const x of [t.scatter, t.integrated, ...(t.history ?? []), t.partials, t.spectral?.scatterAlpha, t.spectral?.integratedAlpha])
1078
+ this.#retire.retire(x);
1079
+ this.#textures = null;
1080
+ this.#historyValid = false;
1081
+ this.#historyIndex = 0;
1082
+ this.#froxelPartialsIdle = 0;
1083
+ this.#froxelIdle = 0;
1084
+ this.outputs.froxels = null;
1085
+ this.outputs.version++;
1086
+ }
1087
+ #ensureTextures(W, H, D, temporal, multi, layers, spectral = false) {
1088
+ const t = this.#textures;
1089
+ // K7.16: the multi-group partials go after VDB_FRAME_RELEASE_UPDATES updates in a row with one gather group (the
1090
+ // history goes with `temporal` in #releaseUnused)
1091
+ if (multi)
1092
+ this.#froxelPartialsIdle = 0;
1093
+ else if (t?.partials && ++this.#froxelPartialsIdle >= VDB_FRAME_RELEASE_UPDATES) {
1094
+ this.#retire.retire(t.partials);
1095
+ t.partials = null;
1096
+ t.partialLayers = 0;
1097
+ this.#froxelPartialsIdle = 0;
1098
+ }
1099
+ // K6.4: grey and spectral froxel textures differ (the alpha textures, a history twice as deep)
1100
+ const sameSize = !!t && t.size[0] === W && t.size[1] === H && t.size[2] === D && !!t.spectral === spectral;
1101
+ if (t && sameSize && (!temporal || t.history) && (!multi || (t.partials && t.partialLayers === layers))) {
1102
+ return t;
1103
+ }
1104
+ let changed = false;
1105
+ const next = sameSize && t ? { ...t } : (() => {
1106
+ if (t) {
1107
+ this.#retire.retire(t.scatter);
1108
+ this.#retire.retire(t.integrated);
1109
+ t.history?.forEach((h) => this.#retire.retire(h));
1110
+ this.#retire.retire(t.partials);
1111
+ this.#retire.retire(t.spectral?.scatterAlpha);
1112
+ this.#retire.retire(t.spectral?.integratedAlpha);
1113
+ }
1114
+ changed = true;
1115
+ this.#historyValid = false;
1116
+ const alphaFormat = this.#tier1 ? "rg16float" : "rgba16float";
1117
+ return {
1118
+ size: [W, H, D],
1119
+ scatter: createFroxelTexture(this.device, `${this.#label} scatter`, [W, H, D], "rgba16float"),
1120
+ integrated: createFroxelTexture(this.device, `${this.#label} integrated`, [W, H, D + 1], "rgba16float"),
1121
+ history: null,
1122
+ partials: null,
1123
+ partialLayers: 0,
1124
+ spectral: spectral
1125
+ ? {
1126
+ scatterAlpha: createFroxelTexture(this.device, `${this.#label} scatter alpha`, [W, H, D], "rgba16float"),
1127
+ integratedAlpha: createFroxelTexture(this.device, `${this.#label} integrated alpha`, [W, H, D + 1], alphaFormat),
1128
+ alphaFormat,
1129
+ }
1130
+ : null,
1131
+ };
1132
+ })();
1133
+ if (temporal && !next.history) {
1134
+ // K6.4 spectral: the scatter history at z < D, the alpha history at z >= D
1135
+ const depth = spectral ? 2 * D : D;
1136
+ next.history = [createFroxelTexture(this.device, `${this.#label} history 0`, [W, H, depth], "rgba16float"), createFroxelTexture(this.device, `${this.#label} history 1`, [W, H, depth], "rgba16float")];
1137
+ this.#historyValid = false;
1138
+ this.#historyIndex = 0;
1139
+ }
1140
+ if (multi && (!next.partials || next.partialLayers !== layers)) {
1141
+ this.#retire.retire(next.partials);
1142
+ next.partials = createFroxelTexture(this.device, `${this.#label} partials`, [W, H, layers * D], "r32uint", false);
1143
+ next.partialLayers = layers;
1144
+ }
1145
+ this.#textures = next;
1146
+ if (changed)
1147
+ this.outputs.version++;
1148
+ return next;
1149
+ }
1150
+ /** The resolve kernel's key: temporal, K6.4 spectral and the alpha prefix format. */
1151
+ #resolveKey() {
1152
+ return { temporal: this.settings.temporal, spectral: !!this.settings.spectral, alphaFormat: this.#tier1 ? "rg16float" : "rgba16float" };
1153
+ }
1154
+ #group0Bind() {
1155
+ if (!this.#group0) {
1156
+ const layout = computePipeline(this.device, vdbFrameResolveSpec({ temporal: false })).layouts[0];
1157
+ this.#group0 = this.device.createBindGroup({
1158
+ label: `${this.#label} group 0`,
1159
+ layout,
1160
+ entries: [
1161
+ { binding: 0, resource: { buffer: this.#frameBuffer } },
1162
+ { binding: 1, resource: { buffer: this.#lightsBuffer } },
1163
+ { binding: 2, resource: this.#linear },
1164
+ { binding: 3, resource: { buffer: this.#env.buffer } },
1165
+ { binding: 4, resource: { buffer: this.#mie } },
1166
+ ],
1167
+ });
1168
+ }
1169
+ return this.#group0;
1170
+ }
1171
+ #bindCache = new Map();
1172
+ /** A bind group cached on the identity of everything it binds (rebuilt when one changes). */
1173
+ #cached(name, keys, make) {
1174
+ const hit = this.#bindCache.get(name);
1175
+ if (hit && hit.keys.length === keys.length && hit.keys.every((k, i) => k === keys[i]))
1176
+ return hit.group;
1177
+ const group = make();
1178
+ this.#bindCache.set(name, { keys, group });
1179
+ return group;
1180
+ }
1181
+ /** K6.5b: the 4 occluder slot views of this update (the placeholder in empty slots). */
1182
+ #occluderSlots() {
1183
+ if (!this.#occluderPlaceholder) {
1184
+ const texture = this.device.createTexture({ label: `${this.#label} occluder placeholder`, size: [1, 1, 1], format: "r32float", usage: 0x04 /* TEXTURE_BINDING */ });
1185
+ this.#occluderPlaceholder = { texture, view: texture.createView({ dimension: "2d-array" }) };
1186
+ }
1187
+ const placeholder = this.#occluderPlaceholder.view;
1188
+ return [0, 1, 2, 3].map((k) => this.#occluderViews[k] ?? placeholder);
1189
+ }
1190
+ /** K6.5b: the group-1 entries of the occluder slots. */
1191
+ #occluderEntries(views) {
1192
+ return views.map((view, k) => ({ binding: VDB_FRAME_OCCLUDER_BINDING + k, resource: view }));
1193
+ }
1194
+ #gatherBind(layout, tex, multi, frameLighting, lut) {
1195
+ const b = frameLighting ? FRAME_GATHER_BINDINGS : GATHER_BINDINGS;
1196
+ const transmittance = frameLighting ? this.#grid.transmittance : null;
1197
+ const environment = frameLighting ? this.#grid.environment : null;
1198
+ const alpha = tex.spectral?.scatterAlpha ?? null;
1199
+ const name = `gather${frameLighting ? "-frame" : ""}${multi ? "-multi" : ""}${lut ? "-lut" : ""}${alpha ? "-spectral" : ""}`;
1200
+ const occluders = this.#occluderSlots();
1201
+ return this.#cached(name, [layout, tex.scatter, ...(multi ? [tex.partials] : []), ...(transmittance ? [transmittance, environment] : []), ...(lut ? [lut] : []), ...(alpha ? [alpha] : []), this.#groupsBuffer, ...occluders], () => this.device.createBindGroup({
1202
+ label: `${this.#label} gather group 1`,
1203
+ layout,
1204
+ entries: [
1205
+ { binding: b.volumes, resource: { buffer: this.#volumesBuffer } },
1206
+ { binding: b.group, resource: { buffer: this.#groupsBuffer, size: VDB_FRAME_GROUP.size } },
1207
+ { binding: b.scatter, resource: tex.scatter.createView({ dimension: "3d" }) },
1208
+ ...(multi ? [{ binding: b.partials, resource: tex.partials.createView({ dimension: "3d" }) }] : []),
1209
+ ...(transmittance
1210
+ ? [
1211
+ { binding: FRAME_GATHER_BINDINGS.transmittance, resource: transmittance.createView({ dimension: "3d" }) },
1212
+ { binding: FRAME_GATHER_BINDINGS.environmentGrid, resource: environment.createView({ dimension: "3d" }) },
1213
+ ]
1214
+ : []),
1215
+ ...(lut ? [{ binding: b.emissionLut, resource: lut.createView() }] : []),
1216
+ ...(alpha ? [{ binding: b.scatterAlpha, resource: alpha.createView({ dimension: "3d" }) }] : []),
1217
+ ...this.#occluderEntries(occluders),
1218
+ ],
1219
+ }));
1220
+ }
1221
+ #gridDensityBind(layout, gt, multi) {
1222
+ const b = GRID_DENSITY_BINDINGS;
1223
+ const absorption = gt.absorption;
1224
+ return this.#cached(`grid-density${multi ? "-multi" : ""}${absorption ? "-spectral" : ""}`, [layout, gt.shadow, ...(multi ? [gt.partials] : []), ...(absorption ? [absorption] : []), this.#groupsBuffer], () => this.device.createBindGroup({
1225
+ label: `${this.#label} grid density group 1`,
1226
+ layout,
1227
+ entries: [
1228
+ { binding: b.volumes, resource: { buffer: this.#volumesBuffer } },
1229
+ { binding: b.group, resource: { buffer: this.#groupsBuffer, size: VDB_FRAME_GROUP.size } },
1230
+ { binding: b.grid, resource: gt.shadow.createView({ dimension: "3d" }) },
1231
+ ...(multi ? [{ binding: b.partials, resource: gt.partials.createView({ dimension: "3d" }) }] : []),
1232
+ ...(absorption ? [{ binding: b.absorption, resource: absorption.createView({ dimension: "3d" }) }] : []),
1233
+ ],
1234
+ }));
1235
+ }
1236
+ #transmittanceBind(layout, gt) {
1237
+ const b = TRANSMITTANCE_BINDINGS;
1238
+ const occluders = this.#occluderSlots();
1239
+ const absorption = gt.absorption;
1240
+ const transmittance = gt.transmittance;
1241
+ return this.#cached(`transmittance${absorption ? "-spectral" : ""}`, [layout, gt.shadow, transmittance, ...(absorption ? [absorption] : []), ...occluders], () => this.device.createBindGroup({
1242
+ label: `${this.#label} transmittance group 1`,
1243
+ layout,
1244
+ entries: [
1245
+ { binding: b.grid, resource: gt.shadow.createView({ dimension: "3d" }) },
1246
+ { binding: b.transmittance, resource: transmittance.createView({ dimension: "3d" }) },
1247
+ ...(absorption ? [{ binding: b.absorption, resource: absorption.createView({ dimension: "3d" }) }] : []),
1248
+ ...this.#occluderEntries(occluders),
1249
+ ],
1250
+ }));
1251
+ }
1252
+ #environmentGridBind(layout, gt) {
1253
+ const b = ENV_GRID_BINDINGS;
1254
+ const absorption = gt.absorption;
1255
+ const environment = gt.environment;
1256
+ return this.#cached(`environment-grid${absorption ? "-spectral" : ""}`, [layout, gt.shadow, environment, ...(absorption ? [absorption] : [])], () => this.device.createBindGroup({
1257
+ label: `${this.#label} environment grid group 1`,
1258
+ layout,
1259
+ entries: [
1260
+ { binding: b.grid, resource: gt.shadow.createView({ dimension: "3d" }) },
1261
+ { binding: b.out, resource: environment.createView({ dimension: "3d" }) },
1262
+ ...(absorption ? [{ binding: b.absorption, resource: absorption.createView({ dimension: "3d" }) }] : []),
1263
+ ],
1264
+ }));
1265
+ }
1266
+ #resolveBind(layout, tex, temporal) {
1267
+ const b = RESOLVE_BINDINGS;
1268
+ const historyIn = tex.history ? tex.history[this.#historyIndex] : null;
1269
+ const historyOut = tex.history ? tex.history[1 - this.#historyIndex] : null;
1270
+ const sp = tex.spectral;
1271
+ return this.#cached(`resolve${temporal ? `-${this.#historyIndex}` : ""}${sp ? "-spectral" : ""}`, [layout, tex.scatter, tex.integrated, ...(temporal ? [historyIn, historyOut] : []), ...(sp ? [sp.scatterAlpha, sp.integratedAlpha] : [])], () => this.device.createBindGroup({
1272
+ label: `${this.#label} resolve group 1`,
1273
+ layout,
1274
+ entries: [
1275
+ { binding: b.scatter, resource: tex.scatter.createView({ dimension: "3d" }) },
1276
+ { binding: b.integrated, resource: tex.integrated.createView({ dimension: "3d" }) },
1277
+ ...(temporal
1278
+ ? [
1279
+ { binding: b.historyIn, resource: historyIn.createView({ dimension: "3d" }) },
1280
+ { binding: b.historyOut, resource: historyOut.createView({ dimension: "3d" }) },
1281
+ ]
1282
+ : []),
1283
+ ...(sp
1284
+ ? [
1285
+ { binding: b.scatterAlpha, resource: sp.scatterAlpha.createView({ dimension: "3d" }) },
1286
+ { binding: b.integratedAlpha, resource: sp.integratedAlpha.createView({ dimension: "3d" }) },
1287
+ ]
1288
+ : []),
1289
+ ],
1290
+ }));
1291
+ }
1292
+ #sourceBind(source, layout) {
1293
+ const hit = this.#sourceGroups.get(source);
1294
+ if (hit && hit.version === source.version && hit.layout === layout)
1295
+ return hit.group;
1296
+ const group = this.device.createBindGroup({ label: `${this.#label} source group 2`, layout, entries: source.bindEntries(SOURCE_SLOT) });
1297
+ this.#sourceGroups.set(source, { version: source.version, layout, group });
1298
+ return group;
1299
+ }
1300
+ // ---------------------------------------------------------------- packing
1301
+ /**
1302
+ * Packs the lights; returns the sorted records (directional, point, spot; ≤ 16), the sky direction and (K6.5b) each
1303
+ * sorted light's occluder map (the first 4 maps of this frame's directional, point and spot lights take slots 0–3).
1304
+ */
1305
+ #packLights(lights, occluders, outwardEnvironment = false) {
1306
+ const w = this.#lightsWriter;
1307
+ const L = VDB_FRAME_LIGHTS;
1308
+ w.clear(0, L.size);
1309
+ const ambient = [0, 0, 0];
1310
+ const probe = new Float32Array(36);
1311
+ const hemi = [];
1312
+ const hemiSkySum = [0, 0, 0];
1313
+ const hemiGroundSum = [0, 0, 0];
1314
+ const directional = [];
1315
+ const point = [];
1316
+ const spot = [];
1317
+ // K6.5b: the light id of each record (element 16), for the occluder maps
1318
+ const ids = new Map();
1319
+ const norm = (v) => {
1320
+ const l = Math.hypot(v[0], v[1], v[2]) || 1;
1321
+ return [v[0] / l, v[1] / l, v[2] / l];
1322
+ };
1323
+ let hemiTotal = 0;
1324
+ let sky = null;
1325
+ for (const l of lights) {
1326
+ switch (l.kind) {
1327
+ case "ambient":
1328
+ for (let i = 0; i < 3; i++)
1329
+ ambient[i] = ambient[i] + l.color[i];
1330
+ break;
1331
+ case "probe":
1332
+ for (let i = 0; i < 9; i++)
1333
+ for (let c = 0; c < 3; c++)
1334
+ probe[i * 4 + c] = probe[i * 4 + c] + (l.sh[i * 3 + c] ?? 0);
1335
+ break;
1336
+ case "hemisphere":
1337
+ hemiTotal++;
1338
+ if (hemi.length < VDB_FRAME_MAX_HEMISPHERE_LIGHTS)
1339
+ hemi.push({ sky: l.sky, ground: l.ground, up: norm(l.up) });
1340
+ for (let i = 0; i < 3; i++) {
1341
+ hemiSkySum[i] = hemiSkySum[i] + l.sky[i];
1342
+ hemiGroundSum[i] = hemiGroundSum[i] + l.ground[i];
1343
+ }
1344
+ // his frameSkyDirection: the first hemisphere light's direction
1345
+ if (!sky && Math.hypot(l.up[0], l.up[1], l.up[2]) > 0)
1346
+ sky = norm(l.up);
1347
+ break;
1348
+ case "directional": {
1349
+ const d = norm(l.direction);
1350
+ const r = [-d[0], -d[1], -d[2], 1, ...l.color, 0, 0, 0, 0, 0, 0, 0, 0, 0];
1351
+ ids.set(r, l.id);
1352
+ directional.push(r);
1353
+ break;
1354
+ }
1355
+ case "point": {
1356
+ const r = [...l.position, 2, ...l.color, 0, 0, 0, 0, 0, l.distance, l.decay, 0, 0];
1357
+ ids.set(r, l.id);
1358
+ point.push(r);
1359
+ break;
1360
+ }
1361
+ case "spot": {
1362
+ const d = norm(l.direction);
1363
+ const r = [...l.position, 3, ...l.color, l.cosPenumbra, -d[0], -d[1], -d[2], l.cosAngle, l.distance, l.decay, 0, 0];
1364
+ ids.set(r, l.id);
1365
+ spot.push(r);
1366
+ break;
1367
+ }
1368
+ }
1369
+ }
1370
+ const sorted = [...directional, ...point, ...spot];
1371
+ if (sorted.length > VDB_FRAME_MAX_LIGHTS || hemiTotal > VDB_FRAME_MAX_HEMISPHERE_LIGHTS) {
1372
+ this.#warnOnce("lights", `too many lights: only ${VDB_FRAME_MAX_LIGHTS} lights and ${VDB_FRAME_MAX_HEMISPHERE_LIGHTS} hemisphere lights are used.`);
1373
+ }
1374
+ const used = sorted.slice(0, VDB_FRAME_MAX_LIGHTS);
1375
+ const skyDirection = sky ?? [0, 1, 0];
1376
+ // K6.5b: occluder slots (falloff.z = slot + 1), their layers, bias, flags and matrices
1377
+ const occluderOf = used.map(() => null);
1378
+ const views = [];
1379
+ const info = [];
1380
+ const matrices = new Float32Array(VDB_FRAME_MAX_OCCLUDERS * VDB_FRAME_OCCLUDER_LAYERS * 16);
1381
+ for (const o of occluders) {
1382
+ const index = used.findIndex((r) => ids.get(r) === o.light);
1383
+ if (index < 0) {
1384
+ this.#warnOnce(`occluder-light-${String(o.light)}`, `the occluder map of light ${String(o.light)} has no directional, point or spot light of that id in this frame (or it is past the ${VDB_FRAME_MAX_LIGHTS} lights); it is ignored.`);
1385
+ continue;
1386
+ }
1387
+ if (occluderOf[index]) {
1388
+ this.#warnOnce("occluder-twice", `light ${String(o.light)} has two occluder maps; the first is used.`);
1389
+ continue;
1390
+ }
1391
+ if (views.length >= VDB_FRAME_MAX_OCCLUDERS) {
1392
+ this.#warnOnce("occluders", `more than ${VDB_FRAME_MAX_OCCLUDERS} occluder maps: only the first ${VDB_FRAME_MAX_OCCLUDERS} (in input order) shadow the volumes.`);
1393
+ break;
1394
+ }
1395
+ const layers = o.viewProjection.length;
1396
+ if (layers < 1 || layers > VDB_FRAME_OCCLUDER_LAYERS) {
1397
+ throw new VDBError("VDB_BAD_OPTION", `VDBFrameRenderer.update: occluder of light ${String(o.light)} has ${layers} view-projections; give 1–${VDB_FRAME_OCCLUDER_LAYERS} (one per layer of its depth view).`);
1398
+ }
1399
+ const slot = views.length;
1400
+ occluderOf[index] = o;
1401
+ used[index][14] = slot + 1;
1402
+ views.push(o.depth);
1403
+ info.push(layers, o.bias ?? 0, o.reversedDepth ? 1 : 0, o.filter === "nearest" ? 1 : 0);
1404
+ o.viewProjection.forEach((m, l) => {
1405
+ for (let k = 0; k < 16; k++)
1406
+ matrices[(slot * VDB_FRAME_OCCLUDER_LAYERS + l) * 16 + k] = m[k];
1407
+ });
1408
+ }
1409
+ this.#occluderViews = views;
1410
+ // K6.Q1: the shadowed ambient's direction pairs, when there is distant light to shadow (ambient, a probe, hemisphere
1411
+ // lights; 'frame' lighting's 'outward' environment)
1412
+ const s = this.settings;
1413
+ const distant = ambient.some((v) => v !== 0) || probe.some((v) => v !== 0) || hemi.length > 0 || outwardEnvironment;
1414
+ const pairs = s.ambientOcclusion && distant ? Math.min(VDB_FRAME_AMBIENT_MAX_PAIRS, Math.max(1, Math.round(s.ambientOcclusionPairs))) : 0;
1415
+ // K7.15 (his VDB-167): the 'frame' sky up / down marches run only when something reads them: the probe, hemisphere
1416
+ // lights and the 'outward' environment, and ambient light through the AO pairs (pair 0 is the sky marches; without
1417
+ // AO ambient light is unshadowed). The gathers read the skipped entries (1) only times zero light. His 'outward'
1418
+ // test also counts an environment with no extracted light; ours has no count on the CPU (no readback), and such a map
1419
+ // is black, so its outward irradiance is 0 and the entries' value does not matter.
1420
+ const skyMarch = pairs > 0 || probe.some((v) => v !== 0) || hemi.length > 0 || outwardEnvironment;
1421
+ const directions = pairs > 0 ? vdbFrameAmbientDirections(skyDirection, pairs) : [];
1422
+ const aoSteps = Math.max(0, Math.round(s.ambientOcclusionSteps));
1423
+ w.set(L, 0, "ambient", [ambient[0], ambient[1], ambient[2], hemi.length]);
1424
+ w.set(L, 0, "counts", [used.length, views.length, pairs, aoSteps]);
1425
+ // K6.Q1d-a (D41): the dipole targets are read (and written) only then; kept through a gap without distant light
1426
+ const dipoleOn = vdbFrameDipoleSettingsOn(s);
1427
+ const dipoleRead = dipoleOn && pairs > 0;
1428
+ const dipoleTargets = this.#dipoleKept(dipoleOn, dipoleRead);
1429
+ let frameMode = 0;
1430
+ if (pairs > 0) {
1431
+ w.set(L, 0, "ambientDirections", directions.flatMap((d) => [...d, 0]));
1432
+ // K6.Q1c: the dipole fit's M+ / 2 rows and the phase weight's mode (internal `ambientPhase`, both lightings)
1433
+ const mode = (s.ambientPhase ?? "dipole") === "dipole" ? 1 : 0;
1434
+ // K6.Q1d / K6.Q1d-a: [1].w 1 while 'frame' lighting reads the pairs' dipole (pairs > 0: AO on and distant light)
1435
+ frameMode = dipoleRead ? 1 : 0;
1436
+ const m = vdbFrameAmbientDipoleMatrix(directions);
1437
+ w.set(L, 0, "ambientDipole", [m[0], m[1], m[2], mode, m[3], m[4], m[5], frameMode, m[6], m[7], m[8], 0]);
1438
+ }
1439
+ w.set(L, 0, "probe", probe);
1440
+ w.set(L, 0, "hemiSky", hemi.flatMap((h) => [...h.sky, 0]));
1441
+ w.set(L, 0, "hemiGround", hemi.flatMap((h) => [...h.ground, 0]));
1442
+ w.set(L, 0, "hemiUp", hemi.flatMap((h) => [...h.up, 0]));
1443
+ w.set(L, 0, "position", used.flatMap((r) => r.slice(0, 4)));
1444
+ w.set(L, 0, "color", used.flatMap((r) => r.slice(4, 8)));
1445
+ w.set(L, 0, "spot", used.flatMap((r) => r.slice(8, 12)));
1446
+ w.set(L, 0, "falloff", used.flatMap((r) => r.slice(12, 16)));
1447
+ w.set(L, 0, "sky", [...skyDirection, skyMarch ? 1 : 0]);
1448
+ w.set(L, 0, "hemiSkySum", [...hemiSkySum, 0]);
1449
+ w.set(L, 0, "hemiGroundSum", [...hemiGroundSum, 0]);
1450
+ if (views.length > 0) {
1451
+ w.set(L, 0, "occluderInfo", info);
1452
+ w.set(L, 0, "occluderMatrix", matrices);
1453
+ }
1454
+ this.device.queue.writeBuffer(this.#lightsBuffer, 0, w.buffer);
1455
+ return { sorted: used, sky: skyDirection, occluderOf, ambient: [pairs, frameMode, ...directions.flat()], skyMarch, dipoleTargets };
1456
+ }
1457
+ /**
1458
+ * K6.Q1d-a (D41): whether 'frame' lighting's transmittance stack holds the pairs' dipole targets this update. `on`: the
1459
+ * settings read them (`vdbFrameDipoleSettingsOn`); `read`: a gather reads them this update (distant light too,
1460
+ * `vdbFrameDipoleTargetsWanted`). Made at the first update that reads them; freed at the next update once a setting
1461
+ * turns them off (K7.16), and after {@link VDB_FRAME_RELEASE_UPDATES} updates in a row without distant light, so a
1462
+ * light that comes and goes does not reallocate the stack every frame. While kept unread nothing writes or reads them
1463
+ * (`ambientDipole[1].w` is 0).
1464
+ */
1465
+ #dipoleKept(on, read) {
1466
+ if (!on) {
1467
+ this.#dipoleIdle = 0;
1468
+ return (this.#dipoleHeld = false);
1469
+ }
1470
+ if (read) {
1471
+ this.#dipoleIdle = 0;
1472
+ return (this.#dipoleHeld = true);
1473
+ }
1474
+ if (this.#dipoleHeld && ++this.#dipoleIdle >= VDB_FRAME_RELEASE_UPDATES) {
1475
+ this.#dipoleHeld = false;
1476
+ this.#dipoleIdle = 0;
1477
+ }
1478
+ return this.#dipoleHeld;
1479
+ }
1480
+ /** The phase fields of a volume after its overrides (V65), or the renderer's own ('frame' lighting) for null. */
1481
+ #phaseOf(p) {
1482
+ const s = this.settings;
1483
+ return {
1484
+ phase: p?.phase ?? s.phase,
1485
+ phaseG: p?.phaseG ?? s.phaseG,
1486
+ phaseBackG: p?.phaseBackG ?? s.phaseBackG,
1487
+ phaseBackWeight: p?.phaseBackWeight ?? s.phaseBackWeight,
1488
+ phaseGExponent: p?.phaseGExponent ?? s.phaseGExponent,
1489
+ };
1490
+ }
1491
+ /** densityScale after normalizeDensity (his getDensityScale). */
1492
+ #densityScaleOf(p, slot) {
1493
+ const mean = p.densityMean ?? slot.stats.meanNonZero;
1494
+ return p.normalizeDensity && mean > 0 ? p.densityScale / mean : p.densityScale;
1495
+ }
1496
+ #packVolumes(records, codes, spectral = false) {
1497
+ const w = this.#volumesWriter;
1498
+ const V = VDB_FRAME_VOLUME;
1499
+ records.forEach((r, i) => {
1500
+ const base = i * VDB_FRAME_VOLUME_BYTES;
1501
+ const p = r.volume.params;
1502
+ const slot = r.volume.slot;
1503
+ const phaseFields = this.#phaseOf(p);
1504
+ const phase = vdbFramePhaseVector(phaseFields);
1505
+ const ms = vdbFrameMultipleScatteringValue(this.settings.multipleScattering === "octaves" ? false : this.settings.multipleScattering, phaseFields);
1506
+ const levels = slot.lodLevels;
1507
+ w.clear(base, VDB_FRAME_VOLUME_BYTES);
1508
+ w.set(V, base, "viewToLocal", r.viewToLocal);
1509
+ w.set(V, base, "localToView", r.localToView);
1510
+ w.set(V, base, "worldToLocal", r.worldToLocal);
1511
+ w.set(V, base, "rect", r.rect);
1512
+ w.set(V, base, "slices", [r.first, r.count, r.volume.slot.v, p.lights >>> 0]);
1513
+ w.set(V, base, "scatterOpacity", [...p.scatterColor, p.opacity]);
1514
+ w.set(V, base, "baseExtinction", [...p.baseColor, p.extinction]);
1515
+ w.set(V, base, "offsetWrap", [...p.offset3D, WRAP_CODE[p.wrap3D] ?? 0]);
1516
+ w.set(V, base, "phase", phase);
1517
+ w.set(V, base, "phaseSpectrumMs", [...vdbFramePhaseSpectrum(phaseFields), ms]);
1518
+ w.set(V, base, "density", [this.#densityScaleOf(p, slot), p.densityCutoff, vdbMat4MaxScale(p.matrixWorld), p.absorbance]);
1519
+ w.set(V, base, "emission", [p.emissiveIntensity, p.temperatureRange[0], p.temperatureRange[1], levels]);
1520
+ w.set(V, base, "march", [Math.max(0, Math.round(p.shadowSteps)), p.mipmaps && levels > 0 ? 1 : 0, p.hdda ? 1 : 0, codes[i] ?? 0]);
1521
+ // K6.4: each channel's extinction scale (his getFrameExtinctionSpectrum); grey kernels do not read it
1522
+ w.set(V, base, "extinctionSpectrum", spectral ? [...vdbFrameExtinctionSpectrum([...p.extinctionScale], p.angstromExponent), 0] : [1, 1, 1, 0]);
1523
+ });
1524
+ this.device.queue.writeBuffer(this.#volumesBuffer, 0, w.buffer, 0, Math.max(1, records.length) * VDB_FRAME_VOLUME_BYTES);
1525
+ }
1526
+ /** One record per source group: its gather range and role among the gather groups, its casters and their role. */
1527
+ #packGroups(groups, gatherGroups, casterGroups) {
1528
+ const bytes = Math.max(4, groups.length) * VDB_FRAME_GROUP_STRIDE;
1529
+ if (this.#groupsBuffer.size < bytes) {
1530
+ this.#retire.retire(this.#groupsBuffer);
1531
+ this.#groupsBuffer = this.device.createBuffer({ label: `${this.#label} groups`, size: bytes, usage: BUFFER_USAGE.UNIFORM | BUFFER_USAGE.COPY_DST });
1532
+ this.#groupsWriter = new VDBUniformWriter(bytes);
1533
+ }
1534
+ const w = this.#groupsWriter;
1535
+ const role = (list, g) => {
1536
+ const i = list.indexOf(g);
1537
+ return i < 0 ? 0 : (i === 0 ? 1 : 0) | (i === list.length - 1 ? 2 : 0);
1538
+ };
1539
+ groups.forEach((g, i) => {
1540
+ w.clear(i * VDB_FRAME_GROUP_STRIDE, VDB_FRAME_GROUP_STRIDE);
1541
+ w.set(VDB_FRAME_GROUP, i * VDB_FRAME_GROUP_STRIDE, "range", [g.first, g.visible, role(gatherGroups, g), gatherGroups.indexOf(g)]);
1542
+ w.set(VDB_FRAME_GROUP, i * VDB_FRAME_GROUP_STRIDE, "casters", [g.first + g.casterStart, g.casters, role(casterGroups, g), casterGroups.indexOf(g)]);
1543
+ });
1544
+ this.device.queue.writeBuffer(this.#groupsBuffer, 0, w.buffer, 0, groups.length * VDB_FRAME_GROUP_STRIDE);
1545
+ }
1546
+ // ---------------------------------------------------------------- render
1547
+ render(encoder, targets) {
1548
+ this.#check();
1549
+ const key = this.#compositeKey();
1550
+ if (!key)
1551
+ throw new VDBError("VDB_BAD_OPTION", "VDBFrameRenderer.render: create the renderer with options.composite ({ colorFormat, depthFormat }).");
1552
+ const froxels = this.outputs.froxels;
1553
+ if (!this.#recorded || !froxels)
1554
+ return;
1555
+ const srgb = key.srgb && (targets.outputColorSpace ?? "srgb") === "srgb";
1556
+ // K6.4: the spectral composite reads the alpha prefix of this update's textures
1557
+ const spectral = !!froxels.integratedAlpha;
1558
+ const finalKey = { ...key, srgb, spectral };
1559
+ if (srgb && !targets.sceneColor) {
1560
+ throw new VDBError("VDB_BAD_OPTION", "VDBFrameRenderer.render: sRGB blending reads the scene colour: pass targets.sceneColor (a copy of the colour target), or set settings.srgbBlending = false.");
1561
+ }
1562
+ if (spectral && !targets.sceneColor) {
1563
+ throw new VDBError("VDB_BAD_OPTION", "VDBFrameRenderer.render: spectral media composite over the scene colour themselves (three transmittances): pass targets.sceneColor (a copy of the colour target).");
1564
+ }
1565
+ const [sw, sh] = targets.size;
1566
+ // Only the screen-size fields move here; the rest is the update's.
1567
+ const fw = this.#frameWriter;
1568
+ fw.set(VDB_FRAME_UNIFORMS, 0, "screen", [sw, sh, (targets.clampColors ?? true) ? 1 : 0, 0]);
1569
+ const screen = VDB_FRAME_UNIFORMS.fields.get("screen");
1570
+ this.device.queue.writeBuffer(this.#frameBuffer, screen.offset, fw.buffer, screen.offset, 16);
1571
+ const built = renderPipeline(this.device, vdbFrameCompositeSpec(finalKey));
1572
+ const [x0, y0, x1, y1] = froxels.layout.screenRect;
1573
+ // clip → pixels (y down)
1574
+ const px0 = Math.max(0, Math.floor((x0 * 0.5 + 0.5) * sw));
1575
+ const px1 = Math.min(sw, Math.ceil((x1 * 0.5 + 0.5) * sw));
1576
+ const py0 = Math.max(0, Math.floor((1 - (y1 * 0.5 + 0.5)) * sh));
1577
+ const py1 = Math.min(sh, Math.ceil((1 - (y0 * 0.5 + 0.5)) * sh));
1578
+ if (px1 <= px0 || py1 <= py0)
1579
+ return;
1580
+ const group1 = this.device.createBindGroup({
1581
+ label: `${this.#label} composite group 1`,
1582
+ layout: built.layouts[1],
1583
+ entries: [
1584
+ { binding: 0, resource: froxels.integrated.createView({ dimension: "3d" }) },
1585
+ { binding: 1, resource: this.#linear },
1586
+ { binding: 2, resource: targets.depth },
1587
+ ...(srgb || spectral ? [{ binding: 3, resource: targets.sceneColor }] : []),
1588
+ ...(spectral ? [{ binding: VDB_FRAME_COMPOSITE_ALPHA_BINDING, resource: froxels.integratedAlpha.createView({ dimension: "3d" }) }] : []),
1589
+ ],
1590
+ });
1591
+ const pass = encoder.beginRenderPass({ label: `${this.#label} composite`, colorAttachments: [{ view: targets.color, loadOp: "load", storeOp: "store" }] });
1592
+ pass.setPipeline(built.pipeline);
1593
+ pass.setBindGroup(0, this.#group0Bind());
1594
+ pass.setBindGroup(1, group1);
1595
+ pass.setScissorRect(px0, py0, px1 - px0, py1 - py0);
1596
+ pass.draw(3);
1597
+ pass.end();
1598
+ }
1599
+ // ---------------------------------------------------------------- lifecycle
1600
+ #warnOnce(key, message) {
1601
+ if (this.#warned.has(key))
1602
+ return;
1603
+ this.#warned.add(key);
1604
+ console.warn(`@pmndrs/vdb frame renderer: ${message}`);
1605
+ }
1606
+ #check() {
1607
+ if (this.#disposed)
1608
+ throw new VDBError("VDB_DISPOSED", "VDBFrameRenderer: the renderer was disposed; create a new one.");
1609
+ }
1610
+ dispose() {
1611
+ if (this.#disposed)
1612
+ return;
1613
+ this.#disposed = true;
1614
+ const t = this.#textures;
1615
+ if (t) {
1616
+ t.scatter.destroy();
1617
+ t.integrated.destroy();
1618
+ t.history?.forEach((h) => h.destroy());
1619
+ t.partials?.destroy();
1620
+ t.spectral?.scatterAlpha.destroy();
1621
+ t.spectral?.integratedAlpha.destroy();
1622
+ }
1623
+ this.#textures = null;
1624
+ const g = this.#grid;
1625
+ if (g) {
1626
+ g.shadow.destroy();
1627
+ g.transmittance?.destroy();
1628
+ g.partials?.destroy();
1629
+ g.environment?.destroy();
1630
+ g.absorption?.destroy();
1631
+ }
1632
+ this.#grid = null;
1633
+ this.#shadows.dispose();
1634
+ this.#probes.dispose();
1635
+ this.#colors.dispose();
1636
+ this.outputs.emissionProbes = null;
1637
+ this.#env.dispose();
1638
+ this.#scattering.dispose();
1639
+ this.#mie.destroy();
1640
+ this.#occluderPlaceholder?.texture.destroy();
1641
+ this.#occluderPlaceholder = null;
1642
+ this.#occluderViews = [];
1643
+ this.#retire.drain();
1644
+ this.#frameBuffer.destroy();
1645
+ this.#lightsBuffer.destroy();
1646
+ this.#volumesBuffer.destroy();
1647
+ this.#groupsBuffer.destroy();
1648
+ this.outputs.froxels = null;
1649
+ this.#volumes.length = 0;
1650
+ }
1651
+ /** @internal The textures (harness probes and tests). */
1652
+ get debugTextures() {
1653
+ return this.#textures;
1654
+ }
1655
+ /** @internal The emission textures (harness probes): direction and emitter textures, slots, the list buffer. */
1656
+ get debugEmission() {
1657
+ const P = this.#probes;
1658
+ return { directions: P.directionTexture, emitters: P.emitterTexture, probes: P.probeTexture, slots: P.slots };
1659
+ }
1660
+ /** @internal The environment state (harness probes and tests): the buffer, the maps and the kernel counts. */
1661
+ /** @internal K6.3 (harness probes): the 'mlp' feature mips, the multi-scale chain and the network in use. */
1662
+ get debugScattering() {
1663
+ return this.#scattering.debug;
1664
+ }
1665
+ /** @internal The environment state (harness probes and tests). */
1666
+ get debugEnvironment() {
1667
+ return this.#env;
1668
+ }
1669
+ /** @internal The 'frame' lighting grid textures and the live cascade layout (harness probes and tests). */
1670
+ get debugGrid() {
1671
+ const g = this.#grid;
1672
+ if (!g)
1673
+ return null;
1674
+ const count = this.#frameWriter.f32[VDB_FRAME_UNIFORMS.fields.get("gridLayout").offset / 4];
1675
+ const v = (a) => a.slice(0, count).map((p) => [p.x, p.y, p.z]);
1676
+ return { textures: g, count, gridMin: v(this.#gridMin), gridSize: v(this.#gridSize), gridVoxel: v(this.#gridVoxel) };
1677
+ }
1678
+ }
1679
+ /**
1680
+ * Creates the core frame renderer on the host's device (design §2.2). It makes its uniform buffers now and
1681
+ * its froxel textures at the first `update()` with volumes in view.
1682
+ *
1683
+ * @param device The host's `GPUDevice`.
1684
+ * @param options {@link VDBFrameRendererOptions}.
1685
+ */
1686
+ export function vdbCreateFrameRenderer(device, options = {}) {
1687
+ if (!device || typeof device.createTexture !== "function") {
1688
+ throw new VDBError("VDB_UNSUPPORTED_DEVICE", "vdbCreateFrameRenderer: pass the host's GPUDevice.");
1689
+ }
1690
+ return new FrameRenderer(device, options);
1691
+ }
1692
+ /** @internal The froxel textures of a renderer from {@link vdbCreateFrameRenderer} (harness probes). */
1693
+ export function vdbFrameRendererTextures(r) {
1694
+ return r.debugTextures;
1695
+ }
1696
+ /** @internal The emission textures of a renderer (harness probes). */
1697
+ export function vdbFrameRendererEmission(r) {
1698
+ return r.debugEmission;
1699
+ }
1700
+ /** @internal The 'frame' lighting grid of a renderer (harness probes): stacks, their layouts and the live cascades. */
1701
+ export function vdbFrameRendererGrid(r) {
1702
+ return r.debugGrid;
1703
+ }
1704
+ /** @internal The environment of a renderer (harness probes): its buffer, maps and kernel counts (K6.2b). */
1705
+ export function vdbFrameRendererEnvironment(r) {
1706
+ return r.debugEnvironment;
1707
+ }
1708
+ /** @internal K6.3 (harness probes): the 'mlp' feature mips, the 'multi-scale' chain and the network in use. */
1709
+ export function vdbFrameRendererScattering(r) {
1710
+ return r.debugScattering;
1711
+ }
1712
+ //# sourceMappingURL=renderer.js.map