@pmndrs/vdb 0.0.0-stage → 0.1.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 (390) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/LICENSE +21 -0
  3. package/README.md +448 -2
  4. package/THIRD_PARTY_NOTICES.md +147 -0
  5. package/dist/core/compute/atlas.d.ts +94 -0
  6. package/dist/core/compute/atlas.js +98 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/pyramid.d.ts +105 -0
  12. package/dist/core/compute/pyramid.js +455 -0
  13. package/dist/core/compute/pyramid.js.map +1 -0
  14. package/dist/core/compute/shared.d.ts +115 -0
  15. package/dist/core/compute/shared.js +211 -0
  16. package/dist/core/compute/shared.js.map +1 -0
  17. package/dist/core/compute/stats.d.ts +71 -0
  18. package/dist/core/compute/stats.js +188 -0
  19. package/dist/core/compute/stats.js.map +1 -0
  20. package/dist/core/compute/value-transform.d.ts +23 -0
  21. package/dist/core/compute/value-transform.js +58 -0
  22. package/dist/core/compute/value-transform.js.map +1 -0
  23. package/dist/core/errors.d.ts +11 -0
  24. package/dist/core/errors.js +9 -0
  25. package/dist/core/errors.js.map +1 -0
  26. package/dist/core/index.d.ts +30 -0
  27. package/dist/core/index.js +27 -0
  28. package/dist/core/index.js.map +1 -0
  29. package/dist/core/internal.d.ts +15 -0
  30. package/dist/core/internal.js +15 -0
  31. package/dist/core/internal.js.map +1 -0
  32. package/dist/core/pool/affine.d.ts +34 -0
  33. package/dist/core/pool/affine.js +100 -0
  34. package/dist/core/pool/affine.js.map +1 -0
  35. package/dist/core/pool/allocator.d.ts +32 -0
  36. package/dist/core/pool/allocator.js +81 -0
  37. package/dist/core/pool/allocator.js.map +1 -0
  38. package/dist/core/pool/image-header.d.ts +82 -0
  39. package/dist/core/pool/image-header.js +175 -0
  40. package/dist/core/pool/image-header.js.map +1 -0
  41. package/dist/core/pool/layout.d.ts +164 -0
  42. package/dist/core/pool/layout.js +267 -0
  43. package/dist/core/pool/layout.js.map +1 -0
  44. package/dist/core/pool/limits.d.ts +40 -0
  45. package/dist/core/pool/limits.js +79 -0
  46. package/dist/core/pool/limits.js.map +1 -0
  47. package/dist/core/pool/pool.d.ts +279 -0
  48. package/dist/core/pool/pool.js +953 -0
  49. package/dist/core/pool/pool.js.map +1 -0
  50. package/dist/core/source/dense.d.ts +19 -0
  51. package/dist/core/source/dense.js +287 -0
  52. package/dist/core/source/dense.js.map +1 -0
  53. package/dist/core/source/types.d.ts +63 -0
  54. package/dist/core/source/types.js +9 -0
  55. package/dist/core/source/types.js.map +1 -0
  56. package/dist/core/types.d.ts +28 -0
  57. package/dist/core/types.js +28 -0
  58. package/dist/core/types.js.map +1 -0
  59. package/dist/core/wgsl/api.d.ts +41 -0
  60. package/dist/core/wgsl/api.js +463 -0
  61. package/dist/core/wgsl/api.js.map +1 -0
  62. package/dist/core/wgsl/generate.d.ts +82 -0
  63. package/dist/core/wgsl/generate.js +505 -0
  64. package/dist/core/wgsl/generate.js.map +1 -0
  65. package/dist/core/wgsl/level-set.d.ts +54 -0
  66. package/dist/core/wgsl/level-set.js +194 -0
  67. package/dist/core/wgsl/level-set.js.map +1 -0
  68. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  69. package/dist/core/wgsl/pnanovdb.chunks.generated.js +330 -0
  70. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  71. package/dist/core/wgsl/reserved.d.ts +9 -0
  72. package/dist/core/wgsl/reserved.js +26 -0
  73. package/dist/core/wgsl/reserved.js.map +1 -0
  74. package/dist/core/wgsl/types.d.ts +104 -0
  75. package/dist/core/wgsl/types.js +2 -0
  76. package/dist/core/wgsl/types.js.map +1 -0
  77. package/dist/three/coarse-first.d.ts +162 -0
  78. package/dist/three/coarse-first.js +187 -0
  79. package/dist/three/coarse-first.js.map +1 -0
  80. package/dist/three/compute.d.ts +63 -0
  81. package/dist/three/compute.js +56 -0
  82. package/dist/three/compute.js.map +1 -0
  83. package/dist/three/device.d.ts +59 -0
  84. package/dist/three/device.js +59 -0
  85. package/dist/three/device.js.map +1 -0
  86. package/dist/three/frame/blackbody.d.ts +42 -0
  87. package/dist/three/frame/blackbody.js +74 -0
  88. package/dist/three/frame/blackbody.js.map +1 -0
  89. package/dist/three/frame/chunks.d.ts +157 -0
  90. package/dist/three/frame/chunks.js +559 -0
  91. package/dist/three/frame/chunks.js.map +1 -0
  92. package/dist/three/frame/density-material.d.ts +53 -0
  93. package/dist/three/frame/density-material.js +353 -0
  94. package/dist/three/frame/density-material.js.map +1 -0
  95. package/dist/three/frame/emission-light.d.ts +167 -0
  96. package/dist/three/frame/emission-light.js +655 -0
  97. package/dist/three/frame/emission-light.js.map +1 -0
  98. package/dist/three/frame/environment-grid-material.d.ts +21 -0
  99. package/dist/three/frame/environment-grid-material.js +184 -0
  100. package/dist/three/frame/environment-grid-material.js.map +1 -0
  101. package/dist/three/frame/environment-material.d.ts +22 -0
  102. package/dist/three/frame/environment-material.js +87 -0
  103. package/dist/three/frame/environment-material.js.map +1 -0
  104. package/dist/three/frame/grid-mip-material.d.ts +12 -0
  105. package/dist/three/frame/grid-mip-material.js +61 -0
  106. package/dist/three/frame/grid-mip-material.js.map +1 -0
  107. package/dist/three/frame/index.d.ts +39 -0
  108. package/dist/three/frame/index.js +35 -0
  109. package/dist/three/frame/index.js.map +1 -0
  110. package/dist/three/frame/inject-material.d.ts +56 -0
  111. package/dist/three/frame/inject-material.js +424 -0
  112. package/dist/three/frame/inject-material.js.map +1 -0
  113. package/dist/three/frame/integrate-material.d.ts +26 -0
  114. package/dist/three/frame/integrate-material.js +198 -0
  115. package/dist/three/frame/integrate-material.js.map +1 -0
  116. package/dist/three/frame/layout.d.ts +34 -0
  117. package/dist/three/frame/layout.js +48 -0
  118. package/dist/three/frame/layout.js.map +1 -0
  119. package/dist/three/frame/lighting-material.d.ts +41 -0
  120. package/dist/three/frame/lighting-material.js +257 -0
  121. package/dist/three/frame/lighting-material.js.map +1 -0
  122. package/dist/three/frame/lights.d.ts +11 -0
  123. package/dist/three/frame/lights.js +16 -0
  124. package/dist/three/frame/lights.js.map +1 -0
  125. package/dist/three/frame/medium.d.ts +21 -0
  126. package/dist/three/frame/medium.js +29 -0
  127. package/dist/three/frame/medium.js.map +1 -0
  128. package/dist/three/frame/neural.d.ts +14 -0
  129. package/dist/three/frame/neural.js +105 -0
  130. package/dist/three/frame/neural.js.map +1 -0
  131. package/dist/three/frame/phase.d.ts +44 -0
  132. package/dist/three/frame/phase.js +80 -0
  133. package/dist/three/frame/phase.js.map +1 -0
  134. package/dist/three/frame/renderer.d.ts +493 -0
  135. package/dist/three/frame/renderer.js +1498 -0
  136. package/dist/three/frame/renderer.js.map +1 -0
  137. package/dist/three/frame/shadow-density-material.d.ts +30 -0
  138. package/dist/three/frame/shadow-density-material.js +123 -0
  139. package/dist/three/frame/shadow-density-material.js.map +1 -0
  140. package/dist/three/frame/spectrum.d.ts +18 -0
  141. package/dist/three/frame/spectrum.js +36 -0
  142. package/dist/three/frame/spectrum.js.map +1 -0
  143. package/dist/three/frame/temporal-material.d.ts +29 -0
  144. package/dist/three/frame/temporal-material.js +152 -0
  145. package/dist/three/frame/temporal-material.js.map +1 -0
  146. package/dist/three/frame/three-internals.d.ts +65 -0
  147. package/dist/three/frame/three-internals.js +150 -0
  148. package/dist/three/frame/three-internals.js.map +1 -0
  149. package/dist/three/frame/transmittance-material.d.ts +31 -0
  150. package/dist/three/frame/transmittance-material.js +315 -0
  151. package/dist/three/frame/transmittance-material.js.map +1 -0
  152. package/dist/three/frame/view.d.ts +103 -0
  153. package/dist/three/frame/view.js +296 -0
  154. package/dist/three/frame/view.js.map +1 -0
  155. package/dist/three/frame/volume-shadow-material.d.ts +36 -0
  156. package/dist/three/frame/volume-shadow-material.js +128 -0
  157. package/dist/three/frame/volume-shadow-material.js.map +1 -0
  158. package/dist/three/frame/volume-shadows.d.ts +153 -0
  159. package/dist/three/frame/volume-shadows.js +756 -0
  160. package/dist/three/frame/volume-shadows.js.map +1 -0
  161. package/dist/three/frame/volume.d.ts +172 -0
  162. package/dist/three/frame/volume.js +256 -0
  163. package/dist/three/frame/volume.js.map +1 -0
  164. package/dist/three/grid-node.d.ts +196 -0
  165. package/dist/three/grid-node.js +510 -0
  166. package/dist/three/grid-node.js.map +1 -0
  167. package/dist/three/index.d.ts +43 -0
  168. package/dist/three/index.js +49 -0
  169. package/dist/three/index.js.map +1 -0
  170. package/dist/three/internal.d.ts +14 -0
  171. package/dist/three/internal.js +14 -0
  172. package/dist/three/internal.js.map +1 -0
  173. package/dist/three/level-set-material.d.ts +112 -0
  174. package/dist/three/level-set-material.js +204 -0
  175. package/dist/three/level-set-material.js.map +1 -0
  176. package/dist/three/material.d.ts +194 -0
  177. package/dist/three/material.js +359 -0
  178. package/dist/three/material.js.map +1 -0
  179. package/dist/three/points.d.ts +84 -0
  180. package/dist/three/points.js +130 -0
  181. package/dist/three/points.js.map +1 -0
  182. package/dist/three/sequence.d.ts +317 -0
  183. package/dist/three/sequence.js +526 -0
  184. package/dist/three/sequence.js.map +1 -0
  185. package/dist/three/sparse-source.d.ts +233 -0
  186. package/dist/three/sparse-source.js +876 -0
  187. package/dist/three/sparse-source.js.map +1 -0
  188. package/dist/three/volume-source.d.ts +167 -0
  189. package/dist/three/volume-source.js +353 -0
  190. package/dist/three/volume-source.js.map +1 -0
  191. package/dist/tools/cpu/compute.d.ts +97 -0
  192. package/dist/tools/cpu/compute.js +218 -0
  193. package/dist/tools/cpu/compute.js.map +1 -0
  194. package/dist/tools/cpu/level-set.d.ts +72 -0
  195. package/dist/tools/cpu/level-set.js +261 -0
  196. package/dist/tools/cpu/level-set.js.map +1 -0
  197. package/dist/tools/cpu/march.d.ts +206 -0
  198. package/dist/tools/cpu/march.js +575 -0
  199. package/dist/tools/cpu/march.js.map +1 -0
  200. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  201. package/dist/tools/cpu/probe-coords.js +116 -0
  202. package/dist/tools/cpu/probe-coords.js.map +1 -0
  203. package/dist/tools/cpu/read-value.d.ts +31 -0
  204. package/dist/tools/cpu/read-value.js +336 -0
  205. package/dist/tools/cpu/read-value.js.map +1 -0
  206. package/dist/tools/cpu/sample-trilinear.d.ts +30 -0
  207. package/dist/tools/cpu/sample-trilinear.js +156 -0
  208. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  209. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  210. package/dist/tools/cpu/stride-tables.generated.d.ts +1058 -0
  211. package/dist/tools/cpu/stride-tables.generated.js +1266 -0
  212. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  213. package/dist/tools/cpu/stride-tables.js +78 -0
  214. package/dist/tools/cpu/stride-tables.js.map +1 -0
  215. package/dist/tools/errors.d.ts +57 -0
  216. package/dist/tools/errors.js +58 -0
  217. package/dist/tools/errors.js.map +1 -0
  218. package/dist/tools/frame/blackbody.d.ts +42 -0
  219. package/dist/tools/frame/blackbody.js +116 -0
  220. package/dist/tools/frame/blackbody.js.map +1 -0
  221. package/dist/tools/frame/emission.d.ts +128 -0
  222. package/dist/tools/frame/emission.js +282 -0
  223. package/dist/tools/frame/emission.js.map +1 -0
  224. package/dist/tools/frame/environment.d.ts +105 -0
  225. package/dist/tools/frame/environment.js +268 -0
  226. package/dist/tools/frame/environment.js.map +1 -0
  227. package/dist/tools/frame/grid.d.ts +302 -0
  228. package/dist/tools/frame/grid.js +703 -0
  229. package/dist/tools/frame/grid.js.map +1 -0
  230. package/dist/tools/frame/index.d.ts +136 -0
  231. package/dist/tools/frame/index.js +348 -0
  232. package/dist/tools/frame/index.js.map +1 -0
  233. package/dist/tools/frame/medium.d.ts +61 -0
  234. package/dist/tools/frame/medium.js +99 -0
  235. package/dist/tools/frame/medium.js.map +1 -0
  236. package/dist/tools/frame/mie-table.d.ts +6 -0
  237. package/dist/tools/frame/mie-table.js +16 -0
  238. package/dist/tools/frame/mie-table.js.map +1 -0
  239. package/dist/tools/frame/mie.d.ts +54 -0
  240. package/dist/tools/frame/mie.js +176 -0
  241. package/dist/tools/frame/mie.js.map +1 -0
  242. package/dist/tools/frame/neural-weights.d.ts +9 -0
  243. package/dist/tools/frame/neural-weights.js +245 -0
  244. package/dist/tools/frame/neural-weights.js.map +1 -0
  245. package/dist/tools/frame/neural.d.ts +80 -0
  246. package/dist/tools/frame/neural.js +150 -0
  247. package/dist/tools/frame/neural.js.map +1 -0
  248. package/dist/tools/frame/pyramid-layout.d.ts +38 -0
  249. package/dist/tools/frame/pyramid-layout.js +53 -0
  250. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  251. package/dist/tools/frame/shadows.d.ts +80 -0
  252. package/dist/tools/frame/shadows.js +182 -0
  253. package/dist/tools/frame/shadows.js.map +1 -0
  254. package/dist/tools/frame/sparse.d.ts +65 -0
  255. package/dist/tools/frame/sparse.js +191 -0
  256. package/dist/tools/frame/sparse.js.map +1 -0
  257. package/dist/tools/frame/spectral.d.ts +203 -0
  258. package/dist/tools/frame/spectral.js +550 -0
  259. package/dist/tools/frame/spectral.js.map +1 -0
  260. package/dist/tools/index.d.ts +106 -0
  261. package/dist/tools/index.js +88 -0
  262. package/dist/tools/index.js.map +1 -0
  263. package/dist/tools/internal.d.ts +46 -0
  264. package/dist/tools/internal.js +31 -0
  265. package/dist/tools/internal.js.map +1 -0
  266. package/dist/tools/nanovdb/build-from-vdb.d.ts +50 -0
  267. package/dist/tools/nanovdb/build-from-vdb.js +92 -0
  268. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  269. package/dist/tools/nanovdb/bytes.d.ts +220 -0
  270. package/dist/tools/nanovdb/bytes.js +345 -0
  271. package/dist/tools/nanovdb/bytes.js.map +1 -0
  272. package/dist/tools/nanovdb/coarse-first.d.ts +62 -0
  273. package/dist/tools/nanovdb/coarse-first.js +86 -0
  274. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  275. package/dist/tools/nanovdb/index.d.ts +32 -0
  276. package/dist/tools/nanovdb/index.js +24 -0
  277. package/dist/tools/nanovdb/index.js.map +1 -0
  278. package/dist/tools/nanovdb/inspect.d.ts +24 -0
  279. package/dist/tools/nanovdb/inspect.js +63 -0
  280. package/dist/tools/nanovdb/inspect.js.map +1 -0
  281. package/dist/tools/nanovdb/leaf-codec.d.ts +85 -0
  282. package/dist/tools/nanovdb/leaf-codec.js +320 -0
  283. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  284. package/dist/tools/nanovdb/quantize.d.ts +43 -0
  285. package/dist/tools/nanovdb/quantize.js +277 -0
  286. package/dist/tools/nanovdb/quantize.js.map +1 -0
  287. package/dist/tools/nanovdb/resample.d.ts +160 -0
  288. package/dist/tools/nanovdb/resample.js +679 -0
  289. package/dist/tools/nanovdb/resample.js.map +1 -0
  290. package/dist/tools/nanovdb/serialize.d.ts +145 -0
  291. package/dist/tools/nanovdb/serialize.js +395 -0
  292. package/dist/tools/nanovdb/serialize.js.map +1 -0
  293. package/dist/tools/nanovdb/stats.d.ts +58 -0
  294. package/dist/tools/nanovdb/stats.js +149 -0
  295. package/dist/tools/nanovdb/stats.js.map +1 -0
  296. package/dist/tools/nanovdb/transform.d.ts +26 -0
  297. package/dist/tools/nanovdb/transform.js +91 -0
  298. package/dist/tools/nanovdb/transform.js.map +1 -0
  299. package/dist/tools/nanovdb/tree.d.ts +175 -0
  300. package/dist/tools/nanovdb/tree.js +518 -0
  301. package/dist/tools/nanovdb/tree.js.map +1 -0
  302. package/dist/tools/nanovdb/write-nvdb.d.ts +39 -0
  303. package/dist/tools/nanovdb/write-nvdb.js +210 -0
  304. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  305. package/dist/tools/nvdb-file.d.ts +195 -0
  306. package/dist/tools/nvdb-file.js +606 -0
  307. package/dist/tools/nvdb-file.js.map +1 -0
  308. package/dist/tools/nvdb-stream.d.ts +138 -0
  309. package/dist/tools/nvdb-stream.js +365 -0
  310. package/dist/tools/nvdb-stream.js.map +1 -0
  311. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  312. package/dist/tools/vdb/bit-utils.js +42 -0
  313. package/dist/tools/vdb/bit-utils.js.map +1 -0
  314. package/dist/tools/vdb/blosc.d.ts +56 -0
  315. package/dist/tools/vdb/blosc.js +231 -0
  316. package/dist/tools/vdb/blosc.js.map +1 -0
  317. package/dist/tools/vdb/byte-reader.d.ts +40 -0
  318. package/dist/tools/vdb/byte-reader.js +139 -0
  319. package/dist/tools/vdb/byte-reader.js.map +1 -0
  320. package/dist/tools/vdb/compression.d.ts +73 -0
  321. package/dist/tools/vdb/compression.js +249 -0
  322. package/dist/tools/vdb/compression.js.map +1 -0
  323. package/dist/tools/vdb/errors.d.ts +10 -0
  324. package/dist/tools/vdb/errors.js +11 -0
  325. package/dist/tools/vdb/errors.js.map +1 -0
  326. package/dist/tools/vdb/grid.d.ts +37 -0
  327. package/dist/tools/vdb/grid.js +147 -0
  328. package/dist/tools/vdb/grid.js.map +1 -0
  329. package/dist/tools/vdb/half-float.d.ts +9 -0
  330. package/dist/tools/vdb/half-float.js +24 -0
  331. package/dist/tools/vdb/half-float.js.map +1 -0
  332. package/dist/tools/vdb/index.d.ts +3 -0
  333. package/dist/tools/vdb/index.js +3 -0
  334. package/dist/tools/vdb/index.js.map +1 -0
  335. package/dist/tools/vdb/inflate.d.ts +24 -0
  336. package/dist/tools/vdb/inflate.js +334 -0
  337. package/dist/tools/vdb/inflate.js.map +1 -0
  338. package/dist/tools/vdb/metadata.d.ts +17 -0
  339. package/dist/tools/vdb/metadata.js +72 -0
  340. package/dist/tools/vdb/metadata.js.map +1 -0
  341. package/dist/tools/vdb/parse.d.ts +25 -0
  342. package/dist/tools/vdb/parse.js +171 -0
  343. package/dist/tools/vdb/parse.js.map +1 -0
  344. package/dist/tools/vdb/point-render-data.d.ts +31 -0
  345. package/dist/tools/vdb/point-render-data.js +57 -0
  346. package/dist/tools/vdb/point-render-data.js.map +1 -0
  347. package/dist/tools/vdb/points.d.ts +160 -0
  348. package/dist/tools/vdb/points.js +794 -0
  349. package/dist/tools/vdb/points.js.map +1 -0
  350. package/dist/tools/vdb/transform.d.ts +23 -0
  351. package/dist/tools/vdb/transform.js +54 -0
  352. package/dist/tools/vdb/transform.js.map +1 -0
  353. package/dist/tools/vdb/tree.d.ts +111 -0
  354. package/dist/tools/vdb/tree.js +228 -0
  355. package/dist/tools/vdb/tree.js.map +1 -0
  356. package/dist/tools/vdb/types.d.ts +138 -0
  357. package/dist/tools/vdb/types.js +3 -0
  358. package/dist/tools/vdb/types.js.map +1 -0
  359. package/dist/tools/wvdb/bake.d.ts +116 -0
  360. package/dist/tools/wvdb/bake.js +311 -0
  361. package/dist/tools/wvdb/bake.js.map +1 -0
  362. package/dist/tools/wvdb/dense.d.ts +112 -0
  363. package/dist/tools/wvdb/dense.js +309 -0
  364. package/dist/tools/wvdb/dense.js.map +1 -0
  365. package/dist/tools/wvdb/format.d.ts +161 -0
  366. package/dist/tools/wvdb/format.js +303 -0
  367. package/dist/tools/wvdb/format.js.map +1 -0
  368. package/dist/tools/wvdb/index.d.ts +13 -0
  369. package/dist/tools/wvdb/index.js +14 -0
  370. package/dist/tools/wvdb/index.js.map +1 -0
  371. package/dist/tools/wvdb/level-set.d.ts +48 -0
  372. package/dist/tools/wvdb/level-set.js +153 -0
  373. package/dist/tools/wvdb/level-set.js.map +1 -0
  374. package/dist/tools/wvdb/nanovdb.d.ts +54 -0
  375. package/dist/tools/wvdb/nanovdb.js +60 -0
  376. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  377. package/dist/tools/wvdb/read.d.ts +260 -0
  378. package/dist/tools/wvdb/read.js +743 -0
  379. package/dist/tools/wvdb/read.js.map +1 -0
  380. package/dist/tools/wvdb/sha256.d.ts +7 -0
  381. package/dist/tools/wvdb/sha256.js +76 -0
  382. package/dist/tools/wvdb/sha256.js.map +1 -0
  383. package/dist/tools/wvdb/write.d.ts +127 -0
  384. package/dist/tools/wvdb/write.js +396 -0
  385. package/dist/tools/wvdb/write.js.map +1 -0
  386. package/package.json +82 -4
  387. package/vendor/LICENSE +201 -0
  388. package/vendor/NOTICE +19 -0
  389. package/vendor/VENDOR.md +85 -0
  390. package/vendor/pnanovdb.wgsl +1539 -0
