@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,1479 +1,461 @@
1
1
  // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
2
- // src/three-openvdb/frame/webgpu/FrameRenderer.js L79–135 (caster signatures, fullscreen geometry,
3
- // targets, scenes), L144–174 (getClipRect, getMaxTextureSize), L191–246 (settings, the ported
4
- // subset), L249–430 (fields, constructor), L431–481 (render, createProxyGeometry), L493–570
5
- // (isFrameLighting, renderEnvironmentGrid), L572–596 (renderEnvironmentMap), L598–645
6
- // (collectVolumes, usesShadowGrid, isNeural), L715–895 (getSliceRange, updateTargets,
7
- // updateGridTargets), L897–1005 (renderFrame, updateFroxelArea, renderTemporal), L1007–1061
8
- // (copyEnvironment, prepareLightScene, renderInject), L1063–1308 (renderFrameLighting,
9
- // transmittanceUnchanged, renderShadowDensity, updateGridVersion), L1347–1474 (pool setup,
10
- // updatePool, getFroxelRect, getCascadeCount, updateGrid, getGridRange), L1476–1716 (light
11
- // records, visitLight, updateLights), L1718–1784 (dispose);
12
- // src/three-openvdb/frame/webgpu/frameShaderChunks.js L800–830 (setVolumeUniforms);
13
- // K3.4: FrameRenderer.js L232–242 (multipleScattering 'neural' default, octave settings), L291–296 and
14
- // L642–699 (isNeural, the grid mip targets, renderGridMips), L1052–1056 and L1086–1098 (octaves,
15
- // two-sided and neural uniforms of the inject and transmittance passes), L1132 and L1201 (octaves of the
16
- // density and lighting passes), L506–518 and L559 (octaves in the environment grid signature and pass),
17
- // L1213–1226 (the neural, two-sided and octave fields of the transmittance signature);
18
- // K3.5: L176–189 (createAtlasTarget, isSpectralTarget), L335–337 (the spectral transmittance targets),
19
- // L514 and L556 (spectral in the environment grid signature and pass), L638–640 (isSpectral), L702–713
20
- // (getSpectralTransmittanceTarget), L725–866 (the spectral targets of updateTargets / updateGridTargets),
21
- // L908 (environment lights in both lighting modes), L973–1003 (the alpha targets of renderTemporal),
22
- // L1030 (the inject pass reads the scene environment), L1079–1196 (the slot group loop and the spectral maps
23
- // of renderFrameLighting), L1210–1231 (the spectral fields of the transmittance signature), L1303
24
- // (spectral in the grid signature);
25
- // K3.6: L218–230 (the castShadow* settings), L269 and L456 (volumeShadows, updated before each frame), L340–350
26
- // (gridRenderId / gridCamera, castVersion), L634–636 (usesShadowGrid with castShadows), L1250–1290
27
- // (renderShadowDensity onlyLast), L1310–1345 (prepareShadowGrid), L1719 (dispose of the volume shadows).
2
+ // src/three-openvdb/frame/webgpu/FrameRenderer.js L191–246 (the settings; now the core's), L431–481 (render: the
3
+ // first proxy of a render draws the frame, override passes draw nothing), L1476–1716 (visitLight: the scene's lights
4
+ // in the camera's layers).
28
5
  // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
29
- // Changes: TypeScript; one inject, density and shadow density material per volume source (the
30
- // source is compiled into each; DIVERGES V30); mesh shadows (K3.6, volume-shadows.ts); the neural
31
- // network is a settable value (`neuralNetwork`; null: diffusion, with a warning); per-pass timing
32
- // hooks and a redraw-skip counter. Divergences: DIVERGES.md (K3.1, K3.3
33
- // and K3.4 rows), V23–V25, V30–V34.
6
+ // Changes (K6.8): the TSL passes are gone; every frame is the core frame renderer (`vdbCreateFrameRenderer`, compute on
7
+ // three's device), recorded into its own encoder and submitted before three's frame. Divergences: DIVERGES.md (K3.1,
8
+ // K3.3, K6 rows).
34
9
  /**
35
- * The froxel renderer (K3.1 `'volume'` lighting, K3.3 `'frame'` lighting; R1 §2). Each
36
- * `VDBFrameVolume` proxy calls {@link VDBFrameRenderer.render} from `onBeforeRender`; the first
37
- * proxy in a render draws the froxels into a slice atlas, and every proxy then draws the integrate
38
- * material, which composites the atlas over the scene up to the scene depth.
39
- *
40
- * `'frame'` lighting: shadow density of every caster into a world grid (≤ 4 cascades, redrawn only
41
- * when its signature changes), transmittance from each grid voxel to ≤ 6 light slots and the sky,
42
- * an optional environment grid ('directional' / 'spherical-harmonics' environment lights from a
43
- * PMREM readback), the density pass per volume, one lighting pass for all volumes, then temporal
44
- * reprojection.
10
+ * The froxel renderer of `./three` (K6.8, design §6): a thin adapter over the core frame renderer. One
11
+ * core `VDBFrameRenderer` per three renderer device; in the first `VDBFrameVolume` proxy's `onBeforeRender` of a render (or
12
+ * a volume shadow receiver's / the emission light's `updateBefore`, whichever comes first) it collects the volumes in the
13
+ * camera's layers, converts the scene's lights (shadow cameras → volume shadow requests, three's shadow maps →
14
+ * occluders), passes `scene.environment`, records `core.update()` into its own encoder and submits; three's frame
15
+ * submits after it. Every proxy then draws the composite material over three's scene depth and colour.
45
16
  */
46
17
  import * as THREE from "three";
47
- import { NodeMaterial } from "three/webgpu";
48
- import * as TSL from "three/tsl";
49
- import { VDBFrameEnvironmentLights, frameEnvironmentMapHeight, frameEnvironmentMapWidth, frameEnvironmentModes } from "../../tools/frame/environment.js";
50
- import { vdbFrameCascadeCasters, vdbFrameGridCascades, vdbFrameGridRange, vdbFrameGridSignatureState, vdbFrameUpdateGridSignatures, vdbSameValues, vdbSignaturePushElements, vdbSignaturePushVector, } from "../../tools/frame/grid.js";
51
- import { createAreaUniforms, createEnvironmentGridUniforms, createFroxelUniforms, createGridUniforms, createLightUniforms, createTileUniforms, frameMaxHemisphereLights, frameMaxLights, frameMaxShadowCascades, frameTileVertex, } from "./chunks.js";
52
- import { VDBFrameDensityMaterial, createDensityShadowUniforms, frameDensityEnvironment } from "./density-material.js";
53
- import { VDBFrameEnvironmentMapMaterial } from "./environment-material.js";
54
- import { VDBFrameEnvironmentGridMaterial } from "./environment-grid-material.js";
55
- import { VDBFrameInjectMaterial } from "./inject-material.js";
56
- import { VDBFrameIntegrateMaterial } from "./integrate-material.js";
57
- import { getAtlasLayout, getFroxelSize } from "./layout.js";
58
- import { VDBFrameLightingMaterial } from "./lighting-material.js";
59
- import { getFramePhase, getFramePhaseSpectrum, getFrameMultipleScattering, getFrameScatteringOctaves, getFrameTwoSidedDiffusion, isFrameDiffusion } from "./phase.js";
60
- import { VDBFrameGridMipMaterial } from "./grid-mip-material.js";
61
- import { vdbFrameNeuralCheck } from "../../tools/frame/neural.js";
18
+ import { vdbFrameMlpFromNeural } from "../../tools/frame/mlp.js";
62
19
  import { vdbFrameNeuralWeights } from "../../tools/frame/neural-weights.js";
