@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
@@ -5,7 +5,7 @@
5
5
  * attribute and rewrote the vendored library's buffer global.
6
6
  *
7
7
  * const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });
8
- * const material = new VDBVolumeMaterial(renderer, grids, id, { densityScale: 40 });
8
+ * const material = new VDBVolumeMaterial(renderer, grids, id);
9
9
  * scene.add(new Mesh(vdbProxyGeometry(pool.info(id)), material));
10
10
  * // per frame: pool.update(encoder) (or pool.flush()), then grids.update(), then render.
11
11
  *
@@ -25,7 +25,15 @@
25
25
  * that half voxel, which shows where a grid's min-side voxels are dense);
26
26
  * - lighting as in v1: Henyey-Greenstein phase on a directional sun, an
27
27
  * N-step shadow march toward the sun (a second accessor), a constant
28
- * ambient floor, and a per-fragment budget on the total samples.
28
+ * ambient floor, and a per-fragment budget on the total samples;
29
+ * - the look is sized to the grid by default (EX1a, DIVERGES V291): the
30
+ * extinction is `opticalDepth` across the grid's longest index side at the
31
+ * grid's mean density, and the shadow ray spans `shadowReach` of that side.
32
+ * The side is read from the pool record per fragment (`vdbIndexMin` /
33
+ * `vdbIndexMax`), so it follows a `gridId` change, a `pool.replace` and a
34
+ * coarse-first swap; the mean (`densityReference`) is the root node's
35
+ * average statistic, read from `pool.info(id)` at each render. An explicit
36
+ * `densityScale` (> 0) is extinction per index voxel, as in 0.1.
29
37
  *
30
38
  * Rendered on a proxy box with `side: BackSide` (the camera can be inside);
31
39
  * entry and exit come from the analytic clip, not the rasterized faces. The
@@ -39,10 +47,12 @@
39
47
  *
40
48
  * Units and assumptions:
41
49
  * - The march runs in the grid's **index space**: `stepSize` is in index
42
- * voxels, and `densityScale` integrates per index voxel. Opacity therefore
43
- * does not change with the world size of the grid: `pool.setTransform` (or
44
- * a NanoVDB map) that scales the grid scales its footprint, not how opaque
45
- * it looks.
50
+ * voxels, `opticalDepth` is relative to the index box and `densityScale`
51
+ * integrates per index voxel. Opacity therefore does not change with the
52
+ * world size of the grid: `pool.setTransform` (or a NanoVDB map) that scales
53
+ * the grid scales its footprint, not how opaque it looks.
54
+ * - `densityReference` follows the grid: a sequence that replaces the grid
55
+ * each frame is normalised per frame. Pass a number to pin it.
46
56
  * - The proxy mesh is not tied to the grid: after `material.gridId.value = id`
47
57
  * or `pool.setTransform(id, ...)`, build a new `vdbProxyGeometry(pool.info(id))`
48
58
  * for the mesh, or fragments outside the old box are never rasterized.
@@ -58,6 +68,7 @@ import { getDevice } from "./device.js";
58
68
  import { VDBGridNode } from "./grid-node.js";
59
69
  /** Default hard caps of the compiled loops (the live uniforms clamp under them). */
60
70
  export const VDB_VOLUME_MAX_STEPS_CAP = 1024;
71
+ /** Default compiled cap on `shadowSteps`. */
61
72
  export const VDB_VOLUME_SHADOW_STEPS_CAP = 128;
62
73
  /**
63
74
  * Default cap on the total samples (primary + shadow) one fragment takes.
@@ -67,16 +78,55 @@ export const VDB_VOLUME_SHADOW_STEPS_CAP = 128;
67
78
  * primary loop, and the fragment returns its partial march.
68
79
  */
69
80
  export const VDB_VOLUME_SAMPLE_BUDGET_CAP = 16384;
81
+ /** Default `opticalDepth`: the optical depth across the grid's longest index side at its mean density (EX1a). */
82
+ export const VDB_VOLUME_OPTICAL_DEPTH = 6;
83
+ /** Default `shadowReach`: the shadow ray spans this fraction of the grid's longest index side (EX1a). */
84
+ export const VDB_VOLUME_SHADOW_REACH = 0.3;
85
+ /** Default `sunIntensity` (EX1a): about 4π × 1.25, so the sun reads against the ambient term (a phase is about 1 / 4π). */
86
+ export const VDB_VOLUME_SUN_INTENSITY = 16;
70
87
  const DEFAULTS = {
71
- densityScale: 40,
88
+ densityScale: 0,
89
+ opticalDepth: VDB_VOLUME_OPTICAL_DEPTH,
72
90
  stepSize: 0.75,
73
91
  maxSteps: 512,
74
- sunIntensity: 3,
92
+ sunIntensity: VDB_VOLUME_SUN_INTENSITY,
75
93
  anisotropy: 0.3,
76
94
  shadowSteps: 12,
77
95
  shadowDensity: 1,
96
+ shadowReach: VDB_VOLUME_SHADOW_REACH,
78
97
  ambient: 0.15,
79
98
  };
99
+ /** The smallest `densityReference` the march divides by. */
100
+ export const VDB_VOLUME_MIN_REFERENCE = 1e-20;
101
+ /**
102
+ * The `densityReference` of a grid: its root average statistic when the image has one above 0, else 1 (no
103
+ * statistics, an empty grid, or a grid of non-positive values).
104
+ *
105
+ * @param rootAverage `pool.info(id).rootAverage`.
106
+ */
107
+ export function vdbVolumeDensityReference(rootAverage) {
108
+ return typeof rootAverage === "number" && Number.isFinite(rootAverage) && rootAverage > 0 ? rootAverage : 1;
109
+ }
110
+ /**
111
+ * The CPU twin of the scale lines of the march entry (EX1a): what `VDBVolumeMaterial` derives from the grid's
112
+ * longest index side. `densityScale > 0` is the extinction as given, else
113
+ * `opticalDepth / (longest * densityReference)`;
114
+ * `shadowReach > 0` spreads the shadow steps over that fraction of the side (midpoint samples), else they step
115
+ * by `stepSize` (0.1's march).
116
+ *
117
+ * @param longest The grid's longest index side in voxels (`max(indexBBox.max - indexBBox.min) + 1`).
118
+ * @param u The material's uniform values.
119
+ */
120
+ export function vdbVolumeMarchScales(longest, u) {
121
+ const side = Math.max(longest, 1);
122
+ const extinction = u.densityScale > 0 ? u.densityScale : u.opticalDepth / (side * Math.max(u.densityReference ?? 1, VDB_VOLUME_MIN_REFERENCE));
123
+ const steps = Math.trunc(Math.min(Math.max(u.shadowSteps, 0), u.shadowStepsCap ?? VDB_VOLUME_SHADOW_STEPS_CAP));
124
+ if (u.shadowReach > 0) {
125
+ const shadowStep = (u.shadowReach * side) / Math.max(steps, 1);
126
+ return { extinction, shadowStep, shadowStart: shadowStep * 0.5 };
127
+ }
128
+ return { extinction, shadowStep: u.stepSize, shadowStart: u.stepSize };
129
+ }
80
130
  /** Entry name of the march `wgslFn`. */
81
131
  const ENTRY = "vdbThreeVolumeMarch";
82
132
  /**
@@ -105,11 +155,14 @@ function marchWgsl(maxStepsCap, shadowStepsCap, sampleBudgetCap) {
105
155
  sun_color: vec3f,
106
156
  sun_intensity: f32,
107
157
  density_scale: f32,
158
+ optical_depth: f32,
159
+ density_reference: f32,
108
160
  step_size: f32,
109
161
  max_steps: f32,
110
162
  g: f32,
111
163
  shadow_steps: f32,
112
164
  shadow_density: f32,
165
+ shadow_reach: f32,
113
166
  ambient: f32,
114
167
  jitter: f32,
115
168
  pix: vec2f
@@ -154,6 +207,22 @@ function marchWgsl(maxStepsCap, shadowStepsCap, sampleBudgetCap) {
154
207
  var color = vec3f(0.0);
155
208
  let max_i = i32(clamp(max_steps, 1.0, ${maxStepsCap}.0));
156
209
  let shadow_n = i32(clamp(shadow_steps, 0.0, ${shadowStepsCap}.0));
210
+
211
+ // What the look takes from the grid's size (CPU twin: vdbVolumeMarchScales). The extinction per index voxel
212
+ // is the explicit scale as given, else the optical depth across the longest index side at the reference
213
+ // density; the shadow ray steps by the march step, or spans the reach fraction of the side (midpoint samples).
214
+ let dims = vec3f(vdbIndexMax(grid_id) - vdbIndexMin(grid_id) + vec3i(1));
215
+ let longest = max(max(dims.x, max(dims.y, dims.z)), 1.0);
216
+ var extinction = density_scale;
217
+ if !(extinction > 0.0) {
218
+ extinction = optical_depth / (longest * max(density_reference, 1.0e-20));
219
+ }
220
+ var shadow_step = step_size;
221
+ var shadow_start = step_size;
222
+ if shadow_reach > 0.0 {
223
+ shadow_step = shadow_reach * longest / f32(max(shadow_n, 1));
224
+ shadow_start = shadow_step * 0.5;
225
+ }
157
226
  let budget = ${sampleBudgetCap};
158
227
  var samples = 0;
159
228
 
@@ -162,20 +231,20 @@ function marchWgsl(maxStepsCap, shadowStepsCap, sampleBudgetCap) {
162
231
  break;
163
232
  }
164
233
  let pos = o_idx + d_idx * t;
165
- let density = max(vdbSample(&acc, pos), 0.0) * density_scale;
234
+ let density = max(vdbSample(&acc, pos), 0.0) * extinction;
166
235
  samples++;
167
236
  if density > 0.0 {
168
237
  let a = 1.0 - exp(-density * step_size);
169
238
  var tau = 0.0;
170
- var st = step_size;
239
+ var st = shadow_start;
171
240
  for (var s = 0; s < shadow_n; s++) {
172
241
  if samples >= budget {
173
242
  break;
174
243
  }
175
- let sd = max(vdbSample(&sacc, pos + sun_idx * st), 0.0) * density_scale * shadow_density;
244
+ let sd = max(vdbSample(&sacc, pos + sun_idx * st), 0.0) * extinction * shadow_density;
176
245
  samples++;
177
- tau += sd * step_size;
178
- st += step_size;
246
+ tau += sd * shadow_step;
247
+ st += shadow_step;
179
248
  }
180
249
  let lit = sun_color * (sun_intensity * exp(-tau) * phase) + vec3f(ambient);
181
250
  color += transmittance * a * lit;
@@ -202,11 +271,17 @@ function positiveInt(name, value, fallback) {
202
271
  * render.
203
272
  *
204
273
  * const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });
205
- * const material = new VDBVolumeMaterial(renderer, grids, id, { densityScale: 40 });
274
+ * const material = new VDBVolumeMaterial(renderer, grids, id);
206
275
  * const mesh = new Mesh(vdbProxyGeometry(pool.info(id)), material);
207
276
  *
208
- * - `stepSize` is in index voxels and `densityScale` integrates per index
209
- * voxel, so opacity ignores the grid's world scale (`setTransform` scaling
277
+ * - The defaults are sized to the grid: `opticalDepth` (6) is the optical
278
+ * depth across the grid's longest index side at its mean density
279
+ * (`densityReference`), and the shadow ray spans `shadowReach` (0.3) of
280
+ * that side, so a grid of any resolution and value range draws as a lit
281
+ * volume. `densityScale` > 0 replaces them with an extinction per index
282
+ * voxel; 0.1's look is `{ densityScale: 40, sunIntensity: 3, shadowReach: 0 }`.
283
+ * - `stepSize` is in index voxels and the density integrates in index
284
+ * space, so opacity ignores the grid's world scale (`setTransform` scaling
210
285
  * changes the size on screen, not the opacity).
211
286
  * - After `gridId.value = otherId` or `pool.setTransform(id, ...)`, give the
212
287
  * mesh a new `vdbProxyGeometry(pool.info(id))`.
@@ -217,6 +292,7 @@ function positiveInt(name, value, fallback) {
217
292
  * makes {@link gridId} a `uint` uniform; a node is kept as given.
218
293
  */