@@ -0,0 +1,655 @@
1
+ // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
2
+ // src/three-openvdb/frame/core/FrameEmissionLight.js L1–287 (FrameEmissionLightBase: emitters, keys, probe
3
+ // cascades, prepareProbes); src/three-openvdb/frame/webgpu/FrameEmissionLight.js L59–658 (probe grid uniforms,
4
+ // the direction / reduce / probe pass materials, FrameEmissionLightNode, FrameEmissionLight: targets, slots,
5
+ // updateProbes, dispose, the node registration).
6
+ // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
7
+ // Changes: TypeScript; one class (his CPU base and WebGPU subclass merged); the direction pass reads each emitter
8
+ // through its own volume source (one direction material per source, as the other passes, DIVERGES V30) instead of
9
+ // one material that swaps 3D textures; no CPU mip step (the sources hold their LOD); the pass materials belong to
10
+ // the light (his are shared by all lights and never freed); the probe cascade maths is engine-free
11
+ // (`@pmndrs/vdb/tools` `vdbFrameEmissionProbeGrid`, with twins of every pass); every three r187 internal goes
12
+ // through `three-internals.ts` (VDB_ENGINE_MISMATCH on another three). Divergences: DIVERGES.md (K3.6 rows).
13
+ /**
14
+ * K3.6: light from the emissive grids of every visible `VDBFrameVolume` (his `FrameEmissionLight`). Add one to the
15
+ * scene; three's lit node materials (`MeshStandardMaterial`, `MeshLambertMaterial`, …) receive it as irradiance, like a
16
+ * light probe. Per changed volume: its emitted light along 16 directions × 8² rays (direction pass), the mean and the
17
+ * luminance-weighted centre (reduce pass); then L1 irradiance probes of all volumes as point lights, in up to 4
18
+ * cascades of ≤ 32³ (probe pass). A lit pixel reads 6 texels (12 near a cascade side), for any number of volumes.
19
+ * The passes run before the first lit mesh of each render and only when a volume or the cascades changed.
20
+ *
21
+ * const light = new VDBFrameEmissionLight({ intensity: 25, resolution: 32 });
22
+ * scene.add(light); // volumes need an emission channel; colour: VDBFrameVolume `emissionColor`
23
+ */
24
+ import * as THREE from "three";
25
+ import { AnalyticLightNode, NodeMaterial } from "three/webgpu";
26
+ import * as TSL from "three/tsl";
27
+ import { vdbVolumeNodes } from "../volume-source.js";
28
+ import { createFrameVolumeUniforms, createGridNodes, frameFragCoord, frameFullscreenVertex, frameLoad } from "./chunks.js";
29
+ import { frameEmissionAtlasColumns as atlasColumns, frameEmissionAtlasSize as atlasSize, frameEmissionDirections as directionCount, frameEmissionGoldenAngle as goldenAngle, frameEmissionMaxCascades as maxCascades, frameEmissionRays as rayCount, vdbFrameEmissionProbeGrid, vdbFrameEmitterBounds, } from "../../tools/frame/emission.js";
30
+ import { setVolumeUniforms } from "./renderer.js";
31
+ import { vdbFramePrecompiling, vdbFrameRegisterLightNode, vdbFrameRenderUpdateType, vdbFrameRendererUtils } from "./three-internals.js";
32
+ const { Discard, Fn, If, Loop, Break, abs, clamp, cos, cross, dot, exp, float, floor, int, inverseSqrt, ivec2, luminance, max, min, mix, normalWorld, normalize, outputStruct, positionGeometry, positionWorld, property, renderGroup, select, sin, smoothstep, sqrt, texture, uniform, uniformArray, vec3, vec4 } = TSL;
33
+ // NOTE Probe cascades in the uniform names of createGridNodes. Cascade 0 is the finest.
34
+ const createProbeGridUniforms = (group = null) => {
35
+ const nodes = {
36
+ frameGridMin: uniformArray(Array.from({ length: maxCascades }, () => new THREE.Vector3()), "vec3"),
37
+ frameGridSize: uniformArray(Array.from({ length: maxCascades }, () => new THREE.Vector3(1.0, 1.0, 1.0)), "vec3"),
38
+ frameGridCount: uniform(0, "int"),
39
+ frameGridResolution: uniform(1.0),
40
+ frameGridColumns: uniform(atlasColumns),
41
+ frameGridAtlasSize: uniform(new THREE.Vector2(atlasSize, atlasSize)),
42
+ };
43
+ if (group) {
44
+ Object.values(nodes).forEach((node) => node.setGroup(group));
45
+ }
46
+ return nodes;
47
+ };
48
+ const setProbeGridUniforms = (uniforms, light) => {
49
+ const min = uniforms.frameGridMin.array;
50
+ const size = uniforms.frameGridSize.array;
51
+ for (let i = 0; i < maxCascades; i++) {
52
+ min[i].copy(light.cascadeMin[i]);
53
+ size[i].copy(light.cascadeSize[i]);
54
+ }
55
+ uniforms.frameGridCount.value = light.cascadeCount;
56
+ uniforms.frameGridResolution.value = light.probeResolution;
57
+ };
58
+ const fullscreenPositions = [-1, -1, 0, 3, -1, 0, -1, 3, 0];
59
+ const quadPositions = [-1, -1, 0, 1, -1, 0, 1, 1, 0, -1, -1, 0, 1, 1, 0, -1, 1, 0];
60
+ const createGeometry = (positions) => {
61
+ const geometry = new THREE.BufferGeometry();
62
+ geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
63
+ return geometry;
64
+ };
65
+ const createTarget = (count, type, filter, width = 1, height = 1) => new THREE.RenderTarget(width, height, {
66
+ count,
67
+ type,
68
+ format: THREE.RGBAFormat,
69
+ minFilter: filter,
70
+ magFilter: filter,
71
+ generateMipmaps: false,
72
+ depthBuffer: false,
73
+ });
74
+ const setPassMaterial = (material) => {
75
+ material.side = THREE.DoubleSide;
76
+ material.depthTest = false;
77
+ material.depthWrite = false;
78
+ material.blending = THREE.NoBlending;
79
+ };
80
+ /**
81
+ * Light that one volume sends in each of 16 directions: one texel per direction, one row per volume (slot). Parallel
82
+ * rays cover the bounding sphere; each adds the emission with the volume's transmittance. Output 0: intensity
83
+ * (emission × ray area) and the radius. Output 1: the luminance-weighted world position. One material per volume
84
+ * source (the source is compiled in). Twin: `vdbFrameEmissionDirectionTexel`.
85
+ */
86
+ export class VDBFrameEmissionDirectionMaterial extends NodeMaterial {
87
+ volumeUniforms = createFrameVolumeUniforms();
88
+ sourceUniforms;
89
+ source;
90
+ emissionColor;
91
+ frameSlot = uniform(0.0);
92
+ frameTargetSize = uniform(new THREE.Vector2(directionCount, 1.0));
93
+ frameEmitterCenter = uniform(new THREE.Vector3());
94
+ frameEmitterRadius = uniform(1.0);
95
+ frameSteps = uniform(24, "int");
96
+ mipmaps;
97
+ constructor(o) {
98
+ super();
99
+ this.name = "VDBFrameEmissionDirectionMaterial";
100
+ this.source = o.source;
101
+ this.sourceUniforms = o.sourceUniforms;
102
+ this.mipmaps = o.mipmaps;
103
+ this.emissionColor = o.emissionColor;
104
+ this.buildNodes();
105
+ setPassMaterial(this);
106
+ }
107
+ setMipmaps(mipmaps) {
108
+ if (mipmaps !== this.mipmaps) {
109
+ this.mipmaps = mipmaps;
110
+ this.buildNodes();
111
+ this.needsUpdate = true;
112
+ }
113
+ }
114
+ buildNodes() {
115
+ const volume = vdbVolumeNodes(this.source, this.sourceUniforms, { useMipmaps: this.mipmaps, ...(this.emissionColor ? { emissionColor: this.emissionColor } : {}) });
116
+ const { frameWorldToLocal, frameAbsorbance } = this.volumeUniforms;
117
+ const frameWorldScale = this.sourceUniforms.worldScale;
118
+ const { frameSlot, frameTargetSize, frameEmitterCenter, frameEmitterRadius, frameSteps } = this;
119
+ const outputIntensity = property("vec4");
120
+ const outputCenter = property("vec4");
121
+ // NOTE The quad covers the row of the slot
122
+ this.vertexNode = vec4(positionGeometry.x, frameSlot.add(positionGeometry.y.mul(0.5).add(0.5)).div(frameTargetSize.y).mul(2.0).sub(1.0), 0.0, 1.0);
123
+ this.colorNode = Fn(() => {
124
+ const index = floor(frameFragCoord(frameTargetSize).x).toVar();
125
+ // NOTE Fibonacci sphere direction, from the volume to the viewer
126
+ const y = float(1.0).sub(index.mul(2.0).add(1.0).div(directionCount)).toVar();
127
+ const ring = sqrt(max(0.0, float(1.0).sub(y.mul(y))));
128
+ const phi = index.mul(goldenAngle);
129
+ const direction = vec3(cos(phi).mul(ring), y, sin(phi).mul(ring)).toVar();
130
+ const helper = select(abs(direction.y).lessThan(0.999), vec3(0.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0));
131
+ const tangent = normalize(cross(helper, direction)).toVar();
132
+ const bitangent = cross(direction, tangent).toVar();
133
+ const diameter = frameEmitterRadius.mul(2.0).toVar();
134
+ const spacing = diameter.div(rayCount).toVar();
135
+ const stepCount = float(frameSteps).toVar();
136
+ const intensity = vec3(0.0).toVar();
137
+ const center = vec4(0.0).toVar();
138
+ Loop({ start: int(0), end: int(rayCount * rayCount), type: "int", condition: "<", name: "r" }, ({ r }) => {
139
+ const u = float(r.mod(int(rayCount))).add(0.5).div(rayCount).mul(2.0).sub(1.0);
140
+ const v = float(r.div(int(rayCount))).add(0.5).div(rayCount).mul(2.0).sub(1.0);
141
+ const worldStart = frameEmitterCenter.add(direction.mul(frameEmitterRadius)).add(tangent.mul(u.mul(frameEmitterRadius))).add(bitangent.mul(v.mul(frameEmitterRadius))).toVar();
142
+ const worldEnd = worldStart.sub(direction.mul(diameter)).toVar();
143
+ const localStart = frameWorldToLocal.mul(vec4(worldStart, 1.0)).xyz.toVar();
144
+ const localEnd = frameWorldToLocal.mul(vec4(worldEnd, 1.0)).xyz.toVar();
145
+ const segment = volume.boxSegment(localStart, localEnd).toVar();
146
+ If(segment.x.lessThan(segment.y), () => {
147
+ const segmentLength = segment.y.sub(segment.x).toVar();
148
+ const stepLength = segmentLength.mul(diameter).div(stepCount).toVar();
149
+ // NOTE Smoke uses the mip level of the step. Emission uses level 0: power grows with temperature^4, mipmaps lose it.
150
+ const lod = volume.getLod(stepLength.div(frameWorldScale)).toVar();
151
+ const transmittance = float(1.0).toVar();
152
+ Loop({ start: int(0), end: frameSteps, type: "int", condition: "<", name: "s" }, ({ s }) => {
153
+ const t = segment.x.add(segmentLength.mul(float(s).add(0.5).div(stepCount))).toVar();
154
+ const localPosition = mix(localStart, localEnd, t).toVar();
155
+ const extinction = volume.sampleExtinction(localPosition, lod).toVar();
156
+ If(extinction.greaterThan(0.0), () => {
157
+ // NOTE Absorbance scales the shadow of the volume, the same as for scene lights
158
+ const alpha = float(1.0).sub(exp(extinction.mul(stepLength).negate()));
159
+ const radiance = volume.sampleEmission(localPosition, float(0.0)).mul(transmittance.mul(alpha)).toVar();
160
+ intensity.addAssign(radiance);
161
+ center.addAssign(vec4(mix(worldStart, worldEnd, t), 1.0).mul(luminance(radiance)));
162
+ transmittance.mulAssign(exp(extinction.mul(frameAbsorbance).mul(stepLength).negate()));
163
+ If(transmittance.lessThan(0.01), () => {
164
+ Break();
165
+ });
166
+ });
167
+ });
168
+ });
169
+ });
170
+ const area = spacing.mul(spacing);
171
+ outputIntensity.assign(vec4(intensity.mul(area), frameEmitterRadius));
172
+ outputCenter.assign(center.mul(area));
173
+ return vec4(0.0);
174
+ })();
175
+ this.outputNode = outputStruct(outputIntensity, outputCenter);
176
+ }
177
+ }
178
+ /** One texel per volume: the mean intensity of all directions, and the centre of the visible emission. Twin: `vdbFrameEmissionReduce`. */
179
+ export class VDBFrameEmissionReduceMaterial extends NodeMaterial {
180
+ frameTargetSize = uniform(new THREE.Vector2(1.0, 1.0));
181
+ frameDirectionSize = uniform(new THREE.Vector2(directionCount, 1.0));
182
+ frameDirectionIntensity = texture(new THREE.Texture());
183
+ frameDirectionCenter = texture(new THREE.Texture());
184
+ constructor() {
185
+ super();
186
+ this.name = "VDBFrameEmissionReduceMaterial";
187
+ const outputIntensity = property("vec4");
188
+ const outputCenter = property("vec4");
189
+ this.vertexNode = frameFullscreenVertex;
190
+ this.colorNode = Fn(() => {
191
+ const row = int(floor(frameFragCoord(this.frameTargetSize).y)).toVar();
192
+ const intensity = vec4(0.0).toVar();
193
+ const center = vec4(0.0).toVar();
194
+ Loop(directionCount, ({ i }) => {
195
+ const texel = ivec2(i, row);
196
+ intensity.addAssign(frameLoad(this.frameDirectionIntensity, texel, this.frameDirectionSize));
197
+ center.addAssign(frameLoad(this.frameDirectionCenter, texel, this.frameDirectionSize));
198
+ });
199
+ const visible = center.w.greaterThan(0.0);
200
+ outputIntensity.assign(intensity.div(directionCount));
201
+ outputCenter.assign(select(visible, vec4(center.xyz.div(max(center.w, 1e-12)), 1.0), vec4(0.0)));
202
+ return vec4(0.0);
203
+ })();
204
+ this.outputNode = outputStruct(outputIntensity, outputCenter);
205
+ setPassMaterial(this);
206
+ }
207
+ }
208
+ /**
209
+ * L1 irradiance of all volumes at each probe, E(n) = x + dot(yzw, n) per colour channel: each volume is a point light
210
+ * at its emission centre, its radius softening the distance near it. Twin: `vdbFrameEmissionProbe`.
211
+ */
212
+ export class VDBFrameEmissionProbeMaterial extends NodeMaterial {
213
+ gridUniforms = createProbeGridUniforms();
214
+ frameEmitterCount = uniform(0, "int");
215
+ frameEmitterSize = uniform(new THREE.Vector2(1.0, 1.0));
216
+ frameEmitterIntensity = texture(new THREE.Texture());
217
+ frameEmitterCenter = texture(new THREE.Texture());
218
+ constructor() {
219
+ super();
220
+ this.name = "VDBFrameEmissionProbeMaterial";
221
+ const outputRed = property("vec4");
222
+ const outputGreen = property("vec4");
223
+ const outputBlue = property("vec4");
224
+ const grid = createGridNodes(this.gridUniforms);
225
+ const { frameGridMin, frameGridSize, frameGridCount, frameGridResolution, frameGridAtlasSize } = this.gridUniforms;
226
+ this.vertexNode = frameFullscreenVertex;
227
+ this.colorNode = Fn(() => {
228
+ const fragCoord = frameFragCoord(frameGridAtlasSize).toVar();
229
+ // NOTE Tiles right of the atlas columns are not used. Smaller grids leave them empty.
230
+ If(fragCoord.x.greaterThanEqual(frameGridResolution.mul(atlasColumns)), () => {
231
+ Discard();
232
+ });
233
+ const cell = grid.getGridCell(fragCoord);
234
+ If(cell.cascade.greaterThanEqual(frameGridCount), () => {
235
+ Discard();
236
+ });
237
+ const probe = frameGridMin.element(cell.cascade).add(cell.gridUvw.mul(frameGridSize.element(cell.cascade))).toVar();
238
+ const constant = vec3(0.0).toVar();
239
+ const directionRed = vec3(0.0).toVar();
240
+ const directionGreen = vec3(0.0).toVar();
241
+ const directionBlue = vec3(0.0).toVar();
242
+ Loop(this.frameEmitterCount, ({ i }) => {
243
+ const texel = ivec2(int(0), i);
244
+ const center = frameLoad(this.frameEmitterCenter, texel, this.frameEmitterSize).toVar();
245
+ If(center.w.greaterThan(0.0), () => {
246
+ const emitter = frameLoad(this.frameEmitterIntensity, texel, this.frameEmitterSize).toVar();
247
+ const toProbe = probe.sub(center.xyz).toVar();
248
+ const distanceSquared = dot(toProbe, toProbe).toVar();
249
+ const soft = emitter.w.mul(0.25);
250
+ const softDistanceSquared = distanceSquared.add(soft.mul(soft)).toVar();
251
+ const irradiance = emitter.rgb.div(softDistanceSquared).toVar();
252
+ // NOTE L1 projection of a point light: E(n) = E / 4 + E / 2 * dot(l, n). The direction fades near the centre.
253
+ const toLight = toProbe.mul(inverseSqrt(max(distanceSquared, 1e-12))).mul(distanceSquared.div(softDistanceSquared).mul(-0.5)).toVar();
254
+ constant.addAssign(irradiance.mul(0.25));
255
+ directionRed.addAssign(toLight.mul(irradiance.r));
256
+ directionGreen.addAssign(toLight.mul(irradiance.g));
257
+ directionBlue.addAssign(toLight.mul(irradiance.b));
258
+ });
259
+ });
260
+ outputRed.assign(vec4(constant.r, directionRed));
261
+ outputGreen.assign(vec4(constant.g, directionGreen));
262
+ outputBlue.assign(vec4(constant.b, directionBlue));
263
+ return vec4(0.0);
264
+ })();
265
+ this.outputNode = outputStruct(outputRed, outputGreen, outputBlue);
266
+ setPassMaterial(this);
267
+ }
268
+ }
269
+ /**
270
+ * The irradiance at a lit point from the finest probe cascade that contains it; near a cascade side the next one
271
+ * blends in (as the shadow grid); past the last cascade its clamped edge probes fall off with distance squared.
272
+ */
273
+ export class VDBFrameEmissionLightNode extends AnalyticLightNode {
274
+ static get type() {
275
+ return "VDBFrameEmissionLightNode";
276
+ }
277
+ probeMaps;
278
+ gridUniforms;
279
+ probeCenter;
280
+ probeActive;
281
+ constructor(light = null) {
282
+ super(light);
283
+ // NOTE The passes run before the first lit mesh of each render, as shadow maps
284
+ const render = vdbFrameRenderUpdateType();
285
+ this.updateType = render;
286
+ this.updateBeforeType = render;
287
+ const maps = light ? light.probeTarget.textures : [new THREE.Texture(), new THREE.Texture(), new THREE.Texture()];
288
+ this.probeMaps = maps.map((map) => texture(map));
289
+ // NOTE Render group, as three's lights: lit materials without node changes update only shared uniforms
290
+ this.gridUniforms = createProbeGridUniforms(renderGroup);
291
+ this.probeCenter = uniform(new THREE.Vector3()).setGroup(renderGroup);
292
+ this.probeActive = uniform(0.0).setGroup(renderGroup);
293
+ }
294
+ get emissionLight() {
295
+ return this.light;
296
+ }
297
+ updateBefore(frame) {
298
+ const { renderer, scene, camera } = frame;
299
+ // NOTE No passes while three precompiles materials (compileAsync), as shadow maps
300
+ if (vdbFramePrecompiling(renderer)) {
301
+ return undefined;
302
+ }
303
+ this.emissionLight.updateProbes(renderer, scene, camera);
304
+ return undefined;
305
+ }
306
+ update(frame) {
307
+ super.update(frame);
308
+ const light = this.emissionLight;
309
+ setProbeGridUniforms(this.gridUniforms, light);
310
+ this.probeCenter.value.copy(light.probeCenter);
311
+ this.probeActive.value = light.emitterCount > 0 ? 1.0 : 0.0;
312
+ return undefined;
313
+ }
314
+ setup(builder) {
315
+ const grid = createGridNodes(this.gridUniforms);
316
+ const { frameGridMin, frameGridSize, frameGridCount, frameGridResolution } = this.gridUniforms;
317
+ const { probeCenter, probeActive } = this;
318
+ const [redMap, greenMap, blueMap] = this.probeMaps;
319
+ const irradiance = Fn(() => {
320
+ const position = positionWorld.toVar();
321
+ const red = vec4(0.0).toVar();
322
+ const green = vec4(0.0).toVar();
323
+ const blue = vec4(0.0).toVar();
324
+ const falloff = float(1.0).toVar();
325
+ const sampleProbes = (cascade, uvw, weight) => {
326
+ red.assign(mix(red, grid.sampleGrid(redMap, cascade, uvw), weight));
327
+ green.assign(mix(green, grid.sampleGrid(greenMap, cascade, uvw), weight));
328
+ blue.assign(mix(blue, grid.sampleGrid(blueMap, cascade, uvw), weight));
329
+ };
330
+ If(frameGridCount.greaterThan(0), () => {
331
+ const cascade = grid.findCascade(position, int(0)).toVar();
332
+ If(cascade.greaterThanEqual(0), () => {
333
+ const uvw = grid.gridUvw(cascade, position).toVar();
334
+ sampleProbes(cascade, uvw, float(1.0));
335
+ const sideDistance = min(uvw, vec3(1.0).sub(uvw));
336
+ const blend = float(1.0).sub(smoothstep(0.0, 0.1, min(sideDistance.x, min(sideDistance.y, sideDistance.z)))).toVar();
337
+ If(blend.greaterThan(0.0), () => {
338
+ const nextCascade = grid.findCascade(position, cascade.add(1)).toVar();
339
+ If(nextCascade.greaterThanEqual(0), () => {
340
+ sampleProbes(nextCascade, grid.gridUvw(nextCascade, position), blend);
341
+ });
342
+ });
343
+ }).Else(() => {
344
+ const lastCascade = frameGridCount.sub(1).toVar();
345
+ const inset = float(0.5).div(frameGridResolution);
346
+ const uvw = clamp(grid.gridUvw(lastCascade, position), vec3(inset), vec3(float(1.0).sub(inset))).toVar();
347
+ const toEdge = frameGridMin.element(lastCascade).add(uvw.mul(frameGridSize.element(lastCascade))).sub(probeCenter);
348
+ const toPoint = position.sub(probeCenter);
349
+ sampleProbes(lastCascade, uvw, float(1.0));
350
+ falloff.assign(min(1.0, dot(toEdge, toEdge).div(max(dot(toPoint, toPoint), 1e-6))));
351
+ });
352
+ });
353
+ const normal = normalWorld;
354
+ return max(vec3(red.x.add(dot(red.yzw, normal)), green.x.add(dot(green.yzw, normal)), blue.x.add(dot(blue.yzw, normal))), vec3(0.0)).mul(falloff.mul(probeActive));
355
+ })();
356
+ const b = builder;
357
+ const colorNode = this.colorNode;
358
+ b.context.irradiance.addAssign(colorNode.mul(irradiance));
359
+ return null;
360
+ }
361
+ }
362
+ const unitBox = new THREE.Box3(new THREE.Vector3(-0.5, -0.5, -0.5), new THREE.Vector3(0.5, 0.5, 0.5));
363
+ const cameraPosition = new THREE.Vector3();
364
+ const createEmitter = () => ({
365
+ frameVolume: null,
366
+ key: "",
367
+ matrix: new THREE.Matrix4(),
368
+ matrixWorld: new THREE.Matrix4(),
369
+ worldToLocal: new THREE.Matrix4(),
370
+ localToView: new THREE.Matrix4(),
371
+ viewToLocal: new THREE.Matrix4(),
372
+ worldBox: new THREE.Box3(),
373
+ viewNear: 0,
374
+ viewFar: 0,
375
+ ready: true,
376
+ center: new THREE.Vector3(),
377
+ radius: 0.0,
378
+ });
379
+ // NOTE An id for each source object (the emitter key: a new source or a replaced grid draws again)
380
+ const sourceIds = new WeakMap();
381
+ let nextSourceId = 1;
382
+ const sourceKey = (frameVolume) => {
383
+ const source = frameVolume.source;
384
+ let id = sourceIds.get(source);
385
+ if (id === undefined) {
386
+ id = nextSourceId++;
387
+ sourceIds.set(source, id);
388
+ }
389
+ const values = [id, source.version ?? -1, source.lodLevels, source.lod ?? "-"];
390
+ if (source.textures) {
391
+ for (const name of ["density", "mask", "emission"]) {
392
+ const t = source.textures[name];
393
+ values.push(t ? `${t.map.id}.${t.map.version}` : "-", t?.mip ? `${t.mip.id}.${t.mip.version}` : "-");
394
+ }
395
+ }
396
+ // NOTE The colour hook's runtime value (vdbFrameBlackbodyEmission: the soot exponent)
397
+ const hook = frameVolume.emissionColor;
398
+ values.push(hook?.sootExponent ? hook.sootExponent.value : "-");
399
+ return values.join(":");
400
+ };
401
+ /** One registration of the light node class (internal 4), checked at the first construction. */
402
+ let registered = false;
403
+ export class VDBFrameEmissionLight extends THREE.Light {
404
+ isVDBFrameEmissionLight = true;
405
+ resolution;
406
+ range;
407
+ cascades;
408
+ distance;
409
+ steps;
410
+ cascadeMin = Array.from({ length: maxCascades }, () => new THREE.Vector3());
411
+ cascadeSize = Array.from({ length: maxCascades }, () => new THREE.Vector3(1.0, 1.0, 1.0));
412
+ cascadeCount = 0;
413
+ probeResolution = 2;
414
+ probeCenter = new THREE.Vector3();
415
+ emitters = [];
416
+ emitterCount = 0;
417
+ slotKeys = [];
418
+ slotCount = 0;
419
+ probeKey = "";
420
+ // NOTE Float targets for the volumes: intensities in world units do not overflow
421
+ directionTarget = createTarget(2, THREE.FloatType, THREE.NearestFilter);
422
+ emitterTarget = createTarget(2, THREE.FloatType, THREE.NearestFilter);
423
+ // NOTE The probe atlas has the size for the largest grid and all cascades: lit materials keep its binding
424
+ probeTarget = createTarget(3, THREE.HalfFloatType, THREE.LinearFilter, atlasSize, atlasSize);
425
+ // NOTE One draw for each changed volume, in one render
426
+ directionScene = new THREE.Scene();
427
+ directionPool = [];
428
+ reduceMaterial = new VDBFrameEmissionReduceMaterial();
429
+ probeMaterial = new VDBFrameEmissionProbeMaterial();
430
+ reduceScene;
431
+ probeScene;
432
+ // NOTE WebGPURenderer calls updateProjectionMatrix() on the camera
433
+ passCamera = new THREE.OrthographicCamera();
434
+ // NOTE RendererUtils fills this object
435
+ rendererState = {};
436
+ /** Volumes drawn in the last probe update and whether the probes were drawn (not his; tests and timing). */
437
+ lastUpdate = { directions: 0, probes: false };
438
+ constructor(props = {}) {
439
+ const { color = 0xffffff, intensity = 1.0, resolution = 16, range = 3.0, cascades = 1, distance = 512, steps = 24 } = props;
440
+ super(color, intensity);
441
+ if (!registered) {
442
+ vdbFrameRegisterLightNode(VDBFrameEmissionLight, VDBFrameEmissionLightNode);
443
+ registered = true;
444
+ }
445
+ this.type = "VDBFrameEmissionLight";
446
+ this.resolution = resolution;
447
+ this.range = range;
448
+ this.cascades = cascades;
449
+ this.distance = distance;
450
+ this.steps = steps;
451
+ this.directionScene.matrixWorldAutoUpdate = false;
452
+ const createPassScene = (material) => {
453
+ const scene = new THREE.Scene();
454
+ const mesh = new THREE.Mesh(createGeometry(fullscreenPositions), material);
455
+ mesh.frustumCulled = false;
456
+ scene.matrixWorldAutoUpdate = false;
457
+ scene.add(mesh);
458
+ return scene;
459
+ };
460
+ this.reduceScene = createPassScene(this.reduceMaterial);
461
+ this.probeScene = createPassScene(this.probeMaterial);
462
+ }
463
+ getSteps() {
464
+ return Math.max(1, Math.round(this.steps));
465
+ }
466
+ /** The direction-pass material of a volume (its source compiled in), made on first use. */
467
+ getDirectionMaterial(frameVolume) {
468
+ const mipmaps = frameVolume.mipmaps && frameVolume.source.lodLevels > 0;
469
+ let material = frameVolume.emissionDirectionMaterial;
470
+ if (!material) {
471
+ material = new VDBFrameEmissionDirectionMaterial({ source: frameVolume.source, sourceUniforms: frameVolume.sourceUniforms, mipmaps, ...(frameVolume.emissionColor ? { emissionColor: frameVolume.emissionColor } : {}) });
472
+ frameVolume.emissionDirectionMaterial = material;
473
+ }
474
+ material.setMipmaps(mipmaps);
475
+ return material;
476
+ }
477
+ // NOTE Emissive volumes of the scene (visible, with an emission channel)
478
+ collectEmitters(scene) {
479
+ let count = 0;
480
+ const steps = this.getSteps();
481
+ scene.traverseVisible((object) => {
482
+ const frameVolume = object;
483
+ if (!frameVolume.isVDBFrameVolume || !frameVolume.source.channels.emission) {
484
+ return;
485
+ }
486
+ for (const volume of frameVolume.volumes) {
487
+ if (!volume.ready) {
488
+ continue;
489
+ }
490
+ if (!this.emitters[count]) {
491
+ this.emitters[count] = createEmitter();
492
+ }
493
+ const emitter = this.emitters[count++];
494
+ emitter.frameVolume = frameVolume;
495
+ emitter.matrixWorld.multiplyMatrices(frameVolume.matrixWorld, volume.matrix);
496
+ emitter.worldToLocal.copy(emitter.matrixWorld).invert();
497
+ emitter.worldBox.copy(unitBox).applyMatrix4(emitter.matrixWorld);
498
+ const bounds = vdbFrameEmitterBounds(emitter.matrixWorld.elements);
499
+ emitter.center.fromArray(bounds.center);
500
+ emitter.radius = bounds.radius;
501
+ emitter.key = [
502
+ sourceKey(frameVolume),
503
+ frameVolume.extinction,
504
+ frameVolume.getDensityScale(),
505
+ frameVolume.densityCutoff,
506
+ frameVolume.absorbance,
507
+ frameVolume.emissiveIntensity,
508
+ frameVolume.temperatureRange.x,
509
+ frameVolume.temperatureRange.y,
510
+ frameVolume.offset3D.x,
511
+ frameVolume.offset3D.y,
512
+ frameVolume.offset3D.z,
513
+ frameVolume.wrap3D,
514
+ frameVolume.mipmaps,
515
+ steps,
516
+ ...emitter.matrixWorld.elements,
517
+ ].join(",");
518
+ }
519
+ });
520
+ this.emitterCount = count;
521
+ }
522
+ // NOTE The probe cascades (tools/frame/emission.ts). Returns a key that changes with them.
523
+ updateProbeGrid(camera) {
524
+ cameraPosition.setFromMatrixPosition(camera.matrixWorld);
525
+ const boxes = this.emitters.slice(0, this.emitterCount).map((e) => ({ min: e.worldBox.min.toArray(), max: e.worldBox.max.toArray() }));
526
+ const grid = vdbFrameEmissionProbeGrid({ resolution: this.resolution, range: this.range, cascades: this.cascades, distance: this.distance }, boxes, cameraPosition.toArray());
527
+ this.probeResolution = grid.resolution;
528
+ this.probeCenter.fromArray(grid.center);
529
+ for (let i = 0; i < grid.count; i++) {
530
+ this.cascadeMin[i].fromArray(grid.min[i]);
531
+ this.cascadeSize[i].fromArray(grid.size[i]);
532
+ }
533
+ this.cascadeCount = grid.count;
534
+ return grid.key;
535
+ }
536
+ // NOTE The changed volumes as { emitter, slot }, or null when the probes stay the same.
537
+ // Slots grow to the next power of two. New targets are empty, so all volumes draw again.
538
+ prepareProbes(scene, camera) {
539
+ this.collectEmitters(scene);
540
+ if (this.emitterCount > this.slotCount) {
541
+ this.slotCount = Math.pow(2, Math.ceil(Math.log2(this.emitterCount)));
542
+ this.slotKeys = [];
543
+ this.resizeSlots();
544
+ }
545
+ const changed = [];
546
+ for (let i = 0; i < this.emitterCount; i++) {
547
+ const emitter = this.emitters[i];
548
+ if (this.slotKeys[i] !== emitter.key) {
549
+ this.slotKeys[i] = emitter.key;
550
+ changed.push({ emitter, slot: i });
551
+ }
552
+ }
553
+ if (this.emitterCount === 0) {
554
+ this.probeKey = "";
555
+ return null;
556
+ }
557
+ const probeKey = `${this.emitterCount},${this.updateProbeGrid(camera)}`;
558
+ if (changed.length === 0 && probeKey === this.probeKey) {
559
+ return null;
560
+ }
561
+ this.probeKey = probeKey;
562
+ return changed;
563
+ }
564
+ // NOTE New targets, because setSize() destroys the GPU textures that materials still bind
565
+ resizeSlots() {
566
+ this.directionTarget.dispose();
567
+ this.emitterTarget.dispose();
568
+ this.directionTarget = createTarget(2, THREE.FloatType, THREE.NearestFilter, directionCount, this.slotCount);
569
+ this.emitterTarget = createTarget(2, THREE.FloatType, THREE.NearestFilter, 1, this.slotCount);
570
+ }
571
+ getDirectionMesh(index) {
572
+ if (!this.directionPool[index]) {
573
+ const mesh = new THREE.Mesh(createGeometry(quadPositions), new THREE.MeshBasicMaterial());
574
+ mesh.frustumCulled = false;
575
+ mesh.matrixAutoUpdate = false;
576
+ mesh.onBeforeRender = () => {
577
+ const { emitter, slot } = mesh.userData;
578
+ const material = mesh.material;
579
+ setVolumeUniforms(material, emitter.frameVolume, emitter);
580
+ material.frameSlot.value = slot;
581
+ material.frameTargetSize.value.set(directionCount, this.slotCount);
582
+ material.frameEmitterCenter.value.copy(emitter.center);
583
+ material.frameEmitterRadius.value = emitter.radius;
584
+ material.frameSteps.value = this.getSteps();
585
+ };
586
+ this.directionScene.add(mesh);
587
+ this.directionPool[index] = mesh;
588
+ }
589
+ return this.directionPool[index];
590
+ }
591
+ /** Runs the passes of changed volumes. The light node calls it before the lit meshes of each render. */
592
+ updateProbes(renderer, scene, viewCamera) {
593
+ this.lastUpdate.directions = 0;
594
+ this.lastUpdate.probes = false;
595
+ const changed = this.prepareProbes(scene, viewCamera);
596
+ if (!changed) {
597
+ return;
598
+ }
599
+ changed.forEach(({ emitter, slot }, index) => {
600
+ const mesh = this.getDirectionMesh(index);
601
+ mesh.material = this.getDirectionMaterial(emitter.frameVolume);
602
+ mesh.userData.emitter = emitter;
603
+ mesh.userData.slot = slot;
604
+ });
605
+ const { reduceMaterial, probeMaterial, reduceScene, probeScene, passCamera: camera } = this;
606
+ const utils = vdbFrameRendererUtils();
607
+ this.rendererState = utils.resetRendererState(renderer, this.rendererState);
608
+ // NOTE Each pass writes all its texels. Rows of volumes that did not change stay.
609
+ renderer.autoClear = false;
610
+ try {
611
+ if (changed.length > 0) {
612
+ this.directionPool.forEach((mesh, index) => {
613
+ mesh.visible = index < changed.length;
614
+ });
615
+ renderer.setRenderTarget(this.directionTarget);
616
+ renderer.render(this.directionScene, camera);
617
+ reduceMaterial.frameTargetSize.value.set(1, this.slotCount);
618
+ reduceMaterial.frameDirectionSize.value.set(directionCount, this.slotCount);
619
+ reduceMaterial.frameDirectionIntensity.value = this.directionTarget.textures[0];
620
+ reduceMaterial.frameDirectionCenter.value = this.directionTarget.textures[1];
621
+ renderer.setRenderTarget(this.emitterTarget);
622
+ renderer.render(reduceScene, camera);
623
+ }
624
+ setProbeGridUniforms(probeMaterial.gridUniforms, this);
625
+ probeMaterial.frameEmitterCount.value = this.emitterCount;
626
+ probeMaterial.frameEmitterSize.value.set(1, this.slotCount);
627
+ probeMaterial.frameEmitterIntensity.value = this.emitterTarget.textures[0];
628
+ probeMaterial.frameEmitterCenter.value = this.emitterTarget.textures[1];
629
+ renderer.setRenderTarget(this.probeTarget);
630
+ renderer.render(probeScene, camera);
631
+ this.lastUpdate.directions = changed.length;
632
+ this.lastUpdate.probes = true;
633
+ }
634
+ finally {
635
+ utils.restoreRendererState(renderer, this.rendererState);
636
+ }
637
+ }
638
+ dispose() {
639
+ super.dispose();
640
+ this.slotKeys = [];
641
+ this.slotCount = 0;
642
+ this.probeKey = "";
643
+ this.directionTarget.dispose();
644
+ this.emitterTarget.dispose();
645
+ this.probeTarget.dispose();
646
+ this.directionPool.forEach((mesh) => mesh.geometry.dispose());
647
+ this.directionPool = [];
648
+ this.reduceMaterial.dispose();
649
+ this.probeMaterial.dispose();
650
+ for (const scene of [this.reduceScene, this.probeScene]) {
651
+ scene.children[0]?.geometry.dispose();
652
+ }
653
+ }
654
+ }
655
+ //# sourceMappingURL=emission-light.js.map