@pmndrs/vdb 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (576) hide show
  1. package/CHANGELOG.md +592 -2
  2. package/README.md +85 -37
  3. package/THIRD_PARTY_NOTICES.md +197 -29
  4. package/dist/core/compute/atlas.d.ts +10 -2
  5. package/dist/core/compute/atlas.js +6 -1
  6. package/dist/core/compute/atlas.js.map +1 -1
  7. package/dist/core/compute/index.d.ts +3 -3
  8. package/dist/core/compute/index.js +2 -2
  9. package/dist/core/compute/index.js.map +1 -1
  10. package/dist/core/compute/majorant-build.d.ts +45 -0
  11. package/dist/core/compute/majorant-build.js +193 -0
  12. package/dist/core/compute/majorant-build.js.map +1 -0
  13. package/dist/core/compute/multi-scale.d.ts +155 -0
  14. package/dist/core/compute/multi-scale.js +684 -0
  15. package/dist/core/compute/multi-scale.js.map +1 -0
  16. package/dist/core/compute/pyramid.d.ts +22 -7
  17. package/dist/core/compute/pyramid.js +22 -9
  18. package/dist/core/compute/pyramid.js.map +1 -1
  19. package/dist/core/compute/shared.d.ts +1 -0
  20. package/dist/core/compute/shared.js.map +1 -1
  21. package/dist/core/compute/stats.d.ts +10 -3
  22. package/dist/core/compute/stats.js +6 -1
  23. package/dist/core/compute/stats.js.map +1 -1
  24. package/dist/core/compute/value-transform.d.ts +8 -1
  25. package/dist/core/compute/value-transform.js +9 -3
  26. package/dist/core/compute/value-transform.js.map +1 -1
  27. package/dist/core/errors.d.ts +10 -0
  28. package/dist/core/errors.js +8 -0
  29. package/dist/core/errors.js.map +1 -1
  30. package/dist/core/frame/emission.d.ts +85 -0
  31. package/dist/core/frame/emission.js +422 -0
  32. package/dist/core/frame/emission.js.map +1 -0
  33. package/dist/core/frame/environment.d.ts +47 -0
  34. package/dist/core/frame/environment.js +178 -0
  35. package/dist/core/frame/environment.js.map +1 -0
  36. package/dist/core/frame/index.d.ts +39 -0
  37. package/dist/core/frame/index.js +27 -0
  38. package/dist/core/frame/index.js.map +1 -0
  39. package/dist/core/frame/kernels.d.ts +115 -0
  40. package/dist/core/frame/kernels.js +496 -0
  41. package/dist/core/frame/kernels.js.map +1 -0
  42. package/dist/core/frame/limits.d.ts +67 -0
  43. package/dist/core/frame/limits.js +109 -0
  44. package/dist/core/frame/limits.js.map +1 -0
  45. package/dist/core/frame/phase.d.ts +17 -0
  46. package/dist/core/frame/phase.js +53 -0
  47. package/dist/core/frame/phase.js.map +1 -0
  48. package/dist/core/frame/pipelines.d.ts +49 -0
  49. package/dist/core/frame/pipelines.js +147 -0
  50. package/dist/core/frame/pipelines.js.map +1 -0
  51. package/dist/core/frame/renderer.d.ts +122 -0
  52. package/dist/core/frame/renderer.js +1712 -0
  53. package/dist/core/frame/renderer.js.map +1 -0
  54. package/dist/core/frame/resources.d.ts +71 -0
  55. package/dist/core/frame/resources.js +100 -0
  56. package/dist/core/frame/resources.js.map +1 -0
  57. package/dist/core/frame/scattering.d.ts +97 -0
  58. package/dist/core/frame/scattering.js +332 -0
  59. package/dist/core/frame/scattering.js.map +1 -0
  60. package/dist/core/frame/settings.d.ts +243 -0
  61. package/dist/core/frame/settings.js +67 -0
  62. package/dist/core/frame/settings.js.map +1 -0
  63. package/dist/core/frame/shadows.d.ts +55 -0
  64. package/dist/core/frame/shadows.js +460 -0
  65. package/dist/core/frame/shadows.js.map +1 -0
  66. package/dist/core/frame/types.d.ts +415 -0
  67. package/dist/core/frame/types.js +49 -0
  68. package/dist/core/frame/types.js.map +1 -0
  69. package/dist/core/frame/uniforms.d.ts +105 -0
  70. package/dist/core/frame/uniforms.js +276 -0
  71. package/dist/core/frame/uniforms.js.map +1 -0
  72. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  73. package/dist/core/frame/wgsl/chunks.js +728 -0
  74. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  75. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  76. package/dist/core/frame/wgsl/emission.js +353 -0
  77. package/dist/core/frame/wgsl/emission.js.map +1 -0
  78. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  79. package/dist/core/frame/wgsl/environment.js +711 -0
  80. package/dist/core/frame/wgsl/environment.js.map +1 -0
  81. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  82. package/dist/core/frame/wgsl/gather.js +850 -0
  83. package/dist/core/frame/wgsl/gather.js.map +1 -0
  84. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  85. package/dist/core/frame/wgsl/integrate.js +213 -0
  86. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  87. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  88. package/dist/core/frame/wgsl/lighting.js +1636 -0
  89. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  90. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  91. package/dist/core/frame/wgsl/occluders.js +95 -0
  92. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  93. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  94. package/dist/core/frame/wgsl/resolve.js +205 -0
  95. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  96. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  97. package/dist/core/frame/wgsl/shadows.js +328 -0
  98. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  99. package/dist/core/half.d.ts +11 -0
  100. package/dist/core/half.js +22 -0
  101. package/dist/core/half.js.map +1 -0
  102. package/dist/core/index.d.ts +25 -3
  103. package/dist/core/index.js +23 -4
  104. package/dist/core/index.js.map +1 -1
  105. package/dist/core/internal.d.ts +17 -1
  106. package/dist/core/internal.js +18 -1
  107. package/dist/core/internal.js.map +1 -1
  108. package/dist/core/pool/image-header.d.ts +13 -2
  109. package/dist/core/pool/image-header.js +24 -5
  110. package/dist/core/pool/image-header.js.map +1 -1
  111. package/dist/core/pool/layout.d.ts +35 -1
  112. package/dist/core/pool/layout.js +51 -2
  113. package/dist/core/pool/layout.js.map +1 -1
  114. package/dist/core/pool/limits.d.ts +1 -0
  115. package/dist/core/pool/limits.js +1 -0
  116. package/dist/core/pool/limits.js.map +1 -1
  117. package/dist/core/pool/pool.d.ts +120 -15
  118. package/dist/core/pool/pool.js +255 -24
  119. package/dist/core/pool/pool.js.map +1 -1
  120. package/dist/core/reference/index.d.ts +6 -0
  121. package/dist/core/reference/index.js +7 -0
  122. package/dist/core/reference/index.js.map +1 -0
  123. package/dist/core/reference/renderer.d.ts +105 -0
  124. package/dist/core/reference/renderer.js +474 -0
  125. package/dist/core/reference/renderer.js.map +1 -0
  126. package/dist/core/reference/wgsl.d.ts +65 -0
  127. package/dist/core/reference/wgsl.js +803 -0
  128. package/dist/core/reference/wgsl.js.map +1 -0
  129. package/dist/{three → core}/sequence.d.ts +32 -2
  130. package/dist/{three → core}/sequence.js +24 -2
  131. package/dist/core/sequence.js.map +1 -0
  132. package/dist/core/source/brick-cache.d.ts +165 -0
  133. package/dist/core/source/brick-cache.js +627 -0
  134. package/dist/core/source/brick-cache.js.map +1 -0
  135. package/dist/core/source/dense-fill.d.ts +53 -0
  136. package/dist/core/source/dense-fill.js +377 -0
  137. package/dist/core/source/dense-fill.js.map +1 -0
  138. package/dist/core/source/dense.d.ts +33 -2
  139. package/dist/core/source/dense.js +121 -24
  140. package/dist/core/source/dense.js.map +1 -1
  141. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  142. package/dist/core/source/sparse-wgsl.js +481 -0
  143. package/dist/core/source/sparse-wgsl.js.map +1 -0
  144. package/dist/core/source/sparse.d.ts +192 -0
  145. package/dist/core/source/sparse.js +762 -0
  146. package/dist/core/source/sparse.js.map +1 -0
  147. package/dist/core/source/types.d.ts +59 -2
  148. package/dist/core/source/types.js.map +1 -1
  149. package/dist/core/surface/index.d.ts +10 -0
  150. package/dist/core/surface/index.js +9 -0
  151. package/dist/core/surface/index.js.map +1 -0
  152. package/dist/core/surface/level-set-pass.d.ts +140 -0
  153. package/dist/core/surface/level-set-pass.js +291 -0
  154. package/dist/core/surface/level-set-pass.js.map +1 -0
  155. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  156. package/dist/core/surface/level-set-wgsl.js +99 -0
  157. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  158. package/dist/core/surface/points.d.ts +109 -0
  159. package/dist/core/surface/points.js +226 -0
  160. package/dist/core/surface/points.js.map +1 -0
  161. package/dist/core/types.d.ts +12 -3
  162. package/dist/core/types.js +6 -2
  163. package/dist/core/types.js.map +1 -1
  164. package/dist/core/wgsl/api.d.ts +29 -5
  165. package/dist/core/wgsl/api.js +110 -27
  166. package/dist/core/wgsl/api.js.map +1 -1
  167. package/dist/core/wgsl/generate.d.ts +8 -0
  168. package/dist/core/wgsl/generate.js +195 -22
  169. package/dist/core/wgsl/generate.js.map +1 -1
  170. package/dist/core/wgsl/lean.d.ts +50 -0
  171. package/dist/core/wgsl/lean.js +327 -0
  172. package/dist/core/wgsl/lean.js.map +1 -0
  173. package/dist/core/wgsl/level-set.d.ts +5 -1
  174. package/dist/core/wgsl/level-set.js +11 -5
  175. package/dist/core/wgsl/level-set.js.map +1 -1
  176. package/dist/core/wgsl/majorant.d.ts +62 -0
  177. package/dist/core/wgsl/majorant.js +381 -0
  178. package/dist/core/wgsl/majorant.js.map +1 -0
  179. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +2 -2
  180. package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
  181. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
  182. package/dist/core/wgsl/types.d.ts +97 -3
  183. package/dist/core/wgsl/types.js.map +1 -1
  184. package/dist/three/coarse-first.d.ts +53 -8
  185. package/dist/three/coarse-first.js +24 -6
  186. package/dist/three/coarse-first.js.map +1 -1
  187. package/dist/three/compute.d.ts +12 -2
  188. package/dist/three/compute.js +16 -6
  189. package/dist/three/compute.js.map +1 -1
  190. package/dist/three/device.d.ts +7 -0
  191. package/dist/three/device.js +3 -0
  192. package/dist/three/device.js.map +1 -1
  193. package/dist/three/frame/core-environment.d.ts +38 -0
  194. package/dist/three/frame/core-environment.js +154 -0
  195. package/dist/three/frame/core-environment.js.map +1 -0
  196. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  197. package/dist/three/frame/core-integrate-material.js +162 -0
  198. package/dist/three/frame/core-integrate-material.js.map +1 -0
  199. package/dist/three/frame/core-occluders.d.ts +53 -0
  200. package/dist/three/frame/core-occluders.js +193 -0
  201. package/dist/three/frame/core-occluders.js.map +1 -0
  202. package/dist/three/frame/core-structs.d.ts +34 -0
  203. package/dist/three/frame/core-structs.js +61 -0
  204. package/dist/three/frame/core-structs.js.map +1 -0
  205. package/dist/three/frame/core-textures.d.ts +41 -0
  206. package/dist/three/frame/core-textures.js +114 -0
  207. package/dist/three/frame/core-textures.js.map +1 -0
  208. package/dist/three/frame/emission-light.d.ts +64 -114
  209. package/dist/three/frame/emission-light.js +188 -567
  210. package/dist/three/frame/emission-light.js.map +1 -1
  211. package/dist/three/frame/index.d.ts +11 -31
  212. package/dist/three/frame/index.js +9 -29
  213. package/dist/three/frame/index.js.map +1 -1
  214. package/dist/three/frame/medium.d.ts +12 -0
  215. package/dist/three/frame/medium.js.map +1 -1
  216. package/dist/three/frame/renderer.d.ts +58 -454
  217. package/dist/three/frame/renderer.js +409 -1427
  218. package/dist/three/frame/renderer.js.map +1 -1
  219. package/dist/three/frame/spectrum.d.ts +0 -14
  220. package/dist/three/frame/spectrum.js +2 -23
  221. package/dist/three/frame/spectrum.js.map +1 -1
  222. package/dist/three/frame/three-internals.d.ts +3 -8
  223. package/dist/three/frame/three-internals.js +13 -11
  224. package/dist/three/frame/three-internals.js.map +1 -1
  225. package/dist/three/frame/volume-shadows.d.ts +93 -107
  226. package/dist/three/frame/volume-shadows.js +278 -631
  227. package/dist/three/frame/volume-shadows.js.map +1 -1
  228. package/dist/three/frame/volume.d.ts +91 -33
  229. package/dist/three/frame/volume.js +63 -51
  230. package/dist/three/frame/volume.js.map +1 -1
  231. package/dist/three/grid-node.d.ts +34 -1
  232. package/dist/three/grid-node.js +36 -1
  233. package/dist/three/grid-node.js.map +1 -1
  234. package/dist/three/index.d.ts +20 -11
  235. package/dist/three/index.js +21 -12
  236. package/dist/three/index.js.map +1 -1
  237. package/dist/three/internal.d.ts +14 -8
  238. package/dist/three/internal.js +11 -7
  239. package/dist/three/internal.js.map +1 -1
  240. package/dist/three/level-set-material.d.ts +81 -8
  241. package/dist/three/level-set-material.js +162 -125
  242. package/dist/three/level-set-material.js.map +1 -1
  243. package/dist/three/level-set-physical-material.d.ts +154 -0
  244. package/dist/three/level-set-physical-material.js +253 -0
  245. package/dist/three/level-set-physical-material.js.map +1 -0
  246. package/dist/three/level-set-velocity.d.ts +94 -0
  247. package/dist/three/level-set-velocity.js +208 -0
  248. package/dist/three/level-set-velocity.js.map +1 -0
  249. package/dist/three/material.d.ts +141 -11
  250. package/dist/three/material.js +161 -18
  251. package/dist/three/material.js.map +1 -1
  252. package/dist/three/points.d.ts +60 -4
  253. package/dist/three/points.js +140 -9
  254. package/dist/three/points.js.map +1 -1
  255. package/dist/three/sparse-source.d.ts +49 -117
  256. package/dist/three/sparse-source.js +109 -580
  257. package/dist/three/sparse-source.js.map +1 -1
  258. package/dist/three/volume-source.d.ts +11 -156
  259. package/dist/three/volume-source.js +29 -272
  260. package/dist/three/volume-source.js.map +1 -1
  261. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  262. package/dist/tools/cpu/brick-atlas.js +129 -0
  263. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  264. package/dist/tools/cpu/compute.d.ts +23 -4
  265. package/dist/tools/cpu/compute.js +35 -14
  266. package/dist/tools/cpu/compute.js.map +1 -1
  267. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  268. package/dist/tools/cpu/lean-reads.js +262 -0
  269. package/dist/tools/cpu/lean-reads.js.map +1 -0
  270. package/dist/tools/cpu/level-set.d.ts +42 -3
  271. package/dist/tools/cpu/level-set.js +59 -7
  272. package/dist/tools/cpu/level-set.js.map +1 -1
  273. package/dist/tools/cpu/majorant.d.ts +265 -0
  274. package/dist/tools/cpu/majorant.js +541 -0
  275. package/dist/tools/cpu/majorant.js.map +1 -0
  276. package/dist/tools/cpu/march.d.ts +93 -2
  277. package/dist/tools/cpu/march.js +165 -14
  278. package/dist/tools/cpu/march.js.map +1 -1
  279. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  280. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  281. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  282. package/dist/tools/cpu/points.d.ts +29 -0
  283. package/dist/tools/cpu/points.js +38 -0
  284. package/dist/tools/cpu/points.js.map +1 -0
  285. package/dist/tools/cpu/read-value.d.ts +19 -6
  286. package/dist/tools/cpu/read-value.js +32 -17
  287. package/dist/tools/cpu/read-value.js.map +1 -1
  288. package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
  289. package/dist/tools/cpu/sample-trilinear.js +19 -7
  290. package/dist/tools/cpu/sample-trilinear.js.map +1 -1
  291. package/dist/tools/cpu/stride-tables.d.ts +2 -2
  292. package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
  293. package/dist/tools/cpu/stride-tables.generated.js +7 -6
  294. package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
  295. package/dist/tools/cpu/stride-tables.js +1 -1
  296. package/dist/tools/cpu/stride-tables.js.map +1 -1
  297. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  298. package/dist/tools/cpu/surface-nets.js +597 -0
  299. package/dist/tools/cpu/surface-nets.js.map +1 -0
  300. package/dist/tools/errors.d.ts +9 -0
  301. package/dist/tools/errors.js +9 -0
  302. package/dist/tools/errors.js.map +1 -1
  303. package/dist/tools/frame/ambient.d.ts +98 -0
  304. package/dist/tools/frame/ambient.js +274 -0
  305. package/dist/tools/frame/ambient.js.map +1 -0
  306. package/dist/tools/frame/blackbody.d.ts +15 -0
  307. package/dist/tools/frame/blackbody.js +35 -0
  308. package/dist/tools/frame/blackbody.js.map +1 -1
  309. package/dist/tools/frame/brick-cache.d.ts +165 -0
  310. package/dist/tools/frame/brick-cache.js +326 -0
  311. package/dist/tools/frame/brick-cache.js.map +1 -0
  312. package/dist/tools/frame/emission.d.ts +9 -0
  313. package/dist/tools/frame/emission.js +9 -1
  314. package/dist/tools/frame/emission.js.map +1 -1
  315. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  316. package/dist/tools/frame/environment-gpu.js +280 -0
  317. package/dist/tools/frame/environment-gpu.js.map +1 -0
  318. package/dist/tools/frame/environment.d.ts +3 -2
  319. package/dist/tools/frame/environment.js +8 -4
  320. package/dist/tools/frame/environment.js.map +1 -1
  321. package/dist/tools/frame/froxel.d.ts +58 -0
  322. package/dist/tools/frame/froxel.js +115 -0
  323. package/dist/tools/frame/froxel.js.map +1 -0
  324. package/dist/tools/frame/grid.d.ts +90 -0
  325. package/dist/tools/frame/grid.js +112 -13
  326. package/dist/tools/frame/grid.js.map +1 -1
  327. package/dist/tools/frame/index.d.ts +14 -0
  328. package/dist/tools/frame/index.js +45 -4
  329. package/dist/tools/frame/index.js.map +1 -1
  330. package/dist/tools/frame/medium.d.ts +16 -0
  331. package/dist/tools/frame/medium.js +3 -1
  332. package/dist/tools/frame/medium.js.map +1 -1
  333. package/dist/tools/frame/mie.d.ts +9 -0
  334. package/dist/tools/frame/mie.js +18 -0
  335. package/dist/tools/frame/mie.js.map +1 -1
  336. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  337. package/dist/tools/frame/mlp-nn.js +159 -0
  338. package/dist/tools/frame/mlp-nn.js.map +1 -0
  339. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  340. package/dist/tools/frame/mlp-tza.js +186 -0
  341. package/dist/tools/frame/mlp-tza.js.map +1 -0
  342. package/dist/tools/frame/mlp.d.ts +183 -0
  343. package/dist/tools/frame/mlp.js +434 -0
  344. package/dist/tools/frame/mlp.js.map +1 -0
  345. package/dist/tools/frame/ms-exit.d.ts +42 -0
  346. package/dist/tools/frame/ms-exit.js +90 -0
  347. package/dist/tools/frame/ms-exit.js.map +1 -0
  348. package/dist/tools/frame/multi-scale.d.ts +152 -0
  349. package/dist/tools/frame/multi-scale.js +302 -0
  350. package/dist/tools/frame/multi-scale.js.map +1 -0
  351. package/dist/tools/frame/neural-weights.d.ts +6 -5
  352. package/dist/tools/frame/neural-weights.js +234 -235
  353. package/dist/tools/frame/neural-weights.js.map +1 -1
  354. package/dist/tools/frame/neural.js +1 -1
  355. package/dist/tools/frame/neural.js.map +1 -1
  356. package/dist/tools/frame/occluders.d.ts +51 -0
  357. package/dist/tools/frame/occluders.js +72 -0
  358. package/dist/tools/frame/occluders.js.map +1 -0
  359. package/dist/tools/frame/pyramid-layout.d.ts +17 -0
  360. package/dist/tools/frame/pyramid-layout.js +47 -0
  361. package/dist/tools/frame/pyramid-layout.js.map +1 -1
  362. package/dist/tools/frame/shadows.d.ts +110 -0
  363. package/dist/tools/frame/shadows.js +286 -0
  364. package/dist/tools/frame/shadows.js.map +1 -1
  365. package/dist/tools/frame/sparse.d.ts +82 -0
  366. package/dist/tools/frame/sparse.js +242 -1
  367. package/dist/tools/frame/sparse.js.map +1 -1
  368. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  369. package/dist/tools/frame/spectral-stack.js +391 -0
  370. package/dist/tools/frame/spectral-stack.js.map +1 -0
  371. package/dist/tools/frame/spectral.d.ts +21 -2
  372. package/dist/tools/frame/spectral.js +30 -8
  373. package/dist/tools/frame/spectral.js.map +1 -1
  374. package/dist/tools/frame/stack.d.ts +115 -0
  375. package/dist/tools/frame/stack.js +290 -0
  376. package/dist/tools/frame/stack.js.map +1 -0
  377. package/dist/tools/frame/view.d.ts +131 -0
  378. package/dist/tools/frame/view.js +337 -0
  379. package/dist/tools/frame/view.js.map +1 -0
  380. package/dist/tools/index.d.ts +66 -15
  381. package/dist/tools/index.js +55 -11
  382. package/dist/tools/index.js.map +1 -1
  383. package/dist/tools/internal.d.ts +58 -17
  384. package/dist/tools/internal.js +65 -11
  385. package/dist/tools/internal.js.map +1 -1
  386. package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
  387. package/dist/tools/nanovdb/build-from-vdb.js +10 -2
  388. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
  389. package/dist/tools/nanovdb/bytes.d.ts +17 -4
  390. package/dist/tools/nanovdb/bytes.js +46 -3
  391. package/dist/tools/nanovdb/bytes.js.map +1 -1
  392. package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
  393. package/dist/tools/nanovdb/coarse-first.js +7 -1
  394. package/dist/tools/nanovdb/coarse-first.js.map +1 -1
  395. package/dist/tools/nanovdb/half.d.ts +22 -0
  396. package/dist/tools/nanovdb/half.js +73 -0
  397. package/dist/tools/nanovdb/half.js.map +1 -0
  398. package/dist/tools/nanovdb/index.d.ts +3 -1
  399. package/dist/tools/nanovdb/index.js +2 -1
  400. package/dist/tools/nanovdb/index.js.map +1 -1
  401. package/dist/tools/nanovdb/inspect.d.ts +10 -1
  402. package/dist/tools/nanovdb/inspect.js +8 -1
  403. package/dist/tools/nanovdb/inspect.js.map +1 -1
  404. package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
  405. package/dist/tools/nanovdb/leaf-codec.js +40 -4
  406. package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
  407. package/dist/tools/nanovdb/quantize.d.ts +39 -10
  408. package/dist/tools/nanovdb/quantize.js +96 -44
  409. package/dist/tools/nanovdb/quantize.js.map +1 -1
  410. package/dist/tools/nanovdb/resample.d.ts +20 -3
  411. package/dist/tools/nanovdb/resample.js +20 -7
  412. package/dist/tools/nanovdb/resample.js.map +1 -1
  413. package/dist/tools/nanovdb/serialize.d.ts +34 -3
  414. package/dist/tools/nanovdb/serialize.js +51 -7
  415. package/dist/tools/nanovdb/serialize.js.map +1 -1
  416. package/dist/tools/nanovdb/stats.d.ts +34 -5
  417. package/dist/tools/nanovdb/stats.js +87 -11
  418. package/dist/tools/nanovdb/stats.js.map +1 -1
  419. package/dist/tools/nanovdb/transform.d.ts +4 -0
  420. package/dist/tools/nanovdb/transform.js +3 -0
  421. package/dist/tools/nanovdb/transform.js.map +1 -1
  422. package/dist/tools/nanovdb/tree.d.ts +14 -3
  423. package/dist/tools/nanovdb/tree.js +25 -13
  424. package/dist/tools/nanovdb/tree.js.map +1 -1
  425. package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
  426. package/dist/tools/nanovdb/write-nvdb.js +108 -28
  427. package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
  428. package/dist/tools/nvdb-file.d.ts +77 -7
  429. package/dist/tools/nvdb-file.js +177 -20
  430. package/dist/tools/nvdb-file.js.map +1 -1
  431. package/dist/tools/nvdb-stream.d.ts +23 -7
  432. package/dist/tools/nvdb-stream.js +78 -34
  433. package/dist/tools/nvdb-stream.js.map +1 -1
  434. package/dist/tools/reference/analytic.d.ts +41 -0
  435. package/dist/tools/reference/analytic.js +95 -0
  436. package/dist/tools/reference/analytic.js.map +1 -0
  437. package/dist/tools/reference/environment.d.ts +62 -0
  438. package/dist/tools/reference/environment.js +154 -0
  439. package/dist/tools/reference/environment.js.map +1 -0
  440. package/dist/tools/reference/index.d.ts +12 -0
  441. package/dist/tools/reference/index.js +13 -0
  442. package/dist/tools/reference/index.js.map +1 -0
  443. package/dist/tools/reference/media.d.ts +14 -0
  444. package/dist/tools/reference/media.js +30 -0
  445. package/dist/tools/reference/media.js.map +1 -0
  446. package/dist/tools/reference/rng.d.ts +20 -0
  447. package/dist/tools/reference/rng.js +30 -0
  448. package/dist/tools/reference/rng.js.map +1 -0
  449. package/dist/tools/reference/scene.d.ts +312 -0
  450. package/dist/tools/reference/scene.js +169 -0
  451. package/dist/tools/reference/scene.js.map +1 -0
  452. package/dist/tools/reference/tables.d.ts +98 -0
  453. package/dist/tools/reference/tables.js +264 -0
  454. package/dist/tools/reference/tables.js.map +1 -0
  455. package/dist/tools/reference/trace.d.ts +160 -0
  456. package/dist/tools/reference/trace.js +497 -0
  457. package/dist/tools/reference/trace.js.map +1 -0
  458. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  459. package/dist/tools/vdb/blosc-write.js +197 -0
  460. package/dist/tools/vdb/blosc-write.js.map +1 -0
  461. package/dist/tools/vdb/blosc.d.ts +35 -5
  462. package/dist/tools/vdb/blosc.js +82 -26
  463. package/dist/tools/vdb/blosc.js.map +1 -1
  464. package/dist/tools/vdb/blosclz.d.ts +33 -0
  465. package/dist/tools/vdb/blosclz.js +112 -0
  466. package/dist/tools/vdb/blosclz.js.map +1 -0
  467. package/dist/tools/vdb/byte-reader.d.ts +13 -3
  468. package/dist/tools/vdb/byte-reader.js +26 -4
  469. package/dist/tools/vdb/byte-reader.js.map +1 -1
  470. package/dist/tools/vdb/compression.d.ts +13 -5
  471. package/dist/tools/vdb/compression.js +13 -2
  472. package/dist/tools/vdb/compression.js.map +1 -1
  473. package/dist/tools/vdb/grid.js +8 -2
  474. package/dist/tools/vdb/grid.js.map +1 -1
  475. package/dist/tools/vdb/index.d.ts +2 -1
  476. package/dist/tools/vdb/index.js.map +1 -1
  477. package/dist/tools/vdb/lz4.d.ts +30 -0
  478. package/dist/tools/vdb/lz4.js +228 -0
  479. package/dist/tools/vdb/lz4.js.map +1 -0
  480. package/dist/tools/vdb/metadata.js +1 -1
  481. package/dist/tools/vdb/metadata.js.map +1 -1
  482. package/dist/tools/vdb/parse.d.ts +24 -2
  483. package/dist/tools/vdb/parse.js +102 -32
  484. package/dist/tools/vdb/parse.js.map +1 -1
  485. package/dist/tools/vdb/point-render-data.d.ts +49 -1
  486. package/dist/tools/vdb/point-render-data.js +91 -11
  487. package/dist/tools/vdb/point-render-data.js.map +1 -1
  488. package/dist/tools/vdb/points.d.ts +26 -0
  489. package/dist/tools/vdb/points.js +46 -5
  490. package/dist/tools/vdb/points.js.map +1 -1
  491. package/dist/tools/vdb/types.d.ts +59 -2
  492. package/dist/tools/vdb/types.js.map +1 -1
  493. package/dist/tools/wvdb/bake.d.ts +38 -9
  494. package/dist/tools/wvdb/bake.js +63 -13
  495. package/dist/tools/wvdb/bake.js.map +1 -1
  496. package/dist/tools/wvdb/dense.d.ts +80 -1
  497. package/dist/tools/wvdb/dense.js +67 -8
  498. package/dist/tools/wvdb/dense.js.map +1 -1
  499. package/dist/tools/wvdb/format.d.ts +59 -0
  500. package/dist/tools/wvdb/format.js +3 -0
  501. package/dist/tools/wvdb/format.js.map +1 -1
  502. package/dist/tools/wvdb/index.d.ts +1 -0
  503. package/dist/tools/wvdb/index.js +1 -0
  504. package/dist/tools/wvdb/index.js.map +1 -1
  505. package/dist/tools/wvdb/level-set.d.ts +10 -2
  506. package/dist/tools/wvdb/level-set.js.map +1 -1
  507. package/dist/tools/wvdb/nanovdb.d.ts +6 -1
  508. package/dist/tools/wvdb/nanovdb.js +5 -1
  509. package/dist/tools/wvdb/nanovdb.js.map +1 -1
  510. package/dist/tools/wvdb/partial.d.ts +74 -0
  511. package/dist/tools/wvdb/partial.js +233 -0
  512. package/dist/tools/wvdb/partial.js.map +1 -0
  513. package/dist/tools/wvdb/read.d.ts +77 -1
  514. package/dist/tools/wvdb/read.js +30 -7
  515. package/dist/tools/wvdb/read.js.map +1 -1
  516. package/dist/tools/wvdb/write.d.ts +23 -1
  517. package/dist/tools/wvdb/write.js +8 -1
  518. package/dist/tools/wvdb/write.js.map +1 -1
  519. package/package.json +2 -1
  520. package/vendor/VENDOR.md +21 -6
  521. package/vendor/pnanovdb.wgsl +52 -14
  522. package/dist/three/frame/blackbody.d.ts +0 -42
  523. package/dist/three/frame/blackbody.js +0 -74
  524. package/dist/three/frame/blackbody.js.map +0 -1
  525. package/dist/three/frame/chunks.d.ts +0 -157
  526. package/dist/three/frame/chunks.js +0 -559
  527. package/dist/three/frame/chunks.js.map +0 -1
  528. package/dist/three/frame/density-material.d.ts +0 -53
  529. package/dist/three/frame/density-material.js +0 -353
  530. package/dist/three/frame/density-material.js.map +0 -1
  531. package/dist/three/frame/environment-grid-material.d.ts +0 -21
  532. package/dist/three/frame/environment-grid-material.js +0 -184
  533. package/dist/three/frame/environment-grid-material.js.map +0 -1
  534. package/dist/three/frame/environment-material.d.ts +0 -22
  535. package/dist/three/frame/environment-material.js +0 -87
  536. package/dist/three/frame/environment-material.js.map +0 -1
  537. package/dist/three/frame/grid-mip-material.d.ts +0 -12
  538. package/dist/three/frame/grid-mip-material.js +0 -61
  539. package/dist/three/frame/grid-mip-material.js.map +0 -1
  540. package/dist/three/frame/inject-material.d.ts +0 -56
  541. package/dist/three/frame/inject-material.js +0 -424
  542. package/dist/three/frame/inject-material.js.map +0 -1
  543. package/dist/three/frame/integrate-material.d.ts +0 -26
  544. package/dist/three/frame/integrate-material.js +0 -198
  545. package/dist/three/frame/integrate-material.js.map +0 -1
  546. package/dist/three/frame/layout.d.ts +0 -34
  547. package/dist/three/frame/layout.js +0 -48
  548. package/dist/three/frame/layout.js.map +0 -1
  549. package/dist/three/frame/lighting-material.d.ts +0 -41
  550. package/dist/three/frame/lighting-material.js +0 -257
  551. package/dist/three/frame/lighting-material.js.map +0 -1
  552. package/dist/three/frame/lights.d.ts +0 -11
  553. package/dist/three/frame/lights.js +0 -16
  554. package/dist/three/frame/lights.js.map +0 -1
  555. package/dist/three/frame/neural.d.ts +0 -14
  556. package/dist/three/frame/neural.js +0 -105
  557. package/dist/three/frame/neural.js.map +0 -1
  558. package/dist/three/frame/phase.d.ts +0 -44
  559. package/dist/three/frame/phase.js +0 -80
  560. package/dist/three/frame/phase.js.map +0 -1
  561. package/dist/three/frame/shadow-density-material.d.ts +0 -30
  562. package/dist/three/frame/shadow-density-material.js +0 -123
  563. package/dist/three/frame/shadow-density-material.js.map +0 -1
  564. package/dist/three/frame/temporal-material.d.ts +0 -29
  565. package/dist/three/frame/temporal-material.js +0 -152
  566. package/dist/three/frame/temporal-material.js.map +0 -1
  567. package/dist/three/frame/transmittance-material.d.ts +0 -31
  568. package/dist/three/frame/transmittance-material.js +0 -315
  569. package/dist/three/frame/transmittance-material.js.map +0 -1
  570. package/dist/three/frame/view.d.ts +0 -103
  571. package/dist/three/frame/view.js +0 -296
  572. package/dist/three/frame/view.js.map +0 -1
  573. package/dist/three/frame/volume-shadow-material.d.ts +0 -36
  574. package/dist/three/frame/volume-shadow-material.js +0 -128
  575. package/dist/three/frame/volume-shadow-material.js.map +0 -1
  576. package/dist/three/sequence.js.map +0 -1
