@pmndrs/vdb 0.1.0 → 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 (576) hide show
  1. package/CHANGELOG.md +592 -2
  2. package/README.md +85 -37
  3. package/THIRD_PARTY_NOTICES.md +197 -29
  4. package/dist/core/compute/atlas.d.ts +10 -2
  5. package/dist/core/compute/atlas.js +6 -1
  6. package/dist/core/compute/atlas.js.map +1 -1
  7. package/dist/core/compute/index.d.ts +3 -3
  8. package/dist/core/compute/index.js +2 -2
  9. package/dist/core/compute/index.js.map +1 -1
  10. package/dist/core/compute/majorant-build.d.ts +45 -0
  11. package/dist/core/compute/majorant-build.js +193 -0
  12. package/dist/core/compute/majorant-build.js.map +1 -0
  13. package/dist/core/compute/multi-scale.d.ts +155 -0
  14. package/dist/core/compute/multi-scale.js +684 -0
  15. package/dist/core/compute/multi-scale.js.map +1 -0
  16. package/dist/core/compute/pyramid.d.ts +22 -7
  17. package/dist/core/compute/pyramid.js +22 -9
  18. package/dist/core/compute/pyramid.js.map +1 -1
  19. package/dist/core/compute/shared.d.ts +1 -0
  20. package/dist/core/compute/shared.js.map +1 -1
  21. package/dist/core/compute/stats.d.ts +10 -3
  22. package/dist/core/compute/stats.js +6 -1
  23. package/dist/core/compute/stats.js.map +1 -1
  24. package/dist/core/compute/value-transform.d.ts +8 -1
  25. package/dist/core/compute/value-transform.js +9 -3
  26. package/dist/core/compute/value-transform.js.map +1 -1
  27. package/dist/core/errors.d.ts +10 -0
  28. package/dist/core/errors.js +8 -0
  29. package/dist/core/errors.js.map +1 -1
  30. package/dist/core/frame/emission.d.ts +85 -0
  31. package/dist/core/frame/emission.js +422 -0
  32. package/dist/core/frame/emission.js.map +1 -0
  33. package/dist/core/frame/environment.d.ts +47 -0
  34. package/dist/core/frame/environment.js +178 -0
  35. package/dist/core/frame/environment.js.map +1 -0
  36. package/dist/core/frame/index.d.ts +39 -0
  37. package/dist/core/frame/index.js +27 -0
  38. package/dist/core/frame/index.js.map +1 -0
  39. package/dist/core/frame/kernels.d.ts +115 -0
  40. package/dist/core/frame/kernels.js +496 -0
  41. package/dist/core/frame/kernels.js.map +1 -0
  42. package/dist/core/frame/limits.d.ts +67 -0
  43. package/dist/core/frame/limits.js +109 -0
  44. package/dist/core/frame/limits.js.map +1 -0
  45. package/dist/core/frame/phase.d.ts +17 -0
  46. package/dist/core/frame/phase.js +53 -0
  47. package/dist/core/frame/phase.js.map +1 -0
  48. package/dist/core/frame/pipelines.d.ts +49 -0
  49. package/dist/core/frame/pipelines.js +147 -0
  50. package/dist/core/frame/pipelines.js.map +1 -0
  51. package/dist/core/frame/renderer.d.ts +122 -0
  52. package/dist/core/frame/renderer.js +1712 -0
  53. package/dist/core/frame/renderer.js.map +1 -0
  54. package/dist/core/frame/resources.d.ts +71 -0
  55. package/dist/core/frame/resources.js +100 -0
  56. package/dist/core/frame/resources.js.map +1 -0
  57. package/dist/core/frame/scattering.d.ts +97 -0
  58. package/dist/core/frame/scattering.js +332 -0
  59. package/dist/core/frame/scattering.js.map +1 -0
  60. package/dist/core/frame/settings.d.ts +243 -0
  61. package/dist/core/frame/settings.js +67 -0
  62. package/dist/core/frame/settings.js.map +1 -0
  63. package/dist/core/frame/shadows.d.ts +55 -0
  64. package/dist/core/frame/shadows.js +460 -0
  65. package/dist/core/frame/shadows.js.map +1 -0
  66. package/dist/core/frame/types.d.ts +415 -0
  67. package/dist/core/frame/types.js +49 -0
  68. package/dist/core/frame/types.js.map +1 -0
  69. package/dist/core/frame/uniforms.d.ts +105 -0
  70. package/dist/core/frame/uniforms.js +276 -0
  71. package/dist/core/frame/uniforms.js.map +1 -0
  72. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  73. package/dist/core/frame/wgsl/chunks.js +728 -0
  74. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  75. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  76. package/dist/core/frame/wgsl/emission.js +353 -0
  77. package/dist/core/frame/wgsl/emission.js.map +1 -0
  78. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  79. package/dist/core/frame/wgsl/environment.js +711 -0
  80. package/dist/core/frame/wgsl/environment.js.map +1 -0
  81. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  82. package/dist/core/frame/wgsl/gather.js +850 -0
  83. package/dist/core/frame/wgsl/gather.js.map +1 -0
  84. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  85. package/dist/core/frame/wgsl/integrate.js +213 -0
  86. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  87. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  88. package/dist/core/frame/wgsl/lighting.js +1636 -0
  89. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  90. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  91. package/dist/core/frame/wgsl/occluders.js +95 -0
  92. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  93. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  94. package/dist/core/frame/wgsl/resolve.js +205 -0
  95. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  96. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  97. package/dist/core/frame/wgsl/shadows.js +328 -0
  98. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  99. package/dist/core/half.d.ts +11 -0
  100. package/dist/core/half.js +22 -0
  101. package/dist/core/half.js.map +1 -0
  102. package/dist/core/index.d.ts +25 -3
  103. package/dist/core/index.js +23 -4
  104. package/dist/core/index.js.map +1 -1
  105. package/dist/core/internal.d.ts +17 -1
  106. package/dist/core/internal.js +18 -1
  107. package/dist/core/internal.js.map +1 -1
  108. package/dist/core/pool/image-header.d.ts +13 -2
  109. package/dist/core/pool/image-header.js +24 -5
  110. package/dist/core/pool/image-header.js.map +1 -1
  111. package/dist/core/pool/layout.d.ts +35 -1
  112. package/dist/core/pool/layout.js +51 -2
  113. package/dist/core/pool/layout.js.map +1 -1
  114. package/dist/core/pool/limits.d.ts +1 -0
  115. package/dist/core/pool/limits.js +1 -0
  116. package/dist/core/pool/limits.js.map +1 -1
  117. package/dist/core/pool/pool.d.ts +120 -15
  118. package/dist/core/pool/pool.js +255 -24
  119. package/dist/core/pool/pool.js.map +1 -1
  120. package/dist/core/reference/index.d.ts +6 -0
  121. package/dist/core/reference/index.js +7 -0
  122. package/dist/core/reference/index.js.map +1 -0
  123. package/dist/core/reference/renderer.d.ts +105 -0
  124. package/dist/core/reference/renderer.js +474 -0
  125. package/dist/core/reference/renderer.js.map +1 -0
  126. package/dist/core/reference/wgsl.d.ts +65 -0
  127. package/dist/core/reference/wgsl.js +803 -0
  128. package/dist/core/reference/wgsl.js.map +1 -0
  129. package/dist/{three → core}/sequence.d.ts +32 -2
  130. package/dist/{three → core}/sequence.js +24 -2
  131. package/dist/core/sequence.js.map +1 -0
  132. package/dist/core/source/brick-cache.d.ts +165 -0
  133. package/dist/core/source/brick-cache.js +627 -0
  134. package/dist/core/source/brick-cache.js.map +1 -0
  135. package/dist/core/source/dense-fill.d.ts +53 -0
  136. package/dist/core/source/dense-fill.js +377 -0
  137. package/dist/core/source/dense-fill.js.map +1 -0
  138. package/dist/core/source/dense.d.ts +33 -2
  139. package/dist/core/source/dense.js +121 -24
  140. package/dist/core/source/dense.js.map +1 -1
  141. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  142. package/dist/core/source/sparse-wgsl.js +481 -0
  143. package/dist/core/source/sparse-wgsl.js.map +1 -0
  144. package/dist/core/source/sparse.d.ts +192 -0
  145. package/dist/core/source/sparse.js +762 -0
  146. package/dist/core/source/sparse.js.map +1 -0
  147. package/dist/core/source/types.d.ts +59 -2
  148. package/dist/core/source/types.js.map +1 -1
  149. package/dist/core/surface/index.d.ts +10 -0
  150. package/dist/core/surface/index.js +9 -0
  151. package/dist/core/surface/index.js.map +1 -0
  152. package/dist/core/surface/level-set-pass.d.ts +140 -0
  153. package/dist/core/surface/level-set-pass.js +291 -0
  154. package/dist/core/surface/level-set-pass.js.map +1 -0
  155. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  156. package/dist/core/surface/level-set-wgsl.js +99 -0
  157. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  158. package/dist/core/surface/points.d.ts +109 -0
  159. package/dist/core/surface/points.js +226 -0
  160. package/dist/core/surface/points.js.map +1 -0
  161. package/dist/core/types.d.ts +12 -3
  162. package/dist/core/types.js +6 -2
  163. package/dist/core/types.js.map +1 -1
  164. package/dist/core/wgsl/api.d.ts +29 -5
  165. package/dist/core/wgsl/api.js +110 -27
  166. package/dist/core/wgsl/api.js.map +1 -1
  167. package/dist/core/wgsl/generate.d.ts +8 -0
  168. package/dist/core/wgsl/generate.js +195 -22
  169. package/dist/core/wgsl/generate.js.map +1 -1
  170. package/dist/core/wgsl/lean.d.ts +50 -0
  171. package/dist/core/wgsl/lean.js +327 -0
  172. package/dist/core/wgsl/lean.js.map +1 -0
  173. package/dist/core/wgsl/level-set.d.ts +5 -1
  174. package/dist/core/wgsl/level-set.js +11 -5
  175. package/dist/core/wgsl/level-set.js.map +1 -1
  176. package/dist/core/wgsl/majorant.d.ts +62 -0
  177. package/dist/core/wgsl/majorant.js +381 -0
  178. package/dist/core/wgsl/majorant.js.map +1 -0
  179. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +2 -2
  180. package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
  181. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
  182. package/dist/core/wgsl/types.d.ts +97 -3
  183. package/dist/core/wgsl/types.js.map +1 -1
  184. package/dist/three/coarse-first.d.ts +53 -8
  185. package/dist/three/coarse-first.js +24 -6
  186. package/dist/three/coarse-first.js.map +1 -1
  187. package/dist/three/compute.d.ts +12 -2
  188. package/dist/three/compute.js +16 -6
  189. package/dist/three/compute.js.map +1 -1
  190. package/dist/three/device.d.ts +7 -0
  191. package/dist/three/device.js +3 -0
  192. package/dist/three/device.js.map +1 -1
  193. package/dist/three/frame/core-environment.d.ts +38 -0
  194. package/dist/three/frame/core-environment.js +154 -0
  195. package/dist/three/frame/core-environment.js.map +1 -0
  196. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  197. package/dist/three/frame/core-integrate-material.js +162 -0
  198. package/dist/three/frame/core-integrate-material.js.map +1 -0
  199. package/dist/three/frame/core-occluders.d.ts +53 -0
  200. package/dist/three/frame/core-occluders.js +193 -0
  201. package/dist/three/frame/core-occluders.js.map +1 -0
  202. package/dist/three/frame/core-structs.d.ts +34 -0
  203. package/dist/three/frame/core-structs.js +61 -0
  204. package/dist/three/frame/core-structs.js.map +1 -0
  205. package/dist/three/frame/core-textures.d.ts +41 -0
  206. package/dist/three/frame/core-textures.js +114 -0
  207. package/dist/three/frame/core-textures.js.map +1 -0
  208. package/dist/three/frame/emission-light.d.ts +64 -114
  209. package/dist/three/frame/emission-light.js +188 -567
  210. package/dist/three/frame/emission-light.js.map +1 -1
  211. package/dist/three/frame/index.d.ts +11 -31
  212. package/dist/three/frame/index.js +9 -29
  213. package/dist/three/frame/index.js.map +1 -1
  214. package/dist/three/frame/medium.d.ts +12 -0
  215. package/dist/three/frame/medium.js.map +1 -1
  216. package/dist/three/frame/renderer.d.ts +58 -454
  217. package/dist/three/frame/renderer.js +409 -1427
  218. package/dist/three/frame/renderer.js.map +1 -1
  219. package/dist/three/frame/spectrum.d.ts +0 -14
  220. package/dist/three/frame/spectrum.js +2 -23
  221. package/dist/three/frame/spectrum.js.map +1 -1
  222. package/dist/three/frame/three-internals.d.ts +3 -8
  223. package/dist/three/frame/three-internals.js +13 -11
  224. package/dist/three/frame/three-internals.js.map +1 -1
  225. package/dist/three/frame/volume-shadows.d.ts +93 -107
  226. package/dist/three/frame/volume-shadows.js +278 -631
  227. package/dist/three/frame/volume-shadows.js.map +1 -1
  228. package/dist/three/frame/volume.d.ts +91 -33
  229. package/dist/three/frame/volume.js +63 -51
  230. package/dist/three/frame/volume.js.map +1 -1
  231. package/dist/three/grid-node.d.ts +34 -1
  232. package/dist/three/grid-node.js +36 -1
  233. package/dist/three/grid-node.js.map +1 -1
  234. package/dist/three/index.d.ts +20 -11
  235. package/dist/three/index.js +21 -12
  236. package/dist/three/index.js.map +1 -1
  237. package/dist/three/internal.d.ts +14 -8
  238. package/dist/three/internal.js +11 -7
  239. package/dist/three/internal.js.map +1 -1
  240. package/dist/three/level-set-material.d.ts +81 -8
  241. package/dist/three/level-set-material.js +162 -125
  242. package/dist/three/level-set-material.js.map +1 -1
  243. package/dist/three/level-set-physical-material.d.ts +154 -0
  244. package/dist/three/level-set-physical-material.js +253 -0
  245. package/dist/three/level-set-physical-material.js.map +1 -0
  246. package/dist/three/level-set-velocity.d.ts +94 -0
  247. package/dist/three/level-set-velocity.js +208 -0
  248. package/dist/three/level-set-velocity.js.map +1 -0
  249. package/dist/three/material.d.ts +141 -11
  250. package/dist/three/material.js +161 -18
  251. package/dist/three/material.js.map +1 -1
  252. package/dist/three/points.d.ts +60 -4
  253. package/dist/three/points.js +140 -9
  254. package/dist/three/points.js.map +1 -1
  255. package/dist/three/sparse-source.d.ts +49 -117
  256. package/dist/three/sparse-source.js +109 -580
  257. package/dist/three/sparse-source.js.map +1 -1
  258. package/dist/three/volume-source.d.ts +11 -156
  259. package/dist/three/volume-source.js +29 -272
  260. package/dist/three/volume-source.js.map +1 -1
  261. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  262. package/dist/tools/cpu/brick-atlas.js +129 -0
  263. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  264. package/dist/tools/cpu/compute.d.ts +23 -4
  265. package/dist/tools/cpu/compute.js +35 -14
  266. package/dist/tools/cpu/compute.js.map +1 -1
  267. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  268. package/dist/tools/cpu/lean-reads.js +262 -0
  269. package/dist/tools/cpu/lean-reads.js.map +1 -0
  270. package/dist/tools/cpu/level-set.d.ts +42 -3
  271. package/dist/tools/cpu/level-set.js +59 -7
  272. package/dist/tools/cpu/level-set.js.map +1 -1
  273. package/dist/tools/cpu/majorant.d.ts +265 -0
  274. package/dist/tools/cpu/majorant.js +541 -0
  275. package/dist/tools/cpu/majorant.js.map +1 -0
  276. package/dist/tools/cpu/march.d.ts +93 -2
  277. package/dist/tools/cpu/march.js +165 -14
  278. package/dist/tools/cpu/march.js.map +1 -1
  279. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  280. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  281. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  282. package/dist/tools/cpu/points.d.ts +29 -0
  283. package/dist/tools/cpu/points.js +38 -0
  284. package/dist/tools/cpu/points.js.map +1 -0
  285. package/dist/tools/cpu/read-value.d.ts +19 -6
  286. package/dist/tools/cpu/read-value.js +32 -17
  287. package/dist/tools/cpu/read-value.js.map +1 -1
  288. package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
  289. package/dist/tools/cpu/sample-trilinear.js +19 -7
  290. package/dist/tools/cpu/sample-trilinear.js.map +1 -1
  291. package/dist/tools/cpu/stride-tables.d.ts +2 -2
  292. package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
  293. package/dist/tools/cpu/stride-tables.generated.js +7 -6
  294. package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
  295. package/dist/tools/cpu/stride-tables.js +1 -1
  296. package/dist/tools/cpu/stride-tables.js.map +1 -1
  297. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  298. package/dist/tools/cpu/surface-nets.js +597 -0
  299. package/dist/tools/cpu/surface-nets.js.map +1 -0
  300. package/dist/tools/errors.d.ts +9 -0
  301. package/dist/tools/errors.js +9 -0
  302. package/dist/tools/errors.js.map +1 -1
  303. package/dist/tools/frame/ambient.d.ts +98 -0
  304. package/dist/tools/frame/ambient.js +274 -0
  305. package/dist/tools/frame/ambient.js.map +1 -0
  306. package/dist/tools/frame/blackbody.d.ts +15 -0
  307. package/dist/tools/frame/blackbody.js +35 -0
  308. package/dist/tools/frame/blackbody.js.map +1 -1
  309. package/dist/tools/frame/brick-cache.d.ts +165 -0
  310. package/dist/tools/frame/brick-cache.js +326 -0
  311. package/dist/tools/frame/brick-cache.js.map +1 -0
  312. package/dist/tools/frame/emission.d.ts +9 -0
  313. package/dist/tools/frame/emission.js +9 -1
  314. package/dist/tools/frame/emission.js.map +1 -1
  315. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  316. package/dist/tools/frame/environment-gpu.js +280 -0
  317. package/dist/tools/frame/environment-gpu.js.map +1 -0
  318. package/dist/tools/frame/environment.d.ts +3 -2
  319. package/dist/tools/frame/environment.js +8 -4
  320. package/dist/tools/frame/environment.js.map +1 -1
  321. package/dist/tools/frame/froxel.d.ts +58 -0
  322. package/dist/tools/frame/froxel.js +115 -0
  323. package/dist/tools/frame/froxel.js.map +1 -0
  324. package/dist/tools/frame/grid.d.ts +90 -0
  325. package/dist/tools/frame/grid.js +112 -13
  326. package/dist/tools/frame/grid.js.map +1 -1
  327. package/dist/tools/frame/index.d.ts +14 -0
  328. package/dist/tools/frame/index.js +45 -4
  329. package/dist/tools/frame/index.js.map +1 -1
  330. package/dist/tools/frame/medium.d.ts +16 -0
  331. package/dist/tools/frame/medium.js +3 -1
  332. package/dist/tools/frame/medium.js.map +1 -1
  333. package/dist/tools/frame/mie.d.ts +9 -0
  334. package/dist/tools/frame/mie.js +18 -0
  335. package/dist/tools/frame/mie.js.map +1 -1
  336. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  337. package/dist/tools/frame/mlp-nn.js +159 -0
  338. package/dist/tools/frame/mlp-nn.js.map +1 -0
  339. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  340. package/dist/tools/frame/mlp-tza.js +186 -0
  341. package/dist/tools/frame/mlp-tza.js.map +1 -0
  342. package/dist/tools/frame/mlp.d.ts +183 -0
  343. package/dist/tools/frame/mlp.js +434 -0
  344. package/dist/tools/frame/mlp.js.map +1 -0
  345. package/dist/tools/frame/ms-exit.d.ts +42 -0
  346. package/dist/tools/frame/ms-exit.js +90 -0
  347. package/dist/tools/frame/ms-exit.js.map +1 -0
  348. package/dist/tools/frame/multi-scale.d.ts +152 -0
  349. package/dist/tools/frame/multi-scale.js +302 -0
  350. package/dist/tools/frame/multi-scale.js.map +1 -0
  351. package/dist/tools/frame/neural-weights.d.ts +6 -5
  352. package/dist/tools/frame/neural-weights.js +234 -235
  353. package/dist/tools/frame/neural-weights.js.map +1 -1
  354. package/dist/tools/frame/neural.js +1 -1
  355. package/dist/tools/frame/neural.js.map +1 -1
  356. package/dist/tools/frame/occluders.d.ts +51 -0
  357. package/dist/tools/frame/occluders.js +72 -0
  358. package/dist/tools/frame/occluders.js.map +1 -0
  359. package/dist/tools/frame/pyramid-layout.d.ts +17 -0
  360. package/dist/tools/frame/pyramid-layout.js +47 -0
  361. package/dist/tools/frame/pyramid-layout.js.map +1 -1
  362. package/dist/tools/frame/shadows.d.ts +110 -0
  363. package/dist/tools/frame/shadows.js +286 -0
  364. package/dist/tools/frame/shadows.js.map +1 -1
  365. package/dist/tools/frame/sparse.d.ts +82 -0
  366. package/dist/tools/frame/sparse.js +242 -1
  367. package/dist/tools/frame/sparse.js.map +1 -1
  368. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  369. package/dist/tools/frame/spectral-stack.js +391 -0
  370. package/dist/tools/frame/spectral-stack.js.map +1 -0
  371. package/dist/tools/frame/spectral.d.ts +21 -2
  372. package/dist/tools/frame/spectral.js +30 -8
  373. package/dist/tools/frame/spectral.js.map +1 -1
  374. package/dist/tools/frame/stack.d.ts +115 -0
  375. package/dist/tools/frame/stack.js +290 -0
  376. package/dist/tools/frame/stack.js.map +1 -0
  377. package/dist/tools/frame/view.d.ts +131 -0
  378. package/dist/tools/frame/view.js +337 -0
  379. package/dist/tools/frame/view.js.map +1 -0
  380. package/dist/tools/index.d.ts +66 -15
  381. package/dist/tools/index.js +55 -11
  382. package/dist/tools/index.js.map +1 -1
  383. package/dist/tools/internal.d.ts +58 -17
  384. package/dist/tools/internal.js +65 -11
  385. package/dist/tools/internal.js.map +1 -1
  386. package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
  387. package/dist/tools/nanovdb/build-from-vdb.js +10 -2
  388. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
  389. package/dist/tools/nanovdb/bytes.d.ts +17 -4
  390. package/dist/tools/nanovdb/bytes.js +46 -3
  391. package/dist/tools/nanovdb/bytes.js.map +1 -1
  392. package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
  393. package/dist/tools/nanovdb/coarse-first.js +7 -1
  394. package/dist/tools/nanovdb/coarse-first.js.map +1 -1
  395. package/dist/tools/nanovdb/half.d.ts +22 -0
  396. package/dist/tools/nanovdb/half.js +73 -0
  397. package/dist/tools/nanovdb/half.js.map +1 -0
  398. package/dist/tools/nanovdb/index.d.ts +3 -1
  399. package/dist/tools/nanovdb/index.js +2 -1
  400. package/dist/tools/nanovdb/index.js.map +1 -1
  401. package/dist/tools/nanovdb/inspect.d.ts +10 -1
  402. package/dist/tools/nanovdb/inspect.js +8 -1
  403. package/dist/tools/nanovdb/inspect.js.map +1 -1
  404. package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
  405. package/dist/tools/nanovdb/leaf-codec.js +40 -4
  406. package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
  407. package/dist/tools/nanovdb/quantize.d.ts +39 -10
  408. package/dist/tools/nanovdb/quantize.js +96 -44
  409. package/dist/tools/nanovdb/quantize.js.map +1 -1
  410. package/dist/tools/nanovdb/resample.d.ts +20 -3
  411. package/dist/tools/nanovdb/resample.js +20 -7
  412. package/dist/tools/nanovdb/resample.js.map +1 -1
  413. package/dist/tools/nanovdb/serialize.d.ts +34 -3
  414. package/dist/tools/nanovdb/serialize.js +51 -7
  415. package/dist/tools/nanovdb/serialize.js.map +1 -1
  416. package/dist/tools/nanovdb/stats.d.ts +34 -5
  417. package/dist/tools/nanovdb/stats.js +87 -11
  418. package/dist/tools/nanovdb/stats.js.map +1 -1
  419. package/dist/tools/nanovdb/transform.d.ts +4 -0
  420. package/dist/tools/nanovdb/transform.js +3 -0
  421. package/dist/tools/nanovdb/transform.js.map +1 -1
  422. package/dist/tools/nanovdb/tree.d.ts +14 -3
  423. package/dist/tools/nanovdb/tree.js +25 -13
  424. package/dist/tools/nanovdb/tree.js.map +1 -1
  425. package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
  426. package/dist/tools/nanovdb/write-nvdb.js +108 -28
  427. package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
  428. package/dist/tools/nvdb-file.d.ts +77 -7
  429. package/dist/tools/nvdb-file.js +177 -20
  430. package/dist/tools/nvdb-file.js.map +1 -1
  431. package/dist/tools/nvdb-stream.d.ts +23 -7
  432. package/dist/tools/nvdb-stream.js +78 -34
  433. package/dist/tools/nvdb-stream.js.map +1 -1
  434. package/dist/tools/reference/analytic.d.ts +41 -0
  435. package/dist/tools/reference/analytic.js +95 -0
  436. package/dist/tools/reference/analytic.js.map +1 -0
  437. package/dist/tools/reference/environment.d.ts +62 -0
  438. package/dist/tools/reference/environment.js +154 -0
  439. package/dist/tools/reference/environment.js.map +1 -0
  440. package/dist/tools/reference/index.d.ts +12 -0
  441. package/dist/tools/reference/index.js +13 -0
  442. package/dist/tools/reference/index.js.map +1 -0
  443. package/dist/tools/reference/media.d.ts +14 -0
  444. package/dist/tools/reference/media.js +30 -0
  445. package/dist/tools/reference/media.js.map +1 -0
  446. package/dist/tools/reference/rng.d.ts +20 -0
  447. package/dist/tools/reference/rng.js +30 -0
  448. package/dist/tools/reference/rng.js.map +1 -0
  449. package/dist/tools/reference/scene.d.ts +312 -0
  450. package/dist/tools/reference/scene.js +169 -0
  451. package/dist/tools/reference/scene.js.map +1 -0
  452. package/dist/tools/reference/tables.d.ts +98 -0
  453. package/dist/tools/reference/tables.js +264 -0
  454. package/dist/tools/reference/tables.js.map +1 -0
  455. package/dist/tools/reference/trace.d.ts +160 -0
  456. package/dist/tools/reference/trace.js +497 -0
  457. package/dist/tools/reference/trace.js.map +1 -0
  458. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  459. package/dist/tools/vdb/blosc-write.js +197 -0
  460. package/dist/tools/vdb/blosc-write.js.map +1 -0
  461. package/dist/tools/vdb/blosc.d.ts +35 -5
  462. package/dist/tools/vdb/blosc.js +82 -26
  463. package/dist/tools/vdb/blosc.js.map +1 -1
  464. package/dist/tools/vdb/blosclz.d.ts +33 -0
  465. package/dist/tools/vdb/blosclz.js +112 -0
  466. package/dist/tools/vdb/blosclz.js.map +1 -0
  467. package/dist/tools/vdb/byte-reader.d.ts +13 -3
  468. package/dist/tools/vdb/byte-reader.js +26 -4
  469. package/dist/tools/vdb/byte-reader.js.map +1 -1
  470. package/dist/tools/vdb/compression.d.ts +13 -5
  471. package/dist/tools/vdb/compression.js +13 -2
  472. package/dist/tools/vdb/compression.js.map +1 -1
  473. package/dist/tools/vdb/grid.js +8 -2
  474. package/dist/tools/vdb/grid.js.map +1 -1
  475. package/dist/tools/vdb/index.d.ts +2 -1
  476. package/dist/tools/vdb/index.js.map +1 -1
  477. package/dist/tools/vdb/lz4.d.ts +30 -0
  478. package/dist/tools/vdb/lz4.js +228 -0
  479. package/dist/tools/vdb/lz4.js.map +1 -0
  480. package/dist/tools/vdb/metadata.js +1 -1
  481. package/dist/tools/vdb/metadata.js.map +1 -1
  482. package/dist/tools/vdb/parse.d.ts +24 -2
  483. package/dist/tools/vdb/parse.js +102 -32
  484. package/dist/tools/vdb/parse.js.map +1 -1
  485. package/dist/tools/vdb/point-render-data.d.ts +49 -1
  486. package/dist/tools/vdb/point-render-data.js +91 -11
  487. package/dist/tools/vdb/point-render-data.js.map +1 -1
  488. package/dist/tools/vdb/points.d.ts +26 -0
  489. package/dist/tools/vdb/points.js +46 -5
  490. package/dist/tools/vdb/points.js.map +1 -1
  491. package/dist/tools/vdb/types.d.ts +59 -2
  492. package/dist/tools/vdb/types.js.map +1 -1
  493. package/dist/tools/wvdb/bake.d.ts +38 -9
  494. package/dist/tools/wvdb/bake.js +63 -13
  495. package/dist/tools/wvdb/bake.js.map +1 -1
  496. package/dist/tools/wvdb/dense.d.ts +80 -1
  497. package/dist/tools/wvdb/dense.js +67 -8
  498. package/dist/tools/wvdb/dense.js.map +1 -1
  499. package/dist/tools/wvdb/format.d.ts +59 -0
  500. package/dist/tools/wvdb/format.js +3 -0
  501. package/dist/tools/wvdb/format.js.map +1 -1
  502. package/dist/tools/wvdb/index.d.ts +1 -0
  503. package/dist/tools/wvdb/index.js +1 -0
  504. package/dist/tools/wvdb/index.js.map +1 -1
  505. package/dist/tools/wvdb/level-set.d.ts +10 -2
  506. package/dist/tools/wvdb/level-set.js.map +1 -1
  507. package/dist/tools/wvdb/nanovdb.d.ts +6 -1
  508. package/dist/tools/wvdb/nanovdb.js +5 -1
  509. package/dist/tools/wvdb/nanovdb.js.map +1 -1
  510. package/dist/tools/wvdb/partial.d.ts +74 -0
  511. package/dist/tools/wvdb/partial.js +233 -0
  512. package/dist/tools/wvdb/partial.js.map +1 -0
  513. package/dist/tools/wvdb/read.d.ts +77 -1
  514. package/dist/tools/wvdb/read.js +30 -7
  515. package/dist/tools/wvdb/read.js.map +1 -1
  516. package/dist/tools/wvdb/write.d.ts +23 -1
  517. package/dist/tools/wvdb/write.js +8 -1
  518. package/dist/tools/wvdb/write.js.map +1 -1
  519. package/package.json +2 -1
  520. package/vendor/VENDOR.md +21 -6
  521. package/vendor/pnanovdb.wgsl +52 -14
  522. package/dist/three/frame/blackbody.d.ts +0 -42
  523. package/dist/three/frame/blackbody.js +0 -74
  524. package/dist/three/frame/blackbody.js.map +0 -1
  525. package/dist/three/frame/chunks.d.ts +0 -157
  526. package/dist/three/frame/chunks.js +0 -559
  527. package/dist/three/frame/chunks.js.map +0 -1
  528. package/dist/three/frame/density-material.d.ts +0 -53
  529. package/dist/three/frame/density-material.js +0 -353
  530. package/dist/three/frame/density-material.js.map +0 -1
  531. package/dist/three/frame/environment-grid-material.d.ts +0 -21
  532. package/dist/three/frame/environment-grid-material.js +0 -184
  533. package/dist/three/frame/environment-grid-material.js.map +0 -1
  534. package/dist/three/frame/environment-material.d.ts +0 -22
  535. package/dist/three/frame/environment-material.js +0 -87
  536. package/dist/three/frame/environment-material.js.map +0 -1
  537. package/dist/three/frame/grid-mip-material.d.ts +0 -12
  538. package/dist/three/frame/grid-mip-material.js +0 -61
  539. package/dist/three/frame/grid-mip-material.js.map +0 -1
  540. package/dist/three/frame/inject-material.d.ts +0 -56
  541. package/dist/three/frame/inject-material.js +0 -424
  542. package/dist/three/frame/inject-material.js.map +0 -1
  543. package/dist/three/frame/integrate-material.d.ts +0 -26
  544. package/dist/three/frame/integrate-material.js +0 -198
  545. package/dist/three/frame/integrate-material.js.map +0 -1
  546. package/dist/three/frame/layout.d.ts +0 -34
  547. package/dist/three/frame/layout.js +0 -48
  548. package/dist/three/frame/layout.js.map +0 -1
  549. package/dist/three/frame/lighting-material.d.ts +0 -41
  550. package/dist/three/frame/lighting-material.js +0 -257
  551. package/dist/three/frame/lighting-material.js.map +0 -1
  552. package/dist/three/frame/lights.d.ts +0 -11
  553. package/dist/three/frame/lights.js +0 -16
  554. package/dist/three/frame/lights.js.map +0 -1
  555. package/dist/three/frame/neural.d.ts +0 -14
  556. package/dist/three/frame/neural.js +0 -105
  557. package/dist/three/frame/neural.js.map +0 -1
  558. package/dist/three/frame/phase.d.ts +0 -44
  559. package/dist/three/frame/phase.js +0 -80
  560. package/dist/three/frame/phase.js.map +0 -1
  561. package/dist/three/frame/shadow-density-material.d.ts +0 -30
  562. package/dist/three/frame/shadow-density-material.js +0 -123
  563. package/dist/three/frame/shadow-density-material.js.map +0 -1
  564. package/dist/three/frame/temporal-material.d.ts +0 -29
  565. package/dist/three/frame/temporal-material.js +0 -152
  566. package/dist/three/frame/temporal-material.js.map +0 -1
  567. package/dist/three/frame/transmittance-material.d.ts +0 -31
  568. package/dist/three/frame/transmittance-material.js +0 -315
  569. package/dist/three/frame/transmittance-material.js.map +0 -1
  570. package/dist/three/frame/view.d.ts +0 -103
  571. package/dist/three/frame/view.js +0 -296
  572. package/dist/three/frame/view.js.map +0 -1
  573. package/dist/three/frame/volume-shadow-material.d.ts +0 -36
  574. package/dist/three/frame/volume-shadow-material.js +0 -128
  575. package/dist/three/frame/volume-shadow-material.js.map +0 -1
  576. package/dist/three/sequence.js.map +0 -1
