@pmndrs/vdb 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (570) hide show
  1. package/CHANGELOG.md +727 -0
  2. package/LICENSE +21 -0
  3. package/README.md +496 -2
  4. package/THIRD_PARTY_NOTICES.md +315 -0
  5. package/dist/core/compute/atlas.d.ts +102 -0
  6. package/dist/core/compute/atlas.js +103 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/majorant-build.d.ts +45 -0
  12. package/dist/core/compute/majorant-build.js +193 -0
  13. package/dist/core/compute/majorant-build.js.map +1 -0
  14. package/dist/core/compute/multi-scale.d.ts +155 -0
  15. package/dist/core/compute/multi-scale.js +684 -0
  16. package/dist/core/compute/multi-scale.js.map +1 -0
  17. package/dist/core/compute/pyramid.d.ts +120 -0
  18. package/dist/core/compute/pyramid.js +468 -0
  19. package/dist/core/compute/pyramid.js.map +1 -0
  20. package/dist/core/compute/shared.d.ts +116 -0
  21. package/dist/core/compute/shared.js +211 -0
  22. package/dist/core/compute/shared.js.map +1 -0
  23. package/dist/core/compute/stats.d.ts +78 -0
  24. package/dist/core/compute/stats.js +193 -0
  25. package/dist/core/compute/stats.js.map +1 -0
  26. package/dist/core/compute/value-transform.d.ts +30 -0
  27. package/dist/core/compute/value-transform.js +64 -0
  28. package/dist/core/compute/value-transform.js.map +1 -0
  29. package/dist/core/errors.d.ts +21 -0
  30. package/dist/core/errors.js +17 -0
  31. package/dist/core/errors.js.map +1 -0
  32. package/dist/core/frame/emission.d.ts +85 -0
  33. package/dist/core/frame/emission.js +422 -0
  34. package/dist/core/frame/emission.js.map +1 -0
  35. package/dist/core/frame/environment.d.ts +47 -0
  36. package/dist/core/frame/environment.js +178 -0
  37. package/dist/core/frame/environment.js.map +1 -0
  38. package/dist/core/frame/index.d.ts +39 -0
  39. package/dist/core/frame/index.js +27 -0
  40. package/dist/core/frame/index.js.map +1 -0
  41. package/dist/core/frame/kernels.d.ts +115 -0
  42. package/dist/core/frame/kernels.js +496 -0
  43. package/dist/core/frame/kernels.js.map +1 -0
  44. package/dist/core/frame/limits.d.ts +67 -0
  45. package/dist/core/frame/limits.js +109 -0
  46. package/dist/core/frame/limits.js.map +1 -0
  47. package/dist/core/frame/phase.d.ts +17 -0
  48. package/dist/core/frame/phase.js +53 -0
  49. package/dist/core/frame/phase.js.map +1 -0
  50. package/dist/core/frame/pipelines.d.ts +49 -0
  51. package/dist/core/frame/pipelines.js +147 -0
  52. package/dist/core/frame/pipelines.js.map +1 -0
  53. package/dist/core/frame/renderer.d.ts +122 -0
  54. package/dist/core/frame/renderer.js +1712 -0
  55. package/dist/core/frame/renderer.js.map +1 -0
  56. package/dist/core/frame/resources.d.ts +71 -0
  57. package/dist/core/frame/resources.js +100 -0
  58. package/dist/core/frame/resources.js.map +1 -0
  59. package/dist/core/frame/scattering.d.ts +97 -0
  60. package/dist/core/frame/scattering.js +332 -0
  61. package/dist/core/frame/scattering.js.map +1 -0
  62. package/dist/core/frame/settings.d.ts +243 -0
  63. package/dist/core/frame/settings.js +67 -0
  64. package/dist/core/frame/settings.js.map +1 -0
  65. package/dist/core/frame/shadows.d.ts +55 -0
  66. package/dist/core/frame/shadows.js +460 -0
  67. package/dist/core/frame/shadows.js.map +1 -0
  68. package/dist/core/frame/types.d.ts +415 -0
  69. package/dist/core/frame/types.js +49 -0
  70. package/dist/core/frame/types.js.map +1 -0
  71. package/dist/core/frame/uniforms.d.ts +105 -0
  72. package/dist/core/frame/uniforms.js +276 -0
  73. package/dist/core/frame/uniforms.js.map +1 -0
  74. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  75. package/dist/core/frame/wgsl/chunks.js +728 -0
  76. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  77. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  78. package/dist/core/frame/wgsl/emission.js +353 -0
  79. package/dist/core/frame/wgsl/emission.js.map +1 -0
  80. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  81. package/dist/core/frame/wgsl/environment.js +711 -0
  82. package/dist/core/frame/wgsl/environment.js.map +1 -0
  83. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  84. package/dist/core/frame/wgsl/gather.js +850 -0
  85. package/dist/core/frame/wgsl/gather.js.map +1 -0
  86. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  87. package/dist/core/frame/wgsl/integrate.js +213 -0
  88. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  89. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  90. package/dist/core/frame/wgsl/lighting.js +1636 -0
  91. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  92. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  93. package/dist/core/frame/wgsl/occluders.js +95 -0
  94. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  95. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  96. package/dist/core/frame/wgsl/resolve.js +205 -0
  97. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  98. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  99. package/dist/core/frame/wgsl/shadows.js +328 -0
  100. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  101. package/dist/core/half.d.ts +11 -0
  102. package/dist/core/half.js +22 -0
  103. package/dist/core/half.js.map +1 -0
  104. package/dist/core/index.d.ts +52 -0
  105. package/dist/core/index.js +46 -0
  106. package/dist/core/index.js.map +1 -0
  107. package/dist/core/internal.d.ts +31 -0
  108. package/dist/core/internal.js +32 -0
  109. package/dist/core/internal.js.map +1 -0
  110. package/dist/core/pool/affine.d.ts +34 -0
  111. package/dist/core/pool/affine.js +100 -0
  112. package/dist/core/pool/affine.js.map +1 -0
  113. package/dist/core/pool/allocator.d.ts +32 -0
  114. package/dist/core/pool/allocator.js +81 -0
  115. package/dist/core/pool/allocator.js.map +1 -0
  116. package/dist/core/pool/image-header.d.ts +93 -0
  117. package/dist/core/pool/image-header.js +194 -0
  118. package/dist/core/pool/image-header.js.map +1 -0
  119. package/dist/core/pool/layout.d.ts +198 -0
  120. package/dist/core/pool/layout.js +316 -0
  121. package/dist/core/pool/layout.js.map +1 -0
  122. package/dist/core/pool/limits.d.ts +41 -0
  123. package/dist/core/pool/limits.js +80 -0
  124. package/dist/core/pool/limits.js.map +1 -0
  125. package/dist/core/pool/pool.d.ts +384 -0
  126. package/dist/core/pool/pool.js +1184 -0
  127. package/dist/core/pool/pool.js.map +1 -0
  128. package/dist/core/reference/index.d.ts +6 -0
  129. package/dist/core/reference/index.js +7 -0
  130. package/dist/core/reference/index.js.map +1 -0
  131. package/dist/core/reference/renderer.d.ts +105 -0
  132. package/dist/core/reference/renderer.js +474 -0
  133. package/dist/core/reference/renderer.js.map +1 -0
  134. package/dist/core/reference/wgsl.d.ts +65 -0
  135. package/dist/core/reference/wgsl.js +803 -0
  136. package/dist/core/reference/wgsl.js.map +1 -0
  137. package/dist/core/sequence.d.ts +347 -0
  138. package/dist/core/sequence.js +548 -0
  139. package/dist/core/sequence.js.map +1 -0
  140. package/dist/core/source/brick-cache.d.ts +165 -0
  141. package/dist/core/source/brick-cache.js +627 -0
  142. package/dist/core/source/brick-cache.js.map +1 -0
  143. package/dist/core/source/dense-fill.d.ts +53 -0
  144. package/dist/core/source/dense-fill.js +377 -0
  145. package/dist/core/source/dense-fill.js.map +1 -0
  146. package/dist/core/source/dense.d.ts +50 -0
  147. package/dist/core/source/dense.js +384 -0
  148. package/dist/core/source/dense.js.map +1 -0
  149. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  150. package/dist/core/source/sparse-wgsl.js +481 -0
  151. package/dist/core/source/sparse-wgsl.js.map +1 -0
  152. package/dist/core/source/sparse.d.ts +192 -0
  153. package/dist/core/source/sparse.js +762 -0
  154. package/dist/core/source/sparse.js.map +1 -0
  155. package/dist/core/source/types.d.ts +120 -0
  156. package/dist/core/source/types.js +9 -0
  157. package/dist/core/source/types.js.map +1 -0
  158. package/dist/core/surface/index.d.ts +10 -0
  159. package/dist/core/surface/index.js +9 -0
  160. package/dist/core/surface/index.js.map +1 -0
  161. package/dist/core/surface/level-set-pass.d.ts +140 -0
  162. package/dist/core/surface/level-set-pass.js +291 -0
  163. package/dist/core/surface/level-set-pass.js.map +1 -0
  164. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  165. package/dist/core/surface/level-set-wgsl.js +99 -0
  166. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  167. package/dist/core/surface/points.d.ts +109 -0
  168. package/dist/core/surface/points.js +226 -0
  169. package/dist/core/surface/points.js.map +1 -0
  170. package/dist/core/types.d.ts +37 -0
  171. package/dist/core/types.js +32 -0
  172. package/dist/core/types.js.map +1 -0
  173. package/dist/core/wgsl/api.d.ts +65 -0
  174. package/dist/core/wgsl/api.js +546 -0
  175. package/dist/core/wgsl/api.js.map +1 -0
  176. package/dist/core/wgsl/generate.d.ts +90 -0
  177. package/dist/core/wgsl/generate.js +678 -0
  178. package/dist/core/wgsl/generate.js.map +1 -0
  179. package/dist/core/wgsl/lean.d.ts +50 -0
  180. package/dist/core/wgsl/lean.js +327 -0
  181. package/dist/core/wgsl/lean.js.map +1 -0
  182. package/dist/core/wgsl/level-set.d.ts +58 -0
  183. package/dist/core/wgsl/level-set.js +200 -0
  184. package/dist/core/wgsl/level-set.js.map +1 -0
  185. package/dist/core/wgsl/majorant.d.ts +62 -0
  186. package/dist/core/wgsl/majorant.js +381 -0
  187. package/dist/core/wgsl/majorant.js.map +1 -0
  188. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  189. package/dist/core/wgsl/pnanovdb.chunks.generated.js +333 -0
  190. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  191. package/dist/core/wgsl/reserved.d.ts +9 -0
  192. package/dist/core/wgsl/reserved.js +26 -0
  193. package/dist/core/wgsl/reserved.js.map +1 -0
  194. package/dist/core/wgsl/types.d.ts +198 -0
  195. package/dist/core/wgsl/types.js +2 -0
  196. package/dist/core/wgsl/types.js.map +1 -0
  197. package/dist/three/coarse-first.d.ts +207 -0
  198. package/dist/three/coarse-first.js +205 -0
  199. package/dist/three/coarse-first.js.map +1 -0
  200. package/dist/three/compute.d.ts +73 -0
  201. package/dist/three/compute.js +66 -0
  202. package/dist/three/compute.js.map +1 -0
  203. package/dist/three/device.d.ts +66 -0
  204. package/dist/three/device.js +62 -0
  205. package/dist/three/device.js.map +1 -0
  206. package/dist/three/frame/core-environment.d.ts +38 -0
  207. package/dist/three/frame/core-environment.js +154 -0
  208. package/dist/three/frame/core-environment.js.map +1 -0
  209. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  210. package/dist/three/frame/core-integrate-material.js +162 -0
  211. package/dist/three/frame/core-integrate-material.js.map +1 -0
  212. package/dist/three/frame/core-occluders.d.ts +53 -0
  213. package/dist/three/frame/core-occluders.js +193 -0
  214. package/dist/three/frame/core-occluders.js.map +1 -0
  215. package/dist/three/frame/core-structs.d.ts +34 -0
  216. package/dist/three/frame/core-structs.js +61 -0
  217. package/dist/three/frame/core-structs.js.map +1 -0
  218. package/dist/three/frame/core-textures.d.ts +41 -0
  219. package/dist/three/frame/core-textures.js +114 -0
  220. package/dist/three/frame/core-textures.js.map +1 -0
  221. package/dist/three/frame/emission-light.d.ts +117 -0
  222. package/dist/three/frame/emission-light.js +276 -0
  223. package/dist/three/frame/emission-light.js.map +1 -0
  224. package/dist/three/frame/index.d.ts +19 -0
  225. package/dist/three/frame/index.js +15 -0
  226. package/dist/three/frame/index.js.map +1 -0
  227. package/dist/three/frame/medium.d.ts +33 -0
  228. package/dist/three/frame/medium.js +29 -0
  229. package/dist/three/frame/medium.js.map +1 -0
  230. package/dist/three/frame/renderer.d.ts +97 -0
  231. package/dist/three/frame/renderer.js +480 -0
  232. package/dist/three/frame/renderer.js.map +1 -0
  233. package/dist/three/frame/spectrum.d.ts +4 -0
  234. package/dist/three/frame/spectrum.js +15 -0
  235. package/dist/three/frame/spectrum.js.map +1 -0
  236. package/dist/three/frame/three-internals.d.ts +60 -0
  237. package/dist/three/frame/three-internals.js +152 -0
  238. package/dist/three/frame/three-internals.js.map +1 -0
  239. package/dist/three/frame/volume-shadows.d.ts +139 -0
  240. package/dist/three/frame/volume-shadows.js +403 -0
  241. package/dist/three/frame/volume-shadows.js.map +1 -0
  242. package/dist/three/frame/volume.d.ts +230 -0
  243. package/dist/three/frame/volume.js +268 -0
  244. package/dist/three/frame/volume.js.map +1 -0
  245. package/dist/three/grid-node.d.ts +229 -0
  246. package/dist/three/grid-node.js +545 -0
  247. package/dist/three/grid-node.js.map +1 -0
  248. package/dist/three/index.d.ts +52 -0
  249. package/dist/three/index.js +58 -0
  250. package/dist/three/index.js.map +1 -0
  251. package/dist/three/internal.d.ts +20 -0
  252. package/dist/three/internal.js +18 -0
  253. package/dist/three/internal.js.map +1 -0
  254. package/dist/three/level-set-material.d.ts +185 -0
  255. package/dist/three/level-set-material.js +241 -0
  256. package/dist/three/level-set-material.js.map +1 -0
  257. package/dist/three/level-set-physical-material.d.ts +154 -0
  258. package/dist/three/level-set-physical-material.js +253 -0
  259. package/dist/three/level-set-physical-material.js.map +1 -0
  260. package/dist/three/level-set-velocity.d.ts +94 -0
  261. package/dist/three/level-set-velocity.js +208 -0
  262. package/dist/three/level-set-velocity.js.map +1 -0
  263. package/dist/three/material.d.ts +324 -0
  264. package/dist/three/material.js +502 -0
  265. package/dist/three/material.js.map +1 -0
  266. package/dist/three/points.d.ts +140 -0
  267. package/dist/three/points.js +261 -0
  268. package/dist/three/points.js.map +1 -0
  269. package/dist/three/sparse-source.d.ts +165 -0
  270. package/dist/three/sparse-source.js +405 -0
  271. package/dist/three/sparse-source.js.map +1 -0
  272. package/dist/three/volume-source.d.ts +22 -0
  273. package/dist/three/volume-source.js +110 -0
  274. package/dist/three/volume-source.js.map +1 -0
  275. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  276. package/dist/tools/cpu/brick-atlas.js +129 -0
  277. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  278. package/dist/tools/cpu/compute.d.ts +116 -0
  279. package/dist/tools/cpu/compute.js +239 -0
  280. package/dist/tools/cpu/compute.js.map +1 -0
  281. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  282. package/dist/tools/cpu/lean-reads.js +262 -0
  283. package/dist/tools/cpu/lean-reads.js.map +1 -0
  284. package/dist/tools/cpu/level-set.d.ts +111 -0
  285. package/dist/tools/cpu/level-set.js +313 -0
  286. package/dist/tools/cpu/level-set.js.map +1 -0
  287. package/dist/tools/cpu/majorant.d.ts +265 -0
  288. package/dist/tools/cpu/majorant.js +541 -0
  289. package/dist/tools/cpu/majorant.js.map +1 -0
  290. package/dist/tools/cpu/march.d.ts +297 -0
  291. package/dist/tools/cpu/march.js +726 -0
  292. package/dist/tools/cpu/march.js.map +1 -0
  293. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  294. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  295. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  296. package/dist/tools/cpu/points.d.ts +29 -0
  297. package/dist/tools/cpu/points.js +38 -0
  298. package/dist/tools/cpu/points.js.map +1 -0
  299. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  300. package/dist/tools/cpu/probe-coords.js +116 -0
  301. package/dist/tools/cpu/probe-coords.js.map +1 -0
  302. package/dist/tools/cpu/read-value.d.ts +44 -0
  303. package/dist/tools/cpu/read-value.js +351 -0
  304. package/dist/tools/cpu/read-value.js.map +1 -0
  305. package/dist/tools/cpu/sample-trilinear.d.ts +43 -0
  306. package/dist/tools/cpu/sample-trilinear.js +168 -0
  307. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  308. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  309. package/dist/tools/cpu/stride-tables.generated.d.ts +1059 -0
  310. package/dist/tools/cpu/stride-tables.generated.js +1267 -0
  311. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  312. package/dist/tools/cpu/stride-tables.js +78 -0
  313. package/dist/tools/cpu/stride-tables.js.map +1 -0
  314. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  315. package/dist/tools/cpu/surface-nets.js +597 -0
  316. package/dist/tools/cpu/surface-nets.js.map +1 -0
  317. package/dist/tools/errors.d.ts +66 -0
  318. package/dist/tools/errors.js +67 -0
  319. package/dist/tools/errors.js.map +1 -0
  320. package/dist/tools/frame/ambient.d.ts +98 -0
  321. package/dist/tools/frame/ambient.js +274 -0
  322. package/dist/tools/frame/ambient.js.map +1 -0
  323. package/dist/tools/frame/blackbody.d.ts +57 -0
  324. package/dist/tools/frame/blackbody.js +151 -0
  325. package/dist/tools/frame/blackbody.js.map +1 -0
  326. package/dist/tools/frame/brick-cache.d.ts +165 -0
  327. package/dist/tools/frame/brick-cache.js +326 -0
  328. package/dist/tools/frame/brick-cache.js.map +1 -0
  329. package/dist/tools/frame/emission.d.ts +137 -0
  330. package/dist/tools/frame/emission.js +290 -0
  331. package/dist/tools/frame/emission.js.map +1 -0
  332. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  333. package/dist/tools/frame/environment-gpu.js +280 -0
  334. package/dist/tools/frame/environment-gpu.js.map +1 -0
  335. package/dist/tools/frame/environment.d.ts +106 -0
  336. package/dist/tools/frame/environment.js +272 -0
  337. package/dist/tools/frame/environment.js.map +1 -0
  338. package/dist/tools/frame/froxel.d.ts +58 -0
  339. package/dist/tools/frame/froxel.js +115 -0
  340. package/dist/tools/frame/froxel.js.map +1 -0
  341. package/dist/tools/frame/grid.d.ts +392 -0
  342. package/dist/tools/frame/grid.js +802 -0
  343. package/dist/tools/frame/grid.js.map +1 -0
  344. package/dist/tools/frame/index.d.ts +150 -0
  345. package/dist/tools/frame/index.js +389 -0
  346. package/dist/tools/frame/index.js.map +1 -0
  347. package/dist/tools/frame/medium.d.ts +77 -0
  348. package/dist/tools/frame/medium.js +101 -0
  349. package/dist/tools/frame/medium.js.map +1 -0
  350. package/dist/tools/frame/mie-table.d.ts +6 -0
  351. package/dist/tools/frame/mie-table.js +16 -0
  352. package/dist/tools/frame/mie-table.js.map +1 -0
  353. package/dist/tools/frame/mie.d.ts +63 -0
  354. package/dist/tools/frame/mie.js +194 -0
  355. package/dist/tools/frame/mie.js.map +1 -0
  356. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  357. package/dist/tools/frame/mlp-nn.js +159 -0
  358. package/dist/tools/frame/mlp-nn.js.map +1 -0
  359. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  360. package/dist/tools/frame/mlp-tza.js +186 -0
  361. package/dist/tools/frame/mlp-tza.js.map +1 -0
  362. package/dist/tools/frame/mlp.d.ts +183 -0
  363. package/dist/tools/frame/mlp.js +434 -0
  364. package/dist/tools/frame/mlp.js.map +1 -0
  365. package/dist/tools/frame/ms-exit.d.ts +42 -0
  366. package/dist/tools/frame/ms-exit.js +90 -0
  367. package/dist/tools/frame/ms-exit.js.map +1 -0
  368. package/dist/tools/frame/multi-scale.d.ts +152 -0
  369. package/dist/tools/frame/multi-scale.js +302 -0
  370. package/dist/tools/frame/multi-scale.js.map +1 -0
  371. package/dist/tools/frame/neural-weights.d.ts +10 -0
  372. package/dist/tools/frame/neural-weights.js +244 -0
  373. package/dist/tools/frame/neural-weights.js.map +1 -0
  374. package/dist/tools/frame/neural.d.ts +80 -0
  375. package/dist/tools/frame/neural.js +150 -0
  376. package/dist/tools/frame/neural.js.map +1 -0
  377. package/dist/tools/frame/occluders.d.ts +51 -0
  378. package/dist/tools/frame/occluders.js +72 -0
  379. package/dist/tools/frame/occluders.js.map +1 -0
  380. package/dist/tools/frame/pyramid-layout.d.ts +55 -0
  381. package/dist/tools/frame/pyramid-layout.js +100 -0
  382. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  383. package/dist/tools/frame/shadows.d.ts +190 -0
  384. package/dist/tools/frame/shadows.js +468 -0
  385. package/dist/tools/frame/shadows.js.map +1 -0
  386. package/dist/tools/frame/sparse.d.ts +147 -0
  387. package/dist/tools/frame/sparse.js +432 -0
  388. package/dist/tools/frame/sparse.js.map +1 -0
  389. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  390. package/dist/tools/frame/spectral-stack.js +391 -0
  391. package/dist/tools/frame/spectral-stack.js.map +1 -0
  392. package/dist/tools/frame/spectral.d.ts +222 -0
  393. package/dist/tools/frame/spectral.js +572 -0
  394. package/dist/tools/frame/spectral.js.map +1 -0
  395. package/dist/tools/frame/stack.d.ts +115 -0
  396. package/dist/tools/frame/stack.js +290 -0
  397. package/dist/tools/frame/stack.js.map +1 -0
  398. package/dist/tools/frame/view.d.ts +131 -0
  399. package/dist/tools/frame/view.js +337 -0
  400. package/dist/tools/frame/view.js.map +1 -0
  401. package/dist/tools/index.d.ts +157 -0
  402. package/dist/tools/index.js +132 -0
  403. package/dist/tools/index.js.map +1 -0
  404. package/dist/tools/internal.d.ts +87 -0
  405. package/dist/tools/internal.js +85 -0
  406. package/dist/tools/internal.js.map +1 -0
  407. package/dist/tools/nanovdb/build-from-vdb.d.ts +59 -0
  408. package/dist/tools/nanovdb/build-from-vdb.js +100 -0
  409. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  410. package/dist/tools/nanovdb/bytes.d.ts +233 -0
  411. package/dist/tools/nanovdb/bytes.js +388 -0
  412. package/dist/tools/nanovdb/bytes.js.map +1 -0
  413. package/dist/tools/nanovdb/coarse-first.d.ts +78 -0
  414. package/dist/tools/nanovdb/coarse-first.js +92 -0
  415. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  416. package/dist/tools/nanovdb/half.d.ts +22 -0
  417. package/dist/tools/nanovdb/half.js +73 -0
  418. package/dist/tools/nanovdb/half.js.map +1 -0
  419. package/dist/tools/nanovdb/index.d.ts +34 -0
  420. package/dist/tools/nanovdb/index.js +25 -0
  421. package/dist/tools/nanovdb/index.js.map +1 -0
  422. package/dist/tools/nanovdb/inspect.d.ts +33 -0
  423. package/dist/tools/nanovdb/inspect.js +70 -0
  424. package/dist/tools/nanovdb/inspect.js.map +1 -0
  425. package/dist/tools/nanovdb/leaf-codec.d.ts +119 -0
  426. package/dist/tools/nanovdb/leaf-codec.js +356 -0
  427. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  428. package/dist/tools/nanovdb/quantize.d.ts +72 -0
  429. package/dist/tools/nanovdb/quantize.js +329 -0
  430. package/dist/tools/nanovdb/quantize.js.map +1 -0
  431. package/dist/tools/nanovdb/resample.d.ts +177 -0
  432. package/dist/tools/nanovdb/resample.js +692 -0
  433. package/dist/tools/nanovdb/resample.js.map +1 -0
  434. package/dist/tools/nanovdb/serialize.d.ts +176 -0
  435. package/dist/tools/nanovdb/serialize.js +439 -0
  436. package/dist/tools/nanovdb/serialize.js.map +1 -0
  437. package/dist/tools/nanovdb/stats.d.ts +87 -0
  438. package/dist/tools/nanovdb/stats.js +225 -0
  439. package/dist/tools/nanovdb/stats.js.map +1 -0
  440. package/dist/tools/nanovdb/transform.d.ts +30 -0
  441. package/dist/tools/nanovdb/transform.js +94 -0
  442. package/dist/tools/nanovdb/transform.js.map +1 -0
  443. package/dist/tools/nanovdb/tree.d.ts +186 -0
  444. package/dist/tools/nanovdb/tree.js +530 -0
  445. package/dist/tools/nanovdb/tree.js.map +1 -0
  446. package/dist/tools/nanovdb/write-nvdb.d.ts +74 -0
  447. package/dist/tools/nanovdb/write-nvdb.js +290 -0
  448. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  449. package/dist/tools/nvdb-file.d.ts +265 -0
  450. package/dist/tools/nvdb-file.js +763 -0
  451. package/dist/tools/nvdb-file.js.map +1 -0
  452. package/dist/tools/nvdb-stream.d.ts +154 -0
  453. package/dist/tools/nvdb-stream.js +409 -0
  454. package/dist/tools/nvdb-stream.js.map +1 -0
  455. package/dist/tools/reference/analytic.d.ts +41 -0
  456. package/dist/tools/reference/analytic.js +95 -0
  457. package/dist/tools/reference/analytic.js.map +1 -0
  458. package/dist/tools/reference/environment.d.ts +62 -0
  459. package/dist/tools/reference/environment.js +154 -0
  460. package/dist/tools/reference/environment.js.map +1 -0
  461. package/dist/tools/reference/index.d.ts +12 -0
  462. package/dist/tools/reference/index.js +13 -0
  463. package/dist/tools/reference/index.js.map +1 -0
  464. package/dist/tools/reference/media.d.ts +14 -0
  465. package/dist/tools/reference/media.js +30 -0
  466. package/dist/tools/reference/media.js.map +1 -0
  467. package/dist/tools/reference/rng.d.ts +20 -0
  468. package/dist/tools/reference/rng.js +30 -0
  469. package/dist/tools/reference/rng.js.map +1 -0
  470. package/dist/tools/reference/scene.d.ts +312 -0
  471. package/dist/tools/reference/scene.js +169 -0
  472. package/dist/tools/reference/scene.js.map +1 -0
  473. package/dist/tools/reference/tables.d.ts +98 -0
  474. package/dist/tools/reference/tables.js +264 -0
  475. package/dist/tools/reference/tables.js.map +1 -0
  476. package/dist/tools/reference/trace.d.ts +160 -0
  477. package/dist/tools/reference/trace.js +497 -0
  478. package/dist/tools/reference/trace.js.map +1 -0
  479. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  480. package/dist/tools/vdb/bit-utils.js +42 -0
  481. package/dist/tools/vdb/bit-utils.js.map +1 -0
  482. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  483. package/dist/tools/vdb/blosc-write.js +197 -0
  484. package/dist/tools/vdb/blosc-write.js.map +1 -0
  485. package/dist/tools/vdb/blosc.d.ts +86 -0
  486. package/dist/tools/vdb/blosc.js +287 -0
  487. package/dist/tools/vdb/blosc.js.map +1 -0
  488. package/dist/tools/vdb/blosclz.d.ts +33 -0
  489. package/dist/tools/vdb/blosclz.js +112 -0
  490. package/dist/tools/vdb/blosclz.js.map +1 -0
  491. package/dist/tools/vdb/byte-reader.d.ts +50 -0
  492. package/dist/tools/vdb/byte-reader.js +161 -0
  493. package/dist/tools/vdb/byte-reader.js.map +1 -0
  494. package/dist/tools/vdb/compression.d.ts +81 -0
  495. package/dist/tools/vdb/compression.js +260 -0
  496. package/dist/tools/vdb/compression.js.map +1 -0
  497. package/dist/tools/vdb/errors.d.ts +10 -0
  498. package/dist/tools/vdb/errors.js +11 -0
  499. package/dist/tools/vdb/errors.js.map +1 -0
  500. package/dist/tools/vdb/grid.d.ts +37 -0
  501. package/dist/tools/vdb/grid.js +153 -0
  502. package/dist/tools/vdb/grid.js.map +1 -0
  503. package/dist/tools/vdb/half-float.d.ts +9 -0
  504. package/dist/tools/vdb/half-float.js +24 -0
  505. package/dist/tools/vdb/half-float.js.map +1 -0
  506. package/dist/tools/vdb/index.d.ts +4 -0
  507. package/dist/tools/vdb/index.js +3 -0
  508. package/dist/tools/vdb/index.js.map +1 -0
  509. package/dist/tools/vdb/inflate.d.ts +24 -0
  510. package/dist/tools/vdb/inflate.js +334 -0
  511. package/dist/tools/vdb/inflate.js.map +1 -0
  512. package/dist/tools/vdb/lz4.d.ts +30 -0
  513. package/dist/tools/vdb/lz4.js +228 -0
  514. package/dist/tools/vdb/lz4.js.map +1 -0
  515. package/dist/tools/vdb/metadata.d.ts +17 -0
  516. package/dist/tools/vdb/metadata.js +72 -0
  517. package/dist/tools/vdb/metadata.js.map +1 -0
  518. package/dist/tools/vdb/parse.d.ts +47 -0
  519. package/dist/tools/vdb/parse.js +241 -0
  520. package/dist/tools/vdb/parse.js.map +1 -0
  521. package/dist/tools/vdb/point-render-data.d.ts +79 -0
  522. package/dist/tools/vdb/point-render-data.js +137 -0
  523. package/dist/tools/vdb/point-render-data.js.map +1 -0
  524. package/dist/tools/vdb/points.d.ts +186 -0
  525. package/dist/tools/vdb/points.js +835 -0
  526. package/dist/tools/vdb/points.js.map +1 -0
  527. package/dist/tools/vdb/transform.d.ts +23 -0
  528. package/dist/tools/vdb/transform.js +54 -0
  529. package/dist/tools/vdb/transform.js.map +1 -0
  530. package/dist/tools/vdb/tree.d.ts +111 -0
  531. package/dist/tools/vdb/tree.js +228 -0
  532. package/dist/tools/vdb/tree.js.map +1 -0
  533. package/dist/tools/vdb/types.d.ts +195 -0
  534. package/dist/tools/vdb/types.js +3 -0
  535. package/dist/tools/vdb/types.js.map +1 -0
  536. package/dist/tools/wvdb/bake.d.ts +145 -0
  537. package/dist/tools/wvdb/bake.js +361 -0
  538. package/dist/tools/wvdb/bake.js.map +1 -0
  539. package/dist/tools/wvdb/dense.d.ts +191 -0
  540. package/dist/tools/wvdb/dense.js +368 -0
  541. package/dist/tools/wvdb/dense.js.map +1 -0
  542. package/dist/tools/wvdb/format.d.ts +220 -0
  543. package/dist/tools/wvdb/format.js +306 -0
  544. package/dist/tools/wvdb/format.js.map +1 -0
  545. package/dist/tools/wvdb/index.d.ts +14 -0
  546. package/dist/tools/wvdb/index.js +15 -0
  547. package/dist/tools/wvdb/index.js.map +1 -0
  548. package/dist/tools/wvdb/level-set.d.ts +56 -0
  549. package/dist/tools/wvdb/level-set.js +153 -0
  550. package/dist/tools/wvdb/level-set.js.map +1 -0
  551. package/dist/tools/wvdb/nanovdb.d.ts +59 -0
  552. package/dist/tools/wvdb/nanovdb.js +64 -0
  553. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  554. package/dist/tools/wvdb/partial.d.ts +74 -0
  555. package/dist/tools/wvdb/partial.js +233 -0
  556. package/dist/tools/wvdb/partial.js.map +1 -0
  557. package/dist/tools/wvdb/read.d.ts +336 -0
  558. package/dist/tools/wvdb/read.js +766 -0
  559. package/dist/tools/wvdb/read.js.map +1 -0
  560. package/dist/tools/wvdb/sha256.d.ts +7 -0
  561. package/dist/tools/wvdb/sha256.js +76 -0
  562. package/dist/tools/wvdb/sha256.js.map +1 -0
  563. package/dist/tools/wvdb/write.d.ts +149 -0
  564. package/dist/tools/wvdb/write.js +403 -0
  565. package/dist/tools/wvdb/write.js.map +1 -0
  566. package/package.json +83 -4
  567. package/vendor/LICENSE +201 -0
  568. package/vendor/NOTICE +19 -0
  569. package/vendor/VENDOR.md +100 -0
  570. package/vendor/pnanovdb.wgsl +1577 -0
