@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,440 +1,218 @@
1
1
  // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
2
- // src/three-openvdb/frame/core/FrameEmissionLight.js L1–287 (FrameEmissionLightBase: emitters, keys, probe
3
- // cascades, prepareProbes); src/three-openvdb/frame/webgpu/FrameEmissionLight.js L59–658 (probe grid uniforms,
4
- // the direction / reduce / probe pass materials, FrameEmissionLightNode, FrameEmissionLight: targets, slots,
5
- // updateProbes, dispose, the node registration).
2
+ // src/three-openvdb/frame/core/FrameEmissionLight.js L1–287 (FrameEmissionLightBase: props, probe cascades);
3
+ // src/three-openvdb/frame/webgpu/FrameEmissionLight.js L59–658 (FrameEmissionLightNode: the probe lookup with the
4
+ // cascade blend and the falloff past the last cascade; FrameEmissionLight: props, the node registration).
6
5
  // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
7
- // Changes: TypeScript; one class (his CPU base and WebGPU subclass merged); the direction pass reads each emitter
8
- // through its own volume source (one direction material per source, as the other passes, DIVERGES V30) instead of
9
- // one material that swaps 3D textures; no CPU mip step (the sources hold their LOD); the pass materials belong to
10
- // the light (his are shared by all lights and never freed); the probe cascade maths is engine-free
11
- // (`@pmndrs/vdb/tools` `vdbFrameEmissionProbeGrid`, with twins of every pass); every three r187 internal goes
12
- // through `three-internals.ts` (VDB_ENGINE_MISMATCH on another three). Divergences: DIVERGES.md (K3.6 rows).
6
+ // Changes: TypeScript; K6.8: the emitters and probes are the core frame renderer's (its emission kernels, a stacked 3D
7
+ // texture read with hardware trilinear); this light carries the settings and lights meshes; K6.8b: the lookup is the
8
+ // core's own WGSL (`vdbEmissionIrradiance` of `vdbEmissionProbeWgsl()`) through a `wgslFn`, the probe grid read from the
9
+ // core's buffer through a storage stand-in, instead of a TSL port; every three r187 internal goes through
10
+ // `three-internals.ts` or the stand-in self-tests (VDB_ENGINE_MISMATCH on another three). Divergences: DIVERGES.md (K3.6,
11
+ // K6.5, K6.8b rows).
13
12
  /**
14
- * K3.6: light from the emissive grids of every visible `VDBFrameVolume` (his `FrameEmissionLight`). Add one to the
15
- * scene; three's lit node materials (`MeshStandardMaterial`, `MeshLambertMaterial`, …) receive it as irradiance, like a
16
- * light probe. Per changed volume: its emitted light along 16 directions × 8² rays (direction pass), the mean and the
17
- * luminance-weighted centre (reduce pass); then L1 irradiance probes of all volumes as point lights, in up to 4
18
- * cascades of ≤ 32³ (probe pass). A lit pixel reads 6 texels (12 near a cascade side), for any number of volumes.
19
- * The passes run before the first lit mesh of each render and only when a volume or the cascades changed.
13
+ * K3.6 / K6.5: light from the emissive grids of every visible `VDBFrameVolume` (his `FrameEmissionLight`). Add one to
14
+ * the scene; three's lit node materials (`MeshStandardMaterial`, `MeshLambertMaterial`, …) receive it as irradiance,
15
+ * like a light probe. The core frame renderer of the scene's volumes draws the emitters and L1 irradiance probes (up to
16
+ * 4 cascades of ≤ 32³) when a volume or the cascades changed; a lit pixel reads 6 texels (12 near a cascade side).
20
17
  *
21
18
  * const light = new VDBFrameEmissionLight({ intensity: 25, resolution: 32 });
22
19
  * scene.add(light); // volumes need an emission channel; colour: VDBFrameVolume `emissionColor`
20
+ *
21
+ * K6.8b: a lit pixel runs the core's `vdbEmissionIrradiance(probes, smp, grid, world, normal)` (`vdbEmissionProbeWgsl()`,
22
+ * twin `vdbFrameEmissionLookup` + `vdbFrameEmissionIrradiance`) through a `wgslFn`: `probes` is the core's probe stack
23
+ * (`outputs.emissionProbes.texture`, a 3D texture stand-in) and `grid` its `VdbEmissionGrid` buffer
24
+ * (`outputs.emissionProbes.grid`, bound through a storage stand-in and unpacked from `array<vec4u>`; the core rewrites it
25
+ * each update). The texture and storage nodes are made once; their `value` follows the core (placeholders while it has no
26
+ * probes: a 1³ texture and a zero grid, which lights nothing). three r187 re-reads a plain material's texture and storage
27
+ * bindings only on a full refresh, so a new core object (a new probe resolution, a released stack, another frame
28
+ * renderer) also rebuilds the receivers: the light keeps `castShadow` on (it casts no shadow) and its node bumps
29
+ * `version`, which three's lights cache key holds for a `castShadow` light. They rebuild at their next render; the core
30
+ * keeps the old stack alive two more updates (the K6.10 finding-8 class).
23
31
  */
24
32
  import * as THREE from "three";
25
- import { AnalyticLightNode, NodeMaterial } from "three/webgpu";
33
+ import { AnalyticLightNode } from "three/webgpu";
26
34
  import * as TSL from "three/tsl";