@@ -1,11 +1,8 @@
1
- // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
2
- // src/three-openvdb/frame/webgpu/frameShaderChunks.js L729–763 (createVolumeUniforms, the source
3
- // half), L834–1028 (createVolumeNodes: getLod, sampleExtinction, sampleAlbedo, sampleEmission and
4
- // the box helpers, through ./volume-source.ts).
1
+ // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0): the source half of createVolumeUniforms /
2
+ // createVolumeNodes (frameShaderChunks.js L729–763, L834–1028), whose sparse-grid port (the TSL half) was deleted in K6.11
3
+ // (D35); this file is the handle the core's sparse source is made from.
5
4
  // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
6
- // Changes: the density is read from a sparse NanoVDB grid in a VDBGridPool (vdbSample, trilinear)
7
- // instead of an 8-bit 3D texture; three LOD strategies instead of his box mip atlas; an HDDA
8
- // empty-space query for marches. Divergences: DIVERGES.md (K3.2 rows), V23–V25.
5
+ // Divergences: DIVERGES.md (K3.2 rows), V23–V25, V145.
9
6
  /**
10
7
  * The sparse volume source (K3.2, R1 §4.2–4.3): a `VDBGridPool` grid behind the same seam as the
11
8
  * dense `.wvdb` source, so `VDBFrameVolume` renders NanoVDB grids.
@@ -14,23 +11,28 @@
14
11
  * const source = vdbSparseSource(grids, { density: id }, { lod: "coarse-pyramid", images: { density: image } });
15
12
  * const volume = new VDBFrameVolume(source, { extinction: 100 }); // box: the grid's world box
16
13
  *
14
+ * K6.8a / K6.11: the source is a handle (grids, ids, options, boxes, stats, the image-follow state). `VDBFrameRenderer`
15
+ * reads it into the core's sparse source (`vdbSparseSource`), which builds its own pyramids and reads the grids itself.
16
+ * The handle holds no GPU object. (Custom TSL materials sample a pooled grid through `VDBGridNode`; custom WGSL or compute
17
+ * uses the core source's `wgsl()`.)
18
+ *
17
19
  * Positions are his local unit box [-0.5, 0.5]³; uvw = local + 0.5 (+ offset, wrapped) maps onto the
18
20
  * channel grid's index cell box `[min − ½, max + ½]` (voxel centres at integers), so uvw
19
21
  * (i + 0.5) / N lands on voxel min + i as on a dense texel centre. The sample position is clamped to
20
- * `[min, max]` (his clamp-to-edge). Level 0 is the pool's trilinear `vdbSample`; with the node helper
22
+ * `[min, max]` (his clamp-to-edge). Level 0 is the pool's trilinear sample; with the node helper
21
23
  * `'fastTrilinear'` (recommended, K3.2d) it is `vdbSampleFast` through one accessor per shader invocation
22
- * (`cacheAccessor`): the same values, 1.5–2× faster on the hardware GPU (docs/archive/handoffs/K3-2d.md).
24
+ * (`cacheAccessor`): the same values, 1.5–2× faster on the hardware GPU (docs/archive/handoffs/K3-2d.md). (The core's
25
+ * sparse source reads these options.)
23
26
  *
24
27
  * LOD (`lod`, his `sampleExtinction(localPos, lod)` at lod ≥ 1; R1 §4.3):
25
28
  * - `'none'`: level 0 always (no prefilter; aliases when a froxel spans many voxels). lodLevels 0.
26
29
  * - `'coarse-pyramid'` (default, the K3.2 A/B pick): a dense r16f pyramid from L₀ = max(1, ⌈log2(maxTexels / pyramidMax)⌉):
27
30
  * the base is a box resample of the grid, the levels above it his box mip atlas. lod in (0, L₀)
28
31
  * blends level 0 toward L₀; lod ≥ L₀ samples the pyramid as his mip atlas. GPU bytes: ~2 B × (base
29
- * + atlas) texels. Built on the GPU from the pool grid by default (`pyramidBuild: 'gpu'`, K3.2a: the
30
- * core's `vdbCreateBoxPyramid`, no CPU image needed) and rebuilt when the grid's image changes
31
- * (`pool.replace`: a sequence frame), checked once per render that samples it; `'cpu'` keeps the
32
- * K3.2 path (`@pmndrs/vdb/tools` `vdbBoxPyramid` from `images.density`, static). Both give the same
33
- * texels to ≤ 1 f16 ulp (e2e/k3-pyramid.spec.ts).
32
+ * + atlas) texels. The core's sparse source builds it on the GPU from the pool grid (K3.2a: the core's
33
+ * `vdbCreateBoxPyramid`, no CPU image needed) and rebuilds it when the grid's image changes
34
+ * (`pool.replace`: a sequence frame). K6.11: the CPU build (`pyramidBuild: 'cpu'`, the three textures' static path) is
35
+ * deleted; `@pmndrs/vdb/tools` `vdbBoxPyramid` stays the GPU build's CPU twin.
34
36
  * - `'node-average'`: no extra memory: trilinear over the node averages (`vdbNodeAverage`) at
35
37
  * level 3 (leaves, the exact 8³ box mean for fog leaves) and level 7 (lower nodes, the mean of
36
38
  * their active voxels); lod in (0, 3) blends level 0 → 3, (3, 7) blends 3 → 7. Needs stats.
@@ -41,28 +43,15 @@
41
43
  * Following the image (`followImage`, G16a): the index boxes, world box and pyramid are fixed when the source is
42
44
  * made unless it follows the grids' images. Then a `pool.replace` that changes a channel grid's box (a coarse-first
43
45
  * swap: the preview, then the full grid in the same id) is re-read from `pool.info` once the new image is resident:
44
- * new box uniforms, a new GPU pyramid of the new size (its textures swapped into the same texture nodes), the LOD
45
- * range as a uniform, and a new `version`, which a `VDBFrameVolume` follows with its box. No shader is rebuilt, and the
46
- * pyramid kernels of every type the `VDBGridNode` decodes are compiled up front.
46
+ * the new layout, the LOD range and a new `version`, which a `VDBFrameVolume` follows with its box. No shader is rebuilt.
47
47
  *
48
48
  * Mask, albedo and emission grids (optional, scalar; albedo may be three grids for RGB) are read at
49
49
  * level 0 only. One VDB module per shader: every grid goes through the one `VDBGridNode`.
50
50
  */