@@ -0,0 +1,802 @@
1
+ // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
2
+ // src/three-openvdb/frame/core/frameGrid.js L12–223 (signature helpers, updateGridCascades,
3
+ // getGridRange, getCascadeCasters, updateGridSignatures);
4
+ // src/three-openvdb/frame/webgpu/frameShaderChunks.js L403–414 (frameIsotropicDiffusion),
5
+ // L1061–1194 (createGridNodes: gridUvw, insideGrid, findCascade, sampleTiles, sampleShadows,
6
+ // getGridCell);
7
+ // src/three-openvdb/frame/webgpu/FrameTransmittanceMaterial.js L129–190 (gridExtinction, march,
8
+ // skyTotal), L237–269 (near-extinction skip, slot packing);
9
+ // src/three-openvdb/frame/webgpu/FrameTemporalMaterial.js L119–157 (reprojection, motion blend);
10
+ // src/three-openvdb/frame/webgpu/FrameDensityMaterial.js L172–357 (the grey density pass),
11
+ // FrameLightingMaterial.js L296–436 (the grey lighting pass), FrameEnvironmentGridMaterial.js L92–281
12
+ // (the grey environment grid pass), as CPU twins.
13
+ // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
14
+ // Changes: engine-free (plain `{ x, y, z }` vectors and boxes instead of three's `Box3`/`Vector3`,
15
+ // so `tools` stays free of three; the three adapter passes its own objects, which fit); the shader
16
+ // maths as f64 CPU twins (test oracles of the `./three` 'frame' lighting passes); K3.4 adds the octave,
17
+ // two-sided and neural (callback) terms; the spectral twins are in spectral.ts (K3.5; they share
18
+ // `vdbFrameDensityFroxelSteps`). Divergences: DIVERGES.md (K3.3, K3.4 rows).
19
+ /**
20
+ * The world shadow grid of mjurczyk's `'frame'` lighting (K3.3, R1 §6 Step 3), engine-free: the
21
+ * cascade layout (power-of-two voxels, snapped bounds, the last cascade fits every caster), each
22
+ * caster's voxel range in a cascade, the change signatures that skip redraws, and CPU twins of the
23
+ * grid shader maths (atlas cell, cascade search, slice-atlas sampling, the transmittance march,
24
+ * isotropic diffusion, the temporal reprojection). `@pmndrs/vdb/three` `frame/grid.ts` and the
25
+ * 'frame' passes use these; the e2e harness checks the GPU passes against them.
26
+ */
27
+ import { vdbFrameDistanceFade, vdbFrameFroxel, vdbFrameNoise, vdbFrameOctavesOff, vdbFramePhaseColor, vdbFrameRand3, vdbFrameShadowMarchDepth, vdbFrameShadowStep, vdbFrameShadowTotal, vdbFrameShadowTransmittance, vdbFrameShadowedLightColor, vdbFrameTwoSidedDiffusion, vdbFrameViewPosition, } from "./index.js";
28
+ import { vdbFrameMsExitFactorGrey, vdbFrameMsExitGrey } from "./ms-exit.js";
29
+ const AXES = ["x", "y", "z"];
30
+ /** His `pushVector`: x, y (, z (, w)) of a vector into a signature. */
31
+ export function vdbSignaturePushVector(values, v) {
32
+ values.push(v.x, v.y);
33
+ if (v.z !== undefined)
34
+ values.push(v.z);
35
+ if (v.w !== undefined)
36
+ values.push(v.w);
37
+ }
38
+ /** His `pushElements`. */
39
+ export function vdbSignaturePushElements(values, elements) {
40
+ for (let i = 0; i < elements.length; i++)
41
+ values.push(elements[i]);
42
+ }
43
+ /** His `sameValues`: signatures are flat arrays compared value by value. */
44
+ export function vdbSameValues(a, b) {
45
+ if (a.length !== b.length)
46
+ return false;
47
+ for (let i = 0; i < a.length; i++)
48
+ if (a[i] !== b[i])
49
+ return false;
50
+ return true;
51
+ }
52
+ const box = { min: { x: 0, y: 0, z: 0 }, max: { x: 0, y: 0, z: 0 } };
53
+ const casterBox = { min: { x: 0, y: 0, z: 0 }, max: { x: 0, y: 0, z: 0 } };
54
+ const makeEmpty = (b) => {
55
+ b.min.x = b.min.y = b.min.z = Infinity;
56
+ b.max.x = b.max.y = b.max.z = -Infinity;
57
+ };
58
+ const isEmpty = (b) => b.max.x < b.min.x || b.max.y < b.min.y || b.max.z < b.min.z;
59
+ const copyBox = (to, from) => {
60
+ for (const a of AXES) {
61
+ to.min[a] = from.min[a];
62
+ to.max[a] = from.max[a];
63
+ }
64
+ };
65
+ /**
66
+ * His `updateGridCascades`: the last cascade fits all caster boxes (then far volumes get coarse
67
+ * shadows, not none); finer cascades are around the camera within `shadowDistance`, each half the
68
+ * size of the next; voxels are powers of two and bounds snap to them (shadows stay still while the
69
+ * camera moves). A fine cascade equal to the casters' box is skipped (the last one covers it).
70
+ * Writes `gridMin`, `gridSize`, `gridVoxel` (one entry per cascade); returns the count (0: no casters).
71
+ */
72
+ export function vdbFrameGridCascades(casterBoxes, cameraPosition, shadowDistance, resolution, cascades, gridMin, gridSize, gridVoxel) {
73
+ makeEmpty(casterBox);
74
+ for (const b of casterBoxes) {
75
+ for (const a of AXES) {
76
+ casterBox.min[a] = Math.min(casterBox.min[a], b.min[a]);
77
+ casterBox.max[a] = Math.max(casterBox.max[a], b.max[a]);
78
+ }
79
+ }
80
+ if (isEmpty(casterBox))
81
+ return 0;
82
+ const fineHalfSize = Math.min(shadowDistance, 0.5 * Math.max(casterBox.max.x - casterBox.min.x, casterBox.max.y - casterBox.min.y, casterBox.max.z - casterBox.min.z));
83
+ let count = 0;
84
+ for (let cascade = 0; cascade < cascades; cascade++) {
85
+ if (cascade === cascades - 1) {
86
+ copyBox(box, casterBox);
87
+ }
88
+ else {
89
+ const halfSize = fineHalfSize / Math.pow(2.0, cascades - 1 - cascade);
90
+ for (const a of AXES) {
91
+ // three Box3.intersect: max of the mins, min of the maxes, then empty when inverted.
92
+ box.min[a] = Math.max(cameraPosition[a] - halfSize, casterBox.min[a]);
93
+ box.max[a] = Math.min(cameraPosition[a] + halfSize, casterBox.max[a]);
94
+ }
95
+ if (isEmpty(box))
96
+ makeEmpty(box);
97
+ }
98
+ const equalsCasters = AXES.every((a) => box.min[a] === casterBox.min[a] && box.max[a] === casterBox.max[a]);
99
+ if (isEmpty(box) || (cascade < cascades - 1 && equalsCasters))
100
+ continue;
101
+ for (const a of AXES) {
102
+ const extent = Math.max(box.max[a] - box.min[a], 1e-6);
103
+ const voxel = Math.pow(2.0, Math.ceil(Math.log2(extent / (resolution - 1))));
104
+ gridVoxel[count][a] = voxel;
105
+ gridMin[count][a] = Math.floor(box.min[a] / voxel) * voxel;
106
+ gridSize[count][a] = voxel * resolution;
107
+ }
108
+ count++;
109
+ }
110
+ return count;
111
+ }
112
+ /** K6.Q1b `'optical'`: the optical depth one shadow grid cell may span at the caster's mean density. */
113
+ export const VDB_FRAME_ADAPTIVE_OPTICAL_DEPTH = 2;
114
+ /** K6.Q1b `'voxels'`: the source voxels one shadow grid cell may span. */
115
+ export const VDB_FRAME_ADAPTIVE_VOXELS = 16;
116
+ /** K6.Q1b: adaptive resolutions are multiples of this (fewer distinct sizes: fewer grid reallocations). */
117
+ export const VDB_FRAME_ADAPTIVE_STEP = 16;
118
+ /**
119
+ * K6.Q1b: the largest grid cell (world units) the casters ask for under `rule`: the smallest over the casters
120
+ * (Infinity: none asks, e.g. no extinction).
121
+ */
122
+ export function vdbFrameAdaptiveCellSize(casters, rule) {
123
+ let cell = Infinity;
124
+ for (const c of casters) {
125
+ if (rule !== "optical") {
126
+ for (let a = 0; a < 3; a++)
127
+ if (c.texels[a] > 0 && c.size[a] > 0)
128
+ cell = Math.min(cell, (VDB_FRAME_ADAPTIVE_VOXELS * c.size[a]) / c.texels[a]);
129
+ }
130
+ if (rule !== "voxels" && c.meanExtinction > 0)
131
+ cell = Math.min(cell, VDB_FRAME_ADAPTIVE_OPTICAL_DEPTH / c.meanExtinction);
132
+ }
133
+ return cell;
134
+ }
135
+ /**
136
+ * K6.Q1b: the size-adaptive shadow grid resolution. {@link vdbFrameGridCascades} snaps the casters' cascade (the
137
+ * last one) to power-of-two voxels: voxel = 2^⌈log2(extent / (R − 1))⌉, so R alone covers the largest box side with
138
+ * between R / 2 and R cells. This picks the power-of-two voxel at or below `cell` and the smallest R whose cascade
139
+ * uses it (R − 1 ≥ extent / voxel), rounded up to a multiple of {@link VDB_FRAME_ADAPTIVE_STEP}, within [`base`,
140
+ * `max`]. `max` ≤ `base` (the default 0) or no finite `cell` gives `base`: the fixed `shadowResolution`.
141
+ */
142
+ export function vdbFrameAdaptiveGridResolution(casterBoxes, cell, base, max) {
143
+ if (!(max > base) || !(cell > 0) || !Number.isFinite(cell))
144
+ return base;
145
+ let extent = 0;
146
+ for (const a of AXES) {
147
+ let lo = Infinity;
148
+ let hi = -Infinity;
149
+ for (const b of casterBoxes) {
150
+ lo = Math.min(lo, b.min[a]);
151
+ hi = Math.max(hi, b.max[a]);
152
+ }
153
+ if (hi > lo)
154
+ extent = Math.max(extent, hi - lo);
155
+ }
156
+ if (!(extent > 0))
157
+ return base;
158
+ const voxel = Math.pow(2, Math.floor(Math.log2(cell)));
159
+ const need = Math.ceil(extent / voxel - 1e-9) + 1;
160
+ const stepped = Math.ceil(need / VDB_FRAME_ADAPTIVE_STEP) * VDB_FRAME_ADAPTIVE_STEP;
161
+ return Math.max(base, Math.min(Math.floor(max), stepped));
162
+ }
163
+ const toCell = (value, min, voxel, resolution, round) => Math.min(resolution, Math.max(0, round((value - min) / voxel)));
164
+ /**
165
+ * His `getGridRange`: the voxel rectangle (x0, y0, x1, y1) and the atlas slices (first, count) of a
166
+ * world box in one cascade. Writes `target`; returns false when the box is out of the cascade.
167
+ */
168
+ export function vdbFrameGridRange(worldBox, cascade, resolution, gridMin, gridVoxel, target) {
169
+ const origin = gridMin[cascade];
170
+ const voxel = gridVoxel[cascade];
171
+ const { min, max } = worldBox;
172
+ const x0 = toCell(min.x, origin.x, voxel.x, resolution, Math.floor);
173
+ const y0 = toCell(min.y, origin.y, voxel.y, resolution, Math.floor);
174
+ const z0 = toCell(min.z, origin.z, voxel.z, resolution, Math.floor);
175
+ const x1 = toCell(max.x, origin.x, voxel.x, resolution, Math.ceil);
176
+ const y1 = toCell(max.y, origin.y, voxel.y, resolution, Math.ceil);
177
+ const z1 = toCell(max.z, origin.z, voxel.z, resolution, Math.ceil);
178
+ if (x1 <= x0 || y1 <= y0 || z1 <= z0)
179
+ return false;
180
+ if (Array.isArray(target.rect)) {
181
+ target.rect[0] = x0;
182
+ target.rect[1] = y0;
183
+ target.rect[2] = x1;
184
+ target.rect[3] = y1;
185
+ }
186
+ else {
187
+ const r = target.rect;
188
+ r.x = x0;
189
+ r.y = y0;
190
+ r.z = x1;
191
+ r.w = y1;
192
+ }
193
+ target.first = cascade * resolution + z0;
194
+ target.count = z1 - z0;
195
+ return true;
196
+ }
197
+ /** His `getCascadeCasters`: one item per caster per cascade from `firstCascade`; `pool` is reused. */
198
+ export function vdbFrameCascadeCasters(casters, firstCascade, count, pool) {
199
+ const { items, entries } = pool;
200
+ items.length = 0;
201
+ for (let cascade = firstCascade; cascade < count; cascade++) {
202
+ for (const caster of casters) {
203
+ if (items.length === entries.length)
204
+ entries.push({ caster, cascade });
205
+ const entry = entries[items.length];
206
+ entry.caster = caster;
207
+ entry.cascade = cascade;
208
+ items.push(entry);
209
+ }
210
+ }
211
+ return items;
212
+ }
213
+ /** A fresh {@link VDBFrameGridSignatureState}. */
214
+ export const vdbFrameGridSignatureState = () => ({
215
+ gridSignature: [],
216
+ nextGridSignature: [],
217
+ castSignature: [],
218
+ nextCastSignature: [],
219
+ casterSignature: [],
220
+ gridVersion: 0,
221
+ castVersion: 0,
222
+ });
223
+ /**
224
+ * His `updateGridSignatures`: `gridVersion` changes when the cascades, a caster transform, a caster's
225
+ * data or a caster's shadow props change; `castVersion` only for the last cascade. `pushCaster(values, caster)`
226
+ * adds what the shadow density pass reads of one caster (transform, source identity and version, props).
227
+ * Returns true when `castVersion` changed. Arrays are swapped, never reallocated.
228
+ */
229
+ export function vdbFrameUpdateGridSignatures(state, casters, count, resolution, spectral, gridMin, gridSize, pushCaster) {
230
+ const casterValues = state.casterSignature;
231
+ const castValues = state.nextCastSignature;
232
+ const gridValues = state.nextGridSignature;
233
+ casterValues.length = 0;
234
+ for (const caster of casters)
235
+ pushCaster(casterValues, caster);
236
+ // NOTE The cascade count changes the atlas layout, so a new count needs a new draw
237
+ castValues.length = 0;
238
+ castValues.push(casters.length, count, resolution, spectral ? 1 : 0);
239
+ if (count > 0) {
240
+ vdbSignaturePushVector(castValues, gridMin[count - 1]);
241
+ vdbSignaturePushVector(castValues, gridSize[count - 1]);
242
+ }
243
+ vdbSignaturePushElements(castValues, casterValues);
244
+ gridValues.length = 0;
245
+ gridValues.push(count);
246
+ for (let i = 0; i < count; i++) {
247
+ vdbSignaturePushVector(gridValues, gridMin[i]);
248
+ vdbSignaturePushVector(gridValues, gridSize[i]);
249
+ }
250
+ vdbSignaturePushElements(gridValues, castValues);
251
+ if (!vdbSameValues(gridValues, state.gridSignature)) {
252
+ state.gridVersion++;
253
+ state.nextGridSignature = state.gridSignature;
254
+ state.gridSignature = gridValues;
255
+ }
256
+ const castChanged = !vdbSameValues(castValues, state.castSignature);
257
+ if (castChanged) {
258
+ state.castVersion++;
259
+ state.nextCastSignature = state.castSignature;
260
+ state.castSignature = castValues;
261
+ }
262
+ return castChanged;
263
+ }
264
+ /** gridUvw: world position → [0, 1]³ of a cascade. */
265
+ export function vdbFrameGridUvw(grid, cascade, world) {
266
+ const m = grid.gridMin[cascade];
267
+ const s = grid.gridSize[cascade];
268
+ return [(world[0] - m[0]) / s[0], (world[1] - m[1]) / s[1], (world[2] - m[2]) / s[2]];
269
+ }
270
+ /** insideGrid: half a voxel inside the cascade (the linear filter then never reads the clamped edge). */
271
+ export function vdbFrameInsideGrid(resolution, uvw) {
272
+ const inset = 0.5 / resolution;
273
+ return Math.min(uvw[0], uvw[1], uvw[2]) >= inset && Math.max(uvw[0], uvw[1], uvw[2]) <= 1 - inset;
274
+ }
275
+ /** findCascade: the finest cascade ≥ `firstCascade` that contains the position, or −1. */
276
+ export function vdbFrameFindCascade(grid, world, firstCascade = 0, maxCascades = 4) {
277
+ let cascade = -1;
278
+ for (let i = maxCascades - 1; i >= 0; i--) {
279
+ if (i < grid.count && i >= firstCascade && vdbFrameInsideGrid(grid.resolution, vdbFrameGridUvw(grid, i, world)))
280
+ cascade = i;
281
+ }
282
+ return cascade;
283
+ }
284
+ /** getGridCell: cascade and grid uvw of an atlas pixel (bottom-left `fragCoord`, a pixel centre). */
285
+ export function vdbFrameGridCell(resolution, columns, fragCoord) {
286
+ const tile = [Math.floor(fragCoord[0] / resolution), Math.floor(fragCoord[1] / resolution)];
287
+ const tileIndex = tile[1] * columns + tile[0];
288
+ const cascade = Math.floor(tileIndex / resolution);
289
+ const z = tileIndex - cascade * resolution;
290
+ return {
291
+ cascade,
292
+ gridUvw: [(fragCoord[0] - tile[0] * resolution) / resolution, (fragCoord[1] - tile[1] * resolution) / resolution, (z + 0.5) / resolution],
293
+ };
294
+ }
295
+ /** Hardware bilinear (texel centres at i + ½, clamp to edge) of a bottom-first atlas at texel coordinates. */
296
+ export function vdbFrameAtlasBilinear(atlas, x, y, out = []) {
297
+ const { data, width, height, channels } = atlas;
298
+ const fx = x - 0.5;
299
+ const fy = y - 0.5;
300
+ const x0 = Math.floor(fx);
301
+ const y0 = Math.floor(fy);
302
+ const ax = fx - x0;
303
+ const ay = fy - y0;
304
+ const cx = (i) => Math.min(width - 1, Math.max(0, i));
305
+ const cy = (i) => Math.min(height - 1, Math.max(0, i));
306
+ const xa = cx(x0);
307
+ const xb = cx(x0 + 1);
308
+ const ya = cy(y0);
309
+ const yb = cy(y0 + 1);
310
+ for (let c = 0; c < channels; c++) {
311
+ const t00 = data[(ya * width + xa) * channels + c];
312
+ const t10 = data[(ya * width + xb) * channels + c];
313
+ const t01 = data[(yb * width + xa) * channels + c];
314
+ const t11 = data[(yb * width + xb) * channels + c];
315
+ out[c] = (t00 * (1 - ax) + t10 * ax) * (1 - ay) + (t01 * (1 - ax) + t11 * ax) * ay;
316
+ }
317
+ out.length = channels;
318
+ return out;
319
+ }
320
+ /** sampleTiles: hardware bilinear in a slice, linear between slices (z tiles from `tileOffset`). */
321
+ export function vdbFrameSampleTiles(atlas, resolution, tileOffset, columns, uvw) {
322
+ const z = uvw[2] * resolution - 0.5;
323
+ const z0 = Math.min(Math.max(Math.floor(z), 0), resolution - 1);
324
+ const z1 = Math.min(z0 + 1, resolution - 1);
325
+ const blend = Math.min(Math.max(z - z0, 0), 1);
326
+ const xy = [Math.min(Math.max(uvw[0] * resolution, 0.5), resolution - 0.5), Math.min(Math.max(uvw[1] * resolution, 0.5), resolution - 0.5)];
327
+ const tileTexel = (index) => [(index % columns) * resolution + xy[0], Math.floor(index / columns) * resolution + xy[1]];
328
+ const [ax, ay] = tileTexel(tileOffset + z0);
329
+ const [bx, by] = tileTexel(tileOffset + z1);
330
+ const a = vdbFrameAtlasBilinear(atlas, ax, ay);
331
+ const b = vdbFrameAtlasBilinear(atlas, bx, by);
332
+ return a.map((v, c) => v + (b[c] - v) * blend);
333
+ }
334
+ /** sampleGrid: {@link vdbFrameSampleTiles} of one cascade of the grid atlas. */
335
+ export function vdbFrameSampleGrid(atlas, grid, cascade, uvw) {
336
+ return vdbFrameSampleTiles(atlas, grid.resolution, cascade * grid.resolution, grid.columns, uvw);
337
+ }
338
+ /** gridExtinction of the transmittance pass: (extinction, absorption) at a world position, 0 outside the grid. */
339
+ export function vdbFrameGridExtinction(atlas, grid, world) {
340
+ const found = vdbFrameFindCascade(grid, world, 0);
341
+ if (found < 0)
342
+ return [0, 0];
343
+ const s = vdbFrameSampleGrid(atlas, grid, found, vdbFrameGridUvw(grid, found, world));
344
+ return [s[0], s[1]];
345
+ }
346
+ /**
347
+ * The transmittance pass `march` (grey): one voxel of the finest cascade at the probe per step along the
348
+ * direction's fastest axis, coarser cascades after leaving a fine one, stop outside the grid, at
349
+ * `maxDistance` or past march depth 6 (with octaves, the last octave's). Each step samples `jitter` of the
350
+ * way along it. Returns (direct, total, reduced depth, effective depth); `out.opticalDepth` gets the direct
351
+ * optical depth (the neural input).
352
+ */
353
+ export function vdbFrameGridMarch(extinctionAt, grid, origin, direction, maxDistance, jitter, multipleScattering, octaves = vdbFrameOctavesOff, out) {
354
+ const depths = [0, 0, 0];
355
+ let traveled = 0;
356
+ const probe = [...origin];
357
+ for (let i = 0; i < 1024; i++) {
358
+ const cascade = vdbFrameFindCascade(grid, probe, 0);
359
+ if (cascade < 0 || traveled >= maxDistance || vdbFrameShadowMarchDepth(depths, multipleScattering, octaves) > 6)
360
+ break;
361
+ const voxel = grid.gridVoxel[cascade];
362
+ const perUnit = Math.max(Math.abs(direction[0]) / voxel[0], Math.abs(direction[1]) / voxel[1], Math.abs(direction[2]) / voxel[2]);
363
+ const step = Math.min(1 / perUnit, maxDistance - traveled);
364
+ const s = extinctionAt([probe[0] + direction[0] * step * jitter, probe[1] + direction[1] * step * jitter, probe[2] + direction[2] * step * jitter]);
365
+ const d = vdbFrameShadowStep(s[0], s[1], multipleScattering);
366
+ depths[0] += d[0] * step;
367
+ depths[1] += d[1] * step;
368
+ depths[2] += d[2] * step;
369
+ for (let c = 0; c < 3; c++)
370
+ probe[c] = probe[c] + direction[c] * step;
371
+ traveled += step;
372
+ }
373
+ const t = vdbFrameShadowTransmittance(depths, multipleScattering, octaves);
374
+ if (out)
375
+ out.opticalDepth = depths[0];
376
+ return [t[0], t[1], depths[2], depths[1]];
377
+ }
378
+ /**
379
+ * frameIsotropicDiffusion: total transmittance of isotropic light (sky, environment) with diffusion,
380
+ * the two-sided slab 2 (back + z₀) / (front + back + 2 z₀) of the reduced depths (z₀ = ⅔), times
381
+ * exp(−effective front). Opposite directions sum to 2 in a white medium (white furnace).
382
+ */
383
+ export function vdbFrameIsotropicDiffusion(frontReduced, backReduced, frontEffective) {
384
+ const z0 = 2 / 3;
385
+ return ((backReduced + z0) * 2) / (frontReduced + backReduced + 2 * z0) * Math.exp(-frontEffective);
386
+ }
387
+ /** The shader's `normalize`. */
388
+ const normalize3 = (v) => {
389
+ const l = Math.hypot(v[0], v[1], v[2]);
390
+ return l > 0 ? [v[0] / l, v[1] / l, v[2] / l] : [0, 0, 0];
391
+ };
392
+ /**
393
+ * The transmittance pass (grey) at one grid voxel: the 4 MRT outputs (vec4 each) his `colorNode` writes,
394
+ * for `lights` (≤ 6 slots) and the sky direction. `fragCoord` is the voxel's atlas pixel (for the jitter
395
+ * noise; `jitter` < 0 is off). Voxels with no extinction within half a voxel keep 1.0 everywhere, as his
396
+ * pass. `modes`: octaves, two-sided or neural (K3.4).
397
+ */
398
+ export function vdbFrameTransmittanceVoxel(atlas, grid, fragCoord, lights, skyDirection, multipleScattering, jitterValue, modes = {}) {
399
+ const octaves = modes.octaves ?? vdbFrameOctavesOff;
400
+ const out = [
401
+ [1, 1, 1, 1],
402
+ [1, 1, 1, 1],
403
+ [1, 1, 1, 1],
404
+ [1, 1, 1, 1],
405
+ ];
406
+ const cell = vdbFrameGridCell(grid.resolution, grid.columns, fragCoord);
407
+ if (cell.cascade >= grid.count)
408
+ return out;
409
+ const voxel = grid.gridVoxel[cell.cascade];
410
+ const m = grid.gridMin[cell.cascade];
411
+ const s = grid.gridSize[cell.cascade];
412
+ const world = [m[0] + cell.gridUvw[0] * s[0], m[1] + cell.gridUvw[1] * s[1], m[2] + cell.gridUvw[2] * s[2]];
413
+ const extinctionAt = (p) => vdbFrameGridExtinction(atlas, grid, p);
414
+ let near = 0;
415
+ for (let i = 0; i < 8; i++) {
416
+ const c = [(i & 1) - 0.5, ((i >> 1) & 1) - 0.5, ((i >> 2) & 1) - 0.5];
417
+ near += extinctionAt([world[0] + c[0] * voxel[0], world[1] + c[1] * voxel[1], world[2] + c[2] * voxel[2]])[0];
418
+ }
419
+ if (!(near > 0))
420
+ return out;
421
+ const jitter = vdbFrameNoise(jitterValue, fragCoord);
422
+ const sky = normalize3(skyDirection);
423
+ const slot = (i) => {
424
+ if (i >= lights.length)
425
+ return [1, 1, 0, 0];
426
+ const l = lights[i];
427
+ const isDirection = l[3] < 1.5;
428
+ const toLight = [l[0] - world[0], l[1] - world[1], l[2] - world[2]];
429
+ const dir = isDirection ? normalize3([l[0], l[1], l[2]]) : normalize3(toLight);
430
+ const optical = { opticalDepth: 0 };
431
+ const result = vdbFrameGridMarch(extinctionAt, grid, world, dir, isDirection ? 1e20 : Math.hypot(...toLight), jitter, multipleScattering, octaves, optical);
432
+ if (modes.twoSided) {
433
+ const back = vdbFrameGridMarch(extinctionAt, grid, world, [-dir[0], -dir[1], -dir[2]], 1e20, jitter, multipleScattering, octaves);
434
+ result[1] = vdbFrameTwoSidedDiffusion(result[0], result[2], result[3], back[2]);
435
+ }
436
+ if (modes.neural)
437
+ result[1] = result[0] + modes.neural(world, dir, optical.opticalDepth);
438
+ return result;
439
+ };
440
+ const ls = [0, 1, 2, 3, 4, 5].map(slot);
441
+ const up = vdbFrameGridMarch(extinctionAt, grid, world, sky, 1e20, jitter, multipleScattering, octaves);
442
+ const down = vdbFrameGridMarch(extinctionAt, grid, world, [-sky[0], -sky[1], -sky[2]], 1e20, jitter, multipleScattering, octaves);
443
+ const skyTotal = (f, b) => (multipleScattering > 0 ? vdbFrameIsotropicDiffusion(f[2], b[2], f[3]) : f[1]);
444
+ out[0] = [skyTotal(up, down), skyTotal(down, up), ls[0][1], ls[1][1]];
445
+ out[1] = [ls[2][1], ls[3][1], ls[4][1], ls[5][1]];
446
+ out[2] = [ls[0][0], ls[1][0], ls[2][0], ls[3][0]];
447
+ out[3] = [ls[4][0], ls[5][0], 1, 1];
448
+ return out;
449
+ }
450
+ /**
451
+ * sampleShadows: the slot atlases at a world position, 1 outside the grid, blended toward the next
452
+ * cascade within 10% of a cascade's sides (no visible cascade borders).
453
+ */
454
+ export function vdbFrameSampleShadows(atlases, grid, world) {
455
+ const out = atlases.map(() => [1, 1, 1, 1]);
456
+ const cascade = vdbFrameFindCascade(grid, world, 0);
457
+ if (cascade < 0)
458
+ return out;
459
+ const uvw = vdbFrameGridUvw(grid, cascade, world);
460
+ atlases.forEach((a, i) => {
461
+ out[i] = vdbFrameSampleGrid(a, grid, cascade, uvw);
462
+ });
463
+ const side = Math.min(uvw[0], uvw[1], uvw[2], 1 - uvw[0], 1 - uvw[1], 1 - uvw[2]);
464
+ const blend = 1 - smoothstep(0, 0.1, side);
465
+ if (blend > 0) {
466
+ const next = vdbFrameFindCascade(grid, world, cascade + 1);
467
+ if (next >= 0) {
468
+ const nextUvw = vdbFrameGridUvw(grid, next, world);
469
+ atlases.forEach((a, i) => {
470
+ const v = vdbFrameSampleGrid(a, grid, next, nextUvw);
471
+ out[i] = out[i].map((x, c) => x + (v[c] - x) * blend);
472
+ });
473
+ }
474
+ }
475
+ return out;
476
+ }
477
+ /**
478
+ * The density pass of 'frame' lighting at one froxel of one volume (FrameDensityMaterial `buildNodes`,
479
+ * grey, octaves off, no environment term): the slice's sub-step pre-integration through the source,
480
+ * the visible position, and the shadow slots there. Returns the 4 MRT outputs (before additive
481
+ * blending), or null when the froxel is discarded. `fragCoord` is the atlas pixel (bottom-left).
482
+ */
483
+ export function vdbFrameDensityFroxel(fragCoord, p) {
484
+ const f = vdbFrameDensityFroxelSteps(fragCoord, p);
485
+ if (!f)
486
+ return null;
487
+ const { viewNear, viewFar, localNear, localFar, t0, segment, steps, subStepLength, lod, jitter, mul } = f;
488
+ const lerp3 = (x, y, t) => [x[0] + (y[0] - x[0]) * t, x[1] + (y[1] - x[1]) * t, x[2] + (y[2] - x[2]) * t];
489
+ let extinctionSum = 0;
490
+ let transmittance = 1;
491
+ let visibleWeight = 0;
492
+ let visibleTSum = 0;
493
+ for (let i = 0; i < steps; i++) {
494
+ const t = t0 + segment * ((i + jitter) / steps);
495
+ const e = vdbFrameSliceExtinction(p, fragCoord, i, lerp3(localNear, localFar, t), lod) * p.opacity * vdbFrameDistanceFade(p.fadeRadius, lerp3(viewNear, viewFar, t));
496
+ const stepT = Math.exp(-e * subStepLength);
497
+ const w = transmittance * (1 - stepT);
498
+ visibleWeight += w;
499
+ visibleTSum += w * t;
500
+ extinctionSum += e;
501
+ transmittance *= stepT;
502
+ }
503
+ return densityFroxelTail(p, viewNear, viewFar, mul, extinctionSum, steps, segment, visibleWeight, visibleTSum, { localNear, localFar, lod });
504
+ }
505
+ /** Sub-step `i`'s extinction in the slice march: `extinctionAt`, or the stochastic filter's one-voxel read (issue #2). */
506
+ export function vdbFrameSliceExtinction(p, fragCoord, i, local, lod) {
507
+ const s = p.stochastic;
508
+ return s ? s.at(local, lod, vdbFrameRand3(fragCoord, ((s.volume << 16) | i) >>> 0, s.seed)) : p.extinctionAt(local, lod);
509
+ }
510
+ /** The froxel geometry of the density pass (and the inject pre-integration): box segment, sub-steps, lods. null: discarded. */
511
+ export function vdbFrameDensityFroxelSteps(fragCoord, p) {
512
+ const froxel = vdbFrameFroxel(p.froxelGrid, p.columns, p.range, p.projectionInverse, fragCoord);
513
+ const mul = (m, v) => [0, 1, 2].map((r) => m[r] * v[0] + m[4 + r] * v[1] + m[8 + r] * v[2] + m[12 + r]);
514
+ const { viewNear, viewFar } = froxel;
515
+ const localNear = mul(p.viewToLocal, viewNear);
516
+ const localFar = mul(p.viewToLocal, viewFar);
517
+ // boxSegment of the unit box
518
+ const dir = [localFar[0] - localNear[0], localFar[1] - localNear[1], localFar[2] - localNear[2]];
519
+ let t0 = 0;
520
+ let t1 = 1;
521
+ {
522
+ let lo = -Infinity;
523
+ let hi = Infinity;
524
+ for (let a = 0; a < 3; a++) {
525
+ const inv = 1 / dir[a];
526
+ const ta = (-0.5 - localNear[a]) * inv;
527
+ const tb = (0.5 - localNear[a]) * inv;
528
+ lo = Math.max(lo, Math.min(ta, tb));
529
+ hi = Math.min(hi, Math.max(ta, tb));
530
+ }
531
+ t0 = Math.max(0, lo);
532
+ t1 = Math.min(1, hi);
533
+ }
534
+ if (t0 >= t1)
535
+ return null;
536
+ const segment = t1 - t0;
537
+ const getLod = (size) => Math.max(0, Math.log2(size * p.maxTexels));
538
+ const sliceMiddle = (froxel.sliceNear + froxel.sliceFar) * 0.5;
539
+ const a = vdbFrameViewPosition(p.projectionInverse, [froxel.uv[0] + 1 / p.froxelGrid[0], froxel.uv[1]], sliceMiddle);
540
+ const b = vdbFrameViewPosition(p.projectionInverse, froxel.uv, sliceMiddle);
541
+ const widthLod = getLod(Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]) / p.worldScale);
542
+ const sampledLod = p.mipLevels > 0 ? Math.min(widthLod, p.mipLevels) : 0;
543
+ const boxLength = Math.hypot(...dir) * segment;
544
+ const steps = Math.trunc(Math.min(Math.max(Math.ceil(Math.pow(2, getLod(boxLength) - sampledLod) * 2), 1), p.subSteps));
545
+ const subStepLength = (Math.hypot(viewFar[0] - viewNear[0], viewFar[1] - viewNear[1], viewFar[2] - viewNear[2]) * segment) / steps;
546
+ const lod = Math.max(widthLod, getLod(subStepLength / p.worldScale));
547
+ const jitter = vdbFrameNoise(p.jitter, fragCoord);
548
+ return { froxel, viewNear, viewFar, localNear, localFar, t0, segment, steps, subStepLength, lod, jitter, mul };
549
+ }
550
+ function densityFroxelTail(p, viewNear, viewFar, mul, extinctionSum, steps, segment, visibleWeight, visibleTSum, at) {
551
+ const lerp3 = (x, y, t) => [x[0] + (y[0] - x[0]) * t, x[1] + (y[1] - x[1]) * t, x[2] + (y[2] - x[2]) * t];
552
+ const extinction = (extinctionSum / steps) * segment;
553
+ if (!(extinction > 0))
554
+ return null;
555
+ const visibleT = visibleWeight > 0 ? visibleTSum / visibleWeight : 0.5;
556
+ const visibleWorld = mul(p.cameraWorld, lerp3(viewNear, viewFar, visibleT));
557
+ const visibleLocal = at ? lerp3(at.localNear, at.localFar, visibleT) : null;
558
+ const albedo = p.albedoAt && visibleLocal ? p.albedoAt(visibleLocal, at.lod) : [...p.baseColor];
559
+ const sh = p.shadowsAt ? p.shadowsAt(visibleWorld) : p.shadows ? vdbFrameSampleShadows(p.shadows.atlases, p.shadows.grid, visibleWorld) : [1, 2, 3, 4].map(() => [1, 1, 1, 1]);
560
+ const shadow0 = [...sh[0]];
561
+ const shadow1 = [...sh[1]];
562
+ const directs = [sh[2][0], sh[2][1], sh[2][2], sh[2][3], sh[3][0], sh[3][1]];
563
+ const m = p.cameraWorld;
564
+ const ray = normalize3([0, 1, 2].map((r) => m[r] * (viewFar[0] - viewNear[0]) + m[4 + r] * (viewFar[1] - viewNear[1]) + m[8 + r] * (viewFar[2] - viewNear[2])));
565
+ const slotRef = [
566
+ [shadow0, 2],
567
+ [shadow0, 3],
568
+ [shadow1, 0],
569
+ [shadow1, 1],
570
+ [shadow1, 2],
571
+ [shadow1, 3],
572
+ ];
573
+ const octaves = p.octaves ?? vdbFrameOctavesOff;
574
+ const phaseSpectrum = p.phaseSpectrum ?? [1, 1, 0];
575
+ // K7.4c: the slot's total with the scattered part (total − direct) × its exit factor (green); code 0 (and K7.4a-2's 3,
576
+ // whose green factor is 1): his
577
+ const msExitTotal = (direct, total, v, ray, lightDir) => vdbFrameMsExitGrey(p.msExit ?? 0)
578
+ ? direct * v + (total - direct) * vdbFrameMsExitFactorGrey(p.msExit, p.phase, phaseSpectrum, ray[0] * lightDir[0] + ray[1] * lightDir[1] + ray[2] * lightDir[2], direct, total - direct, albedo)
579
+ : total - direct * (1 - v);
580
+ slotRef.forEach(([s, c], index) => {
581
+ if (index < p.sceneLightCount) {
582
+ const l = p.lightPositions[index];
583
+ const lightDir = l[3] < 1.5 ? [l[0], l[1], l[2]] : normalize3([l[0] - visibleWorld[0], l[1] - visibleWorld[1], l[2] - visibleWorld[2]]);
584
+ // frameShadowedLight(...).g: the green phase × direct + the scattered light (K6.5b: direct × occluder visibility,
585
+ // passed as (direct·v, total − direct·(1 − v)) so the scattered part total − direct is unchanged)
586
+ const v = p.occluderAt ? p.occluderAt(index, visibleWorld) : 1;
587
+ const direct = directs[index];
588
+ // K6.3 octaves: the slot keeps 1 / (1 + depth) unoccluded in the transmittance; both terms take v here
589
+ s[c] =
590
+ octaves[0] > 0
591
+ ? vdbFrameShadowedLightColor(p.phase, phaseSpectrum, octaves, ray, lightDir, [direct, s[c]])[1] * v
592
+ : vdbFrameShadowedLightColor(p.phase, phaseSpectrum, octaves, ray, lightDir, [direct * v, msExitTotal(direct, s[c], v, ray, lightDir)])[1];
593
+ }
594
+ else {
595
+ s[c] = vdbFrameShadowTotal(s[c], octaves);
596
+ }
597
+ });
598
+ shadow0[0] = vdbFrameShadowTotal(shadow0[0], octaves);
599
+ shadow0[1] = vdbFrameShadowTotal(shadow0[1], octaves);
600
+ // K6.Q1: the hemispherical visibilities replace the sky totals
601
+ if (p.ambientOcclusion) {
602
+ // K6.Q1d: × the phase weight of the pairs' dipole (green)
603
+ const w = p.ambientWeight ? p.ambientWeight(visibleWorld, ray, sh[3][2], sh[3][3])[1] : 1;
604
+ shadow0[0] = sh[3][2] * w;
605
+ shadow0[1] = sh[3][3] * w;
606
+ }
607
+ const ext = (v) => v.map((x) => Math.min(x * extinction, 6.0e4));
608
+ const own = p.emissionAt && visibleLocal ? p.emissionAt(visibleLocal, at.lod) : [0, 0, 0];
609
+ const emission = [p.scatterColor[0] + own[0], p.scatterColor[1] + own[1], p.scatterColor[2] + own[2]];
610
+ if (p.environmentGrid && p.shadows) {
611
+ // sampleEnvironmentGrid: the last cascade, its own atlas; the unshadowed light (× the octave total) outside it
612
+ const g = p.shadows.grid;
613
+ const uvw = vdbFrameGridUvw(g, g.count - 1, visibleWorld);
614
+ const outside = vdbFrameShadowTotal(1, octaves);
615
+ const env = vdbFrameInsideGrid(g.resolution, uvw) ? vdbFrameSampleTiles(p.environmentGrid.atlas, g.resolution, 0, p.environmentGrid.columns, uvw) : p.environmentGrid.unshadowed.map((v) => v * outside);
616
+ for (let c = 0; c < 3; c++)
617
+ emission[c] = emission[c] + (albedo[c] * env[c]) / Math.PI;
618
+ }
619
+ if (p.environmentAt) {
620
+ const env = p.environmentAt(visibleWorld, visibleLocal, [shadow0[0], shadow0[1]]);
621
+ for (let c = 0; c < 3; c++)
622
+ emission[c] = emission[c] + (albedo[c] * env[c]) / Math.PI;
623
+ }
624
+ return [
625
+ [albedo[0] * extinction, albedo[1] * extinction, albedo[2] * extinction, extinction],
626
+ [emission[0] * extinction, emission[1] * extinction, emission[2] * extinction, visibleT * extinction],
627
+ ext(shadow0),
628
+ ext(shadow1),
629
+ ];
630
+ }
631
+ /**
632
+ * The environment grid pass (FrameEnvironmentGridMaterial, grey) at one voxel of the last
633
+ * cascade: `fragCoord` is the pixel of the environment grid atlas (`envColumns` tile columns), `lights`
634
+ * the environment lights without a shadow slot, `unshadowed` their colour sum (the value outside the
635
+ * casters). One-voxel steps that stay in the last cascade; with diffusion the two-sided total of the
636
+ * march and the opposite march. Returns the RGBA output.
637
+ */
638
+ export function vdbFrameEnvironmentGridVoxel(atlas, grid, envColumns, fragCoord, lights, unshadowed, multipleScattering, octaves = vdbFrameOctavesOff) {
639
+ const cascade = grid.count - 1;
640
+ const res = grid.resolution;
641
+ const tile = [Math.floor(fragCoord[0] / res), Math.floor(fragCoord[1] / res)];
642
+ const z = tile[1] * envColumns + tile[0];
643
+ const uvw0 = [(fragCoord[0] - tile[0] * res) / res, (fragCoord[1] - tile[1] * res) / res, (z + 0.5) / res];
644
+ const voxel = grid.gridVoxel[cascade];
645
+ const m = grid.gridMin[cascade];
646
+ const s = grid.gridSize[cascade];
647
+ const world = [m[0] + uvw0[0] * s[0], m[1] + uvw0[1] * s[1], m[2] + uvw0[2] * s[2]];
648
+ const uvwOf = (p) => [(p[0] - m[0]) / s[0], (p[1] - m[1]) / s[1], (p[2] - m[2]) / s[2]];
649
+ const sample = (p) => vdbFrameSampleGrid(atlas, grid, cascade, uvwOf(p));
650
+ let near = 0;
651
+ for (let i = 0; i < 8; i++) {
652
+ const c = [(i & 1) - 0.5, ((i >> 1) & 1) - 0.5, ((i >> 2) & 1) - 0.5];
653
+ near += sample([world[0] + c[0] * voxel[0], world[1] + c[1] * voxel[1], world[2] + c[2] * voxel[2]])[0];
654
+ }
655
+ // Octaves: the unshadowed light gets the octaves too
656
+ const outside = vdbFrameShadowTotal(1, octaves);
657
+ if (!(z < res && near > 0))
658
+ return [unshadowed[0] * outside, unshadowed[1] * outside, unshadowed[2] * outside, 1];
659
+ const marchDepths = (dir) => {
660
+ const perUnit = Math.max(Math.abs(dir[0]) / voxel[0], Math.abs(dir[1]) / voxel[1], Math.abs(dir[2]) / voxel[2]);
661
+ const step = 1 / perUnit;
662
+ const probe = [world[0] + dir[0] * step * 0.5, world[1] + dir[1] * step * 0.5, world[2] + dir[2] * step * 0.5];
663
+ const depths = [0, 0, 0];
664
+ for (let i = 0; i < 1024; i++) {
665
+ const uvw = uvwOf(probe);
666
+ if (uvw.some((v) => v < 0 || v > 1) || vdbFrameShadowMarchDepth(depths, multipleScattering, octaves) > 6)
667
+ break;
668
+ const v = vdbFrameSampleGrid(atlas, grid, cascade, uvw);
669
+ const d = vdbFrameShadowStep(v[0], v[1], multipleScattering);
670
+ for (let c = 0; c < 3; c++) {
671
+ depths[c] = depths[c] + d[c] * step;
672
+ probe[c] = probe[c] + dir[c] * step;
673
+ }
674
+ }
675
+ return depths;
676
+ };
677
+ const irradiance = [0, 0, 0];
678
+ for (const light of lights) {
679
+ const depths = marchDepths(light.direction);
680
+ const total = multipleScattering > 0
681
+ ? vdbFrameIsotropicDiffusion(depths[2], marchDepths([-light.direction[0], -light.direction[1], -light.direction[2]])[2], depths[1])
682
+ : vdbFrameShadowTotal(vdbFrameShadowTransmittance(depths, multipleScattering, octaves)[1], octaves);
683
+ for (let c = 0; c < 3; c++)
684
+ irradiance[c] = irradiance[c] + light.color[c] * total;
685
+ }
686
+ return [Math.max(irradiance[0], 0), Math.max(irradiance[1], 0), Math.max(irradiance[2], 0), 1];
687
+ }
688
+ /**
689
+ * The temporal pass reprojection of a froxel centre (FrameTemporalMaterial L123–157): the previous
690
+ * frame's uv and fractional slice of a world position, and the history blend (the motion of a
691
+ * quarter cell or more uses only the current froxel). Returns null when the point is outside the
692
+ * previous froxel grid (or behind its camera).
693
+ */
694
+ export function vdbFrameReproject(world, previousView, previousProjection, previousRange, grid, current, temporalBlend) {
695
+ const mul = (m, v) => {
696
+ const o = [0, 0, 0, 0];
697
+ for (let r = 0; r < 4; r++)
698
+ o[r] = m[r] * v[0] + m[4 + r] * v[1] + m[8 + r] * v[2] + m[12 + r] * v[3];
699
+ return o;
700
+ };
701
+ const view = mul(previousView, [world[0], world[1], world[2], 1]);
702
+ const clip = mul(previousProjection, view);
703
+ if (!(clip[3] > 0))
704
+ return null;
705
+ const uv = [(clip[0] / clip[3]) * 0.5 + 0.5, (clip[1] / clip[3]) * 0.5 + 0.5];
706
+ const t = Math.log(Math.max(-view[2], 1e-6) / previousRange[0]) / Math.log(previousRange[1] / previousRange[0]);
707
+ const slice = t * grid[2] - 0.5;
708
+ const inside = Math.min(uv[0], uv[1]) >= 0 && Math.max(uv[0], uv[1]) <= 1 && slice >= -0.5 && slice <= grid[2] - 0.5;
709
+ if (!inside)
710
+ return null;
711
+ const motion = Math.hypot((uv[0] - current.uv[0]) * grid[0], (uv[1] - current.uv[1]) * grid[1], slice - current.slice);
712
+ const blend = temporalBlend + (1 - temporalBlend) * Math.min(Math.max(motion * 4, 0), 1);
713
+ return { uv, slice, blend };
714
+ }
715
+ /** three's `getShIrradianceAt` (the probe's L2 irradiance at a unit normal). */
716
+ function shIrradiance(normal, sh) {
717
+ const [x, y, z] = normal;
718
+ const k = [0.886227, 2 * 0.511664 * y, 2 * 0.511664 * z, 2 * 0.511664 * x, 2 * 0.429043 * x * y, 2 * 0.429043 * y * z, z * z * 0.743125 - 0.247708, 2 * 0.429043 * x * z, 0.429043 * (x * x - y * y)];
719
+ return [0, 1, 2].map((c) => k.reduce((sum, w, i) => sum + (sh[i]?.[c] ?? 0) * w, 0));
720
+ }
721
+ const smoothstep = (e0, e1, x) => {
722
+ const t = Math.min(Math.max((x - e0) / (e1 - e0), 0), 1);
723
+ return t * t * (3 - 2 * t);
724
+ };
725
+ /** three's `getDistanceAttenuation` (Frostbite window). */
726
+ const distanceAttenuation = (d, cutoff, decay) => {
727
+ const falloff = 1 / Math.max(Math.pow(d, decay), 0.01);
728
+ return cutoff > 0 ? falloff * Math.pow(Math.min(Math.max(1 - Math.pow(d / cutoff, 4), 0), 1), 2) : falloff;
729
+ };
730
+ /**
731
+ * The lighting pass of 'frame' lighting at one froxel (FrameLightingMaterial `createFragmentNode`,
732
+ * grey, light probe off): from the 4 density targets
733
+ * (albedo·σ, σ), (emission·σ, t·σ), (sky up, sky down, slot 0, slot 1)·σ, (slots 2–5)·σ, the froxel's
734
+ * view segment and the camera matrix (column-major). Returns the premultiplied (radiance·α, α), or
735
+ * zeros when σ ≤ 0 (the pass discards; the target is cleared).
736
+ */
737
+ export function vdbFrameLightingFroxel(density, viewNear, viewFar, cameraWorld, inputs) {
738
+ const [albedoT, emissionT, shadow0T, shadow1T] = density;
739
+ const extinction = albedoT[3];
740
+ if (!(extinction > 0))
741
+ return [0, 0, 0, 0];
742
+ const m = cameraWorld;
743
+ const visibleT = Math.min(Math.max(emissionT[3] / extinction, 0), 1);
744
+ const view = [viewNear[0] + (viewFar[0] - viewNear[0]) * visibleT, viewNear[1] + (viewFar[1] - viewNear[1]) * visibleT, viewNear[2] + (viewFar[2] - viewNear[2]) * visibleT];
745
+ const world = [0, 1, 2].map((r) => m[r] * view[0] + m[4 + r] * view[1] + m[8 + r] * view[2] + m[12 + r]);
746
+ const seg = [viewFar[0] - viewNear[0], viewFar[1] - viewNear[1], viewFar[2] - viewNear[2]];
747
+ const ray = normalize3([0, 1, 2].map((r) => m[r] * seg[0] + m[4 + r] * seg[1] + m[8 + r] * seg[2]));
748
+ const s0 = shadow0T.map((v) => v / extinction);
749
+ const s1 = shadow1T.map((v) => v / extinction);
750
+ const slots = [s0[2], s0[3], s1[0], s1[1], s1[2], s1[3]];
751
+ const skyUp = s0[0] * 0.5;
752
+ const skyDown = s0[1] * 0.5;
753
+ const spectrum = inputs.phaseSpectrum ?? [1, 1, 0];
754
+ const colorPhase = spectrum[2] > 0.5;
755
+ const directs = colorPhase && inputs.directAt ? inputs.directAt(world) : [1, 1, 1, 1, 1, 1];
756
+ const ambientScale = inputs.ambientOcclusion ? skyUp + skyDown : 1;
757
+ const irradiance = [0, 1, 2].map((c) => inputs.ambient[c] * ambientScale + inputs.hemiSky[c] * skyUp + inputs.hemiGround[c] * skyDown);
758
+ if (inputs.probe) {
759
+ const sky = normalize3(inputs.sky ?? [0, 1, 0]);
760
+ const up = shIrradiance(sky, inputs.probe);
761
+ const down = shIrradiance([-sky[0], -sky[1], -sky[2]], inputs.probe);
762
+ for (let c = 0; c < 3; c++)
763
+ irradiance[c] = irradiance[c] + up[c] * skyUp + down[c] * skyDown;
764
+ }
765
+ inputs.lights.forEach((light, i) => {
766
+ const p = light.position;
767
+ const toLight = [p[0] - world[0], p[1] - world[1], p[2] - world[2]];
768
+ const lightDistance = Math.hypot(...toLight);
769
+ const dir = p[3] < 1.5 ? [p[0], p[1], p[2]] : normalize3(toLight);
770
+ const spot = p[3] > 2.5 && light.spot ? smoothstep(light.spot[3], light.penumbra ?? 1, normalize3(toLight)[0] * light.spot[0] + normalize3(toLight)[1] * light.spot[1] + normalize3(toLight)[2] * light.spot[2]) : 1;
771
+ const dist = p[3] > 1.5 ? distanceAttenuation(lightDistance, light.falloff?.[0] ?? 0, light.falloff?.[1] ?? 0) : 1;
772
+ // A light with no shadow slot: no shadow (1, 1); octaves still add their light.
773
+ const unshadowed = vdbFrameShadowedLightColor(inputs.phase, spectrum, inputs.octaves ?? vdbFrameOctavesOff, ray, dir, [1, 1]);
774
+ const hasSlot = i < inputs.shadowLightCount;
775
+ const shadow = i < 6 ? slots[i] : 1;
776
+ const v = inputs.occluderAt ? inputs.occluderAt(i, world) : 1;
777
+ const factor = hasSlot ? [shadow, shadow, shadow] : [unshadowed[0] * v, unshadowed[1] * v, unshadowed[2] * v];
778
+ // Per-channel phases: the slot holds the green phase; the direct light adds the red and blue difference.
779
+ if (colorPhase && hasSlot) {
780
+ const phase = vdbFramePhaseColor(inputs.phase, spectrum, ray, dir);
781
+ const direct = (i < 6 ? directs[i] : 1) * v;
782
+ for (let c = 0; c < 3; c++)
783
+ factor[c] = factor[c] + (phase[c] - phase[1]) * direct;
784
+ }
785
+ for (let c = 0; c < 3; c++)
786
+ irradiance[c] = irradiance[c] + light.color[c] * factor[c] * spot * dist;
787
+ });
788
+ inputs.environmentColors.forEach((color, i) => {
789
+ const slot = inputs.environmentShadowSlot + i;
790
+ const shadow = slot < 6 ? slots[slot] : 1;
791
+ for (let c = 0; c < 3; c++)
792
+ irradiance[c] = irradiance[c] + color[c] * shadow;
793
+ });
794
+ const alpha = 1 - Math.exp(-extinction * Math.hypot(...seg));
795
+ const out = [0, 0, 0, alpha];
796
+ for (let c = 0; c < 3; c++) {
797
+ const radiance = (albedoT[c] / extinction) * irradiance[c] * (1 / Math.PI) + emissionT[c] / extinction;
798
+ out[c] = radiance * alpha;
799
+ }
800
+ return out;
801
+ }
802
+ //# sourceMappingURL=grid.js.map