@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,98 @@
1
+ /**
2
+ * K6.R1: the reference renderer's tables. Tabulated phase functions (his Lorenz-Mie and Mie RGB tables, sampled by
3
+ * inverse CDF), the blackbody emission colour (the renderer's LUT over log temperature) and per-cell majorant grids
4
+ * (piecewise-constant density bounds for delta and ratio tracking: dense texels or the sparse pool's node stats).
5
+ * The GPU kernel reads the same numbers (`core/reference/renderer.ts` packs them into its table and majorant
6
+ * textures), so the CPU twin and the kernel make the same decisions.
7
+ */
8
+ import { type VDBColorMatchingFunctions } from "../frame/blackbody.js";
9
+ import type { WvdbDenseVolume } from "../wvdb/dense.js";
10
+ import type { VDBRefVec3, VDBReferenceColorTable, VDBReferenceMajorantGrid, VDBReferencePhaseTable } from "./scene.js";
11
+ /**
12
+ * The sampling CDF of a phase table: the marginal density of u (θ = π u²) of the channel mean m,
13
+ * p(u) = m(u) · π u · sin(π u²) (phase / isotropic → per steradian, dω = 4π² u sin θ du), trapezoid weights per
14
+ * table interval, normalised; stored in f32 (the GPU table's precision) so the twin and the kernel pick the same
15
+ * interval.
16
+ */
17
+ export declare function vdbReferencePhaseTableCdf(values: ArrayLike<number>, size: number): Float32Array;
18
+ /** A phase table from RGB values (phase / isotropic at θ = π u², `size` angles). */
19
+ export declare function vdbReferencePhaseTable(values: ArrayLike<number>, size: number): VDBReferencePhaseTable;
20
+ /**
21
+ * His Lorenz-Mie tables (the committed `mie-table.ts`, `vdbFrameMieTexels`): 'mono' ('lorenz-mie', one table for
22
+ * every channel) or 'rgb' ('lorenz-mie-rgb', one per channel).
23
+ */
24
+ export declare function vdbReferenceMiePhaseTable(kind: "mono" | "rgb"): VDBReferencePhaseTable;
25
+ /** The tabulated phase per steradian of each channel at cos θ. */
26
+ export declare function vdbRefPhaseTableEval(t: VDBReferencePhaseTable, cosTheta: number): VDBRefVec3;
27
+ /**
28
+ * Sample cos θ from the table's CDF with ξ ∈ [0, 1): the interval j with cdf[j] ≤ ξ < cdf[j+1] (binary search),
29
+ * u uniform in it. `weight` per channel = phase / sampling density (1 for a table whose channels are equal, up to the
30
+ * piecewise-constant density's error): the estimate stays unbiased per channel.
31
+ */
32
+ export declare function vdbRefPhaseTableSample(t: VDBReferencePhaseTable, xi: number): {
33
+ cosTheta: number;
34
+ weight: VDBRefVec3;
35
+ pdfU: number;
36
+ pdf: number;
37
+ };
38
+ /**
39
+ * K6.R2: the density per steradian with which {@link vdbRefPhaseTableSample} picks cos θ (the channel mean's
40
+ * piecewise-constant marginal in u; the MIS weight of a phase-sampled direction).
41
+ */
42
+ export declare function vdbRefPhaseTablePdf(t: VDBReferencePhaseTable, cosTheta: number): number;
43
+ /**
44
+ * The renderer's blackbody emission colour (`vdbFrameBlackbodyEmission(spectrum, sootExponent)`, three/frame) as a
45
+ * reference colour table: its 256 log-spaced columns at the soot exponent (his texel row blend included), read with
46
+ * the same linear blend in log temperature, so the reference's colour equals `vdbFrameBlackbodyColor` (f32 table).
47
+ * `exponent`: 0 for 'planck', the soot exponent for 'soot' (`vdbFrameEmissionSpectrum`).
48
+ */
49
+ export declare function vdbReferenceBlackbodyTable(exponent?: number, cmf?: VDBColorMatchingFunctions): VDBReferenceColorTable;
50
+ /** A colour table read at `temperature` (K): log-temperature column, linear blend, clamped to the table's range. */
51
+ export declare function vdbRefColorTableAt(t: VDBReferenceColorTable, temperature: number): VDBRefVec3;
52
+ /**
53
+ * The cell of a majorant grid the ray o + t·d (unit-box local coordinates) is in at t, and the t where it leaves
54
+ * it. Each coordinate is nudged by 1e-4 cell in the direction of travel, so a point on a cell face belongs to the
55
+ * cell ahead and the exit is past t. Twin of the kernel's `vdbRefMajorantAt`.
56
+ */
57
+ export declare function vdbRefMajorantCell(g: VDBReferenceMajorantGrid, lo: readonly number[], ld: readonly number[], t: number): {
58
+ index: number;
59
+ exit: number;
60
+ cell: [number, number, number];
61
+ };
62
+ /**
63
+ * Majorants of a dense source from its texels: per cell of `cellTexels`³ texels, the largest density texel a
64
+ * trilinear read inside the cell can touch (the cell's texel range ± one texel, clamped), times the mask's when the
65
+ * volume has one. Exact bound of the hardware-trilinear read (convex weights).
66
+ */
67
+ export declare function vdbReferenceMajorantGridDense(volume: Pick<WvdbDenseVolume, "density" | "mask">, cellTexels?: number): VDBReferenceMajorantGrid;
68
+ /** Options of {@link vdbReferenceMajorantGridSparse}. */
69
+ export interface VDBReferenceMajorantGridSparseOptions {
70
+ /** The source's `normalize: 'clamp01'` (bounds capped at 1). Default false. */
71
+ clamp01?: boolean;
72
+ /** Index voxels per cell side. Default 8 (a leaf). */
73
+ cellVoxels?: number;
74
+ /**
75
+ * 'stats' (default): leaf max from the node stats (ACTIVE values only, as the pool's `nodeStats`), active tiles by
76
+ * their value. 'voxels': every leaf voxel decoded (also inactive ones), for checking the stats bound.
77
+ */
78
+ from?: "stats" | "voxels";
79
+ /** Leaf voxel values for `from: 'voxels'` (`leafVoxels` of tools/cpu/march; injected to keep this module light). */
80
+ leafValues?: (image: Uint32Array, leafAddress: number) => ArrayLike<number>;
81
+ }
82
+ /**
83
+ * Majorants of one sparse volume (a NanoVDB float grid read through `indexBox`, `vdbSparseSource` at level 0) from
84
+ * the tree: each leaf's max (node stats) and each active tile's value bound every cell its voxels can reach under a
85
+ * trilinear read (the node's index box dilated by one voxel; uvw 0 is index min − ½). Cells no node reaches are 0
86
+ * (the background is assumed 0: fog volumes; a non-zero background is a violation the twin counts).
87
+ */
88
+ export declare function vdbReferenceMajorantGridSparse(image: Uint32Array, indexBox: {
89
+ min: readonly number[];
90
+ max: readonly number[];
91
+ }, o?: VDBReferenceMajorantGridSparseOptions): VDBReferenceMajorantGrid;
92
+ /** The share of a majorant grid's cells that are 0 (empty space delta tracking skips) and the mean bound. */
93
+ export declare function vdbReferenceMajorantGridStats(g: VDBReferenceMajorantGrid): {
94
+ cells: number;
95
+ empty: number;
96
+ mean: number;
97
+ max: number;
98
+ };
@@ -0,0 +1,264 @@
1
+ /**
2
+ * K6.R1: the reference renderer's tables. Tabulated phase functions (his Lorenz-Mie and Mie RGB tables, sampled by
3
+ * inverse CDF), the blackbody emission colour (the renderer's LUT over log temperature) and per-cell majorant grids
4
+ * (piecewise-constant density bounds for delta and ratio tracking: dense texels or the sparse pool's node stats).
5
+ * The GPU kernel reads the same numbers (`core/reference/renderer.ts` packs them into its table and majorant
6
+ * textures), so the CPU twin and the kernel make the same decisions.
7
+ */
8
+ import { nodeStats, treeNodes } from "../cpu/march.js";
9
+ import { frameBlackbodyMaxTemperature, frameBlackbodyMinTemperature, frameBlackbodyTableSize, vdbCie1931Fit, vdbFrameBlackbodyColor } from "../frame/blackbody.js";
10
+ import { frameMieRgbTable, frameMieTable, frameMieTableSize } from "../frame/mie-table.js";
11
+ // ── tabulated phase ──────────────────────────────────────────────────────────────────────────────────
12
+ /**
13
+ * The sampling CDF of a phase table: the marginal density of u (θ = π u²) of the channel mean m,
14
+ * p(u) = m(u) · π u · sin(π u²) (phase / isotropic → per steradian, dω = 4π² u sin θ du), trapezoid weights per
15
+ * table interval, normalised; stored in f32 (the GPU table's precision) so the twin and the kernel pick the same
16
+ * interval.
17
+ */
18
+ export function vdbReferencePhaseTableCdf(values, size) {
19
+ const q = (i) => {
20
+ const u = i / (size - 1);
21
+ const m = (values[i * 3] + values[i * 3 + 1] + values[i * 3 + 2]) / 3;
22
+ return m * Math.PI * u * Math.sin(Math.PI * u * u);
23
+ };
24
+ const acc = new Float64Array(size);
25
+ for (let i = 0; i + 1 < size; i++)
26
+ acc[i + 1] = acc[i] + (q(i) + q(i + 1)) / (2 * (size - 1));
27
+ const total = acc[size - 1];
28
+ const cdf = new Float32Array(size);
29
+ for (let i = 0; i < size; i++)
30
+ cdf[i] = acc[i] / total;
31
+ cdf[size - 1] = 1;
32
+ return cdf;
33
+ }
34
+ /** A phase table from RGB values (phase / isotropic at θ = π u², `size` angles). */
35
+ export function vdbReferencePhaseTable(values, size) {
36
+ if (values.length !== size * 3 || size < 2)
37
+ throw new RangeError(`vdbReferencePhaseTable: ${values.length} values for ${size} angles`);
38
+ const v = Float32Array.from(values);
39
+ return { size, values: v, cdf: vdbReferencePhaseTableCdf(v, size) };
40
+ }
41
+ /**
42
+ * His Lorenz-Mie tables (the committed `mie-table.ts`, `vdbFrameMieTexels`): 'mono' ('lorenz-mie', one table for
43
+ * every channel) or 'rgb' ('lorenz-mie-rgb', one per channel).
44
+ */
45
+ export function vdbReferenceMiePhaseTable(kind) {
46
+ const n = frameMieTableSize;
47
+ const values = new Float32Array(n * 3);
48
+ for (let i = 0; i < n; i++) {
49
+ for (let c = 0; c < 3; c++)
50
+ values[i * 3 + c] = kind === "mono" ? frameMieTable[i] : frameMieRgbTable[i * 3 + c];
51
+ }
52
+ return vdbReferencePhaseTable(values, n);
53
+ }
54
+ /** The table's RGB phase / isotropic at u ∈ [0, 1] (texel u·(N − 1), linear blend: `vdbFrameMieTexel`). */
55
+ function tableAt(t, u) {
56
+ const texel = Math.min(Math.max(u, 0), 1) * (t.size - 1);
57
+ const i = Math.min(Math.trunc(texel), t.size - 2);
58
+ const f = texel - i;
59
+ const a = i * 3;
60
+ return [0, 1, 2].map((c) => t.values[a + c] + (t.values[a + 3 + c] - t.values[a + c]) * f);
61
+ }
62
+ /** The tabulated phase per steradian of each channel at cos θ. */
63
+ export function vdbRefPhaseTableEval(t, cosTheta) {
64
+ const u = Math.sqrt(Math.acos(Math.min(Math.max(cosTheta, -1), 1)) / Math.PI);
65
+ const v = tableAt(t, u);
66
+ return [v[0] / (4 * Math.PI), v[1] / (4 * Math.PI), v[2] / (4 * Math.PI)];
67
+ }
68
+ /**
69
+ * Sample cos θ from the table's CDF with ξ ∈ [0, 1): the interval j with cdf[j] ≤ ξ < cdf[j+1] (binary search),
70
+ * u uniform in it. `weight` per channel = phase / sampling density (1 for a table whose channels are equal, up to the
71
+ * piecewise-constant density's error): the estimate stays unbiased per channel.
72
+ */
73
+ export function vdbRefPhaseTableSample(t, xi) {
74
+ let lo = 0;
75
+ let hi = t.size - 1;
76
+ while (hi - lo > 1) {
77
+ const mid = (lo + hi) >> 1;
78
+ if (t.cdf[mid] <= xi)
79
+ lo = mid;
80
+ else
81
+ hi = mid;
82
+ }
83
+ const c0 = t.cdf[lo];
84
+ const c1 = t.cdf[lo + 1];
85
+ const f = (xi - c0) / (c1 - c0);
86
+ const u = (lo + f) / (t.size - 1);
87
+ const pdfU = (c1 - c0) * (t.size - 1);
88
+ const theta = Math.PI * u * u;
89
+ const s = (Math.PI * u * Math.sin(theta)) / pdfU;
90
+ const v = tableAt(t, u);
91
+ return { cosTheta: Math.cos(theta), weight: [v[0] * s, v[1] * s, v[2] * s], pdfU, pdf: tablePdf(pdfU, u, Math.sin(theta)) };
92
+ }
93
+ /** Density per steradian of a table sample: pdfU / (4π² u sin θ) (dω = 4π² u sin θ du), finite at u → 0 (K6.R2). */
94
+ function tablePdf(pdfU, u, sinTheta) {
95
+ return pdfU / Math.max(4 * Math.PI * Math.PI * u * sinTheta, 1e-30);
96
+ }
97
+ /**
98
+ * K6.R2: the density per steradian with which {@link vdbRefPhaseTableSample} picks cos θ (the channel mean's
99
+ * piecewise-constant marginal in u; the MIS weight of a phase-sampled direction).
100
+ */
101
+ export function vdbRefPhaseTablePdf(t, cosTheta) {
102
+ const c = Math.min(Math.max(cosTheta, -1), 1);
103
+ const u = Math.sqrt(Math.acos(c) / Math.PI);
104
+ const j = Math.min(Math.trunc(u * (t.size - 1)), t.size - 2);
105
+ const pdfU = (t.cdf[j + 1] - t.cdf[j]) * (t.size - 1);
106
+ return tablePdf(pdfU, u, Math.sqrt(Math.max(0, 1 - c * c)));
107
+ }
108
+ // ── blackbody emission colour ────────────────────────────────────────────────────────────────────────
109
+ /**
110
+ * The renderer's blackbody emission colour (`vdbFrameBlackbodyEmission(spectrum, sootExponent)`, three/frame) as a
111
+ * reference colour table: its 256 log-spaced columns at the soot exponent (his texel row blend included), read with
112
+ * the same linear blend in log temperature, so the reference's colour equals `vdbFrameBlackbodyColor` (f32 table).
113
+ * `exponent`: 0 for 'planck', the soot exponent for 'soot' (`vdbFrameEmissionSpectrum`).
114
+ */
115
+ export function vdbReferenceBlackbodyTable(exponent = 0, cmf = vdbCie1931Fit) {
116
+ const n = frameBlackbodyTableSize;
117
+ const values = new Float32Array(n * 3);
118
+ for (let i = 0; i < n; i++) {
119
+ const temperature = frameBlackbodyMinTemperature * (frameBlackbodyMaxTemperature / frameBlackbodyMinTemperature) ** (i / (n - 1));
120
+ values.set(vdbFrameBlackbodyColor(temperature, exponent, cmf), i * 3);
121
+ }
122
+ return { size: n, values, minTemperature: frameBlackbodyMinTemperature, maxTemperature: frameBlackbodyMaxTemperature };
123
+ }
124
+ /** A colour table read at `temperature` (K): log-temperature column, linear blend, clamped to the table's range. */
125
+ export function vdbRefColorTableAt(t, temperature) {
126
+ const x = Math.min(1, Math.max(0, Math.log(Math.max(temperature, 1e-3) / t.minTemperature) / Math.log(t.maxTemperature / t.minTemperature))) * (t.size - 1);
127
+ const i = Math.min(Math.trunc(x), t.size - 2);
128
+ const f = x - i;
129
+ return [0, 1, 2].map((c) => t.values[i * 3 + c] + (t.values[i * 3 + 3 + c] - t.values[i * 3 + c]) * f);
130
+ }
131
+ // ── majorant grids ───────────────────────────────────────────────────────────────────────────────────
132
+ /**
133
+ * The cell of a majorant grid the ray o + t·d (unit-box local coordinates) is in at t, and the t where it leaves
134
+ * it. Each coordinate is nudged by 1e-4 cell in the direction of travel, so a point on a cell face belongs to the
135
+ * cell ahead and the exit is past t. Twin of the kernel's `vdbRefMajorantAt`.
136
+ */
137
+ export function vdbRefMajorantCell(g, lo, ld, t) {
138
+ let exit = Infinity;
139
+ let index = 0;
140
+ let stride = 1;
141
+ const cell = [0, 0, 0];
142
+ for (let k = 0; k < 3; k++) {
143
+ const n = g.dims[k];
144
+ const q = (lo[k] + ld[k] * t + 0.5) * n;
145
+ const nudge = ld[k] > 0 ? 1e-4 : ld[k] < 0 ? -1e-4 : 0;
146
+ const c = Math.min(Math.max(Math.floor(q + nudge), 0), n - 1);
147
+ if (Math.abs(ld[k]) > 1e-12) {
148
+ const face = (c + (ld[k] > 0 ? 1 : 0)) / n - 0.5;
149
+ exit = Math.min(exit, (face - lo[k]) / ld[k]);
150
+ }
151
+ index += c * stride;
152
+ stride *= n;
153
+ cell[k] = c;
154
+ }
155
+ return { index, exit, cell };
156
+ }
157
+ /**
158
+ * Majorants of a dense source from its texels: per cell of `cellTexels`³ texels, the largest density texel a
159
+ * trilinear read inside the cell can touch (the cell's texel range ± one texel, clamped), times the mask's when the
160
+ * volume has one. Exact bound of the hardware-trilinear read (convex weights).
161
+ */
162
+ export function vdbReferenceMajorantGridDense(volume, cellTexels = 8) {
163
+ const D = volume.density.dimensions;
164
+ const dims = [0, 1, 2].map((k) => Math.max(1, Math.ceil(D[k] / cellTexels)));
165
+ const blockMax = (tex) => {
166
+ const out = new Float32Array(dims[0] * dims[1] * dims[2]);
167
+ const range = (k, c) => {
168
+ const n = dims[k];
169
+ const lo = Math.floor((c * D[k]) / n - 0.5);
170
+ const hi = Math.floor(((c + 1) * D[k]) / n - 0.5) + 1;
171
+ return [Math.max(lo, 0), Math.min(hi, D[k] - 1)];
172
+ };
173
+ const stride = tex.texelBytes;
174
+ for (let cz = 0; cz < dims[2]; cz++) {
175
+ const [z0, z1] = range(2, cz);
176
+ for (let cy = 0; cy < dims[1]; cy++) {
177
+ const [y0, y1] = range(1, cy);
178
+ for (let cx = 0; cx < dims[0]; cx++) {
179
+ const [x0, x1] = range(0, cx);
180
+ let m = 0;
181
+ for (let z = z0; z <= z1; z++)
182
+ for (let y = y0; y <= y1; y++) {
183
+ const row = (z * D[1] + y) * D[0];
184
+ for (let x = x0; x <= x1; x++)
185
+ m = Math.max(m, tex.data[(row + x) * stride]);
186
+ }
187
+ out[(cz * dims[1] + cy) * dims[0] + cx] = m / 255;
188
+ }
189
+ }
190
+ }
191
+ return out;
192
+ };
193
+ const values = blockMax(volume.density);
194
+ if (volume.mask) {
195
+ const mask = blockMax(volume.mask);
196
+ for (let i = 0; i < values.length; i++)
197
+ values[i] = values[i] * mask[i];
198
+ }
199
+ return { dims, values };
200
+ }
201
+ /**
202
+ * Majorants of one sparse volume (a NanoVDB float grid read through `indexBox`, `vdbSparseSource` at level 0) from
203
+ * the tree: each leaf's max (node stats) and each active tile's value bound every cell its voxels can reach under a
204
+ * trilinear read (the node's index box dilated by one voxel; uvw 0 is index min − ½). Cells no node reaches are 0
205
+ * (the background is assumed 0: fog volumes; a non-zero background is a violation the twin counts).
206
+ */
207
+ export function vdbReferenceMajorantGridSparse(image, indexBox, o = {}) {
208
+ const cell = o.cellVoxels ?? 8;
209
+ const size = [0, 1, 2].map((k) => indexBox.max[k] - indexBox.min[k] + 1);
210
+ const dims = size.map((s) => Math.max(1, Math.ceil(s / cell)));
211
+ const values = new Float32Array(dims[0] * dims[1] * dims[2]);
212
+ const put = (origin, dim, value) => {
213
+ if (!(value > 0))
214
+ return;
215
+ const r = [0, 1, 2].map((k) => {
216
+ // voxels origin … origin + dim − 1 reach index coordinates (origin − 1, origin + dim); uvw = (x − min + ½) / size
217
+ const u0 = (origin[k] - 1 - indexBox.min[k] + 0.5) / size[k];
218
+ const u1 = (origin[k] + dim - indexBox.min[k] + 0.5) / size[k];
219
+ return [Math.max(Math.floor(u0 * dims[k]), 0), Math.min(Math.floor(u1 * dims[k]), dims[k] - 1)];
220
+ });
221
+ for (let z = r[2][0]; z <= r[2][1]; z++)
222
+ for (let y = r[1][0]; y <= r[1][1]; y++)
223
+ for (let x = r[0][0]; x <= r[0][1]; x++) {
224
+ const i = (z * dims[1] + y) * dims[0] + x;
225
+ if (value > values[i])
226
+ values[i] = value;
227
+ }
228
+ };
229
+ for (const node of treeNodes(image)) {
230
+ for (const t of node.activeTiles)
231
+ put(t.origin, t.dim, t.value);
232
+ if (node.level !== 0)
233
+ continue;
234
+ let m;
235
+ if (o.from === "voxels") {
236
+ if (!o.leafValues)
237
+ throw new RangeError("vdbReferenceMajorantGridSparse: from 'voxels' needs leafValues");
238
+ m = -Infinity;
239
+ for (const v of Array.from(o.leafValues(image, node.address)))
240
+ m = Math.max(m, v);
241
+ }
242
+ else
243
+ m = nodeStats(image, 0, node.address).max;
244
+ put(node.origin, 8, m);
245
+ }
246
+ if (o.clamp01)
247
+ for (let i = 0; i < values.length; i++)
248
+ values[i] = Math.min(values[i], 1);
249
+ return { dims, values };
250
+ }
251
+ /** The share of a majorant grid's cells that are 0 (empty space delta tracking skips) and the mean bound. */
252
+ export function vdbReferenceMajorantGridStats(g) {
253
+ let empty = 0;
254
+ let sum = 0;
255
+ let max = 0;
256
+ for (const v of g.values) {
257
+ if (!(v > 0))
258
+ empty++;
259
+ sum += v;
260
+ max = Math.max(max, v);
261
+ }
262
+ return { cells: g.values.length, empty: empty / g.values.length, mean: sum / g.values.length, max };
263
+ }
264
+ //# sourceMappingURL=tables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../src/tools/reference/tables.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,aAAa,EAAE,sBAAsB,EAAkC,MAAM,uBAAuB,CAAC;AACnM,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI3F,wGAAwG;AAExG;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAyB,EAAE,IAAY;IAC/E,MAAM,CAAC,GAAG,CAAC,CAAS,EAAE,EAAE;QACtB,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;QACzB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAE,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAE,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAE,CAAC,GAAG,CAAC,CAAC;QACzE,OAAO,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,C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E,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC;AACtG,CAAC","sourcesContent":["/**\n * K6.R1: the reference renderer's tables. Tabulated phase functions (his Lorenz-Mie and Mie RGB tables, sampled by\n * inverse CDF), the blackbody emission colour (the renderer's LUT over log temperature) and per-cell majorant grids\n * (piecewise-constant density bounds for delta and ratio tracking: dense texels or the sparse pool's node stats).\n * The GPU kernel reads the same numbers (`core/reference/renderer.ts` packs them into its table and majorant\n * textures), so the CPU twin and the kernel make the same decisions.\n */\n\nimport { nodeStats, treeNodes } from \"../cpu/march.js\";\nimport { frameBlackbodyMaxTemperature, frameBlackbodyMinTemperature, frameBlackbodyTableSize, vdbCie1931Fit, vdbFrameBlackbodyColor, type VDBColorMatchingFunctions } from \"../frame/blackbody.js\";\nimport { frameMieRgbTable, frameMieTable, frameMieTableSize } from \"../frame/mie-table.js\";\nimport type { WvdbDenseVolume } from \"../wvdb/dense.js\";\nimport type { VDBRefVec3, VDBReferenceColorTable, VDBReferenceMajorantGrid, VDBReferencePhaseTable } from \"./scene.js\";\n\n// ── tabulated phase ──────────────────────────────────────────────────────────────────────────────────\n\n/**\n * The sampling CDF of a phase table: the marginal density of u (θ = π u²) of the channel mean m,\n * p(u) = m(u) · π u · sin(π u²) (phase / isotropic → per steradian, dω = 4π² u sin θ du), trapezoid weights per\n * table interval, normalised; stored in f32 (the GPU table's precision) so the twin and the kernel pick the same\n * interval.\n */\nexport function vdbReferencePhaseTableCdf(values: ArrayLike<number>, size: number): Float32Array {\n const q = (i: number) => {\n const u = i / (size - 1);\n const m = (values[i * 3]! + values[i * 3 + 1]! + values[i * 3 + 2]!) / 3;\n return m * Math.PI * u * Math.sin(Math.PI * u * u);\n };\n const acc = new Float64Array(size);\n for (let i = 0; i + 1 < size; i++) acc[i + 1] = acc[i]! + (q(i) + q(i + 1)) / (2 * (size - 1));\n const total = acc[size - 1]!;\n const cdf = new Float32Array(size);\n for (let i = 0; i < size; i++) cdf[i] = acc[i]! / total;\n cdf[size - 1] = 1;\n return cdf;\n}\n\n/** A phase table from RGB values (phase / isotropic at θ = π u², `size` angles). */\nexport function vdbReferencePhaseTable(values: ArrayLike<number>, size: number): VDBReferencePhaseTable {\n if (values.length !== size * 3 || size < 2) throw new RangeError(`vdbReferencePhaseTable: ${values.length} values for ${size} angles`);\n const v = Float32Array.from(values);\n return { size, values: v, cdf: vdbReferencePhaseTableCdf(v, size) };\n}\n\n/**\n * His Lorenz-Mie tables (the committed `mie-table.ts`, `vdbFrameMieTexels`): 'mono' ('lorenz-mie', one table for\n * every channel) or 'rgb' ('lorenz-mie-rgb', one per channel).\n */\nexport function vdbReferenceMiePhaseTable(kind: \"mono\" | \"rgb\"): VDBReferencePhaseTable {\n const n = frameMieTableSize;\n const values = new Float32Array(n * 3);\n for (let i = 0; i < n; i++) {\n for (let c = 0; c < 3; c++) values[i * 3 + c] = kind === \"mono\" ? frameMieTable[i]! : frameMieRgbTable[i * 3 + c]!;\n }\n return vdbReferencePhaseTable(values, n);\n}\n\n/** The table's RGB phase / isotropic at u ∈ [0, 1] (texel u·(N − 1), linear blend: `vdbFrameMieTexel`). */\nfunction tableAt(t: VDBReferencePhaseTable, u: number): VDBRefVec3 {\n const texel = Math.min(Math.max(u, 0), 1) * (t.size - 1);\n const i = Math.min(Math.trunc(texel), t.size - 2);\n const f = texel - i;\n const a = i * 3;\n return [0, 1, 2].map((c) => t.values[a + c]! + (t.values[a + 3 + c]! - t.values[a + c]!) * f) as VDBRefVec3;\n}\n\n/** The tabulated phase per steradian of each channel at cos θ. */\nexport function vdbRefPhaseTableEval(t: VDBReferencePhaseTable, cosTheta: number): VDBRefVec3 {\n const u = Math.sqrt(Math.acos(Math.min(Math.max(cosTheta, -1), 1)) / Math.PI);\n const v = tableAt(t, u);\n return [v[0] / (4 * Math.PI), v[1] / (4 * Math.PI), v[2] / (4 * Math.PI)];\n}\n\n/**\n * Sample cos θ from the table's CDF with ξ ∈ [0, 1): the interval j with cdf[j] ≤ ξ < cdf[j+1] (binary search),\n * u uniform in it. `weight` per channel = phase / sampling density (1 for a table whose channels are equal, up to the\n * piecewise-constant density's error): the estimate stays unbiased per channel.\n */\nexport function vdbRefPhaseTableSample(t: VDBReferencePhaseTable, xi: number): { cosTheta: number; weight: VDBRefVec3; pdfU: number; pdf: number } {\n let lo = 0;\n let hi = t.size - 1;\n while (hi - lo > 1) {\n const mid = (lo + hi) >> 1;\n if (t.cdf[mid]! <= xi) lo = mid;\n else hi = mid;\n }\n const c0 = t.cdf[lo]!;\n const c1 = t.cdf[lo + 1]!;\n const f = (xi - c0) / (c1 - c0);\n const u = (lo + f) / (t.size - 1);\n const pdfU = (c1 - c0) * (t.size - 1);\n const theta = Math.PI * u * u;\n const s = (Math.PI * u * Math.sin(theta)) / pdfU;\n const v = tableAt(t, u);\n return { cosTheta: Math.cos(theta), weight: [v[0] * s, v[1] * s, v[2] * s], pdfU, pdf: tablePdf(pdfU, u, Math.sin(theta)) };\n}\n\n/** Density per steradian of a table sample: pdfU / (4π² u sin θ) (dω = 4π² u sin θ du), finite at u → 0 (K6.R2). */\nfunction tablePdf(pdfU: number, u: number, sinTheta: number): number {\n return pdfU / Math.max(4 * Math.PI * Math.PI * u * sinTheta, 1e-30);\n}\n\n/**\n * K6.R2: the density per steradian with which {@link vdbRefPhaseTableSample} picks cos θ (the channel mean's\n * piecewise-constant marginal in u; the MIS weight of a phase-sampled direction).\n */\nexport function vdbRefPhaseTablePdf(t: VDBReferencePhaseTable, cosTheta: number): number {\n const c = Math.min(Math.max(cosTheta, -1), 1);\n const u = Math.sqrt(Math.acos(c) / Math.PI);\n const j = Math.min(Math.trunc(u * (t.size - 1)), t.size - 2);\n const pdfU = (t.cdf[j + 1]! - t.cdf[j]!) * (t.size - 1);\n return tablePdf(pdfU, u, Math.sqrt(Math.max(0, 1 - c * c)));\n}\n\n// ── blackbody emission colour ────────────────────────────────────────────────────────────────────────\n\n/**\n * The renderer's blackbody emission colour (`vdbFrameBlackbodyEmission(spectrum, sootExponent)`, three/frame) as a\n * reference colour table: its 256 log-spaced columns at the soot exponent (his texel row blend included), read with\n * the same linear blend in log temperature, so the reference's colour equals `vdbFrameBlackbodyColor` (f32 table).\n * `exponent`: 0 for 'planck', the soot exponent for 'soot' (`vdbFrameEmissionSpectrum`).\n */\nexport function vdbReferenceBlackbodyTable(exponent = 0, cmf: VDBColorMatchingFunctions = vdbCie1931Fit): VDBReferenceColorTable {\n const n = frameBlackbodyTableSize;\n const values = new Float32Array(n * 3);\n for (let i = 0; i < n; i++) {\n const temperature = frameBlackbodyMinTemperature * (frameBlackbodyMaxTemperature / frameBlackbodyMinTemperature) ** (i / (n - 1));\n values.set(vdbFrameBlackbodyColor(temperature, exponent, cmf), i * 3);\n }\n return { size: n, values, minTemperature: frameBlackbodyMinTemperature, maxTemperature: frameBlackbodyMaxTemperature };\n}\n\n/** A colour table read at `temperature` (K): log-temperature column, linear blend, clamped to the table's range. */\nexport function vdbRefColorTableAt(t: VDBReferenceColorTable, temperature: number): VDBRefVec3 {\n const x = Math.min(1, Math.max(0, Math.log(Math.max(temperature, 1e-3) / t.minTemperature) / Math.log(t.maxTemperature / t.minTemperature))) * (t.size - 1);\n const i = Math.min(Math.trunc(x), t.size - 2);\n const f = x - i;\n return [0, 1, 2].map((c) => t.values[i * 3 + c]! + (t.values[i * 3 + 3 + c]! - t.values[i * 3 + c]!) * f) as VDBRefVec3;\n}\n\n// ── majorant grids ───────────────────────────────────────────────────────────────────────────────────\n\n/**\n * The cell of a majorant grid the ray o + t·d (unit-box local coordinates) is in at t, and the t where it leaves\n * it. Each coordinate is nudged by 1e-4 cell in the direction of travel, so a point on a cell face belongs to the\n * cell ahead and the exit is past t. Twin of the kernel's `vdbRefMajorantAt`.\n */\nexport function vdbRefMajorantCell(g: VDBReferenceMajorantGrid, lo: readonly number[], ld: readonly number[], t: number): { index: number; exit: number; cell: [number, number, number] } {\n let exit = Infinity;\n let index = 0;\n let stride = 1;\n const cell: [number, number, number] = [0, 0, 0];\n for (let k = 0; k < 3; k++) {\n const n = g.dims[k]!;\n const q = (lo[k]! + ld[k]! * t + 0.5) * n;\n const nudge = ld[k]! > 0 ? 1e-4 : ld[k]! < 0 ? -1e-4 : 0;\n const c = Math.min(Math.max(Math.floor(q + nudge), 0), n - 1);\n if (Math.abs(ld[k]!) > 1e-12) {\n const face = (c + (ld[k]! > 0 ? 1 : 0)) / n - 0.5;\n exit = Math.min(exit, (face - lo[k]!) / ld[k]!);\n }\n index += c * stride;\n stride *= n;\n cell[k] = c;\n }\n return { index, exit, cell };\n}\n\n/**\n * Majorants of a dense source from its texels: per cell of `cellTexels`³ texels, the largest density texel a\n * trilinear read inside the cell can touch (the cell's texel range ± one texel, clamped), times the mask's when the\n * volume has one. Exact bound of the hardware-trilinear read (convex weights).\n */\nexport function vdbReferenceMajorantGridDense(volume: Pick<WvdbDenseVolume, \"density\" | \"mask\">, cellTexels = 8): VDBReferenceMajorantGrid {\n const D = volume.density.dimensions;\n const dims = [0, 1, 2].map((k) => Math.max(1, Math.ceil(D[k]! / cellTexels))) as [number, number, number];\n const blockMax = (tex: NonNullable<WvdbDenseVolume[\"mask\"]>) => {\n const out = new Float32Array(dims[0] * dims[1] * dims[2]);\n const range = (k: number, c: number) => {\n const n = dims[k]!;\n const lo = Math.floor((c * D[k]!) / n - 0.5);\n const hi = Math.floor(((c + 1) * D[k]!) / n - 0.5) + 1;\n return [Math.max(lo, 0), Math.min(hi, D[k]! - 1)] as const;\n };\n const stride = tex.texelBytes;\n for (let cz = 0; cz < dims[2]; cz++) {\n const [z0, z1] = range(2, cz);\n for (let cy = 0; cy < dims[1]; cy++) {\n const [y0, y1] = range(1, cy);\n for (let cx = 0; cx < dims[0]; cx++) {\n const [x0, x1] = range(0, cx);\n let m = 0;\n for (let z = z0; z <= z1; z++) for (let y = y0; y <= y1; y++) {\n const row = (z * D[1]! + y) * D[0]!;\n for (let x = x0; x <= x1; x++) m = Math.max(m, tex.data[(row + x) * stride]!);\n }\n out[(cz * dims[1] + cy) * dims[0] + cx] = m / 255;\n }\n }\n }\n return out;\n };\n const values = blockMax(volume.density);\n if (volume.mask) {\n const mask = blockMax(volume.mask);\n for (let i = 0; i < values.length; i++) values[i] = values[i]! * mask[i]!;\n }\n return { dims, values };\n}\n\n/** Options of {@link vdbReferenceMajorantGridSparse}. */\nexport interface VDBReferenceMajorantGridSparseOptions {\n /** The source's `normalize: 'clamp01'` (bounds capped at 1). Default false. */\n clamp01?: boolean;\n /** Index voxels per cell side. Default 8 (a leaf). */\n cellVoxels?: number;\n /**\n * 'stats' (default): leaf max from the node stats (ACTIVE values only, as the pool's `nodeStats`), active tiles by\n * their value. 'voxels': every leaf voxel decoded (also inactive ones), for checking the stats bound.\n */\n from?: \"stats\" | \"voxels\";\n /** Leaf voxel values for `from: 'voxels'` (`leafVoxels` of tools/cpu/march; injected to keep this module light). */\n leafValues?: (image: Uint32Array, leafAddress: number) => ArrayLike<number>;\n}\n\n/**\n * Majorants of one sparse volume (a NanoVDB float grid read through `indexBox`, `vdbSparseSource` at level 0) from\n * the tree: each leaf's max (node stats) and each active tile's value bound every cell its voxels can reach under a\n * trilinear read (the node's index box dilated by one voxel; uvw 0 is index min − ½). Cells no node reaches are 0\n * (the background is assumed 0: fog volumes; a non-zero background is a violation the twin counts).\n */\nexport function vdbReferenceMajorantGridSparse(image: Uint32Array, indexBox: { min: readonly number[]; max: readonly number[] }, o: VDBReferenceMajorantGridSparseOptions = {}): VDBReferenceMajorantGrid {\n const cell = o.cellVoxels ?? 8;\n const size = [0, 1, 2].map((k) => indexBox.max[k]! - indexBox.min[k]! + 1);\n const dims = size.map((s) => Math.max(1, Math.ceil(s / cell))) as [number, number, number];\n const values = new Float32Array(dims[0] * dims[1] * dims[2]);\n const put = (origin: readonly number[], dim: number, value: number) => {\n if (!(value > 0)) return;\n const r = [0, 1, 2].map((k) => {\n // voxels origin … origin + dim − 1 reach index coordinates (origin − 1, origin + dim); uvw = (x − min + ½) / size\n const u0 = (origin[k]! - 1 - indexBox.min[k]! + 0.5) / size[k]!;\n const u1 = (origin[k]! + dim - indexBox.min[k]! + 0.5) / size[k]!;\n return [Math.max(Math.floor(u0 * dims[k]!), 0), Math.min(Math.floor(u1 * dims[k]!), dims[k]! - 1)] as const;\n });\n for (let z = r[2]![0]; z <= r[2]![1]; z++) for (let y = r[1]![0]; y <= r[1]![1]; y++) for (let x = r[0]![0]; x <= r[0]![1]; x++) {\n const i = (z * dims[1] + y) * dims[0] + x;\n if (value > values[i]!) values[i] = value;\n }\n };\n for (const node of treeNodes(image)) {\n for (const t of node.activeTiles) put(t.origin, t.dim, t.value);\n if (node.level !== 0) continue;\n let m: number;\n if (o.from === \"voxels\") {\n if (!o.leafValues) throw new RangeError(\"vdbReferenceMajorantGridSparse: from 'voxels' needs leafValues\");\n m = -Infinity;\n for (const v of Array.from(o.leafValues(image, node.address))) m = Math.max(m, v);\n } else m = nodeStats(image, 0, node.address).max;\n put(node.origin, 8, m);\n }\n if (o.clamp01) for (let i = 0; i < values.length; i++) values[i] = Math.min(values[i]!, 1);\n return { dims, values };\n}\n\n/** The share of a majorant grid's cells that are 0 (empty space delta tracking skips) and the mean bound. */\nexport function vdbReferenceMajorantGridStats(g: VDBReferenceMajorantGrid): { cells: number; empty: number; mean: number; max: number } {\n let empty = 0;\n let sum = 0;\n let max = 0;\n for (const v of g.values) {\n if (!(v > 0)) empty++;\n sum += v;\n max = Math.max(max, v);\n }\n return { cells: g.values.length, empty: empty / g.values.length, mean: sum / g.values.length, max };\n}\n"]}
@@ -0,0 +1,160 @@
1
+ /**
2
+ * K6.R: the CPU twin of the reference renderer's GPU kernel (`core/reference/wgsl.ts` `vdbRefTraceCs`): a
3
+ * brute-force volumetric path tracer (design K6-core-renderer.md §7.4) over the renderer's medium model
4
+ * ({@link VDBReferenceScene}). Same algorithm, same random stream ({@link vdbRefRng}), same draw order, in f64:
5
+ *
6
+ * 1. The camera ray of the pixel (centre, or uniform in the pixel with `pixelFilter: 'box'`: 2 draws).
7
+ * 2. The primary transmittance T by ratio tracking (Novák et al. 2014) to infinity.
8
+ * 3. One path by delta tracking (Woodcock): at each real collision with volume i (picked by σᵢ / σ̄): emission
9
+ * (β · Le), then β ·= albedo, next-event estimation of every light (phase × ratio-tracked transmittance), then
10
+ * Russian roulette on β from `rrStart`, and a new direction sampled from the phase (3 draws:
11
+ * lobe, cos θ, φ; a tabulated phase (K6.R1) samples cos θ by inverse CDF and weights β per channel). A path that
12
+ * leaves the media after ≥ 1 collision gathers the environment; a collision past `maxBounces` ends the path
13
+ * (K6.R1: so `maxBounces` 1 is single scattering of the lights AND the environment).
14
+ * K6.R2 (`environmentSampling: 'mis'`, the default, with an equirect map that has light): after the lights, NEE of
15
+ * the map: 4 draws (row, column, azimuth and sin latitude in the texel; `vdbRefEnvSample`), the sampled texel's
16
+ * radiance × phase × the power-heuristic weight against the phase density / the map density, then (if that is
17
+ * > 0) the ratio-tracked transmittance to infinity. The escape gathers the map × the complementary weight (the
18
+ * phase density of the direction it was sampled with vs the map's density there), the rest of the environment
19
+ * (uniform, hemispheres, probe) with weight 1.
20
+ *
21
+ * Tracking runs piecewise over the ray's intervals in each volume's box (or inscribed ball): the majorant on a
22
+ * piece is Σ σᵢ · majorantᵢ of the volumes covering it, so empty gaps cost no steps. A volume with a majorant grid
23
+ * (K6.R1) splits its interval at its cells' faces and uses each cell's bound (a 0 cell is skipped without draws). Each tentative step draws 1
24
+ * number (free flight); delta tracking draws 1 more to accept or reject; ratio tracking draws 1 when it plays
25
+ * Russian roulette (T < {@link VDB_REFERENCE_RATIO_RR}: survive ½, × 2). Issue #2: with `densityFilter: 'stochastic'`
26
+ * every σ lookup (each volume covering the tentative collision, in volume order, after the free-flight draw) first
27
+ * draws 3 numbers (xi x, y, z) and reads one voxel ({@link VDBReferenceMediumCpu.densityStochastic}).
28
+ *
29
+ * Output per sample: (L.r, L.g, L.b, T): L the radiance scattered or emitted toward the camera by the media (the
30
+ * background behind is NOT in L: composite `L + T · background`).
31
+ */
32
+ import { type VDBRefVec3, type VDBReferenceColorTable, type VDBReferenceEnvironment, type VDBReferenceLight, type VDBReferenceMajorantGrid, type VDBReferencePhaseTable, type VDBReferenceScene, type VDBReferenceSettings, type VDBReferenceVolume } from "./scene.js";
33
+ /** What the CPU twin reads from a volume's source at uvw (level 0; the source's own clamping). */
34
+ export interface VDBReferenceMediumCpu {
35
+ /** density × mask (before the cutoff). */
36
+ density(uvw: readonly number[]): number;
37
+ /**
38
+ * Issue #2: density × mask with the density from ONE voxel picked by `xi` ∈ [0, 1)³ with probability equal to its
39
+ * trilinear weight (twin of `vdbSrcDensityStochastic`); its mean over `xi` is {@link density}. Default:
40
+ * {@link density} (the dense source: hardware trilinear is one fetch).
41
+ */
42
+ densityStochastic?(uvw: readonly number[], xi: readonly number[]): number;
43
+ /** The albedo channel in [0, 1] (default (1, 1, 1)). */
44
+ albedo?(uvw: readonly number[]): VDBRefVec3;
45
+ /** The emission channel value (default 0). */
46
+ emission?(uvw: readonly number[]): number;
47
+ }
48
+ /**
49
+ * Deliberate breaks for the fail-before checks (each must fail an analytic test); the GPU kernel has the same
50
+ * names as WGSL patches (`core/reference/wgsl.ts` `VDB_REFERENCE_MUTATIONS`).
51
+ */
52
+ export type VDBReferenceMutation = "ratio-weight" | "delta-accept" | "phase-norm" | "nee-transmittance" | "emission-albedo" | "escape-depth" | "majorant-cell" | "phase-table-weight" | "falloff" | "env-pdf" | "mis-weight";
53
+ /** Options of {@link vdbReferenceRenderCpu}. */
54
+ export interface VDBReferenceCpuOptions {
55
+ /** Batches to accumulate (batch b uses sample indices b·spp … b·spp + spp − 1). Default 1. */
56
+ batches?: number;
57
+ /** First batch index (to continue an accumulation). Default 0. */
58
+ firstBatch?: number;
59
+ /** Only these pixels ([x, y], y from the top); default every pixel. */
60
+ pixels?: readonly (readonly [number, number])[];
61
+ /** A deliberate break (tests). */
62
+ mutate?: VDBReferenceMutation;
63
+ /** Issue #2: the GPU kernel's `densityFilter` (`'stochastic'`: 3 draws per σ lookup). Default 'trilinear'. */
64
+ densityFilter?: "trilinear" | "stochastic";
65
+ }
66
+ /** Accumulated per-pixel sums of batch means: `sum` and `sumSq` (RGBA = L.rgb, T), `batches` of them. */
67
+ export interface VDBReferenceAccum {
68
+ width: number;
69
+ height: number;
70
+ batches: number;
71
+ /** Σ over batches of the batch mean, RGBA per pixel (row 0 at the top). */
72
+ sum: Float64Array | Float32Array;
73
+ /** Σ over batches of the squared batch mean. */
74
+ sumSq: Float64Array | Float32Array;
75
+ }
76
+ /** Statistics the CPU twin keeps (not on the GPU). */
77
+ export interface VDBReferenceCpuStats {
78
+ samples: number;
79
+ /** Tentative collisions where σ(x) exceeded the majorant (delta tracking is biased then). */
80
+ majorantViolations: number;
81
+ /** Paths cut by `maxBounces` while their throughput was > 0. */
82
+ truncated: number;
83
+ /** Tracks stopped by {@link VDB_REFERENCE_MAX_STEPS}. */
84
+ stepLimited: number;
85
+ /** Mean scattering events per path. */
86
+ meanDepth: number;
87
+ /** Paths with at least 2 scattering events (multiple scattering), and the longest path. */
88
+ multiple: number;
89
+ maxDepth: number;
90
+ }
91
+ interface PreparedVolume {
92
+ src: VDBReferenceVolume;
93
+ medium: VDBReferenceMediumCpu;
94
+ worldToLocal: Float64Array;
95
+ sigma: number;
96
+ majorant: number;
97
+ cutoff: number;
98
+ albedo: VDBRefVec3;
99
+ g: number;
100
+ backG: number;
101
+ backWeight: number;
102
+ sphere: boolean;
103
+ emits: boolean;
104
+ emission: VDBRefVec3;
105
+ colorTable: VDBReferenceColorTable | null;
106
+ table: VDBReferencePhaseTable | null;
107
+ grid: VDBReferenceMajorantGrid | null;
108
+ t0: number;
109
+ t1: number;
110
+ /** Ray origin and direction in the unit box (set per track when the volume has a majorant grid). */
111
+ lo: VDBRefVec3;
112
+ ld: VDBRefVec3;
113
+ /** The majorant σ̄ of the current tracking piece. */
114
+ maj: number;
115
+ }
116
+ /** smoothstep with e1 ≤ e0 read as a step at e0 (WGSL's smoothstep is undefined there). */
117
+ export declare function vdbRefSmoothstep(e0: number, e1: number, x: number): number;
118
+ /** Henyey-Greenstein phase (per steradian; integrates to 1 over the sphere). */
119
+ export declare function vdbRefHenyeyGreenstein(cosTheta: number, g: number): number;
120
+ /** The dual-lobe phase (1 − w)·HG(g) + w·HG(backG) per steradian. */
121
+ export declare function vdbRefPhase(cosTheta: number, g: number, backG: number, backWeight: number): number;
122
+ /** cos θ of an HG sample from u ∈ [0, 1) (inverse CDF; isotropic for |g| < 1e-3). */
123
+ export declare function vdbRefSampleHgCos(g: number, u: number): number;
124
+ /** A direction at cos θ, azimuth 2π·u from `n` (Duff et al. 2017 basis). */
125
+ export declare function vdbRefDirectionAround(n: readonly number[], cosTheta: number, u: number): VDBRefVec3;
126
+ /** The ray interval [t0, t1] inside a volume (local box or inscribed ball), clipped to [0, tMax]; t0 > t1 if none. */
127
+ export declare function vdbRefVolumeInterval(worldToLocal: ArrayLike<number>, sphere: boolean, o: readonly number[], d: readonly number[], tMax: number): [number, number];
128
+ /** Environment radiance in direction `d` (unit). K6.R2: the equirect map's part × `mapWeight` (its MIS weight). */
129
+ export declare function vdbRefEnvironmentRadiance(env: VDBReferenceEnvironment | undefined, d: readonly number[], mapWeight?: number): VDBRefVec3;
130
+ /** The camera ray of pixel (px, py) (y from the top) at sub-pixel offset (jx, jy) ∈ [0, 1)². */
131
+ export declare function vdbRefCameraRay(camera: VDBReferenceScene["camera"], width: number, height: number, px: number, py: number, jx: number, jy: number): {
132
+ o: VDBRefVec3;
133
+ d: VDBRefVec3;
134
+ };
135
+ /** One light's NEE setup at x: direction, distance and Li (already × falloff and spot attenuation); null when it is dark. */
136
+ export declare function vdbRefLightAt(l: VDBReferenceLight, x: readonly number[], mutate?: VDBReferenceMutation): {
137
+ dir: VDBRefVec3;
138
+ dist: number;
139
+ li: VDBRefVec3;
140
+ } | null;
141
+ /**
142
+ * One sample of pixel (px, py): (L.r, L.g, L.b, T). `sampleIndex` = batch · spp + s.
143
+ */
144
+ export declare function vdbReferenceSampleCpu(scene: VDBReferenceScene, vols: PreparedVolume[], settings: Required<VDBReferenceSettings>, px: number, py: number, sampleIndex: number, stats: VDBReferenceCpuStats, mutate?: VDBReferenceMutation, densityFilter?: "trilinear" | "stochastic"): [number, number, number, number];
145
+ /**
146
+ * Render the reference on the CPU: `batches` batches of `spp` samples per pixel, accumulated as per-pixel sums of
147
+ * batch means (the GPU accumulation's layout). Small images or sampled pixels only (it is f64 JavaScript).
148
+ */
149
+ export declare function vdbReferenceRenderCpu(scene: VDBReferenceScene, media: readonly VDBReferenceMediumCpu[], settingsIn: VDBReferenceSettings, o?: VDBReferenceCpuOptions): VDBReferenceAccum & {
150
+ stats: VDBReferenceCpuStats;
151
+ };
152
+ /**
153
+ * Mean and standard error of the mean per pixel and channel from accumulated sums (n batches; the error needs
154
+ * n ≥ 2: it is the spread of batch means / √n).
155
+ */
156
+ export declare function vdbReferenceStatistics(a: VDBReferenceAccum): {
157
+ mean: Float64Array;
158
+ stderr: Float64Array;
159
+ };
160
+ export {};