51
- import * as THREE from "three";
52
- import * as TSL from "three/tsl";
53
- import { code, wgslFn } from "three/tsl";
54
51
  import { VDBError } from "../core/errors.js";
55
- import { vdbCreateBoxPyramid, warmBoxPyramidPipelines } from "../core/compute/pyramid.js";
56
- import { vdbBoxPyramid } from "../tools/frame/sparse.js";
57
52
  import { vdbBoxPyramidLayout } from "../tools/frame/pyramid-layout.js";
58
- import { getGPUTexture, webgpuBackendOf } from "./device.js";
59
53
  import { leafVoxels, treeNodes } from "../tools/cpu/march.js";
60
- import { vdbSample } from "./grid-node.js";
61
- import { vdbBoxNodes, vdbDensityScaleOf, vdbGridUv, vdbMaxComponent, vdbMipSampler, } from "./volume-source.js";
62
- const { If, clamp, float, int, log2, max, min, mix, pow, select, texture3D, uint, uniform, vec2, vec3 } = TSL;
63
54
  const bad = (message) => new VDBError("VDB_BAD_OPTION", `vdbSparseSource: ${message}`);
64
- /** G16a: the pyramid texture nodes of a following source's uniforms (their textures change with the layout). */
65
- const pyramidTextures = new WeakMap();
66
55
  /** The non-zero density stats of an image (all leaf voxels, active or not, and active tiles). */
