@pmndrs/vdb 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (576) hide show
  1. package/CHANGELOG.md +592 -2
  2. package/README.md +85 -37
  3. package/THIRD_PARTY_NOTICES.md +197 -29
  4. package/dist/core/compute/atlas.d.ts +10 -2
  5. package/dist/core/compute/atlas.js +6 -1
  6. package/dist/core/compute/atlas.js.map +1 -1
  7. package/dist/core/compute/index.d.ts +3 -3
  8. package/dist/core/compute/index.js +2 -2
  9. package/dist/core/compute/index.js.map +1 -1
  10. package/dist/core/compute/majorant-build.d.ts +45 -0
  11. package/dist/core/compute/majorant-build.js +193 -0
  12. package/dist/core/compute/majorant-build.js.map +1 -0
  13. package/dist/core/compute/multi-scale.d.ts +155 -0
  14. package/dist/core/compute/multi-scale.js +684 -0
  15. package/dist/core/compute/multi-scale.js.map +1 -0
  16. package/dist/core/compute/pyramid.d.ts +22 -7
  17. package/dist/core/compute/pyramid.js +22 -9
  18. package/dist/core/compute/pyramid.js.map +1 -1
  19. package/dist/core/compute/shared.d.ts +1 -0
  20. package/dist/core/compute/shared.js.map +1 -1
  21. package/dist/core/compute/stats.d.ts +10 -3
  22. package/dist/core/compute/stats.js +6 -1
  23. package/dist/core/compute/stats.js.map +1 -1
  24. package/dist/core/compute/value-transform.d.ts +8 -1
  25. package/dist/core/compute/value-transform.js +9 -3
  26. package/dist/core/compute/value-transform.js.map +1 -1
  27. package/dist/core/errors.d.ts +10 -0
  28. package/dist/core/errors.js +8 -0
  29. package/dist/core/errors.js.map +1 -1
  30. package/dist/core/frame/emission.d.ts +85 -0
  31. package/dist/core/frame/emission.js +422 -0
  32. package/dist/core/frame/emission.js.map +1 -0
  33. package/dist/core/frame/environment.d.ts +47 -0
  34. package/dist/core/frame/environment.js +178 -0
  35. package/dist/core/frame/environment.js.map +1 -0
  36. package/dist/core/frame/index.d.ts +39 -0
  37. package/dist/core/frame/index.js +27 -0
  38. package/dist/core/frame/index.js.map +1 -0
  39. package/dist/core/frame/kernels.d.ts +115 -0
  40. package/dist/core/frame/kernels.js +496 -0
  41. package/dist/core/frame/kernels.js.map +1 -0
  42. package/dist/core/frame/limits.d.ts +67 -0
  43. package/dist/core/frame/limits.js +109 -0
  44. package/dist/core/frame/limits.js.map +1 -0
  45. package/dist/core/frame/phase.d.ts +17 -0
  46. package/dist/core/frame/phase.js +53 -0
  47. package/dist/core/frame/phase.js.map +1 -0
  48. package/dist/core/frame/pipelines.d.ts +49 -0
  49. package/dist/core/frame/pipelines.js +147 -0
  50. package/dist/core/frame/pipelines.js.map +1 -0
  51. package/dist/core/frame/renderer.d.ts +122 -0
  52. package/dist/core/frame/renderer.js +1712 -0
  53. package/dist/core/frame/renderer.js.map +1 -0
  54. package/dist/core/frame/resources.d.ts +71 -0
  55. package/dist/core/frame/resources.js +100 -0
  56. package/dist/core/frame/resources.js.map +1 -0
  57. package/dist/core/frame/scattering.d.ts +97 -0
  58. package/dist/core/frame/scattering.js +332 -0
  59. package/dist/core/frame/scattering.js.map +1 -0
  60. package/dist/core/frame/settings.d.ts +243 -0
  61. package/dist/core/frame/settings.js +67 -0
  62. package/dist/core/frame/settings.js.map +1 -0
  63. package/dist/core/frame/shadows.d.ts +55 -0
  64. package/dist/core/frame/shadows.js +460 -0
  65. package/dist/core/frame/shadows.js.map +1 -0
  66. package/dist/core/frame/types.d.ts +415 -0
  67. package/dist/core/frame/types.js +49 -0
  68. package/dist/core/frame/types.js.map +1 -0
  69. package/dist/core/frame/uniforms.d.ts +105 -0
  70. package/dist/core/frame/uniforms.js +276 -0
  71. package/dist/core/frame/uniforms.js.map +1 -0
  72. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  73. package/dist/core/frame/wgsl/chunks.js +728 -0
  74. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  75. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  76. package/dist/core/frame/wgsl/emission.js +353 -0
  77. package/dist/core/frame/wgsl/emission.js.map +1 -0
  78. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  79. package/dist/core/frame/wgsl/environment.js +711 -0
  80. package/dist/core/frame/wgsl/environment.js.map +1 -0
  81. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  82. package/dist/core/frame/wgsl/gather.js +850 -0
  83. package/dist/core/frame/wgsl/gather.js.map +1 -0
  84. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  85. package/dist/core/frame/wgsl/integrate.js +213 -0
  86. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  87. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  88. package/dist/core/frame/wgsl/lighting.js +1636 -0
  89. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  90. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  91. package/dist/core/frame/wgsl/occluders.js +95 -0
  92. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  93. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  94. package/dist/core/frame/wgsl/resolve.js +205 -0
  95. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  96. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  97. package/dist/core/frame/wgsl/shadows.js +328 -0
  98. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  99. package/dist/core/half.d.ts +11 -0
  100. package/dist/core/half.js +22 -0
  101. package/dist/core/half.js.map +1 -0
  102. package/dist/core/index.d.ts +25 -3
  103. package/dist/core/index.js +23 -4
  104. package/dist/core/index.js.map +1 -1
  105. package/dist/core/internal.d.ts +17 -1
  106. package/dist/core/internal.js +18 -1
  107. package/dist/core/internal.js.map +1 -1
  108. package/dist/core/pool/image-header.d.ts +13 -2
  109. package/dist/core/pool/image-header.js +24 -5
  110. package/dist/core/pool/image-header.js.map +1 -1
  111. package/dist/core/pool/layout.d.ts +35 -1
  112. package/dist/core/pool/layout.js +51 -2
  113. package/dist/core/pool/layout.js.map +1 -1
  114. package/dist/core/pool/limits.d.ts +1 -0
  115. package/dist/core/pool/limits.js +1 -0
  116. package/dist/core/pool/limits.js.map +1 -1
  117. package/dist/core/pool/pool.d.ts +120 -15
  118. package/dist/core/pool/pool.js +255 -24
  119. package/dist/core/pool/pool.js.map +1 -1
  120. package/dist/core/reference/index.d.ts +6 -0
  121. package/dist/core/reference/index.js +7 -0
  122. package/dist/core/reference/index.js.map +1 -0
  123. package/dist/core/reference/renderer.d.ts +105 -0
  124. package/dist/core/reference/renderer.js +474 -0
  125. package/dist/core/reference/renderer.js.map +1 -0
  126. package/dist/core/reference/wgsl.d.ts +65 -0
  127. package/dist/core/reference/wgsl.js +803 -0
  128. package/dist/core/reference/wgsl.js.map +1 -0
  129. package/dist/{three → core}/sequence.d.ts +32 -2
  130. package/dist/{three → core}/sequence.js +24 -2
  131. package/dist/core/sequence.js.map +1 -0
  132. package/dist/core/source/brick-cache.d.ts +165 -0
  133. package/dist/core/source/brick-cache.js +627 -0
  134. package/dist/core/source/brick-cache.js.map +1 -0
  135. package/dist/core/source/dense-fill.d.ts +53 -0
  136. package/dist/core/source/dense-fill.js +377 -0
  137. package/dist/core/source/dense-fill.js.map +1 -0
  138. package/dist/core/source/dense.d.ts +33 -2
  139. package/dist/core/source/dense.js +121 -24
  140. package/dist/core/source/dense.js.map +1 -1
  141. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  142. package/dist/core/source/sparse-wgsl.js +481 -0
  143. package/dist/core/source/sparse-wgsl.js.map +1 -0
  144. package/dist/core/source/sparse.d.ts +192 -0
  145. package/dist/core/source/sparse.js +762 -0
  146. package/dist/core/source/sparse.js.map +1 -0
  147. package/dist/core/source/types.d.ts +59 -2
  148. package/dist/core/source/types.js.map +1 -1
  149. package/dist/core/surface/index.d.ts +10 -0
  150. package/dist/core/surface/index.js +9 -0
  151. package/dist/core/surface/index.js.map +1 -0
  152. package/dist/core/surface/level-set-pass.d.ts +140 -0
  153. package/dist/core/surface/level-set-pass.js +291 -0
  154. package/dist/core/surface/level-set-pass.js.map +1 -0
  155. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  156. package/dist/core/surface/level-set-wgsl.js +99 -0
  157. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  158. package/dist/core/surface/points.d.ts +109 -0
  159. package/dist/core/surface/points.js +226 -0
  160. package/dist/core/surface/points.js.map +1 -0
  161. package/dist/core/types.d.ts +12 -3
  162. package/dist/core/types.js +6 -2
  163. package/dist/core/types.js.map +1 -1
  164. package/dist/core/wgsl/api.d.ts +29 -5
  165. package/dist/core/wgsl/api.js +110 -27
  166. package/dist/core/wgsl/api.js.map +1 -1
  167. package/dist/core/wgsl/generate.d.ts +8 -0
  168. package/dist/core/wgsl/generate.js +195 -22
  169. package/dist/core/wgsl/generate.js.map +1 -1
  170. package/dist/core/wgsl/lean.d.ts +50 -0
  171. package/dist/core/wgsl/lean.js +327 -0
  172. package/dist/core/wgsl/lean.js.map +1 -0
  173. package/dist/core/wgsl/level-set.d.ts +5 -1
  174. package/dist/core/wgsl/level-set.js +11 -5
  175. package/dist/core/wgsl/level-set.js.map +1 -1
  176. package/dist/core/wgsl/majorant.d.ts +62 -0
  177. package/dist/core/wgsl/majorant.js +381 -0
  178. package/dist/core/wgsl/majorant.js.map +1 -0
  179. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +2 -2
  180. package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
  181. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
  182. package/dist/core/wgsl/types.d.ts +97 -3
  183. package/dist/core/wgsl/types.js.map +1 -1
  184. package/dist/three/coarse-first.d.ts +53 -8
  185. package/dist/three/coarse-first.js +24 -6
  186. package/dist/three/coarse-first.js.map +1 -1
  187. package/dist/three/compute.d.ts +12 -2
  188. package/dist/three/compute.js +16 -6
  189. package/dist/three/compute.js.map +1 -1
  190. package/dist/three/device.d.ts +7 -0
  191. package/dist/three/device.js +3 -0
  192. package/dist/three/device.js.map +1 -1
  193. package/dist/three/frame/core-environment.d.ts +38 -0
  194. package/dist/three/frame/core-environment.js +154 -0
  195. package/dist/three/frame/core-environment.js.map +1 -0
  196. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  197. package/dist/three/frame/core-integrate-material.js +162 -0
  198. package/dist/three/frame/core-integrate-material.js.map +1 -0
  199. package/dist/three/frame/core-occluders.d.ts +53 -0
  200. package/dist/three/frame/core-occluders.js +193 -0
  201. package/dist/three/frame/core-occluders.js.map +1 -0
  202. package/dist/three/frame/core-structs.d.ts +34 -0
  203. package/dist/three/frame/core-structs.js +61 -0
  204. package/dist/three/frame/core-structs.js.map +1 -0
  205. package/dist/three/frame/core-textures.d.ts +41 -0
  206. package/dist/three/frame/core-textures.js +114 -0
  207. package/dist/three/frame/core-textures.js.map +1 -0
  208. package/dist/three/frame/emission-light.d.ts +64 -114
  209. package/dist/three/frame/emission-light.js +188 -567
  210. package/dist/three/frame/emission-light.js.map +1 -1
  211. package/dist/three/frame/index.d.ts +11 -31
  212. package/dist/three/frame/index.js +9 -29
  213. package/dist/three/frame/index.js.map +1 -1
  214. package/dist/three/frame/medium.d.ts +12 -0
  215. package/dist/three/frame/medium.js.map +1 -1
  216. package/dist/three/frame/renderer.d.ts +58 -454
  217. package/dist/three/frame/renderer.js +409 -1427
  218. package/dist/three/frame/renderer.js.map +1 -1
  219. package/dist/three/frame/spectrum.d.ts +0 -14
  220. package/dist/three/frame/spectrum.js +2 -23
  221. package/dist/three/frame/spectrum.js.map +1 -1
  222. package/dist/three/frame/three-internals.d.ts +3 -8
  223. package/dist/three/frame/three-internals.js +13 -11
  224. package/dist/three/frame/three-internals.js.map +1 -1
  225. package/dist/three/frame/volume-shadows.d.ts +93 -107
  226. package/dist/three/frame/volume-shadows.js +278 -631
  227. package/dist/three/frame/volume-shadows.js.map +1 -1
  228. package/dist/three/frame/volume.d.ts +91 -33
  229. package/dist/three/frame/volume.js +63 -51
  230. package/dist/three/frame/volume.js.map +1 -1
  231. package/dist/three/grid-node.d.ts +34 -1
  232. package/dist/three/grid-node.js +36 -1
  233. package/dist/three/grid-node.js.map +1 -1
  234. package/dist/three/index.d.ts +20 -11
  235. package/dist/three/index.js +21 -12
  236. package/dist/three/index.js.map +1 -1
  237. package/dist/three/internal.d.ts +14 -8
  238. package/dist/three/internal.js +11 -7
  239. package/dist/three/internal.js.map +1 -1
  240. package/dist/three/level-set-material.d.ts +81 -8
  241. package/dist/three/level-set-material.js +162 -125
  242. package/dist/three/level-set-material.js.map +1 -1
  243. package/dist/three/level-set-physical-material.d.ts +154 -0
  244. package/dist/three/level-set-physical-material.js +253 -0
  245. package/dist/three/level-set-physical-material.js.map +1 -0
  246. package/dist/three/level-set-velocity.d.ts +94 -0
  247. package/dist/three/level-set-velocity.js +208 -0
  248. package/dist/three/level-set-velocity.js.map +1 -0
  249. package/dist/three/material.d.ts +141 -11
  250. package/dist/three/material.js +161 -18
  251. package/dist/three/material.js.map +1 -1
  252. package/dist/three/points.d.ts +60 -4
  253. package/dist/three/points.js +140 -9
  254. package/dist/three/points.js.map +1 -1
  255. package/dist/three/sparse-source.d.ts +49 -117
  256. package/dist/three/sparse-source.js +109 -580
  257. package/dist/three/sparse-source.js.map +1 -1
  258. package/dist/three/volume-source.d.ts +11 -156
  259. package/dist/three/volume-source.js +29 -272
  260. package/dist/three/volume-source.js.map +1 -1
  261. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  262. package/dist/tools/cpu/brick-atlas.js +129 -0
  263. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  264. package/dist/tools/cpu/compute.d.ts +23 -4
  265. package/dist/tools/cpu/compute.js +35 -14
  266. package/dist/tools/cpu/compute.js.map +1 -1
  267. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  268. package/dist/tools/cpu/lean-reads.js +262 -0
  269. package/dist/tools/cpu/lean-reads.js.map +1 -0
  270. package/dist/tools/cpu/level-set.d.ts +42 -3
  271. package/dist/tools/cpu/level-set.js +59 -7
  272. package/dist/tools/cpu/level-set.js.map +1 -1
  273. package/dist/tools/cpu/majorant.d.ts +265 -0
  274. package/dist/tools/cpu/majorant.js +541 -0
  275. package/dist/tools/cpu/majorant.js.map +1 -0
  276. package/dist/tools/cpu/march.d.ts +93 -2
  277. package/dist/tools/cpu/march.js +165 -14
  278. package/dist/tools/cpu/march.js.map +1 -1
  279. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  280. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  281. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  282. package/dist/tools/cpu/points.d.ts +29 -0
  283. package/dist/tools/cpu/points.js +38 -0
  284. package/dist/tools/cpu/points.js.map +1 -0
  285. package/dist/tools/cpu/read-value.d.ts +19 -6
  286. package/dist/tools/cpu/read-value.js +32 -17
  287. package/dist/tools/cpu/read-value.js.map +1 -1
  288. package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
  289. package/dist/tools/cpu/sample-trilinear.js +19 -7
  290. package/dist/tools/cpu/sample-trilinear.js.map +1 -1
  291. package/dist/tools/cpu/stride-tables.d.ts +2 -2
  292. package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
  293. package/dist/tools/cpu/stride-tables.generated.js +7 -6
  294. package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
  295. package/dist/tools/cpu/stride-tables.js +1 -1
  296. package/dist/tools/cpu/stride-tables.js.map +1 -1
  297. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  298. package/dist/tools/cpu/surface-nets.js +597 -0
  299. package/dist/tools/cpu/surface-nets.js.map +1 -0
  300. package/dist/tools/errors.d.ts +9 -0
  301. package/dist/tools/errors.js +9 -0
  302. package/dist/tools/errors.js.map +1 -1
  303. package/dist/tools/frame/ambient.d.ts +98 -0
  304. package/dist/tools/frame/ambient.js +274 -0
  305. package/dist/tools/frame/ambient.js.map +1 -0
  306. package/dist/tools/frame/blackbody.d.ts +15 -0
  307. package/dist/tools/frame/blackbody.js +35 -0
  308. package/dist/tools/frame/blackbody.js.map +1 -1
  309. package/dist/tools/frame/brick-cache.d.ts +165 -0
  310. package/dist/tools/frame/brick-cache.js +326 -0
  311. package/dist/tools/frame/brick-cache.js.map +1 -0
  312. package/dist/tools/frame/emission.d.ts +9 -0
  313. package/dist/tools/frame/emission.js +9 -1
  314. package/dist/tools/frame/emission.js.map +1 -1
  315. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  316. package/dist/tools/frame/environment-gpu.js +280 -0
  317. package/dist/tools/frame/environment-gpu.js.map +1 -0
  318. package/dist/tools/frame/environment.d.ts +3 -2
  319. package/dist/tools/frame/environment.js +8 -4
  320. package/dist/tools/frame/environment.js.map +1 -1
  321. package/dist/tools/frame/froxel.d.ts +58 -0
  322. package/dist/tools/frame/froxel.js +115 -0
  323. package/dist/tools/frame/froxel.js.map +1 -0
  324. package/dist/tools/frame/grid.d.ts +90 -0
  325. package/dist/tools/frame/grid.js +112 -13
  326. package/dist/tools/frame/grid.js.map +1 -1
  327. package/dist/tools/frame/index.d.ts +14 -0
  328. package/dist/tools/frame/index.js +45 -4
  329. package/dist/tools/frame/index.js.map +1 -1
  330. package/dist/tools/frame/medium.d.ts +16 -0
  331. package/dist/tools/frame/medium.js +3 -1
  332. package/dist/tools/frame/medium.js.map +1 -1
  333. package/dist/tools/frame/mie.d.ts +9 -0
  334. package/dist/tools/frame/mie.js +18 -0
  335. package/dist/tools/frame/mie.js.map +1 -1
  336. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  337. package/dist/tools/frame/mlp-nn.js +159 -0
  338. package/dist/tools/frame/mlp-nn.js.map +1 -0
  339. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  340. package/dist/tools/frame/mlp-tza.js +186 -0
  341. package/dist/tools/frame/mlp-tza.js.map +1 -0
  342. package/dist/tools/frame/mlp.d.ts +183 -0
  343. package/dist/tools/frame/mlp.js +434 -0
  344. package/dist/tools/frame/mlp.js.map +1 -0
  345. package/dist/tools/frame/ms-exit.d.ts +42 -0
  346. package/dist/tools/frame/ms-exit.js +90 -0
  347. package/dist/tools/frame/ms-exit.js.map +1 -0
  348. package/dist/tools/frame/multi-scale.d.ts +152 -0
  349. package/dist/tools/frame/multi-scale.js +302 -0
  350. package/dist/tools/frame/multi-scale.js.map +1 -0
  351. package/dist/tools/frame/neural-weights.d.ts +6 -5
  352. package/dist/tools/frame/neural-weights.js +234 -235
  353. package/dist/tools/frame/neural-weights.js.map +1 -1
  354. package/dist/tools/frame/neural.js +1 -1
  355. package/dist/tools/frame/neural.js.map +1 -1
  356. package/dist/tools/frame/occluders.d.ts +51 -0
  357. package/dist/tools/frame/occluders.js +72 -0
  358. package/dist/tools/frame/occluders.js.map +1 -0
  359. package/dist/tools/frame/pyramid-layout.d.ts +17 -0
  360. package/dist/tools/frame/pyramid-layout.js +47 -0
  361. package/dist/tools/frame/pyramid-layout.js.map +1 -1
  362. package/dist/tools/frame/shadows.d.ts +110 -0
  363. package/dist/tools/frame/shadows.js +286 -0
  364. package/dist/tools/frame/shadows.js.map +1 -1
  365. package/dist/tools/frame/sparse.d.ts +82 -0
  366. package/dist/tools/frame/sparse.js +242 -1
  367. package/dist/tools/frame/sparse.js.map +1 -1
  368. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  369. package/dist/tools/frame/spectral-stack.js +391 -0
  370. package/dist/tools/frame/spectral-stack.js.map +1 -0
  371. package/dist/tools/frame/spectral.d.ts +21 -2
  372. package/dist/tools/frame/spectral.js +30 -8
  373. package/dist/tools/frame/spectral.js.map +1 -1
  374. package/dist/tools/frame/stack.d.ts +115 -0
  375. package/dist/tools/frame/stack.js +290 -0
  376. package/dist/tools/frame/stack.js.map +1 -0
  377. package/dist/tools/frame/view.d.ts +131 -0
  378. package/dist/tools/frame/view.js +337 -0
  379. package/dist/tools/frame/view.js.map +1 -0
  380. package/dist/tools/index.d.ts +66 -15
  381. package/dist/tools/index.js +55 -11
  382. package/dist/tools/index.js.map +1 -1
  383. package/dist/tools/internal.d.ts +58 -17
  384. package/dist/tools/internal.js +65 -11
  385. package/dist/tools/internal.js.map +1 -1
  386. package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
  387. package/dist/tools/nanovdb/build-from-vdb.js +10 -2
  388. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
  389. package/dist/tools/nanovdb/bytes.d.ts +17 -4
  390. package/dist/tools/nanovdb/bytes.js +46 -3
  391. package/dist/tools/nanovdb/bytes.js.map +1 -1
  392. package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
  393. package/dist/tools/nanovdb/coarse-first.js +7 -1
  394. package/dist/tools/nanovdb/coarse-first.js.map +1 -1
  395. package/dist/tools/nanovdb/half.d.ts +22 -0
  396. package/dist/tools/nanovdb/half.js +73 -0
  397. package/dist/tools/nanovdb/half.js.map +1 -0
  398. package/dist/tools/nanovdb/index.d.ts +3 -1
  399. package/dist/tools/nanovdb/index.js +2 -1
  400. package/dist/tools/nanovdb/index.js.map +1 -1
  401. package/dist/tools/nanovdb/inspect.d.ts +10 -1
  402. package/dist/tools/nanovdb/inspect.js +8 -1
  403. package/dist/tools/nanovdb/inspect.js.map +1 -1
  404. package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
  405. package/dist/tools/nanovdb/leaf-codec.js +40 -4
  406. package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
  407. package/dist/tools/nanovdb/quantize.d.ts +39 -10
  408. package/dist/tools/nanovdb/quantize.js +96 -44
  409. package/dist/tools/nanovdb/quantize.js.map +1 -1
  410. package/dist/tools/nanovdb/resample.d.ts +20 -3
  411. package/dist/tools/nanovdb/resample.js +20 -7
  412. package/dist/tools/nanovdb/resample.js.map +1 -1
  413. package/dist/tools/nanovdb/serialize.d.ts +34 -3
  414. package/dist/tools/nanovdb/serialize.js +51 -7
  415. package/dist/tools/nanovdb/serialize.js.map +1 -1
  416. package/dist/tools/nanovdb/stats.d.ts +34 -5
  417. package/dist/tools/nanovdb/stats.js +87 -11
  418. package/dist/tools/nanovdb/stats.js.map +1 -1
  419. package/dist/tools/nanovdb/transform.d.ts +4 -0
  420. package/dist/tools/nanovdb/transform.js +3 -0
  421. package/dist/tools/nanovdb/transform.js.map +1 -1
  422. package/dist/tools/nanovdb/tree.d.ts +14 -3
  423. package/dist/tools/nanovdb/tree.js +25 -13
  424. package/dist/tools/nanovdb/tree.js.map +1 -1
  425. package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
  426. package/dist/tools/nanovdb/write-nvdb.js +108 -28
  427. package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
  428. package/dist/tools/nvdb-file.d.ts +77 -7
  429. package/dist/tools/nvdb-file.js +177 -20
  430. package/dist/tools/nvdb-file.js.map +1 -1
  431. package/dist/tools/nvdb-stream.d.ts +23 -7
  432. package/dist/tools/nvdb-stream.js +78 -34
  433. package/dist/tools/nvdb-stream.js.map +1 -1
  434. package/dist/tools/reference/analytic.d.ts +41 -0
  435. package/dist/tools/reference/analytic.js +95 -0
  436. package/dist/tools/reference/analytic.js.map +1 -0
  437. package/dist/tools/reference/environment.d.ts +62 -0
  438. package/dist/tools/reference/environment.js +154 -0
  439. package/dist/tools/reference/environment.js.map +1 -0
  440. package/dist/tools/reference/index.d.ts +12 -0
  441. package/dist/tools/reference/index.js +13 -0
  442. package/dist/tools/reference/index.js.map +1 -0
  443. package/dist/tools/reference/media.d.ts +14 -0
  444. package/dist/tools/reference/media.js +30 -0
  445. package/dist/tools/reference/media.js.map +1 -0
  446. package/dist/tools/reference/rng.d.ts +20 -0
  447. package/dist/tools/reference/rng.js +30 -0
  448. package/dist/tools/reference/rng.js.map +1 -0
  449. package/dist/tools/reference/scene.d.ts +312 -0
  450. package/dist/tools/reference/scene.js +169 -0
  451. package/dist/tools/reference/scene.js.map +1 -0
  452. package/dist/tools/reference/tables.d.ts +98 -0
  453. package/dist/tools/reference/tables.js +264 -0
  454. package/dist/tools/reference/tables.js.map +1 -0
  455. package/dist/tools/reference/trace.d.ts +160 -0
  456. package/dist/tools/reference/trace.js +497 -0
  457. package/dist/tools/reference/trace.js.map +1 -0
  458. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  459. package/dist/tools/vdb/blosc-write.js +197 -0
  460. package/dist/tools/vdb/blosc-write.js.map +1 -0
  461. package/dist/tools/vdb/blosc.d.ts +35 -5
  462. package/dist/tools/vdb/blosc.js +82 -26
  463. package/dist/tools/vdb/blosc.js.map +1 -1
  464. package/dist/tools/vdb/blosclz.d.ts +33 -0
  465. package/dist/tools/vdb/blosclz.js +112 -0
  466. package/dist/tools/vdb/blosclz.js.map +1 -0
  467. package/dist/tools/vdb/byte-reader.d.ts +13 -3
  468. package/dist/tools/vdb/byte-reader.js +26 -4
  469. package/dist/tools/vdb/byte-reader.js.map +1 -1
  470. package/dist/tools/vdb/compression.d.ts +13 -5
  471. package/dist/tools/vdb/compression.js +13 -2
  472. package/dist/tools/vdb/compression.js.map +1 -1
  473. package/dist/tools/vdb/grid.js +8 -2
  474. package/dist/tools/vdb/grid.js.map +1 -1
  475. package/dist/tools/vdb/index.d.ts +2 -1
  476. package/dist/tools/vdb/index.js.map +1 -1
  477. package/dist/tools/vdb/lz4.d.ts +30 -0
  478. package/dist/tools/vdb/lz4.js +228 -0
  479. package/dist/tools/vdb/lz4.js.map +1 -0
  480. package/dist/tools/vdb/metadata.js +1 -1
  481. package/dist/tools/vdb/metadata.js.map +1 -1
  482. package/dist/tools/vdb/parse.d.ts +24 -2
  483. package/dist/tools/vdb/parse.js +102 -32
  484. package/dist/tools/vdb/parse.js.map +1 -1
  485. package/dist/tools/vdb/point-render-data.d.ts +49 -1
  486. package/dist/tools/vdb/point-render-data.js +91 -11
  487. package/dist/tools/vdb/point-render-data.js.map +1 -1
  488. package/dist/tools/vdb/points.d.ts +26 -0
  489. package/dist/tools/vdb/points.js +46 -5
  490. package/dist/tools/vdb/points.js.map +1 -1
  491. package/dist/tools/vdb/types.d.ts +59 -2
  492. package/dist/tools/vdb/types.js.map +1 -1
  493. package/dist/tools/wvdb/bake.d.ts +38 -9
  494. package/dist/tools/wvdb/bake.js +63 -13
  495. package/dist/tools/wvdb/bake.js.map +1 -1
  496. package/dist/tools/wvdb/dense.d.ts +80 -1
  497. package/dist/tools/wvdb/dense.js +67 -8
  498. package/dist/tools/wvdb/dense.js.map +1 -1
  499. package/dist/tools/wvdb/format.d.ts +59 -0
  500. package/dist/tools/wvdb/format.js +3 -0
  501. package/dist/tools/wvdb/format.js.map +1 -1
  502. package/dist/tools/wvdb/index.d.ts +1 -0
  503. package/dist/tools/wvdb/index.js +1 -0
  504. package/dist/tools/wvdb/index.js.map +1 -1
  505. package/dist/tools/wvdb/level-set.d.ts +10 -2
  506. package/dist/tools/wvdb/level-set.js.map +1 -1
  507. package/dist/tools/wvdb/nanovdb.d.ts +6 -1
  508. package/dist/tools/wvdb/nanovdb.js +5 -1
  509. package/dist/tools/wvdb/nanovdb.js.map +1 -1
  510. package/dist/tools/wvdb/partial.d.ts +74 -0
  511. package/dist/tools/wvdb/partial.js +233 -0
  512. package/dist/tools/wvdb/partial.js.map +1 -0
  513. package/dist/tools/wvdb/read.d.ts +77 -1
  514. package/dist/tools/wvdb/read.js +30 -7
  515. package/dist/tools/wvdb/read.js.map +1 -1
  516. package/dist/tools/wvdb/write.d.ts +23 -1
  517. package/dist/tools/wvdb/write.js +8 -1
  518. package/dist/tools/wvdb/write.js.map +1 -1
  519. package/package.json +2 -1
  520. package/vendor/VENDOR.md +21 -6
  521. package/vendor/pnanovdb.wgsl +52 -14
  522. package/dist/three/frame/blackbody.d.ts +0 -42
  523. package/dist/three/frame/blackbody.js +0 -74
  524. package/dist/three/frame/blackbody.js.map +0 -1
  525. package/dist/three/frame/chunks.d.ts +0 -157
  526. package/dist/three/frame/chunks.js +0 -559
  527. package/dist/three/frame/chunks.js.map +0 -1
  528. package/dist/three/frame/density-material.d.ts +0 -53
  529. package/dist/three/frame/density-material.js +0 -353
  530. package/dist/three/frame/density-material.js.map +0 -1
  531. package/dist/three/frame/environment-grid-material.d.ts +0 -21
  532. package/dist/three/frame/environment-grid-material.js +0 -184
  533. package/dist/three/frame/environment-grid-material.js.map +0 -1
  534. package/dist/three/frame/environment-material.d.ts +0 -22
  535. package/dist/three/frame/environment-material.js +0 -87
  536. package/dist/three/frame/environment-material.js.map +0 -1
  537. package/dist/three/frame/grid-mip-material.d.ts +0 -12
  538. package/dist/three/frame/grid-mip-material.js +0 -61
  539. package/dist/three/frame/grid-mip-material.js.map +0 -1
  540. package/dist/three/frame/inject-material.d.ts +0 -56
  541. package/dist/three/frame/inject-material.js +0 -424
  542. package/dist/three/frame/inject-material.js.map +0 -1
  543. package/dist/three/frame/integrate-material.d.ts +0 -26
  544. package/dist/three/frame/integrate-material.js +0 -198
  545. package/dist/three/frame/integrate-material.js.map +0 -1
  546. package/dist/three/frame/layout.d.ts +0 -34
  547. package/dist/three/frame/layout.js +0 -48
  548. package/dist/three/frame/layout.js.map +0 -1
  549. package/dist/three/frame/lighting-material.d.ts +0 -41
  550. package/dist/three/frame/lighting-material.js +0 -257
  551. package/dist/three/frame/lighting-material.js.map +0 -1
  552. package/dist/three/frame/lights.d.ts +0 -11
  553. package/dist/three/frame/lights.js +0 -16
  554. package/dist/three/frame/lights.js.map +0 -1
  555. package/dist/three/frame/neural.d.ts +0 -14
  556. package/dist/three/frame/neural.js +0 -105
  557. package/dist/three/frame/neural.js.map +0 -1
  558. package/dist/three/frame/phase.d.ts +0 -44
  559. package/dist/three/frame/phase.js +0 -80
  560. package/dist/three/frame/phase.js.map +0 -1
  561. package/dist/three/frame/shadow-density-material.d.ts +0 -30
  562. package/dist/three/frame/shadow-density-material.js +0 -123
  563. package/dist/three/frame/shadow-density-material.js.map +0 -1
  564. package/dist/three/frame/temporal-material.d.ts +0 -29
  565. package/dist/three/frame/temporal-material.js +0 -152
  566. package/dist/three/frame/temporal-material.js.map +0 -1
  567. package/dist/three/frame/transmittance-material.d.ts +0 -31
  568. package/dist/three/frame/transmittance-material.js +0 -315
  569. package/dist/three/frame/transmittance-material.js.map +0 -1
  570. package/dist/three/frame/view.d.ts +0 -103
  571. package/dist/three/frame/view.js +0 -296
  572. package/dist/three/frame/view.js.map +0 -1
  573. package/dist/three/frame/volume-shadow-material.d.ts +0 -36
  574. package/dist/three/frame/volume-shadow-material.js +0 -128
  575. package/dist/three/frame/volume-shadow-material.js.map +0 -1
  576. package/dist/three/sequence.js.map +0 -1
