@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
@@ -1,559 +0,0 @@
1
- // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
2
- // src/three-openvdb/frame/webgpu/frameShaderChunks.js L62–203 (frag coord, sample, froxel uniforms
3
- // and maths, distance fade, LOD and sub-steps, IGN noise, Henyey-Greenstein), L273–315
4
- // (framePhaseWeight, framePhaseColor), L330–373 (shadow absorption, step, depth, march depth,
5
- // transmittance), L464–481 (frameShadowedLight), L624–686 (light uniforms), L727–763
6
- // (createVolumeUniforms, the part that is not the source), L1208–1228 (tile uniforms and vertex);
7
- // K3.3: L72–80 (frameLoad, frameFullscreenVertex), L403–414 (frameIsotropicDiffusion), L450–462
8
- // (frameShadowTotal, octaves off), L624–686 (the hemisphere, light-probe, sky and environment light
9
- // uniforms), L1030–1206 (shadow grid uniforms and nodes);
10
- // K3.4: L206–219 and L250–271 (the Lorenz-Mie texture, frameMieTexel, frameMiePhase, frameMieRgbPhase),
11
- // L273–328 (the Mie branches of framePhaseWeight / framePhaseColor, framePhaseWeightScaled), L342–399
12
- // (octave march depth and transmittance, frameShadowOpticalDepth, frameOctaveLight), L416–462
13
- // (frameTwoSidedDiffusion, frameShadowTotal with octaves), L464–481 (frameShadowedLight with octaves);
14
- // K3.5: L483–622 (frameMeanComponent and the spectral chunks: frameSpectralShadowUnit / Depths / Step,
15
- // frameSpectralGridAlbedo, frameSpectralShadowTransmittance, frameSpectralOctaveLight, frameSpectralShadowTotal,
16
- // frameSpectralShadowedLight, frameUnpackSpectralGroup).
17
- // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
18
- // Changes: TypeScript; the source half of createVolumeUniforms/createVolumeNodes is
19
- // `../volume-source.ts`; the Mie table texture is made on first use
20
- // from our generator's tables (tools/frame/mie-table.ts, his numbers). The Shadertoy `blackBody()`
21
- // is not ported (R1 §7, DIVERGES V24). Divergences: DIVERGES.md (K3.1, K3.4 rows), V23–V25.
22
- /**
23
- * Shared TSL of the froxel passes (K3.1, R1 §6 Step 1): the subset his `'volume'` lighting uses.
24
- * CPU twins: `@pmndrs/vdb/tools` `vdbFrame*` (tools/frame). Names follow his file so diffs against
25
- * upstream stay readable.
26
- *
27
- * NOTE Shaders use the bottom-left pixel origin of GLSL (gl_FragCoord). three.js nodes use the
28
- * top-left origin of WebGPU. These helpers convert between them.
29
- */
30
- import * as THREE from "three";
31
- import * as TSL from "three/tsl";
32
- import { vdbMaxComponent, vdbMinComponent } from "../volume-source.js";
33
- import { vdbFrameMieTableSize } from "../../tools/frame/mie.js";
34
- import { frameMaxScatteringOctaves, frameMieAsymmetry, frameMieRgbMode, getFrameMieTexels } from "./phase.js";
35
- // NOTE TSL's r187 typings narrow node types; the ported shader code is written against untyped nodes,
36
- // as volume-source.ts is (VDBTslNode).
37
- const { Break, If, Loop, abs, acos, ceil, clamp, dot, exp, exp2, float, floor, fract, int, instanceIndex, ivec2, length, log, max, min, mix, mod, positionGeometry, pow, screenCoordinate, select, smoothstep, sqrt, step, texture, uniform, uniformArray, vec2, vec3, vec4 } = TSL;
38
- export const minComponent = vdbMinComponent;
39
- export const maxComponent = vdbMaxComponent;
40
- export const frameFragCoord = (targetSize) => vec2(screenCoordinate.x, targetSize.y.sub(screenCoordinate.y));
41
- // NOTE Bottom-left texel of a render target texture
42
- export const frameLoad = (textureNode, texel, targetSize) => textureNode.load(ivec2(texel.x, int(targetSize.y).sub(texel.y).sub(1)));
43
- // NOTE Fullscreen triangle. Positions are clip coordinates.
44
- export const frameFullscreenVertex = vec4(positionGeometry.xy, 0.0, 1.0);
45
- // NOTE Bottom-left uv of a render target texture. Level 0, then sampling is allowed in loops and branches.
46
- export const frameSample = (textureNode, uv) => textureNode.sample(vec2(uv.x, float(1.0).sub(uv.y))).level(float(0.0));
47
- // NOTE Froxel grid layout and view reconstruction. Shared by all froxel passes.
48
- export const createFroxelUniforms = () => ({
49
- froxelGrid: uniform(new THREE.Vector3(1.0, 1.0, 1.0)),
50
- froxelColumns: uniform(1.0),
51
- froxelRange: uniform(new THREE.Vector2(0.1, 1.0)),
52
- froxelProjectionInverse: uniform(new THREE.Matrix4()),
53
- froxelSubSteps: uniform(6, "int"),
54
- froxelAtlasSize: uniform(new THREE.Vector2(1.0, 1.0)),
55
- frameJitter: uniform(0.5),
56
- frameFadeRadius: uniform(0.0),
57
- });
58
- export const frameSliceDepth = (froxel, t) => froxel.froxelRange.x.mul(pow(froxel.froxelRange.y.div(froxel.froxelRange.x), t));
59
- // NOTE Two points on the pixel ray. NDC depth 0.0 and 1.0 are in the frustum in WebGPU and WebGL.
60
- export const frameGetViewPosition = (froxel, uv, viewDepth) => {
61
- const ndc = uv.mul(2.0).sub(1.0);
62
- const nearPoint = froxel.froxelProjectionInverse.mul(vec4(ndc, 0.0, 1.0));
63
- const farPoint = froxel.froxelProjectionInverse.mul(vec4(ndc, 1.0, 1.0));
64
- const near = nearPoint.xyz.div(nearPoint.w);
65
- const far = farPoint.xyz.div(farPoint.w);
66
- const t = viewDepth.add(near.z).div(near.z.sub(far.z));
67
- return mix(near, far, t);
68
- };
69
- // NOTE Slice, uv and view positions of the froxel at an atlas pixel
70
- export const frameGetFroxel = (froxel, fragCoord) => {
71
- const { froxelGrid, froxelColumns } = froxel;
72
- const tile = floor(fragCoord.div(froxelGrid.xy));
73
- const slice = tile.y.mul(froxelColumns).add(tile.x);
74
- const uv = fragCoord.sub(tile.mul(froxelGrid.xy)).div(froxelGrid.xy);
75
- const sliceNear = frameSliceDepth(froxel, slice.div(froxelGrid.z));
76
- const sliceFar = frameSliceDepth(froxel, slice.add(1.0).div(froxelGrid.z));
77
- return {
78
- tile,
79
- slice,
80
- uv,
81
- sliceNear,
82
- sliceFar,
83
- viewNear: frameGetViewPosition(froxel, uv, sliceNear),
84
- viewFar: frameGetViewPosition(froxel, uv, sliceFar),
85
- };
86
- };
87
- // NOTE Exponent of the distance fade. 4.0 is FogExp2 with density 2 / frameFadeRadius.
88
- const frameFadeExponent = 4.0;
89
- const frameFadeEnd = Math.exp(-frameFadeExponent);
90
- // NOTE Density scale at a view position. 1.0 at the camera, 0.0 at frameFadeRadius. Radius 0.0: no fade.
91
- export const frameDistanceFade = (froxel, viewPosition) => {
92
- const x = clamp(length(viewPosition).div(froxel.frameFadeRadius), 0.0, 1.0);
93
- const fade = exp(x.mul(x).mul(-frameFadeExponent))
94
- .sub(frameFadeEnd)
95
- .div(1.0 - frameFadeEnd);
96
- return select(froxel.frameFadeRadius.greaterThan(0.0), fade, float(1.0));
97
- };
98
- // NOTE Mip level of a froxel from its width or the sub-step length, the larger one
99
- export const getFroxelLod = (froxel, cell, volume, subStepLength, worldScale) => {
100
- const sliceMiddle = cell.sliceNear.add(cell.sliceFar).mul(0.5);
101
- const neighborUv = cell.uv.add(vec2(float(1.0).div(froxel.froxelGrid.x), 0.0));
102
- const froxelWidth = frameGetViewPosition(froxel, neighborUv, sliceMiddle).sub(frameGetViewPosition(froxel, cell.uv, sliceMiddle)).length();
103
- return volume.getLod(max(froxelWidth, subStepLength).div(worldScale)).toVar();
104
- };
105
- // NOTE The mip level the extinction is read from for this froxel width: level 0 without mipmaps, and no level past the
106
- // ones the density grid and the mask grid have. The mask presence is compile-time here (DIVERGES V23).
107
- export const getSampledLod = (source, hasMask, widthLod, mipmaps) => {
108
- if (!mipmaps) {
109
- return float(0.0);
110
- }
111
- const maskLevels = hasMask ? source.mipLevels.mask : widthLod;
112
- return min(widthLod, min(source.mipLevels.density, maskLevels));
113
- };
114
- // NOTE Sub-steps for the part of a slice inside the volume box: two for each voxel of the mip level that is read, at
115
- // most froxelSubSteps. A thin slice or a far volume needs fewer than froxelSubSteps.
116
- export const getBoxSteps = (volume, localNear, localFar, segment, sampledLod, froxelSubSteps) => {
117
- const boxLength = localFar.sub(localNear).length().mul(segment);
118
- const steps = ceil(exp2(volume.getLod(boxLength).sub(sampledLod)).mul(2.0));
119
- return int(clamp(steps, 1.0, float(froxelSubSteps))).toVar();
120
- };
121
- // NOTE Per-pixel noise that changes each frame. Interleaved gradient noise (Jimenez 2014,
122
- // https://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare).
123
- // NOTE Returns 0.5 when jitter is off (frameJitter is negative).
124
- export const frameNoise = (jitter, pixel) => {
125
- const noise = fract(float(52.9829189).mul(fract(dot(pixel, vec2(0.06711056, 0.00583715)))));
126
- return select(jitter.lessThan(0.0), float(0.5), fract(noise.add(jitter)));
127
- };
128
- // NOTE Henyey-Greenstein phase divided by the isotropic phase 1 / (4 PI). g = 0 gives 1.
129
- export const frameHenyeyGreenstein = (cosTheta, g) => {
130
- const g2 = g.mul(g);
131
- return float(1.0)
132
- .sub(g2)
133
- .div(pow(max(float(1.0).add(g2).sub(g.mul(2.0).mul(cosTheta)), 1e-4), 1.5));
134
- };
135
- // NOTE Henyey-Greenstein phase of each channel, g of each channel
136
- export const frameHenyeyGreensteinColor = (cosTheta, g) => {
137
- const g2 = g.mul(g);
138
- return vec3(1.0)
139
- .sub(g2)
140
- .div(pow(max(vec3(1.0).add(g2).sub(g.mul(2.0).mul(cosTheta)), vec3(1e-4)), vec3(1.5)));
141
- };
142
- // NOTE Lorenz-Mie phase tables, see getFrameMieTexels. Float values, read with load and a linear blend.
143
- // Made on first use (one texture for all shaders).
144
- let frameMieMap = null;
145
- export const getFrameMieMap = () => {
146
- if (!frameMieMap) {
147
- const mieTexture = new THREE.DataTexture(getFrameMieTexels(), vdbFrameMieTableSize, 1, THREE.RGBAFormat, THREE.FloatType);
148
- mieTexture.minFilter = THREE.NearestFilter;
149
- mieTexture.magFilter = THREE.NearestFilter;
150
- mieTexture.needsUpdate = true;
151
- frameMieMap = texture(mieTexture);
152
- }
153
- return frameMieMap;
154
- };
155
- // NOTE Table texel u is at the scattering angle PI * u^2. Red, green, blue: 'lorenz-mie-rgb'. Alpha: 'lorenz-mie'.
156
- export const frameMieTexel = (cosTheta) => {
157
- const map = getFrameMieMap();
158
- const u = sqrt(acos(clamp(cosTheta, -1.0, 1.0)).mul(1.0 / Math.PI));
159
- const texel = u.mul(vdbFrameMieTableSize - 1).toVar();
160
- const index = min(int(texel), int(vdbFrameMieTableSize - 2)).toVar();
161
- const a = map.load(ivec2(index, 0));
162
- const b = map.load(ivec2(index.add(1), 0));
163
- return mix(a, b, texel.sub(float(index)));
164
- };
165
- const frameMiePhase = (cosTheta) => frameMieTexel(cosTheta).a;
166
- const frameMieRgbPhase = (cosTheta) => frameMieTexel(cosTheta).rgb;
167
- // NOTE framePhase is (forward g, back g, back weight, Lorenz-Mie mode), see phase.ts. Call in a Fn body.
168
- // NOTE rayDirection: from the camera to the sample. lightDirection: from the sample to the light.
169
- export const framePhaseWeight = (framePhase, rayDirection, lightDirection) => {
170
- const cosTheta = dot(rayDirection, lightDirection).toVar();
171
- const weight = mix(frameHenyeyGreenstein(cosTheta, framePhase.x), frameHenyeyGreenstein(cosTheta, framePhase.y), framePhase.z).toVar();
172
- If(framePhase.w.greaterThan(0.0), () => {
173
- weight.assign(mix(weight, frameMiePhase(cosTheta), framePhase.w));
174
- });
175
- return weight;
176
- };
177
- // NOTE Phase of each channel (red, green, blue). Call in a Fn body.
178
- // NOTE phaseSpectrum is (red g scale, blue g scale, flag), see phase.ts. Flag 0.0: the same phase for all channels.
179
- export const framePhaseColor = (framePhase, phaseSpectrum, rayDirection, lightDirection) => {
180
- const color = vec3(0.0).toVar();
181
- If(phaseSpectrum.z.lessThan(0.5), () => {
182
- color.assign(vec3(framePhaseWeight(framePhase, rayDirection, lightDirection)));
183
- })
184
- .ElseIf(framePhase.w.greaterThan(frameMieRgbMode - 0.5), () => {
185
- color.assign(frameMieRgbPhase(dot(rayDirection, lightDirection)));
186
- })
187
- .Else(() => {
188
- const cosTheta = dot(rayDirection, lightDirection).toVar();
189
- const scale = vec3(phaseSpectrum.x, 1.0, phaseSpectrum.y).toVar();
190
- color.assign(mix(frameHenyeyGreensteinColor(cosTheta, clamp(scale.mul(framePhase.x), -0.99, 0.99)), frameHenyeyGreensteinColor(cosTheta, clamp(scale.mul(framePhase.y), -0.99, 0.99)), framePhase.z));
191
- });
192
- return color;
193
- };
194
- // NOTE Phase with all g multiplied by gScale. Lorenz-Mie uses Henyey-Greenstein with the table asymmetry g.
195
- // 'lorenz-mie-rgb' too: it is the same for all channels.
196
- export const framePhaseWeightScaled = (framePhase, cosTheta, gScale) => mix(mix(frameHenyeyGreenstein(cosTheta, framePhase.x.mul(gScale)), frameHenyeyGreenstein(cosTheta, framePhase.y.mul(gScale)), framePhase.z), frameHenyeyGreenstein(cosTheta, gScale.mul(frameMieAsymmetry)), min(framePhase.w, 1.0));
197
- // NOTE Absorption of the shadow extinction: the part of the light that the albedo (linear luminance) does not scatter
198
- export const frameShadowAbsorption = (extinction, albedo) => extinction.mul(float(1.0).sub(clamp(dot(albedo, vec3(0.2126, 0.7152, 0.0722)), 0.0, 1.0)));
199
- // NOTE Shadow march values for each unit of length: (extinction, effective extinction, reduced scattering).
200
- // multipleScattering is 1 - g (phase.ts). Diffusion approximation: effective = sqrt(3 * absorption * (absorption + reduced)).
201
- export const frameShadowStep = (extinction, absorption, multipleScattering) => {
202
- const absorbed = min(absorption, extinction).toVar();
203
- const reducedScattering = extinction.sub(absorbed).mul(multipleScattering).toVar();
204
- return vec3(extinction, sqrt(absorbed.mul(3.0).mul(absorbed.add(reducedScattering))), reducedScattering);
205
- };
206
- // NOTE -log of the total shadow transmittance (direct and scattered light) of the summed march values.
207
- // exp(-effective) / (1 + 0.75 * reduced), never less than the direct light exp(-extinction). 0.0 multipleScattering: direct only.
208
- export const frameShadowDepth = (depths, multipleScattering) => select(multipleScattering.greaterThan(0.0), min(depths.x, depths.y.add(log(depths.z.mul(0.75).add(1.0)))), depths.x);
209
- // NOTE octaves is (count N, extinction a, contribution b, phase c) of the indirect light octaves (phase.ts). N 0 is off.
210
- // NOTE Optical depth of the least shadowed light term. Marches stop when it is large.
211
- // Octaves: the last octave has extinction * a^N, so the march goes deeper.
212
- export const frameShadowMarchDepth = (depths, multipleScattering, octaves) => select(octaves.x.greaterThan(0.0), depths.x.mul(pow(octaves.y, octaves.x)), frameShadowDepth(depths, multipleScattering));
213
- // NOTE Shadow values (direct, total) transmittance. Direct light gets the phase function, scattered light (total - direct) is isotropic.
214
- // NOTE Octaves: y is 1 / (1 + optical depth). Half float targets keep it for deep volumes, and 1.0 is no shadow.
215
- export const frameShadowTransmittance = (depths, multipleScattering, octaves) => vec2(exp(depths.x.negate()), select(octaves.x.greaterThan(0.0), float(1.0).div(depths.x.add(1.0)), exp(frameShadowDepth(depths, multipleScattering).negate())));
216
- // NOTE Optical depth from the y shadow value of octaves
217
- export const frameShadowOpticalDepth = (shadowY) => max(float(1.0).div(max(shadowY, 1e-6)).sub(1.0), 0.0);
218
- // NOTE Sum of b^n * phase(g * c^n) * exp(-a^n * optical depth), n 1 to N. Call in a Fn body.
219
- // NOTE framePhase null is isotropic (phase 1).
220
- export const frameOctaveLight = (octaves, opticalDepth, framePhase, cosTheta) => {
221
- const light = float(0.0).toVar();
222
- const extinctionScale = float(1.0).toVar();
223
- const contribution = float(1.0).toVar();
224
- const gScale = float(1.0).toVar();
225
- Loop(frameMaxScatteringOctaves, ({ i }) => {
226
- If(float(i.add(1)).greaterThan(octaves.x), () => {
227
- Break();
228
- });
229
- extinctionScale.mulAssign(octaves.y);
230
- contribution.mulAssign(octaves.z);
231
- gScale.mulAssign(octaves.w);
232
- const phase = framePhase ? framePhaseWeightScaled(framePhase, cosTheta, gScale) : float(1.0);
233
- light.addAssign(contribution.mul(phase).mul(exp(opticalDepth.mul(extinctionScale).negate())));
234
- });
235
- return light;
236
- };
237
- // NOTE Light of a shadowed light of each channel, divided by the light color: phase * direct + scattered. Call in a Fn body.
238
- // Diffusion or single scattering: the scattered light (total - direct) is isotropic.
239
- // Octaves: sum of b^n * phase(g * c^n) * exp(-a^n * optical depth), n 1 to N.
240
- export const frameShadowedLight = (framePhase, phaseSpectrum, octaves, rayDirection, lightDirection, shadow) => {
241
- const light = framePhaseColor(framePhase, phaseSpectrum, rayDirection, lightDirection).mul(shadow.x).toVar();
242
- If(octaves.x.greaterThan(0.0), () => {
243
- const opticalDepth = frameShadowOpticalDepth(shadow.y).toVar();
244
- light.addAssign(vec3(frameOctaveLight(octaves, opticalDepth, framePhase, dot(rayDirection, lightDirection).toVar())));
245
- }).Else(() => {
246
- light.addAssign(vec3(shadow.y.sub(shadow.x)));
247
- });
248
- return light;
249
- };
250
- // NOTE Total transmittance of isotropic light (environment, sky) with diffusion multiple scattering.
251
- // Two-sided slab diffusion: 2 * (back + z0) / (front + back + 2 z0) of the reduced depths, z0 = 2/3, times exp(-effective front).
252
- // Light that is scattered and not absorbed is not lost: opposite directions sum to 2. In a white volume, a uniform
253
- // environment then gives the same light inside and outside (white furnace test). Front is toward the light.
254
- const frameDiffusionExtrapolation = 2.0 / 3.0;
255
- export const frameIsotropicDiffusion = (frontReduced, backReduced, frontEffective) => backReduced
256
- .add(frameDiffusionExtrapolation)
257
- .mul(2.0)
258
- .div(frontReduced.add(backReduced).add(2.0 * frameDiffusionExtrapolation))
259
- .mul(exp(frontEffective.negate()));
260
- // NOTE multipleScattering 'two-sided': total transmittance of a light direction (direct and scattered light).
261
- // Diffusion with a collimated source in the volume between the light side and the far side: front reduced depth f
262
- // (toward the light), back reduced depth b (away from the light), L = f + b. Light also leaves at the sides: the volume
263
- // is as wide as it is deep (L), so phi'' - k^2 phi = -3 exp(-x) with k^2 = 2 (PI / (L + 2 z0))^2, the lowest side mode.
264
- // Robin boundaries phi = z0 phi' at x = 0 and phi = -z0 phi' at x = L, z0 = 2/3. Then the reduced beam exp(-f),
265
- // times exp(-effective front) for absorption, never less than the direct light.
266
- export const frameTwoSidedDiffusion = (direct, frontReduced, frontEffective, backReduced) => {
267
- const z0 = frameDiffusionExtrapolation;
268
- const slab = frontReduced.add(backReduced);
269
- const k0 = float(Math.SQRT2 * Math.PI).div(slab.add(2.0 * z0));
270
- // NOTE k = 1 has no particular solution of this form. A small shift keeps the result continuous.
271
- const k = k0.add(float(1.0).sub(step(0.01, abs(float(1.0).sub(k0.mul(k0))))).mul(0.01)).toVar();
272
- const p = float(-3.0).div(float(1.0).sub(k.mul(k))).toVar();
273
- const kl = k.mul(slab);
274
- const coshKl = exp(kl).add(exp(kl.negate())).mul(0.5).toVar();
275
- const sinhKl = exp(kl).sub(exp(kl.negate())).mul(0.5).toVar();
276
- const c12 = k.mul(-z0);
277
- const r1 = p.mul(-(1.0 + z0));
278
- const c21 = coshKl.add(k.mul(z0).mul(sinhKl));
279
- const c22 = sinhKl.add(k.mul(z0).mul(coshKl));
280
- const r2 = p.negate().mul(exp(slab.negate())).mul(1.0 - z0);
281
- const det = c22.sub(c12.mul(c21)).toVar();
282
- const c = r1.mul(c22).sub(c12.mul(r2)).div(det);
283
- const d = r2.sub(c21.mul(r1)).div(det);
284
- const kf = k.mul(frontReduced);
285
- const beam = exp(frontReduced.negate());
286
- const diffuse = p
287
- .mul(beam)
288
- .add(c.mul(exp(kf).add(exp(kf.negate())).mul(0.5)))
289
- .add(d.mul(exp(kf).sub(exp(kf.negate())).mul(0.5)));
290
- return max(direct, diffuse.add(beam).mul(exp(frontEffective.negate())));
291
- };
292
- // NOTE Total transmittance of isotropic light (no phase) from the y shadow value. Call in a Fn body.
293
- // Octaves: sum of b^n * exp(-a^n * optical depth), n 0 (direct) to N.
294
- export const frameShadowTotal = (shadowY, octaves) => {
295
- const total = float(shadowY).toVar();
296
- If(octaves.x.greaterThan(0.0), () => {
297
- const opticalDepth = frameShadowOpticalDepth(shadowY).toVar();
298
- total.assign(exp(opticalDepth.negate()).add(frameOctaveLight(octaves, opticalDepth, null, null)));
299
- });
300
- return total;
301
- };
302
- export const frameMeanComponent = (value) => dot(value, vec3(1.0 / 3.0));
303
- // NOTE Shadow depths of one unit of extinction. spectrum: extinction scale of each channel.
304
- // Absorption is the part that the albedo of each channel does not scatter. The same as frameShadowStep for each channel.
305
- export const frameSpectralShadowUnit = (spectrum, albedo, multipleScattering) => {
306
- const absorbed = vec3(spectrum).mul(float(1.0).sub(clamp(albedo, 0.0, 1.0))).toVar();
307
- const reducedScattering = vec3(spectrum).sub(absorbed).mul(multipleScattering).toVar();
308
- return {
309
- x: vec3(spectrum),
310
- y: sqrt(absorbed.mul(3.0).mul(absorbed.add(reducedScattering))).toVar(),
311
- z: reducedScattering,
312
- };
313
- };
314
- // NOTE Shadow depths of opticalDepth units. One volume has one spectrum, then all depths grow linearly.
315
- export const frameSpectralShadowDepths = (unit, opticalDepth) => ({
316
- x: unit.x.mul(opticalDepth),
317
- y: unit.y.mul(opticalDepth),
318
- z: unit.z.mul(opticalDepth),
319
- });
320
- // NOTE Shadow depths of one march step for each channel of the grid, the same as frameShadowStep.
321
- // extinction and absorption are vec3. Volumes in a grid voxel can have other spectra, so the depths are summed for each channel.
322
- export const frameSpectralShadowStep = (extinction, absorption, multipleScattering) => {
323
- const absorbed = min(absorption, extinction).toVar();
324
- const reducedScattering = vec3(extinction).sub(absorbed).mul(multipleScattering).toVar();
325
- return {
326
- x: vec3(extinction),
327
- y: sqrt(absorbed.mul(3.0).mul(absorbed.add(reducedScattering))),
328
- z: reducedScattering,
329
- };
330
- };
331
- // NOTE Single-scattering albedo of each channel of a grid voxel from (extinction, absorption). 1.0 with no extinction.
332
- export const frameSpectralGridAlbedo = (extinction, absorption) => select(maxComponent(extinction).greaterThan(0.0), clamp(vec3(1.0).sub(absorption.div(max(extinction, vec3(1e-8)))), 0.0, 1.0), vec3(1.0));
333
- // NOTE Shadow values of each channel, the same as frameShadowTransmittance
334
- export const frameSpectralShadowTransmittance = (depths, multipleScattering, octaves) => ({
335
- x: exp(depths.x.negate()),
336
- y: select(octaves.x.greaterThan(0.0), vec3(1.0).div(depths.x.add(1.0)), exp(frameShadowDepth(depths, multipleScattering).negate())),
337
- });
338
- // NOTE Octave light of each channel, the same as frameOctaveLight. Octave n also gets albedo^n: each octave is one more scattering.
339
- // Call in a Fn body. framePhase null is isotropic (phase 1).
340
- export const frameSpectralOctaveLight = (octaves, opticalDepth, albedo, framePhase, cosTheta) => {
341
- const light = vec3(0.0).toVar();
342
- const extinctionScale = float(1.0).toVar();
343
- const contribution = float(1.0).toVar();
344
- const gScale = float(1.0).toVar();
345
- const albedoScale = vec3(1.0).toVar();
346
- const octaveAlbedo = clamp(albedo, 0.0, 1.0).toVar();
347
- Loop(frameMaxScatteringOctaves, ({ i }) => {
348
- If(float(i.add(1)).greaterThan(octaves.x), () => {
349
- Break();
350
- });
351
- extinctionScale.mulAssign(octaves.y);
352
- contribution.mulAssign(octaves.z);
353
- gScale.mulAssign(octaves.w);
354
- albedoScale.mulAssign(octaveAlbedo);
355
- const phase = framePhase ? framePhaseWeightScaled(framePhase, cosTheta, gScale) : float(1.0);
356
- light.addAssign(albedoScale.mul(contribution.mul(phase)).mul(exp(opticalDepth.mul(extinctionScale).negate())));
357
- });
358
- return light;
359
- };
360
- // NOTE Total transmittance of isotropic light of each channel, the same as frameShadowTotal. Call in a Fn body.
361
- export const frameSpectralShadowTotal = (shadowY, octaves, albedo) => {
362
- const total = vec3(shadowY).toVar();
363
- If(octaves.x.greaterThan(0.0), () => {
364
- const opticalDepth = frameShadowOpticalDepth(total).toVar();
365
- total.assign(exp(opticalDepth.negate()).add(frameSpectralOctaveLight(octaves, opticalDepth, albedo, null, null)));
366
- });
367
- return total;
368
- };
369
- // NOTE Light of a shadowed light of each channel, the same as frameShadowedLight. Call in a Fn body.
370
- export const frameSpectralShadowedLight = (framePhase, phaseSpectrum, octaves, rayDirection, lightDirection, shadow, albedo) => {
371
- const light = vec3(shadow.x).mul(framePhaseColor(framePhase, phaseSpectrum, rayDirection, lightDirection)).toVar();
372
- If(octaves.x.greaterThan(0.0), () => {
373
- const opticalDepth = frameShadowOpticalDepth(vec3(shadow.y)).toVar();
374
- light.addAssign(frameSpectralOctaveLight(octaves, opticalDepth, albedo, framePhase, dot(rayDirection, lightDirection).toVar()));
375
- }).Else(() => {
376
- light.addAssign(vec3(shadow.y).sub(shadow.x));
377
- });
378
- return light;
379
- };
380
- // NOTE The two entries of a spectral transmittance group from its 3 targets (spectrum.ts)
381
- export const frameUnpackSpectralGroup = (map0, map1, map2) => ({
382
- a: { x: map0.rgb, y: vec3(map0.a, map1.r, map1.g) },
383
- b: { x: vec3(map1.b, map1.a, map2.r), y: map2.gba },
384
- });
385
- export const frameMaxLights = 16;
386
- export const frameMaxHemisphereLights = 4;
387
- export const frameMaxEnvironmentLights = 12;
388
- // NOTE Scene lights in world space. Lights are in shadow slot order: directional, point, spot.
389
- // NOTE Position w: 1.0 directional (xyz is the direction to the light), 2.0 point, 3.0 spot.
390
- // NOTE Color rgb is color * intensity, color w is the spot penumbra cosine.
391
- // NOTE Spot xyz is the direction from the target to the light, spot w is the cone cosine.
392
- // NOTE Falloff x is the light distance, falloff y is the decay. Point and spot lights only.
393
- // NOTE Both lighting paths read every light uniform: 'volume' lighting (inject, K3.5) per volume with its own marches,
394
- // 'frame' lighting through the shadow grid (K3.3).
395
- export const createLightUniforms = () => ({
396
- frameAmbientColor: uniform(new THREE.Color(0x000000)),
397
- frameLightProbe: uniformArray(Array.from({ length: 9 }, () => new THREE.Vector3()), "vec3"),
398
- // NOTE Sums of all hemisphere lights, for combined lighting. Sky direction is from the first one.
399
- frameHemiSkyColor: uniform(new THREE.Color(0x000000)),
400
- frameHemiGroundColor: uniform(new THREE.Color(0x000000)),
401
- frameSkyDirection: uniform(new THREE.Vector3(0.0, 1.0, 0.0)),
402
- // NOTE Each hemisphere light, for per-volume lighting. Directions point up (sky).
403
- frameHemiCount: uniform(0, "int"),
404
- frameHemiSkyColors: uniformArray(Array.from({ length: frameMaxHemisphereLights }, () => new THREE.Vector3()), "vec3"),
405
- frameHemiGroundColors: uniformArray(Array.from({ length: frameMaxHemisphereLights }, () => new THREE.Vector3()), "vec3"),
406
- frameHemiDirections: uniformArray(Array.from({ length: frameMaxHemisphereLights }, () => new THREE.Vector3()), "vec3"),
407
- frameLightCount: uniform(0, "int"),
408
- frameLightPositions: uniformArray(Array.from({ length: frameMaxLights }, () => new THREE.Vector4()), "vec4"),
409
- frameLightColors: uniformArray(Array.from({ length: frameMaxLights }, () => new THREE.Vector4()), "vec4"),
410
- frameLightSpots: uniformArray(Array.from({ length: frameMaxLights }, () => new THREE.Vector4()), "vec4"),
411
- frameLightFalloffs: uniformArray(Array.from({ length: frameMaxLights }, () => new THREE.Vector2()), "vec2"),
412
- // NOTE Environment lights (settings.environmentLighting). World directions to the light.
413
- // Colors are isotropic irradiance, no phase. Count is 0 with the 'outward' environment.
414
- frameEnvironmentCount: uniform(0, "int"),
415
- frameEnvironmentDirections: uniformArray(Array.from({ length: frameMaxEnvironmentLights }, () => new THREE.Vector3(0.0, 1.0, 0.0)), "vec3"),
416
- frameEnvironmentColors: uniformArray(Array.from({ length: frameMaxEnvironmentLights }, () => new THREE.Vector3()), "vec3"),
417
- // NOTE Environment grid lights with no shadow, clamped to 0 or more. Used outside the environment grid.
418
- frameEnvironmentUnshadowed: uniform(new THREE.Vector3()),
419
- });
420
- // NOTE Values of one frame volume that are not the source (the source half is vdbVolumeUniforms). The renderer sets
421
- // them before each draw (setVolumeUniforms in renderer.ts).
422
- export const createFrameVolumeUniforms = () => ({
423
- frameViewToLocal: uniform(new THREE.Matrix4()),
424
- frameLocalToView: uniform(new THREE.Matrix4()),
425
- frameWorldToLocal: uniform(new THREE.Matrix4()),
426
- frameScatterColor: uniform(new THREE.Color(0x000000)),
427
- // NOTE Extinction scale of each channel (spectrum.ts). Only spectral shaders read it.
428
- frameExtinctionSpectrum: uniform(new THREE.Vector3(1.0, 1.0, 1.0)),
429
- frameAbsorbance: uniform(1.0),
430
- frameOpacity: uniform(1.0),
431
- // NOTE Phase of this volume for 'volume' lighting: (forward g, back g, back weight, Lorenz-Mie weight)
432
- framePhase: uniform(new THREE.Vector4()),
433
- // NOTE Phase of each channel (phase.ts getFramePhaseSpectrum)
434
- framePhaseSpectrum: uniform(new THREE.Vector3()),
435
- });
436
- export const frameMaxShadowCascades = 4;
437
- // NOTE World-space shadow grid cascades. Cascade 0 is the finest, near the camera.
438
- // All cascades are z slices (tiles) in one 2D atlas.
439
- export const createGridUniforms = (frameJitter) => ({
440
- frameGridMin: uniformArray(Array.from({ length: frameMaxShadowCascades }, () => new THREE.Vector3()), "vec3"),
441
- frameGridSize: uniformArray(Array.from({ length: frameMaxShadowCascades }, () => new THREE.Vector3()), "vec3"),
442
- frameGridVoxel: uniformArray(Array.from({ length: frameMaxShadowCascades }, () => new THREE.Vector3()), "vec3"),
443
- frameGridCount: uniform(0, "int"),
444
- frameGridResolution: uniform(1.0),
445
- frameGridColumns: uniform(1.0),
446
- frameGridAtlasSize: uniform(new THREE.Vector2(1.0, 1.0)),
447
- frameJitter,
448
- });
449
- // NOTE Environment grid: environment light of each voxel of the last shadow grid cascade, in its own atlas
450
- export const createEnvironmentGridUniforms = () => ({
451
- frameEnvironmentGridCascade: uniform(0, "int"),
452
- frameEnvironmentGridColumns: uniform(1.0),
453
- frameEnvironmentGridAtlasSize: uniform(new THREE.Vector2(1.0, 1.0)),
454
- });
455
- export const createGridNodes = (grid) => {
456
- const { frameGridMin, frameGridSize, frameGridCount, frameGridResolution, frameGridColumns } = grid;
457
- const gridUvw = (cascade, worldPosition) => worldPosition.sub(frameGridMin.element(cascade)).div(frameGridSize.element(cascade));
458
- // NOTE Half a voxel inside the cascade. Then the linear filter does not read the clamped edge.
459
- const insideGrid = (uvw) => {
460
- const inset = float(0.5).div(frameGridResolution);
461
- return minComponent(uvw)
462
- .greaterThanEqual(inset)
463
- .and(maxComponent(uvw).lessThanEqual(float(1.0).sub(inset)));
464
- };
465
- // NOTE Finest cascade from the first cascade that contains the position, or -1
466
- const findCascade = (worldPosition, firstCascade) => {
467
- let cascade = int(-1);
468
- for (let i = frameMaxShadowCascades - 1; i >= 0; i--) {
469
- cascade = select(int(i)
470
- .lessThan(frameGridCount)
471
- .and(int(i).greaterThanEqual(firstCascade))
472
- .and(insideGrid(gridUvw(int(i), worldPosition))), int(i), cascade);
473
- }
474
- return cascade;
475
- };
476
- // NOTE Hardware bilinear filter in the slice, manual linear filter between slices.
477
- // NOTE The grid is the z slices (tiles) from tileOffset in an atlas with columns tile columns.
478
- // resolution: voxels on each side of the grid (each tile is resolution x resolution).
479
- const sampleTiles = (atlas, resolution, tileOffset, columns, atlasSize, uvw) => {
480
- const z = uvw.z.mul(resolution).sub(0.5);
481
- const z0 = clamp(floor(z), 0.0, resolution.sub(1.0));
482
- const z1 = min(z0.add(1.0), resolution.sub(1.0));
483
- const blend = clamp(z.sub(z0), 0.0, 1.0);
484
- const xy = clamp(uvw.xy.mul(resolution), vec2(0.5), vec2(resolution.sub(0.5)));
485
- const tileUv = (index) => {
486
- const tile = vec2(mod(index, columns), floor(index.div(columns)));
487
- return tile.mul(resolution).add(xy).div(atlasSize);
488
- };
489
- return mix(frameSample(atlas, tileUv(tileOffset.add(z0))), frameSample(atlas, tileUv(tileOffset.add(z1))), blend);
490
- };
491
- const sampleGrid = (atlas, cascade, uvw) => sampleTiles(atlas, frameGridResolution, float(cascade).mul(frameGridResolution), frameGridColumns, grid.frameGridAtlasSize, uvw);
492
- // NOTE Environment grid: the last cascade only, in its own atlas. outside is the value outside it.
493
- // NOTE Call in a Fn body. Returns a vec4 variable.
494
- const sampleEnvironmentGrid = (map, environmentGrid, worldPosition, outside) => {
495
- const value = vec4(outside).toVar();
496
- const uvw = gridUvw(environmentGrid.frameEnvironmentGridCascade, worldPosition).toVar();
497
- If(insideGrid(uvw), () => {
498
- value.assign(sampleTiles(map, frameGridResolution, float(0.0), environmentGrid.frameEnvironmentGridColumns, environmentGrid.frameEnvironmentGridAtlasSize, uvw));
499
- });
500
- return value;
501
- };
502
- // NOTE Transmittance of the shadow slots at a world position. 1.0 outside the grid.
503
- // Call in a Fn body. Returns one vec4 variable for each map.
504
- const sampleShadows = (maps, worldPosition) => {
505
- const shadows = maps.map(() => vec4(1.0).toVar());
506
- const cascade = findCascade(worldPosition, int(0)).toVar();
507
- If(cascade.greaterThanEqual(0), () => {
508
- const uvw = gridUvw(cascade, worldPosition).toVar();
509
- maps.forEach((map, index) => {
510
- shadows[index].assign(sampleGrid(map, cascade, uvw));
511
- });
512
- // NOTE Blend to the next cascade near the sides of this cascade. Then cascade borders are not visible.
513
- const sideDistance = min(uvw, vec3(1.0).sub(uvw));
514
- const blend = float(1.0).sub(smoothstep(0.0, 0.1, minComponent(sideDistance))).toVar();
515
- If(blend.greaterThan(0.0), () => {
516
- const nextCascade = findCascade(worldPosition, cascade.add(1)).toVar();
517
- If(nextCascade.greaterThanEqual(0), () => {
518
- const nextUvw = gridUvw(nextCascade, worldPosition).toVar();
519
- maps.forEach((map, index) => {
520
- shadows[index].assign(mix(shadows[index], sampleGrid(map, nextCascade, nextUvw), blend));
521
- });
522
- });
523
- });
524
- });
525
- return shadows;
526
- };
527
- // NOTE Cascade and grid position of an atlas pixel
528
- const getGridCell = (fragCoord) => {
529
- const resolution = frameGridResolution;
530
- const tile = floor(fragCoord.div(resolution));
531
- const tileIndex = tile.y.mul(frameGridColumns).add(tile.x);
532
- const cascade = floor(tileIndex.div(resolution));
533
- const z = tileIndex.sub(cascade.mul(resolution));
534
- return {
535
- cascade: int(cascade),
536
- gridUvw: vec3(fragCoord.sub(tile.mul(resolution)), z.add(0.5)).div(resolution),
537
- };
538
- };
539
- return { gridUvw, insideGrid, findCascade, sampleTiles, sampleGrid, sampleEnvironmentGrid, sampleShadows, getGridCell };
540
- };
541
- // NOTE Instanced quad for froxel passes. One instance for each tile (slice), the quad covers the volume rectangle.
542
- export const createTileUniforms = () => ({
543
- frameTileSize: uniform(new THREE.Vector2(1.0, 1.0)),
544
- frameTileColumns: uniform(1.0),
545
- frameTargetSize: uniform(new THREE.Vector2(1.0, 1.0)),
546
- });
547
- // NOTE Froxel area of all volumes (view.ts getFroxelArea). Passes over the whole froxel grid draw only it.
548
- export const createAreaUniforms = () => ({
549
- frameAreaRect: uniform(new THREE.Vector4()),
550
- frameAreaSliceStart: uniform(0.0),
551
- });
552
- export const frameTileVertex = (tileUniforms, rect, sliceStart) => {
553
- const { frameTileSize, frameTileColumns, frameTargetSize } = tileUniforms;
554
- const slice = sliceStart.add(float(instanceIndex));
555
- const tile = vec2(mod(slice, frameTileColumns), floor(slice.div(frameTileColumns)));
556
- const cell = mix(rect.xy, rect.zw, positionGeometry.xy.mul(0.5).add(0.5));
557
- return vec4(tile.mul(frameTileSize).add(cell).div(frameTargetSize).mul(2.0).sub(1.0), 0.0, 1.0);
558
- };
559
- //# sourceMappingURL=chunks.js.map