@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,728 @@
1
+ // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
2
+ // src/three-openvdb/frame/webgpu/frameShaderChunks.js L94–107 (frameSliceDepth, frameGetViewPosition),
3
+ // L109–127 (frameGetFroxel), L129–142 (frameDistanceFade), L157–185 (getFroxelLod, getBoxSteps,
4
+ // frameNoise), L187–203 (frameHenyeyGreenstein, frameHenyeyGreensteinColor), L273–315 (framePhaseWeight,
5
+ // framePhaseColor), L330–373 (frameShadowAbsorption, frameShadowStep, frameShadowDepth,
6
+ // frameShadowTransmittance), L403–414 (frameIsotropicDiffusion), L938–958 (boxExit, boxSegment);
7
+ // three.js r187 getShIrradianceAt (MIT).
8
+ // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
9
+ // Changes: TSL → WGSL for the core compute kernels (K6.1); the froxel of a 3D texel replaces the atlas
10
+ // pixel (the noise keeps his virtual atlas coordinate); K6.3: the Lorenz-Mie table reads (frameMieTexel, L206–271), octaves
11
+ // (L316–399: frameShadowMarchDepth, frameOctaveLight, frameShadowTotal, frameShadowedLight) and frameTwoSidedDiffusion
12
+ // (L416–451); K6.4: the spectral chunks (L483–622: frameMeanComponent, frameSpectralShadowUnit / Step / Depth /
13
+ // Transmittance, frameSpectralGridAlbedo, frameSpectralOctaveLight / ShadowTotal / ShadowedLight). CPU twins: tools/frame
14
+ // (index.ts, froxel.ts, mie.ts, spectral.ts). Divergences:
15
+ // DIVERGES.md (K3.1, K6.1 rows).
16
+ import { vdbFrameMieAsymmetry, vdbFrameMieRgbMode, vdbFrameMieTableSize } from "../../../tools/frame/mie.js";
17
+ import { vdbFrameMaxScatteringOctaves } from "../../../tools/frame/index.js";
18
+ /**
19
+ * `frameChunksWgsl(roots)`: the source-free `vdbFrame*` WGSL functions the frame kernels share, emitted
20
+ * as the dependency closure of `roots` in one fixed order (same roots, same bytes). They read the group-0
21
+ * uniforms `vdbFrame` / `vdbFrameLights` (`vdbFrameUniformsWgsl`).
22
+ */
23
+ /** Lorenz-Mie table texels (his `frameMieTableSize`), its asymmetry and the 'lorenz-mie-rgb' mode (tools/frame/mie.ts). */
24
+ const MIE_SIZE = vdbFrameMieTableSize;
25
+ const MIE_ASYMMETRY = vdbFrameMieAsymmetry;
26
+ const MIE_RGB_MODE = vdbFrameMieRgbMode;
27
+ const MAX_OCTAVES = vdbFrameMaxScatteringOctaves;
28
+ /** The chunks in emission order (a chunk's deps come before it). */
29
+ const CHUNKS = [
30
+ [
31
+ "constants",
32
+ {
33
+ deps: [],
34
+ code: `const VDB_FRAME_PI: f32 = 3.141592653589793;
35
+ const VDB_FRAME_FADE_END: f32 = 0.018315638888734179; // exp(-4)
36
+ const VDB_FRAME_LIGHT_AMBIENT: u32 = 32u;
37
+ const VDB_FRAME_LIGHT_POINT: u32 = 16u;
38
+ const VDB_FRAME_LIGHT_DIRECTIONAL: u32 = 8u;
39
+ const VDB_FRAME_LIGHT_SPOT: u32 = 4u;
40
+ const VDB_FRAME_LIGHT_HEMISPHERE: u32 = 2u;
41
+ const VDB_FRAME_LIGHT_ENVIRONMENT: u32 = 1u;
42
+ `,
43
+ },
44
+ ],
45
+ [
46
+ "mat3",
47
+ {
48
+ deps: [],
49
+ code: `fn vdbFrameMat3(m: mat4x4f) -> mat3x3f {
50
+ return mat3x3f(m[0].xyz, m[1].xyz, m[2].xyz);
51
+ }
52
+ `,
53
+ },
54
+ ],
55
+ [
56
+ "sliceDepth",
57
+ {
58
+ deps: [],
59
+ code: `// frameSliceDepth: view depth at the slice fraction t of the log range
60
+ fn vdbFrameSliceDepth(t: f32) -> f32 {
61
+ return vdbFrame.range.x * pow(vdbFrame.range.y / vdbFrame.range.x, t);
62
+ }
63
+ `,
64
+ },
65
+ ],
66
+ [
67
+ "viewPosition",
68
+ {
69
+ deps: [],
70
+ code: `// frameGetViewPosition: two points on the pixel ray (NDC depth 0 and 1), the one at viewDepth
71
+ fn vdbFrameViewPosition(uv: vec2f, viewDepth: f32) -> vec3f {
72
+ let ndc = uv * 2.0 - 1.0;
73
+ let nearPoint = vdbFrame.projectionInverse * vec4f(ndc, 0.0, 1.0);
74
+ let farPoint = vdbFrame.projectionInverse * vec4f(ndc, 1.0, 1.0);
75
+ let near = nearPoint.xyz / nearPoint.w;
76
+ let far = farPoint.xyz / farPoint.w;
77
+ let t = (viewDepth + near.z) / (near.z - far.z);
78
+ return mix(near, far, vec3f(t));
79
+ }
80
+ `,
81
+ },
82
+ ],
83
+ [
84
+ "froxel",
85
+ {
86
+ deps: ["sliceDepth", "viewPosition"],
87
+ code: `// frameGetFroxel for the 3D texel cell; fragCoord is his atlas pixel (the noise reads it)
88
+ struct VdbFrameFroxel {
89
+ fragCoord: vec2f,
90
+ uv: vec2f,
91
+ sliceNear: f32,
92
+ sliceFar: f32,
93
+ viewNear: vec3f,
94
+ viewFar: vec3f,
95
+ };
96
+ fn vdbFrameFroxelAt(cell: vec3u) -> VdbFrameFroxel {
97
+ let grid = vdbFrame.grid;
98
+ let slice = f32(cell.z);
99
+ let row = floor(slice / grid.w);
100
+ let tile = vec2f(slice - grid.w * row, row);
101
+ let xy = vec2f(cell.xy) + 0.5;
102
+ var f: VdbFrameFroxel;
103
+ f.fragCoord = tile * grid.xy + xy;
104
+ f.uv = (f.fragCoord - tile * grid.xy) / grid.xy;
105
+ f.sliceNear = vdbFrameSliceDepth(slice / grid.z);
106
+ f.sliceFar = vdbFrameSliceDepth((slice + 1.0) / grid.z);
107
+ f.viewNear = vdbFrameViewPosition(f.uv, f.sliceNear);
108
+ f.viewFar = vdbFrameViewPosition(f.uv, f.sliceFar);
109
+ return f;
110
+ }
111
+ `,
112
+ },
113
+ ],
114
+ [
115
+ "noise",
116
+ {
117
+ deps: [],
118
+ code: `// frameNoise: interleaved gradient noise (Jimenez 2014); 0.5 when jitter is off (negative)
119
+ fn vdbFrameNoise(jitter: f32, pixel: vec2f) -> f32 {
120
+ let noise = fract(52.9829189 * fract(dot(pixel, vec2f(0.06711056, 0.00583715))));
121
+ return select(fract(noise + jitter), 0.5, jitter < 0.0);
122
+ }
123
+ `,
124
+ },
125
+ ],
126
+ [
127
+ "rand",
128
+ {
129
+ deps: [],
130
+ code: `// Issue #2 step 2: pcg3d (Jarzynski & Olano 2020)
131
+ fn vdbFramePcg3d(v0: vec3u) -> vec3u {
132
+ var v = v0 * 1664525u + 1013904223u;
133
+ v.x += v.y * v.z;
134
+ v.y += v.z * v.x;
135
+ v.z += v.x * v.y;
136
+ v = v ^ (v >> vec3u(16u));
137
+ v.x += v.y * v.z;
138
+ v.y += v.z * v.x;
139
+ v.z += v.x * v.y;
140
+ return v;
141
+ }
142
+ // the stochastic density filter's three uniforms of one lookup: the froxel's atlas pixel, a key ((volume << 16) | step)
143
+ // and the frame seed (flags.w); 24-bit values (exact in f32)
144
+ fn vdbFrameRand3(pixel: vec2f, key: u32) -> vec3f {
145
+ let seed = vdbFramePcg3d(vec3u(vdbFrame.flags.w, 0x9e3779b9u, 0x7f4a7c15u)).x;
146
+ let h = vdbFramePcg3d(vec3u(vec2u(pixel), key ^ seed));
147
+ return vec3f(h >> vec3u(8u)) * (1.0 / 16777216.0);
148
+ }
149
+ `,
150
+ },
151
+ ],
152
+ [
153
+ "fade",
154
+ {
155
+ deps: ["constants"],
156
+ code: `// frameDistanceFade: 1 at the camera, 0 at the fade radius; radius 0: no fade
157
+ fn vdbFrameDistanceFade(viewPosition: vec3f) -> f32 {
158
+ let radius = vdbFrame.jitterFade.y;
159
+ if (radius <= 0.0) {
160
+ return 1.0;
161
+ }
162
+ let x = clamp(length(viewPosition) / radius, 0.0, 1.0);
163
+ return (exp(x * x * -4.0) - VDB_FRAME_FADE_END) / (1.0 - VDB_FRAME_FADE_END);
164
+ }
165
+ `,
166
+ },
167
+ ],
168
+ [
169
+ "box",
170
+ {
171
+ deps: [],
172
+ code: `// boxExit / boxSegment of the local unit box [-0.5, 0.5]^3
173
+ fn vdbFrameBoxExit(origin: vec3f, direction: vec3f) -> f32 {
174
+ let inverseDirection = vec3f(1.0) / direction;
175
+ let tMin = (vec3f(-0.5) - origin) * inverseDirection;
176
+ let tMax = (vec3f(0.5) - origin) * inverseDirection;
177
+ let far = max(tMin, tMax);
178
+ return max(0.0, min(far.x, min(far.y, far.z)));
179
+ }
180
+ fn vdbFrameBoxSegment(start: vec3f, end: vec3f) -> vec2f {
181
+ let inverseDirection = vec3f(1.0) / (end - start);
182
+ let tMin = (vec3f(-0.5) - start) * inverseDirection;
183
+ let tMax = (vec3f(0.5) - start) * inverseDirection;
184
+ let near = min(tMin, tMax);
185
+ let far = max(tMin, tMax);
186
+ return vec2f(max(0.0, max(near.x, max(near.y, near.z))), min(1.0, min(far.x, min(far.y, far.z))));
187
+ }
188
+ `,
189
+ },
190
+ ],
191
+ [
192
+ "lod",
193
+ {
194
+ deps: ["viewPosition"],
195
+ code: `// getLod: the level of a footprint of localSize (unit-box units)
196
+ fn vdbFrameLod(localSize: f32, maxTexels: f32) -> f32 {
197
+ return max(0.0, log2(localSize * maxTexels));
198
+ }
199
+ // getFroxelLod: the level of the froxel width at the slice middle or the sub-step, the larger
200
+ fn vdbFrameFroxelLod(f: VdbFrameFroxel, subStepLength: f32, worldScale: f32, maxTexels: f32) -> f32 {
201
+ let sliceMiddle = (f.sliceNear + f.sliceFar) * 0.5;
202
+ let neighborUv = f.uv + vec2f(1.0 / vdbFrame.grid.x, 0.0);
203
+ let froxelWidth = length(vdbFrameViewPosition(neighborUv, sliceMiddle) - vdbFrameViewPosition(f.uv, sliceMiddle));
204
+ return vdbFrameLod(max(froxelWidth, subStepLength) / worldScale, maxTexels);
205
+ }
206
+ // getBoxSteps: two sub-steps per voxel of the read level across the in-box part, at most subSteps
207
+ fn vdbFrameBoxSteps(localNear: vec3f, localFar: vec3f, segment: f32, sampledLod: f32, maxTexels: f32) -> u32 {
208
+ let boxLength = length(localFar - localNear) * segment;
209
+ let steps = ceil(exp2(vdbFrameLod(boxLength, maxTexels) - sampledLod) * 2.0);
210
+ return u32(clamp(steps, 1.0, f32(vdbFrame.flags.x)));
211
+ }
212
+ `,
213
+ },
214
+ ],
215
+ [
216
+ "phase",
217
+ {
218
+ deps: ["constants"],
219
+ code: `// frameHenyeyGreenstein: HG over the isotropic phase; g = 0 gives 1
220
+ fn vdbFrameHenyeyGreenstein(cosTheta: f32, g: f32) -> f32 {
221
+ let g2 = g * g;
222
+ return (1.0 - g2) / pow(max(1.0 + g2 - 2.0 * g * cosTheta, 1e-4), 1.5);
223
+ }
224
+ fn vdbFrameHenyeyGreensteinColor(cosTheta: f32, g: vec3f) -> vec3f {
225
+ let g2 = g * g;
226
+ return (vec3f(1.0) - g2) / pow(max(vec3f(1.0) + g2 - g * 2.0 * cosTheta, vec3f(1e-4)), vec3f(1.5));
227
+ }
228
+ // K6.3: the Lorenz-Mie tables (V47; rgb 'lorenz-mie-rgb', a 'lorenz-mie'), ${MIE_SIZE} texels at the angle PI u^2, as
229
+ // binary16 in a uniform buffer (two texels per vec4u; no sampled texture), read with a linear blend (his frameMieTexel)
230
+ struct VdbFrameMieTable {
231
+ t: array<vec4u, ${MIE_SIZE / 2}>,
232
+ };
233
+ @group(0) @binding(4) var<uniform> vdbFrameMie: VdbFrameMieTable;
234
+ fn vdbFrameMieLoad(i: i32) -> vec4f {
235
+ let w = vdbFrameMie.t[u32(i) >> 1u];
236
+ let odd = (u32(i) & 1u) == 1u;
237
+ return vec4f(unpack2x16float(select(w.x, w.z, odd)), unpack2x16float(select(w.y, w.w, odd)));
238
+ }
239
+ fn vdbFrameMieTexel(cosTheta: f32) -> vec4f {
240
+ let u = sqrt(acos(clamp(cosTheta, -1.0, 1.0)) * (1.0 / VDB_FRAME_PI));
241
+ let texel = u * ${MIE_SIZE - 1}.0;
242
+ let index = min(i32(texel), ${MIE_SIZE - 2});
243
+ return mix(vdbFrameMieLoad(index), vdbFrameMieLoad(index + 1), vec4f(texel - f32(index)));
244
+ }
245
+ // framePhaseWeight: (forward g, back g, back weight, Lorenz-Mie mode); mode > 0 mixes the 'lorenz-mie' table in
246
+ fn vdbFramePhaseWeight(phase: vec4f, cosTheta: f32) -> f32 {
247
+ let w = mix(vdbFrameHenyeyGreenstein(cosTheta, phase.x), vdbFrameHenyeyGreenstein(cosTheta, phase.y), phase.z);
248
+ if (phase.w > 0.0) {
249
+ return mix(w, vdbFrameMieTexel(cosTheta).w, phase.w);
250
+ }
251
+ return w;
252
+ }
253
+ // framePhaseColor: spectrum (red g scale, blue g scale, flag); flag 0: one phase for all channels; 'lorenz-mie-rgb'
254
+ // (mode 2): its three tables
255
+ fn vdbFramePhaseColor(phase: vec4f, spectrum: vec3f, cosTheta: f32) -> vec3f {
256
+ if (spectrum.z < 0.5) {
257
+ return vec3f(vdbFramePhaseWeight(phase, cosTheta));
258
+ }
259
+ if (phase.w > ${MIE_RGB_MODE - 0.5}) {
260
+ return vdbFrameMieTexel(cosTheta).xyz;
261
+ }
262
+ let scale = vec3f(spectrum.x, 1.0, spectrum.y);
263
+ return mix(
264
+ vdbFrameHenyeyGreensteinColor(cosTheta, clamp(scale * phase.x, vec3f(-0.99), vec3f(0.99))),
265
+ vdbFrameHenyeyGreensteinColor(cosTheta, clamp(scale * phase.y, vec3f(-0.99), vec3f(0.99))),
266
+ vec3f(phase.z),
267
+ );
268
+ }
269
+ // framePhaseWeightScaled: every g x gScale; the Lorenz-Mie modes use HG with the table asymmetry x gScale
270
+ fn vdbFramePhaseWeightScaled(phase: vec4f, cosTheta: f32, gScale: f32) -> f32 {
271
+ let lobes = mix(vdbFrameHenyeyGreenstein(cosTheta, phase.x * gScale), vdbFrameHenyeyGreenstein(cosTheta, phase.y * gScale), phase.z);
272
+ return mix(lobes, vdbFrameHenyeyGreenstein(cosTheta, gScale * ${MIE_ASYMMETRY}), min(phase.w, 1.0));
273
+ }
274
+ `,
275
+ },
276
+ ],
277
+ [
278
+ "ambientPhase",
279
+ {
280
+ deps: [],
281
+ code: `// K6.Q1c (V128): the distant light's phase weight from the pairs' dipole fit (T = a + b.w), from the sums of the up and
282
+ // down totals over the pairs and the dipole sum b.r (r the view ray): each HG lobe's clamp(a + g b.r, 0, 1) (g its mean
283
+ // cosine; spectral: scaled and clamped as vdbFramePhaseColor; the Lorenz-Mie asymmetry for both Mie modes), mixed by the
284
+ // back weight, over a; 1 where a <= 1e-6
285
+ fn vdbFrameAmbientPhaseFactor(sumUp: vec3f, sumDown: vec3f, dipole: vec3f, pairs: u32, phase: vec4f, spectrum: vec3f) -> vec3f {
286
+ let a = (sumUp + sumDown) / f32(2u * pairs);
287
+ var g0 = vec3f(${MIE_ASYMMETRY});
288
+ var g1 = vec3f(${MIE_ASYMMETRY});
289
+ if (phase.w < ${MIE_RGB_MODE - 0.5}) {
290
+ let scale = select(vec3f(1.0), vec3f(spectrum.x, 1.0, spectrum.y), spectrum.z > 0.5);
291
+ let mie = min(phase.w, 1.0);
292
+ g0 = mix(clamp(scale * phase.x, vec3f(-0.99), vec3f(0.99)), g0, mie);
293
+ g1 = mix(clamp(scale * phase.y, vec3f(-0.99), vec3f(0.99)), g1, mie);
294
+ }
295
+ let v = mix(clamp(a + g0 * dipole, vec3f(0.0), vec3f(1.0)), clamp(a + g1 * dipole, vec3f(0.0), vec3f(1.0)), vec3f(phase.z));
296
+ return select(vec3f(1.0), v / max(a, vec3f(1e-6)), a > vec3f(1e-6));
297
+ }
298
+ `,
299
+ },
300
+ ],
301
+ [
302
+ "msExit",
303
+ {
304
+ deps: ["phase"],
305
+ code: `// K7.4c (internal msExit, V229; tools/frame/ms-exit.ts): the exit of a light's scattered part (total - direct). Its mean
306
+ // cosine along the light's travel: the small-angle first moment D^(1 - albedo g) - D over the scattered total, clamped
307
+ // between 0 and g (the first order's); 0 without scattered light
308
+ fn vdbFrameMsExitMean(direct: f32, scattered: f32, albedo: f32, g: f32) -> f32 {
309
+ if (!(scattered > 1e-6) || !(direct > 0.0)) {
310
+ return 0.0;
311
+ }
312
+ let flux = exp(log(direct) * (1.0 - clamp(albedo, 0.0, 1.0) * g)) - direct;
313
+ return clamp(flux / scattered, min(g, 0.0), max(g, 0.0));
314
+ }
315
+ // one lobe's g of each channel (as vdbFrameAmbientPhaseFactor)
316
+ fn vdbFrameMsExitLobe(phase: vec4f, spectrum: vec3f, g: f32) -> vec3f {
317
+ if (phase.w > ${MIE_RGB_MODE - 0.5}) {
318
+ return vec3f(${MIE_ASYMMETRY});
319
+ }
320
+ let scale = select(vec3f(1.0), vec3f(spectrum.x, 1.0, spectrum.y), spectrum.z > 0.5);
321
+ return mix(clamp(scale * g, vec3f(-0.99), vec3f(0.99)), vec3f(${MIE_ASYMMETRY}), vec3f(min(phase.w, 1.0)));
322
+ }
323
+ // the factor on the scattered light of each channel over the isotropic exit: mode 1 'dipole' mix_i max(1 + 3 g_i m cos, 0),
324
+ // mode 2 'hg' mix_i HG(g_i m, cos) (m the mean cosine above, cos the direct term's); K7.4a-2 mode 3 'hg-chroma': the 'hg'
325
+ // factor over its green channel's (the chromatic part only: green, and every channel of a grey medium, exit as his)
326
+ fn vdbFrameMsExit(mode: f32, phase: vec4f, spectrum: vec3f, cosTheta: f32, direct: vec3f, scattered: vec3f, albedo: vec3f) -> vec3f {
327
+ let g0 = vdbFrameMsExitLobe(phase, spectrum, phase.x);
328
+ let g1 = vdbFrameMsExitLobe(phase, spectrum, phase.y);
329
+ let gMean = mix(g0, g1, vec3f(phase.z));
330
+ let m = vec3f(
331
+ vdbFrameMsExitMean(direct.x, scattered.x, albedo.x, gMean.x),
332
+ vdbFrameMsExitMean(direct.y, scattered.y, albedo.y, gMean.y),
333
+ vdbFrameMsExitMean(direct.z, scattered.z, albedo.z, gMean.z),
334
+ );
335
+ if (mode < 1.5) {
336
+ let k = m * (3.0 * cosTheta);
337
+ return mix(max(vec3f(1.0) + g0 * k, vec3f(0.0)), max(vec3f(1.0) + g1 * k, vec3f(0.0)), vec3f(phase.z));
338
+ }
339
+ let hg = mix(vdbFrameHenyeyGreensteinColor(cosTheta, g0 * m), vdbFrameHenyeyGreensteinColor(cosTheta, g1 * m), vec3f(phase.z));
340
+ if (mode > 2.5) {
341
+ return hg / max(hg.y, 1e-6);
342
+ }
343
+ return hg;
344
+ }
345
+ `,
346
+ },
347
+ ],
348
+ [
349
+ "shadow",
350
+ {
351
+ deps: [],
352
+ code: `// frameShadowAbsorption: the extinction the albedo (Rec. 709 luminance) does not scatter
353
+ fn vdbFrameShadowAbsorption(extinction: f32, albedo: vec3f) -> f32 {
354
+ return extinction * (1.0 - clamp(dot(albedo, vec3f(0.2126, 0.7152, 0.0722)), 0.0, 1.0));
355
+ }
356
+ // frameShadowStep: (extinction, effective extinction, reduced scattering) per unit of length
357
+ fn vdbFrameShadowStep(extinction: f32, absorption: f32, multipleScattering: f32) -> vec3f {
358
+ let absorbed = min(absorption, extinction);
359
+ let reducedScattering = (extinction - absorbed) * multipleScattering;
360
+ return vec3f(extinction, sqrt(absorbed * 3.0 * (absorbed + reducedScattering)), reducedScattering);
361
+ }
362
+ // frameShadowDepth: -log of the total transmittance (1D diffusion when multipleScattering > 0)
363
+ fn vdbFrameShadowDepth(depths: vec3f, multipleScattering: f32) -> f32 {
364
+ return select(depths.x, min(depths.x, depths.y + log(depths.z * 0.75 + 1.0)), multipleScattering > 0.0);
365
+ }
366
+ // K6.3 frameShadowMarchDepth: the depth that stops a march; octaves (count, a, b, c): the last octave's sigma a^N depth
367
+ fn vdbFrameShadowMarchDepth(depths: vec3f, multipleScattering: f32, octaves: vec4f) -> f32 {
368
+ if (octaves.x > 0.0) {
369
+ return depths.x * pow(octaves.y, octaves.x);
370
+ }
371
+ return vdbFrameShadowDepth(depths, multipleScattering);
372
+ }
373
+ // frameShadowTransmittance: (direct, total); octaves: total holds 1 / (1 + optical depth) (K6.3)
374
+ fn vdbFrameShadowTransmittance(depths: vec3f, multipleScattering: f32, octaves: vec4f) -> vec2f {
375
+ if (octaves.x > 0.0) {
376
+ return vec2f(exp(-depths.x), 1.0 / (depths.x + 1.0));
377
+ }
378
+ return vec2f(exp(-depths.x), exp(-vdbFrameShadowDepth(depths, multipleScattering)));
379
+ }
380
+ // frameIsotropicDiffusion: two-sided slab total of isotropic light (white furnace), z0 = 2/3
381
+ fn vdbFrameIsotropicDiffusion(frontReduced: f32, backReduced: f32, frontEffective: f32) -> f32 {
382
+ return (backReduced + 2.0 / 3.0) * 2.0 / (frontReduced + backReduced + 4.0 / 3.0) * exp(-frontEffective);
383
+ }
384
+ // K6.3 frameTwoSidedDiffusion ('two-sided'): 1D slab diffusion with a collimated source between the light side (front
385
+ // reduced depth f) and the far side (back b), the lowest side mode k^2 = 2 (PI / (f + b + 2 z0))^2, Robin boundaries
386
+ // z0 = 2/3; the diffuse plus the reduced beam exp(-f), times exp(-effective front), never below the direct light
387
+ fn vdbFrameTwoSidedDiffusion(direct: f32, frontReduced: f32, frontEffective: f32, backReduced: f32) -> f32 {
388
+ let z0 = 2.0 / 3.0;
389
+ let slab = frontReduced + backReduced;
390
+ let k0 = 4.442882938158366 / (slab + 2.0 * z0);
391
+ let k = k0 + (1.0 - step(0.01, abs(1.0 - k0 * k0))) * 0.01;
392
+ let p = -3.0 / (1.0 - k * k);
393
+ let kl = k * slab;
394
+ let coshKl = (exp(kl) + exp(-kl)) * 0.5;
395
+ let sinhKl = (exp(kl) - exp(-kl)) * 0.5;
396
+ let c12 = k * -z0;
397
+ let r1 = p * -(1.0 + z0);
398
+ let c21 = coshKl + k * z0 * sinhKl;
399
+ let c22 = sinhKl + k * z0 * coshKl;
400
+ let r2 = -p * exp(-slab) * (1.0 - z0);
401
+ let det = c22 - c12 * c21;
402
+ let c = (r1 * c22 - c12 * r2) / det;
403
+ let d = (r2 - c21 * r1) / det;
404
+ let kf = k * frontReduced;
405
+ let beam = exp(-frontReduced);
406
+ let diffuse = p * beam + c * (exp(kf) + exp(-kf)) * 0.5 + d * (exp(kf) - exp(-kf)) * 0.5;
407
+ return max(direct, (diffuse + beam) * exp(-frontEffective));
408
+ }
409
+ `,
410
+ },
411
+ ],
412
+ [
413
+ "octaveTotal",
414
+ {
415
+ deps: ["shadow"],
416
+ code: `// K6.3 multipleScattering 'octaves' (count N, extinction a, contribution b, phase c), isotropic light
417
+ // frameShadowOpticalDepth: the optical depth back from the octave shadow value 1 / (1 + depth)
418
+ fn vdbFrameShadowOpticalDepth(shadowY: f32) -> f32 {
419
+ return max(1.0 / max(shadowY, 1e-6) - 1.0, 0.0);
420
+ }
421
+ // frameOctaveLight of isotropic light: sum over n = 1..N of b^n exp(-a^n depth)
422
+ fn vdbFrameOctaveSum(octaves: vec4f, opticalDepth: f32) -> f32 {
423
+ var light = 0.0;
424
+ var extinctionScale = 1.0;
425
+ var contribution = 1.0;
426
+ for (var i = 0u; i < ${MAX_OCTAVES}u; i++) {
427
+ if (f32(i + 1u) > octaves.x) {
428
+ break;
429
+ }
430
+ extinctionScale *= octaves.y;
431
+ contribution *= octaves.z;
432
+ light += contribution * exp(-opticalDepth * extinctionScale);
433
+ }
434
+ return light;
435
+ }
436
+ // frameShadowTotal: total transmittance of isotropic light from the y shadow value; octaves: exp(-depth) + the octaves
437
+ fn vdbFrameShadowTotal(shadowY: f32, octaves: vec4f) -> f32 {
438
+ if (octaves.x > 0.0) {
439
+ let depth = vdbFrameShadowOpticalDepth(shadowY);
440
+ return exp(-depth) + vdbFrameOctaveSum(octaves, depth);
441
+ }
442
+ return shadowY;
443
+ }
444
+ `,
445
+ },
446
+ ],
447
+ [
448
+ "octaves",
449
+ {
450
+ deps: ["phase", "octaveTotal"],
451
+ code: `// frameOctaveLight: sum over n = 1..N of b^n phase(g c^n) exp(-a^n depth)
452
+ fn vdbFrameOctaveLight(octaves: vec4f, opticalDepth: f32, phase: vec4f, cosTheta: f32) -> f32 {
453
+ var light = 0.0;
454
+ var extinctionScale = 1.0;
455
+ var contribution = 1.0;
456
+ var gScale = 1.0;
457
+ for (var i = 0u; i < ${MAX_OCTAVES}u; i++) {
458
+ if (f32(i + 1u) > octaves.x) {
459
+ break;
460
+ }
461
+ extinctionScale *= octaves.y;
462
+ contribution *= octaves.z;
463
+ gScale *= octaves.w;
464
+ light += contribution * vdbFramePhaseWeightScaled(phase, cosTheta, gScale) * exp(-opticalDepth * extinctionScale);
465
+ }
466
+ return light;
467
+ }
468
+ // frameShadowedLight of each channel: phase x direct + the scattered light (total - direct, isotropic), or with
469
+ // octaves their phased sum from the octave shadow value
470
+ fn vdbFrameShadowedLight(phase: vec4f, spectrum: vec3f, octaves: vec4f, cosTheta: f32, shadow: vec2f) -> vec3f {
471
+ let direct = vdbFramePhaseColor(phase, spectrum, cosTheta) * shadow.x;
472
+ if (octaves.x > 0.0) {
473
+ return direct + vec3f(vdbFrameOctaveLight(octaves, vdbFrameShadowOpticalDepth(shadow.y), phase, cosTheta));
474
+ }
475
+ return direct + vec3f(shadow.y - shadow.x);
476
+ }
477
+ `,
478
+ },
479
+ ],
480
+ [
481
+ "spectral",
482
+ {
483
+ deps: ["shadow", "octaveTotal", "phase"],
484
+ code: `// K6.4 spectral media (his frameShaderChunks L483–622): values of each channel (red, green, blue). Depths are
485
+ // (x extinction, y effective extinction, z reduced scattering) of each channel; shadows (x direct, y total).
486
+ struct VdbFrameSpectralDepths {
487
+ x: vec3f,
488
+ y: vec3f,
489
+ z: vec3f,
490
+ };
491
+ struct VdbFrameSpectralShadow {
492
+ x: vec3f,
493
+ y: vec3f,
494
+ };
495
+ // A spectral march: direct, total, reduced depth, effective depth of each channel
496
+ struct VdbFrameSpectralMarch {
497
+ x: vec3f,
498
+ y: vec3f,
499
+ z: vec3f,
500
+ w: vec3f,
501
+ };
502
+ fn vdbFrameMeanComponent(v: vec3f) -> f32 {
503
+ return dot(v, vec3f(1.0 / 3.0));
504
+ }
505
+ fn vdbFrameMinComponent(v: vec3f) -> f32 {
506
+ return min(v.x, min(v.y, v.z));
507
+ }
508
+ fn vdbFrameMaxComponent(v: vec3f) -> f32 {
509
+ return max(v.x, max(v.y, v.z));
510
+ }
511
+ fn vdbFrameSpectralUnmarched() -> VdbFrameSpectralMarch {
512
+ return VdbFrameSpectralMarch(vec3f(1.0), vec3f(1.0), vec3f(0.0), vec3f(0.0));
513
+ }
514
+ // frameSpectralShadowUnit: the depths of one unit of extinction for a volume's spectrum and albedo
515
+ fn vdbFrameSpectralShadowUnit(spectrum: vec3f, albedo: vec3f, multipleScattering: f32) -> VdbFrameSpectralDepths {
516
+ let absorbed = spectrum * (vec3f(1.0) - clamp(albedo, vec3f(0.0), vec3f(1.0)));
517
+ let reduced = (spectrum - absorbed) * multipleScattering;
518
+ return VdbFrameSpectralDepths(spectrum, sqrt(absorbed * 3.0 * (absorbed + reduced)), reduced);
519
+ }
520
+ // frameSpectralShadowStep: the step depths of each channel from the grid's (extinction, absorption) of each channel
521
+ fn vdbFrameSpectralShadowStep(extinction: vec3f, absorption: vec3f, multipleScattering: f32) -> VdbFrameSpectralDepths {
522
+ let absorbed = min(absorption, extinction);
523
+ let reduced = (extinction - absorbed) * multipleScattering;
524
+ return VdbFrameSpectralDepths(extinction, sqrt(absorbed * 3.0 * (absorbed + reduced)), reduced);
525
+ }
526
+ // frameSpectralGridAlbedo: 1 - absorption / extinction of each channel, 1 with no extinction
527
+ fn vdbFrameSpectralGridAlbedo(extinction: vec3f, absorption: vec3f) -> vec3f {
528
+ if (!(vdbFrameMaxComponent(extinction) > 0.0)) {
529
+ return vec3f(1.0);
530
+ }
531
+ return clamp(vec3f(1.0) - absorption / max(extinction, vec3f(1e-8)), vec3f(0.0), vec3f(1.0));
532
+ }
533
+ // frameShadowDepth of each channel
534
+ fn vdbFrameSpectralShadowDepth(d: VdbFrameSpectralDepths, multipleScattering: f32) -> vec3f {
535
+ return select(d.x, min(d.x, d.y + log(d.z * 0.75 + vec3f(1.0))), multipleScattering > 0.0);
536
+ }
537
+ // frameShadowMarchDepth of each channel (a march stops when the smallest is past its limit)
538
+ fn vdbFrameSpectralShadowMarchDepth(d: VdbFrameSpectralDepths, multipleScattering: f32, octaves: vec4f) -> vec3f {
539
+ if (octaves.x > 0.0) {
540
+ return d.x * pow(octaves.y, octaves.x);
541
+ }
542
+ return vdbFrameSpectralShadowDepth(d, multipleScattering);
543
+ }
544
+ // frameSpectralShadowTransmittance: (direct, total) of each channel; octaves: total is 1 / (1 + depth)
545
+ fn vdbFrameSpectralShadowTransmittance(d: VdbFrameSpectralDepths, multipleScattering: f32, octaves: vec4f) -> VdbFrameSpectralShadow {
546
+ if (octaves.x > 0.0) {
547
+ return VdbFrameSpectralShadow(exp(-d.x), vec3f(1.0) / (d.x + vec3f(1.0)));
548
+ }
549
+ return VdbFrameSpectralShadow(exp(-d.x), exp(-vdbFrameSpectralShadowDepth(d, multipleScattering)));
550
+ }
551
+ // frameIsotropicDiffusion of each channel
552
+ fn vdbFrameIsotropicDiffusion3(frontReduced: vec3f, backReduced: vec3f, frontEffective: vec3f) -> vec3f {
553
+ return (backReduced + vec3f(2.0 / 3.0)) * 2.0 / (frontReduced + backReduced + vec3f(4.0 / 3.0)) * exp(-frontEffective);
554
+ }
555
+ // frameTwoSidedDiffusion of each channel
556
+ fn vdbFrameTwoSidedDiffusion3(direct: vec3f, frontReduced: vec3f, frontEffective: vec3f, backReduced: vec3f) -> vec3f {
557
+ return vec3f(
558
+ vdbFrameTwoSidedDiffusion(direct.x, frontReduced.x, frontEffective.x, backReduced.x),
559
+ vdbFrameTwoSidedDiffusion(direct.y, frontReduced.y, frontEffective.y, backReduced.y),
560
+ vdbFrameTwoSidedDiffusion(direct.z, frontReduced.z, frontEffective.z, backReduced.z),
561
+ );
562
+ }
563
+ // frameSpectralOctaveLight: sum over n = 1..N of albedo^n b^n phase(g c^n) exp(-a^n depth) of each channel (each octave
564
+ // is one more scattering); phased false: isotropic (phase 1)
565
+ fn vdbFrameSpectralOctaveLight(octaves: vec4f, opticalDepth: vec3f, albedo: vec3f, phase: vec4f, cosTheta: f32, phased: bool) -> vec3f {
566
+ var light = vec3f(0.0);
567
+ var extinctionScale = 1.0;
568
+ var contribution = 1.0;
569
+ var gScale = 1.0;
570
+ var albedoScale = vec3f(1.0);
571
+ let octaveAlbedo = clamp(albedo, vec3f(0.0), vec3f(1.0));
572
+ for (var i = 0u; i < ${MAX_OCTAVES}u; i++) {
573
+ if (f32(i + 1u) > octaves.x) {
574
+ break;
575
+ }
576
+ extinctionScale *= octaves.y;
577
+ contribution *= octaves.z;
578
+ gScale *= octaves.w;
579
+ albedoScale *= octaveAlbedo;
580
+ let p = select(1.0, vdbFramePhaseWeightScaled(phase, cosTheta, gScale), phased);
581
+ light += albedoScale * (contribution * p) * exp(-opticalDepth * extinctionScale);
582
+ }
583
+ return light;
584
+ }
585
+ // frameSpectralShadowTotal: total transmittance of isotropic light of each channel from the y shadow values
586
+ fn vdbFrameSpectralShadowTotal(shadowY: vec3f, octaves: vec4f, albedo: vec3f) -> vec3f {
587
+ if (octaves.x > 0.0) {
588
+ let depth = max(vec3f(1.0) / max(shadowY, vec3f(1e-6)) - vec3f(1.0), vec3f(0.0));
589
+ return exp(-depth) + vdbFrameSpectralOctaveLight(octaves, depth, albedo, vec4f(0.0), 0.0, false);
590
+ }
591
+ return shadowY;
592
+ }
593
+ // frameSpectralShadowedLight: phase x direct + scattered of each channel (octaves: the spectral octave light)
594
+ fn vdbFrameSpectralShadowedLight(phase: vec4f, spectrum: vec3f, octaves: vec4f, cosTheta: f32, shadow: VdbFrameSpectralShadow, albedo: vec3f) -> vec3f {
595
+ let direct = vdbFramePhaseColor(phase, spectrum, cosTheta) * shadow.x;
596
+ if (octaves.x > 0.0) {
597
+ let depth = max(vec3f(1.0) / max(shadow.y, vec3f(1e-6)) - vec3f(1.0), vec3f(0.0));
598
+ return direct + vdbFrameSpectralOctaveLight(octaves, depth, albedo, phase, cosTheta, true);
599
+ }
600
+ return direct + shadow.y - shadow.x;
601
+ }
602
+ `,
603
+ },
604
+ ],
605
+ [
606
+ "sh",
607
+ {
608
+ deps: [],
609
+ code: `// three's getShIrradianceAt: irradiance of the light probe SH9 along a unit normal
610
+ fn vdbFrameShIrradiance(normal: vec3f) -> vec3f {
611
+ let x = normal.x;
612
+ let y = normal.y;
613
+ let z = normal.z;
614
+ var result = vdbFrameLights.probe[0].xyz * 0.886227;
615
+ result += vdbFrameLights.probe[1].xyz * (2.0 * 0.511664) * y;
616
+ result += vdbFrameLights.probe[2].xyz * (2.0 * 0.511664) * z;
617
+ result += vdbFrameLights.probe[3].xyz * (2.0 * 0.511664) * x;
618
+ result += vdbFrameLights.probe[4].xyz * (2.0 * 0.429043) * x * y;
619
+ result += vdbFrameLights.probe[5].xyz * (2.0 * 0.429043) * y * z;
620
+ result += vdbFrameLights.probe[6].xyz * (z * z * 0.743125 - 0.247708);
621
+ result += vdbFrameLights.probe[7].xyz * (2.0 * 0.429043) * x * z;
622
+ result += vdbFrameLights.probe[8].xyz * 0.429043 * (x * x - y * y);
623
+ return result;
624
+ }
625
+ `,
626
+ },
627
+ ],
628
+ [
629
+ "envSh",
630
+ {
631
+ deps: [],
632
+ code: `// K6.2b: irradiance of the environment buffer's SH9 along a unit normal (three's getShIrradianceAt; the
633
+ // Ramamoorthi-Hanrahan cosine convolution), clamped at 0
634
+ fn vdbFrameEnvIrradiance(normal: vec3f) -> vec3f {
635
+ let x = normal.x;
636
+ let y = normal.y;
637
+ let z = normal.z;
638
+ var result = vdbFrameEnv.sh[0].xyz * 0.886227;
639
+ result += vdbFrameEnv.sh[1].xyz * (2.0 * 0.511664) * y;
640
+ result += vdbFrameEnv.sh[2].xyz * (2.0 * 0.511664) * z;
641
+ result += vdbFrameEnv.sh[3].xyz * (2.0 * 0.511664) * x;
642
+ result += vdbFrameEnv.sh[4].xyz * (2.0 * 0.429043) * x * y;
643
+ result += vdbFrameEnv.sh[5].xyz * (2.0 * 0.429043) * y * z;
644
+ result += vdbFrameEnv.sh[6].xyz * (z * z * 0.743125 - 0.247708);
645
+ result += vdbFrameEnv.sh[7].xyz * (2.0 * 0.429043) * x * z;
646
+ result += vdbFrameEnv.sh[8].xyz * 0.429043 * (x * x - y * y);
647
+ return max(result, vec3f(0.0));
648
+ }
649
+ `,
650
+ },
651
+ ],
652
+ [
653
+ "grid",
654
+ {
655
+ deps: [],
656
+ code: `// The world shadow grid (his createGridNodes): gridUvw, insideGrid (half a voxel in), findCascade
657
+ fn vdbFrameGridUvw(cascade: u32, world: vec3f) -> vec3f {
658
+ return (world - vdbFrame.gridMin[cascade].xyz) / vdbFrame.gridSize[cascade].xyz;
659
+ }
660
+ fn vdbFrameInsideGrid(uvw: vec3f) -> bool {
661
+ let inset = 0.5 / vdbFrame.gridLayout.y;
662
+ return min(uvw.x, min(uvw.y, uvw.z)) >= inset && max(uvw.x, max(uvw.y, uvw.z)) <= 1.0 - inset;
663
+ }
664
+ // the finest cascade from first that holds the position, or -1
665
+ fn vdbFrameFindCascade(world: vec3f, first: u32) -> i32 {
666
+ let count = u32(vdbFrame.gridLayout.x);
667
+ for (var c = first; c < count; c++) {
668
+ if (vdbFrameInsideGrid(vdbFrameGridUvw(c, world))) {
669
+ return i32(c);
670
+ }
671
+ }
672
+ return -1;
673
+ }
674
+ // sampleTiles on a stacked 3D texture: hardware trilinear in the R^3 sub-volume at origin, clamped to its
675
+ // half-texel box (his clamp to edge in a slice and between slices)
676
+ fn vdbFrameStackSample(stack: texture_3d<f32>, origin: vec3f, uvw: vec3f) -> vec4f {
677
+ let r = vdbFrame.gridLayout.y;
678
+ let p = origin + clamp(uvw * r, vec3f(0.5), vec3f(r - 0.5));
679
+ return textureSampleLevel(stack, vdbFrameLinear, p / vec3f(textureDimensions(stack)), 0.0);
680
+ }
681
+ // his grid atlas pixel of a voxel (the jitter noise reads it): tile cascade * R + z of an atlas with gridLayout.z columns
682
+ fn vdbFrameGridFragCoord(cascade: u32, cell: vec3u) -> vec2f {
683
+ let r = u32(vdbFrame.gridLayout.y);
684
+ let columns = u32(vdbFrame.gridLayout.z);
685
+ let tile = cascade * r + cell.z;
686
+ return vec2f(f32((tile % columns) * r + cell.x), f32((tile / columns) * r + cell.y)) + 0.5;
687
+ }
688
+ `,
689
+ },
690
+ ],
691
+ [
692
+ "srgb",
693
+ {
694
+ deps: [],
695
+ code: `// three's sRGBTransferOETF / sRGBTransferEOTF
696
+ fn vdbFrameSrgbOetf(color: vec3f) -> vec3f {
697
+ let a = pow(color, vec3f(0.41666)) * 1.055 - 0.055;
698
+ return select(a, color * 12.92, color <= vec3f(0.0031308));
699
+ }
700
+ fn vdbFrameSrgbEotf(color: vec3f) -> vec3f {
701
+ let a = pow(color * 0.9478672986 + 0.0521327014, vec3f(2.4));
702
+ return select(a, color * 0.0773993808, color <= vec3f(0.04045));
703
+ }
704
+ `,
705
+ },
706
+ ],
707
+ ];
708
+ const BY_NAME = new Map(CHUNKS);
709
+ /** The closure of `roots` (with dependencies), in the fixed chunk order. */
710
+ export function frameChunksWgsl(roots) {
711
+ const want = new Set();
712
+ const visit = (name) => {
713
+ if (want.has(name))
714
+ return;
715
+ const chunk = BY_NAME.get(name);
716
+ if (!chunk)
717
+ throw new Error(`frameChunksWgsl: unknown chunk ${name}`);
718
+ want.add(name);
719
+ for (const d of chunk.deps)
720
+ visit(d);
721
+ };
722
+ for (const r of roots)
723
+ visit(r);
724
+ return CHUNKS.filter(([name]) => want.has(name))
725
+ .map(([, c]) => c.code)
726
+ .join("\n");
727
+ }
728
+ //# sourceMappingURL=chunks.js.map