63
- import { VDBFrameShadowDensityMaterial } from "./shadow-density-material.js";
64
- import { getFrameExtinctionSpectrum, getFrameSpectralGroups } from "./spectrum.js";
65
- import { VDBFrameTemporalMaterial } from "./temporal-material.js";
66
- import { VDBFrameTransmittanceMaterial, frameNeuralMipLevels, frameShadowLightSlots } from "./transmittance-material.js";
67
- import { VDBFrameVolumeShadows } from "./volume-shadows.js";
68
- import { FrameVolumeCollector, getFrameFadeRadius, getFroxelArea, getFroxelRect, getFroxelSliceRange } from "./view.js";
69
- const { outputStruct, vec4 } = TSL;
70
- const clearColor = new THREE.Color();
71
- const vector3 = new THREE.Vector3();
72
- const froxelSize = { width: 1, height: 1 };
73
- const lightPosition = new THREE.Vector3();
74
- const lightTarget = new THREE.Vector3();
75
- const lightColor = new THREE.Color();
76
- const cameraPosition = new THREE.Vector3();
77
- const extinctionSpectrum = new THREE.Vector3();
78
- // NOTE Instanced, then frame volume proxies skip the draw with instanceCount 0 (three.js does not draw 0 instances)
79
- export const createFullscreenGeometry = () => {
80
- const geometry = new THREE.InstancedBufferGeometry();
81
- geometry.instanceCount = 1;
82
- geometry.setAttribute("position", new THREE.Float32BufferAttribute([-1, -1, 0, 3, -1, 0, -1, 3, 0], 3));
83
- return geometry;
84
- };
85
- const tileQuadPosition = new THREE.Float32BufferAttribute([-1, -1, 0, 1, -1, 0, 1, 1, 0, -1, -1, 0, 1, 1, 0, -1, 1, 0], 3);
86
- const createRenderTarget = (width, height, options = {}) => new THREE.RenderTarget(width, height, {
87
- type: THREE.HalfFloatType,
88
- format: THREE.RGBAFormat,
89
- minFilter: THREE.LinearFilter,
90
- magFilter: THREE.LinearFilter,
91
- generateMipmaps: false,
92
- depthBuffer: false,
93
- ...options,
94
- });
95
- // NOTE Froxel atlas. Spectral: a second target with the red and blue alpha (and the green alpha in w for blending).
96
- const createAtlasTarget = (width, height, spectral) => {
97
- if (!spectral) {
98
- return createRenderTarget(width, height);
99
- }
100
- const target = createRenderTarget(width, height, { count: 2 });
101
- target.textures[1].format = THREE.RGFormat;
102
- return target;
103
- };
104
- const isSpectralTarget = (target) => target.textures.length > 1;
105
- const createScene = () => {
106
- const scene = new THREE.Scene();
107
- scene.matrixWorldAutoUpdate = false;
108
- return scene;
109
- };
110
- // NOTE Instanced tile quads: one instance for each slice
111
- const createTileGeometry = () => {
112
- const geometry = new THREE.InstancedBufferGeometry();
113
- geometry.instanceCount = 0;
114
- geometry.setAttribute("position", tileQuadPosition);
115
- return geometry;
116
- };
117
- // NOTE Clip rectangle of a froxel cell rectangle, padding cells larger on each side. An empty rectangle stays empty.
118
- const clipRect = { x0: 0, y0: 0, x1: 0, y1: 0 };
119
- const getClipRect = (rect, width, height, padding) => {
120
- if (rect.z <= rect.x || rect.w <= rect.y) {
121
- clipRect.x0 = clipRect.y0 = clipRect.x1 = clipRect.y1 = 0.0;
122
- return clipRect;
123
- }
124
- clipRect.x0 = (Math.max(0, rect.x - padding) / width) * 2.0 - 1.0;
125
- clipRect.y0 = (Math.max(0, rect.y - padding) / height) * 2.0 - 1.0;
126
- clipRect.x1 = (Math.min(width, rect.z + padding) / width) * 2.0 - 1.0;
127
- clipRect.y1 = (Math.min(height, rect.w + padding) / height) * 2.0 - 1.0;
128
- return clipRect;
129
- };
130
- const getMaxTextureSize = (renderer) => {
131
- const backend = renderer.backend;
132
- return backend.device ? backend.device.limits.maxTextureDimension2D : Infinity;
133
- };
134
- // NOTE What the shadow density pass reads of a caster's source: its identity, version and LOD mode
135
- // (his pushCasterMaps pushes the texture ids and versions). A new source or a replaced grid draws again.
136
- const sourceIds = new WeakMap();
137
- let nextSourceId = 1;
138
- const pushCasterSource = (values, frameVolume) => {
139
- const source = frameVolume.source;
140
- let id = sourceIds.get(source);
141
- if (id === undefined) {
142
- id = nextSourceId++;
143
- sourceIds.set(source, id);
144
- }
145
- values.push(id, source.version ?? -1, source.lodLevels, source.lod === "node-average" ? 2 : source.lod === "none" ? 0 : 1);
146
- if (source.textures) {
147
- for (const name of ["density", "mask", "albedo"]) {
148
- const t = source.textures[name];
149
- values.push(t ? t.map.id : -1, t ? t.map.version : -1, t?.mip ? t.mip.id : -1, t?.mip ? t.mip.version : -1);
150
- }
151
- }
152
- };
153
- // NOTE An id for each network object (the transmittance signature: a swapped network draws again)
154
- const networkIds = new WeakMap();
155
- let nextNetworkId = 1;
156
- const networkId = (network) => {
157
- let id = networkIds.get(network);
158
- if (id === undefined) {
159
- id = nextNetworkId++;
160
- networkIds.set(network, id);
161
- }
162
- return id;
163
- };
164
- /** His `FrameRenderer` (`'volume'` and `'frame'` lighting). One instance can serve many volumes and cameras. */
20
+ import { vdbFrameDefaultSettings } from "../../core/frame/settings.js";
21
+ import { vdbCreateFrameRenderer } from "../../core/frame/renderer.js";
22
+ import { vdbSparseSource as vdbCoreSparseSource } from "../../core/source/sparse.js";
23
+ import { vdbDenseSource } from "../../core/source/dense.js";
24
+ import { getDevice } from "../device.js";
25
+ import { vdbFrameRenderId } from "./three-internals.js";
26
+ import { VDBCoreTextureBinding, vdbCoreTextureSelfTest } from "./core-textures.js";
27
+ import { VDBFrameCoreIntegrateMaterial } from "./core-integrate-material.js";
28
+ import { VDBCoreOccluders } from "./core-occluders.js";
29
+ import { VDBCoreEnvironment } from "./core-environment.js";
30
+ import { VDBFrameVolumeShadowReceivers } from "./volume-shadows.js";
31
+ import { getFrameAngstromExponent } from "./spectrum.js";
32
+ /** Our trained network (K6.N, D36) as the core MLP (the default `mlp`; one object, so the core uploads it once). */
33
+ const DEFAULT_MLP = vdbFrameMlpFromNeural(vdbFrameNeuralWeights);
34
+ /** Instanced, so a proxy skips its draw with `instanceCount = 0` (three draws no instances). A quad the composite places. */
35
+ const proxyQuad = new THREE.Float32BufferAttribute([-1, -1, 0, 1, -1, 0, 1, 1, 0, -1, -1, 0, 1, 1, 0, -1, 1, 0], 3);
36
+ /** His `FrameRenderer`, on the core: one instance can serve many volumes and cameras. */
165
37
  export class VDBFrameRenderer {
166
- settings = {
167
- width: 512,
168
- height: 512,
169
- pixelsPerFroxel: 0,
170
- depth: 24,
171
- subSteps: 32,
172
- near: 0.1,
173
- far: Infinity,
174
- fadeRadius: Infinity,
175
- jitter: false,
176
- temporal: true,
177
- temporalBlend: 0.2,
178
- lighting: "frame",
179
- shadowResolution: 64,
180
- shadowCascades: 1,
181
- shadowDistance: 512,
182
- phase: "henyey-greenstein",
183
- phaseG: 0.8,
184
- phaseBackG: -0.3,
185
- phaseBackWeight: 0.2,
186
- phaseGExponent: 0.0,
187
- srgbBlending: true,
188
- environmentLighting: "directional",
189
- environmentSamples: 8,
190
- environmentShOrder: 1,
191
- multipleScattering: "neural",
192
- scatteringOctaves: 4,
193
- scatteringOctaveExtinction: 0.5,
194
- scatteringOctaveContribution: 0.5,
195
- scatteringOctavePhase: 0.5,
196
- spectral: false,
197
- castShadows: false,
198
- castShadowMapSize: 512,
199
- castShadowCascades: 1,
200
- castShadowDistance: 4000,
201
- castShadowSteps: 32,
202
- castShadowUpdatesPerFrame: 1,
203
- castShadowCoarse: false,
204
- };
205
38
  /**
206
- * The network of multipleScattering `'neural'` (default: his trained weights, `@pmndrs/vdb/tools`
207
- * `vdbFrameNeuralWeights`; see THIRD_PARTY_NOTICES.md for their provenance). Set another network of the same
208
- * shape to swap it, or null to run `'neural'` as 1D diffusion (warns once). Not his (his is a module import).
39
+ * The settings (the core's `VDBFrameSettings`: his names and v0.26 defaults plus the K6 fields); live, read at the
40
+ * next render and shared by every volume this renderer draws.
209
41
  */
210
- neuralNetwork = vdbFrameNeuralWeights;
211
- /** Per-pass hooks (timing, debugging). */
42
+ settings = vdbFrameDefaultSettings();
43
+ /**
44
+ * EXPERIMENTAL: the network of `multipleScattering` `'mlp'` / `'neural'` as `VDBFrameMlp` data (layer shapes,
45
+ * activations, weights; default: mjurczyk's trained weights). Assign another network of that form (no rebuild), or
46
+ * null to run those modes as 1D diffusion (warned).
47
+ */
48
+ mlp = DEFAULT_MLP;
49
+ /** Timing and debug hooks around each core update ({@link VDBFramePassHook}). */
212
50
  passHook = null;
213
51
  /**
214
- * Timing/debug hook: proxies draw the integrate pass over the last froxel atlas without rendering
215
- * the froxels again (the per-pass timing harness times integrate alone with it). Not his.
52
+ * Whether the volumes are drawn into the froxels at the next render (default true). False keeps the last froxels
53
+ * (the composite still draws them; volume shadow maps and probes still update): `update(…, { froxels: false })`.
216
54
  */
217
- holdFroxels = false;
218
- /** Redraws and skips of the signature-cached 'frame' passes (the K3.3 redraw-skip rate). Not his. */
219
- redrawStats = {
220
- shadowDensity: { drawn: 0, skipped: 0 },
221
- transmittance: { drawn: 0, skipped: 0 },
222
- environmentGrid: { drawn: 0, skipped: 0 },
223
- };
224
- // NOTE TSL uniform nodes. Passes share them, the CPU writes .value.
225
- froxelUniforms = createFroxelUniforms();
226
- // NOTE Canvas and drawing buffer sizes that settings.pixelsPerFroxel holds (layout.ts getFroxelSize)
227
- froxelHeldSize = { canvasX: 0, canvasY: 0, bufferX: 0, bufferY: 0 };
228
- froxelTileUniforms = createTileUniforms();
229
- // NOTE Froxel area of all volumes. Passes over the froxel grid draw only this area.
230
- froxelAreaUniforms = createAreaUniforms();
231
- froxelArea = { rect: new THREE.Vector4(), first: 0, count: 0 };
232
- areaGeometry = createTileGeometry();
233
- gridUniforms = createGridUniforms(this.froxelUniforms.frameJitter);
234
- gridTileUniforms = createTileUniforms();
235
- densityShadowUniforms = createDensityShadowUniforms();
236
- lightUniforms = createLightUniforms();
237
- environmentGridUniforms = createEnvironmentGridUniforms();
238
- // NOTE Octaves of the settings (getFrameScatteringOctaves), for the signatures
239
- scatteringOctaves = new THREE.Vector4();
240
- integrateMaterial;
241
- lightingMaterial;
242
- transmittanceMaterial;
243
- temporalMaterial;
244
- // NOTE The light scene draws the volume inject pass or the lighting pass. The inject mesh takes the inject material of each volume.
245
- injectScene = createScene();
246
- injectMesh = new THREE.Mesh(createTileGeometry(), new THREE.MeshBasicMaterial());
247
- lightingMesh;
248
- densityScene = createScene();
249
- densityPool = [];
250
- // NOTE Clears the density targets in the froxel area (one draw for all targets)
251
- densityClearMaterial = new NodeMaterial();
252
- densityClearScene = createScene();
253
- densityClearMesh;
254
- shadowScene = createScene();
255
- shadowPool = [];
256
- transmittanceScene = createScene();
257
- transmittanceMesh;
258
- temporalScene = createScene();
259
- temporalMesh;
260
- historyTargets = [null, null];
261
- historyIndex = 0;
262
- historyValid = false;
263
- historyCamera = null;
264
- previousViewMatrix = new THREE.Matrix4();
265
- previousProjectionMatrix = new THREE.Matrix4();
266
- previousRange = new THREE.Vector2(0.1, 1.0);
267
- jitterIndex = 0;
268
- // NOTE Environment lights from a small map of the scene environment (tools/frame/environment.ts)
269
- environmentLights;
270
- environmentMapMaterial = new VDBFrameEnvironmentMapMaterial();
271
- environmentMapScene = createScene();
272
- environmentMapMesh;
273
- environmentMapCamera = new THREE.OrthographicCamera(-1.0, 1.0, 1.0, -1.0, 0.0, 1.0);
274
- environmentMapTarget = null;
275
- environment = null;
276
- // NOTE Environment grid: environment light of the last cascade voxels, from the environment lights with no slot
277
- environmentGridMaterial;
278
- environmentGridScene = createScene();
279
- environmentGridMesh;
280
- environmentGridTarget = null;
281
- environmentGridSignature = [];
282
- nextEnvironmentGridSignature = [];
283
- // NOTE multipleScattering 'neural': mips of the last grid cascade, levels 1 and up (VDBFrameGridMipMaterial)
284
- gridMipMaterial = new VDBFrameGridMipMaterial();
285
- gridMipScene = createScene();
286
- gridMipMesh;
287
- gridMipTargets = [];
288
- gridMipSignature = [];
289
- atlasTarget = null;
290
- densityTarget = null;
291
- shadowDensityTarget = null;
292
- transmittanceTarget = null;
293
- // NOTE Renderer settings.spectral: 3 transmittance targets for each slot group in use (spectrum.ts).
294
- // Made when a group is first used. transmittanceTarget is null then.
295
- spectralTransmittanceTargets = [];
296
- lightLimitWarned = false;
297
- warned = new Set();
298
- // NOTE Shadow grid state: cascades of the last update, signatures (tools/frame/grid.ts)
299
- gridState = vdbFrameGridSignatureState();
300
- // NOTE World shadow grid of the current render. Volume shadows make it before the first lit mesh; 'frame' lighting
301
- // then uses it again (gridFreshCamera). gridState.castVersion changes when the last cascade (all volumes) changes.
302
- gridRenderId = -1;
303
- gridCamera = null;
304
- gridFreshCamera = null;
305
- gridReady = false;
306
- /** K3.6: volume shadows on meshes (settings.castShadows). */
307
- volumeShadows;
308
- // NOTE gridVersion and target of the last shadow density draw. The same version is not drawn again.
309
- shadowDrawnVersion = -1;
310
- shadowDrawnTarget = null;
311
- transmittanceSignature = [];
312
- nextTransmittanceSignature = [];
313
- // NOTE collectVolumes result of the current render
314
- collected = {
315
- renderId: -1,
316
- camera: null,
317
- scene: null,
318
- result: null,
319
- };
320
- volumeCollector = new FrameVolumeCollector();
321
- sliceRange = { first: 0, count: 0 };
322
- gridRange = { rect: new THREE.Vector4(), first: 0, count: 0 };
323
- cascadeCasterPool = { items: [], entries: [] };
324
- lightState = {
325
- camera: null,
326
- hemiCount: 0,
327
- hasSky: false,
328
- directions: { length: 0, entries: [] },
329
- points: { length: 0, entries: [] },
330
- spots: { length: 0, entries: [] },
331
- };
332
- lightResult = { shadowLightCount: 0, environmentLightCount: 0, environmentShadowSlot: 0, environmentGridLights: [] };
333
- environmentGridLightEntries = [];
334
- cachedFrame = -1;
335
- cachedCamera = null;
336
- rendererWarned = false;
337
- constructor() {
338
- this.integrateMaterial = new VDBFrameIntegrateMaterial({ froxelUniforms: this.froxelUniforms });
339
- this.lightingMaterial = new VDBFrameLightingMaterial({
340
- froxelUniforms: this.froxelUniforms,
341
- froxelTileUniforms: this.froxelTileUniforms,
342
- froxelAreaUniforms: this.froxelAreaUniforms,
343
- lightUniforms: this.lightUniforms,
344
- gridUniforms: this.gridUniforms,
345
- densityShadowUniforms: this.densityShadowUniforms,
346
- });
347
- this.transmittanceMaterial = new VDBFrameTransmittanceMaterial({ gridUniforms: this.gridUniforms, lightUniforms: this.lightUniforms });
348
- this.temporalMaterial = new VDBFrameTemporalMaterial({ froxelUniforms: this.froxelUniforms, froxelTileUniforms: this.froxelTileUniforms, froxelAreaUniforms: this.froxelAreaUniforms });
349
- this.environmentGridMaterial = new VDBFrameEnvironmentGridMaterial({ gridUniforms: this.gridUniforms, environmentGridUniforms: this.environmentGridUniforms, lightUniforms: this.lightUniforms });
350
- this.environmentLights = new VDBFrameEnvironmentLights((renderer, scene) => this.renderEnvironmentMap(renderer, scene));
351
- this.volumeShadows = new VDBFrameVolumeShadows(this);
352
- this.lightingMesh = new THREE.Mesh(this.areaGeometry, this.lightingMaterial);
353
- this.densityClearMesh = new THREE.Mesh(this.areaGeometry, this.densityClearMaterial);
354
- this.transmittanceMesh = new THREE.Mesh(createFullscreenGeometry(), this.transmittanceMaterial);
355
- this.temporalMesh = new THREE.Mesh(this.areaGeometry, this.temporalMaterial);
356
- this.environmentMapMesh = new THREE.Mesh(createFullscreenGeometry(), this.environmentMapMaterial);
357
- this.environmentGridMesh = new THREE.Mesh(createFullscreenGeometry(), this.environmentGridMaterial);
358
- this.gridMipMesh = new THREE.Mesh(createFullscreenGeometry(), this.gridMipMaterial);
359
- for (const mesh of [this.injectMesh, this.lightingMesh, this.transmittanceMesh, this.temporalMesh, this.densityClearMesh, this.environmentMapMesh, this.environmentGridMesh, this.gridMipMesh]) {
360
- mesh.frustumCulled = false;
361
- }
362
- this.temporalScene.add(this.temporalMesh);
363
- this.densityClearMaterial.vertexNode = frameTileVertex(this.froxelTileUniforms, this.froxelAreaUniforms.frameAreaRect, this.froxelAreaUniforms.frameAreaSliceStart);
364
- this.densityClearMaterial.fragmentNode = outputStruct(vec4(0.0), vec4(0.0), vec4(0.0), vec4(0.0));
365
- this.densityClearMaterial.depthTest = false;
366
- this.densityClearMaterial.depthWrite = false;
367
- this.densityClearMaterial.blending = THREE.NoBlending;
368
- this.densityClearScene.add(this.densityClearMesh);
369
- this.injectScene.add(this.injectMesh, this.lightingMesh);
370
- this.transmittanceScene.add(this.transmittanceMesh);
371
- this.environmentMapScene.add(this.environmentMapMesh);
372
- this.environmentGridScene.add(this.environmentGridMesh);
373
- this.gridMipScene.add(this.gridMipMesh);
374
- }
375
- warnOnce(key, message) {
376
- if (!this.warned.has(key)) {
377
- this.warned.add(key);
378
- console.warn(`VDBFrameRenderer: ${message}`);
379
- }
55
+ froxels = true;
56
+ #core = null;
57
+ #device = null;
58
+ #material = null;
59
+ #prefix = new VDBCoreTextureBinding();
60
+ /** K6.4: the stand-in of the spectral alpha prefix (`outputs.froxels.integratedAlpha`). */
61
+ #alphaPrefix = new VDBCoreTextureBinding();
62
+ #denseSources = new WeakMap();
63
+ #sparseSources = new Map();
64
+ #sparseSlots = new WeakMap();
65
+ /** The three source's stats object each core slot last took (a new object: `refreshStats()` ran). */
66
+ #slotStats = new WeakMap();
67
+ #volumes = new Map();
68
+ #frameId = 0;
69
+ #frameKey = null;
70
+ #cachedFrame = -1;
71
+ #cachedCamera = null;
72
+ #rendererWarned = false;
73
+ /** K6.5b: three's shadow maps as the core's occluder maps. */
74
+ #occluders = new VDBCoreOccluders();
75
+ /** K6.2b: `scene.environment` as the core's environment input. */
76
+ #environment = new VDBCoreEnvironment();
77
+ /** @internal K6.5: volume shadows on meshes: the shadow filter on each shadow light, reading the core's maps. */
78
+ volumeShadows = new VDBFrameVolumeShadowReceivers(this);
79
+ /** The core frame renderer (made at the first render, per device; null before). Read its `outputs`; set nothing on it. */
80
+ get core() {
81
+ return this.#core;
82
+ }
83
+ /** Redraws and skips of the core's signature-cached passes ('frame' lighting) and volume shadow pieces (zeros before the first render). */
84
+ get redrawStats() {
85
+ return this.#core?.redrawStats ?? { shadowDensity: { drawn: 0, skipped: 0 }, transmittance: { drawn: 0, skipped: 0 }, environmentGrid: { drawn: 0, skipped: 0 }, volumeShadows: { drawn: 0, waiting: 0 } };
86
+ }
87
+ /** The composite material every volume proxy draws (one per renderer). */
88
+ proxyMaterial() {
89
+ this.#material ??= new VDBFrameCoreIntegrateMaterial();
90
+ return this.#material;
91
+ }
92
+ /** A quad geometry for a volume proxy; the composite places it over the froxel area. */
93
+ createProxyGeometry() {
94
+ const geometry = new THREE.InstancedBufferGeometry();
95
+ geometry.instanceCount = 1;
96
+ geometry.setAttribute("position", proxyQuad);
97
+ return geometry;
380
98
  }
381
- // NOTE Each frame volume proxy calls this. The first proxy in a frame renders the frame. Other proxies draw nothing.
99
+ /**
100
+ * Called by each volume proxy before it draws: the first proxy of a render runs the core update (once per render,
101
+ * camera and scene); every proxy then composites the froxels. Override passes (depth, normals) draw nothing.
102
+ */
382
103
  render(renderer, scene, camera, proxy) {
383
104
  if (!renderer.isWebGPURenderer) {
384
- if (!this.rendererWarned) {
105
+ if (!this.#rendererWarned) {
385
106
  console.error("VDBFrameVolume: needs WebGPURenderer (three/webgpu).");
386
- this.rendererWarned = true;
107
+ this.#rendererWarned = true;
387
108
  }
388
109
  return;
389
110
  }
390
- const frame = renderer.info.render.calls;
391
- // NOTE Override passes (depth, normals) of other effects must not draw or start the frame
392
111
  if (scene.overrideMaterial) {
393
112
  proxy.geometry.instanceCount = 0;
394
113
  return;
395
114
  }
396
- if (frame === this.cachedFrame && camera === this.cachedCamera) {
115
+ const frame = renderer.info.render.calls;
116
+ if (frame === this.#cachedFrame && camera === this.#cachedCamera) {
397
117
  proxy.geometry.instanceCount = 0;
398
118
  return;
399
119
  }
400
- // NOTE Puts the volume shadow filter on new shadow lights (and frees the maps of removed ones)
401
- this.volumeShadows.update(renderer, scene);
402
- if (this.holdFroxels && this.atlasTarget) {
403
- this.cachedFrame = frame;
404
- this.cachedCamera = camera;
405
- proxy.geometry.instanceCount = 1;
406
- return;
407
- }
408
- const { volumes, casters } = this.collectVolumes(renderer, scene, camera);
409
- if (volumes.length > 0) {
410
- this.renderFrame(renderer, scene, camera, volumes, casters);
411
- }
412
- // NOTE Nested renders increase info.render.calls. Keep the new value. Then other proxies in this frame skip.
413
- this.cachedFrame = renderer.info.render.calls;
414
- this.cachedCamera = camera;
415
- proxy.geometry.instanceCount = volumes.length > 0 ? 1 : 0;
120
+ const material = this.proxyMaterial();
121
+ // NOTE three draws the material it chose before onBeforeRender: a swapped proxy draws the composite from the next frame
122
+ if (proxy.material !== material)
123
+ proxy.material = material;
124
+ const u = this.coreFrame(renderer, scene, camera);
125
+ if (u?.recorded && u.outputs.froxels) {
126
+ if (this.#prefix.set(u.outputs.froxels.integrated))
127
+ material.prefix.value = this.#prefix.texture;
128
+ // K6.4: spectral media composite with the alpha prefix (their own blend over three's viewport texture)
129
+ const alpha = u.outputs.froxels.integratedAlpha;
130
+ if (alpha && this.#alphaPrefix.set(alpha))
131
+ material.alphaPrefix.value = this.#alphaPrefix.texture;
132
+ material.setSpectral(!!alpha);
133
+ material.setLayout(u.outputs.froxels.layout, camera);
134
+ material.setSrgbBlending(this.settings.srgbBlending && renderer.outputColorSpace === THREE.SRGBColorSpace, renderer.toneMapping === THREE.NoToneMapping);
135
+ }
136
+ this.#cachedFrame = renderer.info.render.calls;
137
+ this.#cachedCamera = camera;
138
+ proxy.geometry.instanceCount = u?.recorded ? 1 : 0;
416
139
  }
417
140
  /**
418
- * Draws only the froxel atlas for this scene and camera (no integrate): the per-pass timing
419
- * harness renders this alone. Returns the number of volumes in view.
141
+ * The core update of one render, recorded into its own encoder and submitted (three's frame submits after it, so queue
142
+ * order is right). It runs once per render id, camera and scene; the first caller runs it: a volume shadow receiver's
143
+ * or the emission light's `updateBefore` (before any receiver of the render draws, his order), else the first volume
144
+ * proxy. The volume shadow maps and the emission probes are drawn here.
420
145
  */
421
- renderFroxels(renderer, scene, camera) {
422
- this.collected.renderId = -1;
423
- const { volumes, casters } = this.collectVolumes(renderer, scene, camera);
424
- if (volumes.length > 0) {
425
- this.renderFrame(renderer, scene, camera, volumes, casters);
426
- }
427
- return volumes.length;
428
- }
429
- // NOTE A quad. The integrate material puts it on the screen rectangle of the froxel area.
430
- createProxyGeometry() {
431
- const geometry = createTileGeometry();
432
- geometry.instanceCount = 1;
433
- return geometry;
434
- }
435
- isFrameLighting() {
436
- return this.settings.lighting === "frame";
437
- }
438
- // NOTE The world shadow grid is used by 'frame' lighting and by volume shadows on meshes
439
- usesShadowGrid() {
440
- return this.isFrameLighting() || this.settings.castShadows;
441
- }
442
- // NOTE Visible volumes and shadow casters, one time in a render (the render id of three.js NodeFrame, internal)
443
- collectVolumes(renderer, scene, camera) {
444
- const renderId = renderer._nodes?.nodeFrame?.renderId ?? -1;
445
- const { collected } = this;
446
- if (renderId !== -1 && collected.renderId === renderId && collected.camera === camera && collected.scene === scene && collected.result) {
447
- return collected.result;
448
- }
449
- collected.renderId = renderId;
450
- collected.camera = camera;
451
- collected.scene = scene;
452
- collected.result = this.volumeCollector.collect(scene, camera, this.settings, this.usesShadowGrid(), null);
453
- if (collected.result.volumes.length > 0) {
454
- this.froxelUniforms.froxelRange.value.set(collected.result.near, collected.result.far);
455
- }
456
- return collected.result;
457
- }
458
- // NOTE Slices of a volume. Returns this.sliceRange ({ first, count }), used again in the next call.
459
- getSliceRange(volume) {
460
- const { froxelRange, froxelGrid } = this.froxelUniforms;
461
- return getFroxelSliceRange(volume, froxelRange.value, froxelGrid.value.z, this.sliceRange);
462
- }
463
- checkSettings() {
464
- const s = this.settings;
465
- if (this.isFrameLighting() && s.multipleScattering === "neural" && !this.neuralNetwork) {
466
- this.warnOnce("neural", "multipleScattering 'neural' has no network (neuralNetwork is null); the scene light slots use 1D diffusion (true).");
467
- }
468
- }
469
- /** The multiple scattering mode (settings.multipleScattering; 'neural' is diffusion outside the network). */
470
- multipleScatteringMode() {
471
- return this.settings.multipleScattering;
472
- }
473
- isSpectral() {
474
- return this.settings.spectral === true;
475
- }
476
- // NOTE multipleScattering 'neural' uses the network only with grey 'frame' lighting. Other cases use diffusion.
477
- isNeural() {
478
- if (this.settings.multipleScattering !== "neural" || this.settings.spectral || !this.neuralNetwork)
479
- return false;
480
- const problem = vdbFrameNeuralCheck(this.neuralNetwork);
481
- if (problem) {
482
- this.warnOnce("neural-shape", `neuralNetwork ${this.neuralNetwork.name ?? ""} does not fit the shader (${problem}); using 1D diffusion.`);
483
- return false;
484
- }
485
- return true;
486
- }
487
- // NOTE Mips of the last grid cascade for the network. Drawn again only when the grid changes.
488
- renderGridMips(renderer, camera) {
489
- const { frameGridResolution, frameGridColumns, frameGridCount } = this.gridUniforms;
490
- const resolution = frameGridResolution.value;
491
- const source = this.shadowDensityTarget;
492
- const signature = [this.gridState.gridVersion, source.texture.id, resolution, frameGridCount.value, frameGridColumns.value];
493
- if (vdbSameValues(signature, this.gridMipSignature)) {
494
- return;
495
- }
496
- this.gridMipSignature = signature;
497
- this.gridMipMesh.layers.mask = camera.layers.mask;
498
- const material = this.gridMipMaterial;
499
- const { frameNeuralMipMaps, frameNeuralMipLayouts } = this.transmittanceMaterial;
500
- // NOTE Source of the next level: the grid atlas first, then the level before
501
- let previous = null;
502
- for (let level = 1; level <= frameNeuralMipLevels; level++) {
503
- const side = Math.max(1, resolution >> level);
504
- const layout = getAtlasLayout(side, side, side);
505
- let target = this.gridMipTargets[level - 1];
506
- if (!target || target.width !== layout.width || target.height !== layout.height) {
507
- target?.dispose();
508
- target = createRenderTarget(layout.width, layout.height, { format: THREE.RGFormat });
509
- this.gridMipTargets[level - 1] = target;
510
- }
511
- if (previous) {
512
- material.frameMipSource.value = previous.target.texture;
513
- material.frameMipSourceResolution.value = previous.side;
514
- material.frameMipSourceColumns.value = previous.layout.columns;
515
- material.frameMipSourceTile.value = 0;
516
- material.frameMipSourceSize.value.set(previous.layout.width, previous.layout.height);
517
- }
518
- else {
519
- material.frameMipSource.value = source.texture;
520
- material.frameMipSourceResolution.value = resolution;
521
- material.frameMipSourceColumns.value = frameGridColumns.value;
522
- material.frameMipSourceTile.value = (frameGridCount.value - 1) * resolution;
523
- material.frameMipSourceSize.value.set(source.width, source.height);
524
- }
525
- material.frameMipResolution.value = side;
526
- material.frameMipColumns.value = layout.columns;
527
- material.frameMipSize.value.set(layout.width, layout.height);
528
- renderer.setRenderTarget(target);
529
- renderer.render(this.gridMipScene, camera);
530
- frameNeuralMipMaps[level - 1].value = target.texture;
531
- frameNeuralMipLayouts[level - 1].value.set(layout.columns, layout.width, layout.height);
532
- previous = { target, side, layout };
533
- }
534
- }
535
- // NOTE The 3 transmittance targets of a spectral slot group, the same size as the shadow grid
536
- getSpectralTransmittanceTarget(group) {
537
- const targets = this.spectralTransmittanceTargets;
538
- while (targets.length <= group) {
539
- const { width, height } = this.shadowDensityTarget;
540
- targets.push(createRenderTarget(width, height, { count: 3 }));
541
- }
542
- return targets[group];
543
- }
544
- // NOTE The lighting and density passes keep their group textures bound when they do not read them: they get their
545
- // own placeholders (one texture each, see renderFrameLighting), not the disposed targets.
546
- disposeSpectralTransmittanceTargets() {
547
- this.spectralTransmittanceTargets.forEach((target) => target.dispose());
548
- this.spectralTransmittanceTargets = [];
549
- for (const map of [...this.lightingMaterial.frameSpectralTransmittanceMaps, ...this.densityShadowUniforms.frameSkyTransmittanceMaps]) {
550
- map.value = new THREE.Texture();
551
- }
552
- }
553
- updateTargets(renderer) {
554
- const { depth, subSteps } = this.settings;
555
- const { width, height } = getFroxelSize(this.settings, renderer, froxelSize, this.froxelHeldSize);
556
- const spectral = this.isSpectral();
557
- const froxelAtlas = getAtlasLayout(width, height, depth);
558
- if (!this.atlasTarget || this.atlasTarget.width !== froxelAtlas.width || this.atlasTarget.height !== froxelAtlas.height || isSpectralTarget(this.atlasTarget) !== spectral) {
559
- const maxTextureSize = getMaxTextureSize(renderer);
560
- if (froxelAtlas.width > maxTextureSize || froxelAtlas.height > maxTextureSize) {
561
- console.warn("VDBFrameRenderer: froxel atlas is larger than maxTextureSize. Decrease width, height or depth.");
562
- }
563
- this.atlasTarget?.dispose();
564
- this.atlasTarget = createAtlasTarget(froxelAtlas.width, froxelAtlas.height, spectral);
565
- this.historyValid = false;
566
- }
567
- // NOTE The per-volume inject materials are set in renderInject
568
- this.lightingMaterial.setSpectral(spectral);
569
- this.temporalMaterial.setSpectral(spectral);
570
- this.integrateMaterial.setSpectral(spectral);
571
- const { froxelGrid, froxelColumns } = this.froxelUniforms;
572
- // NOTE A new grid layout makes the history unusable, also when the atlas keeps its size (600 x 400 to 400 x 600)
573
- if (froxelGrid.value.x !== width || froxelGrid.value.y !== height || froxelGrid.value.z !== depth || froxelColumns.value !== froxelAtlas.columns) {
574
- this.historyValid = false;
575
- }
576
- froxelGrid.value.set(width, height, depth);
577
- froxelColumns.value = froxelAtlas.columns;
578
- this.froxelUniforms.froxelSubSteps.value = Math.max(1, Math.round(subSteps));
579
- this.froxelTileUniforms.frameTileSize.value.set(width, height);
580
- this.froxelTileUniforms.frameTileColumns.value = froxelAtlas.columns;
581
- this.froxelTileUniforms.frameTargetSize.value.set(froxelAtlas.width, froxelAtlas.height);
582
- this.froxelUniforms.froxelAtlasSize.value.set(froxelAtlas.width, froxelAtlas.height);
583
- this.integrateMaterial.froxelAtlas.value = this.atlasTarget.textures[0];
584
- this.integrateMaterial.froxelAlphaAtlas.value = this.atlasTarget.textures[spectral ? 1 : 0];
585
- if (this.settings.temporal) {
586
- for (let index = 0; index < this.historyTargets.length; index++) {
587
- const target = this.historyTargets[index];
588
- if (!target || target.width !== froxelAtlas.width || target.height !== froxelAtlas.height || isSpectralTarget(target) !== spectral) {
589
- target?.dispose();
590
- this.historyTargets[index] = createAtlasTarget(froxelAtlas.width, froxelAtlas.height, spectral);
591
- this.historyValid = false;
592
- }
593
- }
594
- }
595
- if (this.isFrameLighting()) {
596
- // NOTE Spectral: 3 targets (albedo, emission, extinction of each channel), no light slot targets
597
- const densityCount = spectral ? 3 : 4;
598
- if (!this.densityTarget || this.densityTarget.width !== froxelAtlas.width || this.densityTarget.height !== froxelAtlas.height || this.densityTarget.textures.length !== densityCount) {
599
- this.densityTarget?.dispose();
600
- this.densityTarget = createRenderTarget(froxelAtlas.width, froxelAtlas.height, { count: densityCount, minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter });
601
- this.densityClearMaterial.fragmentNode = outputStruct(...Array.from({ length: densityCount }, () => vec4(0.0)));
602
- this.densityClearMaterial.needsUpdate = true;
146
+ coreFrame(renderer, scene, camera) {
147
+ if (!renderer.isWebGPURenderer)
148
+ return null;
149
+ const renderId = vdbFrameRenderId(renderer);
150
+ const key = this.#frameKey;
151
+ if (key && key.renderId === renderId && key.camera === camera && key.scene === scene)
152
+ return key.result;
153
+ const device = getDevice(renderer);
154
+ if (!this.#core || this.#device !== device) {
155
+ vdbCoreTextureSelfTest(renderer, device);
156
+ this.#core?.dispose();
157
+ this.#core = vdbCreateFrameRenderer(device, { label: "vdb three frame" });
158
+ this.#device = device;
159
+ this.#denseSources = new WeakMap();
160
+ this.#volumes = new Map();
161
+ this.#disposeSparse();
162
+ }
163
+ const core = this.#core;
164
+ Object.assign(core.settings, this.settings);
165
+ core.mlp = this.mlp;
166
+ // K6.5: the volume shadow filter on each shadow light (receivers build with it from the next render)
167
+ this.volumeShadows.update(renderer, scene);
168
+ const seen = new Set();
169
+ scene.traverseVisible((object) => {
170
+ const frameVolume = object;
171
+ if (!frameVolume.isVDBFrameVolume || frameVolume.frameRenderer !== this || !frameVolume.proxy.layers.test(camera.layers))
172
+ return;
173
+ frameVolume.syncSource();
174
+ const handle = this.#volumeOf(frameVolume, device);
175
+ frameVolume.boxMatrixWorld.multiplyMatrices(frameVolume.matrixWorld, frameVolume.boxMatrix);
176
+ this.#setParams(handle.params, frameVolume, frameVolume.boxMatrixWorld);
177
+ handle.visible = true;
178
+ // his collector: every volume in the camera's layers casts into the shadow grid, also out of view
179
+ handle.castsShadow = true;
180
+ seen.add(handle);
181
+ });
182
+ for (const [frameVolume, handle] of this.#volumes) {
183
+ if (seen.has(handle))
184
+ continue;
185
+ // a volume that is hidden (or out of the camera's layers) neither draws nor casts (Traps: the core casts invisible volumes)
186
+ handle.visible = false;
187
+ handle.castsShadow = false;
188
+ if (!frameVolume.parent) {
189
+ handle.remove();
190
+ this.#volumes.delete(frameVolume);
603
191
  }
604
- this.updateGridTargets();
605
192
  }
606
- }
607
- updateGridTargets() {
608
- const resolution = Math.max(2, Math.round(this.settings.shadowResolution));
609
- const cascades = this.getCascadeCount();
610
- const gridAtlas = getAtlasLayout(resolution, resolution, resolution * cascades);
611
- const spectral = this.isSpectral();
612
- if (!this.shadowDensityTarget || this.shadowDensityTarget.width !== gridAtlas.width || this.shadowDensityTarget.height !== gridAtlas.height || isSpectralTarget(this.shadowDensityTarget) !== spectral) {
613
- this.shadowDensityTarget?.dispose();
614
- this.transmittanceTarget?.dispose();
615
- this.disposeSpectralTransmittanceTargets();
616
- // NOTE Extinction and absorption. Spectral: (extinction rgb, 0) and (absorption rgb, 0).
617
- this.shadowDensityTarget = spectral ? createRenderTarget(gridAtlas.width, gridAtlas.height, { count: 2 }) : createRenderTarget(gridAtlas.width, gridAtlas.height, { format: THREE.RGFormat });
618
- // NOTE Total transmittance (2 targets), then direct transmittance of the light slots (2 targets).
619
- // Spectral: the slot group targets (getSpectralTransmittanceTarget).
620
- this.transmittanceTarget = spectral ? null : createRenderTarget(gridAtlas.width, gridAtlas.height, { count: 4 });
621
- // NOTE A new target is empty, so the last cascade and the environment grid are drawn again
622
- this.gridState.castSignature = [];
623
- this.environmentGridSignature = [];
624
- }
625
- // NOTE The per-volume shadow density materials are set in getShadowDensityMaterial
626
- this.transmittanceMaterial.setSpectral(spectral);
627
- this.environmentGridMaterial.setSpectral(spectral);
628
- // NOTE The environment grid is one cascade. A new target is empty, so the signature is reset.
629
- const environmentAtlas = getAtlasLayout(resolution, resolution, resolution);
630
- if (!this.environmentGridTarget || this.environmentGridTarget.width !== environmentAtlas.width || this.environmentGridTarget.height !== environmentAtlas.height) {
631
- this.environmentGridTarget?.dispose();
632
- this.environmentGridTarget = createRenderTarget(environmentAtlas.width, environmentAtlas.height);
633
- this.environmentGridSignature = [];
634
- }
635
- this.environmentGridUniforms.frameEnvironmentGridColumns.value = environmentAtlas.columns;
636
- this.environmentGridUniforms.frameEnvironmentGridAtlasSize.value.set(environmentAtlas.width, environmentAtlas.height);
637
- this.gridUniforms.frameGridResolution.value = resolution;
638
- this.gridUniforms.frameGridColumns.value = gridAtlas.columns;
639
- this.gridUniforms.frameGridAtlasSize.value.set(gridAtlas.width, gridAtlas.height);
640
- this.gridTileUniforms.frameTileSize.value.set(resolution, resolution);
641
- this.gridTileUniforms.frameTileColumns.value = gridAtlas.columns;
642
- this.gridTileUniforms.frameTargetSize.value.set(gridAtlas.width, gridAtlas.height);
643
- }
644
- renderFrame(renderer, scene, camera, volumes, casters = []) {
645
- this.checkSettings();
646
- const currentRenderTarget = renderer.getRenderTarget();
647
- const currentActiveCubeFace = renderer.getActiveCubeFace();
648
- const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
649
- const currentAutoClear = renderer.autoClear;
650
- const currentClearAlpha = renderer.getClearAlpha();
651
- const currentScissorTest = renderer.getScissorTest();
652
- renderer.getClearColor(clearColor);
653
- // NOTE null: the environment uses the 'outward' path. 'volume' lighting marches every environment light in each volume.
654
- this.environment = this.environmentLights.update(renderer, scene, this.settings);
655
- this.updateTargets(renderer);
656
- this.updateFroxelArea(volumes, camera);
657
- const cam = camera;
658
- this.froxelUniforms.froxelProjectionInverse.value.copy(camera.projectionMatrixInverse);
659
- this.froxelUniforms.frameFadeRadius.value = getFrameFadeRadius(this.settings);
660
- this.integrateMaterial.frameCameraNear.value = cam.near;
661
- this.integrateMaterial.frameCameraFar.value = cam.far;
662
- this.integrateMaterial.frameCameraOrthographic.value = cam.isOrthographicCamera ? 1 : 0;
663
- this.integrateMaterial.setSrgbBlending(this.settings.srgbBlending && renderer.outputColorSpace === THREE.SRGBColorSpace, renderer.toneMapping === THREE.NoToneMapping);
664
- // NOTE Pass materials are unlit. Nested renders do not update shadow maps.
665
- renderer.autoClear = false;
666
- renderer.setScissorTest(false);
667
- renderer.setClearColor(0x000000, 0.0);
668
- // NOTE Golden ratio steps give a new, evenly spread jitter value for each frame
669
- this.froxelUniforms.frameJitter.value = this.settings.jitter ? (this.jitterIndex * 0.618034) % 1.0 : -1.0;
670
- this.jitterIndex = (this.jitterIndex + 1) % 1024;
671
- this.passHook?.begin?.("froxels");
672
- if (this.isFrameLighting()) {
673
- this.renderFrameLighting(renderer, scene, camera, volumes, casters);
674
- }
675
- else {
676
- this.renderInject(renderer, scene, camera, volumes);
677
- }
678
- if (this.settings.temporal) {
679
- this.passHook?.begin?.("temporal");
680
- this.renderTemporal(renderer, camera);
681
- this.passHook?.end?.("temporal");
682
- }
683
- else {
684
- this.historyValid = false;
685
- }
686
- this.passHook?.end?.("froxels");
687
- this.gridFreshCamera = null;
688
- renderer.setScissorTest(currentScissorTest);
689
- renderer.autoClear = currentAutoClear;
690
- renderer.setClearColor(clearColor, currentClearAlpha);
691
- renderer.setRenderTarget(currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel);
692
- }
693
- // NOTE Froxel area of the volumes, for the passes over the froxel grid and for the integrate pass
694
- updateFroxelArea(volumes, camera) {
695
- const { froxelGrid, froxelRange } = this.froxelUniforms;
696
- const { x: width, y: height, z: depth } = froxelGrid.value;
697
- const area = getFroxelArea(volumes, camera, width, height, froxelRange.value, depth, this.froxelArea);
698
- const { frameAreaRect, frameAreaSliceStart } = this.froxelAreaUniforms;
699
- frameAreaRect.value.copy(area.rect);
700
- frameAreaSliceStart.value = area.first;
701
- this.areaGeometry.instanceCount = area.count;
702
- // NOTE One more cell on each side: the linear filter of the integrate pass reads one cell away
703
- const { x0, y0, x1, y1 } = getClipRect(area.rect, width, height, area.count > 0 ? 1 : 0);
704
- this.integrateMaterial.frameScreenRect.value.set(x0, y0, x1, y1);
705
- this.integrateMaterial.frameSliceRange.value.set(area.first, area.first + area.count);
706
- }
707
- // NOTE Blends this frame into the history. The integrate pass then reads the blended froxels.
708
- renderTemporal(renderer, camera) {
709
- const material = this.temporalMaterial;
710
- const readTarget = this.historyTargets[this.historyIndex];
711
- const writeTarget = this.historyTargets[1 - this.historyIndex];
712
193
  const cam = camera;
713
- material.frameCurrentMap.value = this.atlasTarget.textures[0];
714
- material.frameHistoryMap.value = readTarget.textures[0];
715
- material.frameCurrentAlphaMap.value = this.atlasTarget.textures.at(-1);
716
- material.frameHistoryAlphaMap.value = readTarget.textures.at(-1);
717
- material.frameUseHistory.value = this.historyValid && this.historyCamera === camera ? 1 : 0;
718
- material.frameTemporalBlend.value = Math.min(1.0, Math.max(0.01, this.settings.temporalBlend));
719
- material.frameCameraMatrixWorld.value.copy(camera.matrixWorld);
720
- material.framePreviousViewMatrix.value.copy(this.previousViewMatrix);
721
- material.framePreviousProjectionMatrix.value.copy(this.previousProjectionMatrix);
722
- material.framePreviousRange.value.copy(this.previousRange);
723
- this.temporalMesh.layers.mask = camera.layers.mask;
724
- // NOTE The pass draws only the froxel area. The clear empties the other froxels.
725
- renderer.setRenderTarget(writeTarget);
726
- renderer.clear(true, false, false);
727
- renderer.render(this.temporalScene, camera);
728
- this.integrateMaterial.froxelAtlas.value = writeTarget.textures[0];
729
- this.integrateMaterial.froxelAlphaAtlas.value = writeTarget.textures.at(-1);
730
- this.historyIndex = 1 - this.historyIndex;
731
- this.historyValid = true;
732
- this.historyCamera = camera;
733
- this.previousViewMatrix.copy(camera.matrixWorldInverse);
734
- this.previousProjectionMatrix.copy(cam.projectionMatrix);
735
- this.previousRange.copy(this.froxelUniforms.froxelRange.value);
736
- }
737
- // NOTE PMREM rotation and intensity uniforms read the environment of the rendered pass scene
738
- copyEnvironment(target, scene) {
739
- target.environment = scene.environment ?? null;
740
- target.environmentIntensity = scene.environmentIntensity ?? 1.0;
741
- if (scene.environmentRotation)
742
- target.environmentRotation.copy(scene.environmentRotation);
194
+ const buffer = renderer.getDrawingBufferSize(new THREE.Vector2());
195
+ const canvas = renderer.getSize(new THREE.Vector2());
196
+ const { lights, emissionLight, shadowLights } = this.#lights(scene, camera);
197
+ // K6.5b: three draws its pending shadow maps now (before this update's submit), so the occluders are this frame's
198
+ const occluders = this.settings.occlusion ? this.#occluders.input(renderer, scene, camera, shadowLights) : [];
199
+ const hook = this.passHook;
200
+ hook?.begin?.();
201
+ const encoder = device.createCommandEncoder({ label: "vdb three frame" });
202
+ const u = core.update(encoder, {
203
+ frameId: this.#frameId++,
204
+ camera: {
205
+ view: camera.matrixWorldInverse.elements,
206
+ projection: camera.projectionMatrix.elements,
207
+ near: cam.near,
208
+ far: cam.far,
209
+ orthographic: !!cam.isOrthographicCamera,
210
+ reversedDepth: !!renderer.reversedDepthBuffer,
211
+ id: camera.id,
212
+ },
213
+ viewport: { drawingBuffer: [buffer.x, buffer.y], canvas: [canvas.x, canvas.y] },
214
+ lights,
215
+ emissionLight,
216
+ environment: this.#environment.input(renderer, scene),
217
+ occluders,
218
+ }, { froxels: this.froxels, ...(hook?.timestampWrites ? { timestampWrites: hook.timestampWrites } : {}) });
219
+ device.queue.submit([encoder.finish()]);
220
+ // K6.5: the receivers read the maps with the state they were drawn with (copied to their uniforms now, before they draw)
221
+ this.volumeShadows.sync(u.outputs.volumeShadows, core.redrawStats.volumeShadows);
222
+ hook?.end?.(u);
223
+ this.#frameKey = { renderId, camera, scene, result: u };
224
+ return u;
225
+ }
226
+ /** The core volume of a frame volume: its dense source uploaded once on the core side, or a slot of a sparse source. */
227
+ #volumeOf(frameVolume, device) {
228
+ if (frameVolume.source.kind !== "dense")
229
+ return this.#sparseVolumeOf(frameVolume);
230
+ const three = frameVolume.source;
231
+ let source = this.#denseSources.get(three);
232
+ if (!source) {
233
+ source = vdbDenseSource(device, three.volume, { label: "vdb three dense" });
234
+ this.#denseSources.set(three, source);
235
+ }
236
+ else if (source.volume !== three.volume) {
237
+ source.replace(three.volume);
238
+ }
239
+ let handle = this.#volumes.get(frameVolume);
240
+ if (handle && handle.slot.source !== source) {
241
+ handle.remove();
242
+ handle = undefined;
243
+ }
244
+ if (!handle) {
245
+ handle = this.#core.addVolume(source);
246
+ this.#volumes.set(frameVolume, handle);
247
+ }
248
+ return handle;
743
249
  }
744
- prepareLightScene(scene, camera, mesh) {
745
- this.copyEnvironment(this.injectScene, scene);
746
- this.injectMesh.visible = mesh === this.injectMesh;
747
- this.lightingMesh.visible = mesh === this.lightingMesh;
748
- mesh.layers.mask = camera.layers.mask;
749
- return this.updateLights(scene, camera);
250
+ /**
251
+ * K6.1d: the core volume of a frame volume on a sparse source: one core `vdbSparseSource` per pool and source options
252
+ * (its pyramids are the core's own), one slot per three source with the same grids, boxes and stats. K6.8a: the three
253
+ * source is a handle; its TSL half (and its own pyramid) is never made here.
254
+ */
255
+ #sparseVolumeOf(frameVolume) {
256
+ const three = frameVolume.source;
257
+ const pool = three.grids.pool;
258
+ const types = three.grids.options.types;
259
+ const options = {
260
+ lod: three.lod,
261
+ normalize: three.normalize,
262
+ followImage: three.followImage,
263
+ fastTrilinear: three.fastTrilinear,
264
+ cacheAccessor: three.cacheAccessor,
265
+ ...(three.pyramidOptions?.pyramidMax !== undefined ? { pyramidMax: three.pyramidOptions.pyramidMax } : {}),
266
+ ...(types ? { types } : {}),
267
+ // K3.2f (internal): the brick cache; absent when off, so the key (and the source) is the one without it
268
+ ...(three.brickCache && three.brickCache !== "off" ? { brickCache: three.brickCache, ...three.brickOptions } : {}),
269
+ };
270
+ const key = JSON.stringify(options);
271
+ let byKey = this.#sparseSources.get(pool);
272
+ if (!byKey)
273
+ this.#sparseSources.set(pool, (byKey = new Map()));
274
+ let source = byKey.get(key);
275
+ if (!source) {
276
+ source = vdbCoreSparseSource(pool, { ...options, label: "vdb three sparse" });
277
+ byKey.set(key, source);
278
+ }
279
+ let handle = this.#volumes.get(frameVolume);
280
+ let slot = this.#sparseSlots.get(three);
281
+ if (!slot || slot.source !== source || slot.removed) {
282
+ slot?.remove();
283
+ const aux = three.auxBoxes ?? { mask: null, albedo: null, emission: null };
284
+ const auxIndexBoxes = Object.fromEntries(Object.entries(aux).filter(([, b]) => b));
285
+ slot = source.volume(three.ids, three.followImage ? { stats: three.stats } : { indexBox: three.indexBox, auxIndexBoxes, stats: three.stats });
286
+ this.#sparseSlots.set(three, slot);
287
+ this.#slotStats.set(slot, three.stats);
288
+ }
289
+ else if (this.#slotStats.get(slot) !== three.stats) {
290
+ // the three source re-read its stats (`refreshStats()` after a replace): the core slot takes them now, instead of
291
+ // a frame or two later from its own readback of the same image (a coarse-first swap's first full frame, G16a)
292
+ slot.stats = { ...three.stats };
293
+ this.#slotStats.set(slot, three.stats);
294
+ }
295
+ if (handle && handle.slot !== slot) {
296
+ handle.remove();
297
+ handle = undefined;
298
+ }
299
+ if (!handle) {
300
+ handle = this.#core.addVolume(slot);
301
+ this.#volumes.set(frameVolume, handle);
302
+ }
303
+ return handle;
304
+ }
305
+ /** Frees the sparse sources (their slots and pyramids); the pools are the host's. */
306
+ #disposeSparse() {
307
+ for (const byKey of this.#sparseSources.values())
308
+ for (const s of byKey.values())
309
+ s.dispose();
310
+ this.#sparseSources = new Map();
311
+ this.#sparseSlots = new WeakMap();
312
+ }
313
+ /** A frame volume's props as the core's params. */
314
+ #setParams(p, v, matrixWorld) {
315
+ const wrap = v.wrap3D === THREE.RepeatWrapping ? "repeat" : v.wrap3D === THREE.MirroredRepeatWrapping ? "mirror" : "clamp";
316
+ const params = {
317
+ matrixWorld: matrixWorld.elements.slice(),
318
+ baseColor: [v.baseColor.r, v.baseColor.g, v.baseColor.b],
319
+ scatterColor: [v.scatterColor.r, v.scatterColor.g, v.scatterColor.b],
320
+ extinction: v.extinction,
321
+ extinctionScale: [v.extinctionScale.x, v.extinctionScale.y, v.extinctionScale.z],
322
+ // K6.4: a preset name ('smoke', 'air', …) or a number (his getFrameAngstromExponent)
323
+ angstromExponent: getFrameAngstromExponent(v.angstromExponent),
324
+ densityScale: v.densityScale,
325
+ normalizeDensity: v.normalizeDensity,
326
+ densityMean: v.densityMean,
327
+ densityCutoff: v.densityCutoff,
328
+ absorbance: v.absorbance,
329
+ opacity: v.opacity,
330
+ emissiveIntensity: v.emissiveIntensity,
331
+ temperatureRange: [v.temperatureRange.x, v.temperatureRange.y],
332
+ offset3D: [v.offset3D.x, v.offset3D.y, v.offset3D.z],
333
+ wrap3D: wrap,
334
+ lights: v.lights,
335
+ shadowSteps: v.shadowSteps,
336
+ mipmaps: v.mipmaps,
337
+ hdda: v.hdda,
338
+ phase: v.phase,
339
+ phaseG: v.phaseG,
340
+ phaseBackG: v.phaseBackG,
341
+ phaseBackWeight: v.phaseBackWeight,
342
+ phaseGExponent: v.phaseGExponent,
343
+ emissionColor: this.#emissionColor(v),
344
+ };
345
+ Object.assign(p, params);
346
+ }
347
+ /** K6.5: the volume's emission colour as core data ('white' when unset). */
348
+ #emissionColor(v) {
349
+ return v.emissionColor ?? "white";
750
350
  }
751
- renderInject(renderer, scene, camera, volumes) {
752
- const { atlasTarget, injectScene, injectMesh } = this;
753
- this.prepareLightScene(scene, camera, this.injectMesh);
754
- renderer.setRenderTarget(atlasTarget);
755
- renderer.clear(true, false, false);
756
- for (let i = 0; i < volumes.length; i++) {
757
- const { frameVolume, volume } = volumes[i];
758
- const injectMaterial = this.getInjectMaterial(frameVolume);
759
- // NOTE Draw only the froxel rectangle and the slices of this volume. One instance for each slice.
760
- if (!this.getFroxelRect(volume, camera, injectMaterial.frameRect.value)) {
761
- continue;
351
+ /**
352
+ * The scene's lights in the camera's layers as core lights (his visitLight). K6.5: a shadow light with the volume
353
+ * shadow filter on it asks for a volume shadow map (spot: the light's own shadow camera, so both maps share one texel
354
+ * grid; point: its cube near / far; directional: cascades fitted by the core); a `VDBFrameEmissionLight` gives the
355
+ * emission probe settings.
356
+ */
357
+ #lights(scene, camera) {
358
+ const out = [];
359
+ // K6.5b: the directional, spot and point lights passed (their shadow maps are the occluders)
360
+ const shadowLights = [];
361
+ let emissionLight = null;
362
+ const position = new THREE.Vector3();
363
+ const target = new THREE.Vector3();
364
+ const size = this.volumeShadows.getMapSize();
365
+ scene.traverseVisible((object) => {
366
+ const light = object;
367
+ if (!light.isLight || !light.layers.test(camera.layers))
368
+ return;
369
+ if (light.isVDBFrameEmissionLight) {
370
+ if (!emissionLight) {
371
+ const e = light;
372
+ emissionLight = { resolution: e.resolution, range: e.range, cascades: e.cascades, distance: e.distance, steps: Math.max(1, Math.round(e.steps)) };
373
+ }
374
+ return;
762
375
  }
763
- const { first, count } = this.getSliceRange(volume);
764
- injectMaterial.frameSliceStart.value = first;
765
- injectMesh.geometry.instanceCount = count;
766
- injectMesh.material = injectMaterial;
767
- injectMaterial.frameCameraMatrixWorld.value.copy(camera.matrixWorld);
768
- injectMaterial.setEnvironment(scene.environment);
769
- setVolumeUniforms(injectMaterial, frameVolume, volume);
770
- injectMaterial.frameLights.value = frameVolume.lights;
771
- injectMaterial.frameShadowSteps.value = frameVolume.shadowSteps;
772
- injectMaterial.frameMultipleScattering.value = getFrameMultipleScattering(this.multipleScatteringMode(), frameVolume.getPhase());
773
- getFrameScatteringOctaves(this.settings, injectMaterial.frameScatteringOctaves.value);
774
- injectMaterial.frameTwoSided.value = getFrameTwoSidedDiffusion(this.settings.multipleScattering);
775
- this.passHook?.begin?.("inject", { volume: frameVolume });
776
- renderer.setRenderTarget(atlasTarget);
777
- renderer.render(injectScene, camera);
778
- this.passHook?.end?.("inject", { volume: frameVolume });
779
- }
780
- }
781
- /** The inject material of a volume: its source is compiled in (DIVERGES: one material per source). */
782
- getInjectMaterial(frameVolume) {
783
- const mipmaps = this.volumeMipmaps(frameVolume);
784
- let material = frameVolume.injectMaterial;
785
- if (!material || material.froxelUniforms !== this.froxelUniforms) {
786
- material?.dispose();
787
- material = new VDBFrameInjectMaterial({
788
- froxelUniforms: this.froxelUniforms,
789
- froxelTileUniforms: this.froxelTileUniforms,
790
- lightUniforms: this.lightUniforms,
791
- source: frameVolume.source,
792
- sourceUniforms: frameVolume.sourceUniforms,
793
- mipmaps,
794
- hdda: frameVolume.hdda,
795
- spectral: this.isSpectral(),
796
- ...(frameVolume.emissionColor ? { emissionColor: frameVolume.emissionColor } : {}),
797
- });
798
- frameVolume.injectMaterial = material;
799
- }
800
- material.setMipmaps(mipmaps);
801
- material.setHdda(frameVolume.hdda);
802
- material.setSpectral(this.isSpectral());
803
- // NOTE The hemisphere and environment-light loops are compiled in only when the scene has those lights (updateLights)
804
- material.setLightTerms(this.lightUniforms.frameHemiCount.value > 0, this.lightUniforms.frameEnvironmentCount.value > 0);
805
- return material;
806
- }
807
- volumeMipmaps(frameVolume) {
808
- return frameVolume.mipmaps && frameVolume.source.lodLevels > 0;
809
- }
810
- /** The 'frame' density material of a volume (source compiled in, as the inject material). */
811
- getDensityMaterial(frameVolume) {
812
- const mipmaps = this.volumeMipmaps(frameVolume);
813
- let material = frameVolume.densityMaterial;
814
- if (!material || material.frameUniforms.froxelUniforms !== this.froxelUniforms) {
815
- material?.dispose();
816
- material = new VDBFrameDensityMaterial({
817
- froxelUniforms: this.froxelUniforms,
818
- froxelTileUniforms: this.froxelTileUniforms,
819
- gridUniforms: this.gridUniforms,
820
- environmentGridUniforms: this.environmentGridUniforms,
821
- densityShadowUniforms: this.densityShadowUniforms,
822
- lightUniforms: this.lightUniforms,
823
- source: frameVolume.source,
824
- sourceUniforms: frameVolume.sourceUniforms,
825
- mipmaps,
826
- ...(frameVolume.emissionColor ? { emissionColor: frameVolume.emissionColor } : {}),
827
- });
828
- frameVolume.densityMaterial = material;
829
- }
830
- material.setMipmaps(mipmaps);
831
- material.setSpectral(this.isSpectral());
832
- return material;
833
- }
834
- /** The shadow density material of a caster (source compiled in). */
835
- getShadowDensityMaterial(frameVolume) {
836
- const mipmaps = this.volumeMipmaps(frameVolume);
837
- let material = frameVolume.shadowDensityMaterial;
838
- if (!material || material.gridUniforms !== this.gridUniforms) {
839
- material?.dispose();
840
- material = new VDBFrameShadowDensityMaterial({
841
- gridUniforms: this.gridUniforms,
842
- gridTileUniforms: this.gridTileUniforms,
843
- source: frameVolume.source,
844
- sourceUniforms: frameVolume.sourceUniforms,
845
- mipmaps,
846
- });
847
- frameVolume.shadowDensityMaterial = material;
848
- }
849
- material.setMipmaps(mipmaps);
850
- material.setSpectral(this.isSpectral());
851
- return material;
852
- }
853
- // NOTE Combined lighting: density of all volumes, one shadow grid, one lighting pass.
854
- // Lighting and transmittance render calls do not grow with the number of volumes.
855
- renderFrameLighting(renderer, scene, camera, volumes, casters) {
856
- const lights = this.prepareLightScene(scene, camera, this.lightingMesh);
857
- const ms = getFrameMultipleScattering(this.multipleScatteringMode(), this.settings);
858
- const octaves = getFrameScatteringOctaves(this.settings, this.scatteringOctaves);
859
- // NOTE Shadow pass. Extinction of all casters in one world grid, then transmittance to each light.
860
- // It is before the density pass. Then the density pass can sample the shadows of each volume.
861
- this.passHook?.begin?.("shadowDensity");
862
- const useShadows = this.gridFreshCamera === camera ? this.gridReady : this.renderShadowDensity(renderer, camera, casters);
863
- this.passHook?.end?.("shadowDensity");
864
- this.gridFreshCamera = null;
865
- const useEnvironmentGrid = useShadows && lights.environmentGridLights.length > 0;
866
- const spectral = this.isSpectral();
867
- const spectralGroups = getFrameSpectralGroups(lights.shadowLightCount);
868
- if (useShadows) {
869
- const material = this.transmittanceMaterial;
870
- material.frameShadowDensityMap.value = this.shadowDensityTarget.textures[0];
871
- material.frameShadowAbsorptionMap.value = this.shadowDensityTarget.textures.at(-1);
872
- material.frameShadowLightCount.value = lights.shadowLightCount;
873
- material.frameMultipleScattering.value = ms;
874
- material.frameScatteringOctaves.value.copy(octaves);
875
- material.frameTwoSided.value = getFrameTwoSidedDiffusion(this.settings.multipleScattering);
876
- this.transmittanceMesh.layers.mask = camera.layers.mask;
877
- material.setNeural(this.isNeural() ? this.neuralNetwork : null);
878
- if (material.neural) {
879
- this.passHook?.begin?.("gridMips");
880
- this.renderGridMips(renderer, camera);
881
- this.passHook?.end?.("gridMips");
376
+ const i = light.intensity;
377
+ const color = [light.color.r * i, light.color.g * i, light.color.b * i];
378
+ position.setFromMatrixPosition(light.matrixWorld);
379
+ const id = light.id;
380
+ // K6.5: a map for each light the volume shadow filter is on (volumeShadows.update installed it)
381
+ let shadow;
382
+ if (this.settings.castShadows && light.castShadow && this.volumeShadows.entries.has(light)) {
383
+ if (light.isSpotLight) {
384
+ light.shadow.updateMatrices(light);
385
+ const c = light.shadow.camera;
386
+ shadow = { size, view: { viewProjection: new THREE.Matrix4().multiplyMatrices(c.projectionMatrix, c.matrixWorldInverse).elements, near: c.near, far: c.far, orthographic: false } };
387
+ }
388
+ else if (light.isPointLight) {
389
+ const c = light.shadow.camera;
390
+ shadow = { size, view: { near: c.near, far: light.distance || c.far } };
391
+ }
392
+ else if (light.isDirectionalLight)
393
+ shadow = { size, view: "fit" };
882
394
  }
883
- if (this.transmittanceUnchanged(lights.shadowLightCount, spectral ? spectralGroups : 0)) {
884
- this.redrawStats.transmittance.skipped++;
395
+ if ((light.isDirectionalLight || light.isSpotLight || light.isPointLight) && light.castShadow)
396
+ shadowLights.push(light);
397
+ if (light.isAmbientLight)
398
+ out.push({ id, kind: "ambient", color });
399
+ else if (light.isHemisphereLight) {
400
+ const g = light.groundColor;
401
+ const up = position.lengthSq() > 0 ? position.clone().normalize() : new THREE.Vector3(0, 1, 0);
402
+ out.push({ id, kind: "hemisphere", sky: color, ground: [g.r * i, g.g * i, g.b * i], up: [up.x, up.y, up.z] });
885
403
  }
886
- else if (spectral) {
887
- this.redrawStats.transmittance.drawn++;
888
- this.passHook?.begin?.("transmittance");
889
- // NOTE One pass for each slot group in use, each into its own targets
890
- for (let group = 0; group < spectralGroups; group++) {
891
- material.frameSpectralGroup.value = group;
892
- renderer.setRenderTarget(this.getSpectralTransmittanceTarget(group));
893
- renderer.render(this.transmittanceScene, camera);
894
- }
895
- this.passHook?.end?.("transmittance");
404
+ else if (light.isLightProbe) {
405
+ out.push({ id, kind: "probe", sh: light.sh.coefficients.flatMap((c) => [c.x * i, c.y * i, c.z * i]) });
896
406
  }
897
- else {
898
- this.redrawStats.transmittance.drawn++;
899
- this.passHook?.begin?.("transmittance");
900
- renderer.setRenderTarget(this.transmittanceTarget);
901
- renderer.render(this.transmittanceScene, camera);
902
- this.passHook?.end?.("transmittance");
407
+ else if (light.isDirectionalLight) {
408
+ target.setFromMatrixPosition(light.target.matrixWorld).sub(position).normalize();
409
+ out.push({ id, kind: "directional", direction: [target.x, target.y, target.z], color, ...(shadow ? { shadow } : {}) });
903
410
  }
904
- }
905
- if (useEnvironmentGrid) {
906
- this.passHook?.begin?.("environmentGrid");
907
- this.renderEnvironmentGrid(renderer, camera, casters, lights.environmentGridLights, ms, octaves);
908
- this.passHook?.end?.("environmentGrid");
909
- }
910
- const { densityShadowUniforms } = this;
911
- densityShadowUniforms.frameUseShadows.value = useShadows ? 1 : 0;
912
- if (!spectral) {
913
- const transmittance = this.transmittanceTarget;
914
- densityShadowUniforms.frameTransmittanceMap0.value = transmittance.textures[0];
915
- densityShadowUniforms.frameTransmittanceMap1.value = transmittance.textures[1];
916
- densityShadowUniforms.frameTransmittanceMap2.value = transmittance.textures[2];
917
- densityShadowUniforms.frameTransmittanceMap3.value = transmittance.textures[3];
918
- }
919
- densityShadowUniforms.frameShadowSceneLightCount.value = lights.environmentShadowSlot;
920
- getFramePhase(this.settings, densityShadowUniforms.framePhase.value);
921
- getFramePhaseSpectrum(this.settings, densityShadowUniforms.framePhaseSpectrum.value);
922
- densityShadowUniforms.frameScatteringOctaves.value.copy(octaves);
923
- densityShadowUniforms.frameDiffusion.value = isFrameDiffusion(this.multipleScatteringMode()) ? 1 : 0;
924
- densityShadowUniforms.frameEnvironmentGridMap.value = this.environmentGridTarget.texture;
925
- densityShadowUniforms.frameEnvironmentMode.value = useEnvironmentGrid
926
- ? frameDensityEnvironment.grid
927
- : useShadows && lights.environmentLightCount > 0
928
- ? frameDensityEnvironment.none
929
- : frameDensityEnvironment.outward;
930
- densityShadowUniforms.frameCameraMatrixWorld.value.copy(camera.matrixWorld);
931
- // NOTE Spectral: sky up and sky down are in the first two targets of group 0 (bound also without shadows: not his)
932
- if (spectral) {
933
- const skyMaps = densityShadowUniforms.frameSkyTransmittanceMaps;
934
- for (let index = 0; index < skyMaps.length; index++) {
935
- skyMaps[index].value = this.getSpectralTransmittanceTarget(0).textures[index];
411
+ else if (light.isSpotLight) {
412
+ target.setFromMatrixPosition(light.target.matrixWorld).sub(position).normalize();
413
+ out.push({
414
+ id,
415
+ kind: "spot",
416
+ position: [position.x, position.y, position.z],
417
+ direction: [target.x, target.y, target.z],
418
+ color,
419
+ distance: light.distance,
420
+ decay: light.decay,
421
+ cosAngle: Math.cos(light.angle),
422
+ cosPenumbra: Math.cos(light.angle * (1.0 - light.penumbra)),
423
+ ...(shadow ? { shadow } : {}),
424
+ });
936
425
  }
937
- }
938
- this.copyEnvironment(this.densityScene, scene);
939
- // NOTE Density pass. One instanced draw for each volume, one instance for each slice.
940
- this.updatePool(this.densityPool, this.densityScene, volumes, camera, this.setupDensityEntry);
941
- this.densityClearMesh.layers.mask = camera.layers.mask;
942
- this.passHook?.begin?.("density");
943
- renderer.setRenderTarget(this.densityTarget);
944
- renderer.render(this.densityClearScene, camera);
945
- renderer.render(this.densityScene, camera);
946
- this.passHook?.end?.("density");
947
- // NOTE Lighting pass. Each froxel is lit one time from the combined data.
948
- const { lightingMaterial } = this;
949
- const density = this.densityTarget;
950
- lightingMaterial.frameDensityAlbedoMap.value = density.textures[0];
951
- lightingMaterial.frameDensityEmissionMap.value = density.textures[1];
952
- if (spectral) {
953
- lightingMaterial.frameDensityExtinctionMap.value = density.textures[2];
954
- lightingMaterial.frameSpectralGroups.value = useShadows ? spectralGroups : 0;
955
- // NOTE Groups not in use keep the textures they have (their own targets or the initial placeholders); the lighting
956
- // pass does not read them. Not his (he gives them group 0's targets): three's TextureNode uniform hash is its
957
- // texture's uuid, so nodes that hold one texture when the shader is built share one binding, and a group that
958
- // came into use later (an environment light taking a slot after its readback) kept reading group 0.
959
- if (useShadows) {
960
- const maps = lightingMaterial.frameSpectralTransmittanceMaps;
961
- for (let index = 0; index < spectralGroups * 3; index++) {
962
- maps[index].value = this.getSpectralTransmittanceTarget(Math.floor(index / 3)).textures[index % 3];
963
- }
426
+ else if (light.isPointLight) {
427
+ out.push({ id, kind: "point", position: [position.x, position.y, position.z], color, distance: light.distance, decay: light.decay, ...(shadow ? { shadow } : {}) });
964
428
  }
965
- }
966
- else {
967
- lightingMaterial.frameDensityShadowMap0.value = density.textures[2];
968
- lightingMaterial.frameDensityShadowMap1.value = density.textures[3];
969
- }
970
- lightingMaterial.frameShadowLightCount.value = lights.shadowLightCount;
971
- lightingMaterial.frameEnvironmentLightCount.value = useShadows ? lights.environmentLightCount : 0;
972
- lightingMaterial.frameEnvironmentShadowSlot.value = lights.environmentShadowSlot;
973
- lightingMaterial.frameCameraMatrixWorld.value.copy(camera.matrixWorld);
974
- getFramePhase(this.settings, lightingMaterial.framePhase.value);
975
- getFramePhaseSpectrum(this.settings, lightingMaterial.framePhaseSpectrum.value);
976
- lightingMaterial.frameScatteringOctaves.value.copy(octaves);
977
- this.passHook?.begin?.("lighting");
978
- renderer.setRenderTarget(this.atlasTarget);
979
- renderer.clear(true, false, false);
980
- renderer.render(this.injectScene, camera);
981
- this.passHook?.end?.("lighting");
982
- }
983
- // NOTE Whether the transmittance target already holds what this render would draw: the same grid content, target,
984
- // shadow lights and settings. A jittered grid changes in each frame, so it is always drawn.
985
- transmittanceUnchanged(shadowLightCount, spectralGroups = 0) {
986
- const material = this.transmittanceMaterial;
987
- const values = this.nextTransmittanceSignature;
988
- values.length = 0;
989
- // NOTE Spectral rendering has no single transmittance target, only the targets of its groups below
990
- values.push(this.gridState.gridVersion, this.shadowDensityTarget.texture.id, this.transmittanceTarget ? this.transmittanceTarget.texture.id : -1, spectralGroups, shadowLightCount, material.frameMultipleScattering.value);
991
- // NOTE The network: on/off and which weights (a swapped network draws again)
992
- values.push(material.neural ? networkId(material.neural) : 0, material.frameTwoSided.value);
993
- vdbSignaturePushVector(values, material.frameScatteringOctaves.value);
994
- vdbSignaturePushVector(values, this.lightUniforms.frameSkyDirection.value);
995
- for (let group = 0; group < spectralGroups; group++) {
996
- values.push(this.getSpectralTransmittanceTarget(group).texture.id);
997
- }
998
- const shadowLights = material.frameShadowLights.array;
999
- for (let i = 0; i < shadowLightCount; i++) {
1000
- vdbSignaturePushVector(values, shadowLights[i]);
1001
- }
1002
- const jittered = this.froxelUniforms.frameJitter.value >= 0.0;
1003
- const same = !jittered && vdbSameValues(values, this.transmittanceSignature);
1004
- // NOTE A jittered draw matches no signature, so the first frame after jitter is turned off draws again
1005
- if (jittered) {
1006
- values.length = 0;
1007
- }
1008
- this.nextTransmittanceSignature = this.transmittanceSignature;
1009
- this.transmittanceSignature = values;
1010
- return same;
1011
- }
1012
- // NOTE Extinction of all casters in the world shadow grid cascades. Returns false with no casters.
1013
- // NOTE onlyLast: only the last cascade (all volumes), drawn only when castVersion changed. Volume shadows on meshes
1014
- // read only the last cascade; 'frame' lighting needs all cascades.
1015
- renderShadowDensity(renderer, camera, casters, onlyLast = false) {
1016
- const ready = casters.length > 0 && this.updateGrid(casters, camera);
1017
- const castChanged = this.updateGridVersion(ready ? casters : []);
1018
- if (!ready) {
1019
- return false;
1020
- }
1021
- if (onlyLast && !castChanged) {
1022
- this.redrawStats.shadowDensity.skipped++;
1023
- return true;
1024
- }
1025
- if (!onlyLast && this.shadowDrawnVersion === this.gridState.gridVersion && this.shadowDrawnTarget === this.shadowDensityTarget) {
1026
- this.redrawStats.shadowDensity.skipped++;
1027
- return true;
1028
- }
1029
- this.redrawStats.shadowDensity.drawn++;
1030
- // NOTE The clear below empties every cascade, so a draw of the last one alone leaves no full grid to keep
1031
- this.shadowDrawnVersion = onlyLast ? -1 : this.gridState.gridVersion;
1032
- this.shadowDrawnTarget = this.shadowDensityTarget;
1033
- const count = this.gridUniforms.frameGridCount.value;
1034
- const cascadeCasters = vdbFrameCascadeCasters(casters, onlyLast ? count - 1 : 0, count, this.cascadeCasterPool);
1035
- this.updatePool(this.shadowPool, this.shadowScene, cascadeCasters, camera, this.setupShadowEntry);
1036
- renderer.setRenderTarget(this.shadowDensityTarget);
1037
- renderer.clear(true, false, false);
1038
- renderer.render(this.shadowScene, camera);
1039
- return true;
429
+ });
430
+ return { lights: out, emissionLight, shadowLights };
1040
431
  }
1041
432
  /**
1042
- * Makes the world shadow grid one time in a render, before the first lit mesh (the volume shadow maps need it).
1043
- * 'frame' lighting uses it again in the same render. Returns false with no casters. `renderId`: three's node frame
1044
- * render id (three-internals.ts).
433
+ * @internal K6.8a: the core volume a frame volume draws as (null before its first render with this renderer). Its
434
+ * `slot.source` is the core source the frame renderer made for it; a sparse volume's pyramids live there (its
435
+ * `gpuBytes`), not in the three source (demo 15's GPU bytes).
1045
436
  */
1046
- prepareShadowGrid(renderer, scene, camera, renderId) {
1047
- if (this.gridRenderId === renderId && this.gridCamera === camera) {
1048
- return this.gridReady;
1049
- }
1050
- this.gridRenderId = renderId;
1051
- this.gridCamera = camera;
1052
- const { casters } = this.collectVolumes(renderer, scene, camera);
1053
- const currentRenderTarget = renderer.getRenderTarget();
1054
- const currentActiveCubeFace = renderer.getActiveCubeFace();
1055
- const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
1056
- const currentAutoClear = renderer.autoClear;
1057
- const currentClearAlpha = renderer.getClearAlpha();
1058
- const currentScissorTest = renderer.getScissorTest();
1059
- renderer.getClearColor(clearColor);
1060
- renderer.autoClear = false;
1061
- renderer.setScissorTest(false);
1062
- renderer.setClearColor(0x000000, 0.0);
1063
- this.updateGridTargets();
1064
- this.passHook?.begin?.("shadowDensity");
1065
- // NOTE 'volume' lighting: only the last cascade, for the volume shadow maps
1066
- this.gridReady = this.renderShadowDensity(renderer, camera, casters, !this.isFrameLighting());
1067
- this.passHook?.end?.("shadowDensity");
1068
- this.gridFreshCamera = camera;
1069
- renderer.setScissorTest(currentScissorTest);
1070
- renderer.autoClear = currentAutoClear;
1071
- renderer.setClearColor(clearColor, currentClearAlpha);
1072
- renderer.setRenderTarget(currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel);
1073
- return this.gridReady;
1074
- }
1075
- // NOTE gridVersion changes when the cascades, a caster transform, a caster's data or a caster's shadow props change.
1076
- // castVersion changes only for the last cascade. Returns true when castVersion changed.
1077
- updateGridVersion(casters) {
1078
- const { frameGridMin, frameGridSize, frameGridCount, frameGridResolution } = this.gridUniforms;
1079
- return vdbFrameUpdateGridSignatures(this.gridState, casters, frameGridCount.value, frameGridResolution.value, this.isSpectral(), frameGridMin.array, frameGridSize.array, (values, { frameVolume, volume }) => {
1080
- vdbSignaturePushElements(values, volume.matrixWorld.elements);
1081
- pushCasterSource(values, frameVolume);
1082
- values.push(frameVolume.baseColor.r, frameVolume.baseColor.g, frameVolume.baseColor.b);
1083
- values.push(frameVolume.getDensityScale(), frameVolume.densityCutoff, frameVolume.extinction);
1084
- vdbSignaturePushVector(values, getFrameExtinctionSpectrum(frameVolume, extinctionSpectrum));
1085
- values.push(frameVolume.absorbance, frameVolume.mipmaps ? 1 : 0, frameVolume.wrap3D);
1086
- vdbSignaturePushVector(values, frameVolume.offset3D);
1087
- });
1088
- }
1089
- // NOTE Environment grid of the last cascade. It is drawn again only when its signature changes.
1090
- // NOTE Signature: the grid lights, the last cascade, and the caster data that the shadow density pass reads.
1091
- renderEnvironmentGrid(renderer, camera, casters, gridLights, ms, octaves) {
1092
- const { frameGridMin, frameGridSize, frameGridCount, frameGridResolution } = this.gridUniforms;
1093
- const cascade = frameGridCount.value - 1;
1094
- const previous = this.environmentGridSignature;
1095
- const signature = this.nextEnvironmentGridSignature;
1096
- this.environmentGridUniforms.frameEnvironmentGridCascade.value = cascade;
1097
- signature.length = 0;
1098
- signature.push(frameGridResolution.value, cascade, this.isSpectral() ? 1 : 0, ms);
1099
- vdbSignaturePushVector(signature, octaves);
1100
- vdbSignaturePushVector(signature, frameGridMin.array[cascade]);
1101
- vdbSignaturePushVector(signature, frameGridSize.array[cascade]);
1102
- for (const light of gridLights) {
1103
- vdbSignaturePushElements(signature, light.direction);
1104
- vdbSignaturePushElements(signature, light.color);
1105
- }
1106
- // NOTE The caster data the shadow density pass reads: the grid version covers it (transforms, sources, props)
1107
- signature.push(this.gridState.castVersion, casters.length);
1108
- if (vdbSameValues(signature, previous)) {
1109
- this.redrawStats.environmentGrid.skipped++;
1110
- return;
1111
- }
1112
- this.redrawStats.environmentGrid.drawn++;
1113
- this.environmentGridSignature = signature;
1114
- this.nextEnvironmentGridSignature = previous;
1115
- const material = this.environmentGridMaterial;
1116
- material.frameShadowDensityMap.value = this.shadowDensityTarget.textures[0];
1117
- material.frameShadowAbsorptionMap.value = this.shadowDensityTarget.textures.at(-1);
1118
- material.frameLightCount.value = gridLights.length;
1119
- material.frameMultipleScattering.value = ms;
1120
- material.frameScatteringOctaves.value.copy(octaves);
1121
- const directions = material.frameLightDirections.array;
1122
- const colors = material.frameLightColors.array;
1123
- for (let i = 0; i < gridLights.length; i++) {
1124
- directions[i].fromArray(gridLights[i].direction);
1125
- colors[i].fromArray(gridLights[i].color);
1126
- }
1127
- this.environmentGridMesh.layers.mask = camera.layers.mask;
1128
- renderer.setRenderTarget(this.environmentGridTarget);
1129
- renderer.render(this.environmentGridScene, camera);
1130
- }
1131
- // NOTE Draws the lat-long environment map with the rotation of the scene and intensity 1.0, then reads it.
1132
- renderEnvironmentMap(renderer, scene) {
1133
- if (!this.environmentMapTarget) {
1134
- this.environmentMapTarget = createRenderTarget(frameEnvironmentMapWidth, frameEnvironmentMapHeight, {
1135
- type: THREE.FloatType,
1136
- minFilter: THREE.NearestFilter,
1137
- magFilter: THREE.NearestFilter,
1138
- });
1139
- }
1140
- this.copyEnvironment(this.environmentMapScene, scene);
1141
- this.environmentMapScene.environmentIntensity = 1.0;
1142
- this.environmentMapMaterial.setEnvironment(scene.environment);
1143
- const currentRenderTarget = renderer.getRenderTarget();
1144
- renderer.setRenderTarget(this.environmentMapTarget);
1145
- renderer.render(this.environmentMapScene, this.environmentMapCamera);
1146
- renderer.setRenderTarget(currentRenderTarget);
1147
- return renderer.readRenderTargetPixelsAsync(this.environmentMapTarget, 0, 0, frameEnvironmentMapWidth, frameEnvironmentMapHeight);
1148
- }
1149
- // NOTE updatePool setup of the density pass: one instance for each slice of the volume
1150
- setupDensityEntry = (entry, { frameVolume, volume }, camera) => {
1151
- if (!this.getFroxelRect(volume, camera, entry.rect)) {
1152
- return false;
1153
- }
1154
- const { first, count } = this.getSliceRange(volume);
1155
- entry.mesh.material = this.getDensityMaterial(frameVolume);
1156
- entry.mesh.material.setEnvironment(this.densityScene.environment);
1157
- entry.frameVolume = frameVolume;
1158
- entry.volume = volume;
1159
- entry.sliceStart = first;
1160
- entry.geometry.instanceCount = count;
1161
- return true;
1162
- };
1163
- // NOTE updatePool setup of the shadow density pass: the voxels of the volume in one cascade
1164
- setupShadowEntry = (entry, { caster, cascade }) => {
1165
- const { frameVolume, volume } = caster;
1166
- const range = this.getGridRange(volume, cascade);
1167
- if (!range) {
1168
- return false;
1169
- }
1170
- entry.mesh.material = this.getShadowDensityMaterial(frameVolume);
1171
- entry.frameVolume = frameVolume;
1172
- entry.volume = volume;
1173
- entry.rect.copy(range.rect);
1174
- entry.sliceStart = range.first;
1175
- entry.geometry.instanceCount = range.count;
1176
- return true;
1177
- };
1178
- // NOTE Pool entries are reused between frames. Unused entries are hidden.
1179
- // Each entry takes the material of its volume and sets the volume uniforms before its draw.
1180
- updatePool(pool, scene, items, camera, setup) {
1181
- let used = 0;
1182
- for (let i = 0; i < items.length; i++) {
1183
- if (!pool[used]) {
1184
- const geometry = new THREE.InstancedBufferGeometry();
1185
- geometry.setAttribute("position", tileQuadPosition);
1186
- const mesh = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial());
1187
- mesh.frustumCulled = false;
1188
- mesh.matrixAutoUpdate = false;
1189
- const entry = { mesh, geometry, frameVolume: null, volume: null, rect: new THREE.Vector4(), sliceStart: 0 };
1190
- mesh.onBeforeRender = () => {
1191
- const material = mesh.material;
1192
- setVolumeUniforms(material, entry.frameVolume, entry.volume);
1193
- material.frameRect.value.copy(entry.rect);
1194
- material.frameSliceStart.value = entry.sliceStart;
1195
- };
1196
- scene.add(mesh);
1197
- pool[used] = entry;
1198
- }
1199
- const entry = pool[used];
1200
- if (setup(entry, items[i], camera)) {
1201
- entry.mesh.visible = true;
1202
- entry.mesh.layers.mask = camera.layers.mask;
1203
- used++;
1204
- }
1205
- }
1206
- for (let i = used; i < pool.length; i++) {
1207
- pool[i].mesh.visible = false;
1208
- }
1209
- }
1210
- // NOTE Screen rectangle of the volume in froxel cells. Writes target. Returns false when it covers no cell.
1211
- getFroxelRect(volume, camera, target) {
1212
- const { x: width, y: height } = this.froxelUniforms.froxelGrid.value;
1213
- return getFroxelRect(volume, camera, width, height, target);
1214
- }
1215
- getCascadeCount() {
1216
- return Math.min(frameMaxShadowCascades, Math.max(1, Math.round(this.settings.shadowCascades)));
1217
- }
1218
- // NOTE Shadow grid cascades of the casters (tools/frame/grid.ts). Returns false with no casters.
1219
- updateGrid(casters, camera) {
1220
- const { frameGridMin, frameGridSize, frameGridVoxel, frameGridCount, frameGridResolution } = this.gridUniforms;
1221
- cameraPosition.setFromMatrixPosition(camera.matrixWorld);
1222
- const count = vdbFrameGridCascades(casters.map((c) => c.volume.worldBox), cameraPosition, this.settings.shadowDistance, frameGridResolution.value, this.getCascadeCount(), frameGridMin.array, frameGridSize.array, frameGridVoxel.array);
1223
- if (count > 0) {
1224
- frameGridCount.value = count;
1225
- }
1226
- return count > 0;
1227
- }
1228
- // NOTE Voxel rectangle and atlas slices of the volume in one shadow grid cascade
1229
- getGridRange(volume, cascade) {
1230
- const { frameGridMin, frameGridVoxel, frameGridResolution } = this.gridUniforms;
1231
- const found = vdbFrameGridRange(volume.worldBox, cascade, frameGridResolution.value, frameGridMin.array, frameGridVoxel.array, this.gridRange);
1232
- return found ? this.gridRange : null;
1233
- }
1234
- // NOTE A pooled light record of updateLights: (position, w type), (color, w spot cos), (spot direction, cos), falloff
1235
- getLightRecord(list) {
1236
- if (list.length === list.entries.length) {
1237
- list.entries.push({ position: new THREE.Vector4(), color: new THREE.Vector4(), spot: new THREE.Vector4(), falloff: new THREE.Vector2() });
1238
- }
1239
- const record = list.entries[list.length++];
1240
- record.spot.set(0.0, 0.0, 0.0, 0.0);
1241
- record.falloff.set(0.0, 0.0);
1242
- return record;
1243
- }
1244
- // NOTE Light i of updateLights in slot order: directional, point, spot
1245
- getSortedLight(index) {
1246
- const { directions, points, spots } = this.lightState;
1247
- if (index < directions.length) {
1248
- return directions.entries[index];
1249
- }
1250
- if (index < directions.length + points.length) {
1251
- return points.entries[index - directions.length];
1252
- }
1253
- return spots.entries[index - directions.length - points.length];
1254
- }
1255
- // NOTE traverseVisible callback of updateLights. this.lightState holds the state of the current call.
1256
- visitLight = (object) => {
1257
- const state = this.lightState;
1258
- const light = object;
1259
- if (!light.isLight || !light.layers.test(state.camera.layers)) {
1260
- return;
1261
- }
1262
- const { frameAmbientColor, frameLightProbe, frameHemiSkyColor, frameHemiGroundColor, frameSkyDirection, frameHemiSkyColors, frameHemiGroundColors, frameHemiDirections } = this.lightUniforms;
1263
- lightColor.copy(light.color).multiplyScalar(light.intensity);
1264
- lightPosition.setFromMatrixPosition(light.matrixWorld);
1265
- if (light.isAmbientLight) {
1266
- frameAmbientColor.value.add(lightColor);
1267
- }
1268
- else if (light.isHemisphereLight) {
1269
- const hemiCount = state.hemiCount;
1270
- if (hemiCount < frameMaxHemisphereLights) {
1271
- frameHemiSkyColors.array[hemiCount].set(lightColor.r, lightColor.g, lightColor.b);
1272
- frameHemiDirections.array[hemiCount].copy(lightPosition).normalize();
1273
- }
1274
- frameHemiSkyColor.value.add(lightColor);
1275
- lightColor.copy(light.groundColor).multiplyScalar(light.intensity);
1276
- frameHemiGroundColor.value.add(lightColor);
1277
- if (hemiCount < frameMaxHemisphereLights) {
1278
- frameHemiGroundColors.array[hemiCount].set(lightColor.r, lightColor.g, lightColor.b);
1279
- }
1280
- state.hemiCount++;
1281
- if (!state.hasSky && lightPosition.lengthSq() > 0.0) {
1282
- frameSkyDirection.value.copy(lightPosition).normalize();
1283
- state.hasSky = true;
1284
- }
1285
- }
1286
- else if (light.isLightProbe) {
1287
- const { coefficients } = light.sh;
1288
- for (let i = 0; i < coefficients.length; i++) {
1289
- frameLightProbe.array[i].addScaledVector(coefficients[i], light.intensity);
1290
- }
1291
- }
1292
- else if (light.isDirectionalLight) {
1293
- const record = this.getLightRecord(state.directions);
1294
- lightTarget.setFromMatrixPosition(light.target.matrixWorld);
1295
- lightPosition.sub(lightTarget).normalize();
1296
- record.position.set(lightPosition.x, lightPosition.y, lightPosition.z, 1.0);
1297
- record.color.set(lightColor.r, lightColor.g, lightColor.b, 0.0);
1298
- }
1299
- else if (light.isSpotLight) {
1300
- const record = this.getLightRecord(state.spots);
1301
- lightTarget.setFromMatrixPosition(light.target.matrixWorld);
1302
- record.position.set(lightPosition.x, lightPosition.y, lightPosition.z, 3.0);
1303
- record.color.set(lightColor.r, lightColor.g, lightColor.b, Math.cos(light.angle * (1.0 - light.penumbra)));
1304
- lightTarget.subVectors(lightPosition, lightTarget).normalize();
1305
- record.spot.set(lightTarget.x, lightTarget.y, lightTarget.z, Math.cos(light.angle));
1306
- record.falloff.set(light.distance, light.decay);
1307
- }
1308
- else if (light.isPointLight) {
1309
- const record = this.getLightRecord(state.points);
1310
- record.position.set(lightPosition.x, lightPosition.y, lightPosition.z, 2.0);
1311
- record.color.set(lightColor.r, lightColor.g, lightColor.b, 0.0);
1312
- record.falloff.set(light.distance, light.decay);
1313
- }
1314
- };
1315
- // NOTE Scene lights into the light uniforms. Node materials in custom passes have no three.js light uniforms.
1316
- // Shadow slots follow the light order: directional, point, spot.
1317
- // NOTE Returns this.lightResult, used again in the next call.
1318
- updateLights(scene, camera) {
1319
- const u = this.lightUniforms;
1320
- const state = this.lightState;
1321
- const { directions, points, spots } = state;
1322
- state.camera = camera;
1323
- state.hemiCount = 0;
1324
- state.hasSky = false;
1325
- directions.length = 0;
1326
- points.length = 0;
1327
- spots.length = 0;
1328
- u.frameAmbientColor.value.setRGB(0.0, 0.0, 0.0);
1329
- u.frameHemiSkyColor.value.setRGB(0.0, 0.0, 0.0);
1330
- u.frameHemiGroundColor.value.setRGB(0.0, 0.0, 0.0);
1331
- u.frameSkyDirection.value.set(0.0, 1.0, 0.0);
1332
- for (const v of u.frameLightProbe.array) {
1333
- v.set(0.0, 0.0, 0.0);
1334
- }
1335
- scene.traverseVisible(this.visitLight);
1336
- state.camera = null;
1337
- const { hemiCount } = state;
1338
- const lightTotal = directions.length + points.length + spots.length;
1339
- if ((lightTotal > frameMaxLights || hemiCount > frameMaxHemisphereLights) && !this.lightLimitWarned) {
1340
- console.warn(`VDBFrameRenderer: too many lights. Only ${frameMaxLights} lights and ${frameMaxHemisphereLights} hemisphere lights are used.`);
1341
- this.lightLimitWarned = true;
1342
- }
1343
- u.frameHemiCount.value = Math.min(hemiCount, frameMaxHemisphereLights);
1344
- const count = Math.min(lightTotal, frameMaxLights);
1345
- const positions = u.frameLightPositions.array;
1346
- const colors = u.frameLightColors.array;
1347
- const spotArray = u.frameLightSpots.array;
1348
- const falloffs = u.frameLightFalloffs.array;
1349
- for (let i = 0; i < count; i++) {
1350
- const light = this.getSortedLight(i);
1351
- positions[i].copy(light.position);
1352
- colors[i].copy(light.color);
1353
- spotArray[i].copy(light.spot);
1354
- falloffs[i].copy(light.falloff);
1355
- }
1356
- u.frameLightCount.value = count;
1357
- // NOTE Environment lights. 'volume' lighting marches all of them in each volume.
1358
- const { environment } = this;
1359
- const environmentCount = environment ? environment.count : 0;
1360
- const environmentDirections = u.frameEnvironmentDirections.array;
1361
- const environmentColors = u.frameEnvironmentColors.array;
1362
- u.frameEnvironmentCount.value = environmentCount;
1363
- for (let i = 0; i < environmentCount; i++) {
1364
- environmentDirections[i].fromArray(environment.directions[i]);
1365
- environmentColors[i].fromArray(environment.colors[i]);
1366
- }
1367
- // NOTE 'frame' lighting. Scene lights take the first shadow slots.
1368
- // NOTE The dominant 'directional' environment light (light 0) takes the next free slot. Other environment lights go to the environment grid.
1369
- const sceneShadowCount = Math.min(count, frameShadowLightSlots);
1370
- const shadowLights = this.transmittanceMaterial.frameShadowLights.array;
1371
- const frameLighting = this.isFrameLighting() && environmentCount > 0;
1372
- const environmentLightCount = frameLighting &&
1373
- environment.mode === frameEnvironmentModes.directional &&
1374
- sceneShadowCount < frameShadowLightSlots &&
1375
- // NOTE Diffusion: all environment lights use the environment grid. Then both lights of an opposite pair get the same march.
1376
- !isFrameDiffusion(this.multipleScatteringMode())
1377
- ? 1
1378
- : 0;
1379
- const result = this.lightResult;
1380
- const environmentGridLights = result.environmentGridLights;
1381
- environmentGridLights.length = 0;
1382
- for (let i = 0; i < sceneShadowCount; i++) {
1383
- shadowLights[i].copy(this.getSortedLight(i).position);
1384
- }
1385
- if (environmentLightCount > 0) {
1386
- shadowLights[sceneShadowCount].fromArray(environment.directions[0]).setW(1.0);
1387
- }
1388
- u.frameEnvironmentUnshadowed.value.set(0.0, 0.0, 0.0);
1389
- if (frameLighting) {
1390
- for (let i = environmentLightCount; i < environmentCount; i++) {
1391
- const entries = this.environmentGridLightEntries;
1392
- const index = environmentGridLights.length;
1393
- if (index === entries.length) {
1394
- entries.push({ direction: [], color: [] });
1395
- }
1396
- entries[index].direction = environment.directions[i];
1397
- entries[index].color = environment.colors[i];
1398
- environmentGridLights.push(entries[index]);
1399
- u.frameEnvironmentUnshadowed.value.add(environmentColors[i]);
1400
- }
1401
- }
1402
- u.frameEnvironmentUnshadowed.value.max(vector3.set(0.0, 0.0, 0.0));
1403
- result.shadowLightCount = sceneShadowCount + environmentLightCount;
1404
- result.environmentLightCount = environmentLightCount;
1405
- result.environmentShadowSlot = sceneShadowCount;
1406
- return result;
437
+ coreVolumeOf(frameVolume) {
438
+ return this.#volumes.get(frameVolume) ?? null;
1407
439
  }
440
+ /** Frees the core renderer, its stand-ins and the shadow filters. A later render makes them again. */
1408
441
  dispose() {
1409
- // NOTE Puts back the shadow filter of each light; the new instance installs again on the next render
442
+ // NOTE Puts back the shadow filter of each light; the receivers build again without the volume shadow
1410
443
  this.volumeShadows.dispose();
1411
- this.volumeShadows = new VDBFrameVolumeShadows(this);
1412
- this.gridRenderId = -1;
1413
- this.gridCamera = null;
1414
- this.historyTargets.forEach((target) => target?.dispose());
1415
- this.historyTargets = [null, null];
1416
- this.historyValid = false;
1417
- this.disposeSpectralTransmittanceTargets();
1418
- for (const key of ["atlasTarget", "densityTarget", "shadowDensityTarget", "transmittanceTarget", "environmentMapTarget", "environmentGridTarget"]) {
1419
- this[key]?.dispose();
1420
- this[key] = null;
1421
- }
1422
- this.environmentLights = new VDBFrameEnvironmentLights((renderer, scene) => this.renderEnvironmentMap(renderer, scene));
1423
- this.environment = null;
1424
- this.environmentGridSignature = [];
1425
- this.gridMipTargets.forEach((target) => target.dispose());
1426
- this.gridMipTargets = [];
1427
- this.gridMipSignature = [];
1428
- for (const { mesh, geometry } of [...this.densityPool, ...this.shadowPool]) {
1429
- mesh.parent?.remove(mesh);
1430
- geometry.dispose();
1431
- }
1432
- this.densityPool = [];
1433
- this.shadowPool = [];
1434
- this.shadowDrawnVersion = -1;
1435
- this.shadowDrawnTarget = null;
1436
- for (const material of [this.integrateMaterial, this.lightingMaterial, this.transmittanceMaterial, this.temporalMaterial, this.densityClearMaterial, this.environmentMapMaterial, this.environmentGridMaterial, this.gridMipMaterial]) {
1437
- material.dispose();
1438
- }
1439
- this.injectMesh.geometry.dispose();
1440
- this.injectMesh.material.dispose();
1441
- for (const mesh of [this.transmittanceMesh, this.environmentMapMesh, this.environmentGridMesh, this.gridMipMesh]) {
1442
- mesh.geometry.dispose();
1443
- }
1444
- this.areaGeometry.dispose();
1445
- this.cachedFrame = -1;
1446
- this.cachedCamera = null;
444
+ this.#core?.dispose();
445
+ this.#core = null;
446
+ this.#device = null;
447
+ this.#environment.dispose();
448
+ this.#prefix.dispose();
449
+ this.#alphaPrefix.dispose();
450
+ this.#material?.dispose();
451
+ this.#material = null;
452
+ this.#volumes = new Map();
453
+ this.#disposeSparse();
454
+ this.#frameKey = null;
455
+ this.#cachedFrame = -1;
456
+ this.#cachedCamera = null;
1447
457
  }
1448
458
  }
1449
- /** frameShaderChunks.js L800–830 `setVolumeUniforms`: the values of one volume before its draw (inject, density or shadow density). */
1450
- export function setVolumeUniforms(material, frameVolume, volume) {
1451
- const u = material.volumeUniforms;
1452
- const s = material.sourceUniforms;
1453
- // K5.9: a source.replace() (a sequence frame, a resize) reaches the uniforms without volume.updateSource()
1454
- frameVolume.syncSource();
1455
- u.frameViewToLocal.value.copy(volume.viewToLocal);
1456
- u.frameLocalToView.value.copy(volume.localToView);
1457
- u.frameWorldToLocal.value.copy(volume.worldToLocal);
1458
- s.worldScale.value = volume.matrixWorld.getMaxScaleOnAxis();
1459
- s.baseColor.value.copy(frameVolume.baseColor);
1460
- u.frameScatterColor.value.copy(frameVolume.scatterColor);
1461
- s.extinction.value = frameVolume.extinction;
1462
- getFrameExtinctionSpectrum(frameVolume, u.frameExtinctionSpectrum.value);
1463
- s.densityScale.value = frameVolume.getDensityScale();
1464
- s.densityCutoff.value = frameVolume.densityCutoff;
1465
- u.frameAbsorbance.value = frameVolume.absorbance;
1466
- u.frameOpacity.value = frameVolume.opacity;
1467
- s.emissiveIntensity.value = frameVolume.emissiveIntensity;
1468
- s.temperatureRange.value.copy(frameVolume.temperatureRange);
1469
- s.offset3D.value.copy(frameVolume.offset3D);
1470
- s.wrap3D.value = frameVolume.wrap3D;
1471
- // K5.9: the volume's phase overrides, else the renderer's settings (the 'volume' lighting phase; 'frame' lighting
1472
- // draws its one phase from the settings in the lighting pass)
1473
- const phase = frameVolume.getPhase();
1474
- getFramePhase(phase, u.framePhase.value);
1475
- getFramePhaseSpectrum(phase, u.framePhaseSpectrum.value);
1476
- }
1477
459
  /** Per three renderer shared instances (`vdbFrameRenderer(renderer)`). */
1478
460
  const sharedByRenderer = new WeakMap();
1479
461
  let shared = null;