27
- import { vdbVolumeNodes } from "../volume-source.js";
28
- import { createFrameVolumeUniforms, createGridNodes, frameFragCoord, frameFullscreenVertex, frameLoad } from "./chunks.js";
29
- import { frameEmissionAtlasColumns as atlasColumns, frameEmissionAtlasSize as atlasSize, frameEmissionDirections as directionCount, frameEmissionGoldenAngle as goldenAngle, frameEmissionMaxCascades as maxCascades, frameEmissionRays as rayCount, vdbFrameEmissionProbeGrid, vdbFrameEmitterBounds, } from "../../tools/frame/emission.js";
30
- import { setVolumeUniforms } from "./renderer.js";
31
- import { vdbFramePrecompiling, vdbFrameRegisterLightNode, vdbFrameRenderUpdateType, vdbFrameRendererUtils } from "./three-internals.js";
32
- const { Discard, Fn, If, Loop, Break, abs, clamp, cos, cross, dot, exp, float, floor, int, inverseSqrt, ivec2, luminance, max, min, mix, normalWorld, normalize, outputStruct, positionGeometry, positionWorld, property, renderGroup, select, sin, smoothstep, sqrt, texture, uniform, uniformArray, vec3, vec4 } = TSL;
33
- // NOTE Probe cascades in the uniform names of createGridNodes. Cascade 0 is the finest.
34
- const createProbeGridUniforms = (group = null) => {
35
- const nodes = {
36
- frameGridMin: uniformArray(Array.from({ length: maxCascades }, () => new THREE.Vector3()), "vec3"),
37
- frameGridSize: uniformArray(Array.from({ length: maxCascades }, () => new THREE.Vector3(1.0, 1.0, 1.0)), "vec3"),
38
- frameGridCount: uniform(0, "int"),
39
- frameGridResolution: uniform(1.0),
40
- frameGridColumns: uniform(atlasColumns),
41
- frameGridAtlasSize: uniform(new THREE.Vector2(atlasSize, atlasSize)),
42
- };
43
- if (group) {
44
- Object.values(nodes).forEach((node) => node.setGroup(group));
45
- }
46
- return nodes;
47
- };
48
- const setProbeGridUniforms = (uniforms, light) => {
49
- const min = uniforms.frameGridMin.array;
50
- const size = uniforms.frameGridSize.array;
51
- for (let i = 0; i < maxCascades; i++) {
52
- min[i].copy(light.cascadeMin[i]);
53
- size[i].copy(light.cascadeSize[i]);
54
- }
55
- uniforms.frameGridCount.value = light.cascadeCount;
56
- uniforms.frameGridResolution.value = light.probeResolution;
57
- };
58
- const fullscreenPositions = [-1, -1, 0, 3, -1, 0, -1, 3, 0];
59
- const quadPositions = [-1, -1, 0, 1, -1, 0, 1, 1, 0, -1, -1, 0, 1, 1, 0, -1, 1, 0];
60
- const createGeometry = (positions) => {
61
- const geometry = new THREE.BufferGeometry();
62
- geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
63
- return geometry;
64
- };
65
- const createTarget = (count, type, filter, width = 1, height = 1) => new THREE.RenderTarget(width, height, {
66
- count,
67
- type,
68
- format: THREE.RGBAFormat,
69
- minFilter: filter,
70
- magFilter: filter,
71
- generateMipmaps: false,
72
- depthBuffer: false,
73
- });
74
- const setPassMaterial = (material) => {
75
- material.side = THREE.DoubleSide;
76
- material.depthTest = false;
77
- material.depthWrite = false;
78
- material.blending = THREE.NoBlending;
79
- };
80
- /**
81
- * Light that one volume sends in each of 16 directions: one texel per direction, one row per volume (slot). Parallel
82
- * rays cover the bounding sphere; each adds the emission with the volume's transmittance. Output 0: intensity
83
- * (emission × ray area) and the radius. Output 1: the luminance-weighted world position. One material per volume
84
- * source (the source is compiled in). Twin: `vdbFrameEmissionDirectionTexel`.
85
- */
86
- export class VDBFrameEmissionDirectionMaterial extends NodeMaterial {
87
- volumeUniforms = createFrameVolumeUniforms();
88
- sourceUniforms;
89
- source;
90
- emissionColor;
91
- frameSlot = uniform(0.0);
92
- frameTargetSize = uniform(new THREE.Vector2(directionCount, 1.0));
93
- frameEmitterCenter = uniform(new THREE.Vector3());
94
- frameEmitterRadius = uniform(1.0);
95
- frameSteps = uniform(24, "int");
96
- mipmaps;
97
- constructor(o) {
98
- super();
99
- this.name = "VDBFrameEmissionDirectionMaterial";
100
- this.source = o.source;
101
- this.sourceUniforms = o.sourceUniforms;
102
- this.mipmaps = o.mipmaps;
103
- this.emissionColor = o.emissionColor;
104
- this.buildNodes();
105
- setPassMaterial(this);
106
- }
107
- setMipmaps(mipmaps) {
108
- if (mipmaps !== this.mipmaps) {
109
- this.mipmaps = mipmaps;
110
- this.buildNodes();
111
- this.needsUpdate = true;
112
- }
113
- }
114
- buildNodes() {
115
- const volume = vdbVolumeNodes(this.source, this.sourceUniforms, { useMipmaps: this.mipmaps, ...(this.emissionColor ? { emissionColor: this.emissionColor } : {}) });
116
- const { frameWorldToLocal, frameAbsorbance } = this.volumeUniforms;
117
- const frameWorldScale = this.sourceUniforms.worldScale;
118
- const { frameSlot, frameTargetSize, frameEmitterCenter, frameEmitterRadius, frameSteps } = this;
119
- const outputIntensity = property("vec4");
120
- const outputCenter = property("vec4");
121
- // NOTE The quad covers the row of the slot
122
- this.vertexNode = vec4(positionGeometry.x, frameSlot.add(positionGeometry.y.mul(0.5).add(0.5)).div(frameTargetSize.y).mul(2.0).sub(1.0), 0.0, 1.0);
123
- this.colorNode = Fn(() => {
124
- const index = floor(frameFragCoord(frameTargetSize).x).toVar();
125
- // NOTE Fibonacci sphere direction, from the volume to the viewer
126
- const y = float(1.0).sub(index.mul(2.0).add(1.0).div(directionCount)).toVar();
127
- const ring = sqrt(max(0.0, float(1.0).sub(y.mul(y))));
128
- const phi = index.mul(goldenAngle);
129
- const direction = vec3(cos(phi).mul(ring), y, sin(phi).mul(ring)).toVar();
130
- const helper = select(abs(direction.y).lessThan(0.999), vec3(0.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0));
131
- const tangent = normalize(cross(helper, direction)).toVar();
132
- const bitangent = cross(direction, tangent).toVar();
133
- const diameter = frameEmitterRadius.mul(2.0).toVar();
134
- const spacing = diameter.div(rayCount).toVar();
135
- const stepCount = float(frameSteps).toVar();
136
- const intensity = vec3(0.0).toVar();
137
- const center = vec4(0.0).toVar();
138
- Loop({ start: int(0), end: int(rayCount * rayCount), type: "int", condition: "<", name: "r" }, ({ r }) => {
139
- const u = float(r.mod(int(rayCount))).add(0.5).div(rayCount).mul(2.0).sub(1.0);
140
- const v = float(r.div(int(rayCount))).add(0.5).div(rayCount).mul(2.0).sub(1.0);
141
- const worldStart = frameEmitterCenter.add(direction.mul(frameEmitterRadius)).add(tangent.mul(u.mul(frameEmitterRadius))).add(bitangent.mul(v.mul(frameEmitterRadius))).toVar();
142
- const worldEnd = worldStart.sub(direction.mul(diameter)).toVar();
143
- const localStart = frameWorldToLocal.mul(vec4(worldStart, 1.0)).xyz.toVar();
144
- const localEnd = frameWorldToLocal.mul(vec4(worldEnd, 1.0)).xyz.toVar();
145
- const segment = volume.boxSegment(localStart, localEnd).toVar();
146
- If(segment.x.lessThan(segment.y), () => {
147
- const segmentLength = segment.y.sub(segment.x).toVar();
148
- const stepLength = segmentLength.mul(diameter).div(stepCount).toVar();
149
- // NOTE Smoke uses the mip level of the step. Emission uses level 0: power grows with temperature^4, mipmaps lose it.
150
- const lod = volume.getLod(stepLength.div(frameWorldScale)).toVar();
151
- const transmittance = float(1.0).toVar();
152
- Loop({ start: int(0), end: frameSteps, type: "int", condition: "<", name: "s" }, ({ s }) => {
153
- const t = segment.x.add(segmentLength.mul(float(s).add(0.5).div(stepCount))).toVar();
154
- const localPosition = mix(localStart, localEnd, t).toVar();
155
- const extinction = volume.sampleExtinction(localPosition, lod).toVar();
156
- If(extinction.greaterThan(0.0), () => {
157
- // NOTE Absorbance scales the shadow of the volume, the same as for scene lights
158
- const alpha = float(1.0).sub(exp(extinction.mul(stepLength).negate()));
159
- const radiance = volume.sampleEmission(localPosition, float(0.0)).mul(transmittance.mul(alpha)).toVar();
160
- intensity.addAssign(radiance);
161
- center.addAssign(vec4(mix(worldStart, worldEnd, t), 1.0).mul(luminance(radiance)));
162
- transmittance.mulAssign(exp(extinction.mul(frameAbsorbance).mul(stepLength).negate()));
163
- If(transmittance.lessThan(0.01), () => {
164
- Break();
165
- });
166
- });
167
- });
168
- });
169
- });
170
- const area = spacing.mul(spacing);
171
- outputIntensity.assign(vec4(intensity.mul(area), frameEmitterRadius));
172
- outputCenter.assign(center.mul(area));
173
- return vec4(0.0);
174
- })();
175
- this.outputNode = outputStruct(outputIntensity, outputCenter);
176
- }
177
- }
178
- /** One texel per volume: the mean intensity of all directions, and the centre of the visible emission. Twin: `vdbFrameEmissionReduce`. */
179
- export class VDBFrameEmissionReduceMaterial extends NodeMaterial {
180
- frameTargetSize = uniform(new THREE.Vector2(1.0, 1.0));
181
- frameDirectionSize = uniform(new THREE.Vector2(directionCount, 1.0));
182
- frameDirectionIntensity = texture(new THREE.Texture());
183
- frameDirectionCenter = texture(new THREE.Texture());
184
- constructor() {
185
- super();
186
- this.name = "VDBFrameEmissionReduceMaterial";
187
- const outputIntensity = property("vec4");
188
- const outputCenter = property("vec4");
189
- this.vertexNode = frameFullscreenVertex;
190
- this.colorNode = Fn(() => {
191
- const row = int(floor(frameFragCoord(this.frameTargetSize).y)).toVar();
192
- const intensity = vec4(0.0).toVar();
193
- const center = vec4(0.0).toVar();
194
- Loop(directionCount, ({ i }) => {
195
- const texel = ivec2(i, row);
196
- intensity.addAssign(frameLoad(this.frameDirectionIntensity, texel, this.frameDirectionSize));
197
- center.addAssign(frameLoad(this.frameDirectionCenter, texel, this.frameDirectionSize));
198
- });
199
- const visible = center.w.greaterThan(0.0);
200
- outputIntensity.assign(intensity.div(directionCount));
201
- outputCenter.assign(select(visible, vec4(center.xyz.div(max(center.w, 1e-12)), 1.0), vec4(0.0)));
202
- return vec4(0.0);
203
- })();
204
- this.outputNode = outputStruct(outputIntensity, outputCenter);
205
- setPassMaterial(this);
206
- }
207
- }
208
- /**
209
- * L1 irradiance of all volumes at each probe, E(n) = x + dot(yzw, n) per colour channel: each volume is a point light
210
- * at its emission centre, its radius softening the distance near it. Twin: `vdbFrameEmissionProbe`.
211
- */
212
- export class VDBFrameEmissionProbeMaterial extends NodeMaterial {
213
- gridUniforms = createProbeGridUniforms();
214
- frameEmitterCount = uniform(0, "int");
215
- frameEmitterSize = uniform(new THREE.Vector2(1.0, 1.0));
216
- frameEmitterIntensity = texture(new THREE.Texture());
217
- frameEmitterCenter = texture(new THREE.Texture());
218
- constructor() {
219
- super();
220
- this.name = "VDBFrameEmissionProbeMaterial";
221
- const outputRed = property("vec4");
222
- const outputGreen = property("vec4");
223
- const outputBlue = property("vec4");
224
- const grid = createGridNodes(this.gridUniforms);
225
- const { frameGridMin, frameGridSize, frameGridCount, frameGridResolution, frameGridAtlasSize } = this.gridUniforms;
226
- this.vertexNode = frameFullscreenVertex;
227
- this.colorNode = Fn(() => {
228
- const fragCoord = frameFragCoord(frameGridAtlasSize).toVar();
229
- // NOTE Tiles right of the atlas columns are not used. Smaller grids leave them empty.
230
- If(fragCoord.x.greaterThanEqual(frameGridResolution.mul(atlasColumns)), () => {
231
- Discard();
232
- });
233
- const cell = grid.getGridCell(fragCoord);
234
- If(cell.cascade.greaterThanEqual(frameGridCount), () => {
235
- Discard();
236
- });
237
- const probe = frameGridMin.element(cell.cascade).add(cell.gridUvw.mul(frameGridSize.element(cell.cascade))).toVar();
238
- const constant = vec3(0.0).toVar();
239
- const directionRed = vec3(0.0).toVar();
240
- const directionGreen = vec3(0.0).toVar();
241
- const directionBlue = vec3(0.0).toVar();
242
- Loop(this.frameEmitterCount, ({ i }) => {
243
- const texel = ivec2(int(0), i);
244
- const center = frameLoad(this.frameEmitterCenter, texel, this.frameEmitterSize).toVar();
245
- If(center.w.greaterThan(0.0), () => {
246
- const emitter = frameLoad(this.frameEmitterIntensity, texel, this.frameEmitterSize).toVar();
247
- const toProbe = probe.sub(center.xyz).toVar();
248
- const distanceSquared = dot(toProbe, toProbe).toVar();
249
- const soft = emitter.w.mul(0.25);
250
- const softDistanceSquared = distanceSquared.add(soft.mul(soft)).toVar();
251
- const irradiance = emitter.rgb.div(softDistanceSquared).toVar();
252
- // NOTE L1 projection of a point light: E(n) = E / 4 + E / 2 * dot(l, n). The direction fades near the centre.
253
- const toLight = toProbe.mul(inverseSqrt(max(distanceSquared, 1e-12))).mul(distanceSquared.div(softDistanceSquared).mul(-0.5)).toVar();
254
- constant.addAssign(irradiance.mul(0.25));
255
- directionRed.addAssign(toLight.mul(irradiance.r));
256
- directionGreen.addAssign(toLight.mul(irradiance.g));
257
- directionBlue.addAssign(toLight.mul(irradiance.b));
258
- });
259
- });
260
- outputRed.assign(vec4(constant.r, directionRed));
261
- outputGreen.assign(vec4(constant.g, directionGreen));
262
- outputBlue.assign(vec4(constant.b, directionBlue));
263
- return vec4(0.0);
264
- })();
265
- this.outputNode = outputStruct(outputRed, outputGreen, outputBlue);
266
- setPassMaterial(this);
267
- }
268
- }
35
+ import { vdbThreeStorageStandIn } from "../grid-node.js";
36
+ import { getDevice } from "../device.js";
37
+ import { frameEmissionMaxCascades as maxCascades } from "../../tools/frame/emission.js";
38
+ import { vdbFrameCheckLightReset, vdbFramePrecompiling, vdbFrameRegisterLightNode, vdbFrameRenderUpdateType } from "./three-internals.js";
39
+ import { VDBCoreTextureBinding, vdbCoreTextureSelfTest } from "./core-textures.js";
40
+ import { VDBFrameStructLoaderNode, vdbFrameStructWords } from "./core-structs.js";
41
+ import { VDB_EMISSION_GRID, vdbEmissionProbeWgsl } from "../../core/frame/wgsl/emission.js";
42
+ const { code, normalWorld, positionWorld, sampler, storage, texture3D, wgslFn } = TSL;
43
+ /** `vec4u` words of the grid struct. */
44
+ const GRID_WORDS = vdbFrameStructWords(VDB_EMISSION_GRID);
45
+ /** The core's receiver function and the grid struct, one code node shared by every receiver (once per shader). */
46
+ let receiverCode = null;
47
+ const receiverCodeNode = () => (receiverCode ??= code(vdbEmissionProbeWgsl()));
48
+ /** Light nodes made so far: names each one's storage binding and WGSL functions. */
49
+ let names = 0;
269
50
  /**
270
- * The irradiance at a lit point from the finest probe cascade that contains it; near a cascade side the next one
271
- * blends in (as the shadow grid); past the last cascade its clamped edge probes fall off with distance squared.
51
+ * The irradiance at a lit point from the core's probe cascades (`vdbEmissionIrradiance`: the finest cascade that holds
52
+ * it, blended into the next one near its sides; past the last cascade its clamped edge probes fall off with distance
53
+ * squared), times the light's colour × intensity.
272
54
  */