219
294
  export class VDBVolumeMaterial extends NodeMaterial {
295
+ /** Type flag: true. */
220
296
  isVDBVolumeMaterial = true;
221
297
  /** The pool node this material reads (its `module` is the march's include). */
222
298
  grids;
@@ -228,8 +304,29 @@ export class VDBVolumeMaterial extends NodeMaterial {
228
304
  gridId;
229
305
  /** The entry `fn` text (for inspection and tests). */
230
306
  entrySource;
231
- /** Extinction per index voxel at density 1 (opacity of a step: `1 - exp(-density * densityScale * stepSize)`). Default 40. */
307
+ /**
308
+ * Extinction per index voxel at density 1 (opacity of a step: `1 - exp(-density * densityScale * stepSize)`).
309
+ * Default 0: the extinction comes from `opticalDepth` instead. To hide the volume, hide its mesh.
310
+ */
232
311
  densityScale;
312
+ /**
313
+ * Optical depth across the grid's longest index side at the density `densityReference`, used while
314
+ * `densityScale` is 0. It follows the grid (a `gridId` change, a coarse-first swap). Default 6.
315
+ */
316
+ opticalDepth;
317
+ /**
318
+ * The density `opticalDepth` refers to. While {@link densityReferenceAuto} is true it is set at each render
319
+ * to the mean of the grid's active values (`pool.info(id).rootAverage`; 1 without statistics).
320
+ */
321
+ densityReference;
322
+ /**
323
+ * True (the default, unless the constructor got a `densityReference`) while the material reads
324
+ * `densityReference` from the pool at each render. It needs a numeric grid id and a pool with `info(id)`
325
+ * (a `VDBGridPool`); otherwise the uniform keeps its value.
326
+ */
327
+ densityReferenceAuto;
328
+ /** The pool revision and grid id `densityReference` was last read for. */
329
+ #referenceKey = null;
233
330
  /** March step in index voxels (live; the lattice re-anchors per fragment). Default 0.75. */
234
331
  stepSize;
235
332
  /** Primary march steps, clamped to `[1, maxStepsCap]`. Default 512. */
@@ -238,7 +335,7 @@ export class VDBVolumeMaterial extends NodeMaterial {
238
335
  sunDirection;
239
336
  /** Sun colour (linear). Default (1, 0.95, 0.9). */
240
337
  sunColor;
241
- /** Sun intensity. Default 3. */
338
+ /** Sun intensity; the sun term is `sunColor * sunIntensity * phase * shadow` (phase ≈ 1 / 4π). Default 16. */
242
339
  sunIntensity;
243
340
  /** Henyey-Greenstein anisotropy g in (-1, 1). Default 0.3. */
244
341
  anisotropy;
@@ -246,11 +343,19 @@ export class VDBVolumeMaterial extends NodeMaterial {
246
343
  shadowSteps;
247
344
  /** Density multiplier along the shadow ray only. Default 1. */
248
345
  shadowDensity;
346
+ /**
347
+ * Length of the shadow ray as a fraction of the grid's longest index side. Default 0.3. 0 steps the shadow
348
+ * ray by `stepSize` (`shadowSteps * stepSize` voxels, 0.1's march).
349
+ */
350
+ shadowReach;
249
351
  /** Constant ambient term added to the sun light. Default 0.15. */
250
352
  ambient;
251
353
  /** 1 = per-pixel jitter of the first sample on, 0 = off. */
252
354
  jitter;
253
355
  /**
356
+ *
357
+ * @param params Initial uniform values and compile-time caps ({@link VDBVolumeMaterialParameters}).
358
+ *
254
359
  * @param renderer The initialized `WebGPURenderer` the pool and `grids` live on.
255
360
  * @param grids A `VDBGridNode` made on this same renderer, with profile
256
361
  * `sample` or `march` and `helpers: ['rayClipSupport']`. Share one per
@@ -290,6 +395,13 @@ export class VDBVolumeMaterial extends NodeMaterial {
290
395
  this.gridId = (typeof gridId === "number" ? uniform(gridId, "uint") : gridId);
291
396
  this.entrySource = marchWgsl(maxStepsCap, shadowStepsCap, sampleBudgetCap);
292
397
  this.densityScale = uniform(params.densityScale ?? DEFAULTS.densityScale);
398
+ this.opticalDepth = uniform(params.opticalDepth ?? DEFAULTS.opticalDepth);
399
+ this.densityReferenceAuto = params.densityReference === undefined;
400
+ // A render-updated uniform: the callback's return value is assigned (undefined keeps the value).
401
+ this.densityReference = uniform(params.densityReference ?? 1).onRenderUpdate(() => this.#readDensityReference());
402
+ const reference = this.#readDensityReference();
403
+ if (reference !== undefined)
404
+ this.densityReference.value = reference;
293
405
  this.stepSize = uniform(params.stepSize ?? DEFAULTS.stepSize);
294
406
  this.maxSteps = uniform(params.maxSteps ?? DEFAULTS.maxSteps);
295
407
  this.sunDirection = uniform((params.sunDirection ?? new THREE.Vector3(0.5, 0.8, 0.3)).clone().normalize());
@@ -298,6 +410,7 @@ export class VDBVolumeMaterial extends NodeMaterial {
298
410
  this.anisotropy = uniform(params.anisotropy ?? DEFAULTS.anisotropy);
299
411
  this.shadowSteps = uniform(params.shadowSteps ?? DEFAULTS.shadowSteps);
300
412
  this.shadowDensity = uniform(params.shadowDensity ?? DEFAULTS.shadowDensity);
413
+ this.shadowReach = uniform(params.shadowReach ?? DEFAULTS.shadowReach);
301
414
  this.ambient = uniform(params.ambient ?? DEFAULTS.ambient);
302
415
  this.jitter = uniform(params.jitter === false ? 0 : 1);
303
416
  const march = wgslFn(this.entrySource, [grids.module, code(VOLUME_HELPERS_WGSL)]);
@@ -309,11 +422,14 @@ export class VDBVolumeMaterial extends NodeMaterial {
309
422
  sun_color: this.sunColor,
310
423
  sun_intensity: this.sunIntensity,
311
424
  density_scale: this.densityScale,
425
+ optical_depth: this.opticalDepth,
426
+ density_reference: this.densityReference,
312
427
  step_size: this.stepSize,
313
428
  max_steps: this.maxSteps,
314
429
  g: this.anisotropy,
315
430
  shadow_steps: this.shadowSteps,
316
431
  shadow_density: this.shadowDensity,
432
+ shadow_reach: this.shadowReach,
317
433
  ambient: this.ambient,
318
434
  jitter: this.jitter,
319
435
  pix: screenCoordinate,
@@ -325,6 +441,30 @@ export class VDBVolumeMaterial extends NodeMaterial {
325
441
  this.premultipliedAlpha = true;
326
442
  this.toneMapped = false;
327
443
  }
444
+ /**
445
+ * The grid's `densityReference` when it must be (re)read: auto mode, a numeric id, a pool with `info`, and a
446
+ * pool revision or id other than the last read's. `undefined` keeps the uniform's value (a dead id too).
447
+ */
448
+ #readDensityReference() {
449
+ if (!this.densityReferenceAuto)
450
+ return undefined;
451
+ const id = this.gridId.value;
452
+ const pool = this.grids.pool;
453
+ if (typeof id !== "number" || typeof pool.info !== "function")
454
+ return undefined;
455
+ const key = this.#referenceKey;
456
+ if (key && pool.revision !== undefined && key[0] === pool.revision && key[1] === id)
457
+ return undefined;
458
+ let average;
459
+ try {
460
+ average = pool.info(id).rootAverage;
461
+ }
462
+ catch {
463
+ return undefined; // the id is not in the pool (yet)
464
+ }
465
+ this.#referenceKey = [pool.revision, id];
466
+ return vdbVolumeDensityReference(average);
467
+ }
328
468
  }
329
469
  /**
330
470
  * A world-space box for a grid's proxy mesh (add it with an identity
@@ -333,6 +473,9 @@ export class VDBVolumeMaterial extends NodeMaterial {
333
473
  * `pool.info(id).worldBBox`, the box v1 used; `pad: 1` also covers the
334
474
  * min-side half voxel of the trilinear support that `VDBVolumeMaterial`
335
475
  * marches (rays that cross only that shell are otherwise not rasterized).
476
+ *
477
+ * @param info The grid's `pool.info(id)`.
478
+ * @param options `pad`: voxels added on every side of the index box (default 0).
336
479
  */
337
480
  export function vdbProxyGeometry(info, options = {}) {
338
481
  const pad = options.pad ?? 0;
@@ -1 +1 @@
1
- {"version":3,"file":"material.js","sourceRoot":"","sources":["../../src/three/material.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnG,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAA6B,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,WAAW,EAAmB,MAAM,gBAAgB,CAAC;AAE9D,oFAAoF;AACpF,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAC7C,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAC/C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,CAA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AAa,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IACD,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/D,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACjD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * `VDBVolumeMaterial`: the fragment raymarch of one grid in a `VDBGridPool`,\n * through a `VDBGridNode` (task K2.3, docs/archive/handoffs/K2.md). It replaces v1's\n * `NanoVDBVolumeMaterial`, which bound one grid image as its own storage\n * attribute and rewrote the vendored library's buffer global.\n *\n * const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });\n * const material = new VDBVolumeMaterial(renderer, grids, id, { densityScale: 40 });\n * scene.add(new Mesh(vdbProxyGeometry(pool.info(id)), material));\n * // per frame: pool.update(encoder) (or pool.flush()), then grids.update(), then render.\n *\n * The march is one entry `wgslFn` over the public `vdb*` WGSL API, with\n * `grids.module` as its include (the module carries the pool binding):\n * - the world ray goes into the grid's index space through the record's\n * affine (`vdbWorldToIndex`/`vdbWorldToIndexDir`), so `pool.setTransform`\n * instances render where they are;\n * - it is clipped to the sampler's support box (`vdbRayClipSupport`,\n * `[min - 1, max + 1]` for trilinear), not the voxel-cell box, so the\n * min-side half voxel the trilinear taps reach is marched too;\n * - fixed-step density accumulation with `vdbSample` (the node's sampler),\n * premultiplied front-to-back compositing, early-out at low transmittance.\n * The step lattice is anchored at the voxel-box entry (`vdbRayClip`, where\n * v1 started) and extended back over the support shell, so samples inside\n * the box sit where v1's did; only the shell samples are new (v1 skipped\n * that half voxel, which shows where a grid's min-side voxels are dense);\n * - lighting as in v1: Henyey-Greenstein phase on a directional sun, an\n * N-step shadow march toward the sun (a second accessor), a constant\n * ambient floor, and a per-fragment budget on the total samples.\n *\n * Rendered on a proxy box with `side: BackSide` (the camera can be inside);\n * entry and exit come from the analytic clip, not the rasterized faces. The\n * material is `transparent`, `depthWrite: false`, premultiplied alpha. Scene\n * depth compositing is not done (v1 neither).\n *\n * Every tunable is a live TSL uniform (`material.densityScale.value = ...`).\n * The grid is a `uint` uniform too when the constructor got a number\n * (`material.gridId.value = otherId`), so one material can show any grid of\n * the types its `VDBGridNode` compiles without a rebuild.\n *\n * Units and assumptions:\n * - The march runs in the grid's **index space**: `stepSize` is in index\n * voxels, and `densityScale` integrates per index voxel. Opacity therefore\n * does not change with the world size of the grid: `pool.setTransform` (or\n * a NanoVDB map) that scales the grid scales its footprint, not how opaque\n * it looks.\n * - The proxy mesh is not tied to the grid: after `material.gridId.value = id`\n * or `pool.setTransform(id, ...)`, build a new `vdbProxyGeometry(pool.info(id))`\n * for the mesh, or fragments outside the old box are never rasterized.\n * - The view ray is `positionWorld - cameraPosition`: a perspective camera.\n * An orthographic camera's rays are parallel and do not start at\n * `cameraPosition`, so it renders wrongly.\n */\n\nimport * as THREE from \"three\";\nimport { NodeMaterial } from \"three/webgpu\";\nimport { cameraPosition, code, positionWorld, screenCoordinate, uniform, wgslFn } from \"three/tsl\";\nimport { VDBError } from \"../core/errors.js\";\nimport { getDevice, type VDBThreeRendererLike } from \"./device.js\";\nimport { VDBGridNode, type VDBTslNode } from \"./grid-node.js\";\n\n/** Default hard caps of the compiled loops (the live uniforms clamp under them). */\nexport const VDB_VOLUME_MAX_STEPS_CAP = 1024;\nexport const VDB_VOLUME_SHADOW_STEPS_CAP = 128;\n/**\n * Default cap on the total samples (primary + shadow) one fragment takes.\n * `maxSteps` and `shadowSteps` are independent live uniforms, so their product\n * can reach `maxStepsCap * shadowStepsCap` (~131k at the defaults), a driver\n * timeout risk. Once the budget is spent the shadow loop stops first, then the\n * primary loop, and the fragment returns its partial march.\n */\nexport const VDB_VOLUME_SAMPLE_BUDGET_CAP = 16384;\n\n/** Parameters of {@link VDBVolumeMaterial}: initial uniform values and compile-time caps. */\nexport interface VDBVolumeMaterialParameters {\n densityScale?: number;\n /** March step in index voxels. */\n stepSize?: number;\n maxSteps?: number;\n sunDirection?: THREE.Vector3;\n sunColor?: THREE.Color;\n sunIntensity?: number;\n /** Henyey-Greenstein anisotropy g in (-1, 1). */\n anisotropy?: number;\n shadowSteps?: number;\n /** Density multiplier along the shadow ray only. */\n shadowDensity?: number;\n ambient?: number;\n /** Per-pixel jitter of the first sample. Default true. */\n jitter?: boolean;\n /** Hard cap on the primary loop. Default {@link VDB_VOLUME_MAX_STEPS_CAP}. */\n maxStepsCap?: number;\n /** Hard cap on the shadow loop. Default {@link VDB_VOLUME_SHADOW_STEPS_CAP}. */\n shadowStepsCap?: number;\n /** Hard cap on the total samples per fragment. Default {@link VDB_VOLUME_SAMPLE_BUDGET_CAP}. */\n sampleBudgetCap?: number;\n}\n\nconst DEFAULTS = {\n densityScale: 40,\n stepSize: 0.75,\n maxSteps: 512,\n sunIntensity: 3,\n anisotropy: 0.3,\n shadowSteps: 12,\n shadowDensity: 1,\n ambient: 0.15,\n} as const;\n\n/** A live TSL uniform with its value typed (three types `uniform()`'s value as unknown). */\ntype ScalarUniform = ReturnType<typeof uniform> & { value: number };\ntype Vec3Uniform = ReturnType<typeof uniform> & { value: THREE.Vector3 };\ntype ColorUniform = ReturnType<typeof uniform> & { value: THREE.Color };\n/** The `uint` uniform `VDBVolumeMaterial` makes for a numeric grid id (`material.gridId.value = otherId`). */\nexport type VDBUintUniform = ReturnType<typeof uniform> & { value: number };\n\n/** Entry name of the march `wgslFn`. */\nconst ENTRY = \"vdbThreeVolumeMarch\";\n\n/**\n * Module-scope helpers of the march, a second include next to `grids.module`\n * (`wgslFn` parses only its first `fn`, so the entry can't hold them).\n */\nconst VOLUME_HELPERS_WGSL = /* wgsl */ `\nfn vdbThreeHgPhase(cos_theta: f32, g: f32) -> f32 {\n let gg = g * g;\n let denom = 1.0 + gg - 2.0 * g * cos_theta;\n return (1.0 - gg) / (12.566370614359172 * pow(max(denom, 1.0e-4), 1.5));\n}\nfn vdbThreeHash12(p: vec2f) -> f32 {\n var p3 = fract(vec3f(p.x, p.y, p.x) * 0.1031);\n p3 = p3 + dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n}\n`;\n\n/** The march entry, the one `fn` of its `wgslFn`. Caps are compiled in. */\nfunction marchWgsl(maxStepsCap: number, shadowStepsCap: number, sampleBudgetCap: number): string {\n return /* wgsl */ `fn ${ENTRY}(\n grid_id: u32,\n ray_origin_w: vec3f,\n ray_dir_w: vec3f,\n sun_dir_w: vec3f,\n sun_color: vec3f,\n sun_intensity: f32,\n density_scale: f32,\n step_size: f32,\n max_steps: f32,\n g: f32,\n shadow_steps: f32,\n shadow_density: f32,\n ambient: f32,\n jitter: f32,\n pix: vec2f\n) -> vec4f {\n // World -> index through the pool record (instance transform included).\n let o_idx = vdbWorldToIndex(grid_id, ray_origin_w);\n let d_idx = normalize(vdbWorldToIndexDir(grid_id, ray_dir_w));\n let sun_idx = normalize(vdbWorldToIndexDir(grid_id, sun_dir_w));\n\n // Clip to the trilinear support box; a dead id misses.\n var span = vec2f(0.0, 1.0e30);\n if !vdbRayClipSupport(grid_id, o_idx, d_idx, &span) {\n return vec4f(0.0);\n }\n // t0 >= 0: no sample behind the eye (camera inside the support box).\n let t0 = max(span.x, 0.0);\n let t1 = span.y;\n\n var acc = vdbAccessorInit(grid_id);\n var sacc = vdbAccessorInit(grid_id);\n\n // The phase uses the world-space view/sun angle.\n let phase = vdbThreeHgPhase(dot(normalize(ray_dir_w), normalize(sun_dir_w)), g);\n\n // The step lattice is anchored where the ray enters the voxel box\n // (vdbRayClip, v1's entry) and extended back to the support entry, so the\n // samples inside the box sit exactly where v1's did.\n var t = t0;\n var cell = vec2f(0.0, 1.0e30);\n if vdbRayClip(grid_id, o_idx, d_idx, &cell) {\n let anchor = max(cell.x, 0.0);\n t = anchor - ceil((anchor - t0) / step_size) * step_size;\n }\n t += step_size * jitter * vdbThreeHash12(pix);\n // The lattice can start before t0 (the anchor is stepped back in whole\n // steps, plus jitter). Skip those steps on the lattice: they are behind the\n // eye (camera in the support shell) or outside the support box.\n if t < t0 {\n t += ceil((t0 - t) / step_size) * step_size;\n }\n var transmittance = 1.0;\n var color = vec3f(0.0);\n let max_i = i32(clamp(max_steps, 1.0, ${maxStepsCap}.0));\n let shadow_n = i32(clamp(shadow_steps, 0.0, ${shadowStepsCap}.0));\n let budget = ${sampleBudgetCap};\n var samples = 0;\n\n for (var i = 0; i < max_i; i++) {\n if t > t1 || transmittance < 0.003 || samples >= budget {\n break;\n }\n let pos = o_idx + d_idx * t;\n let density = max(vdbSample(&acc, pos), 0.0) * density_scale;\n samples++;\n if density > 0.0 {\n let a = 1.0 - exp(-density * step_size);\n var tau = 0.0;\n var st = step_size;\n for (var s = 0; s < shadow_n; s++) {\n if samples >= budget {\n break;\n }\n let sd = max(vdbSample(&sacc, pos + sun_idx * st), 0.0) * density_scale * shadow_density;\n samples++;\n tau += sd * step_size;\n st += step_size;\n }\n let lit = sun_color * (sun_intensity * exp(-tau) * phase) + vec3f(ambient);\n color += transmittance * a * lit;\n transmittance *= 1.0 - a;\n }\n t += step_size;\n }\n return vec4f(color, 1.0 - transmittance);\n}`;\n}\n\nfunction bad(message: string): VDBError {\n return new VDBError(\"VDB_BAD_OPTION\", `VDBVolumeMaterial: ${message}`);\n}\n\nfunction positiveInt(name: string, value: number | undefined, fallback: number): number {\n const v = value ?? fallback;\n if (!Number.isInteger(v) || v < 1) throw bad(`${name} must be an integer >= 1, got ${JSON.stringify(value)}.`);\n return v;\n}\n\n/**\n * A fragment raymarch of one grid of a `VDBGridPool` (see the file comment for\n * the march). Put it on a `vdbProxyGeometry(pool.info(id))` mesh; each frame\n * run `pool.update(encoder)` (or `pool.flush()`), then `grids.update()`, then\n * render.\n *\n * const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });\n * const material = new VDBVolumeMaterial(renderer, grids, id, { densityScale: 40 });\n * const mesh = new Mesh(vdbProxyGeometry(pool.info(id)), material);\n *\n * - `stepSize` is in index voxels and `densityScale` integrates per index\n * voxel, so opacity ignores the grid's world scale (`setTransform` scaling\n * changes the size on screen, not the opacity).\n * - After `gridId.value = otherId` or `pool.setTransform(id, ...)`, give the\n * mesh a new `vdbProxyGeometry(pool.info(id))`.\n * - Perspective cameras only (the ray starts at `cameraPosition`).\n * - The material must be rendered by the renderer `grids` was made with.\n *\n * @typeParam TGridId What the constructor got as the id: a number (default)\n * makes {@link gridId} a `uint` uniform; a node is kept as given.\n */\nexport class VDBVolumeMaterial<TGridId extends number | VDBTslNode = number> extends NodeMaterial {\n readonly isVDBVolumeMaterial = true;\n\n /** The pool node this material reads (its `module` is the march's include). */\n readonly grids: VDBGridNode;\n /**\n * The grid id: a `uint` uniform when the constructor got a number\n * (`material.gridId.value = otherId`; then give the mesh a new\n * `vdbProxyGeometry`), else the caller's node.\n */\n readonly gridId: TGridId extends number ? VDBUintUniform : VDBTslNode;\n /** The entry `fn` text (for inspection and tests). */\n readonly entrySource: string;\n\n /** Extinction per index voxel at density 1 (opacity of a step: `1 - exp(-density * densityScale * stepSize)`). Default 40. */\n readonly densityScale: ScalarUniform;\n /** March step in index voxels (live; the lattice re-anchors per fragment). Default 0.75. */\n readonly stepSize: ScalarUniform;\n /** Primary march steps, clamped to `[1, maxStepsCap]`. Default 512. */\n readonly maxSteps: ScalarUniform;\n /** Direction toward the sun, world space (normalized at construction; keep it normalized). */\n readonly sunDirection: Vec3Uniform;\n /** Sun colour (linear). Default (1, 0.95, 0.9). */\n readonly sunColor: ColorUniform;\n /** Sun intensity. Default 3. */\n readonly sunIntensity: ScalarUniform;\n /** Henyey-Greenstein anisotropy g in (-1, 1). Default 0.3. */\n readonly anisotropy: ScalarUniform;\n /** Shadow-ray steps toward the sun per lit sample, clamped to `[0, shadowStepsCap]`. Default 12. */\n readonly shadowSteps: ScalarUniform;\n /** Density multiplier along the shadow ray only. Default 1. */\n readonly shadowDensity: ScalarUniform;\n /** Constant ambient term added to the sun light. Default 0.15. */\n readonly ambient: ScalarUniform;\n /** 1 = per-pixel jitter of the first sample on, 0 = off. */\n readonly jitter: ScalarUniform;\n\n /**\n * @param renderer The initialized `WebGPURenderer` the pool and `grids` live on.\n * @param grids A `VDBGridNode` made on this same renderer, with profile\n * `sample` or `march` and `helpers: ['rayClipSupport']`. Share one per\n * pool: one module per shader.\n * @param gridId The grid's pool id (a number, made a `uint` uniform) or a `uint` node.\n * @throws VDBError `VDB_BAD_OPTION` for a `grids` this material can't use\n * (another renderer, profile, helpers), a bad id or cap;\n * `VDB_UNSUPPORTED_DEVICE` for an uninitialized renderer.\n */\n constructor(renderer: VDBThreeRendererLike, grids: VDBGridNode, gridId: TGridId, params: VDBVolumeMaterialParameters = {}) {\n super();\n if (!(grids instanceof VDBGridNode)) throw bad(\"grids must be a VDBGridNode.\");\n getDevice(renderer); // VDB_UNSUPPORTED_DEVICE before init\n if (grids.renderer !== renderer) {\n throw bad(\n \"grids was made for another renderer. A VDBGridNode binds the pool through the renderer it was made with \" +\n \"(another renderer, even on the same GPUDevice, would read 0): create one VDBGridNode per renderer \" +\n \"(new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] })).\",\n );\n }\n if (grids.options.profile === \"read\") {\n throw bad(\"grids needs profile 'sample' or 'march' (vdbSample); this VDBGridNode was made with profile 'read'.\");\n }\n if (!grids.options.helpers?.includes(\"rayClipSupport\")) {\n throw bad(\"grids must compile the 'rayClipSupport' helper: new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] }).\");\n }\n if (typeof gridId === \"number\") {\n if (!Number.isInteger(gridId) || gridId < 0) throw bad(`gridId must be a non-negative integer, got ${gridId}.`);\n } else if (gridId === null || typeof gridId !== \"object\") {\n throw bad(\"gridId must be a number or a uint TSL node.\");\n }\n const maxStepsCap = positiveInt(\"maxStepsCap\", params.maxStepsCap, VDB_VOLUME_MAX_STEPS_CAP);\n const shadowStepsCap = positiveInt(\"shadowStepsCap\", params.shadowStepsCap, VDB_VOLUME_SHADOW_STEPS_CAP);\n const sampleBudgetCap = positiveInt(\"sampleBudgetCap\", params.sampleBudgetCap, VDB_VOLUME_SAMPLE_BUDGET_CAP);\n\n this.grids = grids;\n this.gridId = (typeof gridId === \"number\" ? uniform(gridId, \"uint\") : gridId) as this[\"gridId\"];\n this.entrySource = marchWgsl(maxStepsCap, shadowStepsCap, sampleBudgetCap);\n\n this.densityScale = uniform(params.densityScale ?? DEFAULTS.densityScale) as ScalarUniform;\n this.stepSize = uniform(params.stepSize ?? DEFAULTS.stepSize) as ScalarUniform;\n this.maxSteps = uniform(params.maxSteps ?? DEFAULTS.maxSteps) as ScalarUniform;\n this.sunDirection = uniform((params.sunDirection ?? new THREE.Vector3(0.5, 0.8, 0.3)).clone().normalize()) as Vec3Uniform;\n this.sunColor = uniform(params.sunColor ?? new THREE.Color(1, 0.95, 0.9)) as ColorUniform;\n this.sunIntensity = uniform(params.sunIntensity ?? DEFAULTS.sunIntensity) as ScalarUniform;\n this.anisotropy = uniform(params.anisotropy ?? DEFAULTS.anisotropy) as ScalarUniform;\n this.shadowSteps = uniform(params.shadowSteps ?? DEFAULTS.shadowSteps) as ScalarUniform;\n this.shadowDensity = uniform(params.shadowDensity ?? DEFAULTS.shadowDensity) as ScalarUniform;\n this.ambient = uniform(params.ambient ?? DEFAULTS.ambient) as ScalarUniform;\n this.jitter = uniform(params.jitter === false ? 0 : 1) as ScalarUniform;\n\n const march = wgslFn(this.entrySource, [grids.module, code(VOLUME_HELPERS_WGSL)] as never);\n this.fragmentNode = march({\n grid_id: this.gridId,\n ray_origin_w: cameraPosition,\n ray_dir_w: positionWorld.sub(cameraPosition).normalize(),\n sun_dir_w: this.sunDirection,\n sun_color: this.sunColor,\n sun_intensity: this.sunIntensity,\n density_scale: this.densityScale,\n step_size: this.stepSize,\n max_steps: this.maxSteps,\n g: this.anisotropy,\n shadow_steps: this.shadowSteps,\n shadow_density: this.shadowDensity,\n ambient: this.ambient,\n jitter: this.jitter,\n pix: screenCoordinate,\n });\n\n this.transparent = true;\n this.depthWrite = false;\n this.depthTest = true;\n this.side = THREE.BackSide;\n this.premultipliedAlpha = true;\n this.toneMapped = false;\n }\n}\n\n/** What {@link vdbProxyGeometry} reads from `pool.info(id)`. */\nexport interface VDBProxyGridInfo {\n readonly indexBBox: { readonly min: readonly number[]; readonly max: readonly number[] };\n /** 3x4 row-major index-to-world affine (`pool.info(id).indexToWorld`). */\n readonly indexToWorld: ArrayLike<number>;\n}\n\n/**\n * A world-space box for a grid's proxy mesh (add it with an identity\n * transform): the AABB of the index box's voxels `[min - pad, max + 1 + pad]`\n * through the grid's index-to-world affine. `pad: 0` (default) is\n * `pool.info(id).worldBBox`, the box v1 used; `pad: 1` also covers the\n * min-side half voxel of the trilinear support that `VDBVolumeMaterial`\n * marches (rays that cross only that shell are otherwise not rasterized).\n */\nexport function vdbProxyGeometry(info: VDBProxyGridInfo, options: { pad?: number } = {}): THREE.BoxGeometry {\n const pad = options.pad ?? 0;\n if (!Number.isFinite(pad) || pad < 0) throw bad(`vdbProxyGeometry pad must be a finite number >= 0, got ${pad}.`);\n const m = info.indexToWorld;\n const lo = [0, 1, 2].map((a) => info.indexBBox.min[a]! - pad);\n const hi = [0, 1, 2].map((a) => info.indexBBox.max[a]! + 1 + pad);\n const box = new THREE.Box3();\n const p = new THREE.Vector3();\n for (let k = 0; k < 8; k++) {\n const x = k & 1 ? hi[0]! : lo[0]!;\n const y = k & 2 ? hi[1]! : lo[1]!;\n const z = k & 4 ? hi[2]! : lo[2]!;\n p.set(\n m[0]! * x + m[1]! * y + m[2]! * z + m[3]!,\n m[4]! * x + m[5]! * y + m[6]! * z + m[7]!,\n m[8]! * x + m[9]! * y + m[10]! * z + m[11]!,\n );\n box.expandByPoint(p);\n }\n const size = box.getSize(new THREE.Vector3());\n const center = box.getCenter(new THREE.Vector3());\n const geometry = new THREE.BoxGeometry(size.x, size.y, size.z);\n geometry.translate(center.x, center.y, center.z);\n return geometry;\n}\n"]}
1
+ {"version":3,"file":"material.js","sourceRoot":"","sources":["../../src/three/material.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnG,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAA6B,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,WAAW,EAAmB,MAAM,gBAAgB,CAAC;AAE9D,oFAAoF;AACpF,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAC7C,6CAA6C;AAC7C,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAC/C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,CAAC;AA4DlD,iHAAiH;AACjH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAC1C,yGAAyG;AACzG,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAC3C,2HAA2H;AAC3H,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAE3C,MAAM,QAAQ,GAAG;IACf,YAAY,EAAE,CAAC;IACf,YAAY,EAAE,wBAAwB;IACtC,QAAQ,EAAE,IAAI;IACd,QAAQ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,CAAC,EAAE,CAAC,CAAC,CAAE,CAAC;QAClC,CAAC,CAAC,GAAG,CACH,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,EACzC,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,EACzC,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAE,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAE,CAC5C,CAAC;QACF,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IACD,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/D,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACjD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * `VDBVolumeMaterial`: the fragment raymarch of one grid in a `VDBGridPool`,\n * through a `VDBGridNode` (task K2.3, docs/archive/handoffs/K2.md). It replaces v1's\n * `NanoVDBVolumeMaterial`, which bound one grid image as its own storage\n * attribute and rewrote the vendored library's buffer global.\n *\n * const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });\n * const material = new VDBVolumeMaterial(renderer, grids, id);\n * scene.add(new Mesh(vdbProxyGeometry(pool.info(id)), material));\n * // per frame: pool.update(encoder) (or pool.flush()), then grids.update(), then render.\n *\n * The march is one entry `wgslFn` over the public `vdb*` WGSL API, with\n * `grids.module` as its include (the module carries the pool binding):\n * - the world ray goes into the grid's index space through the record's\n * affine (`vdbWorldToIndex`/`vdbWorldToIndexDir`), so `pool.setTransform`\n * instances render where they are;\n * - it is clipped to the sampler's support box (`vdbRayClipSupport`,\n * `[min - 1, max + 1]` for trilinear), not the voxel-cell box, so the\n * min-side half voxel the trilinear taps reach is marched too;\n * - fixed-step density accumulation with `vdbSample` (the node's sampler),\n * premultiplied front-to-back compositing, early-out at low transmittance.\n * The step lattice is anchored at the voxel-box entry (`vdbRayClip`, where\n * v1 started) and extended back over the support shell, so samples inside\n * the box sit where v1's did; only the shell samples are new (v1 skipped\n * that half voxel, which shows where a grid's min-side voxels are dense);\n * - lighting as in v1: Henyey-Greenstein phase on a directional sun, an\n * N-step shadow march toward the sun (a second accessor), a constant\n * ambient floor, and a per-fragment budget on the total samples;\n * - the look is sized to the grid by default (EX1a, DIVERGES V291): the\n * extinction is `opticalDepth` across the grid's longest index side at the\n * grid's mean density, and the shadow ray spans `shadowReach` of that side.\n * The side is read from the pool record per fragment (`vdbIndexMin` /\n * `vdbIndexMax`), so it follows a `gridId` change, a `pool.replace` and a\n * coarse-first swap; the mean (`densityReference`) is the root node's\n * average statistic, read from `pool.info(id)` at each render. An explicit\n * `densityScale` (> 0) is extinction per index voxel, as in 0.1.\n *\n * Rendered on a proxy box with `side: BackSide` (the camera can be inside);\n * entry and exit come from the analytic clip, not the rasterized faces. The\n * material is `transparent`, `depthWrite: false`, premultiplied alpha. Scene\n * depth compositing is not done (v1 neither).\n *\n * Every tunable is a live TSL uniform (`material.densityScale.value = ...`).\n * The grid is a `uint` uniform too when the constructor got a number\n * (`material.gridId.value = otherId`), so one material can show any grid of\n * the types its `VDBGridNode` compiles without a rebuild.\n *\n * Units and assumptions:\n * - The march runs in the grid's **index space**: `stepSize` is in index\n * voxels, `opticalDepth` is relative to the index box and `densityScale`\n * integrates per index voxel. Opacity therefore does not change with the\n * world size of the grid: `pool.setTransform` (or a NanoVDB map) that scales\n * the grid scales its footprint, not how opaque it looks.\n * - `densityReference` follows the grid: a sequence that replaces the grid\n * each frame is normalised per frame. Pass a number to pin it.\n * - The proxy mesh is not tied to the grid: after `material.gridId.value = id`\n * or `pool.setTransform(id, ...)`, build a new `vdbProxyGeometry(pool.info(id))`\n * for the mesh, or fragments outside the old box are never rasterized.\n * - The view ray is `positionWorld - cameraPosition`: a perspective camera.\n * An orthographic camera's rays are parallel and do not start at\n * `cameraPosition`, so it renders wrongly.\n */\n\nimport * as THREE from \"three\";\nimport { NodeMaterial } from \"three/webgpu\";\nimport { cameraPosition, code, positionWorld, screenCoordinate, uniform, wgslFn } from \"three/tsl\";\nimport { VDBError } from \"../core/errors.js\";\nimport { getDevice, type VDBThreeRendererLike } from \"./device.js\";\nimport { VDBGridNode, type VDBTslNode } from \"./grid-node.js\";\n\n/** Default hard caps of the compiled loops (the live uniforms clamp under them). */\nexport const VDB_VOLUME_MAX_STEPS_CAP = 1024;\n/** Default compiled cap on `shadowSteps`. */\nexport const VDB_VOLUME_SHADOW_STEPS_CAP = 128;\n/**\n * Default cap on the total samples (primary + shadow) one fragment takes.\n * `maxSteps` and `shadowSteps` are independent live uniforms, so their product\n * can reach `maxStepsCap * shadowStepsCap` (~131k at the defaults), a driver\n * timeout risk. Once the budget is spent the shadow loop stops first, then the\n * primary loop, and the fragment returns its partial march.\n */\nexport const VDB_VOLUME_SAMPLE_BUDGET_CAP = 16384;\n\n/** Parameters of {@link VDBVolumeMaterial}: initial uniform values and compile-time caps. */\nexport interface VDBVolumeMaterialParameters {\n /**\n * Extinction per index voxel at density 1. Default 0: the material uses {@link opticalDepth} instead, which\n * suits a grid of any resolution. A value > 0 is used as given (0.1's meaning; 0.1's default was 40).\n */\n densityScale?: number;\n /**\n * Optical depth of a ray that crosses the grid's longest index side at the density `densityReference`, used\n * while `densityScale` is 0: the extinction per index voxel at density 1 is\n * `opticalDepth / (longest side * densityReference)`. Default 6.\n */\n opticalDepth?: number;\n /**\n * The density `opticalDepth` refers to. Default: the mean of the grid's active values (the root node's average\n * statistic, `pool.info(id).rootAverage`), read again at each render, so the default look does not depend on\n * the grid's resolution or value range; 1 for a grid without statistics. A number pins it: for a sequence whose\n * frames should share one scale, or 1 to make `opticalDepth` refer to density 1.\n */\n densityReference?: number;\n /** March step in index voxels. */\n stepSize?: number;\n /** Primary march steps (live, clamped to `maxStepsCap`). Default 512. */\n maxSteps?: number;\n /** Direction toward the sun in world space; normalized at construction. */\n sunDirection?: THREE.Vector3;\n /** Sun colour (linear). Default (1, 0.95, 0.9). */\n sunColor?: THREE.Color;\n /**\n * Sun intensity: the sun term is `sunColor * sunIntensity * phase * shadow`, and a phase function integrates to\n * 1 over the sphere (1 / 4π ≈ 0.08 for isotropic scattering), so 4π lights an unshadowed isotropic sample with\n * `sunColor`. Default 16 (0.1's was 3).\n */\n sunIntensity?: number;\n /** Henyey-Greenstein anisotropy g in (-1, 1). */\n anisotropy?: number;\n /** Shadow-ray steps per lit sample (live, clamped to `shadowStepsCap`). Default 12. */\n shadowSteps?: number;\n /** Density multiplier along the shadow ray only. */\n shadowDensity?: number;\n /**\n * Length of the shadow ray as a fraction of the grid's longest index side: `shadowSteps` steps of\n * `shadowReach * longest side / shadowSteps` voxels, sampled at their midpoints. Default 0.3. 0 steps the\n * shadow ray by `stepSize` (0.1's march: `shadowSteps * stepSize` voxels).\n */\n shadowReach?: number;\n /** Constant ambient term added to the sun light. Default 0.15. */\n ambient?: number;\n /** Per-pixel jitter of the first sample. Default true. */\n jitter?: boolean;\n /** Hard cap on the primary loop. Default {@link VDB_VOLUME_MAX_STEPS_CAP}. */\n maxStepsCap?: number;\n /** Hard cap on the shadow loop. Default {@link VDB_VOLUME_SHADOW_STEPS_CAP}. */\n shadowStepsCap?: number;\n /** Hard cap on the total samples per fragment. Default {@link VDB_VOLUME_SAMPLE_BUDGET_CAP}. */\n sampleBudgetCap?: number;\n}\n\n/** Default `opticalDepth`: the optical depth across the grid's longest index side at its mean density (EX1a). */\nexport const VDB_VOLUME_OPTICAL_DEPTH = 6;\n/** Default `shadowReach`: the shadow ray spans this fraction of the grid's longest index side (EX1a). */\nexport const VDB_VOLUME_SHADOW_REACH = 0.3;\n/** Default `sunIntensity` (EX1a): about 4π × 1.25, so the sun reads against the ambient term (a phase is about 1 / 4π). */\nexport const VDB_VOLUME_SUN_INTENSITY = 16;\n\nconst DEFAULTS = {\n densityScale: 0,\n opticalDepth: VDB_VOLUME_OPTICAL_DEPTH,\n stepSize: 0.75,\n maxSteps: 512,\n sunIntensity: VDB_VOLUME_SUN_INTENSITY,\n anisotropy: 0.3,\n shadowSteps: 12,\n shadowDensity: 1,\n shadowReach: VDB_VOLUME_SHADOW_REACH,\n ambient: 0.15,\n} as const;\n\n/** The smallest `densityReference` the march divides by. */\nexport const VDB_VOLUME_MIN_REFERENCE = 1e-20;\n\n/**\n * The `densityReference` of a grid: its root average statistic when the image has one above 0, else 1 (no\n * statistics, an empty grid, or a grid of non-positive values).\n *\n * @param rootAverage `pool.info(id).rootAverage`.\n */\nexport function vdbVolumeDensityReference(rootAverage: number | undefined): number {\n return typeof rootAverage === \"number\" && Number.isFinite(rootAverage) && rootAverage > 0 ? rootAverage : 1;\n}\n\n/** What {@link vdbVolumeMarchScales} reads: the uniform values of a `VDBVolumeMaterial`. */\nexport interface VDBVolumeMarchScaleInputs {\n densityScale: number;\n opticalDepth: number;\n /** The density `opticalDepth` refers to. Default 1. */\n densityReference?: number;\n stepSize: number;\n shadowSteps: number;\n shadowReach: number;\n /** Compiled cap on `shadowSteps`. Default {@link VDB_VOLUME_SHADOW_STEPS_CAP}. */\n shadowStepsCap?: number;\n}\n\n/** What the march derives from the grid's size. */\nexport interface VDBVolumeMarchScales {\n /** Extinction per index voxel at density 1. */\n extinction: number;\n /** Shadow-ray step, in index voxels. */\n shadowStep: number;\n /** Distance of the first shadow sample from the lit sample, in index voxels. */\n shadowStart: number;\n}\n\n/**\n * The CPU twin of the scale lines of the march entry (EX1a): what `VDBVolumeMaterial` derives from the grid's\n * longest index side. `densityScale > 0` is the extinction as given, else\n * `opticalDepth / (longest * densityReference)`;\n * `shadowReach > 0` spreads the shadow steps over that fraction of the side (midpoint samples), else they step\n * by `stepSize` (0.1's march).\n *\n * @param longest The grid's longest index side in voxels (`max(indexBBox.max - indexBBox.min) + 1`).\n * @param u The material's uniform values.\n */\nexport function vdbVolumeMarchScales(longest: number, u: VDBVolumeMarchScaleInputs): VDBVolumeMarchScales {\n const side = Math.max(longest, 1);\n const extinction = u.densityScale > 0 ? u.densityScale : u.opticalDepth / (side * Math.max(u.densityReference ?? 1, VDB_VOLUME_MIN_REFERENCE));\n const steps = Math.trunc(Math.min(Math.max(u.shadowSteps, 0), u.shadowStepsCap ?? VDB_VOLUME_SHADOW_STEPS_CAP));\n if (u.shadowReach > 0) {\n const shadowStep = (u.shadowReach * side) / Math.max(steps, 1);\n return { extinction, shadowStep, shadowStart: shadowStep * 0.5 };\n }\n return { extinction, shadowStep: u.stepSize, shadowStart: u.stepSize };\n}\n\n/** A live TSL uniform with its value typed (three types `uniform()`'s value as unknown). */\ntype ScalarUniform = ReturnType<typeof uniform> & { value: number };\ntype Vec3Uniform = ReturnType<typeof uniform> & { value: THREE.Vector3 };\ntype ColorUniform = ReturnType<typeof uniform> & { value: THREE.Color };\n/** The `uint` uniform `VDBVolumeMaterial` makes for a numeric grid id (`material.gridId.value = otherId`). */\nexport type VDBUintUniform = ReturnType<typeof uniform> & { value: number };\n\n/** Entry name of the march `wgslFn`. */\nconst ENTRY = \"vdbThreeVolumeMarch\";\n\n/**\n * Module-scope helpers of the march, a second include next to `grids.module`\n * (`wgslFn` parses only its first `fn`, so the entry can't hold them).\n */\nconst VOLUME_HELPERS_WGSL = /* wgsl */ `\nfn vdbThreeHgPhase(cos_theta: f32, g: f32) -> f32 {\n let gg = g * g;\n let denom = 1.0 + gg - 2.0 * g * cos_theta;\n return (1.0 - gg) / (12.566370614359172 * pow(max(denom, 1.0e-4), 1.5));\n}\nfn vdbThreeHash12(p: vec2f) -> f32 {\n var p3 = fract(vec3f(p.x, p.y, p.x) * 0.1031);\n p3 = p3 + dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n}\n`;\n\n/** The march entry, the one `fn` of its `wgslFn`. Caps are compiled in. */\nfunction marchWgsl(maxStepsCap: number, shadowStepsCap: number, sampleBudgetCap: number): string {\n return /* wgsl */ `fn ${ENTRY}(\n grid_id: u32,\n ray_origin_w: vec3f,\n ray_dir_w: vec3f,\n sun_dir_w: vec3f,\n sun_color: vec3f,\n sun_intensity: f32,\n density_scale: f32,\n optical_depth: f32,\n density_reference: f32,\n step_size: f32,\n max_steps: f32,\n g: f32,\n shadow_steps: f32,\n shadow_density: f32,\n shadow_reach: f32,\n ambient: f32,\n jitter: f32,\n pix: vec2f\n) -> vec4f {\n // World -> index through the pool record (instance transform included).\n let o_idx = vdbWorldToIndex(grid_id, ray_origin_w);\n let d_idx = normalize(vdbWorldToIndexDir(grid_id, ray_dir_w));\n let sun_idx = normalize(vdbWorldToIndexDir(grid_id, sun_dir_w));\n\n // Clip to the trilinear support box; a dead id misses.\n var span = vec2f(0.0, 1.0e30);\n if !vdbRayClipSupport(grid_id, o_idx, d_idx, &span) {\n return vec4f(0.0);\n }\n // t0 >= 0: no sample behind the eye (camera inside the support box).\n let t0 = max(span.x, 0.0);\n let t1 = span.y;\n\n var acc = vdbAccessorInit(grid_id);\n var sacc = vdbAccessorInit(grid_id);\n\n // The phase uses the world-space view/sun angle.\n let phase = vdbThreeHgPhase(dot(normalize(ray_dir_w), normalize(sun_dir_w)), g);\n\n // The step lattice is anchored where the ray enters the voxel box\n // (vdbRayClip, v1's entry) and extended back to the support entry, so the\n // samples inside the box sit exactly where v1's did.\n var t = t0;\n var cell = vec2f(0.0, 1.0e30);\n if vdbRayClip(grid_id, o_idx, d_idx, &cell) {\n let anchor = max(cell.x, 0.0);\n t = anchor - ceil((anchor - t0) / step_size) * step_size;\n }\n t += step_size * jitter * vdbThreeHash12(pix);\n // The lattice can start before t0 (the anchor is stepped back in whole\n // steps, plus jitter). Skip those steps on the lattice: they are behind the\n // eye (camera in the support shell) or outside the support box.\n if t < t0 {\n t += ceil((t0 - t) / step_size) * step_size;\n }\n var transmittance = 1.0;\n var color = vec3f(0.0);\n let max_i = i32(clamp(max_steps, 1.0, ${maxStepsCap}.0));\n let shadow_n = i32(clamp(shadow_steps, 0.0, ${shadowStepsCap}.0));\n\n // What the look takes from the grid's size (CPU twin: vdbVolumeMarchScales). The extinction per index voxel\n // is the explicit scale as given, else the optical depth across the longest index side at the reference\n // density; the shadow ray steps by the march step, or spans the reach fraction of the side (midpoint samples).\n let dims = vec3f(vdbIndexMax(grid_id) - vdbIndexMin(grid_id) + vec3i(1));\n let longest = max(max(dims.x, max(dims.y, dims.z)), 1.0);\n var extinction = density_scale;\n if !(extinction > 0.0) {\n extinction = optical_depth / (longest * max(density_reference, 1.0e-20));\n }\n var shadow_step = step_size;\n var shadow_start = step_size;\n if shadow_reach > 0.0 {\n shadow_step = shadow_reach * longest / f32(max(shadow_n, 1));\n shadow_start = shadow_step * 0.5;\n }\n let budget = ${sampleBudgetCap};\n var samples = 0;\n\n for (var i = 0; i < max_i; i++) {\n if t > t1 || transmittance < 0.003 || samples >= budget {\n break;\n }\n let pos = o_idx + d_idx * t;\n let density = max(vdbSample(&acc, pos), 0.0) * extinction;\n samples++;\n if density > 0.0 {\n let a = 1.0 - exp(-density * step_size);\n var tau = 0.0;\n var st = shadow_start;\n for (var s = 0; s < shadow_n; s++) {\n if samples >= budget {\n break;\n }\n let sd = max(vdbSample(&sacc, pos + sun_idx * st), 0.0) * extinction * shadow_density;\n samples++;\n tau += sd * shadow_step;\n st += shadow_step;\n }\n let lit = sun_color * (sun_intensity * exp(-tau) * phase) + vec3f(ambient);\n color += transmittance * a * lit;\n transmittance *= 1.0 - a;\n }\n t += step_size;\n }\n return vec4f(color, 1.0 - transmittance);\n}`;\n}\n\nfunction bad(message: string): VDBError {\n return new VDBError(\"VDB_BAD_OPTION\", `VDBVolumeMaterial: ${message}`);\n}\n\nfunction positiveInt(name: string, value: number | undefined, fallback: number): number {\n const v = value ?? fallback;\n if (!Number.isInteger(v) || v < 1) throw bad(`${name} must be an integer >= 1, got ${JSON.stringify(value)}.`);\n return v;\n}\n\n/**\n * A fragment raymarch of one grid of a `VDBGridPool` (see the file comment for\n * the march). Put it on a `vdbProxyGeometry(pool.info(id))` mesh; each frame\n * run `pool.update(encoder)` (or `pool.flush()`), then `grids.update()`, then\n * render.\n *\n * const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });\n * const material = new VDBVolumeMaterial(renderer, grids, id);\n * const mesh = new Mesh(vdbProxyGeometry(pool.info(id)), material);\n *\n * - The defaults are sized to the grid: `opticalDepth` (6) is the optical\n * depth across the grid's longest index side at its mean density\n * (`densityReference`), and the shadow ray spans `shadowReach` (0.3) of\n * that side, so a grid of any resolution and value range draws as a lit\n * volume. `densityScale` > 0 replaces them with an extinction per index\n * voxel; 0.1's look is `{ densityScale: 40, sunIntensity: 3, shadowReach: 0 }`.\n * - `stepSize` is in index voxels and the density integrates in index\n * space, so opacity ignores the grid's world scale (`setTransform` scaling\n * changes the size on screen, not the opacity).\n * - After `gridId.value = otherId` or `pool.setTransform(id, ...)`, give the\n * mesh a new `vdbProxyGeometry(pool.info(id))`.\n * - Perspective cameras only (the ray starts at `cameraPosition`).\n * - The material must be rendered by the renderer `grids` was made with.\n *\n * @typeParam TGridId What the constructor got as the id: a number (default)\n * makes {@link gridId} a `uint` uniform; a node is kept as given.\n */\nexport class VDBVolumeMaterial<TGridId extends number | VDBTslNode = number> extends NodeMaterial {\n /** Type flag: true. */\n readonly isVDBVolumeMaterial = true;\n\n /** The pool node this material reads (its `module` is the march's include). */\n readonly grids: VDBGridNode;\n /**\n * The grid id: a `uint` uniform when the constructor got a number\n * (`material.gridId.value = otherId`; then give the mesh a new\n * `vdbProxyGeometry`), else the caller's node.\n */\n readonly gridId: TGridId extends number ? VDBUintUniform : VDBTslNode;\n /** The entry `fn` text (for inspection and tests). */\n readonly entrySource: string;\n\n /**\n * Extinction per index voxel at density 1 (opacity of a step: `1 - exp(-density * densityScale * stepSize)`).\n * Default 0: the extinction comes from `opticalDepth` instead. To hide the volume, hide its mesh.\n */\n readonly densityScale: ScalarUniform;\n /**\n * Optical depth across the grid's longest index side at the density `densityReference`, used while\n * `densityScale` is 0. It follows the grid (a `gridId` change, a coarse-first swap). Default 6.\n */\n readonly opticalDepth: ScalarUniform;\n /**\n * The density `opticalDepth` refers to. While {@link densityReferenceAuto} is true it is set at each render\n * to the mean of the grid's active values (`pool.info(id).rootAverage`; 1 without statistics).\n */\n readonly densityReference: ScalarUniform;\n /**\n * True (the default, unless the constructor got a `densityReference`) while the material reads\n * `densityReference` from the pool at each render. It needs a numeric grid id and a pool with `info(id)`\n * (a `VDBGridPool`); otherwise the uniform keeps its value.\n */\n densityReferenceAuto: boolean;\n /** The pool revision and grid id `densityReference` was last read for. */\n #referenceKey: readonly [unknown, unknown] | null = null;\n /** March step in index voxels (live; the lattice re-anchors per fragment). Default 0.75. */\n readonly stepSize: ScalarUniform;\n /** Primary march steps, clamped to `[1, maxStepsCap]`. Default 512. */\n readonly maxSteps: ScalarUniform;\n /** Direction toward the sun, world space (normalized at construction; keep it normalized). */\n readonly sunDirection: Vec3Uniform;\n /** Sun colour (linear). Default (1, 0.95, 0.9). */\n readonly sunColor: ColorUniform;\n /** Sun intensity; the sun term is `sunColor * sunIntensity * phase * shadow` (phase ≈ 1 / 4π). Default 16. */\n readonly sunIntensity: ScalarUniform;\n /** Henyey-Greenstein anisotropy g in (-1, 1). Default 0.3. */\n readonly anisotropy: ScalarUniform;\n /** Shadow-ray steps toward the sun per lit sample, clamped to `[0, shadowStepsCap]`. Default 12. */\n readonly shadowSteps: ScalarUniform;\n /** Density multiplier along the shadow ray only. Default 1. */\n readonly shadowDensity: ScalarUniform;\n /**\n * Length of the shadow ray as a fraction of the grid's longest index side. Default 0.3. 0 steps the shadow\n * ray by `stepSize` (`shadowSteps * stepSize` voxels, 0.1's march).\n */\n readonly shadowReach: ScalarUniform;\n /** Constant ambient term added to the sun light. Default 0.15. */\n readonly ambient: ScalarUniform;\n /** 1 = per-pixel jitter of the first sample on, 0 = off. */\n readonly jitter: ScalarUniform;\n\n /**\n *\n * @param params Initial uniform values and compile-time caps ({@link VDBVolumeMaterialParameters}).\n *\n * @param renderer The initialized `WebGPURenderer` the pool and `grids` live on.\n * @param grids A `VDBGridNode` made on this same renderer, with profile\n * `sample` or `march` and `helpers: ['rayClipSupport']`. Share one per\n * pool: one module per shader.\n * @param gridId The grid's pool id (a number, made a `uint` uniform) or a `uint` node.\n * @throws VDBError `VDB_BAD_OPTION` for a `grids` this material can't use\n * (another renderer, profile, helpers), a bad id or cap;\n * `VDB_UNSUPPORTED_DEVICE` for an uninitialized renderer.\n */\n constructor(renderer: VDBThreeRendererLike, grids: VDBGridNode, gridId: TGridId, params: VDBVolumeMaterialParameters = {}) {\n super();\n if (!(grids instanceof VDBGridNode)) throw bad(\"grids must be a VDBGridNode.\");\n getDevice(renderer); // VDB_UNSUPPORTED_DEVICE before init\n if (grids.renderer !== renderer) {\n throw bad(\n \"grids was made for another renderer. A VDBGridNode binds the pool through the renderer it was made with \" +\n \"(another renderer, even on the same GPUDevice, would read 0): create one VDBGridNode per renderer \" +\n \"(new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] })).\",\n );\n }\n if (grids.options.profile === \"read\") {\n throw bad(\"grids needs profile 'sample' or 'march' (vdbSample); this VDBGridNode was made with profile 'read'.\");\n }\n if (!grids.options.helpers?.includes(\"rayClipSupport\")) {\n throw bad(\"grids must compile the 'rayClipSupport' helper: new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] }).\");\n }\n if (typeof gridId === \"number\") {\n if (!Number.isInteger(gridId) || gridId < 0) throw bad(`gridId must be a non-negative integer, got ${gridId}.`);\n } else if (gridId === null || typeof gridId !== \"object\") {\n throw bad(\"gridId must be a number or a uint TSL node.\");\n }\n const maxStepsCap = positiveInt(\"maxStepsCap\", params.maxStepsCap, VDB_VOLUME_MAX_STEPS_CAP);\n const shadowStepsCap = positiveInt(\"shadowStepsCap\", params.shadowStepsCap, VDB_VOLUME_SHADOW_STEPS_CAP);\n const sampleBudgetCap = positiveInt(\"sampleBudgetCap\", params.sampleBudgetCap, VDB_VOLUME_SAMPLE_BUDGET_CAP);\n\n this.grids = grids;\n this.gridId = (typeof gridId === \"number\" ? uniform(gridId, \"uint\") : gridId) as this[\"gridId\"];\n this.entrySource = marchWgsl(maxStepsCap, shadowStepsCap, sampleBudgetCap);\n\n this.densityScale = uniform(params.densityScale ?? DEFAULTS.densityScale) as ScalarUniform;\n this.opticalDepth = uniform(params.opticalDepth ?? DEFAULTS.opticalDepth) as ScalarUniform;\n this.densityReferenceAuto = params.densityReference === undefined;\n // A render-updated uniform: the callback's return value is assigned (undefined keeps the value).\n this.densityReference = (\n uniform(params.densityReference ?? 1) as ScalarUniform & { onRenderUpdate(callback: () => number | undefined): ScalarUniform }\n ).onRenderUpdate(() => this.#readDensityReference());\n const reference = this.#readDensityReference();\n if (reference !== undefined) this.densityReference.value = reference;\n this.stepSize = uniform(params.stepSize ?? DEFAULTS.stepSize) as ScalarUniform;\n this.maxSteps = uniform(params.maxSteps ?? DEFAULTS.maxSteps) as ScalarUniform;\n this.sunDirection = uniform((params.sunDirection ?? new THREE.Vector3(0.5, 0.8, 0.3)).clone().normalize()) as Vec3Uniform;\n this.sunColor = uniform(params.sunColor ?? new THREE.Color(1, 0.95, 0.9)) as ColorUniform;\n this.sunIntensity = uniform(params.sunIntensity ?? DEFAULTS.sunIntensity) as ScalarUniform;\n this.anisotropy = uniform(params.anisotropy ?? DEFAULTS.anisotropy) as ScalarUniform;\n this.shadowSteps = uniform(params.shadowSteps ?? DEFAULTS.shadowSteps) as ScalarUniform;\n this.shadowDensity = uniform(params.shadowDensity ?? DEFAULTS.shadowDensity) as ScalarUniform;\n this.shadowReach = uniform(params.shadowReach ?? DEFAULTS.shadowReach) as ScalarUniform;\n this.ambient = uniform(params.ambient ?? DEFAULTS.ambient) as ScalarUniform;\n this.jitter = uniform(params.jitter === false ? 0 : 1) as ScalarUniform;\n\n const march = wgslFn(this.entrySource, [grids.module, code(VOLUME_HELPERS_WGSL)] as never);\n this.fragmentNode = march({\n grid_id: this.gridId,\n ray_origin_w: cameraPosition,\n ray_dir_w: positionWorld.sub(cameraPosition).normalize(),\n sun_dir_w: this.sunDirection,\n sun_color: this.sunColor,\n sun_intensity: this.sunIntensity,\n density_scale: this.densityScale,\n optical_depth: this.opticalDepth,\n density_reference: this.densityReference,\n step_size: this.stepSize,\n max_steps: this.maxSteps,\n g: this.anisotropy,\n shadow_steps: this.shadowSteps,\n shadow_density: this.shadowDensity,\n shadow_reach: this.shadowReach,\n ambient: this.ambient,\n jitter: this.jitter,\n pix: screenCoordinate,\n });\n\n this.transparent = true;\n this.depthWrite = false;\n this.depthTest = true;\n this.side = THREE.BackSide;\n this.premultipliedAlpha = true;\n this.toneMapped = false;\n }\n\n /**\n * The grid's `densityReference` when it must be (re)read: auto mode, a numeric id, a pool with `info`, and a\n * pool revision or id other than the last read's. `undefined` keeps the uniform's value (a dead id too).\n */\n #readDensityReference(): number | undefined {\n if (!this.densityReferenceAuto) return undefined;\n const id = (this.gridId as { value?: unknown }).value;\n const pool = this.grids.pool as { info?: (id: number) => { rootAverage?: number }; revision?: unknown };\n if (typeof id !== \"number\" || typeof pool.info !== \"function\") return undefined;\n const key = this.#referenceKey;\n if (key && pool.revision !== undefined && key[0] === pool.revision && key[1] === id) return undefined;\n let average: number | undefined;\n try {\n average = pool.info(id).rootAverage;\n } catch {\n return undefined; // the id is not in the pool (yet)\n }\n this.#referenceKey = [pool.revision, id];\n return vdbVolumeDensityReference(average);\n }\n}\n\n/** What {@link vdbProxyGeometry} reads from `pool.info(id)`. */\nexport interface VDBProxyGridInfo {\n /** Inclusive index-space box of the active voxels (`pool.info(id).indexBBox`). */\n readonly indexBBox: { readonly min: readonly number[]; readonly max: readonly number[] };\n /** 3x4 row-major index-to-world affine (`pool.info(id).indexToWorld`). */\n readonly indexToWorld: ArrayLike<number>;\n}\n\n/**\n * A world-space box for a grid's proxy mesh (add it with an identity\n * transform): the AABB of the index box's voxels `[min - pad, max + 1 + pad]`\n * through the grid's index-to-world affine. `pad: 0` (default) is\n * `pool.info(id).worldBBox`, the box v1 used; `pad: 1` also covers the\n * min-side half voxel of the trilinear support that `VDBVolumeMaterial`\n * marches (rays that cross only that shell are otherwise not rasterized).\n *\n * @param info The grid's `pool.info(id)`.\n * @param options `pad`: voxels added on every side of the index box (default 0).\n */\nexport function vdbProxyGeometry(info: VDBProxyGridInfo, options: { pad?: number } = {}): THREE.BoxGeometry {\n const pad = options.pad ?? 0;\n if (!Number.isFinite(pad) || pad < 0) throw bad(`vdbProxyGeometry pad must be a finite number >= 0, got ${pad}.`);\n const m = info.indexToWorld;\n const lo = [0, 1, 2].map((a) => info.indexBBox.min[a]! - pad);\n const hi = [0, 1, 2].map((a) => info.indexBBox.max[a]! + 1 + pad);\n const box = new THREE.Box3();\n const p = new THREE.Vector3();\n for (let k = 0; k < 8; k++) {\n const x = k & 1 ? hi[0]! : lo[0]!;\n const y = k & 2 ? hi[1]! : lo[1]!;\n const z = k & 4 ? hi[2]! : lo[2]!;\n p.set(\n m[0]! * x + m[1]! * y + m[2]! * z + m[3]!,\n m[4]! * x + m[5]! * y + m[6]! * z + m[7]!,\n m[8]! * x + m[9]! * y + m[10]! * z + m[11]!,\n );\n box.expandByPoint(p);\n }\n const size = box.getSize(new THREE.Vector3());\n const center = box.getCenter(new THREE.Vector3());\n const geometry = new THREE.BoxGeometry(size.x, size.y, size.z);\n geometry.translate(center.x, center.y, center.z);\n return geometry;\n}\n"]}
@@ -16,20 +16,30 @@
16
16
  * instead of decoding the grid itself; the pixel scale reads the render
17
17
  * target's height when one is set (DIVERGES.md).
18
18
  *
19
+ * The sprite size and its clip-space offset are the core's WGSL (`vdbPointSpriteSize`,
20
+ * `vdbPointSpriteVertex`, `core/surface/points.ts`, K6.6), the functions the raw pass
21
+ * `vdbCreatePointPass` calls; the vertex node calls them through `wgslFn`. The disc map stays here.
22
+ *
19
23
  * Positions are world space of the grid (the point list's own transform);
20
24
  * place them with the object's transform as any three object. The sprite sits
21
25
  * at the origin with the points in local space, so frustum culling is off.
26
+ *
27
+ * The arrays can hold more points than are drawn (`capacity` vs `pointCount`): a prefix-ordered list (tools
28
+ * `vdbPointRenderData(grid, { order: 'prefix' })`) thins by count alone, and `.wvdb` points stream in LOD by LOD
29
+ * (K3.7b): `VDBPoints.fromWvdbGrid(header)` sizes the arrays for the grid and `addWvdbLevel(level)` writes each
30
+ * level a `WvdbStreamReader` decodes (only the new range is uploaded) and draws the points that have arrived.
22
31
  */
23
32
  import * as THREE from "three";
24
33
  import { InstancedBufferAttribute, PointsNodeMaterial, Sprite } from "three/webgpu";
25
34
  import * as TSL from "three/tsl";
35
+ import type { WvdbPointsGrid, WvdbPointsGridHeader, WvdbPointsLevel } from "../tools/wvdb/index.js";
26
36
  /** What `VDBPoints` draws (tools `vdbPointRenderData` returns one). */
27
37
  export interface VDBPointsData {
28
38
  /** World positions of the grid, xyz per point. */
29
39
  positions: Float32Array;
30
40
  /** Linear RGB per point (multiplied by the material colour), or null. */
31
41
  colors?: Float32Array | null;
32
- /** Points to draw (default `positions.length / 3`). */
42
+ /** Points to draw (default `positions.length / 3`); the arrays may hold more (`capacity`). */
33
43
  count?: number;
34
44
  /** Mean point spacing in world units: the default diameter is half of it. Default 1. */
35
45
  spacing?: number;
@@ -61,22 +71,68 @@ interface RendererSizeLike {
61
71
  * and the other sprite parameters apply; `Cd` multiplies the colour).
62
72
  */
63
73
  export declare class VDBPoints extends Sprite {
74
+ /** Type flag: true. */
64
75
  readonly isVDBPoints = true;
65
76
  material: PointsNodeMaterial;
66
- /** Points drawn. */
67
- pointCount: number;
68
77
  /** Mean spacing of the points (world units). */
69
78
  spacing: number;
70
79
  /** World diameter of a point, or null for `spacing * 0.5`. */
71
80
  size: number | null;
72
81
  /** Point diameter in pixels at view depth 1 (set before each render). */
73
82
  readonly pixelScale: ScalarUniform;
83
+ /** The instanced position attribute (world xyz per point). */
74
84
  readonly positionAttribute: InstancedBufferAttribute;
85
+ /** The instanced colour attribute (linear RGB per point), or null without colours. */
75
86
  readonly colorAttribute: InstancedBufferAttribute | null;
87
+ private drawn;
88
+ /** `.wvdb` streaming: the grid's mean spacing over all its points, and the points written per LOD. */
89
+ private wvdb;
90
+ /**
91
+ * Builds the sprite from render data (tools `vdbPointRenderData`).
92
+ *
93
+ * @param data World positions (xyz triples), optional colours, count and spacing.
94
+ * @param options Sprite material parameters plus `size`, the world diameter of a point.
95
+ */
76
96
  constructor(data: VDBPointsData, options?: VDBPointsOptions);
97
+ /** Points drawn: the instance count, at most {@link capacity}. Set it to draw a prefix of the arrays. */
98
+ get pointCount(): number;
99
+ set pointCount(n: number);
100
+ /** Points the arrays hold: the most {@link pointCount} can be. */
101
+ get capacity(): number;
102
+ /**
103
+ * Writes points `[first, first + n)` of the arrays (`n = positions.length / 3`) and uploads only that range at the
104
+ * next render. Does not change {@link pointCount}.
105
+ *
106
+ * @param first The first point to write.
107
+ * @param positions xyz per point.
108
+ * @param colors rgb per point (n * 3 values), for a `VDBPoints` made with colours; null or omitted keeps them.
109
+ */
110
+ writePoints(first: number, positions: Float32Array, colors?: Float32Array | null): void;
111
+ /**
112
+ * An empty `VDBPoints` sized for a `.wvdb` points grid (K3.7b): capacity = the grid's points, colours when it has
113
+ * them, nothing drawn. Feed it the grid's LODs with {@link addWvdbLevel} as a `WvdbStreamReader` decodes them.
114
+ *
115
+ * @param grid The grid's header record (`reader.header.grids[i]`, once the header arrived) or a decoded grid.
116
+ * @param options Sprite material parameters plus `size`.
117
+ */
118
+ static fromWvdbGrid(grid: WvdbPointsGridHeader | WvdbPointsGrid, options?: VDBPointsOptions): VDBPoints;
119
+ /**
120
+ * Writes a `.wvdb` points level (a `WvdbStreamReader` event's level for this grid, complete or partial) at its
121
+ * `firstPoint`, uploading only the points not written before, then draws every point that has arrived in order:
122
+ * LOD k's points follow LODs 0..k-1, so the drawn prefix is an even subsample (every 8^(lods-1-k)-th point of the
123
+ * stored order). The default diameter follows: `spacing` becomes the grid's spacing times `cbrt(capacity / pointCount)`.
124
+ *
125
+ * @param level A points level of the grid this `VDBPoints` was made for ({@link fromWvdbGrid}).
126
+ */
127
+ addWvdbLevel(level: WvdbPointsLevel): void;
77
128
  /** The world diameter in use: `size`, or half the spacing. */
78
129
  get diameter(): number;
79
- /** Sets {@link pixelScale} for a camera and the renderer's current target (called before each render). */
130
+ /**
131
+ * Sets {@link pixelScale} for a camera and the renderer's current target (called before each render).
132
+ *
133
+ * @param renderer The renderer whose current target size gives the pixel height.
134
+ * @param camera The camera whose field of view (or zoom) sets the scale.
135
+ */
80
136
  updatePixelScale(renderer: RendererSizeLike, camera: THREE.Camera): void;
81
137
  /** Frees the material (the shared disc texture stays). */
82
138
  dispose(): void;