67
56
  function imageStats(image, clamp01) {
68
57
  let sum = 0;
@@ -101,123 +90,16 @@ function worldBox(box, m) {
101
90
  }
102
91
  return [lo, hi];
103
92
  }
104
- /** A half-float r16f Data3DTexture (linear, clamp-to-edge, no mipmaps); `data` null: GPU-written (no upload). */
105
- function halfTexture(data, dims) {
106
- let half = null;
107
- if (data) {
108
- half = new Uint16Array(data.length);
109
- for (let i = 0; i < data.length; i++)
110
- half[i] = THREE.DataUtils.toHalfFloat(data[i]);
111
- }
112
- const [w, h, d] = dims;
113
- const texture = new THREE.Data3DTexture(half, w, h, d);
114
- // A GPU-written texture: three allocates it (createTexture) but never uploads (no data to upload).
115
- if (!half)
116
- texture.source.dataReady = false;
117
- texture.format = THREE.RedFormat;
118
- texture.type = THREE.HalfFloatType;
119
- texture.minFilter = THREE.LinearFilter;
120
- texture.magFilter = THREE.LinearFilter;
121
- texture.unpackAlignment = 1;
122
- texture.generateMipmaps = false;
123
- texture.needsUpdate = true;
124
- return texture;
93
+ /** Local unit box → sample index space: p = min − ½ + (local + ½)·size (column-major). */
94
+ function boxToSourceOf(b, texels) {
95
+ const [sx, sy, sz] = texels;
96
+ return new Float32Array([sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, b.min[0] - 0.5 + 0.5 * sx, b.min[1] - 0.5 + 0.5 * sy, b.min[2] - 0.5 + 0.5 * sz, 1]);
125
97
  }
126
- // WGSL helpers over the grid module (one module per shader: the VDBGridNode's).
127
- const NODE_AVERAGE_WGSL = /* wgsl */ `fn vdbFrameNodeAverage(g: u32, p: vec3f, dim: u32) -> f32 {
128
- var acc = vdbAccessorInit(g);
129
- let fd = f32(dim);
130
- let q = (p - vec3f(0.5 * fd - 0.5)) / fd;
131
- let base = floor(q);
132
- let w = q - base;
133
- let c = vec3i(base) * i32(dim);
134
- // One call site in a loop: SwiftShader compiles 8 inlined tree walks very slowly.
135
- var v: array<f32, 8>;
136
- for (var k = 0u; k < 8u; k++) {
137
- v[k] = vdbNodeAverage(&acc, c + vec3i(vec3u(k & 1u, (k >> 1u) & 1u, (k >> 2u) & 1u)) * i32(dim), dim);
138
- }
139
- let x00 = v[0] + w.x * (v[1] - v[0]);
140
- let x10 = v[2] + w.x * (v[3] - v[2]);
141
- let x01 = v[4] + w.x * (v[5] - v[4]);
142
- let x11 = v[6] + w.x * (v[7] - v[6]);
143
- let y0 = x00 + w.y * (x10 - x00);
144
- let y1 = x01 + w.y * (x11 - x01);
145
- return y0 + w.z * (y1 - y0);
146
- }`;
147
- // The 'node-average' density at a lod (one call per sample: level 0 → 3 → 7 blends, two taps at most).
148
- const nodeLodWgsl = (sample) => /* wgsl */ `fn vdbFrameNodeLod(g: u32, p: vec3f, lod: f32) -> f32 {
149
- var acc = vdbAccessorInit(g);
150
- if lod <= 0.0 {
151
- return ${sample}(&acc, p);
152
- }
153
- let fine = lod < 3.0;
154
- var a = 0.0;
155
- if fine {
156
- a = ${sample}(&acc, p);
157
- } else {
158
- a = vdbFrameNodeAverage(g, p, 8u);
159
- }
160
- if lod >= 7.0 {
161
- return vdbFrameNodeAverage(g, p, 128u);
162
- }
163
- let b = vdbFrameNodeAverage(g, p, select(128u, 8u, fine));
164
- let t = select((lod - 3.0) / 4.0, lod / 3.0, fine);
165
- return mix(a, b, t);
166
- }`;
167
- // K3.2d: level-0 density through the source's own sampler: vdbSampleFast (helper 'fastTrilinear') and/or one
168
- // accessor per invocation kept in a private variable (copied in and out: WGSL can't pass a ptr<private> where
169
- // the API takes ptr<function>). Same values as vdbSample with a fresh accessor (the accessor cache only skips
170
- // the descent).
171
- const SAMPLE_CACHE_WGSL = /* wgsl */ `var<private> vdbFrameAcc: VdbAccessor;
172
- var<private> vdbFrameAccGrid: u32 = 0xffffffffu;`;
173
- const sampleWgsl = (fast, cached) => {
174
- const call = fast ? "vdbSampleFast" : "vdbSample";
175
- return cached
176
- ? /* wgsl */ `fn vdbFrameSample(g: u32, xyz: vec3f) -> f32 {
177
- if vdbFrameAccGrid != g {
178
- vdbFrameAcc = vdbAccessorInit(g);
179
- vdbFrameAccGrid = g;
180
- }
181
- var a = vdbFrameAcc;
182
- let v = ${call}(&a, xyz);
183
- vdbFrameAcc = a;
184
- return v;
185
- }`
186
- : /* wgsl */ `fn vdbFrameSample(g: u32, xyz: vec3f) -> f32 {
187
- var a = vdbAccessorInit(g);
188
- return ${call}(&a, xyz);
189
- }`;
190
- };
191
- // The HDDA empty-space query; CPU twin tools vdbFrameSkipEmpty (see there for the contract).
192
- const SKIP_EMPTY_WGSL = /* wgsl */ `fn vdbFrameSkipEmpty(g: u32, o: vec3f, d: vec3f, t0: f32, t1: f32, cutoff: f32, dilate: u32) -> vec2f {
193
- var acc = vdbAccessorInit(g);
194
- var h: VdbHdda;
195
- vdbHddaInit(&h, o, t0, d, t1, 8u);
196
- let back = 1e-3 / max(length(d), 1e-6);
197
- var ts = t0;
198
- for (var n = 0u; n < 64u; n++) {
199
- let te = vdbHddaCellEnd(&h);
200
- var b = 0.0;
201
- if dilate == 0u {
202
- b = vdbCellBoundTrilinear(&acc, h.voxel, 8u);
203
- } else {
204
- b = -1e30;
205
- for (var k = 0u; k < 27u; k++) {
206
- let c = vec3i(i32(k % 3u) - 1, i32((k / 3u) % 3u) - 1, i32(k / 9u) - 1) * 8;
207
- b = max(b, vdbNodeMax(&acc, h.voxel + c, 8u));
208
- }
209
- }
210
- if b > cutoff {
211
- return vec2f(max(t0, ts - back), te);
212
- }
213
- ts = te;
214
- if !vdbHddaStep(&h) {
215
- return vec2f(t1, t1);
216
- }
217
- }
218
- let r = max(t0, ts - back);
219
- return vec2f(r, r);
220
- }`;
98
+ const texelsOf = (b) => [b.max[0] - b.min[0] + 1, b.max[1] - b.min[1] + 1, b.max[2] - b.min[2] + 1];
99
+ /**
100
+ * The handle (K6.8a): grids, ids, options, boxes, stats and the image-follow state. The frame renderer reads these into
101
+ * the core's sparse source.
102
+ */
221
103
  class SparseSource {
222
104
  kind = "sparse";
223
105
  grids;
@@ -234,34 +116,24 @@ class SparseSource {
234
116
  statsUpdates = 0;
235
117
  boxToSource;
236
118
  bbox;
237
- pyramid;
238
- gpuBytes;
239
119
  fastTrilinear;
240
120
  cacheAccessor;
241
121
  followImage;
242
- pyramidBuilds = 0;
122
+ pyramidOptions;
123
+ /** K3.2f (internal): the core source's brick cache. */
124
+ brickCache;
125
+ /** K3.2f-e (internal): the core source's other brick options (validated by the core source). */
126
+ brickOptions;
243
127
  layoutUpdates = 0;
244
- /** G16a: the newest channel imageRevision the layout describes, the pool revision last checked, the uniforms to re-apply. */
245
- layoutRevision = -1;
246
- layoutPoolRevision = -1;
247
- layoutListeners = new Set();
248
- /** G16a: `pyramidMax` as given (the pyramid is re-laid out with it). */
249
- pyramidMaxOption;
250
- /** G16a: the atlas node's texture when the layout has no atlas (a 1³ zero texture of its own). */
251
- emptyAtlas = null;
252
- poolRevisionSeen = -1;
253
- poolIds;
254
- versionSeen = { poolRevision: -1, value: 0 };
255
- nodeAverageCache = null;
256
- nodeLodCache = null;
257
- skipCache = null;
258
- sampleCache = null;
128
+ /** G16a: the newest channel imageRevision the layout describes, the pool revision last checked. */
129
+ #layoutRevision = -1;
130
+ #layoutPoolRevision = -1;
131
+ #poolIds;
132
+ #versionSeen = { poolRevision: -1, value: 0 };
259
133
  /** K3.2e: the density imageRevision the stats describe, the pool revision last checked, and a readback in flight. */
260
- statsRevision = -1;
261
- statsPoolRevisionSeen = -1;
262
- statsReadback = null;
263
- /** K5.9a: each of this source's uniforms re-applies its density scale with the new mean when a readback lands. */
264
- statsListeners = new Set();
134
+ #statsRevision = -1;
135
+ #statsPoolRevisionSeen = -1;
136
+ #statsReadback = null;
265
137
  constructor(grids, ids, o) {
266
138
  const pool = grids.pool;
267
139
  if (typeof pool.info !== "function")
@@ -285,6 +157,17 @@ class SparseSource {
285
157
  throw bad("fastTrilinear needs the VDBGridNode's sampler 'trilinear'.");
286
158
  this.fastTrilinear = fastTrilinear;
287
159
  this.cacheAccessor = o.cacheAccessor ?? true;
160
+ const brickCache = o.brickCache ?? "off";
161
+ if (brickCache !== "off" && brickCache !== "f32" && brickCache !== "f16")
162
+ throw bad(`brickCache must be 'off', 'f32' or 'f16', got ${JSON.stringify(brickCache)}.`);
163
+ this.brickCache = brickCache;
164
+ const io = o;
165
+ this.brickOptions = Object.freeze({
166
+ ...(io.brickKernels !== undefined ? { brickKernels: io.brickKernels } : {}),
167
+ ...(io.brickMarkStats !== undefined ? { brickMarkStats: io.brickMarkStats } : {}),
168
+ ...(io.brickCapacity !== undefined ? { brickCapacity: io.brickCapacity } : {}),
169
+ ...(io.brickBudget !== undefined ? { brickBudget: io.brickBudget } : {}),
170
+ });
288
171
  const followImage = o.followImage ?? false;
289
172
  if (typeof followImage !== "boolean")
290
173
  throw bad("followImage must be a boolean.");
@@ -292,11 +175,8 @@ class SparseSource {
292
175
  const fixed = ["indexBox", "auxIndexBoxes", "bbox"].filter((k) => o[k] !== undefined);
293
176
  if (fixed.length)
294
177
  throw bad(`followImage re-reads every box from the pool; drop ${fixed.join(", ")} (fixed boxes).`);
295
- if (lod === "coarse-pyramid" && o.pyramidBuild === "cpu")
296
- throw bad("followImage rebuilds the pyramid from the pool on the GPU; use pyramidBuild 'gpu' (the default).");
297
178
  }
298
179
  this.followImage = followImage;
299
- this.pyramidMaxOption = o.pyramidMax !== undefined ? { pyramidMax: o.pyramidMax } : {};
300
180
  const density = info(ids.density);
301
181
  if (lod === "node-average" && !density.hasStats)
302
182
  throw bad("lod 'node-average' reads node statistics; this grid has none (rebuild it with stats).");
@@ -313,7 +193,7 @@ class SparseSource {
313
193
  this.auxBoxes = { mask: box(ids.mask, aux.mask), albedo: box(albedoId, aux.albedo), emission: box(ids.emission, aux.emission) };
314
194
  this.channels = { mask: ids.mask !== undefined, albedo: ids.albedo !== undefined, emission: ids.emission !== undefined };
315
195
  const b = this.indexBox;
316
- this.texels = [b.max[0] - b.min[0] + 1, b.max[1] - b.min[1] + 1, b.max[2] - b.min[2] + 1];
196
+ this.texels = texelsOf(b);
317
197
  if (this.texels.some((t) => !(t > 0)))
318
198
  throw bad("the density index box is empty.");
319
199
  const image = o.images?.density;
@@ -323,107 +203,36 @@ class SparseSource {
323
203
  this.stats = imageStats(image, normalize === "clamp01");
324
204
  else
325
205
  throw bad("pass images.density (the CPU image, for the density stats) or stats.");
326
- this.statsRevision = density.imageRevision ?? -1;
327
- // Local unit box → sample index space: p = min − ½ + (local + ½)·size (column-major).
328
- const [sx, sy, sz] = this.texels;
329
- this.boxToSource = new Float32Array([sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, b.min[0] - 0.5 + 0.5 * sx, b.min[1] - 0.5 + 0.5 * sy, b.min[2] - 0.5 + 0.5 * sz, 1]);
206
+ this.#statsRevision = density.imageRevision ?? -1;
207
+ this.boxToSource = boxToSourceOf(b, this.texels);
330
208
  this.bbox = o.bbox ? [[...o.bbox[0]], [...o.bbox[1]]] : worldBox(b, density.indexToWorld);
331
- let pyramid = null;
332
- if (lod === "coarse-pyramid") {
333
- const build = o.pyramidBuild ?? "gpu";
334
- if (build !== "gpu" && build !== "cpu")
335
- throw bad(`unknown pyramidBuild ${JSON.stringify(build)}; use 'gpu' or 'cpu'.`);
336
- const pyramidMax = o.pyramidMax !== undefined ? { pyramidMax: o.pyramidMax } : {};
337
- if (build === "cpu") {
338
- if (!image)
339
- throw bad("pyramidBuild 'cpu' builds the pyramid from images.density; pass it, or use pyramidBuild 'gpu' (the default).");
340
- const p = vdbBoxPyramid(image, { indexBox: b, ...pyramidMax });
341
- pyramid = {
342
- build,
343
- level: p.level,
344
- dimensions: p.dimensions,
345
- atlas: p.atlas,
346
- lodLevels: p.lodLevels,
347
- data: p.data,
348
- map: halfTexture(p.data, p.dimensions),
349
- mip: p.atlas ? halfTexture(p.atlas.data, p.atlas.dimensions) : null,
350
- gpu: null,
351
- };
352
- }
353
- else {
354
- const renderer = grids.renderer;
355
- let device;
356
- try {
357
- device = webgpuBackendOf(renderer, "vdbSparseSource").device;
358
- }
359
- catch {
360
- throw bad("pyramidBuild 'gpu' (the default for lod 'coarse-pyramid') needs the VDBGridNode's initialized WebGPURenderer; use pyramidBuild 'cpu' with images.density otherwise.");
361
- }
362
- const initTexture = renderer.initTexture;
363
- if (typeof initTexture !== "function")
364
- throw bad("pyramidBuild 'gpu' needs renderer.initTexture (three r187 WebGPURenderer).");
365
- // G16a: a following source compiles the pyramid kernels of every type the node decodes now, so a swap to
366
- // another grid type creates no pipeline.
367
- if (followImage)
368
- warmBoxPyramidPipelines(device, grids.options.types);
369
- pyramid = this.gpuPyramid(b, ids.density);
370
- }
371
- }
372
- this.pyramid = pyramid;
373
- this.lodLevels = lod === "none" ? 0 : lod === "node-average" ? 7 : pyramid.lodLevels;
374
- this.poolIds = [...new Set(channelIds)];
375
- this.gpuBytes = this.measure();
376
- this.layoutRevision = this.poolIds.reduce((r, id) => Math.max(r, info(id).imageRevision ?? 0), 0);
377
- this.refreshPyramid();
378
- }
379
- /** GPU bytes of the channel grids' pool ranges and the pyramid (see the interface). */
380
- measure() {
381
- const pool = this.grids.pool;
382
- const p = this.pyramid;
383
- const atlasTexels = p?.atlas ? p.atlas.dimensions[0] * p.atlas.dimensions[1] * p.atlas.dimensions[2] : 0;
384
- const pyramidBytes = p ? 2 * (p.dimensions[0] * p.dimensions[1] * p.dimensions[2] + atlasTexels) : 0;
385
- return { pool: this.poolIds.reduce((s, id) => s + pool.info(id).capacity, 0), pyramid: pyramidBytes, pyramidScratch: p?.gpu?.gpuBytes.scratch ?? 0 };
209
+ this.pyramidOptions = o.pyramidMax !== undefined ? { pyramidMax: o.pyramidMax } : {};
210
+ this.lodLevels = this.#lodLevelsOf(this.texels);
211
+ this.#poolIds = [...new Set(channelIds)];
212
+ this.#layoutRevision = this.#poolIds.reduce((r, id) => Math.max(r, info(id).imageRevision ?? 0), 0);
386
213
  }
387
- /** The GPU pyramid of `box` (K3.2a): three textures the core's `vdbCreateBoxPyramid` writes into. */
388
- gpuPyramid(box, densityId) {
389
- const renderer = this.grids.renderer;
390
- const device = webgpuBackendOf(renderer, "vdbSparseSource").device;
391
- const texels = [0, 1, 2].map((a) => box.max[a] - box.min[a] + 1);
392
- const layout = vdbBoxPyramidLayout(texels, this.pyramidMaxOption);
393
- const map = halfTexture(null, layout.dimensions);
394
- const mip = layout.atlas ? halfTexture(null, layout.atlas.dimensions) : null;
395
- map.name = "vdbSparseSource pyramid base";
396
- if (mip)
397
- mip.name = "vdbSparseSource pyramid atlas";
398
- for (const t of [map, mip])
399
- if (t)
400
- renderer.initTexture(t);
401
- const gpu = vdbCreateBoxPyramid(device, this.grids.pool, densityId, {
402
- indexBox: box,
403
- ...this.pyramidMaxOption,
404
- targets: { base: getGPUTexture(renderer, map), atlas: mip ? getGPUTexture(renderer, mip) : null },
405
- label: "vdbSparseSource pyramid",
406
- });
407
- return {
408
- build: "gpu",
409
- level: layout.level,
410
- dimensions: [...layout.dimensions],
411
- atlas: layout.atlas ? { dimensions: [...layout.atlas.dimensions], levels: layout.atlas.levels.length } : null,
412
- lodLevels: layout.lodLevels,
413
- map,
414
- mip,
415
- gpu,
416
- };
214
+ /** The LOD range: 0 (`'none'`), 7 (`'node-average'`), the pyramid layout's levels (`'coarse-pyramid'`). */
215
+ #lodLevelsOf(texels) {
216
+ if (this.lod === "none")
217
+ return 0;
218
+ if (this.lod === "node-average")
219
+ return 7;
220
+ const { pyramidMax } = this.pyramidOptions;
221
+ return vdbBoxPyramidLayout(texels, pyramidMax !== undefined ? { pyramidMax } : {}).lodLevels;
417
222
  }
418
- /** G16a: the atlas texture a following source's shaders bind: the pyramid's, else a 1³ zero texture (never read). */
419
- atlasTexture() {
420
- if (this.pyramid?.mip)
421
- return this.pyramid.mip;
422
- if (!this.emptyAtlas) {
423
- this.emptyAtlas = halfTexture(new Float32Array(1), [1, 1, 1]);
424
- this.emptyAtlas.name = "vdbSparseSource empty atlas";
223
+ /** GPU bytes of the channel grids' pool ranges. */
224
+ get gpuBytes() {
225
+ const pool = this.grids.pool;
226
+ let bytes = 0;
227
+ for (const id of this.#poolIds) {
228
+ try {
229
+ bytes += pool.info(id).capacity;
230
+ }
231
+ catch {
232
+ // A removed grid holds no pool range.
233
+ }
425
234
  }
426
- return this.emptyAtlas;
235
+ return { pool: bytes };
427
236
  }
428
237
  /**
429
238
  * G16a (`followImage`): re-reads the layout when a channel grid's image changed and every channel grid is resident
@@ -435,12 +244,12 @@ class SparseSource {
435
244
  if (!this.followImage)
436
245
  return false;
437
246
  const pool = this.grids.pool;
438
- if (typeof pool.revision !== "number" || pool.revision === this.layoutPoolRevision)
247
+ if (typeof pool.revision !== "number" || pool.revision === this.#layoutPoolRevision)
439
248
  return false;
440
249
  let revision = 0;
441
250
  let resident = true;
442
251
  const infos = [];
443
- for (const id of this.poolIds) {
252
+ for (const id of this.#poolIds) {
444
253
  let i;
445
254
  try {
446
255
  i = pool.info(id);
@@ -453,8 +262,8 @@ class SparseSource {
453
262
  resident = false;
454
263
  infos.push({ id, type: i.type });
455
264
  }
456
- if (revision === this.layoutRevision) {
457
- this.layoutPoolRevision = pool.revision;
265
+ if (revision === this.#layoutRevision) {
266
+ this.#layoutPoolRevision = pool.revision;
458
267
  return false;
459
268
  }
460
269
  if (!resident)
@@ -462,9 +271,9 @@ class SparseSource {
462
271
  // A new image of a type the module does not decode would read 0 through the new boxes, silently: say so instead
463
272
  // (every call until the source is remade over a node that compiles it).
464
273
  this.checkTypes(infos, "a channel grid's new image");
465
- this.relayout();
466
- this.layoutRevision = revision;
467
- this.layoutPoolRevision = pool.revision;
274
+ this.#relayout();
275
+ this.#layoutRevision = revision;
276
+ this.#layoutPoolRevision = pool.revision;
468
277
  return true;
469
278
  }
470
279
  /**
@@ -482,7 +291,7 @@ class SparseSource {
482
291
  `${compiled.join(", ")}; it would read 0. Make the VDBGridNode with types that include every type the images will have ` +
483
292
  `(a coarse-first stream lists them in VDBCoarseFirstEvent.types: types: event.types), then make the source over it.`);
484
293
  }
485
- relayout() {
294
+ #relayout() {
486
295
  const pool = this.grids.pool;
487
296
  const ids = this.ids;
488
297
  const density = pool.info(ids.density);
@@ -490,38 +299,14 @@ class SparseSource {
490
299
  const old = this.indexBox;
491
300
  const moved = b.min.some((v, a) => v !== old.min[a]) || b.max.some((v, a) => v !== old.max[a]);
492
301
  this.indexBox = b;
493
- this.texels = [b.max[0] - b.min[0] + 1, b.max[1] - b.min[1] + 1, b.max[2] - b.min[2] + 1];
494
- const [sx, sy, sz] = this.texels;
495
- this.boxToSource = new Float32Array([sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, b.min[0] - 0.5 + 0.5 * sx, b.min[1] - 0.5 + 0.5 * sy, b.min[2] - 0.5 + 0.5 * sz, 1]);
302
+ this.texels = texelsOf(b);
303
+ this.boxToSource = boxToSourceOf(b, this.texels);
496
304
  this.bbox = worldBox(b, density.indexToWorld);
497
305
  const auxBox = (id) => (id === undefined ? null : { min: [...pool.info(id).indexBBox.min], max: [...pool.info(id).indexBBox.max] });
498
306
  this.auxBoxes = { mask: auxBox(ids.mask), albedo: auxBox(Array.isArray(ids.albedo) ? ids.albedo[0] : ids.albedo), emission: auxBox(ids.emission) };
499
- // A new box needs a pyramid of its size (and box min); the same box rebuilds in place (refreshPyramid).
500
- const previous = this.pyramid;
501
- if (moved && previous?.gpu) {
502
- this.pyramid = this.gpuPyramid(b, ids.density);
503
- this.lodLevels = this.pyramid.lodLevels;
504
- this.poolRevisionSeen = -1;
505
- }
506
- this.gpuBytes = this.measure();
307
+ if (moved)
308
+ this.lodLevels = this.#lodLevelsOf(this.texels);
507
309
  this.layoutUpdates++;
508
- for (const apply of this.layoutListeners)
509
- apply();
510
- // After the uniforms point at the new textures, the old ones go, but not yet: three r187's texture.dispose()
511
- // destroys the GPUTexture at once, and a pass this render already recorded (not submitted yet) may bind them.
512
- // Renders submit in the task that records them, so wait past this task, then for the queue's submitted work.
513
- if (previous !== this.pyramid && previous) {
514
- const retire = () => {
515
- previous.gpu?.destroy();
516
- previous.map.dispose();
517
- previous.mip?.dispose();
518
- };
519
- const device = this.grids.pool.device;
520
- if (device?.queue)
521
- setTimeout(() => void device.queue.onSubmittedWorkDone().then(retire, retire), 0);
522
- else
523
- retire();
524
- }
525
310
  }
526
311
  /**
527
312
  * Content version: the newest `imageRevision` of the channel grids (K3.2a), so a `pool.replace` (a
@@ -533,14 +318,14 @@ class SparseSource {
533
318
  // resident and the boxes were re-read), so a VDBFrameVolume re-reads its box and the uniforms then.
534
319
  if (this.followImage) {
535
320
  this.syncLayout();
536
- return this.layoutRevision;
321
+ return this.#layoutRevision;
537
322
  }
538
323
  const pool = this.grids.pool;
539
324
  if (typeof pool.revision !== "number")
540
325
  return 0;
541
- if (pool.revision !== this.versionSeen.poolRevision) {
326
+ if (pool.revision !== this.#versionSeen.poolRevision) {
542
327
  let value = 0;
543
- for (const id of this.poolIds) {
328
+ for (const id of this.#poolIds) {
544
329
  try {
545
330
  value = Math.max(value, pool.info(id).imageRevision ?? 0);
546
331
  }
@@ -548,38 +333,16 @@ class SparseSource {
548
333
  // A removed grid: keep the others' revision.
549
334
  }
550
335
  }
551
- this.versionSeen = { poolRevision: pool.revision, value };
552
- }
553
- return this.versionSeen.value;
554
- }
555
- refreshPyramid() {
556
- this.syncLayout();
557
- const gpu = this.pyramid?.gpu;
558
- if (!gpu)
559
- return false;
560
- // Cheap test first: the pool's revision moves on any change; the grid's imageRevision tells whether this one did.
561
- const pool = this.grids.pool;
562
- if (pool.revision === this.poolRevisionSeen)
563
- return false;
564
- const device = pool.device;
565
- const encoder = device.createCommandEncoder({ label: "vdbSparseSource pyramid" });
566
- if (!gpu.update(encoder)) {
567
- // Not resident yet (the update that writes it is still to come): look again next time.
568
- if (!gpu.stale)
569
- this.poolRevisionSeen = pool.revision;
570
- return false;
336
+ this.#versionSeen = { poolRevision: pool.revision, value };
571
337
  }
572
- device.queue.submit([encoder.finish()]);
573
- this.poolRevisionSeen = pool.revision;
574
- this.pyramidBuilds++;
575
- return true;
338
+ return this.#versionSeen.value;
576
339
  }
577
340
  refreshStats() {
578
- if (this.statsReadback)
579
- return this.statsReadback;
341
+ if (this.#statsReadback)
342
+ return this.#statsReadback;
580
343
  const pool = this.grids.pool;
581
344
  // Cheap test first (once per render): the pool's revision moves on any change.
582
- if (typeof pool.revision !== "number" || pool.revision === this.statsPoolRevisionSeen || !pool.device || !pool.buffer)
345
+ if (typeof pool.revision !== "number" || pool.revision === this.#statsPoolRevisionSeen || !pool.device || !pool.buffer)
583
346
  return Promise.resolve(false);
584
347
  let info;
585
348
  try {
@@ -589,8 +352,8 @@ class SparseSource {
589
352
  return Promise.resolve(false); // removed: keep the last stats
590
353
  }
591
354
  const revision = info.imageRevision ?? -1;
592
- if (revision === this.statsRevision) {
593
- this.statsPoolRevisionSeen = pool.revision;
355
+ if (revision === this.#statsRevision) {
356
+ this.#statsPoolRevisionSeen = pool.revision;
594
357
  return Promise.resolve(false);
595
358
  }
596
359
  // Not written yet (the update that writes it is still to come): look again next time.
@@ -603,268 +366,34 @@ class SparseSource {
603
366
  encoder.copyBufferToBuffer(buffer, info.imageOffset, staging, 0, bytes);
604
367
  device.queue.submit([encoder.finish()]);
605
368
  const seen = pool.revision;
606
- this.statsReadback = staging
369
+ this.#statsReadback = staging
607
370
  .mapAsync(0x1) // GPUMapMode.READ
608
371
  .then(() => {
609
372
  const image = new Uint32Array(staging.getMappedRange().slice(0));
610
373
  this.stats = imageStats(image, this.normalize === "clamp01");
611
- this.statsRevision = revision;
612
- this.statsPoolRevisionSeen = seen;
374
+ this.#statsRevision = revision;
375
+ this.#statsPoolRevisionSeen = seen;
613
376
  this.statsUpdates++;
614
- for (const apply of this.statsListeners)
615
- apply();
616
377
  return true;
617
378
  })
618
379
  .catch(() => false)
619
380
  .finally(() => {
620
381
  staging.destroy();
621
- this.statsReadback = null;
382
+ this.#statsReadback = null;
622
383
  });
623
- return this.statsReadback;
624
- }
625
- nodeAverageFn() {
626
- this.nodeAverageCache ??= wgslFn(NODE_AVERAGE_WGSL, [this.grids.module]);
627
- return this.nodeAverageCache;
628
- }
629
- nodeLodFn() {
630
- this.nodeLodCache ??= wgslFn(nodeLodWgsl(this.fastTrilinear ? "vdbSampleFast" : "vdbSample"), [this.grids.module, this.nodeAverageFn()]);
631
- return this.nodeLodCache;
632
- }
633
- /** `vdbFrameSample(g, xyz) -> f32`: level 0 (index space) as configured (`fastTrilinear`, `cacheAccessor`). */
634
- sampleFn() {
635
- this.sampleCache ??= wgslFn(sampleWgsl(this.fastTrilinear, this.cacheAccessor), (this.cacheAccessor ? [this.grids.module, code(SAMPLE_CACHE_WGSL, [this.grids.module])] : [this.grids.module]));
636
- return this.sampleCache;
637
- }
638
- skipEmptyFn() {
639
- this.skipCache ??= wgslFn(SKIP_EMPTY_WGSL, [this.grids.module]);
640
- return this.skipCache;
641
- }
642
- createUniforms(p) {
643
- let densityScale = p.densityScale ?? 1.0;
644
- let normalize = p.normalizeDensity ?? true;
645
- const boxUniform = (bx) => bx ? { min: uniform(new THREE.Vector3(...bx.min)), size: uniform(new THREE.Vector3(bx.max[0] - bx.min[0] + 1, bx.max[1] - bx.min[1] + 1, bx.max[2] - bx.min[2] + 1)) } : null;
646
- const levels = uniform(this.lodLevels);
647
- // K3.2e: the mean follows the density image (refreshStats, checked once per render, reads a replaced image
648
- // back). K5.9a: the new mean is applied once, when the readback lands; the render update never writes the
649
- // value, so a value set per draw (VDBFrameVolume's densityScale, through setVolumeUniforms) stays as set.
650
- const densityScaleU = uniform(vdbDensityScaleOf(this, densityScale, normalize)).onRenderUpdate(() => {
651
- this.syncLayout();
652
- void this.refreshStats();
653
- return undefined;
654
- });
655
- const applyStats = () => {
656
- densityScaleU.value = vdbDensityScaleOf(this, densityScale, normalize);
657
- };
658
- this.statsListeners.add(applyStats);
659
- const pyr = this.pyramid;
660
- // G16a: a following source samples its pyramid through texture nodes made here (one pair per uniforms), so a new
661
- // layout swaps their textures; the atlas node always exists (a 1³ texture when the layout has none).
662
- const textures = this.followImage && pyr ? { map: texture3D(pyr.map), mip: texture3D(this.atlasTexture()) } : null;
663
- const u = {
664
- worldScale: uniform(p.worldScale ?? 1.0),
665
- gridTexels: uniform(new THREE.Vector3(...this.texels)),
666
- mipAtlasSize: uniform(new THREE.Vector3(1, 1, 1)),
667
- maps: { density: null, mask: null, albedo: null, emission: null },
668
- mipMaps: { density: null, mask: null, albedo: null, emission: null },
669
- // getSampledLod reads density (and mask) levels; aux channels are level 0 only but report the same.
670
- mipLevels: { density: levels, mask: levels, albedo: levels, emission: levels },
671
- baseColor: uniform(new THREE.Color(p.baseColor ?? 0xffffff)),
672
- extinction: uniform(p.extinction ?? 100.0),
673
- densityScale: densityScaleU,
674
- densityCutoff: uniform(p.densityCutoff ?? 0.0),
675
- emissiveIntensity: uniform(p.emissiveIntensity ?? 1.0),
676
- temperatureRange: uniform(new THREE.Vector2(...(p.temperatureRange ?? [0.0, 6500.0]))),
677
- offset3D: uniform(new THREE.Vector3().copy((p.offset3D ?? { x: 0, y: 0, z: 0 }))),
678
- wrap3D: uniform(p.wrap3D ?? THREE.ClampToEdgeWrapping, "int"),
679
- boxes: { density: boxUniform(this.indexBox), mask: boxUniform(this.auxBoxes.mask), albedo: boxUniform(this.auxBoxes.albedo), emission: boxUniform(this.auxBoxes.emission) },
680
- // The GPU pyramid rebuilds (on an image change) from here: once per render that samples it.
681
- pyramidLevel: pyr?.gpu ? uniform(pyr.level).onRenderUpdate(() => void this.refreshPyramid()) : uniform(pyr?.level ?? 0),
682
- pyramidLevels: uniform(pyr?.atlas?.levels ?? 0),
683
- pyramidTexels: uniform(new THREE.Vector3(...(pyr?.dimensions ?? [1, 1, 1]))),
684
- pyramidAtlasSize: uniform(new THREE.Vector3(...(pyr?.atlas?.dimensions ?? [1, 1, 1]))),
685
- update: (s, o = {}) => {
686
- if (s !== this)
687
- throw bad("these uniforms belong to another source.");
688
- if (o.densityScale !== undefined)
689
- densityScale = o.densityScale;
690
- if (o.normalizeDensity !== undefined)
691
- normalize = o.normalizeDensity;
692
- densityScaleU.value = vdbDensityScaleOf(this, densityScale, normalize);
693
- if (this.followImage)
694
- applyLayout();
695
- },
696
- dispose: () => {
697
- this.statsListeners.delete(applyStats);
698
- this.layoutListeners.delete(applyLayout);
699
- pyramidTextures.delete(u);
700
- },
701
- };
702
- // G16a: the layout as uniform values (and texture swaps), applied again after every re-read.
703
- const setBox = (b, bx) => {
704
- if (!b || !bx)
705
- return;
706
- b.min.value.set(...bx.min);
707
- b.size.value.set(bx.max[0] - bx.min[0] + 1, bx.max[1] - bx.min[1] + 1, bx.max[2] - bx.min[2] + 1);
708
- };
709
- const applyLayout = () => {
710
- u.gridTexels.value.set(...this.texels);
711
- setBox(u.boxes.density, this.indexBox);
712
- setBox(u.boxes.mask, this.auxBoxes.mask);
713
- setBox(u.boxes.albedo, this.auxBoxes.albedo);
714
- setBox(u.boxes.emission, this.auxBoxes.emission);
715
- levels.value = this.lodLevels;
716
- const p = this.pyramid;
717
- if (!p)
718
- return;
719
- u.pyramidLevel.value = p.level;
720
- u.pyramidLevels.value = p.atlas?.levels ?? 0;
721
- u.pyramidTexels.value.set(...p.dimensions);
722
- u.pyramidAtlasSize.value.set(...(p.atlas?.dimensions ?? [1, 1, 1]));
723
- if (textures) {
724
- textures.map.value = p.map;
725
- textures.mip.value = this.atlasTexture();
726
- }
727
- };
728
- if (this.followImage) {
729
- this.layoutListeners.add(applyLayout);
730
- if (textures)
731
- pyramidTextures.set(u, textures);
732
- }
733
- return u;
734
- }
735
- createNodes(u0, o) {
736
- const u = u0;
737
- if (!u.boxes)
738
- throw bad("createNodes needs this source's uniforms (vdbVolumeUniforms(source)).");
739
- const { grids, ids, lod } = this;
740
- const useMipmaps = o.useMipmaps ?? this.lodLevels > 0;
741
- const gridUv = vdbGridUv(u);
742
- const clamp01 = this.normalize === "clamp01";
743
- // G16a: a following source's LOD range is a uniform (it changes with the layout); otherwise a constant.
744
- const lodMax = this.followImage ? u.mipLevels.density : float(this.lodLevels);
745
- const followTextures = this.followImage ? pyramidTextures.get(u) : undefined;
746
- // uvw → sample index space, clamped to the voxels (his clamp-to-edge).
747
- const samplePos = (box, uvw) => clamp(box.min.add(uvw.mul(box.size)).sub(0.5), box.min, box.min.add(box.size).sub(1.0));
748
- const level0 = this.fastTrilinear || this.cacheAccessor ? (id, p) => this.sampleFn()(uint(id), p) : (id, p) => vdbSample(grids, id, p, { space: "index" });
749
- const densityAt = (uvw, lodIn) => {
750
- const p = samplePos(u.boxes.density, uvw).toVar();
751
- if (!useMipmaps || lod === "none")
752
- return level0(ids.density, p);
753
- const l = clamp(lodIn, 0.0, lodMax).toVar();
754
- if (lod === "node-average")
755
- return this.nodeLodFn()(uint(ids.density), p, l);
756
- const r = float(0.0).toVar();
757
- // coarse-pyramid
758
- const pyr = this.pyramid;
759
- if (this.followImage && !followTextures)
760
- throw bad("createNodes needs this source's uniforms (vdbVolumeUniforms(source)).");
761
- const pyrMap = followTextures ? followTextures.map : texture3D(pyr.map);
762
- const pyrMip = followTextures ? followTextures.mip : pyr.mip ? texture3D(pyr.mip) : null;
763
- const { sampleMipmapped } = vdbMipSampler(u.pyramidTexels, u.pyramidAtlasSize);
764
- const coarse = (rel) => (pyrMip ? sampleMipmapped(pyrMap, pyrMip, u.pyramidLevels, uvw, rel).r : pyrMap.sample(uvw).level(float(0.0)).r);
765
- // K3.2d: one level-0 call site (each inlines the whole tree walk), shared by the two branches below.
766
- const fine = float(0.0).toVar();
767
- If(l.lessThan(u.pyramidLevel), () => {
768
- fine.assign(level0(ids.density, p));
769
- });
770
- If(l.lessThanEqual(0.0), () => {
771
- r.assign(fine);
772
- })
773
- .ElseIf(l.lessThan(u.pyramidLevel), () => {
774
- r.assign(mix(fine, coarse(float(0.0)), l.div(u.pyramidLevel)));
775
- })
776
- .Else(() => {
777
- r.assign(coarse(l.sub(u.pyramidLevel)));
778
- });
779
- return r;
780
- };
781
- // L892
782
- const getLod = (localSize) => max(0.0, log2(localSize.mul(vdbMaxComponent(u.gridTexels))));
783
- // L914–936: extinction per world unit; the mask at local + 0.5 (no offset or wrap), as his.
784
- const sampleExtinction = (localPosition, lodIn) => {
785
- const mask = this.channels.mask ? level0(ids.mask, samplePos(u.boxes.mask, localPosition.add(0.5))) : float(1.0);
786
- const raw = densityAt(gridUv(localPosition), lodIn);
787
- const value = (clamp01 ? clamp(raw, 0.0, 1.0) : raw).mul(mask);
788
- return select(value.greaterThan(u.densityCutoff), value, float(0.0)).mul(u.densityScale).mul(u.extinction).div(u.worldScale);
789
- };
790
- // L960–971 (level 0)
791
- const sampleAlbedo = (localPosition) => {
792
- if (!this.channels.albedo)
793
- return u.baseColor.mul(vec3(1.0));
794
- const p = samplePos(u.boxes.albedo, gridUv(localPosition)).toVar();
795
- const a = ids.albedo;
796
- const rgb = Array.isArray(a) ? vec3(level0(a[0], p), level0(a[1], p), level0(a[2], p)) : vec3(level0(a, p));
797
- return u.baseColor.mul(clamp(rgb, 0.0, 1.0));
798
- };
799
- // L990–1017 (level 0), colour via the caller's hook (V24).
800
- const emissionColor = o.emissionColor ?? (() => vec3(1.0));
801
- const sampleEmission = (localPosition) => {
802
- if (!this.channels.emission)
803
- return vec3(0.0);
804
- const range = u.temperatureRange;
805
- const value = level0(ids.emission, samplePos(u.boxes.emission, gridUv(localPosition)));
806
- const temperature = mix(range.x, range.y, value);
807
- const power = pow(temperature.div(max(range.y, 1.0)), 4.0);
808
- const color = select(temperature.greaterThan(0.0), emissionColor(temperature), vec3(0.0));
809
- return color.mul(power).mul(u.emissiveIntensity);
810
- };
811
- // HDDA empty-space query (R1 §4.3 "HDDA gains"): exact only where the bound covers every voxel a
812
- // sample reads: level 0 (the trilinear 2x2x2 cell block), or a coarse level whose taps reach at
813
- // most 8 voxels past the cell (dilated 3x3x3 block): node averages up to level 3, pyramid bases
814
- // up to level 2. Wrapping or an offset moves samples off the ray's cells: no skipping then.
815
- const skipEmpty = (origin, direction, t0, t1, lodIn) => {
816
- const box = u.boxes.density;
817
- const l = useMipmaps && lod !== "none" ? clamp(lodIn, 0.0, lodMax) : float(0.0);
818
- const dilate = int(0).toVar();
819
- // Cost rule (K3.2 A/B): a walk visits 8³ cells at 8 node lookups each, so it only pays while samples are at
820
- // most one cell apart (the march's lod ≤ 3, i.e. steps ≤ 8 voxels); sparser marches sample everything.
821
- const enabled = u.wrap3D
822
- .equal(int(THREE.ClampToEdgeWrapping))
823
- .and(vdbMaxComponent(u.offset3D.abs()).equal(0.0))
824
- .and(lodIn.lessThanEqual(3.0))
825
- .toVar();
826
- if (useMipmaps && lod === "node-average") {
827
- If(l.greaterThan(0.0), () => {
828
- dilate.assign(1);
829
- If(l.greaterThan(3.0), () => {
830
- enabled.assign(false);
831
- });
832
- });
833
- }
834
- else if (useMipmaps && lod === "coarse-pyramid") {
835
- If(l.greaterThan(0.0), () => {
836
- dilate.assign(1);
837
- If(u.pyramidLevel.greaterThan(2.0).or(l.greaterThan(2.0)), () => {
838
- enabled.assign(false);
839
- });
840
- });
841
- }
842
- const result = vec2(t0, 1e30).toVar();
843
- If(enabled, () => {
844
- const o2 = box.min.sub(0.5).add(origin.add(0.5).mul(box.size));
845
- const d2 = direction.mul(box.size);
846
- // The mask multiplies the density, so with a mask only a zero bound is a safe skip.
847
- const cutoff = this.channels.mask ? float(0.0) : max(u.densityCutoff, 0.0);
848
- result.assign(this.skipEmptyFn()(uint(ids.density), o2, d2, t0, t1, cutoff, dilate.toUint()));
849
- });
850
- return result;
851
- };
852
- return { getLod, sampleExtinction, sampleAlbedo, sampleEmission, ...vdbBoxNodes, skipEmpty };
384
+ return this.#statsReadback;
853
385
  }
854
386
  dispose() {
855
- this.pyramid?.gpu?.destroy();
856
- this.pyramid?.map.dispose();
857
- this.pyramid?.mip?.dispose();
858
- this.emptyAtlas?.dispose();
859
- this.layoutListeners.clear();
860
- this.statsListeners.clear();
861
387
  }
862
388
  }
863
389
  /**
864
390
  * A sparse volume source over pool grids (see the file comment). `grids` must be a `VDBGridNode`
865
391
  * made with profile `'march'` and helpers `['cellBoundTrilinear', 'hddaCellEnd']` (+ `'nodeAverage'`
866
- * for that LOD). The source holds no grid buffer of its own (the pool's), only the pyramid textures
867
- * (and, building on the GPU, the build's scratch buffers).
392
+ * for that LOD). The source holds no GPU object (the pool's grid buffer is the pool's).
393
+ *
394
+ * @param grids A `VDBGridNode` with profile `march` and the helpers the LOD needs.
395
+ * @param ids The pool ids of the density grid and optional channels.
396
+ * @param options LOD, normalization, boxes, pyramid and sampling options.
868
397
  */
869
398
  export function vdbSparseSource(grids, ids, options = {}) {
870
399
  if (!grids || typeof grids !== "object" || !("module" in grids))