273
55
  export class VDBFrameEmissionLightNode extends AnalyticLightNode {
274
56
  static get type() {
275
57
  return "VDBFrameEmissionLightNode";
276
58
  }
277
- probeMaps;
278
- gridUniforms;
279
- probeCenter;
280
- probeActive;
59
+ /** Unique per light node: names the storage binding and the WGSL functions. */
60
+ k = names++;
61
+ #nodes = null;
62
+ // NOTE Replaced grid stand-ins. update() runs mid-render, so the next update() disposes them.
63
+ #retired = [];
281
64
  constructor(light = null) {
282
65
  super(light);
283
- // NOTE The passes run before the first lit mesh of each render, as shadow maps
66
+ // NOTE The core update runs before the first lit mesh of each render, as shadow maps
284
67
  const render = vdbFrameRenderUpdateType();
285
68
  this.updateType = render;
286
69
  this.updateBeforeType = render;
287
- const maps = light ? light.probeTarget.textures : [new THREE.Texture(), new THREE.Texture(), new THREE.Texture()];
288
- this.probeMaps = maps.map((map) => texture(map));
289
- // NOTE Render group, as three's lights: lit materials without node changes update only shared uniforms
290
- this.gridUniforms = createProbeGridUniforms(renderGroup);
291
- this.probeCenter = uniform(new THREE.Vector3()).setGroup(renderGroup);
292
- this.probeActive = uniform(0.0).setGroup(renderGroup);
293
70
  }
294
71
  get emissionLight() {
295
72
  return this.light;
296
73
  }
74
+ /** The probe stack and grid bound now (null before the first receiver build); tests and harnesses. @internal */
75
+ get bound() {
76
+ const nodes = this.#nodes;
77
+ if (!nodes)
78
+ return null;
79
+ return { texture: this.emissionLight.coreBinding.gpu, grid: nodes.gridBuffer, placeholder: nodes.gridBuffer === nodes.placeholders.grid };
80
+ }
297
81
  updateBefore(frame) {
298
82
  const { renderer, scene, camera } = frame;
299
- // NOTE No passes while three precompiles materials (compileAsync), as shadow maps
300
- if (vdbFramePrecompiling(renderer)) {
83
+ // NOTE No update while three precompiles materials (compileAsync), as shadow maps
84
+ if (vdbFramePrecompiling(renderer))
301
85
  return undefined;
302
- }
303
86
  this.emissionLight.updateProbes(renderer, scene, camera);
304
87
  return undefined;
305
88
  }
306
89
  update(frame) {
307
90
  super.update(frame);
308
- const light = this.emissionLight;
309
- setProbeGridUniforms(this.gridUniforms, light);
310
- this.probeCenter.value.copy(light.probeCenter);
311
- this.probeActive.value = light.emitterCount > 0 ? 1.0 : 0.0;
91
+ this.#retired.forEach((a) => a.dispose());
92
+ this.#retired.length = 0;
93
+ this.#bind(this.emissionLight.coreProbes);
312
94
  return undefined;
313
95
  }
96
+ /**
97
+ * Points the nodes at the core's probes (null: the placeholders). A new core object gets a new stand-in as the node's
98
+ * `value` and bumps this node's `version`, so the receivers rebuild at their next render (see the file comment).
99
+ */
100
+ #bind(probes) {
101
+ const nodes = this.#nodes;
102
+ if (!nodes)
103
+ return;
104
+ const p = nodes.placeholders;
105
+ let changed = false;
106
+ const binding = this.emissionLight.coreBinding;
107
+ if (binding.set(probes?.texture ?? p.texture)) {
108
+ nodes.probes.value = binding.texture;
109
+ changed = true;
110
+ }
111
+ const grid = probes?.grid ?? p.grid;
112
+ if (grid !== nodes.gridBuffer) {
113
+ this.#retired.push(nodes.grid.value);
114
+ nodes.grid.value = vdbThreeStorageStandIn(nodes.renderer, grid, `vdbEmissionGrid${this.k}`);
115
+ nodes.gridBuffer = grid;
116
+ changed = true;
117
+ }
118
+ if (changed)
119
+ this.needsUpdate = true;
120
+ }
121
+ #nodesOf(renderer) {
122
+ if (this.#nodes) {
123
+ if (this.#nodes.renderer === renderer)
124
+ return this.#nodes;
125
+ throw new Error("VDBFrameEmissionLight: its receivers were built by a second renderer; a light (and its scene) belongs to one renderer");
126
+ }
127
+ // NOTE The rebuild on a new core object needs three's lights cache key to follow this node's version (internal 1)
128
+ vdbFrameCheckLightReset();
129
+ const device = getDevice(renderer);
130
+ vdbCoreTextureSelfTest(renderer, device);
131
+ const placeholders = {
132
+ texture: device.createTexture({ label: "@pmndrs/vdb/three emission probes placeholder", size: [1, 1, 1], dimension: "3d", format: "rgba16float", usage: 0x04 /* TEXTURE_BINDING */ }),
133
+ // A zero grid: info.x (cascades) 0, so vdbEmissionIrradiance returns 0 without sampling
134
+ grid: device.createBuffer({ label: "@pmndrs/vdb/three emission grid placeholder", size: VDB_EMISSION_GRID.size, usage: 0x80 /* STORAGE */ }),
135
+ };
136
+ const light = this.emissionLight;
137
+ const probes = light.coreProbes;
138
+ light.coreBinding.set(probes?.texture ?? placeholders.texture);
139
+ const gridBuffer = probes?.grid ?? placeholders.grid;
140
+ const grid = storage(vdbThreeStorageStandIn(renderer, gridBuffer, `vdbEmissionGrid${this.k}`), "uvec4", GRID_WORDS).toReadOnly();
141
+ grid.setName(`vdbEmissionGrid${this.k}`);
142
+ const loader = new VDBFrameStructLoaderNode(grid, VDB_EMISSION_GRID, `vdbFrameEmissionGrid${this.k}`);
143
+ const name = `vdbFrameEmissionReceiver${this.k}`;
144
+ const source = `fn ${name}(probes: texture_3d<f32>, smp: sampler, world: vec3f, normal: vec3f) -> vec3f {\n return vdbEmissionIrradiance(probes, smp, ${loader.fnName}(), world, normal);\n}`;
145
+ const fn = wgslFn(source, [receiverCodeNode(), loader]);
146
+ this.#nodes = { renderer, placeholders, probes: texture3D(light.coreBinding.texture), grid, gridBuffer, fn };
147
+ return this.#nodes;
148
+ }
314
149
  setup(builder) {
315
- const grid = createGridNodes(this.gridUniforms);
316
- const { frameGridMin, frameGridSize, frameGridCount, frameGridResolution } = this.gridUniforms;
317
- const { probeCenter, probeActive } = this;
318
- const [redMap, greenMap, blueMap] = this.probeMaps;
319
- const irradiance = Fn(() => {
320
- const position = positionWorld.toVar();
321
- const red = vec4(0.0).toVar();
322
- const green = vec4(0.0).toVar();
323
- const blue = vec4(0.0).toVar();
324
- const falloff = float(1.0).toVar();
325
- const sampleProbes = (cascade, uvw, weight) => {
326
- red.assign(mix(red, grid.sampleGrid(redMap, cascade, uvw), weight));
327
- green.assign(mix(green, grid.sampleGrid(greenMap, cascade, uvw), weight));
328
- blue.assign(mix(blue, grid.sampleGrid(blueMap, cascade, uvw), weight));
329
- };
330
- If(frameGridCount.greaterThan(0), () => {
331
- const cascade = grid.findCascade(position, int(0)).toVar();
332
- If(cascade.greaterThanEqual(0), () => {
333
- const uvw = grid.gridUvw(cascade, position).toVar();
334
- sampleProbes(cascade, uvw, float(1.0));
335
- const sideDistance = min(uvw, vec3(1.0).sub(uvw));
336
- const blend = float(1.0).sub(smoothstep(0.0, 0.1, min(sideDistance.x, min(sideDistance.y, sideDistance.z)))).toVar();
337
- If(blend.greaterThan(0.0), () => {
338
- const nextCascade = grid.findCascade(position, cascade.add(1)).toVar();
339
- If(nextCascade.greaterThanEqual(0), () => {
340
- sampleProbes(nextCascade, grid.gridUvw(nextCascade, position), blend);
341
- });
342
- });
343
- }).Else(() => {
344
- const lastCascade = frameGridCount.sub(1).toVar();
345
- const inset = float(0.5).div(frameGridResolution);
346
- const uvw = clamp(grid.gridUvw(lastCascade, position), vec3(inset), vec3(float(1.0).sub(inset))).toVar();
347
- const toEdge = frameGridMin.element(lastCascade).add(uvw.mul(frameGridSize.element(lastCascade))).sub(probeCenter);
348
- const toPoint = position.sub(probeCenter);
349
- sampleProbes(lastCascade, uvw, float(1.0));
350
- falloff.assign(min(1.0, dot(toEdge, toEdge).div(max(dot(toPoint, toPoint), 1e-6))));
351
- });
352
- });
353
- const normal = normalWorld;
354
- return max(vec3(red.x.add(dot(red.yzw, normal)), green.x.add(dot(green.yzw, normal)), blue.x.add(dot(blue.yzw, normal))), vec3(0.0)).mul(falloff.mul(probeActive));
355
- })();
356
150
  const b = builder;
151
+ const nodes = this.#nodesOf(b.renderer);
152
+ const irradiance = nodes.fn({ probes: nodes.probes, smp: sampler(nodes.probes), world: positionWorld, normal: normalWorld });
357
153
  const colorNode = this.colorNode;
358
154
  b.context.irradiance.addAssign(colorNode.mul(irradiance));
359
155
  return null;
360
156
  }