@@ -0,0 +1,62 @@
1
+ /**
2
+ * K6.R2: importance sampling of the reference's equirect environment map (next-event estimation of the map, combined
3
+ * with the phase-sampled escape by multiple importance sampling; `VDBReferenceSettings.environmentSampling`).
4
+ *
5
+ * The map is read nearest (`vdbRefEnvironmentRadiance`: texel x = ⌊u·W⌋, u = atan2(m.z, m.x)/2π + ½; row y = ⌊(1 − v)·H⌋,
6
+ * v = asin(m.y)/π + ½, m = R·d), so it is piecewise constant over texels, and a texel is uniform in solid angle in
7
+ * (azimuth, sin latitude): its solid angle is Ω = (2π / W)·(s_y − s_{y+1}) with s_y = sin(π(½ − y/H)) the sine of its
8
+ * top edge's latitude. Sampling picks a row from the marginal and a column from the row's conditional distribution of
9
+ * luminance × Ω (piecewise constant, so the texel's probability is P = P(y)·P(x | y)), then a direction uniform in the
10
+ * texel's solid angle: azimuth uniform in the column, sin latitude uniform in the row. The density per steradian is
11
+ * P / Ω, exactly (no sin θ approximation).
12
+ *
13
+ * Everything the sampler reads is in one r32float table the GPU kernel reads too (`core/reference/renderer.ts` uploads
14
+ * `data`): rows 0 … H − 1 the conditional CDFs C_y[0 … W], row H the marginal M[0 … H], row H + 1 cos φ and row H + 2
15
+ * sin φ of the column edges φ_x = 2π(x/W − ½) (x = 0 … W), row H + 3 the row edges s_y (y = 0 … H), row H + 4 each
16
+ * row's texel solid angle Ω_y (from f64 edges: the f32 difference of two edges near a pole loses digits); width
17
+ * max(W, H) + 1. Both sides read these f32 numbers, so the twin and the kernel pick the same texels. The kernel turns
18
+ * the column edge by the in-texel angle with a polynomial (WGSL `sin`/`cos` are only accurate to 2^-11, a third of a
19
+ * 4096-wide map's texel); the twin uses `Math.cos` / `Math.sin`.
20
+ */
21
+ import type { VDBRefVec3, VDBReferenceEquirect } from "./scene.js";
22
+ /** The sampling table of an equirect map ({@link vdbReferenceEnvironmentSampler}). */
23
+ export interface VDBReferenceEnvironmentSampler {
24
+ /** The map's size. */
25
+ width: number;
26
+ height: number;
27
+ /** The table's size: max(W, H) + 1 by H + 5. */
28
+ tableWidth: number;
29
+ tableHeight: number;
30
+ /** r32float rows (see the file comment), x fastest. */
31
+ data: Float32Array;
32
+ /** Σ luminance × Ω over the texels (0: nothing to sample; the map is then gathered by escapes only). */
33
+ total: number;
34
+ }
35
+ /**
36
+ * The sampling table of `map` (cached per map object). Weights: luminance (≥ 0) × the texel's solid angle; a row with
37
+ * no light gets a uniform conditional (never picked: its marginal interval is empty).
38
+ */
39
+ export declare function vdbReferenceEnvironmentSampler(map: VDBReferenceEquirect): VDBReferenceEnvironmentSampler;
40
+ /**
41
+ * The density per steradian of texel (x, y): P(y)·P(x | y) / Ω. The mutation `env-pdf` uses every texel's mean solid
42
+ * angle 4π / (W·H) instead of its own (a forgotten latitude Jacobian).
43
+ */
44
+ export declare function vdbRefEnvTexelPdf(s: VDBReferenceEnvironmentSampler, x: number, y: number, mutate?: string): number;
45
+ /** The texel (x, y) the radiance lookup reads in world direction `d` (`vdbRefEnvironmentRadiance`'s mapping). */
46
+ export declare function vdbRefEnvTexelOf(map: VDBReferenceEquirect, d: readonly number[]): [number, number];
47
+ /** The density per steradian with which {@link vdbRefEnvSample} picks world direction `d` (0 when the sampler is empty). */
48
+ export declare function vdbRefEnvPdf(map: VDBReferenceEquirect, s: VDBReferenceEnvironmentSampler, d: readonly number[], mutate?: string): number;
49
+ /**
50
+ * Sample a world direction from the map with xi ∈ [0, 1)⁴ (row, column, azimuth in the texel, sin latitude in the
51
+ * texel): the direction, the sampled texel's radiance (× `intensity`) and its density per steradian. The estimate
52
+ * uses the SAMPLED texel's radiance and density (the kernel's direction can stray across a texel edge by rounding; the
53
+ * texel is what was sampled).
54
+ */
55
+ export declare function vdbRefEnvSample(map: VDBReferenceEquirect, s: VDBReferenceEnvironmentSampler, xi: readonly number[], mutate?: string): {
56
+ dir: VDBRefVec3;
57
+ radiance: VDBRefVec3;
58
+ pdf: number;
59
+ texel: [number, number];
60
+ };
61
+ /** The power heuristic's weight (β = 2) of a technique with density `p` against one with density `q`: p² / (p² + q²). */
62
+ export declare function vdbRefMisWeight(p: number, q: number): number;
@@ -0,0 +1,154 @@
1
+ /**
2
+ * K6.R2: importance sampling of the reference's equirect environment map (next-event estimation of the map, combined
3
+ * with the phase-sampled escape by multiple importance sampling; `VDBReferenceSettings.environmentSampling`).
4
+ *
5
+ * The map is read nearest (`vdbRefEnvironmentRadiance`: texel x = ⌊u·W⌋, u = atan2(m.z, m.x)/2π + ½; row y = ⌊(1 − v)·H⌋,
6
+ * v = asin(m.y)/π + ½, m = R·d), so it is piecewise constant over texels, and a texel is uniform in solid angle in
7
+ * (azimuth, sin latitude): its solid angle is Ω = (2π / W)·(s_y − s_{y+1}) with s_y = sin(π(½ − y/H)) the sine of its
8
+ * top edge's latitude. Sampling picks a row from the marginal and a column from the row's conditional distribution of
9
+ * luminance × Ω (piecewise constant, so the texel's probability is P = P(y)·P(x | y)), then a direction uniform in the
10
+ * texel's solid angle: azimuth uniform in the column, sin latitude uniform in the row. The density per steradian is
11
+ * P / Ω, exactly (no sin θ approximation).
12
+ *
13
+ * Everything the sampler reads is in one r32float table the GPU kernel reads too (`core/reference/renderer.ts` uploads
14
+ * `data`): rows 0 … H − 1 the conditional CDFs C_y[0 … W], row H the marginal M[0 … H], row H + 1 cos φ and row H + 2
15
+ * sin φ of the column edges φ_x = 2π(x/W − ½) (x = 0 … W), row H + 3 the row edges s_y (y = 0 … H), row H + 4 each
16
+ * row's texel solid angle Ω_y (from f64 edges: the f32 difference of two edges near a pole loses digits); width
17
+ * max(W, H) + 1. Both sides read these f32 numbers, so the twin and the kernel pick the same texels. The kernel turns
18
+ * the column edge by the in-texel angle with a polynomial (WGSL `sin`/`cos` are only accurate to 2^-11, a third of a
19
+ * 4096-wide map's texel); the twin uses `Math.cos` / `Math.sin`.
20
+ */
21
+ const LUMA = [0.2126, 0.7152, 0.0722];
22
+ const cache = new WeakMap();
23
+ /**
24
+ * The sampling table of `map` (cached per map object). Weights: luminance (≥ 0) × the texel's solid angle; a row with
25
+ * no light gets a uniform conditional (never picked: its marginal interval is empty).
26
+ */
27
+ export function vdbReferenceEnvironmentSampler(map) {
28
+ const hit = cache.get(map);
29
+ if (hit)
30
+ return hit;
31
+ const W = map.width;
32
+ const H = map.height;
33
+ const tw = Math.max(W, H) + 1;
34
+ const th = H + 5;
35
+ const data = new Float32Array(tw * th);
36
+ const rowEdge = (y) => (y === 0 ? 1 : y === H ? -1 : Math.sin(Math.PI * (0.5 - y / H)));
37
+ const rowWeight = new Float64Array(H);
38
+ const acc = new Float64Array(W + 1);
39
+ for (let y = 0; y < H; y++) {
40
+ const omega = ((2 * Math.PI) / W) * (rowEdge(y) - rowEdge(y + 1));
41
+ data[(H + 4) * tw + y] = omega;
42
+ acc[0] = 0;
43
+ for (let x = 0; x < W; x++) {
44
+ const k = (y * W + x) * 4;
45
+ const l = Math.max(0, LUMA[0] * map.data[k] + LUMA[1] * map.data[k + 1] + LUMA[2] * map.data[k + 2]);
46
+ acc[x + 1] = acc[x] + l;
47
+ }
48
+ const sum = acc[W];
49
+ rowWeight[y] = sum * omega;
50
+ for (let x = 0; x <= W; x++)
51
+ data[y * tw + x] = sum > 0 ? acc[x] / sum : x / W;
52
+ data[y * tw + W] = 1;
53
+ }
54
+ let total = 0;
55
+ for (let y = 0; y < H; y++)
56
+ total += rowWeight[y];
57
+ let m = 0;
58
+ for (let y = 0; y <= H; y++) {
59
+ data[H * tw + y] = total > 0 ? m / total : y / H;
60
+ if (y < H)
61
+ m += rowWeight[y];
62
+ }
63
+ data[H * tw + H] = 1;
64
+ for (let x = 0; x <= W; x++) {
65
+ const phi = 2 * Math.PI * (x / W - 0.5);
66
+ data[(H + 1) * tw + x] = Math.cos(phi);
67
+ data[(H + 2) * tw + x] = Math.sin(phi);
68
+ }
69
+ for (let y = 0; y <= H; y++)
70
+ data[(H + 3) * tw + y] = rowEdge(y);
71
+ const s = { width: W, height: H, tableWidth: tw, tableHeight: th, data, total };
72
+ cache.set(map, s);
73
+ return s;
74
+ }
75
+ /** The interval j with t[j] ≤ xi < t[j + 1] of the increasing table t[0 … n] (binary search, as the phase table's). */
76
+ function search(data, base, n, xi) {
77
+ let lo = 0;
78
+ let hi = n;
79
+ while (hi - lo > 1) {
80
+ const mid = (lo + hi) >> 1;
81
+ if (data[base + mid] <= xi)
82
+ lo = mid;
83
+ else
84
+ hi = mid;
85
+ }
86
+ return lo;
87
+ }
88
+ /**
89
+ * The density per steradian of texel (x, y): P(y)·P(x | y) / Ω. The mutation `env-pdf` uses every texel's mean solid
90
+ * angle 4π / (W·H) instead of its own (a forgotten latitude Jacobian).
91
+ */
92
+ export function vdbRefEnvTexelPdf(s, x, y, mutate) {
93
+ const { width: W, height: H, tableWidth: tw, data } = s;
94
+ const py = data[H * tw + y + 1] - data[H * tw + y];
95
+ const px = data[y * tw + x + 1] - data[y * tw + x];
96
+ const omega = mutate === "env-pdf" ? (4 * Math.PI) / (W * H) : data[(H + 4) * tw + y];
97
+ return omega > 0 ? (py * px) / omega : 0;
98
+ }
99
+ /** The texel (x, y) the radiance lookup reads in world direction `d` (`vdbRefEnvironmentRadiance`'s mapping). */
100
+ export function vdbRefEnvTexelOf(map, d) {
101
+ const r = map.rotation;
102
+ const m = r ? [r[0] * d[0] + r[1] * d[1] + r[2] * d[2], r[3] * d[0] + r[4] * d[1] + r[5] * d[2], r[6] * d[0] + r[7] * d[1] + r[8] * d[2]] : d;
103
+ const u = Math.atan2(m[2], m[0]) / (2 * Math.PI) + 0.5;
104
+ const v = Math.asin(Math.min(Math.max(m[1], -1), 1)) / Math.PI + 0.5;
105
+ const x = Math.min(Math.max(Math.floor(u * map.width), 0), map.width - 1);
106
+ const y = Math.min(Math.max(Math.floor((1 - v) * map.height), 0), map.height - 1);
107
+ return [x, y];
108
+ }
109
+ /** The density per steradian with which {@link vdbRefEnvSample} picks world direction `d` (0 when the sampler is empty). */
110
+ export function vdbRefEnvPdf(map, s, d, mutate) {
111
+ if (!(s.total > 0))
112
+ return 0;
113
+ const [x, y] = vdbRefEnvTexelOf(map, d);
114
+ return vdbRefEnvTexelPdf(s, x, y, mutate);
115
+ }
116
+ /**
117
+ * Sample a world direction from the map with xi ∈ [0, 1)⁴ (row, column, azimuth in the texel, sin latitude in the
118
+ * texel): the direction, the sampled texel's radiance (× `intensity`) and its density per steradian. The estimate
119
+ * uses the SAMPLED texel's radiance and density (the kernel's direction can stray across a texel edge by rounding; the
120
+ * texel is what was sampled).
121
+ */
122
+ export function vdbRefEnvSample(map, s, xi, mutate) {
123
+ const { width: W, height: H, tableWidth: tw, data } = s;
124
+ const y = search(data, H * tw, H, xi[0]);
125
+ const x = search(data, y * tw, W, xi[1]);
126
+ const a = ((2 * Math.PI) / W) * xi[2];
127
+ const c0 = data[(H + 1) * tw + x];
128
+ const s0 = data[(H + 2) * tw + x];
129
+ const ca = Math.cos(a);
130
+ const sa = Math.sin(a);
131
+ const cphi = c0 * ca - s0 * sa;
132
+ const sphi = s0 * ca + c0 * sa;
133
+ const top = data[(H + 3) * tw + y];
134
+ const bottom = data[(H + 3) * tw + y + 1];
135
+ const my = bottom + (top - bottom) * xi[3];
136
+ const r = Math.sqrt(Math.max(0, 1 - my * my));
137
+ const m = [r * cphi, my, r * sphi];
138
+ const R = map.rotation;
139
+ // d = Rᵀ m (R is orthonormal: the lookup applies m = R d)
140
+ const raw = R ? [R[0] * m[0] + R[3] * m[1] + R[6] * m[2], R[1] * m[0] + R[4] * m[1] + R[7] * m[2], R[2] * m[0] + R[5] * m[1] + R[8] * m[2]] : m;
141
+ // unit length again (the f32 column edges are unit only to f32 rounding)
142
+ const len = Math.hypot(raw[0], raw[1], raw[2]);
143
+ const dir = [raw[0] / len, raw[1] / len, raw[2] / len];
144
+ const k = (y * W + x) * 4;
145
+ const scale = map.intensity ?? 1;
146
+ return { dir, radiance: [map.data[k] * scale, map.data[k + 1] * scale, map.data[k + 2] * scale], pdf: vdbRefEnvTexelPdf(s, x, y, mutate), texel: [x, y] };
147
+ }
148
+ /** The power heuristic's weight (β = 2) of a technique with density `p` against one with density `q`: p² / (p² + q²). */
149
+ export function vdbRefMisWeight(p, q) {
150
+ // as a ratio at most 1e15, so the GPU's f32 never overflows (a forward Mie peak, u → 0; a texel the map never picks)
151
+ const r = q / Math.max(p, q * 1e-15, 1e-30);
152
+ return 1 / (1 + r * r);
153
+ }
154
+ //# sourceMappingURL=environment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../src/tools/reference/environment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAkBH,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAC/C,MAAM,KAAK,GAAG,IAAI,OAAO,EAAwD,CAAC;AAElF;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAAC,GAAyB;IACtE,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC;IACpB,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC;IACpB,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC;IACrB,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IAC9B,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IACjB,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAA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E,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,CAAC;IAC5C,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AACzB,CAAC","sourcesContent":["/**\n * K6.R2: importance sampling of the reference's equirect environment map (next-event estimation of the map, combined\n * with the phase-sampled escape by multiple importance sampling; `VDBReferenceSettings.environmentSampling`).\n *\n * The map is read nearest (`vdbRefEnvironmentRadiance`: texel x = ⌊u·W⌋, u = atan2(m.z, m.x)/2π + ½; row y = ⌊(1 − v)·H⌋,\n * v = asin(m.y)/π + ½, m = R·d), so it is piecewise constant over texels, and a texel is uniform in solid angle in\n * (azimuth, sin latitude): its solid angle is Ω = (2π / W)·(s_y − s_{y+1}) with s_y = sin(π(½ − y/H)) the sine of its\n * top edge's latitude. Sampling picks a row from the marginal and a column from the row's conditional distribution of\n * luminance × Ω (piecewise constant, so the texel's probability is P = P(y)·P(x | y)), then a direction uniform in the\n * texel's solid angle: azimuth uniform in the column, sin latitude uniform in the row. The density per steradian is\n * P / Ω, exactly (no sin θ approximation).\n *\n * Everything the sampler reads is in one r32float table the GPU kernel reads too (`core/reference/renderer.ts` uploads\n * `data`): rows 0 … H − 1 the conditional CDFs C_y[0 … W], row H the marginal M[0 … H], row H + 1 cos φ and row H + 2\n * sin φ of the column edges φ_x = 2π(x/W − ½) (x = 0 … W), row H + 3 the row edges s_y (y = 0 … H), row H + 4 each\n * row's texel solid angle Ω_y (from f64 edges: the f32 difference of two edges near a pole loses digits); width\n * max(W, H) + 1. Both sides read these f32 numbers, so the twin and the kernel pick the same texels. The kernel turns\n * the column edge by the in-texel angle with a polynomial (WGSL `sin`/`cos` are only accurate to 2^-11, a third of a\n * 4096-wide map's texel); the twin uses `Math.cos` / `Math.sin`.\n */\n\nimport type { VDBRefVec3, VDBReferenceEquirect } from \"./scene.js\";\n\n/** The sampling table of an equirect map ({@link vdbReferenceEnvironmentSampler}). */\nexport interface VDBReferenceEnvironmentSampler {\n /** The map's size. */\n width: number;\n height: number;\n /** The table's size: max(W, H) + 1 by H + 5. */\n tableWidth: number;\n tableHeight: number;\n /** r32float rows (see the file comment), x fastest. */\n data: Float32Array;\n /** Σ luminance × Ω over the texels (0: nothing to sample; the map is then gathered by escapes only). */\n total: number;\n}\n\nconst LUMA = [0.2126, 0.7152, 0.0722] as const;\nconst cache = new WeakMap<VDBReferenceEquirect, VDBReferenceEnvironmentSampler>();\n\n/**\n * The sampling table of `map` (cached per map object). Weights: luminance (≥ 0) × the texel's solid angle; a row with\n * no light gets a uniform conditional (never picked: its marginal interval is empty).\n */\nexport function vdbReferenceEnvironmentSampler(map: VDBReferenceEquirect): VDBReferenceEnvironmentSampler {\n const hit = cache.get(map);\n if (hit) return hit;\n const W = map.width;\n const H = map.height;\n const tw = Math.max(W, H) + 1;\n const th = H + 5;\n const data = new Float32Array(tw * th);\n const rowEdge = (y: number) => (y === 0 ? 1 : y === H ? -1 : Math.sin(Math.PI * (0.5 - y / H)));\n const rowWeight = new Float64Array(H);\n const acc = new Float64Array(W + 1);\n for (let y = 0; y < H; y++) {\n const omega = ((2 * Math.PI) / W) * (rowEdge(y) - rowEdge(y + 1));\n data[(H + 4) * tw + y] = omega;\n acc[0] = 0;\n for (let x = 0; x < W; x++) {\n const k = (y * W + x) * 4;\n const l = Math.max(0, LUMA[0] * map.data[k]! + LUMA[1] * map.data[k + 1]! + LUMA[2] * map.data[k + 2]!);\n acc[x + 1] = acc[x]! + l;\n }\n const sum = acc[W]!;\n rowWeight[y] = sum * omega;\n for (let x = 0; x <= W; x++) data[y * tw + x] = sum > 0 ? acc[x]! / sum : x / W;\n data[y * tw + W] = 1;\n }\n let total = 0;\n for (let y = 0; y < H; y++) total += rowWeight[y]!;\n let m = 0;\n for (let y = 0; y <= H; y++) {\n data[H * tw + y] = total > 0 ? m / total : y / H;\n if (y < H) m += rowWeight[y]!;\n }\n data[H * tw + H] = 1;\n for (let x = 0; x <= W; x++) {\n const phi = 2 * Math.PI * (x / W - 0.5);\n data[(H + 1) * tw + x] = Math.cos(phi);\n data[(H + 2) * tw + x] = Math.sin(phi);\n }\n for (let y = 0; y <= H; y++) data[(H + 3) * tw + y] = rowEdge(y);\n const s: VDBReferenceEnvironmentSampler = { width: W, height: H, tableWidth: tw, tableHeight: th, data, total };\n cache.set(map, s);\n return s;\n}\n\n/** The interval j with t[j] ≤ xi < t[j + 1] of the increasing table t[0 … n] (binary search, as the phase table's). */\nfunction search(data: Float32Array, base: number, n: number, xi: number): number {\n let lo = 0;\n let hi = n;\n while (hi - lo > 1) {\n const mid = (lo + hi) >> 1;\n if (data[base + mid]! <= xi) lo = mid;\n else hi = mid;\n }\n return lo;\n}\n\n/**\n * The density per steradian of texel (x, y): P(y)·P(x | y) / Ω. The mutation `env-pdf` uses every texel's mean solid\n * angle 4π / (W·H) instead of its own (a forgotten latitude Jacobian).\n */\nexport function vdbRefEnvTexelPdf(s: VDBReferenceEnvironmentSampler, x: number, y: number, mutate?: string): number {\n const { width: W, height: H, tableWidth: tw, data } = s;\n const py = data[H * tw + y + 1]! - data[H * tw + y]!;\n const px = data[y * tw + x + 1]! - data[y * tw + x]!;\n const omega = mutate === \"env-pdf\" ? (4 * Math.PI) / (W * H) : data[(H + 4) * tw + y]!;\n return omega > 0 ? (py * px) / omega : 0;\n}\n\n/** The texel (x, y) the radiance lookup reads in world direction `d` (`vdbRefEnvironmentRadiance`'s mapping). */\nexport function vdbRefEnvTexelOf(map: VDBReferenceEquirect, d: readonly number[]): [number, number] {\n const r = map.rotation;\n const m = r ? [r[0]! * d[0]! + r[1]! * d[1]! + r[2]! * d[2]!, r[3]! * d[0]! + r[4]! * d[1]! + r[5]! * d[2]!, r[6]! * d[0]! + r[7]! * d[1]! + r[8]! * d[2]!] : d;\n const u = Math.atan2(m[2]!, m[0]!) / (2 * Math.PI) + 0.5;\n const v = Math.asin(Math.min(Math.max(m[1]!, -1), 1)) / Math.PI + 0.5;\n const x = Math.min(Math.max(Math.floor(u * map.width), 0), map.width - 1);\n const y = Math.min(Math.max(Math.floor((1 - v) * map.height), 0), map.height - 1);\n return [x, y];\n}\n\n/** The density per steradian with which {@link vdbRefEnvSample} picks world direction `d` (0 when the sampler is empty). */\nexport function vdbRefEnvPdf(map: VDBReferenceEquirect, s: VDBReferenceEnvironmentSampler, d: readonly number[], mutate?: string): number {\n if (!(s.total > 0)) return 0;\n const [x, y] = vdbRefEnvTexelOf(map, d);\n return vdbRefEnvTexelPdf(s, x, y, mutate);\n}\n\n/**\n * Sample a world direction from the map with xi ∈ [0, 1)⁴ (row, column, azimuth in the texel, sin latitude in the\n * texel): the direction, the sampled texel's radiance (× `intensity`) and its density per steradian. The estimate\n * uses the SAMPLED texel's radiance and density (the kernel's direction can stray across a texel edge by rounding; the\n * texel is what was sampled).\n */\nexport function vdbRefEnvSample(map: VDBReferenceEquirect, s: VDBReferenceEnvironmentSampler, xi: readonly number[], mutate?: string): { dir: VDBRefVec3; radiance: VDBRefVec3; pdf: number; texel: [number, number] } {\n const { width: W, height: H, tableWidth: tw, data } = s;\n const y = search(data, H * tw, H, xi[0]!);\n const x = search(data, y * tw, W, xi[1]!);\n const a = ((2 * Math.PI) / W) * xi[2]!;\n const c0 = data[(H + 1) * tw + x]!;\n const s0 = data[(H + 2) * tw + x]!;\n const ca = Math.cos(a);\n const sa = Math.sin(a);\n const cphi = c0 * ca - s0 * sa;\n const sphi = s0 * ca + c0 * sa;\n const top = data[(H + 3) * tw + y]!;\n const bottom = data[(H + 3) * tw + y + 1]!;\n const my = bottom + (top - bottom) * xi[3]!;\n const r = Math.sqrt(Math.max(0, 1 - my * my));\n const m = [r * cphi, my, r * sphi];\n const R = map.rotation;\n // d = Rᵀ m (R is orthonormal: the lookup applies m = R d)\n const raw = R ? [R[0]! * m[0]! + R[3]! * m[1]! + R[6]! * m[2]!, R[1]! * m[0]! + R[4]! * m[1]! + R[7]! * m[2]!, R[2]! * m[0]! + R[5]! * m[1]! + R[8]! * m[2]!] : m;\n // unit length again (the f32 column edges are unit only to f32 rounding)\n const len = Math.hypot(raw[0]!, raw[1]!, raw[2]!);\n const dir: VDBRefVec3 = [raw[0]! / len, raw[1]! / len, raw[2]! / len];\n const k = (y * W + x) * 4;\n const scale = map.intensity ?? 1;\n return { dir, radiance: [map.data[k]! * scale, map.data[k + 1]! * scale, map.data[k + 2]! * scale], pdf: vdbRefEnvTexelPdf(s, x, y, mutate), texel: [x, y] };\n}\n\n/** The power heuristic's weight (β = 2) of a technique with density `p` against one with density `q`: p² / (p² + q²). */\nexport function vdbRefMisWeight(p: number, q: number): number {\n // as a ratio at most 1e15, so the GPU's f32 never overflows (a forward Mie peak, u → 0; a texel the map never picks)\n const r = q / Math.max(p, q * 1e-15, 1e-30);\n return 1 / (1 + r * r);\n}\n"]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * K6.R: the reference renderer's engine-free half (design K6-core-renderer.md §7.4): the scene description, the
3
+ * random stream it shares with the GPU kernel, the CPU twin (a brute-force volumetric path tracer), the media the
4
+ * twin reads and the analytic cases. Internal (`tools/internal.ts`); no public export.
5
+ */
6
+ export * from "./rng.js";
7
+ export * from "./scene.js";
8
+ export * from "./trace.js";
9
+ export * from "./media.js";
10
+ export * from "./analytic.js";
11
+ export * from "./tables.js";
12
+ export * from "./environment.js";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * K6.R: the reference renderer's engine-free half (design K6-core-renderer.md §7.4): the scene description, the
3
+ * random stream it shares with the GPU kernel, the CPU twin (a brute-force volumetric path tracer), the media the
4
+ * twin reads and the analytic cases. Internal (`tools/internal.ts`); no public export.
5
+ */
6
+ export * from "./rng.js";
7
+ export * from "./scene.js";
8
+ export * from "./trace.js";
9
+ export * from "./media.js";
10
+ export * from "./analytic.js";
11
+ export * from "./tables.js";
12
+ export * from "./environment.js";
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/reference/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC","sourcesContent":["/**\n * K6.R: the reference renderer's engine-free half (design K6-core-renderer.md §7.4): the scene description, the\n * random stream it shares with the GPU kernel, the CPU twin (a brute-force volumetric path tracer), the media the\n * twin reads and the analytic cases. Internal (`tools/internal.ts`); no public export.\n */\nexport * from \"./rng.js\";\nexport * from \"./scene.js\";\nexport * from \"./trace.js\";\nexport * from \"./media.js\";\nexport * from \"./analytic.js\";\nexport * from \"./tables.js\";\nexport * from \"./environment.js\";\n"]}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * K6.R: the CPU side of the reference renderer's volume sources ({@link VDBReferenceMediumCpu}): the dense `.wvdb`
3
+ * textures (twin of `vdbDenseSource`: hardware trilinear on the 8-bit texels, `sampleWvdbDenseTexture`), the sparse
4
+ * pool (twin of `vdbSparseSource` at level 0: `tools/frame/sparse.ts`) and a constant medium (analytic tests).
5
+ */
6
+ import { type VDBSparseVolumeCpu } from "../frame/sparse.js";
7
+ import { type WvdbDenseVolume } from "../wvdb/dense.js";
8
+ import type { VDBReferenceMediumCpu } from "./trace.js";
9
+ /** The dense source at level 0: density × mask, the albedo texture's rgb, the emission texture. */
10
+ export declare function vdbReferenceDenseMediumCpu(volume: WvdbDenseVolume): VDBReferenceMediumCpu;
11
+ /** The sparse source at level 0 (one volume of a `vdbSparseSource`, as its CPU twin describes it). */
12
+ export declare function vdbReferenceSparseMediumCpu(vol: VDBSparseVolumeCpu): VDBReferenceMediumCpu;
13
+ /** A constant medium (density `value`, emission channel `emission`), for the analytic tests. */
14
+ export declare function vdbReferenceConstantMediumCpu(value?: number, emission?: number): VDBReferenceMediumCpu;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * K6.R: the CPU side of the reference renderer's volume sources ({@link VDBReferenceMediumCpu}): the dense `.wvdb`
3
+ * textures (twin of `vdbDenseSource`: hardware trilinear on the 8-bit texels, `sampleWvdbDenseTexture`), the sparse
4
+ * pool (twin of `vdbSparseSource` at level 0: `tools/frame/sparse.ts`) and a constant medium (analytic tests).
5
+ */
6
+ import { vdbSparseAlbedoCpu, vdbSparseDensityCpu, vdbSparseDensityStochasticCpu, vdbSparseEmissionCpu, vdbSparseMaskCpu } from "../frame/sparse.js";
7
+ import { sampleWvdbDenseTexture } from "../wvdb/dense.js";
8
+ /** The dense source at level 0: density × mask, the albedo texture's rgb, the emission texture. */
9
+ export function vdbReferenceDenseMediumCpu(volume) {
10
+ const { density, mask, albedo, emission } = volume;
11
+ return {
12
+ density: (uvw) => sampleWvdbDenseTexture(density, uvw, 0) * (mask ? sampleWvdbDenseTexture(mask, uvw, 0) : 1),
13
+ ...(albedo ? { albedo: (uvw) => [0, 1, 2].map((c) => sampleWvdbDenseTexture(albedo, uvw, 0, c)) } : {}),
14
+ ...(emission ? { emission: (uvw) => sampleWvdbDenseTexture(emission, uvw, 0) } : {}),
15
+ };
16
+ }
17
+ /** The sparse source at level 0 (one volume of a `vdbSparseSource`, as its CPU twin describes it). */
18
+ export function vdbReferenceSparseMediumCpu(vol) {
19
+ return {
20
+ density: (uvw) => vdbSparseDensityCpu(vol, uvw, 0).value * vdbSparseMaskCpu(vol, uvw).value,
21
+ densityStochastic: (uvw, xi) => vdbSparseDensityStochasticCpu(vol, uvw, 0, xi).value * vdbSparseMaskCpu(vol, uvw).value,
22
+ ...(vol.albedo ? { albedo: (uvw) => vdbSparseAlbedoCpu(vol, uvw).value } : {}),
23
+ ...(vol.emission ? { emission: (uvw) => vdbSparseEmissionCpu(vol, uvw).value } : {}),
24
+ };
25
+ }
26
+ /** A constant medium (density `value`, emission channel `emission`), for the analytic tests. */
27
+ export function vdbReferenceConstantMediumCpu(value = 1, emission) {
28
+ return { density: () => value, ...(emission !== undefined ? { emission: () => emission } : {}) };
29
+ }
30
+ //# sour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GAAG,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,KAAK;QAC3F,iBAAiB,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,6BAA6B,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,KAAK;QACvH,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9E,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,oBAAoB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrF,CAAC;AACJ,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,6BAA6B,CAAC,KAAK,GAAG,CAAC,EAAE,QAAiB;IACxE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AACnG,CAAC","sourcesContent":["/**\n * K6.R: the CPU side of the reference renderer's volume sources ({@link VDBReferenceMediumCpu}): the dense `.wvdb`\n * textures (twin of `vdbDenseSource`: hardware trilinear on the 8-bit texels, `sampleWvdbDenseTexture`), the sparse\n * pool (twin of `vdbSparseSource` at level 0: `tools/frame/sparse.ts`) and a constant medium (analytic tests).\n */\n\nimport { vdbSparseAlbedoCpu, vdbSparseDensityCpu, vdbSparseDensityStochasticCpu, vdbSparseEmissionCpu, vdbSparseMaskCpu, type VDBSparseVolumeCpu } from \"../frame/sparse.js\";\nimport { sampleWvdbDenseTexture, type WvdbDenseVolume } from \"../wvdb/dense.js\";\nimport type { VDBRefVec3 } from \"./scene.js\";\nimport type { VDBReferenceMediumCpu } from \"./trace.js\";\n\n/** The dense source at level 0: density × mask, the albedo texture's rgb, the emission texture. */\nexport function vdbReferenceDenseMediumCpu(volume: WvdbDenseVolume): VDBReferenceMediumCpu {\n const { density, mask, albedo, emission } = volume;\n return {\n density: (uvw) => sampleWvdbDenseTexture(density, uvw, 0) * (mask ? sampleWvdbDenseTexture(mask, uvw, 0) : 1),\n ...(albedo ? { albedo: (uvw) => [0, 1, 2].map((c) => sampleWvdbDenseTexture(albedo, uvw, 0, c)) as VDBRefVec3 } : {}),\n ...(emission ? { emission: (uvw) => sampleWvdbDenseTexture(emission, uvw, 0) } : {}),\n };\n}\n\n/** The sparse source at level 0 (one volume of a `vdbSparseSource`, as its CPU twin describes it). */\nexport function vdbReferenceSparseMediumCpu(vol: VDBSparseVolumeCpu): VDBReferenceMediumCpu {\n return {\n density: (uvw) => vdbSparseDensityCpu(vol, uvw, 0).value * vdbSparseMaskCpu(vol, uvw).value,\n densityStochastic: (uvw, xi) => vdbSparseDensityStochasticCpu(vol, uvw, 0, xi).value * vdbSparseMaskCpu(vol, uvw).value,\n ...(vol.albedo ? { albedo: (uvw) => vdbSparseAlbedoCpu(vol, uvw).value } : {}),\n ...(vol.emission ? { emission: (uvw) => vdbSparseEmissionCpu(vol, uvw).value } : {}),\n };\n}\n\n/** A constant medium (density `value`, emission channel `emission`), for the analytic tests. */\nexport function vdbReferenceConstantMediumCpu(value = 1, emission?: number): VDBReferenceMediumCpu {\n return { density: () => value, ...(emission !== undefined ? { emission: () => emission } : {}) };\n}\n"]}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * K6.R: the random numbers the reference renderer's GPU kernel and its CPU twin share. A 32-bit LCG with the
3
+ * PCG-RXS-M-XS output permutation (Jarzynski & Olano 2020, "Hash Functions for GPU Rendering", `pcg`), in u32
4
+ * arithmetic only, so the WGSL (`vdbRefRng*` in `core/reference/wgsl.ts`) and this file produce the same bits.
5
+ * Floats take the top 24 bits (`x >>> 8` × 2⁻²⁴): exact in f32, in [0, 1).
6
+ *
7
+ * Seeding: one stream per (seed, sample index, pixel): `state = pcg(pixel + pcg(seed ^ pcg(sampleIndex)))`.
8
+ */
9
+ /** The PCG hash of a u32 (`pcg` of Jarzynski & Olano 2020). */
10
+ export declare function vdbRefPcg(v: number): number;
11
+ /** A random stream; `next()` returns a float in [0, 1) with 24 random bits (exact in f32). */
12
+ export interface VDBRefRng {
13
+ /** The LCG state (u32). */
14
+ state: number;
15
+ /** Draws so far (for tests). */
16
+ draws: number;
17
+ next(): number;
18
+ }
19
+ /** The stream of pixel `pixel` (row-major index), sample `sampleIndex` (batch × spp + s) and `seed`. */
20
+ export declare function vdbRefRng(seed: number, sampleIndex: number, pixel: number): VDBRefRng;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * K6.R: the random numbers the reference renderer's GPU kernel and its CPU twin share. A 32-bit LCG with the
3
+ * PCG-RXS-M-XS output permutation (Jarzynski & Olano 2020, "Hash Functions for GPU Rendering", `pcg`), in u32
4
+ * arithmetic only, so the WGSL (`vdbRefRng*` in `core/reference/wgsl.ts`) and this file produce the same bits.
5
+ * Floats take the top 24 bits (`x >>> 8` × 2⁻²⁴): exact in f32, in [0, 1).
6
+ *
7
+ * Seeding: one stream per (seed, sample index, pixel): `state = pcg(pixel + pcg(seed ^ pcg(sampleIndex)))`.
8
+ */
9
+ /** The PCG hash of a u32 (`pcg` of Jarzynski & Olano 2020). */
10
+ export function vdbRefPcg(v) {
11
+ const s = (Math.imul(v >>> 0, 747796405) + 2891336453) >>> 0;
12
+ const w = Math.imul(((s >>> ((s >>> 28) + 4)) ^ s) >>> 0, 277803737) >>> 0;
13
+ return ((w >>> 22) ^ w) >>> 0;
14
+ }
15
+ /** The stream of pixel `pixel` (row-major index), sample `sampleIndex` (batch × spp + s) and `seed`. */
16
+ export function vdbRefRng(seed, sampleIndex, pixel) {
17
+ const rng = {
18
+ state: vdbRefPcg((pixel + vdbRefPcg((seed ^ vdbRefPcg(sampleIndex >>> 0)) >>> 0)) >>> 0),
19
+ draws: 0,
20
+ next() {
21
+ this.state = (Math.imul(this.state, 747796405) + 2891336453) >>> 0;
22
+ const s = this.state;
23
+ const w = Math.imul(((s >>> ((s >>> 28) + 4)) ^ s) >>> 0, 277803737) >>> 0;
24
+ this.draws++;
25
+ return (((w >>> 22) ^ w) >>> 8) * 5.9604644775390625e-8;
26
+ },
27
+ };
28
+ return rng;
29
+ }
30
+ //# sourceMappingURL=rng.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rng.js","sourceRoot":"","sources":["../../../src/tools/reference/rng.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,+DAA+D;AAC/D,MAAM,UAAU,SAAS,CAAC,CAAS;IACjC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAC7D,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IAC3E,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAWD,wGAAwG;AACxG,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,WAAmB,EAAE,KAAa;IACxE,MAAM,GAAG,GAAc;QACrB,KAAK,EAAE,SAAS,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,IAAI,GAAG,SAAS,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACxF,KAAK,EAAE,CAAC;QACR,IAAI;YACF,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;YACnE,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;YACrB,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;YAC3E,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,qBAAqB,CAAC;QAC1D,CAAC;KACF,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * K6.R: the random numbers the reference renderer's GPU kernel and its CPU twin share. A 32-bit LCG with the\n * PCG-RXS-M-XS output permutation (Jarzynski & Olano 2020, \"Hash Functions for GPU Rendering\", `pcg`), in u32\n * arithmetic only, so the WGSL (`vdbRefRng*` in `core/reference/wgsl.ts`) and this file produce the same bits.\n * Floats take the top 24 bits (`x >>> 8` × 2⁻²⁴): exact in f32, in [0, 1).\n *\n * Seeding: one stream per (seed, sample index, pixel): `state = pcg(pixel + pcg(seed ^ pcg(sampleIndex)))`.\n */\n\n/** The PCG hash of a u32 (`pcg` of Jarzynski & Olano 2020). */\nexport function vdbRefPcg(v: number): number {\n const s = (Math.imul(v >>> 0, 747796405) + 2891336453) >>> 0;\n const w = Math.imul(((s >>> ((s >>> 28) + 4)) ^ s) >>> 0, 277803737) >>> 0;\n return ((w >>> 22) ^ w) >>> 0;\n}\n\n/** A random stream; `next()` returns a float in [0, 1) with 24 random bits (exact in f32). */\nexport interface VDBRefRng {\n /** The LCG state (u32). */\n state: number;\n /** Draws so far (for tests). */\n draws: number;\n next(): number;\n}\n\n/** The stream of pixel `pixel` (row-major index), sample `sampleIndex` (batch × spp + s) and `seed`. */\nexport function vdbRefRng(seed: number, sampleIndex: number, pixel: number): VDBRefRng {\n const rng: VDBRefRng = {\n state: vdbRefPcg((pixel + vdbRefPcg((seed ^ vdbRefPcg(sampleIndex >>> 0)) >>> 0)) >>> 0),\n draws: 0,\n next() {\n this.state = (Math.imul(this.state, 747796405) + 2891336453) >>> 0;\n const s = this.state;\n const w = Math.imul(((s >>> ((s >>> 28) + 4)) ^ s) >>> 0, 277803737) >>> 0;\n this.draws++;\n return (((w >>> 22) ^ w) >>> 8) * 5.9604644775390625e-8;\n },\n };\n return rng;\n}\n"]}