@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,183 @@
1
+ /**
2
+ * K6.3, design §3.6 (Q5): the core's `multipleScattering: 'mlp'` is an EXPERIMENTAL generic small-MLP evaluator. A
3
+ * network is data: its layer shapes become a uniform and its weights a storage buffer, so a new network needs no shader
4
+ * change. The inputs are his `'neural'` features at 3·L + 2 values (L feature levels): log(1 + σ h 2^k) at the voxel,
5
+ * h 2^k toward the light and h 2^k away from it for k < L, then log(1 + direct optical depth) and √(absorption /
6
+ * extinction) of level 1. The output is the scattered light (total − direct) of a light slot. Our trained network (K6.N, D36)
7
+ * ({@link vdbFrameMlpFromNeural} of `vdbFrameNeuralWeights`) is the first network, not the definition.
8
+ */
9
+ import type { Vec2, Vec3 } from "./index.js";
10
+ import type { VDBFrameNeuralNetwork } from "./neural.js";
11
+ import type { VDBFrameTexture3d } from "./stack.js";
12
+ import { type VDBFrameGridLayout } from "./grid.js";
13
+ /** Most layers and the widest layer of the core evaluator (two 64-wide locals). */
14
+ export declare const VDB_FRAME_MLP_MAX_LAYERS = 8;
15
+ export declare const VDB_FRAME_MLP_MAX_WIDTH = 64;
16
+ /** Feature levels L of a network (level 0 the grid, mips 1–5 at the K6.N reaches). */
17
+ export declare const VDB_FRAME_MLP_MAX_LEVELS = 6;
18
+ /**
19
+ * K6.Nb: mips of the core's feature chain (to one voxel, at most this many). 'world' reaches on a grid finer than
20
+ * {@link VDB_FRAME_MLP_REFERENCE_RESOLUTION} read levels past 5 (level k + shift); levels 0–5 are the K6.N chain.
21
+ */
22
+ export declare const VDB_FRAME_MLP_MAX_MIPS = 8;
23
+ /** K6.Nb: the grid side the networks are trained at (`scripts/k6/neural`): the reference of 'world' reaches. */
24
+ export declare const VDB_FRAME_MLP_REFERENCE_RESOLUTION = 64;
25
+ /**
26
+ * K6.Nb `mlpReach`: the feature reaches of a network. `'grid'` (K6.N, his): h 2^k with h the last cascade's largest voxel
27
+ * side, level k (the features move with the grid side). `'world'`: unit 2^k with `unit` the voxel the last cascade would
28
+ * have at {@link VDB_FRAME_MLP_REFERENCE_RESOLUTION} (64) over the same casters, read at mip level k + `shift`
29
+ * (shift = log2(unit / h), an integer: both voxels are powers of two). At side 64 both are the same numbers.
30
+ */
31
+ export interface VDBFrameMlpReach {
32
+ /** The world length of feature level 0. */
33
+ unit: number;
34
+ /** The mip level of feature level k is max(k + shift, 0) (clamped to the chain by the sampler). */
35
+ shift: number;
36
+ }
37
+ /**
38
+ * K6.Nb: the reach of a network on the last cascade. `extent`: the world size of the casters' box (the union of the
39
+ * caster boxes, the last cascade's box); `voxel`: the last cascade's voxel. `'grid'` gives (max voxel side, 0).
40
+ */
41
+ export declare function vdbFrameMlpReach(mode: "grid" | "world", extent: readonly number[], voxel: readonly number[]): VDBFrameMlpReach;
42
+ /**
43
+ * K7.4d-a `mlpFeatures: 'cubic'`: the per-axis reduction of the cubic feature chain. The cascade fitter snaps each axis
44
+ * of the last cascade to its own power-of-two voxel, but a feature level is one length (h 2^k, h the largest voxel
45
+ * side). Axis a has voxels of h / 2^e[a]: level 0 of the cubic chain is the box mean of 2^e[0] × 2^e[1] × 2^e[2] voxels
46
+ * (a cube of side h), every level after it a 2 × 2 × 2 box of the one before (a cube of side h 2^k). (0, 0, 0): the
47
+ * voxels are cubes already, and the chain is the K6.3 one.
48
+ */
49
+ export declare function vdbFrameMlpCubicReduce(voxel: readonly number[]): Vec3;
50
+ /**
51
+ * K7.4d-a: texels per axis of the cubic feature chain's mips: mip j IS feature level j (mip 0 the level-0 boxes of
52
+ * {@link vdbFrameMlpCubicReduce}), max(1, (R >> e[a]) >> j) on axis a, down to one texel and at most
53
+ * {@link VDB_FRAME_MLP_MAX_MIPS} + 1 mips (levels 0 to 8, as the K6.Nb chain plus the grid).
54
+ */
55
+ export declare function vdbFrameMlpCubicSizes(resolution: number, reduce: readonly number[]): Vec3[];
56
+ /**
57
+ * K7.4d-a: the cubic chain's first kernel (`vdbFrameGridMipReduceCs`) at texel `p` of level 0: the mean of the
58
+ * 2^e[0] × 2^e[1] × 2^e[2] voxels (p << e) + i of the last cascade (each axis clamped to `resolution` − 1) read at
59
+ * `origin` in the stack. `channels` values (2: extinction, absorption; 3: a spectral stack's rgb).
60
+ */
61
+ export declare function vdbFrameMlpCubicTexel(source: VDBFrameTexture3d, origin: readonly number[], resolution: number, reduce: readonly number[], p: Vec3, channels?: number): number[];
62
+ /** K6.Nb: the extra inputs of a network after its 3 L + 2 features (1 for `extra: 'g'`, K6.Nb2: 3 for `'phase'`). */
63
+ export declare function vdbFrameMlpExtraInputs(mlp: {
64
+ extra?: VDBFrameMlp["extra"] | undefined;
65
+ }): number;
66
+ /** K6.Nb2: most extra inputs a network may take (the shape uniform's `extra: vec4f`). */
67
+ export declare const VDB_FRAME_MLP_MAX_EXTRA = 4;
68
+ /**
69
+ * K6.Nb: the anisotropy input of `extra: 'g'` networks: the phase's mean cosine, (1 − w) g₁ + w g₂ of its two lobes
70
+ * (`vdbFramePhaseLobes`: the Lorenz-Mie modes at the table's asymmetry; spectral: the green channel).
71
+ */
72
+ export declare function vdbFrameMlpPhaseG(phase: readonly [number, number, number, number], phaseSpectrum: readonly [number, number, number]): number;
73
+ /**
74
+ * K6.Nb2: the anisotropy inputs of `extra: 'phase'` networks: the phase's two lobes (g₁, g₂, w), the phase being
75
+ * (1 − w) HG(g₁) + w HG(g₂) (`vdbFramePhaseLobes`: the Lorenz-Mie modes at the table's asymmetry; spectral: the green
76
+ * channel). Canonical, so one phase has one input: the lobe of weight ≥ ½ first (w ≤ ½), and one lobe (w = 0, or both
77
+ * lobes equal) is (g, g, 0). The trainer's `canonicalPhase` (scripts/k6/neural/inputs.mjs) is the same rule.
78
+ */
79
+ export declare function vdbFrameMlpPhaseInputs(phase: readonly [number, number, number, number], phaseSpectrum: readonly [number, number, number]): [number, number, number];
80
+ /** K6.Nb2: the values of a network's extra inputs for a phase (none, the mean cosine, or the lobes). */
81
+ export declare function vdbFrameMlpExtraValues(mlp: Pick<VDBFrameMlp, "extra">, phase: readonly [number, number, number, number], phaseSpectrum: readonly [number, number, number]): number[];
82
+ /** K6.Nb: the byte offset of `VdbFrameMlp.reach` (after `info` and the layer table); K6.Nb2: `extra` follows it. */
83
+ export declare const VDB_FRAME_MLP_REACH_OFFSET: number;
84
+ /**
85
+ * K6.Nb: the `reach` and (K6.Nb2) `extra` fields of the shape uniform at {@link VDB_FRAME_MLP_REACH_OFFSET}: `reach` =
86
+ * (unit, shift, extra input count, chain base), `extra` = the extra inputs' values (at most
87
+ * {@link VDB_FRAME_MLP_MAX_EXTRA}, f32). K7.4d-a `base`: 0 = level 0 is the grid and level k ≥ 1 mip k − 1 (K6.3); 1 =
88
+ * the cubic chain on a non-cubic cascade, level k is mip k.
89
+ */
90
+ export declare function vdbFrameMlpReachUniform(reach: VDBFrameMlpReach, extra?: readonly number[], base?: 0 | 1): Float32Array;
91
+ /** One dense layer: `outputs` = activation(W · x + b), W row-major (row j = output j). */
92
+ export interface VDBFrameMlpLayer {
93
+ inputs: number;
94
+ outputs: number;
95
+ activation: "relu" | "linear";
96
+ }
97
+ /** A network for the core's experimental `'mlp'` multiple scattering. */
98
+ export interface VDBFrameMlp {
99
+ /** A label for warnings and signatures. */
100
+ name?: string;
101
+ /** Feature levels L (2–6): the first layer takes 3 L + 2 inputs. */
102
+ levels: number;
103
+ layers: readonly VDBFrameMlpLayer[];
104
+ /** The output transform of the last layer's first output: `'exp'` = exp(min(o, 4)) (his), `'linear'` = o. */
105
+ output: "exp" | "linear";
106
+ /**
107
+ * K6.Nb: extra inputs after the 3 L + 2 features. `'g'`: the phase's mean cosine (an anisotropy input: one network
108
+ * for every phase; {@link vdbFrameMlpPhaseG}). K6.Nb2 `'phase'`: the phase's lobes g₁, g₂, w (three inputs,
109
+ * {@link vdbFrameMlpPhaseInputs}). Default none (his layout).
110
+ */
111
+ extra?: "g" | "phase";
112
+ /** Per layer, in order: outputs × inputs weights (row-major), then the outputs biases. */
113
+ weights: Float32Array;
114
+ }
115
+ /** The weight offset of each layer (its row-major W; the biases follow at offset + outputs × inputs). */
116
+ export declare function vdbFrameMlpOffsets(mlp: Pick<VDBFrameMlp, "layers">): number[];
117
+ /** Checks a network the core evaluator runs; returns a reason, or null when it fits. */
118
+ export declare function vdbFrameMlpCheck(mlp: VDBFrameMlp): string | null;
119
+ /**
120
+ * His `'neural'` network (vec4 layout: w1 rows, b1, w2 rows, b2, w3, b3.x) as a generic MLP: the same numbers
121
+ * (his layout is row-major with the biases after each W; the 3 pad floats after b3 are dropped).
122
+ */
123
+ export declare function vdbFrameMlpFromNeural(network: VDBFrameNeuralNetwork): VDBFrameMlp;
124
+ /** The shape uniform of the core kernel (`VdbFrameMlp`: info, then (inputs, outputs, activation, offset) per layer). */
125
+ export declare function vdbFrameMlpShape(mlp: VDBFrameMlp): Uint32Array;
126
+ /** The forward pass (f64): the last layer's first output through the output transform. */
127
+ export declare function vdbFrameMlpForward(mlp: VDBFrameMlp, inputs: ArrayLike<number>): number;
128
+ /**
129
+ * Voxels per side of the core's feature mip chain: mip j has max(1, (R >> 1) >> j), down to one voxel and at most
130
+ * {@link VDB_FRAME_MLP_MAX_MIPS} mips (K6.N had at most 5, levels 1–5; K6.Nb runs on to 1 voxel for 'world' reaches:
131
+ * mips 0–4 and so levels 0–5 are unchanged).
132
+ */
133
+ export declare function vdbFrameMlpMipSizes(resolution: number): number[];
134
+ /**
135
+ * The `gridMips` kernel (his FrameGridMipMaterial box) at texel `p` of a mip of side `size`: the mean of the 2 × 2 × 2
136
+ * source texels 2p + i (each axis clamped to `sourceSize` − 1) of `source` read at `origin` (.xy: extinction, absorption).
137
+ */
138
+ export declare function vdbFrameMlpMipTexel(source: VDBFrameTexture3d, origin: readonly number[], sourceSize: readonly number[], p: Vec3): Vec2;
139
+ /**
140
+ * sampleLevel on the core's textures: level 0 the last cascade in the shadow stack (`grid`, its origin), level k ≥ 1
141
+ * mip min(k − 1, mips − 1) (`mips[j]`, its own texture), hardware trilinear clamped to the half-texel box; 0 outside.
142
+ * K7.4d-a `base` 1 (the cubic chain on a non-cubic cascade): level k is mip min(k, mips − 1), the grid is not read.
143
+ */
144
+ export declare function vdbFrameMlpSampleLevel(layout: VDBFrameGridLayout, grid: VDBFrameTexture3d, gridOrigin: readonly number[], mips: readonly VDBFrameTexture3d[], level: number, world: Vec3, base?: 0 | 1): Vec2;
145
+ /**
146
+ * The 3 L + 2 inputs at a world position for a unit direction to the light (his getLocalInputs + neuralLight). `h` is
147
+ * the reach unit; K6.Nb `shift` reads feature level k at mip level max(k + shift, 0) ('world' reaches,
148
+ * {@link vdbFrameMlpReach}; 0: his).
149
+ */
150
+ export declare function vdbFrameMlpInputs(sample: (level: number, world: Vec3) => Vec2, levels: number, h: number, world: Vec3, direction: Vec3, opticalDepth: number, shift?: number, extra?: readonly number[]): number[];
151
+ /**
152
+ * K7.4a: the spectral `gridMips` kernel at texel `p` (as {@link vdbFrameMlpMipTexel}): the box mean of channels .xyz
153
+ * (extinction rgb of the extinction stack, or absorption rgb of the absorption stack).
154
+ */
155
+ export declare function vdbFrameMlpMipTexelRgb(source: VDBFrameTexture3d, origin: readonly number[], sourceSize: readonly number[], p: Vec3): Vec3;
156
+ /** K7.4a: {@link vdbFrameMlpSampleLevel} of channels .xyz (a spectral stack and its mips; K7.4d-a `base`); 0 outside. */
157
+ export declare function vdbFrameMlpSampleLevelRgb(layout: VDBFrameGridLayout, grid: VDBFrameTexture3d, gridOrigin: readonly number[], mips: readonly VDBFrameTexture3d[], level: number, world: Vec3, base?: 0 | 1): Vec3;
158
+ /**
159
+ * K7.4a: the network's scattered light of each channel of a spectral medium (the spectral transmittance kernel's
160
+ * `vdbFrameMlpLight3`): one forward pass per channel c on that channel's inputs ({@link vdbFrameMlpInputs} with
161
+ * extinction c, absorption c and the direct optical depth c). `extinction` / `absorption` sample a feature level of the
162
+ * extinction and absorption stacks (rgb). On a grey medium the three channels are the grey network's value.
163
+ */
164
+ export declare function vdbFrameSpectralMlpLight(mlp: VDBFrameMlp, extinction: (level: number, world: Vec3) => Vec3, absorption: (level: number, world: Vec3) => Vec3, h: number, world: Vec3, direction: Vec3, opticalDepth: Vec3, shift?: number, extra?: readonly number[]): Vec3;
165
+ /** vec4s of one packed layer: ⌈outputs / 4⌉ × ⌈inputs / 4⌉ mat4x4 (4 vec4 each), then ⌈outputs / 4⌉ bias vec4s. */
166
+ export declare function vdbFrameMlpPackedLayerVectors(l: Pick<VDBFrameMlpLayer, "inputs" | "outputs">): number;
167
+ /** The vec4 offset of each packed layer (its matrices; the bias groups follow at offset + 4 ⌈out/4⌉ ⌈in/4⌉). */
168
+ export declare function vdbFrameMlpPackedOffsets(mlp: Pick<VDBFrameMlp, "layers">): number[];
169
+ /**
170
+ * K6.Na: the weights in the packed layout the core's `mlpRuntime: 'packed'` evaluator reads (`array<vec4f>`): per layer,
171
+ * for each output group o and input chunk k the mat4x4 M[o, k] (column j = input 4k + j, row i = output 4o + i,
172
+ * column-major: element (i, j) at 4j + i), then the biases padded to vec4. Padded inputs and outputs are zero, so a
173
+ * padded output is 0 through ReLU or linear and the next layer's padded inputs read 0.
174
+ */
175
+ export declare function vdbFrameMlpPack(mlp: VDBFrameMlp): Float32Array;
176
+ /** The shape uniform of the packed evaluator: as {@link vdbFrameMlpShape}, with each layer's offset in vec4s. */
177
+ export declare function vdbFrameMlpPackedShape(mlp: VDBFrameMlp): Uint32Array;
178
+ /**
179
+ * The packed evaluator's forward pass (f64) on {@link vdbFrameMlpPack} data and the shape: per output group the bias
180
+ * plus M[o, k] · x[k] over the input chunks, then the activation. A check that the packing loses nothing: it equals
181
+ * {@link vdbFrameMlpForward} on the unpacked network (the oracle of both evaluators).
182
+ */
183
+ export declare function vdbFrameMlpForwardPacked(packed: ArrayLike<number>, shape: ArrayLike<number>, inputs: ArrayLike<number>): number;
@@ -0,0 +1,434 @@
1
+ // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
2
+ // src/three-openvdb/frame/webgpu/frameNeuralChunks.js L14–129 (dense layers, getLocalInputs, neuralLight: the
3
+ // inputs of his 'neural' network), src/three-openvdb/frame/webgpu/FrameGridMipMaterial.js L10–66 (the 2x2x2 box mip).
4
+ // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
5
+ // Changes: a generic small-MLP description (layer shapes as data, any activation sequence) instead of his fixed
6
+ // 20 → 32 → 32 → 1 vec4 layout; the mips are levels of one 3D texture. CPU twins of the core's 'mlp' kernels (K6.3).
7
+ // Divergences: DIVERGES.md (K6.3 rows).
8
+ import { vdbFramePhaseLobes } from "./ambient.js";
9
+ import { vdbFrameTrilinear } from "./stack.js";
10
+ import { vdbFrameGridUvw } from "./grid.js";
11
+ /** Most layers and the widest layer of the core evaluator (two 64-wide locals). */
12
+ export const VDB_FRAME_MLP_MAX_LAYERS = 8;
13
+ export const VDB_FRAME_MLP_MAX_WIDTH = 64;
14
+ /** Feature levels L of a network (level 0 the grid, mips 1–5 at the K6.N reaches). */
15
+ export const VDB_FRAME_MLP_MAX_LEVELS = 6;
16
+ /**
17
+ * K6.Nb: mips of the core's feature chain (to one voxel, at most this many). 'world' reaches on a grid finer than
18
+ * {@link VDB_FRAME_MLP_REFERENCE_RESOLUTION} read levels past 5 (level k + shift); levels 0–5 are the K6.N chain.
19
+ */
20
+ export const VDB_FRAME_MLP_MAX_MIPS = 8;
21
+ /** K6.Nb: the grid side the networks are trained at (`scripts/k6/neural`): the reference of 'world' reaches. */
22
+ export const VDB_FRAME_MLP_REFERENCE_RESOLUTION = 64;
23
+ /** The largest power-of-two voxel side {@link vdbFrameGridCascades} gives a box of `extent` at side `resolution`. */
24
+ const cascadeUnit = (extent, resolution) => Math.max(...[0, 1, 2].map((a) => Math.pow(2, Math.ceil(Math.log2(Math.max(extent[a], 1e-6) / (resolution - 1))))));
25
+ /**
26
+ * K6.Nb: the reach of a network on the last cascade. `extent`: the world size of the casters' box (the union of the
27
+ * caster boxes, the last cascade's box); `voxel`: the last cascade's voxel. `'grid'` gives (max voxel side, 0).
28
+ */
29
+ export function vdbFrameMlpReach(mode, extent, voxel) {
30
+ const h = Math.max(voxel[0], voxel[1], voxel[2]);
31
+ if (mode !== "world" || !(h > 0))
32
+ return { unit: h, shift: 0 };
33
+ const unit = cascadeUnit(extent, VDB_FRAME_MLP_REFERENCE_RESOLUTION);
34
+ return { unit, shift: Math.round(Math.log2(unit / h)) };
35
+ }
36
+ /**
37
+ * K7.4d-a `mlpFeatures: 'cubic'`: the per-axis reduction of the cubic feature chain. The cascade fitter snaps each axis
38
+ * of the last cascade to its own power-of-two voxel, but a feature level is one length (h 2^k, h the largest voxel
39
+ * side). Axis a has voxels of h / 2^e[a]: level 0 of the cubic chain is the box mean of 2^e[0] × 2^e[1] × 2^e[2] voxels
40
+ * (a cube of side h), every level after it a 2 × 2 × 2 box of the one before (a cube of side h 2^k). (0, 0, 0): the
41
+ * voxels are cubes already, and the chain is the K6.3 one.
42
+ */
43
+ export function vdbFrameMlpCubicReduce(voxel) {
44
+ const h = Math.max(voxel[0], voxel[1], voxel[2]);
45
+ const e = (v) => (h > 0 && v > 0 ? Math.max(0, Math.round(Math.log2(h / v))) : 0);
46
+ return [e(voxel[0]), e(voxel[1]), e(voxel[2])];
47
+ }
48
+ /**
49
+ * K7.4d-a: texels per axis of the cubic feature chain's mips: mip j IS feature level j (mip 0 the level-0 boxes of
50
+ * {@link vdbFrameMlpCubicReduce}), max(1, (R >> e[a]) >> j) on axis a, down to one texel and at most
51
+ * {@link VDB_FRAME_MLP_MAX_MIPS} + 1 mips (levels 0 to 8, as the K6.Nb chain plus the grid).
52
+ */
53
+ export function vdbFrameMlpCubicSizes(resolution, reduce) {
54
+ const at = (j) => [0, 1, 2].map((a) => Math.max(1, (resolution >> reduce[a]) >> j));
55
+ const sizes = [at(0)];
56
+ while (sizes.length < VDB_FRAME_MLP_MAX_MIPS + 1 && sizes[sizes.length - 1].some((n) => n > 1))
57
+ sizes.push(at(sizes.length));
58
+ return sizes;
59
+ }
60
+ /**
61
+ * K7.4d-a: the cubic chain's first kernel (`vdbFrameGridMipReduceCs`) at texel `p` of level 0: the mean of the
62
+ * 2^e[0] × 2^e[1] × 2^e[2] voxels (p << e) + i of the last cascade (each axis clamped to `resolution` − 1) read at
63
+ * `origin` in the stack. `channels` values (2: extinction, absorption; 3: a spectral stack's rgb).
64
+ */
65
+ export function vdbFrameMlpCubicTexel(source, origin, resolution, reduce, p, channels = 2) {
66
+ const sum = new Array(channels).fill(0);
67
+ const n = [1 << reduce[0], 1 << reduce[1], 1 << reduce[2]];
68
+ for (let k = 0; k < n[2]; k++)
69
+ for (let j = 0; j < n[1]; j++)
70
+ for (let i = 0; i < n[0]; i++) {
71
+ const q = [p[0] * n[0] + i, p[1] * n[1] + j, p[2] * n[2] + k].map((v, a) => Math.min(v, resolution - 1) + origin[a]);
72
+ const at = (q[0] + (q[1] + q[2] * source.size[1]) * source.size[0]) * source.channels;
73
+ for (let c = 0; c < channels; c++)
74
+ sum[c] = sum[c] + source.data[at + c];
75
+ }
76
+ return sum.map((v) => v / (n[0] * n[1] * n[2]));
77
+ }
78
+ /** K6.Nb: the extra inputs of a network after its 3 L + 2 features (1 for `extra: 'g'`, K6.Nb2: 3 for `'phase'`). */
79
+ export function vdbFrameMlpExtraInputs(mlp) {
80
+ return mlp.extra === "g" ? 1 : mlp.extra === "phase" ? 3 : 0;
81
+ }
82
+ /** K6.Nb2: most extra inputs a network may take (the shape uniform's `extra: vec4f`). */
83
+ export const VDB_FRAME_MLP_MAX_EXTRA = 4;
84
+ /**
85
+ * K6.Nb: the anisotropy input of `extra: 'g'` networks: the phase's mean cosine, (1 − w) g₁ + w g₂ of its two lobes
86
+ * (`vdbFramePhaseLobes`: the Lorenz-Mie modes at the table's asymmetry; spectral: the green channel).
87
+ */
88
+ export function vdbFrameMlpPhaseG(phase, phaseSpectrum) {
89
+ const lobes = vdbFramePhaseLobes([...phase], [...phaseSpectrum]);
90
+ return lobes.g[0][1] + (lobes.g[1][1] - lobes.g[0][1]) * lobes.weight;
91
+ }
92
+ /**
93
+ * K6.Nb2: the anisotropy inputs of `extra: 'phase'` networks: the phase's two lobes (g₁, g₂, w), the phase being
94
+ * (1 − w) HG(g₁) + w HG(g₂) (`vdbFramePhaseLobes`: the Lorenz-Mie modes at the table's asymmetry; spectral: the green
95
+ * channel). Canonical, so one phase has one input: the lobe of weight ≥ ½ first (w ≤ ½), and one lobe (w = 0, or both
96
+ * lobes equal) is (g, g, 0). The trainer's `canonicalPhase` (scripts/k6/neural/inputs.mjs) is the same rule.
97
+ */
98
+ export function vdbFrameMlpPhaseInputs(phase, phaseSpectrum) {
99
+ const lobes = vdbFramePhaseLobes([...phase], [...phaseSpectrum]);
100
+ let g1 = lobes.g[0][1];
101
+ let g2 = lobes.g[1][1];
102
+ let w = lobes.weight;
103
+ if (w > 0.5)
104
+ [g1, g2, w] = [g2, g1, 1 - w];
105
+ return !(w > 0) || g1 === g2 ? [g1, g1, 0] : [g1, g2, w];
106
+ }
107
+ /** K6.Nb2: the values of a network's extra inputs for a phase (none, the mean cosine, or the lobes). */
108
+ export function vdbFrameMlpExtraValues(mlp, phase, phaseSpectrum) {
109
+ if (mlp.extra === "g")
110
+ return [vdbFrameMlpPhaseG(phase, phaseSpectrum)];
111
+ if (mlp.extra === "phase")
112
+ return vdbFrameMlpPhaseInputs(phase, phaseSpectrum);
113
+ return [];
114
+ }
115
+ /** K6.Nb: the byte offset of `VdbFrameMlp.reach` (after `info` and the layer table); K6.Nb2: `extra` follows it. */
116
+ export const VDB_FRAME_MLP_REACH_OFFSET = 16 + 16 * VDB_FRAME_MLP_MAX_LAYERS;
117
+ /**
118
+ * K6.Nb: the `reach` and (K6.Nb2) `extra` fields of the shape uniform at {@link VDB_FRAME_MLP_REACH_OFFSET}: `reach` =
119
+ * (unit, shift, extra input count, chain base), `extra` = the extra inputs' values (at most
120
+ * {@link VDB_FRAME_MLP_MAX_EXTRA}, f32). K7.4d-a `base`: 0 = level 0 is the grid and level k ≥ 1 mip k − 1 (K6.3); 1 =
121
+ * the cubic chain on a non-cubic cascade, level k is mip k.
122
+ */
123
+ export function vdbFrameMlpReachUniform(reach, extra = [], base = 0) {
124
+ const u = new Float32Array(8);
125
+ u[0] = reach.unit;
126
+ u[1] = reach.shift;
127
+ u[2] = Math.min(extra.length, VDB_FRAME_MLP_MAX_EXTRA);
128
+ u[3] = base;
129
+ extra.slice(0, VDB_FRAME_MLP_MAX_EXTRA).forEach((v, i) => (u[4 + i] = v));
130
+ return u;
131
+ }
132
+ /** The weight offset of each layer (its row-major W; the biases follow at offset + outputs × inputs). */
133
+ export function vdbFrameMlpOffsets(mlp) {
134
+ const offsets = [];
135
+ let at = 0;
136
+ for (const l of mlp.layers) {
137
+ offsets.push(at);
138
+ at += l.outputs * (l.inputs + 1);
139
+ }
140
+ return offsets;
141
+ }
142
+ /** Checks a network the core evaluator runs; returns a reason, or null when it fits. */
143
+ export function vdbFrameMlpCheck(mlp) {
144
+ if (!Number.isInteger(mlp.levels) || mlp.levels < 2 || mlp.levels > VDB_FRAME_MLP_MAX_LEVELS)
145
+ return `levels must be 2 to ${VDB_FRAME_MLP_MAX_LEVELS} (got ${mlp.levels})`;
146
+ if (mlp.layers.length < 1 || mlp.layers.length > VDB_FRAME_MLP_MAX_LAYERS)
147
+ return `1 to ${VDB_FRAME_MLP_MAX_LAYERS} layers (got ${mlp.layers.length})`;
148
+ if (mlp.extra !== undefined && mlp.extra !== "g" && mlp.extra !== "phase")
149
+ return "extra must be 'g', 'phase' or absent";
150
+ const inputs = 3 * mlp.levels + 2 + vdbFrameMlpExtraInputs(mlp);
151
+ if (mlp.layers[0].inputs !== inputs)
152
+ return `the first layer takes 3 × levels + 2${mlp.extra ? ` + ${vdbFrameMlpExtraInputs(mlp)} (extra '${mlp.extra}')` : ""} = ${inputs} inputs (got ${mlp.layers[0].inputs})`;
153
+ for (let i = 0; i < mlp.layers.length; i++) {
154
+ const l = mlp.layers[i];
155
+ if (!(l.inputs >= 1 && l.inputs <= VDB_FRAME_MLP_MAX_WIDTH && l.outputs >= 1 && l.outputs <= VDB_FRAME_MLP_MAX_WIDTH))
156
+ return `layer ${i}: widths must be 1 to ${VDB_FRAME_MLP_MAX_WIDTH}`;
157
+ if (i > 0 && l.inputs !== mlp.layers[i - 1].outputs)
158
+ return `layer ${i} takes ${l.inputs} inputs, the layer before gives ${mlp.layers[i - 1].outputs}`;
159
+ if (l.activation !== "relu" && l.activation !== "linear")
160
+ return `layer ${i}: activation must be 'relu' or 'linear'`;
161
+ }
162
+ if (mlp.output !== "exp" && mlp.output !== "linear")
163
+ return "output must be 'exp' or 'linear'";
164
+ const total = mlp.layers.reduce((s, l) => s + l.outputs * (l.inputs + 1), 0);
165
+ if (mlp.weights.length !== total)
166
+ return `expected ${total} weights, got ${mlp.weights.length}`;
167
+ return null;
168
+ }
169
+ /**
170
+ * His `'neural'` network (vec4 layout: w1 rows, b1, w2 rows, b2, w3, b3.x) as a generic MLP: the same numbers
171
+ * (his layout is row-major with the biases after each W; the 3 pad floats after b3 are dropped).
172
+ */
173
+ export function vdbFrameMlpFromNeural(network) {
174
+ const n = network.inputs;
175
+ const h = network.hidden;
176
+ const total = h * (n + 1) + h * (h + 1) + (h + 1);
177
+ return {
178
+ name: network.name ?? "neural",
179
+ levels: network.levels,
180
+ layers: [
181
+ { inputs: n, outputs: h, activation: "relu" },
182
+ { inputs: h, outputs: h, activation: "relu" },
183
+ { inputs: h, outputs: 1, activation: "linear" },
184
+ ],
185
+ output: "exp",
186
+ weights: network.weights.slice(0, total),
187
+ };
188
+ }
189
+ /** The shape uniform of the core kernel (`VdbFrameMlp`: info, then (inputs, outputs, activation, offset) per layer). */
190
+ export function vdbFrameMlpShape(mlp) {
191
+ const u = new Uint32Array(4 + 4 * VDB_FRAME_MLP_MAX_LAYERS);
192
+ u[0] = mlp.layers.length;
193
+ u[1] = mlp.levels;
194
+ u[2] = mlp.output === "exp" ? 1 : 0;
195
+ u[3] = 3 * mlp.levels + 2 + vdbFrameMlpExtraInputs(mlp);
196
+ const offsets = vdbFrameMlpOffsets(mlp);
197
+ mlp.layers.forEach((l, i) => {
198
+ u[4 + 4 * i] = l.inputs;
199
+ u[5 + 4 * i] = l.outputs;
200
+ u[6 + 4 * i] = l.activation === "relu" ? 1 : 0;
201
+ u[7 + 4 * i] = offsets[i];
202
+ });
203
+ return u;
204
+ }
205
+ /** The forward pass (f64): the last layer's first output through the output transform. */
206
+ export function vdbFrameMlpForward(mlp, inputs) {
207
+ const offsets = vdbFrameMlpOffsets(mlp);
208
+ const w = mlp.weights;
209
+ let x = Array.from(inputs);
210
+ mlp.layers.forEach((l, li) => {
211
+ const at = offsets[li];
212
+ const bias = at + l.outputs * l.inputs;
213
+ const out = [];
214
+ for (let j = 0; j < l.outputs; j++) {
215
+ let s = w[bias + j];
216
+ for (let i = 0; i < l.inputs; i++)
217
+ s += w[at + j * l.inputs + i] * (x[i] ?? 0);
218
+ out.push(l.activation === "relu" ? Math.max(s, 0) : s);
219
+ }
220
+ x = out;
221
+ });
222
+ return mlp.output === "exp" ? Math.exp(Math.min(x[0], 4)) : x[0];
223
+ }
224
+ /**
225
+ * Voxels per side of the core's feature mip chain: mip j has max(1, (R >> 1) >> j), down to one voxel and at most
226
+ * {@link VDB_FRAME_MLP_MAX_MIPS} mips (K6.N had at most 5, levels 1–5; K6.Nb runs on to 1 voxel for 'world' reaches:
227
+ * mips 0–4 and so levels 0–5 are unchanged).
228
+ */
229
+ export function vdbFrameMlpMipSizes(resolution) {
230
+ const base = Math.max(1, resolution >> 1);
231
+ const sizes = [base];
232
+ while (sizes.length < VDB_FRAME_MLP_MAX_MIPS && sizes[sizes.length - 1] > 1)
233
+ sizes.push(Math.max(1, sizes[sizes.length - 1] >> 1));
234
+ return sizes;
235
+ }
236
+ /**
237
+ * The `gridMips` kernel (his FrameGridMipMaterial box) at texel `p` of a mip of side `size`: the mean of the 2 × 2 × 2
238
+ * source texels 2p + i (each axis clamped to `sourceSize` − 1) of `source` read at `origin` (.xy: extinction, absorption).
239
+ */
240
+ export function vdbFrameMlpMipTexel(source, origin, sourceSize, p) {
241
+ let a = 0;
242
+ let b = 0;
243
+ for (let i = 0; i < 8; i++) {
244
+ const q = [p[0] * 2 + (i & 1), p[1] * 2 + ((i >> 1) & 1), p[2] * 2 + ((i >> 2) & 1)].map((v, k) => Math.min(v, sourceSize[k] - 1) + origin[k]);
245
+ const at = (q[0] + (q[1] + q[2] * source.size[1]) * source.size[0]) * source.channels;
246
+ a += source.data[at];
247
+ b += source.data[at + 1];
248
+ }
249
+ return [a / 8, b / 8];
250
+ }
251
+ /**
252
+ * sampleLevel on the core's textures: level 0 the last cascade in the shadow stack (`grid`, its origin), level k ≥ 1
253
+ * mip min(k − 1, mips − 1) (`mips[j]`, its own texture), hardware trilinear clamped to the half-texel box; 0 outside.
254
+ * K7.4d-a `base` 1 (the cubic chain on a non-cubic cascade): level k is mip min(k, mips − 1), the grid is not read.
255
+ */
256
+ export function vdbFrameMlpSampleLevel(layout, grid, gridOrigin, mips, level, world, base = 0) {
257
+ const cascade = layout.count - 1;
258
+ const uvw = vdbFrameGridUvw(layout, cascade, world);
259
+ if (uvw.some((v) => v < 0 || v > 1))
260
+ return [0, 0];
261
+ if (level === 0 && base === 0) {
262
+ const r = layout.resolution;
263
+ const s = vdbFrameTrilinear(grid, uvw.map((v, k) => gridOrigin[k] + Math.min(Math.max(v * r, 0.5), r - 0.5)));
264
+ return [s[0], s[1]];
265
+ }
266
+ const t = mips[Math.min(level + base - 1, mips.length - 1)];
267
+ const s = vdbFrameTrilinear(t, uvw.map((v, k) => Math.min(Math.max(v * t.size[k], 0.5), t.size[k] - 0.5)));
268
+ return [s[0], s[1]];
269
+ }
270
+ /**
271
+ * The 3 L + 2 inputs at a world position for a unit direction to the light (his getLocalInputs + neuralLight). `h` is
272
+ * the reach unit; K6.Nb `shift` reads feature level k at mip level max(k + shift, 0) ('world' reaches,
273
+ * {@link vdbFrameMlpReach}; 0: his).
274
+ */
275
+ export function vdbFrameMlpInputs(sample, levels, h, world, direction, opticalDepth, shift = 0, extra = []) {
276
+ const input = new Array(3 * levels + 2 + extra.length).fill(0);
277
+ extra.forEach((v, i) => (input[3 * levels + 2 + i] = v));
278
+ for (let k = 0; k < levels; k++) {
279
+ const reach = h * 2 ** k;
280
+ const level = Math.max(k + shift, 0);
281
+ const s = sample(level, world);
282
+ input[k] = Math.log(s[0] * reach + 1);
283
+ if (k === 1 && s[0] > 0)
284
+ input[3 * levels + 1] = Math.sqrt(Math.min(1, Math.max(0, s[1] / Math.max(s[0], 1e-20))));
285
+ input[levels + k] = Math.log(sample(level, [world[0] + direction[0] * reach, world[1] + direction[1] * reach, world[2] + direction[2] * reach])[0] * reach + 1);
286
+ input[2 * levels + k] = Math.log(sample(level, [world[0] - direction[0] * reach, world[1] - direction[1] * reach, world[2] - direction[2] * reach])[0] * reach + 1);
287
+ }
288
+ input[3 * levels] = Math.log(opticalDepth + 1);
289
+ return input;
290
+ }
291
+ // --- K7.4a: spectral media (the network once per channel) ------------------------------------------------------------
292
+ /**
293
+ * K7.4a: the spectral `gridMips` kernel at texel `p` (as {@link vdbFrameMlpMipTexel}): the box mean of channels .xyz
294
+ * (extinction rgb of the extinction stack, or absorption rgb of the absorption stack).
295
+ */
296
+ export function vdbFrameMlpMipTexelRgb(source, origin, sourceSize, p) {
297
+ const sum = [0, 0, 0];
298
+ for (let i = 0; i < 8; i++) {
299
+ const q = [p[0] * 2 + (i & 1), p[1] * 2 + ((i >> 1) & 1), p[2] * 2 + ((i >> 2) & 1)].map((v, k) => Math.min(v, sourceSize[k] - 1) + origin[k]);
300
+ const at = (q[0] + (q[1] + q[2] * source.size[1]) * source.size[0]) * source.channels;
301
+ for (let c = 0; c < 3; c++)
302
+ sum[c] = sum[c] + source.data[at + c];
303
+ }
304
+ return [sum[0] / 8, sum[1] / 8, sum[2] / 8];
305
+ }
306
+ /** K7.4a: {@link vdbFrameMlpSampleLevel} of channels .xyz (a spectral stack and its mips; K7.4d-a `base`); 0 outside. */
307
+ export function vdbFrameMlpSampleLevelRgb(layout, grid, gridOrigin, mips, level, world, base = 0) {
308
+ const cascade = layout.count - 1;
309
+ const uvw = vdbFrameGridUvw(layout, cascade, world);
310
+ if (uvw.some((v) => v < 0 || v > 1))
311
+ return [0, 0, 0];
312
+ if (level === 0 && base === 0) {
313
+ const r = layout.resolution;
314
+ const s = vdbFrameTrilinear(grid, uvw.map((v, k) => gridOrigin[k] + Math.min(Math.max(v * r, 0.5), r - 0.5)));
315
+ return [s[0], s[1], s[2]];
316
+ }
317
+ const t = mips[Math.min(level + base - 1, mips.length - 1)];
318
+ const s = vdbFrameTrilinear(t, uvw.map((v, k) => Math.min(Math.max(v * t.size[k], 0.5), t.size[k] - 0.5)));
319
+ return [s[0], s[1], s[2]];
320
+ }
321
+ /**
322
+ * K7.4a: the network's scattered light of each channel of a spectral medium (the spectral transmittance kernel's
323
+ * `vdbFrameMlpLight3`): one forward pass per channel c on that channel's inputs ({@link vdbFrameMlpInputs} with
324
+ * extinction c, absorption c and the direct optical depth c). `extinction` / `absorption` sample a feature level of the
325
+ * extinction and absorption stacks (rgb). On a grey medium the three channels are the grey network's value.
326
+ */
327
+ export function vdbFrameSpectralMlpLight(mlp, extinction, absorption, h, world, direction, opticalDepth, shift = 0, extra = []) {
328
+ const out = [0, 0, 0];
329
+ for (let c = 0; c < 3; c++) {
330
+ const sample = (level, p) => [extinction(level, p)[c], absorption(level, p)[c]];
331
+ out[c] = vdbFrameMlpForward(mlp, vdbFrameMlpInputs(sample, mlp.levels, h, world, direction, opticalDepth[c], shift, extra));
332
+ }
333
+ return out;
334
+ }
335
+ // --- K6.Na: the packed layout (pmndrs/denoiser `denoiser-wgsl` conv.ts `packWeights` / `packBias`, one tap) -------------
336
+ // Portions derived from pmndrs/denoiser (MIT, Copyright (c) 2024 Dennis Smolek), commit 3ad5e98:
337
+ // packages/denoiser-wgsl/src/conv.ts `packWeights` (mat4x4 per (output group, input chunk, tap), column j = input
338
+ // channel j of the chunk, row i = output channel 4 × group + i; padded channels zero) and `packBias` (vec4 groups).
339
+ // Changes: a dense layer is its 1 × 1 case (one tap, no second source); every layer of the network goes into one
340
+ // `array<vec4f>` (each mat4x4 as its 4 columns, then the layer's bias groups), so the kernel keeps one storage buffer (D10).
341
+ /** vec4s of one packed layer: ⌈outputs / 4⌉ × ⌈inputs / 4⌉ mat4x4 (4 vec4 each), then ⌈outputs / 4⌉ bias vec4s. */
342
+ export function vdbFrameMlpPackedLayerVectors(l) {
343
+ const out4 = Math.ceil(l.outputs / 4);
344
+ return out4 * Math.ceil(l.inputs / 4) * 4 + out4;
345
+ }
346
+ /** The vec4 offset of each packed layer (its matrices; the bias groups follow at offset + 4 ⌈out/4⌉ ⌈in/4⌉). */
347
+ export function vdbFrameMlpPackedOffsets(mlp) {
348
+ const offsets = [];
349
+ let at = 0;
350
+ for (const l of mlp.layers) {
351
+ offsets.push(at);
352
+ at += vdbFrameMlpPackedLayerVectors(l);
353
+ }
354
+ return offsets;
355
+ }
356
+ /**
357
+ * K6.Na: the weights in the packed layout the core's `mlpRuntime: 'packed'` evaluator reads (`array<vec4f>`): per layer,
358
+ * for each output group o and input chunk k the mat4x4 M[o, k] (column j = input 4k + j, row i = output 4o + i,
359
+ * column-major: element (i, j) at 4j + i), then the biases padded to vec4. Padded inputs and outputs are zero, so a
360
+ * padded output is 0 through ReLU or linear and the next layer's padded inputs read 0.
361
+ */
362
+ export function vdbFrameMlpPack(mlp) {
363
+ const offsets = vdbFrameMlpOffsets(mlp);
364
+ const packed = vdbFrameMlpPackedOffsets(mlp);
365
+ const last = mlp.layers[mlp.layers.length - 1];
366
+ const out = new Float32Array((packed[packed.length - 1] + vdbFrameMlpPackedLayerVectors(last)) * 4);
367
+ mlp.layers.forEach((l, li) => {
368
+ const w = offsets[li];
369
+ const in4 = Math.ceil(l.inputs / 4);
370
+ const out4 = Math.ceil(l.outputs / 4);
371
+ const base = packed[li] * 4;
372
+ for (let o = 0; o < out4; o++) {
373
+ for (let k = 0; k < in4; k++) {
374
+ const m = base + (o * in4 + k) * 16;
375
+ for (let j = 0; j < 4; j++) {
376
+ const input = 4 * k + j;
377
+ if (input >= l.inputs)
378
+ continue;
379
+ for (let i = 0; i < 4; i++) {
380
+ const output = 4 * o + i;
381
+ if (output >= l.outputs)
382
+ continue;
383
+ out[m + 4 * j + i] = mlp.weights[w + output * l.inputs + input];
384
+ }
385
+ }
386
+ }
387
+ }
388
+ const bias = base + out4 * in4 * 16;
389
+ for (let j = 0; j < l.outputs; j++)
390
+ out[bias + j] = mlp.weights[w + l.outputs * l.inputs + j];
391
+ });
392
+ return out;
393
+ }
394
+ /** The shape uniform of the packed evaluator: as {@link vdbFrameMlpShape}, with each layer's offset in vec4s. */
395
+ export function vdbFrameMlpPackedShape(mlp) {
396
+ const u = vdbFrameMlpShape(mlp);
397
+ vdbFrameMlpPackedOffsets(mlp).forEach((offset, i) => {
398
+ u[7 + 4 * i] = offset;
399
+ });
400
+ return u;
401
+ }
402
+ /**
403
+ * The packed evaluator's forward pass (f64) on {@link vdbFrameMlpPack} data and the shape: per output group the bias
404
+ * plus M[o, k] · x[k] over the input chunks, then the activation. A check that the packing loses nothing: it equals
405
+ * {@link vdbFrameMlpForward} on the unpacked network (the oracle of both evaluators).
406
+ */
407
+ export function vdbFrameMlpForwardPacked(packed, shape, inputs) {
408
+ const count = shape[0];
409
+ let x = Array.from({ length: Math.ceil(inputs.length / 4) * 4 }, (_, i) => inputs[i] ?? 0);
410
+ for (let l = 0; l < count; l++) {
411
+ const n = shape[4 + 4 * l];
412
+ const m = shape[5 + 4 * l];
413
+ const relu = shape[6 + 4 * l] === 1;
414
+ const at = shape[7 + 4 * l] * 4;
415
+ const in4 = Math.ceil(n / 4);
416
+ const out4 = Math.ceil(m / 4);
417
+ const next = new Array(out4 * 4).fill(0);
418
+ for (let o = 0; o < out4; o++) {
419
+ const bias = at + (out4 * in4 * 4 + o) * 4;
420
+ for (let i = 0; i < 4; i++) {
421
+ let s = packed[bias + i];
422
+ for (let k = 0; k < in4; k++) {
423
+ const mat = at + (o * in4 + k) * 16;
424
+ for (let j = 0; j < 4; j++)
425
+ s += packed[mat + 4 * j + i] * (x[4 * k + j] ?? 0);
426
+ }
427
+ next[4 * o + i] = relu ? Math.max(s, 0) : s;
428
+ }
429
+ }
430
+ x = next;
431
+ }
432
+ return shape[2] === 1 ? Math.exp(Math.min(x[0], 4)) : x[0];
433
+ }
434
+ //# sourceMappingURL=mlp.js.map