361
- }
362
- const unitBox = new THREE.Box3(new THREE.Vector3(-0.5, -0.5, -0.5), new THREE.Vector3(0.5, 0.5, 0.5));
363
- const cameraPosition = new THREE.Vector3();
364
- const createEmitter = () => ({
365
- frameVolume: null,
366
- key: "",
367
- matrix: new THREE.Matrix4(),
368
- matrixWorld: new THREE.Matrix4(),
369
- worldToLocal: new THREE.Matrix4(),
370
- localToView: new THREE.Matrix4(),
371
- viewToLocal: new THREE.Matrix4(),
372
- worldBox: new THREE.Box3(),
373
- viewNear: 0,
374
- viewFar: 0,
375
- ready: true,
376
- center: new THREE.Vector3(),
377
- radius: 0.0,
378
- });
379
- // NOTE An id for each source object (the emitter key: a new source or a replaced grid draws again)
380
- const sourceIds = new WeakMap();
381
- let nextSourceId = 1;
382
- const sourceKey = (frameVolume) => {
383
- const source = frameVolume.source;
384
- let id = sourceIds.get(source);
385
- if (id === undefined) {
386
- id = nextSourceId++;
387
- sourceIds.set(source, id);
388
- }
389
- const values = [id, source.version ?? -1, source.lodLevels, source.lod ?? "-"];
390
- if (source.textures) {
391
- for (const name of ["density", "mask", "emission"]) {
392
- const t = source.textures[name];
393
- values.push(t ? `${t.map.id}.${t.map.version}` : "-", t?.mip ? `${t.mip.id}.${t.mip.version}` : "-");
157
+ dispose() {
158
+ const nodes = this.#nodes;
159
+ if (nodes) {
160
+ this.#retired.push(nodes.grid.value);
161
+ const p = nodes.placeholders;
162
+ // NOTE A bind group of this render may still name them: destroy after the task that submits it
163
+ setTimeout(() => {
164
+ p.texture.destroy();
165
+ p.grid.destroy();
166
+ }, 0);
167
+ this.#nodes = null;
394
168
  }
169
+ this.#retired.forEach((a) => a.dispose());
170
+ this.#retired.length = 0;
171
+ super.dispose();
395
172
  }
396
- // NOTE The colour hook's runtime value (vdbFrameBlackbodyEmission: the soot exponent)
397
- const hook = frameVolume.emissionColor;
398
- values.push(hook?.sootExponent ? hook.sootExponent.value : "-");
399
- return values.join(":");
400
- };
173
+ }
401
174
  /** One registration of the light node class (internal 4), checked at the first construction. */
402
175
  let registered = false;
176
+ /**
177
+ * Light that lights lit meshes with the emission of emissive `VDBFrameVolume`s (his `FrameEmissionLight`): the core
178
+ * frame renderer of the scene's volumes draws the emitters and the probe cascades; this light's node reads them. Add
179
+ * it to the scene.
180
+ */
403
181
  export class VDBFrameEmissionLight extends THREE.Light {
182
+ /** Type flag. */
404
183
  isVDBFrameEmissionLight = true;
184
+ /** Probes on each axis of each cascade, 2 to 32. */
405
185
  resolution;
186
+ /** Size of the last cascade as a multiple of the box of all emitting volumes. */
406
187
  range;
188
+ /** Probe grid cascades, 1 to 4 (1: one grid for all volumes). */
407
189
  cascades;
190
+ /** Distance from the camera that the finer cascades cover. */
408
191
  distance;
192
+ /** Steps of each ray in a volume (rounded, at least 1). */
409
193
  steps;
194
+ /** Minimum corner of each cascade in world space (valid for the first `cascadeCount`). */
410
195
  cascadeMin = Array.from({ length: maxCascades }, () => new THREE.Vector3());
196
+ /** Size of each cascade in world space (valid for the first `cascadeCount`). */
411
197
  cascadeSize = Array.from({ length: maxCascades }, () => new THREE.Vector3(1.0, 1.0, 1.0));
198
+ /** Cascades in use after the last probe update. */
412
199
  cascadeCount = 0;
200
+ /** Probes on each axis of each cascade after the last update. */
413
201
  probeResolution = 2;
202
+ /** World centre of the probe grid after the last update. */
414
203
  probeCenter = new THREE.Vector3();
415
- emitters = [];
204
+ /** Emissive volumes in the last update. */
416
205
  emitterCount = 0;
417
- slotKeys = [];
418
- slotCount = 0;
419
- probeKey = "";
420
- // NOTE Float targets for the volumes: intensities in world units do not overflow
421
- directionTarget = createTarget(2, THREE.FloatType, THREE.NearestFilter);
422
- emitterTarget = createTarget(2, THREE.FloatType, THREE.NearestFilter);
423
- // NOTE The probe atlas has the size for the largest grid and all cascades: lit materials keep its binding
424
- probeTarget = createTarget(3, THREE.HalfFloatType, THREE.LinearFilter, atlasSize, atlasSize);
425
- // NOTE One draw for each changed volume, in one render
426
- directionScene = new THREE.Scene();
427
- directionPool = [];
428
- reduceMaterial = new VDBFrameEmissionReduceMaterial();
429
- probeMaterial = new VDBFrameEmissionProbeMaterial();
430
- reduceScene;
431
- probeScene;
432
- // NOTE WebGPURenderer calls updateProjectionMatrix() on the camera
433
- passCamera = new THREE.OrthographicCamera();
434
- // NOTE RendererUtils fills this object
435
- rendererState = {};
436
206
  /** Volumes drawn in the last probe update and whether the probes were drawn (not his; tests and timing). */
437
207
  lastUpdate = { directions: 0, probes: false };
208
+ /** The core's probes after the last update (null: none). */
209
+ coreProbes = null;
210
+ /** @internal The stand-in of the core probe stack. */
211
+ coreBinding = new VDBCoreTextureBinding("3d");
212
+ /**
213
+ * Makes the light with its probe grid settings.
214
+ * @param props {@link VDBFrameEmissionLightProps}; all fields optional.
215
+ */
438
216
  constructor(props = {}) {
439
217
  const { color = 0xffffff, intensity = 1.0, resolution = 16, range = 3.0, cascades = 1, distance = 512, steps = 24 } = props;
440
218
  super(color, intensity);
@@ -443,213 +221,56 @@ export class VDBFrameEmissionLight extends THREE.Light {
443
221
  registered = true;
444
222
  }
445
223
  this.type = "VDBFrameEmissionLight";
224
+ // K6.8b: always on, and the light casts no shadow (its node draws none). three r187's lights cache key holds the node
225
+ // version of a castShadow light only; the node bumps it to rebuild its receivers when the core makes new probes.
226
+ Object.defineProperty(this, "castShadow", { get: () => true, set: () => { }, configurable: true, enumerable: true });
446
227
  this.resolution = resolution;
447
228
  this.range = range;
448
229
  this.cascades = cascades;
449
230
  this.distance = distance;
450
231
  this.steps = steps;
451
- this.directionScene.matrixWorldAutoUpdate = false;
452
- const createPassScene = (material) => {
453
- const scene = new THREE.Scene();
454
- const mesh = new THREE.Mesh(createGeometry(fullscreenPositions), material);
455
- mesh.frustumCulled = false;
456
- scene.matrixWorldAutoUpdate = false;
457
- scene.add(mesh);
458
- return scene;
459
- };
460
- this.reduceScene = createPassScene(this.reduceMaterial);
461
- this.probeScene = createPassScene(this.probeMaterial);
462
232
  }
233
+ /** Steps of each ray, rounded and at least 1. */
463
234
  getSteps() {
464
235
  return Math.max(1, Math.round(this.steps));
465
236
  }
466
- /** The direction-pass material of a volume (its source compiled in), made on first use. */
467
- getDirectionMaterial(frameVolume) {
468
- const mipmaps = frameVolume.mipmaps && frameVolume.source.lodLevels > 0;
469
- let material = frameVolume.emissionDirectionMaterial;
470
- if (!material) {
471
- material = new VDBFrameEmissionDirectionMaterial({ source: frameVolume.source, sourceUniforms: frameVolume.sourceUniforms, mipmaps, ...(frameVolume.emissionColor ? { emissionColor: frameVolume.emissionColor } : {}) });
472
- frameVolume.emissionDirectionMaterial = material;
473
- }
474
- material.setMipmaps(mipmaps);
475
- return material;
476
- }
477
- // NOTE Emissive volumes of the scene (visible, with an emission channel)
478
- collectEmitters(scene) {
479
- let count = 0;
480
- const steps = this.getSteps();
481
- scene.traverseVisible((object) => {
482
- const frameVolume = object;
483
- if (!frameVolume.isVDBFrameVolume || !frameVolume.source.channels.emission) {
484
- return;
485
- }
486
- for (const volume of frameVolume.volumes) {
487
- if (!volume.ready) {
488
- continue;
489
- }
490
- if (!this.emitters[count]) {
491
- this.emitters[count] = createEmitter();
492
- }
493
- const emitter = this.emitters[count++];
494
- emitter.frameVolume = frameVolume;
495
- emitter.matrixWorld.multiplyMatrices(frameVolume.matrixWorld, volume.matrix);
496
- emitter.worldToLocal.copy(emitter.matrixWorld).invert();
497
- emitter.worldBox.copy(unitBox).applyMatrix4(emitter.matrixWorld);
498
- const bounds = vdbFrameEmitterBounds(emitter.matrixWorld.elements);
499
- emitter.center.fromArray(bounds.center);
500
- emitter.radius = bounds.radius;
501
- emitter.key = [
502
- sourceKey(frameVolume),
503
- frameVolume.extinction,
504
- frameVolume.getDensityScale(),
505
- frameVolume.densityCutoff,
506
- frameVolume.absorbance,
507
- frameVolume.emissiveIntensity,
508
- frameVolume.temperatureRange.x,
509
- frameVolume.temperatureRange.y,
510
- frameVolume.offset3D.x,
511
- frameVolume.offset3D.y,
512
- frameVolume.offset3D.z,
513
- frameVolume.wrap3D,
514
- frameVolume.mipmaps,
515
- steps,
516
- ...emitter.matrixWorld.elements,
517
- ].join(",");
518
- }
519
- });
520
- this.emitterCount = count;
521
- }
522
- // NOTE The probe cascades (tools/frame/emission.ts). Returns a key that changes with them.
523
- updateProbeGrid(camera) {
524
- cameraPosition.setFromMatrixPosition(camera.matrixWorld);
525
- const boxes = this.emitters.slice(0, this.emitterCount).map((e) => ({ min: e.worldBox.min.toArray(), max: e.worldBox.max.toArray() }));
526
- const grid = vdbFrameEmissionProbeGrid({ resolution: this.resolution, range: this.range, cascades: this.cascades, distance: this.distance }, boxes, cameraPosition.toArray());
527
- this.probeResolution = grid.resolution;
528
- this.probeCenter.fromArray(grid.center);
529
- for (let i = 0; i < grid.count; i++) {
530
- this.cascadeMin[i].fromArray(grid.min[i]);
531
- this.cascadeSize[i].fromArray(grid.size[i]);
532
- }
533
- this.cascadeCount = grid.count;
534
- return grid.key;
535
- }
536
- // NOTE The changed volumes as { emitter, slot }, or null when the probes stay the same.
537
- // Slots grow to the next power of two. New targets are empty, so all volumes draw again.
538
- prepareProbes(scene, camera) {
539
- this.collectEmitters(scene);
540
- if (this.emitterCount > this.slotCount) {
541
- this.slotCount = Math.pow(2, Math.ceil(Math.log2(this.emitterCount)));
542
- this.slotKeys = [];
543
- this.resizeSlots();
544
- }
545
- const changed = [];
546
- for (let i = 0; i < this.emitterCount; i++) {
547
- const emitter = this.emitters[i];
548
- if (this.slotKeys[i] !== emitter.key) {
549
- this.slotKeys[i] = emitter.key;
550
- changed.push({ emitter, slot: i });
551
- }
552
- }
553
- if (this.emitterCount === 0) {
554
- this.probeKey = "";
555
- return null;
556
- }
557
- const probeKey = `${this.emitterCount},${this.updateProbeGrid(camera)}`;
558
- if (changed.length === 0 && probeKey === this.probeKey) {
559
- return null;
560
- }
561
- this.probeKey = probeKey;
562
- return changed;
563
- }
564
- // NOTE New targets, because setSize() destroys the GPU textures that materials still bind
565
- resizeSlots() {
566
- this.directionTarget.dispose();
567
- this.emitterTarget.dispose();
568
- this.directionTarget = createTarget(2, THREE.FloatType, THREE.NearestFilter, directionCount, this.slotCount);
569
- this.emitterTarget = createTarget(2, THREE.FloatType, THREE.NearestFilter, 1, this.slotCount);
570
- }
571
- getDirectionMesh(index) {
572
- if (!this.directionPool[index]) {
573
- const mesh = new THREE.Mesh(createGeometry(quadPositions), new THREE.MeshBasicMaterial());
574
- mesh.frustumCulled = false;
575
- mesh.matrixAutoUpdate = false;
576
- mesh.onBeforeRender = () => {
577
- const { emitter, slot } = mesh.userData;
578
- const material = mesh.material;
579
- setVolumeUniforms(material, emitter.frameVolume, emitter);
580
- material.frameSlot.value = slot;
581
- material.frameTargetSize.value.set(directionCount, this.slotCount);
582
- material.frameEmitterCenter.value.copy(emitter.center);
583
- material.frameEmitterRadius.value = emitter.radius;
584
- material.frameSteps.value = this.getSteps();
585
- };
586
- this.directionScene.add(mesh);
587
- this.directionPool[index] = mesh;
588
- }
589
- return this.directionPool[index];
590
- }
591
- /** Runs the passes of changed volumes. The light node calls it before the lit meshes of each render. */
237
+ /**
238
+ * The core frame of this render (the frame renderer of the scene's first visible volume) draws the emitters and the
239
+ * probes; this light copies the probe grid for its node. The light node calls it before the lit meshes of each render.
240
+ */
592
241
  updateProbes(renderer, scene, viewCamera) {
593
242
  this.lastUpdate.directions = 0;
594
243
  this.lastUpdate.probes = false;
595
- const changed = this.prepareProbes(scene, viewCamera);
596
- if (!changed) {
597
- return;
598
- }
599
- changed.forEach(({ emitter, slot }, index) => {
600
- const mesh = this.getDirectionMesh(index);
601
- mesh.material = this.getDirectionMaterial(emitter.frameVolume);
602
- mesh.userData.emitter = emitter;
603
- mesh.userData.slot = slot;
244
+ let frameRenderer = null;
245
+ scene.traverseVisible((object) => {
246
+ const v = object;
247
+ if (!frameRenderer && v.isVDBFrameVolume)
248
+ frameRenderer = v.frameRenderer;
604
249
  });
605
- const { reduceMaterial, probeMaterial, reduceScene, probeScene, passCamera: camera } = this;
606
- const utils = vdbFrameRendererUtils();
607
- this.rendererState = utils.resetRendererState(renderer, this.rendererState);
608
- // NOTE Each pass writes all its texels. Rows of volumes that did not change stay.
609
- renderer.autoClear = false;
610
- try {
611
- if (changed.length > 0) {
612
- this.directionPool.forEach((mesh, index) => {
613
- mesh.visible = index < changed.length;
614
- });
615
- renderer.setRenderTarget(this.directionTarget);
616
- renderer.render(this.directionScene, camera);
617
- reduceMaterial.frameTargetSize.value.set(1, this.slotCount);
618
- reduceMaterial.frameDirectionSize.value.set(directionCount, this.slotCount);
619
- reduceMaterial.frameDirectionIntensity.value = this.directionTarget.textures[0];
620
- reduceMaterial.frameDirectionCenter.value = this.directionTarget.textures[1];
621
- renderer.setRenderTarget(this.emitterTarget);
622
- renderer.render(reduceScene, camera);
623
- }
624
- setProbeGridUniforms(probeMaterial.gridUniforms, this);
625
- probeMaterial.frameEmitterCount.value = this.emitterCount;
626
- probeMaterial.frameEmitterSize.value.set(1, this.slotCount);
627
- probeMaterial.frameEmitterIntensity.value = this.emitterTarget.textures[0];
628
- probeMaterial.frameEmitterCenter.value = this.emitterTarget.textures[1];
629
- renderer.setRenderTarget(this.probeTarget);
630
- renderer.render(probeScene, camera);
631
- this.lastUpdate.directions = changed.length;
632
- this.lastUpdate.probes = true;
250
+ const fr = frameRenderer;
251
+ fr?.coreFrame(renderer, scene, viewCamera);
252
+ const probes = fr?.core?.outputs.emissionProbes ?? null;
253
+ this.coreProbes = probes;
254
+ if (!probes) {
255
+ this.emitterCount = 0;
256
+ this.cascadeCount = 0;
257
+ return;
633
258
  }
634
- finally {
635
- utils.restoreRendererState(renderer, this.rendererState);
259
+ const { state } = probes;
260
+ this.emitterCount = state.emitters;
261
+ this.cascadeCount = state.count;
262
+ this.probeResolution = state.resolution;
263
+ this.probeCenter.fromArray(state.center);
264
+ for (let i = 0; i < state.count; i++) {
265
+ this.cascadeMin[i].fromArray(state.min[i]);
266
+ this.cascadeSize[i].fromArray(state.size[i]);
636
267
  }
268
+ this.lastUpdate.directions = probes.lastUpdate.directions;
269
+ this.lastUpdate.probes = probes.lastUpdate.probes;
637
270
  }
638
271
  dispose() {
639
272
  super.dispose();
640
- this.slotKeys = [];
641
- this.slotCount = 0;
642
- this.probeKey = "";
643
- this.directionTarget.dispose();
644
- this.emitterTarget.dispose();
645
- this.probeTarget.dispose();
646
- this.directionPool.forEach((mesh) => mesh.geometry.dispose());
647
- this.directionPool = [];
648
- this.reduceMaterial.dispose();
649
- this.probeMaterial.dispose();
650
- for (const scene of [this.reduceScene, this.probeScene]) {
651
- scene.children[0]?.geometry.dispose();
652
- }
273
+ this.coreBinding.dispose();
653
274
  }
654
275
  }
655
276
  //# sourceMappingURL=emission-light.js.map