@@ -0,0 +1,291 @@
1
+ /**
2
+ * The raw level-set reference pass (K6.6, design §3.9): level-set surfaces drawn by an engine-free host
3
+ * into its own render pass, through the same `vdbLevelSetSurface` WGSL that `VDBLevelSetMaterial` calls.
4
+ * Writes `frag_depth` (so surfaces depth-test against the host's meshes) and either a Lambert + ambient
5
+ * shade or a G-buffer texel (world normal, ray distance).
6
+ *
7
+ * const surfaces = vdbCreateLevelSetPass(device, pool, { colorFormat: 'rgba8unorm', depthFormat: 'depth24plus' });
8
+ * // per frame, after pool.update(encoder):
9
+ * const pass = encoder.beginRenderPass({ colorAttachments: [...], depthStencilAttachment: { ... } });
10
+ * surfaces.record(pass, { view, projection, viewport: [0, 0, width, height] }, [{ grid: id, color: [1, 0.8, 0.6] }]);
11
+ * pass.end();
12
+ *
13
+ * Each draw rasterizes the back faces of the grid's index box `[min − 1.5, max + 1.5]` (the trilinear
14
+ * support the trace clips to, half a voxel wider) mapped to world space, so the camera may be inside it;
15
+ * the fragment ignores the box and traces the pixel-centre ray (V57). Uniforms go through
16
+ * `queue.writeBuffer`: one `record()` per submitted encoder (the pool's contract).
17
+ */
18
+ import { VDBError } from "../errors.js";
19
+ import { VDB_ALL_SCALAR_TYPES } from "../types.js";
20
+ import { vdbCheckModule, vdbModuleEntries, vdbModuleWgsl } from "../wgsl/generate.js";
21
+ import { prepareRender, renderPipeline } from "../frame/pipelines.js";
22
+ import { BUFFER_USAGE, STAGE, VDBRetireQueue } from "../frame/resources.js";
23
+ import { VDBUniformWriter, vdbUniformStruct } from "../frame/uniforms.js";
24
+ import { vdbMat4Invert, vdbMat4Multiply } from "../../tools/frame/view.js";
25
+ import { vdbLevelSetSurfaceWgsl } from "./level-set-wgsl.js";
26
+ /** Group 0 binding 0: the camera and lights. */
27
+ export const VDB_LEVEL_SET_PASS_FRAME = vdbUniformStruct("VdbLevelSetPassFrame", [
28
+ { name: "viewProjection", type: "mat4x4f" },
29
+ { name: "projectionInverse", type: "mat4x4f" },
30
+ { name: "cameraWorld", type: "mat4x4f" },
31
+ { name: "viewport", type: "vec4f" },
32
+ { name: "lightDirection", type: "vec4f" },
33
+ { name: "lightColor", type: "vec4f" },
34
+ { name: "ambient", type: "vec4f" },
35
+ // x: orthographic
36
+ { name: "flags", type: "vec4u" },
37
+ ]);
38
+ /** Group 0 binding 1 (dynamic offset): one draw. */
39
+ export const VDB_LEVEL_SET_PASS_DRAW = vdbUniformStruct("VdbLevelSetPassDraw", [
40
+ // the proxy box's world corners, corner k = (x: k & 1, y: k & 2, z: k & 4)
41
+ { name: "corners", type: "vec4f", count: 8 },
42
+ { name: "color", type: "vec4f" },
43
+ { name: "grid", type: "u32" },
44
+ { name: "maxSamples", type: "u32" },
45
+ { name: "sdfToIndex", type: "f32" },
46
+ { name: "normalStep", type: "f32" },
47
+ ], 256);
48
+ /** Byte offset of draw 0 (frame record first, 256-aligned). */
49
+ const DRAWS_AT = 512;
50
+ const DRAW_STRIDE = 256;
51
+ /** Pool slot of the pass's module. */
52
+ const POOL_SLOT = { group: 1, firstBinding: 0 };
53
+ /**
54
+ * The 36 corner indices of the box's 12 triangles, counter-clockwise seen from outside in a right-handed
55
+ * world (a unit test checks every triangle's normal points out). Culling front faces draws the back faces.
56
+ */
57
+ export const VDB_LEVEL_SET_BOX_TRIANGLES = Object.freeze([
58
+ 0, 4, 6, 0, 6, 2, 1, 3, 7, 1, 7, 5, 0, 1, 5, 0, 5, 4, 2, 6, 7, 2, 7, 3, 0, 2, 3, 0, 3, 1, 4, 5, 7, 4, 7, 6,
59
+ ]);
60
+ function bad(message) {
61
+ return new VDBError("VDB_BAD_OPTION", `vdbCreateLevelSetPass: ${message}`);
62
+ }
63
+ /** The entry points (after the module and the surface functions). */
64
+ function entriesWgsl(output, cap) {
65
+ const color = output === "gbuffer"
66
+ ? "vec4f(s.normal, s.t)"
67
+ : "vec4f(vdbLsDraw.color.rgb * (vdbLsFrame.ambient.rgb + vdbLsFrame.lightColor.rgb * max(dot(s.normal, -vdbLsFrame.lightDirection.xyz), 0.0)), 1.0)";
68
+ return /* wgsl */ `${VDB_LEVEL_SET_PASS_FRAME.wgsl}
69
+ ${VDB_LEVEL_SET_PASS_DRAW.wgsl}
70
+ @group(0) @binding(0) var<uniform> vdbLsFrame: VdbLevelSetPassFrame;
71
+ @group(0) @binding(1) var<uniform> vdbLsDraw: VdbLevelSetPassDraw;
72
+
73
+ @vertex
74
+ fn vdbLevelSetPassVs(@builtin(vertex_index) i: u32) -> @builtin(position) vec4f {
75
+ var box = array<u32, 36>(${VDB_LEVEL_SET_BOX_TRIANGLES.map((k) => `${k}u`).join(", ")});
76
+ return vdbLsFrame.viewProjection * vec4f(vdbLsDraw.corners[box[i]].xyz, 1.0);
77
+ }
78
+
79
+ struct VdbLevelSetPassOut {
80
+ @location(0) color: vec4f,
81
+ @builtin(frag_depth) depth: f32,
82
+ };
83
+
84
+ @fragment
85
+ fn vdbLevelSetPassFs(@builtin(position) position: vec4f) -> VdbLevelSetPassOut {
86
+ let uv = vdbLevelSetPixelUv(position.xy, vdbLsFrame.viewport);
87
+ let ray = vdbLevelSetViewRay(uv, vdbLsFrame.projectionInverse, vdbLsFrame.cameraWorld, vdbLsFrame.flags.x != 0u);
88
+ let s = vdbLevelSetSurface(vdbLsDraw.grid, ray, vdbLsFrame.viewProjection, vdbLsDraw.sdfToIndex, clamp(vdbLsDraw.maxSamples, 1u, ${cap}u), vdbLsDraw.normalStep);
89
+ if !s.hit || !(s.ndcDepth >= 0.0 && s.ndcDepth <= 1.0) {
90
+ discard;
91
+ }
92
+ var o: VdbLevelSetPassOut;
93
+ o.color = ${color};
94
+ o.depth = s.ndcDepth;
95
+ return o;
96
+ }
97
+ `;
98
+ }
99
+ /** The full WGSL of a level-set pass (module + `vdbLevelSetSurfaceWgsl()` + entries). */
100
+ export function vdbLevelSetPassWgsl(options) {
101
+ const module = vdbModuleWgsl({ slot: POOL_SLOT, types: options.types, profile: "march", helpers: ["levelSet"] });
102
+ return `${module}\n${vdbLevelSetSurfaceWgsl()}\n${entriesWgsl(options.output ?? "shade", options.maxSamplesCap ?? 1024)}`;
103
+ }
104
+ /** The 3x3 determinant of a 3x4 row-major affine's linear part. */
105
+ function det3(m) {
106
+ return m[0] * (m[5] * m[10] - m[6] * m[9]) - m[1] * (m[4] * m[10] - m[6] * m[8]) + m[2] * (m[4] * m[9] - m[5] * m[8]);
107
+ }
108
+ /**
109
+ * The 8 world corners of a grid's proxy box (`[min − 1.5, max + 1.5]` through the 3x4 row-major
110
+ * index-to-world affine), `x, y, z, 1` each. A mirroring affine swaps the x corners so the triangles stay
111
+ * counter-clockwise from outside.
112
+ */
113
+ export function vdbLevelSetProxyCorners(info, out = new Float32Array(32)) {
114
+ const m = info.indexToWorld;
115
+ const lo = info.indexBBox.min.map((v) => v - 1.5);
116
+ const hi = info.indexBBox.max.map((v) => v + 1.5);
117
+ const flip = det3(m) < 0 ? 1 : 0;
118
+ for (let k = 0; k < 8; k++) {
119
+ const c = k ^ flip;
120
+ const p = [c & 1 ? hi[0] : lo[0], c & 2 ? hi[1] : lo[1], c & 4 ? hi[2] : lo[2]];
121
+ for (let r = 0; r < 3; r++)
122
+ out[k * 4 + r] = m[r * 4] * p[0] + m[r * 4 + 1] * p[1] + m[r * 4 + 2] * p[2] + m[r * 4 + 3];
123
+ out[k * 4 + 3] = 1;
124
+ }
125
+ return out;
126
+ }
127
+ const DEFAULT_LIGHT = [-0.4, -0.8, -0.45];
128
+ /**
129
+ * Creates a level-set pass on `device` for the grids of `pool` (see the file comment). The pipeline is
130
+ * built at the first `record()` (or `prepare()`), cached per device by its WGSL and state.
131
+ *
132
+ * @param device The host's device (the pool's).
133
+ * @param pool The `VDBGridPool` holding the level sets.
134
+ * @param options Formats, output and module types ({@link VDBLevelSetPassOptions}).
135
+ * @throws VDBError `VDB_BAD_OPTION` for bad options.
136
+ */
137
+ export function vdbCreateLevelSetPass(device, pool, options) {
138
+ if (!options || typeof options.colorFormat !== "string" || typeof options.depthFormat !== "string")
139
+ throw bad("colorFormat and depthFormat are required.");
140
+ const output = options.output ?? "shade";
141
+ if (output !== "shade" && output !== "gbuffer")
142
+ throw bad(`output must be 'shade' or 'gbuffer', got ${JSON.stringify(output)}.`);
143
+ const cap = options.maxSamplesCap ?? 1024;
144
+ if (!Number.isInteger(cap) || cap < 1)
145
+ throw bad(`maxSamplesCap must be an integer >= 1, got ${JSON.stringify(options.maxSamplesCap)}.`);
146
+ const types = [...(options.types ?? (pool.types.size > 0 ? [...pool.types] : VDB_ALL_SCALAR_TYPES))];
147
+ const label = options.label ?? "vdb level-set pass";
148
+ const wgsl = vdbLevelSetPassWgsl({ types, output, maxSamplesCap: cap });
149
+ const visibility = STAGE.VERTEX | STAGE.FRAGMENT;
150
+ const spec = {
151
+ label: `${label} (${output})`,
152
+ code: wgsl,
153
+ vertexEntryPoint: "vdbLevelSetPassVs",
154
+ fragmentEntryPoint: "vdbLevelSetPassFs",
155
+ groups: [
156
+ {
157
+ entries: [
158
+ { binding: 0, visibility, buffer: { type: "uniform" } },
159
+ { binding: 1, visibility, buffer: { type: "uniform", hasDynamicOffset: true } },
160
+ ],
161
+ },
162
+ { entries: vdbModuleEntries({ slot: POOL_SLOT, visibility: STAGE.FRAGMENT }) },
163
+ ],
164
+ targets: [{ format: options.colorFormat }],
165
+ depthStencil: { format: options.depthFormat, depthWriteEnabled: true, depthCompare: options.depthCompare ?? "less" },
166
+ primitive: { topology: "triangle-list", cullMode: "front", frontFace: "ccw" },
167
+ };
168
+ const retire = new VDBRetireQueue();
169
+ let uniforms = null;
170
+ let writer = null;
171
+ let frameGroup = null;
172
+ let poolGroup = null;
173
+ let poolBuffer = null;
174
+ let poolVersion = -1;
175
+ let disposed = false;
176
+ const corners = new Float32Array(32);
177
+ const pipeline = () => renderPipeline(device, spec);
178
+ function ensureUniforms(draws) {
179
+ const bytes = DRAWS_AT + Math.max(1, draws) * DRAW_STRIDE;
180
+ if (uniforms && uniforms.size >= bytes)
181
+ return;
182
+ retire.retire(uniforms);
183
+ const size = Math.max(bytes, uniforms ? uniforms.size * 2 : DRAWS_AT + 4 * DRAW_STRIDE);
184
+ uniforms = device.createBuffer({ label: `${label} uniforms`, size, usage: BUFFER_USAGE.UNIFORM | BUFFER_USAGE.COPY_DST });
185
+ writer = new VDBUniformWriter(size);
186
+ frameGroup = device.createBindGroup({
187
+ label: `${label} group 0`,
188
+ layout: pipeline().layouts[0],
189
+ entries: [
190
+ { binding: 0, resource: { buffer: uniforms, offset: 0, size: VDB_LEVEL_SET_PASS_FRAME.size } },
191
+ { binding: 1, resource: { buffer: uniforms, offset: 0, size: VDB_LEVEL_SET_PASS_DRAW.size } },
192
+ ],
193
+ });
194
+ }
195
+ function ensurePoolGroup() {
196
+ if (poolGroup && pool.version === poolVersion && pool.buffer === poolBuffer)
197
+ return;
198
+ poolBuffer = pool.buffer;
199
+ poolVersion = pool.version;
200
+ poolGroup = device.createBindGroup({
201
+ label: `${label} group 1 (pool)`,
202
+ layout: pipeline().layouts[1],
203
+ entries: [{ binding: POOL_SLOT.firstBinding, resource: { buffer: poolBuffer } }],
204
+ });
205
+ }
206
+ function packFrame(w, frame) {
207
+ const s = VDB_LEVEL_SET_PASS_FRAME;
208
+ if (!frame || !frame.view || !frame.projection || !frame.viewport)
209
+ throw bad("record: frame needs view, projection and viewport.");
210
+ const [, , vw, vh] = frame.viewport;
211
+ if (!(vw > 0 && vh > 0))
212
+ throw bad(`record: viewport width and height must be > 0, got ${JSON.stringify(frame.viewport)}.`);
213
+ const orthographic = frame.orthographic ?? frame.projection[11] === 0;
214
+ w.set(s, 0, "viewProjection", vdbMat4Multiply(frame.projection, frame.view));
215
+ w.set(s, 0, "projectionInverse", vdbMat4Invert(frame.projection));
216
+ w.set(s, 0, "cameraWorld", vdbMat4Invert(frame.view));
217
+ w.set(s, 0, "viewport", frame.viewport);
218
+ const light = frame.light === undefined ? { direction: DEFAULT_LIGHT, color: [1, 1, 1] } : frame.light;
219
+ if (light) {
220
+ const d = light.direction;
221
+ const l = Math.hypot(d[0], d[1], d[2]) || 1;
222
+ w.set(s, 0, "lightDirection", [d[0] / l, d[1] / l, d[2] / l, 0]);
223
+ w.set(s, 0, "lightColor", [...light.color, 0]);
224
+ }
225
+ else {
226
+ w.set(s, 0, "lightDirection", [0, -1, 0, 0]);
227
+ w.set(s, 0, "lightColor", [0, 0, 0, 0]);
228
+ }
229
+ w.set(s, 0, "ambient", [...(frame.ambient ?? [0.15, 0.15, 0.15]), 0]);
230
+ w.set(s, 0, "flags", [orthographic ? 1 : 0, 0, 0, 0]);
231
+ }
232
+ function packDraw(w, base, d) {
233
+ const s = VDB_LEVEL_SET_PASS_DRAW;
234
+ if (!d || !Number.isInteger(d.grid) || d.grid < 0)
235
+ throw bad(`record: draw.grid must be a pool id, got ${JSON.stringify(d?.grid)}.`);
236
+ const info = pool.info(d.grid);
237
+ const sdfToIndex = d.sdfToIndex ?? 1 / info.voxelSize[0];
238
+ if (!(Number.isFinite(sdfToIndex) && sdfToIndex > 0))
239
+ throw bad(`record: sdfToIndex must be a positive finite number, got ${sdfToIndex}.`);
240
+ w.clear(base, DRAW_STRIDE);
241
+ w.set(s, base, "corners", vdbLevelSetProxyCorners(info, corners));
242
+ w.set(s, base, "color", [...(d.color ?? [1, 1, 1]), 1]);
243
+ w.set(s, base, "grid", d.grid);
244
+ w.set(s, base, "maxSamples", Math.max(1, Math.min(cap, Math.round(d.maxSamples ?? 512))));
245
+ w.set(s, base, "sdfToIndex", sdfToIndex);
246
+ w.set(s, base, "normalStep", d.normalStep ?? 1);
247
+ }
248
+ return {
249
+ device,
250
+ output,
251
+ types,
252
+ wgsl,
253
+ spec,
254
+ async prepare() {
255
+ if (disposed)
256
+ throw new VDBError("VDB_DISPOSED", `${label}: disposed.`);
257
+ await prepareRender(device, spec);
258
+ },
259
+ record(renderPass, frame, draws) {
260
+ if (disposed)
261
+ throw new VDBError("VDB_DISPOSED", `${label}: disposed.`);
262
+ if (draws.length === 0)
263
+ return;
264
+ vdbCheckModule(pool, { types });
265
+ retire.advance();
266
+ ensureUniforms(draws.length);
267
+ const w = writer;
268
+ packFrame(w, frame);
269
+ draws.forEach((d, i) => packDraw(w, DRAWS_AT + i * DRAW_STRIDE, d));
270
+ device.queue.writeBuffer(uniforms, 0, w.buffer, 0, DRAWS_AT + draws.length * DRAW_STRIDE);
271
+ ensurePoolGroup();
272
+ renderPass.setPipeline(pipeline().pipeline);
273
+ renderPass.setBindGroup(1, poolGroup);
274
+ for (let i = 0; i < draws.length; i++) {
275
+ renderPass.setBindGroup(0, frameGroup, [DRAWS_AT + i * DRAW_STRIDE]);
276
+ renderPass.draw(36);
277
+ }
278
+ },
279
+ dispose() {
280
+ if (disposed)
281
+ return;
282
+ disposed = true;
283
+ retire.drain();
284
+ uniforms?.destroy();
285
+ uniforms = null;
286
+ frameGroup = null;
287
+ poolGroup = null;
288
+ },
289
+ };
290
+ }
291
+ //# sourceMappingURL=level-set-pass.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"level-set-pass.js","sourceRoot":"","sources":["../../../src/core/surface/level-set-pass.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAwB,MAAM,aAAa,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAsB,MAAM,uBAAuB,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB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AC;QACH,CAAC;QACD,OAAO;YACL,IAAI,QAAQ;gBAAE,OAAO;YACrB,QAAQ,GAAG,IAAI,CAAC;YAChB,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,QAAQ,EAAE,OAAO,EAAE,CAAC;YACpB,QAAQ,GAAG,IAAI,CAAC;YAChB,UAAU,GAAG,IAAI,CAAC;YAClB,SAAS,GAAG,IAAI,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The raw level-set reference pass (K6.6, design §3.9): level-set surfaces drawn by an engine-free host\n * into its own render pass, through the same `vdbLevelSetSurface` WGSL that `VDBLevelSetMaterial` calls.\n * Writes `frag_depth` (so surfaces depth-test against the host's meshes) and either a Lambert + ambient\n * shade or a G-buffer texel (world normal, ray distance).\n *\n * const surfaces = vdbCreateLevelSetPass(device, pool, { colorFormat: 'rgba8unorm', depthFormat: 'depth24plus' });\n * // per frame, after pool.update(encoder):\n * const pass = encoder.beginRenderPass({ colorAttachments: [...], depthStencilAttachment: { ... } });\n * surfaces.record(pass, { view, projection, viewport: [0, 0, width, height] }, [{ grid: id, color: [1, 0.8, 0.6] }]);\n * pass.end();\n *\n * Each draw rasterizes the back faces of the grid's index box `[min − 1.5, max + 1.5]` (the trilinear\n * support the trace clips to, half a voxel wider) mapped to world space, so the camera may be inside it;\n * the fragment ignores the box and traces the pixel-centre ray (V57). Uniforms go through\n * `queue.writeBuffer`: one `record()` per submitted encoder (the pool's contract).\n */\n\nimport { VDBError } from \"../errors.js\";\nimport { VDB_ALL_SCALAR_TYPES, type VDBGridTypeName } from \"../types.js\";\nimport type { VDBVec3 } from \"../pool/layout.js\";\nimport { vdbCheckModule, vdbModuleEntries, vdbModuleWgsl } from \"../wgsl/generate.js\";\nimport { prepareRender, renderPipeline, type VDBRenderSpec } from \"../frame/pipelines.js\";\nimport { BUFFER_USAGE, STAGE, VDBRetireQueue } from \"../frame/resources.js\";\nimport { VDBUniformWriter, vdbUniformStruct } from \"../frame/uniforms.js\";\nimport { vdbMat4Invert, vdbMat4Multiply, type VDBMat4 } from \"../../tools/frame/view.js\";\nimport { vdbLevelSetSurfaceWgsl } from \"./level-set-wgsl.js\";\n\n/** What the pass reads from the pool (a `VDBGridPool` has all of it). */\nexport interface VDBLevelSetPassPool {\n readonly buffer: GPUBuffer;\n readonly version: number;\n readonly layoutVersion: number;\n readonly types: ReadonlySet<VDBGridTypeName>;\n info(id: number): {\n readonly indexBBox: { readonly min: readonly number[]; readonly max: readonly number[] };\n readonly indexToWorld: ArrayLike<number>;\n readonly voxelSize: readonly number[];\n };\n}\n\n/** Options of {@link vdbCreateLevelSetPass}. */\nexport interface VDBLevelSetPassOptions {\n /** Format of the one colour attachment. */\n readonly colorFormat: GPUTextureFormat;\n /** Format of the depth attachment (`frag_depth` needs one). */\n readonly depthFormat: GPUTextureFormat;\n /**\n * `'shade'` (default): `color · (ambient + lightColor · max(n · −lightDirection, 0))`, alpha 1, linear.\n * `'gbuffer'`: `(world normal xyz, ray distance t)`; use a float format (`rgba16float`, `rgba32float`).\n */\n readonly output?: \"shade\" | \"gbuffer\";\n /** Grid types the module decodes (fixed at creation; others read 0). Default: the pool's types now. */\n readonly types?: readonly VDBGridTypeName[];\n /** Compiled cap on a draw's `maxSamples`. Default 1024 (`VDB_LEVEL_SET_SAMPLES_CAP`). */\n readonly maxSamplesCap?: number;\n /** Depth test. Default `'less'` (`'greater'` for a reversed-depth host). */\n readonly depthCompare?: GPUCompareFunction;\n readonly label?: string;\n}\n\n/** The camera and lights of one {@link VDBLevelSetPass.record}. Matrices are column-major. */\nexport interface VDBLevelSetPassFrame {\n /** World → view. */\n readonly view: VDBMat4;\n /** View → clip, WebGPU depth range (`[0, 1]`, or reversed). */\n readonly projection: VDBMat4;\n /** Default: `projection[11] === 0` (no perspective divide). */\n readonly orthographic?: boolean;\n /** The render pass's viewport in attachment pixels: `[x, y, width, height]`. */\n readonly viewport: readonly [number, number, number, number];\n /** `'shade'`: one directional light; `direction` is the way the light travels. Default `[-0.4, -0.8, -0.45]`, white. */\n readonly light?: { readonly direction: VDBVec3; readonly color: VDBVec3 } | null;\n /** `'shade'`: ambient radiance. Default `[0.15, 0.15, 0.15]`. */\n readonly ambient?: VDBVec3;\n}\n\n/** One level set to draw. */\nexport interface VDBLevelSetPassDraw {\n /** The grid's pool id. */\n readonly grid: number;\n /** `'shade'` albedo. Default white. */\n readonly color?: VDBVec3;\n /** Index voxels per SDF unit. Default `1 / pool.info(grid).voxelSize[0]`. */\n readonly sdfToIndex?: number;\n /** Trilinear samples per trace, clamped to `[1, maxSamplesCap]`. Default 512. */\n readonly maxSamples?: number;\n /** Central-difference step of the normal in index voxels. Default 1; 0: the trilinear cell's exact gradient (G13c-a). */\n readonly normalStep?: number;\n}\n\n/** A level-set pass (see the file comment). */\nexport interface VDBLevelSetPass {\n readonly device: GPUDevice;\n readonly output: \"shade\" | \"gbuffer\";\n /** Grid types the module decodes. */\n readonly types: readonly VDBGridTypeName[];\n /** The pass's whole WGSL (module + surface + entries), for inspection and size budgets. */\n readonly wgsl: string;\n /** The render pipeline's spec (cache key, layouts, state). */\n readonly spec: VDBRenderSpec;\n /** Builds the pipeline with `createRenderPipelineAsync` (optional warm-up). */\n prepare(): Promise<void>;\n /**\n * Records the draws into the host's render pass (its viewport must equal `frame.viewport`). Call after\n * `pool.update(encoder)` of this frame: the pool's bind group is rebuilt when `pool.version` moved.\n *\n * @throws VDBError `VDB_TYPE_NOT_COMPILED` when the pool holds a type the module doesn't decode;\n * `VDB_BAD_OPTION` for a bad draw; `VDB_DISPOSED` after `dispose()`.\n */\n record(renderPass: GPURenderPassEncoder, frame: VDBLevelSetPassFrame, draws: readonly VDBLevelSetPassDraw[]): void;\n /** Destroys the buffers the pass made (never the pool, device or targets). Idempotent. */\n dispose(): void;\n}\n\n/** Group 0 binding 0: the camera and lights. */\nexport const VDB_LEVEL_SET_PASS_FRAME = vdbUniformStruct(\"VdbLevelSetPassFrame\", [\n { name: \"viewProjection\", type: \"mat4x4f\" },\n { name: \"projectionInverse\", type: \"mat4x4f\" },\n { name: \"cameraWorld\", type: \"mat4x4f\" },\n { name: \"viewport\", type: \"vec4f\" },\n { name: \"lightDirection\", type: \"vec4f\" },\n { name: \"lightColor\", type: \"vec4f\" },\n { name: \"ambient\", type: \"vec4f\" },\n // x: orthographic\n { name: \"flags\", type: \"vec4u\" },\n]);\n\n/** Group 0 binding 1 (dynamic offset): one draw. */\nexport const VDB_LEVEL_SET_PASS_DRAW = vdbUniformStruct(\n \"VdbLevelSetPassDraw\",\n [\n // the proxy box's world corners, corner k = (x: k & 1, y: k & 2, z: k & 4)\n { name: \"corners\", type: \"vec4f\", count: 8 },\n { name: \"color\", type: \"vec4f\" },\n { name: \"grid\", type: \"u32\" },\n { name: \"maxSamples\", type: \"u32\" },\n { name: \"sdfToIndex\", type: \"f32\" },\n { name: \"normalStep\", type: \"f32\" },\n ],\n 256,\n);\n\n/** Byte offset of draw 0 (frame record first, 256-aligned). */\nconst DRAWS_AT = 512;\nconst DRAW_STRIDE = 256;\n/** Pool slot of the pass's module. */\nconst POOL_SLOT = { group: 1, firstBinding: 0 } as const;\n\n/**\n * The 36 corner indices of the box's 12 triangles, counter-clockwise seen from outside in a right-handed\n * world (a unit test checks every triangle's normal points out). Culling front faces draws the back faces.\n */\nexport const VDB_LEVEL_SET_BOX_TRIANGLES: readonly number[] = Object.freeze([\n 0, 4, 6, 0, 6, 2, 1, 3, 7, 1, 7, 5, 0, 1, 5, 0, 5, 4, 2, 6, 7, 2, 7, 3, 0, 2, 3, 0, 3, 1, 4, 5, 7, 4, 7, 6,\n]);\n\nfunction bad(message: string): VDBError {\n return new VDBError(\"VDB_BAD_OPTION\", `vdbCreateLevelSetPass: ${message}`);\n}\n\n/** The entry points (after the module and the surface functions). */\nfunction entriesWgsl(output: \"shade\" | \"gbuffer\", cap: number): string {\n const color =\n output === \"gbuffer\"\n ? \"vec4f(s.normal, s.t)\"\n : \"vec4f(vdbLsDraw.color.rgb * (vdbLsFrame.ambient.rgb + vdbLsFrame.lightColor.rgb * max(dot(s.normal, -vdbLsFrame.lightDirection.xyz), 0.0)), 1.0)\";\n return /* wgsl */ `${VDB_LEVEL_SET_PASS_FRAME.wgsl}\n${VDB_LEVEL_SET_PASS_DRAW.wgsl}\n@group(0) @binding(0) var<uniform> vdbLsFrame: VdbLevelSetPassFrame;\n@group(0) @binding(1) var<uniform> vdbLsDraw: VdbLevelSetPassDraw;\n\n@vertex\nfn vdbLevelSetPassVs(@builtin(vertex_index) i: u32) -> @builtin(position) vec4f {\n var box = array<u32, 36>(${VDB_LEVEL_SET_BOX_TRIANGLES.map((k) => `${k}u`).join(\", \")});\n return vdbLsFrame.viewProjection * vec4f(vdbLsDraw.corners[box[i]].xyz, 1.0);\n}\n\nstruct VdbLevelSetPassOut {\n @location(0) color: vec4f,\n @builtin(frag_depth) depth: f32,\n};\n\n@fragment\nfn vdbLevelSetPassFs(@builtin(position) position: vec4f) -> VdbLevelSetPassOut {\n let uv = vdbLevelSetPixelUv(position.xy, vdbLsFrame.viewport);\n let ray = vdbLevelSetViewRay(uv, vdbLsFrame.projectionInverse, vdbLsFrame.cameraWorld, vdbLsFrame.flags.x != 0u);\n let s = vdbLevelSetSurface(vdbLsDraw.grid, ray, vdbLsFrame.viewProjection, vdbLsDraw.sdfToIndex, clamp(vdbLsDraw.maxSamples, 1u, ${cap}u), vdbLsDraw.normalStep);\n if !s.hit || !(s.ndcDepth >= 0.0 && s.ndcDepth <= 1.0) {\n discard;\n }\n var o: VdbLevelSetPassOut;\n o.color = ${color};\n o.depth = s.ndcDepth;\n return o;\n}\n`;\n}\n\n/** The full WGSL of a level-set pass (module + `vdbLevelSetSurfaceWgsl()` + entries). */\nexport function vdbLevelSetPassWgsl(options: { types: readonly VDBGridTypeName[]; output?: \"shade\" | \"gbuffer\"; maxSamplesCap?: number }): string {\n const module = vdbModuleWgsl({ slot: POOL_SLOT, types: options.types, profile: \"march\", helpers: [\"levelSet\"] });\n return `${module}\\n${vdbLevelSetSurfaceWgsl()}\\n${entriesWgsl(options.output ?? \"shade\", options.maxSamplesCap ?? 1024)}`;\n}\n\n/** The 3x3 determinant of a 3x4 row-major affine's linear part. */\nfunction det3(m: ArrayLike<number>): number {\n return m[0]! * (m[5]! * m[10]! - m[6]! * m[9]!) - m[1]! * (m[4]! * m[10]! - m[6]! * m[8]!) + m[2]! * (m[4]! * m[9]! - m[5]! * m[8]!);\n}\n\n/**\n * The 8 world corners of a grid's proxy box (`[min − 1.5, max + 1.5]` through the 3x4 row-major\n * index-to-world affine), `x, y, z, 1` each. A mirroring affine swaps the x corners so the triangles stay\n * counter-clockwise from outside.\n */\nexport function vdbLevelSetProxyCorners(info: ReturnType<VDBLevelSetPassPool[\"info\"]>, out: Float32Array = new Float32Array(32)): Float32Array {\n const m = info.indexToWorld;\n const lo = info.indexBBox.min.map((v) => v - 1.5);\n const hi = info.indexBBox.max.map((v) => v + 1.5);\n const flip = det3(m) < 0 ? 1 : 0;\n for (let k = 0; k < 8; k++) {\n const c = k ^ flip;\n const p = [c & 1 ? hi[0]! : lo[0]!, c & 2 ? hi[1]! : lo[1]!, c & 4 ? hi[2]! : lo[2]!];\n for (let r = 0; r < 3; r++) out[k * 4 + r] = m[r * 4]! * p[0]! + m[r * 4 + 1]! * p[1]! + m[r * 4 + 2]! * p[2]! + m[r * 4 + 3]!;\n out[k * 4 + 3] = 1;\n }\n return out;\n}\n\nconst DEFAULT_LIGHT: VDBVec3 = [-0.4, -0.8, -0.45];\n\n/**\n * Creates a level-set pass on `device` for the grids of `pool` (see the file comment). The pipeline is\n * built at the first `record()` (or `prepare()`), cached per device by its WGSL and state.\n *\n * @param device The host's device (the pool's).\n * @param pool The `VDBGridPool` holding the level sets.\n * @param options Formats, output and module types ({@link VDBLevelSetPassOptions}).\n * @throws VDBError `VDB_BAD_OPTION` for bad options.\n */\nexport function vdbCreateLevelSetPass(device: GPUDevice, pool: VDBLevelSetPassPool, options: VDBLevelSetPassOptions): VDBLevelSetPass {\n if (!options || typeof options.colorFormat !== \"string\" || typeof options.depthFormat !== \"string\") throw bad(\"colorFormat and depthFormat are required.\");\n const output = options.output ?? \"shade\";\n if (output !== \"shade\" && output !== \"gbuffer\") throw bad(`output must be 'shade' or 'gbuffer', got ${JSON.stringify(output)}.`);\n const cap = options.maxSamplesCap ?? 1024;\n if (!Number.isInteger(cap) || cap < 1) throw bad(`maxSamplesCap must be an integer >= 1, got ${JSON.stringify(options.maxSamplesCap)}.`);\n const types = [...(options.types ?? (pool.types.size > 0 ? [...pool.types] : VDB_ALL_SCALAR_TYPES))];\n const label = options.label ?? \"vdb level-set pass\";\n const wgsl = vdbLevelSetPassWgsl({ types, output, maxSamplesCap: cap });\n const visibility = STAGE.VERTEX | STAGE.FRAGMENT;\n const spec: VDBRenderSpec = {\n label: `${label} (${output})`,\n code: wgsl,\n vertexEntryPoint: \"vdbLevelSetPassVs\",\n fragmentEntryPoint: \"vdbLevelSetPassFs\",\n groups: [\n {\n entries: [\n { binding: 0, visibility, buffer: { type: \"uniform\" } },\n { binding: 1, visibility, buffer: { type: \"uniform\", hasDynamicOffset: true } },\n ],\n },\n { entries: vdbModuleEntries({ slot: POOL_SLOT, visibility: STAGE.FRAGMENT }) },\n ],\n targets: [{ format: options.colorFormat }],\n depthStencil: { format: options.depthFormat, depthWriteEnabled: true, depthCompare: options.depthCompare ?? \"less\" },\n primitive: { topology: \"triangle-list\", cullMode: \"front\", frontFace: \"ccw\" },\n };\n\n const retire = new VDBRetireQueue();\n let uniforms: GPUBuffer | null = null;\n let writer: VDBUniformWriter | null = null;\n let frameGroup: GPUBindGroup | null = null;\n let poolGroup: GPUBindGroup | null = null;\n let poolBuffer: GPUBuffer | null = null;\n let poolVersion = -1;\n let disposed = false;\n const corners = new Float32Array(32);\n\n const pipeline = () => renderPipeline(device, spec);\n\n function ensureUniforms(draws: number): void {\n const bytes = DRAWS_AT + Math.max(1, draws) * DRAW_STRIDE;\n if (uniforms && uniforms.size >= bytes) return;\n retire.retire(uniforms);\n const size = Math.max(bytes, uniforms ? uniforms.size * 2 : DRAWS_AT + 4 * DRAW_STRIDE);\n uniforms = device.createBuffer({ label: `${label} uniforms`, size, usage: BUFFER_USAGE.UNIFORM | BUFFER_USAGE.COPY_DST });\n writer = new VDBUniformWriter(size);\n frameGroup = device.createBindGroup({\n label: `${label} group 0`,\n layout: pipeline().layouts[0]!,\n entries: [\n { binding: 0, resource: { buffer: uniforms, offset: 0, size: VDB_LEVEL_SET_PASS_FRAME.size } },\n { binding: 1, resource: { buffer: uniforms, offset: 0, size: VDB_LEVEL_SET_PASS_DRAW.size } },\n ],\n });\n }\n\n function ensurePoolGroup(): void {\n if (poolGroup && pool.version === poolVersion && pool.buffer === poolBuffer) return;\n poolBuffer = pool.buffer;\n poolVersion = pool.version;\n poolGroup = device.createBindGroup({\n label: `${label} group 1 (pool)`,\n layout: pipeline().layouts[1]!,\n entries: [{ binding: POOL_SLOT.firstBinding, resource: { buffer: poolBuffer } }],\n });\n }\n\n function packFrame(w: VDBUniformWriter, frame: VDBLevelSetPassFrame): void {\n const s = VDB_LEVEL_SET_PASS_FRAME;\n if (!frame || !frame.view || !frame.projection || !frame.viewport) throw bad(\"record: frame needs view, projection and viewport.\");\n const [, , vw, vh] = frame.viewport;\n if (!(vw > 0 && vh > 0)) throw bad(`record: viewport width and height must be > 0, got ${JSON.stringify(frame.viewport)}.`);\n const orthographic = frame.orthographic ?? frame.projection[11] === 0;\n w.set(s, 0, \"viewProjection\", vdbMat4Multiply(frame.projection, frame.view));\n w.set(s, 0, \"projectionInverse\", vdbMat4Invert(frame.projection));\n w.set(s, 0, \"cameraWorld\", vdbMat4Invert(frame.view));\n w.set(s, 0, \"viewport\", frame.viewport);\n const light = frame.light === undefined ? { direction: DEFAULT_LIGHT, color: [1, 1, 1] as VDBVec3 } : frame.light;\n if (light) {\n const d = light.direction;\n const l = Math.hypot(d[0], d[1], d[2]) || 1;\n w.set(s, 0, \"lightDirection\", [d[0] / l, d[1] / l, d[2] / l, 0]);\n w.set(s, 0, \"lightColor\", [...light.color, 0]);\n } else {\n w.set(s, 0, \"lightDirection\", [0, -1, 0, 0]);\n w.set(s, 0, \"lightColor\", [0, 0, 0, 0]);\n }\n w.set(s, 0, \"ambient\", [...(frame.ambient ?? [0.15, 0.15, 0.15]), 0]);\n w.set(s, 0, \"flags\", [orthographic ? 1 : 0, 0, 0, 0]);\n }\n\n function packDraw(w: VDBUniformWriter, base: number, d: VDBLevelSetPassDraw): void {\n const s = VDB_LEVEL_SET_PASS_DRAW;\n if (!d || !Number.isInteger(d.grid) || d.grid < 0) throw bad(`record: draw.grid must be a pool id, got ${JSON.stringify(d?.grid)}.`);\n const info = pool.info(d.grid);\n const sdfToIndex = d.sdfToIndex ?? 1 / info.voxelSize[0]!;\n if (!(Number.isFinite(sdfToIndex) && sdfToIndex > 0)) throw bad(`record: sdfToIndex must be a positive finite number, got ${sdfToIndex}.`);\n w.clear(base, DRAW_STRIDE);\n w.set(s, base, \"corners\", vdbLevelSetProxyCorners(info, corners));\n w.set(s, base, \"color\", [...(d.color ?? [1, 1, 1]), 1]);\n w.set(s, base, \"grid\", d.grid);\n w.set(s, base, \"maxSamples\", Math.max(1, Math.min(cap, Math.round(d.maxSamples ?? 512))));\n w.set(s, base, \"sdfToIndex\", sdfToIndex);\n w.set(s, base, \"normalStep\", d.normalStep ?? 1);\n }\n\n return {\n device,\n output,\n types,\n wgsl,\n spec,\n async prepare() {\n if (disposed) throw new VDBError(\"VDB_DISPOSED\", `${label}: disposed.`);\n await prepareRender(device, spec);\n },\n record(renderPass, frame, draws) {\n if (disposed) throw new VDBError(\"VDB_DISPOSED\", `${label}: disposed.`);\n if (draws.length === 0) return;\n vdbCheckModule(pool, { types });\n retire.advance();\n ensureUniforms(draws.length);\n const w = writer!;\n packFrame(w, frame);\n draws.forEach((d, i) => packDraw(w, DRAWS_AT + i * DRAW_STRIDE, d));\n device.queue.writeBuffer(uniforms!, 0, w.buffer, 0, DRAWS_AT + draws.length * DRAW_STRIDE);\n ensurePoolGroup();\n renderPass.setPipeline(pipeline().pipeline);\n renderPass.setBindGroup(1, poolGroup!);\n for (let i = 0; i < draws.length; i++) {\n renderPass.setBindGroup(0, frameGroup!, [DRAWS_AT + i * DRAW_STRIDE]);\n renderPass.draw(36);\n }\n },\n dispose() {\n if (disposed) return;\n disposed = true;\n retire.drain();\n uniforms?.destroy();\n uniforms = null;\n frameGroup = null;\n poolGroup = null;\n },\n };\n}\n"]}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The level-set surface function (K6.6, design §3.9): the fragment-stage wrapper of the `'levelSet'`
3
+ * helper's trace for hosts that shade with their own BRDF. `VDBLevelSetMaterial` (`./three`) calls it
4
+ * through `wgslFn`; the raw reference pass (`vdbCreateLevelSetPass`) calls it from its fragment entry.
5
+ *
6
+ * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345
7
+ * (`src/three-openvdb/levelset/webgpu/LevelSetSurfaceMaterial.js`: perspective and orthographic view rays,
8
+ * so shadow passes work). Copyright (c) mjurczyk/openvdb contributors, MIT (see THIRD_PARTY_NOTICES.md).
9
+ * Changes: the ray comes from the pixel centre through the inverse projection, not from interpolated box
10
+ * positions (V57); the hit, normal and NDC depth come back as one struct (DIVERGES.md).
11
+ *
12
+ * CPU twins: `tools` `levelSetPixelUv`, `levelSetViewRay`, `levelSetSurface` (`tools/cpu/level-set.ts`).
13
+ */
14
+ /**
15
+ * The WGSL text of the surface functions. Append it after a VDB module generated with profile `'march'`
16
+ * and helpers including `'levelSet'` (`vdbModuleWgsl({ ..., profile: 'march', helpers: ['levelSet'] })`):
17
+ * it calls `vdbLevelSetHit`, `vdbLevelSetNormal`, `vdbWorldToIndex` and `vdbWorldToIndexDir`. One VDB
18
+ * module per shader (Traps); this text has no bindings of its own.
19
+ *
20
+ * ```wgsl
21
+ * struct VdbLevelSetRay { origin: vec3f, dir: vec3f, span: vec2f } // world space; dir unit length
22
+ * struct VdbLevelSetSurface { hit: bool, t: f32, world: vec3f, normal: vec3f, ndcDepth: f32 }
23
+ * fn vdbLevelSetPixelUv(fragCoord: vec2f, viewport: vec4f) -> vec2f; // viewport = (x, y, width, height)
24
+ * fn vdbLevelSetViewRay(uv: vec2f, projectionInverse: mat4x4f, cameraWorld: mat4x4f, orthographic: bool) -> VdbLevelSetRay;
25
+ * fn vdbLevelSetSurface(g: u32, ray: VdbLevelSetRay, viewProjection: mat4x4f, sdfToIndex: f32, maxSamples: u32, normalStep: f32) -> VdbLevelSetSurface;
26
+ * ```
27
+ *
28
+ * - `vdbLevelSetPixelUv`: the pixel centre (`@builtin(position).xy` is the centre already) as a viewport
29
+ * uv, x right and y down, in `[0, 1]`.
30
+ * - `vdbLevelSetViewRay`: the pixel's view ray (V57). Perspective: from the camera position
31
+ * (`cameraWorld[3]`) through `projectionInverse · (ndc, 0.5, 1)`, `t` in `[0, 1e30]`. Orthographic: from
32
+ * that point on the camera plane (view z = 0) along the view axis, `t` in `[-1e5, 1e5]`, so a
33
+ * directional-light shadow camera sees surfaces behind its plane. `t` is in world units.
34
+ * - `vdbLevelSetSurface`: traces grid `g` along `ray` (`vdbLevelSetHit` in the grid's index space;
35
+ * `sdfToIndex` index voxels per SDF unit, 1 / voxel size for a level set in its own units; `maxSamples`
36
+ * trilinear samples). On a hit: `t`, the world hit `origin + dir · t`, the outward world unit normal
37
+ * (`vdbLevelSetNormal`, central differences at `normalStep` index voxels through `W^T`; `normalStep <= 0`: the
38
+ * exact gradient of the trilinear cell at the hit), and the NDC depth
39
+ * `clip.z / clip.w` of `viewProjection · (world, 1)` (WebGPU depth: 0 near, 1 far, or reversed when the
40
+ * host's projection is). On a miss every field is zero and `hit` is false.
41
+ *
42
+ * Every `vdbSample` call site inlines the type-dispatched trilinear reader (K3.7: compile time). The
43
+ * surface has the helper's four sites (march, closing sample, bisection, gradient loop); call it from
44
+ * one place per shader.
45
+ */
46
+ export declare function vdbLevelSetSurfaceWgsl(): string;
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The level-set surface function (K6.6, design §3.9): the fragment-stage wrapper of the `'levelSet'`
3
+ * helper's trace for hosts that shade with their own BRDF. `VDBLevelSetMaterial` (`./three`) calls it
4
+ * through `wgslFn`; the raw reference pass (`vdbCreateLevelSetPass`) calls it from its fragment entry.
5
+ *
6
+ * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345
7
+ * (`src/three-openvdb/levelset/webgpu/LevelSetSurfaceMaterial.js`: perspective and orthographic view rays,
8
+ * so shadow passes work). Copyright (c) mjurczyk/openvdb contributors, MIT (see THIRD_PARTY_NOTICES.md).
9
+ * Changes: the ray comes from the pixel centre through the inverse projection, not from interpolated box
10
+ * positions (V57); the hit, normal and NDC depth come back as one struct (DIVERGES.md).
11
+ *
12
+ * CPU twins: `tools` `levelSetPixelUv`, `levelSetViewRay`, `levelSetSurface` (`tools/cpu/level-set.ts`).
13
+ */
14
+ /**
15
+ * The WGSL text of the surface functions. Append it after a VDB module generated with profile `'march'`
16
+ * and helpers including `'levelSet'` (`vdbModuleWgsl({ ..., profile: 'march', helpers: ['levelSet'] })`):
17
+ * it calls `vdbLevelSetHit`, `vdbLevelSetNormal`, `vdbWorldToIndex` and `vdbWorldToIndexDir`. One VDB
18
+ * module per shader (Traps); this text has no bindings of its own.
19
+ *
20
+ * ```wgsl
21
+ * struct VdbLevelSetRay { origin: vec3f, dir: vec3f, span: vec2f } // world space; dir unit length
22
+ * struct VdbLevelSetSurface { hit: bool, t: f32, world: vec3f, normal: vec3f, ndcDepth: f32 }
23
+ * fn vdbLevelSetPixelUv(fragCoord: vec2f, viewport: vec4f) -> vec2f; // viewport = (x, y, width, height)
24
+ * fn vdbLevelSetViewRay(uv: vec2f, projectionInverse: mat4x4f, cameraWorld: mat4x4f, orthographic: bool) -> VdbLevelSetRay;
25
+ * fn vdbLevelSetSurface(g: u32, ray: VdbLevelSetRay, viewProjection: mat4x4f, sdfToIndex: f32, maxSamples: u32, normalStep: f32) -> VdbLevelSetSurface;
26
+ * ```
27
+ *
28
+ * - `vdbLevelSetPixelUv`: the pixel centre (`@builtin(position).xy` is the centre already) as a viewport
29
+ * uv, x right and y down, in `[0, 1]`.
30
+ * - `vdbLevelSetViewRay`: the pixel's view ray (V57). Perspective: from the camera position
31
+ * (`cameraWorld[3]`) through `projectionInverse · (ndc, 0.5, 1)`, `t` in `[0, 1e30]`. Orthographic: from
32
+ * that point on the camera plane (view z = 0) along the view axis, `t` in `[-1e5, 1e5]`, so a
33
+ * directional-light shadow camera sees surfaces behind its plane. `t` is in world units.
34
+ * - `vdbLevelSetSurface`: traces grid `g` along `ray` (`vdbLevelSetHit` in the grid's index space;
35
+ * `sdfToIndex` index voxels per SDF unit, 1 / voxel size for a level set in its own units; `maxSamples`
36
+ * trilinear samples). On a hit: `t`, the world hit `origin + dir · t`, the outward world unit normal
37
+ * (`vdbLevelSetNormal`, central differences at `normalStep` index voxels through `W^T`; `normalStep <= 0`: the
38
+ * exact gradient of the trilinear cell at the hit), and the NDC depth
39
+ * `clip.z / clip.w` of `viewProjection · (world, 1)` (WebGPU depth: 0 near, 1 far, or reversed when the
40
+ * host's projection is). On a miss every field is zero and `hit` is false.
41
+ *
42
+ * Every `vdbSample` call site inlines the type-dispatched trilinear reader (K3.7: compile time). The
43
+ * surface has the helper's four sites (march, closing sample, bisection, gradient loop); call it from
44
+ * one place per shader.
45
+ */
46
+ export function vdbLevelSetSurfaceWgsl() {
47
+ return LEVEL_SET_SURFACE_WGSL;
48
+ }
49
+ const LEVEL_SET_SURFACE_WGSL = /* wgsl */ `struct VdbLevelSetRay {
50
+ origin: vec3f,
51
+ dir: vec3f,
52
+ span: vec2f,
53
+ };
54
+
55
+ struct VdbLevelSetSurface {
56
+ hit: bool,
57
+ t: f32,
58
+ world: vec3f,
59
+ normal: vec3f,
60
+ ndcDepth: f32,
61
+ };
62
+
63
+ fn vdbLevelSetPixelUv(fragCoord: vec2f, viewport: vec4f) -> vec2f {
64
+ return (fragCoord - viewport.xy) / viewport.zw;
65
+ }
66
+
67
+ fn vdbLevelSetViewRay(uv: vec2f, projectionInverse: mat4x4f, cameraWorld: mat4x4f, orthographic: bool) -> VdbLevelSetRay {
68
+ let ndc = vec2f(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0);
69
+ let clip = projectionInverse * vec4f(ndc, 0.5, 1.0);
70
+ let view = clip.xyz / clip.w;
71
+ var r: VdbLevelSetRay;
72
+ if orthographic {
73
+ r.origin = (cameraWorld * vec4f(view.x, view.y, 0.0, 1.0)).xyz;
74
+ r.dir = normalize((cameraWorld * vec4f(0.0, 0.0, -1.0, 0.0)).xyz);
75
+ r.span = vec2f(-1.0e5, 1.0e5);
76
+ } else {
77
+ r.origin = cameraWorld[3].xyz;
78
+ r.dir = normalize((cameraWorld * vec4f(normalize(view), 0.0)).xyz);
79
+ r.span = vec2f(0.0, 1.0e30);
80
+ }
81
+ return r;
82
+ }
83
+
84
+ fn vdbLevelSetSurface(g: u32, ray: VdbLevelSetRay, viewProjection: mat4x4f, sdfToIndex: f32, maxSamples: u32, normalStep: f32) -> VdbLevelSetSurface {
85
+ var s: VdbLevelSetSurface;
86
+ var span = ray.span;
87
+ if !vdbLevelSetHit(g, vdbWorldToIndex(g, ray.origin), vdbWorldToIndexDir(g, ray.dir), &span, sdfToIndex, maxSamples) {
88
+ return s;
89
+ }
90
+ s.hit = true;
91
+ s.t = span.x;
92
+ s.world = ray.origin + ray.dir * span.x;
93
+ s.normal = vdbLevelSetNormal(g, vdbWorldToIndex(g, s.world), normalStep);
94
+ let clip = viewProjection * vec4f(s.world, 1.0);
95
+ s.ndcDepth = clip.z / clip.w;
96
+ return s;
97
+ }
98
+ `;
99
+ //# sourceMappingURL=level-set-wgsl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"level-set-wgsl.js","sourceRoot":"","sources":["../../../src/core/surface/level-set-wgsl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAED,MAAM,sBAAsB,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDzC,CAAC","sourcesContent":["/**\n * The level-set surface function (K6.6, design §3.9): the fragment-stage wrapper of the `'levelSet'`\n * helper's trace for hosts that shade with their own BRDF. `VDBLevelSetMaterial` (`./three`) calls it\n * through `wgslFn`; the raw reference pass (`vdbCreateLevelSetPass`) calls it from its fragment entry.\n *\n * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345\n * (`src/three-openvdb/levelset/webgpu/LevelSetSurfaceMaterial.js`: perspective and orthographic view rays,\n * so shadow passes work). Copyright (c) mjurczyk/openvdb contributors, MIT (see THIRD_PARTY_NOTICES.md).\n * Changes: the ray comes from the pixel centre through the inverse projection, not from interpolated box\n * positions (V57); the hit, normal and NDC depth come back as one struct (DIVERGES.md).\n *\n * CPU twins: `tools` `levelSetPixelUv`, `levelSetViewRay`, `levelSetSurface` (`tools/cpu/level-set.ts`).\n */\n\n/**\n * The WGSL text of the surface functions. Append it after a VDB module generated with profile `'march'`\n * and helpers including `'levelSet'` (`vdbModuleWgsl({ ..., profile: 'march', helpers: ['levelSet'] })`):\n * it calls `vdbLevelSetHit`, `vdbLevelSetNormal`, `vdbWorldToIndex` and `vdbWorldToIndexDir`. One VDB\n * module per shader (Traps); this text has no bindings of its own.\n *\n * ```wgsl\n * struct VdbLevelSetRay { origin: vec3f, dir: vec3f, span: vec2f } // world space; dir unit length\n * struct VdbLevelSetSurface { hit: bool, t: f32, world: vec3f, normal: vec3f, ndcDepth: f32 }\n * fn vdbLevelSetPixelUv(fragCoord: vec2f, viewport: vec4f) -> vec2f; // viewport = (x, y, width, height)\n * fn vdbLevelSetViewRay(uv: vec2f, projectionInverse: mat4x4f, cameraWorld: mat4x4f, orthographic: bool) -> VdbLevelSetRay;\n * fn vdbLevelSetSurface(g: u32, ray: VdbLevelSetRay, viewProjection: mat4x4f, sdfToIndex: f32, maxSamples: u32, normalStep: f32) -> VdbLevelSetSurface;\n * ```\n *\n * - `vdbLevelSetPixelUv`: the pixel centre (`@builtin(position).xy` is the centre already) as a viewport\n * uv, x right and y down, in `[0, 1]`.\n * - `vdbLevelSetViewRay`: the pixel's view ray (V57). Perspective: from the camera position\n * (`cameraWorld[3]`) through `projectionInverse · (ndc, 0.5, 1)`, `t` in `[0, 1e30]`. Orthographic: from\n * that point on the camera plane (view z = 0) along the view axis, `t` in `[-1e5, 1e5]`, so a\n * directional-light shadow camera sees surfaces behind its plane. `t` is in world units.\n * - `vdbLevelSetSurface`: traces grid `g` along `ray` (`vdbLevelSetHit` in the grid's index space;\n * `sdfToIndex` index voxels per SDF unit, 1 / voxel size for a level set in its own units; `maxSamples`\n * trilinear samples). On a hit: `t`, the world hit `origin + dir · t`, the outward world unit normal\n * (`vdbLevelSetNormal`, central differences at `normalStep` index voxels through `W^T`; `normalStep <= 0`: the\n * exact gradient of the trilinear cell at the hit), and the NDC depth\n * `clip.z / clip.w` of `viewProjection · (world, 1)` (WebGPU depth: 0 near, 1 far, or reversed when the\n * host's projection is). On a miss every field is zero and `hit` is false.\n *\n * Every `vdbSample` call site inlines the type-dispatched trilinear reader (K3.7: compile time). The\n * surface has the helper's four sites (march, closing sample, bisection, gradient loop); call it from\n * one place per shader.\n */\nexport function vdbLevelSetSurfaceWgsl(): string {\n return LEVEL_SET_SURFACE_WGSL;\n}\n\nconst LEVEL_SET_SURFACE_WGSL = /* wgsl */ `struct VdbLevelSetRay {\n origin: vec3f,\n dir: vec3f,\n span: vec2f,\n};\n\nstruct VdbLevelSetSurface {\n hit: bool,\n t: f32,\n world: vec3f,\n normal: vec3f,\n ndcDepth: f32,\n};\n\nfn vdbLevelSetPixelUv(fragCoord: vec2f, viewport: vec4f) -> vec2f {\n return (fragCoord - viewport.xy) / viewport.zw;\n}\n\nfn vdbLevelSetViewRay(uv: vec2f, projectionInverse: mat4x4f, cameraWorld: mat4x4f, orthographic: bool) -> VdbLevelSetRay {\n let ndc = vec2f(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0);\n let clip = projectionInverse * vec4f(ndc, 0.5, 1.0);\n let view = clip.xyz / clip.w;\n var r: VdbLevelSetRay;\n if orthographic {\n r.origin = (cameraWorld * vec4f(view.x, view.y, 0.0, 1.0)).xyz;\n r.dir = normalize((cameraWorld * vec4f(0.0, 0.0, -1.0, 0.0)).xyz);\n r.span = vec2f(-1.0e5, 1.0e5);\n } else {\n r.origin = cameraWorld[3].xyz;\n r.dir = normalize((cameraWorld * vec4f(normalize(view), 0.0)).xyz);\n r.span = vec2f(0.0, 1.0e30);\n }\n return r;\n}\n\nfn vdbLevelSetSurface(g: u32, ray: VdbLevelSetRay, viewProjection: mat4x4f, sdfToIndex: f32, maxSamples: u32, normalStep: f32) -> VdbLevelSetSurface {\n var s: VdbLevelSetSurface;\n var span = ray.span;\n if !vdbLevelSetHit(g, vdbWorldToIndex(g, ray.origin), vdbWorldToIndexDir(g, ray.dir), &span, sdfToIndex, maxSamples) {\n return s;\n }\n s.hit = true;\n s.t = span.x;\n s.world = ray.origin + ray.dir * span.x;\n s.normal = vdbLevelSetNormal(g, vdbWorldToIndex(g, s.world), normalStep);\n let clip = viewProjection * vec4f(s.world, 1.0);\n s.ndcDepth = clip.z / clip.w;\n return s;\n}\n`;\n"]}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Point sprites (K6.6, design §3.9): the sprite size and attenuation as core WGSL
3
+ * (`vdbPointSpriteWgsl`), which `VDBPoints` (`./three`) calls from its TSL vertex, and a raw sprite pass
4
+ * (`vdbCreatePointPass`) for engine-free hosts. The disc is the adapters' (three keeps his mipmapped
5
+ * alpha map); the raw pass cuts an analytic disc.
6
+ *
7
+ * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345
8
+ * (`src/three-openvdb/points/webgpu/VDBPoints.js`, `points/pointsCore.js`: one instanced quad per point,
9
+ * the attenuated size in pixels with a 1-pixel minimum, the pixel scale `diameter · maxScale · zoom /
10
+ * tan(fov / 2) · height / 2`) and three.js r187 (MIT) `PointsNodeMaterial.setupVertexSprite` (the clip-space
11
+ * offset). Copyright (c) mjurczyk/openvdb contributors, MIT (see THIRD_PARTY_NOTICES.md). Changes: plain WGSL
12
+ * and data; the raw pass's disc is analytic (DIVERGES.md).
13
+ *
14
+ * CPU twins: `tools` `pointSpriteSize`, `pointSpriteVertex`, `pointSpriteClip` (`tools/cpu/points.ts`).
15
+ */
16
+ import type { VDBVec3 } from "../pool/layout.js";
17
+ import { type VDBRenderSpec } from "../frame/pipelines.js";
18
+ import { type VDBMat4 } from "../../tools/frame/view.js";
19
+ /**
20
+ * The WGSL text of the sprite functions (no bindings, no module):
21
+ *
22
+ * ```wgsl
23
+ * fn vdbPointSpriteSize(pixelScale: f32, viewDepth: f32, minSize: f32) -> f32;
24
+ * fn vdbPointSpriteVertex(clipCentre: vec4f, corner: vec2f, sizePx: f32, viewportSize: vec2f) -> vec4f;
25
+ * ```
26
+ *
27
+ * - `vdbPointSpriteSize`: the sprite's width in pixels, `max(pixelScale / viewDepth, minSize)` (his 1-pixel
28
+ * minimum: sprites under a pixel are still drawn); `viewDepth` is the point's distance along the view
29
+ * axis (`−view.z`).
30
+ * - `vdbPointSpriteVertex`: a quad corner's clip position, `clipCentre + (corner · sizePx / (viewportSize / 2)
31
+ * · clipCentre.w, 0, 0)`; `corner` in `[−0.5, 0.5]²`, `viewportSize` in pixels. The quad is `sizePx` wide
32
+ * on screen whatever the depth.
33
+ */
34
+ export declare function vdbPointSpriteWgsl(): string;
35
+ /**
36
+ * The pixel scale of {@link vdbPointSpriteSize} (pixels at view depth 1) for a point of world diameter
37
+ * `diameter`: `diameter · maxScale(model) · projection[5] · height / 2`. For a perspective projection
38
+ * `projection[5]` is `zoom / tan(fov / 2)`, his `getAttenuatedPointSize` · `height / 2`.
39
+ *
40
+ * @param diameter World diameter of a point (before the model scale).
41
+ * @param projection Column-major view → clip.
42
+ * @param height Viewport height in pixels.
43
+ * @param model Column-major local → world (default identity).
44
+ */
45
+ export declare function vdbPointPixelScale(diameter: number, projection: VDBMat4, height: number, model?: VDBMat4): number;
46
+ /** Options of {@link vdbCreatePointPass}. */
47
+ export interface VDBPointPassOptions {
48
+ readonly colorFormat: GPUTextureFormat;
49
+ /** Depth attachment format, or null for none. Default null. */
50
+ readonly depthFormat?: GPUTextureFormat | null;
51
+ /** Depth test when `depthFormat` is set. Default `'less'`. */
52
+ readonly depthCompare?: GPUCompareFunction;
53
+ readonly label?: string;
54
+ }
55
+ /** Points to draw (tools `vdbPointRenderData` returns one). */
56
+ export interface VDBPointPassData {
57
+ /** Local positions, xyz per point. */
58
+ readonly positions: Float32Array;
59
+ /** Linear RGB per point (times the frame colour), or null. */
60
+ readonly colors?: Float32Array | null;
61
+ /** Points to draw. Default `positions.length / 3`. */
62
+ readonly count?: number;
63
+ }
64
+ /** The camera of one {@link VDBPointPass.record}. Matrices are column-major. */
65
+ export interface VDBPointPassFrame {
66
+ readonly view: VDBMat4;
67
+ readonly projection: VDBMat4;
68
+ /** Local → world. Default identity. */
69
+ readonly model?: VDBMat4;
70
+ /** The render pass's viewport in attachment pixels: `[x, y, width, height]`. */
71
+ readonly viewport: readonly [number, number, number, number];
72
+ /** Pixels at view depth 1. Default {@link vdbPointPixelScale}`(diameter, projection, height, model)`. */
73
+ readonly pixelScale?: number;
74
+ /** World diameter for the default pixel scale. Default 1. */
75
+ readonly diameter?: number;
76
+ /** Smallest sprite in pixels. Default 1. */
77
+ readonly minSize?: number;
78
+ /** Colour (times each point's colour). Default white. */
79
+ readonly color?: VDBVec3;
80
+ }
81
+ /** A raw point-sprite pass (see the file comment). */
82
+ export interface VDBPointPass {
83
+ readonly device: GPUDevice;
84
+ /** Points of the last {@link setPoints}. */
85
+ readonly count: number;
86
+ /** The pipeline spec without (`[0]`) and with (`[1]`) the colour attribute. */
87
+ readonly specs: readonly [VDBRenderSpec, VDBRenderSpec];
88
+ /** Uploads the points into buffers the pass owns (the old ones are retired). */
89
+ setPoints(data: VDBPointPassData): void;
90
+ /** Builds both pipelines with the async creators (optional). */
91
+ prepare(): Promise<void>;
92
+ /** Records one instanced draw into the host's render pass (one `record()` per submitted encoder). */
93
+ record(renderPass: GPURenderPassEncoder, frame: VDBPointPassFrame): void;
94
+ /** Destroys the buffers the pass made. Idempotent. */
95
+ dispose(): void;
96
+ }
97
+ /** Group 0 binding 0. */
98
+ export declare const VDB_POINT_PASS_FRAME: import("../internal.js").VDBUniformStruct;
99
+ /** The quad's 6 corners (two triangles, three's sprite index order 0 1 2, 0 2 3). */
100
+ export declare const VDB_POINT_SPRITE_CORNERS: readonly (readonly [number, number])[];
101
+ /** The raw pass's WGSL (`colors`: with the per-point colour attribute). */
102
+ export declare function vdbPointPassWgsl(colors: boolean): string;
103
+ /**
104
+ * Creates a raw point-sprite pass on `device` (see the file comment): one instanced quad per point, an
105
+ * analytic round disc, depth-tested when `depthFormat` is set.
106
+ *
107
+ * @throws VDBError `VDB_BAD_OPTION` for bad options or data.
108
+ */
109
+ export declare function vdbCreatePointPass(device: GPUDevice, options: VDBPointPassOptions): VDBPointPass;