@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.
- package/CHANGELOG.md +592 -2
- package/README.md +85 -37
- package/THIRD_PARTY_NOTICES.md +197 -29
- package/dist/core/compute/atlas.d.ts +10 -2
- package/dist/core/compute/atlas.js +6 -1
- package/dist/core/compute/atlas.js.map +1 -1
- package/dist/core/compute/index.d.ts +3 -3
- package/dist/core/compute/index.js +2 -2
- package/dist/core/compute/index.js.map +1 -1
- package/dist/core/compute/majorant-build.d.ts +45 -0
- package/dist/core/compute/majorant-build.js +193 -0
- package/dist/core/compute/majorant-build.js.map +1 -0
- package/dist/core/compute/multi-scale.d.ts +155 -0
- package/dist/core/compute/multi-scale.js +684 -0
- package/dist/core/compute/multi-scale.js.map +1 -0
- package/dist/core/compute/pyramid.d.ts +22 -7
- package/dist/core/compute/pyramid.js +22 -9
- package/dist/core/compute/pyramid.js.map +1 -1
- package/dist/core/compute/shared.d.ts +1 -0
- package/dist/core/compute/shared.js.map +1 -1
- package/dist/core/compute/stats.d.ts +10 -3
- package/dist/core/compute/stats.js +6 -1
- package/dist/core/compute/stats.js.map +1 -1
- package/dist/core/compute/value-transform.d.ts +8 -1
- package/dist/core/compute/value-transform.js +9 -3
- package/dist/core/compute/value-transform.js.map +1 -1
- package/dist/core/errors.d.ts +10 -0
- package/dist/core/errors.js +8 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/frame/emission.d.ts +85 -0
- package/dist/core/frame/emission.js +422 -0
- package/dist/core/frame/emission.js.map +1 -0
- package/dist/core/frame/environment.d.ts +47 -0
- package/dist/core/frame/environment.js +178 -0
- package/dist/core/frame/environment.js.map +1 -0
- package/dist/core/frame/index.d.ts +39 -0
- package/dist/core/frame/index.js +27 -0
- package/dist/core/frame/index.js.map +1 -0
- package/dist/core/frame/kernels.d.ts +115 -0
- package/dist/core/frame/kernels.js +496 -0
- package/dist/core/frame/kernels.js.map +1 -0
- package/dist/core/frame/limits.d.ts +67 -0
- package/dist/core/frame/limits.js +109 -0
- package/dist/core/frame/limits.js.map +1 -0
- package/dist/core/frame/phase.d.ts +17 -0
- package/dist/core/frame/phase.js +53 -0
- package/dist/core/frame/phase.js.map +1 -0
- package/dist/core/frame/pipelines.d.ts +49 -0
- package/dist/core/frame/pipelines.js +147 -0
- package/dist/core/frame/pipelines.js.map +1 -0
- package/dist/core/frame/renderer.d.ts +122 -0
- package/dist/core/frame/renderer.js +1712 -0
- package/dist/core/frame/renderer.js.map +1 -0
- package/dist/core/frame/resources.d.ts +71 -0
- package/dist/core/frame/resources.js +100 -0
- package/dist/core/frame/resources.js.map +1 -0
- package/dist/core/frame/scattering.d.ts +97 -0
- package/dist/core/frame/scattering.js +332 -0
- package/dist/core/frame/scattering.js.map +1 -0
- package/dist/core/frame/settings.d.ts +243 -0
- package/dist/core/frame/settings.js +67 -0
- package/dist/core/frame/settings.js.map +1 -0
- package/dist/core/frame/shadows.d.ts +55 -0
- package/dist/core/frame/shadows.js +460 -0
- package/dist/core/frame/shadows.js.map +1 -0
- package/dist/core/frame/types.d.ts +415 -0
- package/dist/core/frame/types.js +49 -0
- package/dist/core/frame/types.js.map +1 -0
- package/dist/core/frame/uniforms.d.ts +105 -0
- package/dist/core/frame/uniforms.js +276 -0
- package/dist/core/frame/uniforms.js.map +1 -0
- package/dist/core/frame/wgsl/chunks.d.ts +4 -0
- package/dist/core/frame/wgsl/chunks.js +728 -0
- package/dist/core/frame/wgsl/chunks.js.map +1 -0
- package/dist/core/frame/wgsl/emission.d.ts +82 -0
- package/dist/core/frame/wgsl/emission.js +353 -0
- package/dist/core/frame/wgsl/emission.js.map +1 -0
- package/dist/core/frame/wgsl/environment.d.ts +42 -0
- package/dist/core/frame/wgsl/environment.js +711 -0
- package/dist/core/frame/wgsl/environment.js.map +1 -0
- package/dist/core/frame/wgsl/gather.d.ts +55 -0
- package/dist/core/frame/wgsl/gather.js +850 -0
- package/dist/core/frame/wgsl/gather.js.map +1 -0
- package/dist/core/frame/wgsl/integrate.d.ts +78 -0
- package/dist/core/frame/wgsl/integrate.js +213 -0
- package/dist/core/frame/wgsl/integrate.js.map +1 -0
- package/dist/core/frame/wgsl/lighting.d.ts +103 -0
- package/dist/core/frame/wgsl/lighting.js +1636 -0
- package/dist/core/frame/wgsl/lighting.js.map +1 -0
- package/dist/core/frame/wgsl/occluders.d.ts +20 -0
- package/dist/core/frame/wgsl/occluders.js +95 -0
- package/dist/core/frame/wgsl/occluders.js.map +1 -0
- package/dist/core/frame/wgsl/resolve.d.ts +19 -0
- package/dist/core/frame/wgsl/resolve.js +205 -0
- package/dist/core/frame/wgsl/resolve.js.map +1 -0
- package/dist/core/frame/wgsl/shadows.d.ts +35 -0
- package/dist/core/frame/wgsl/shadows.js +328 -0
- package/dist/core/frame/wgsl/shadows.js.map +1 -0
- package/dist/core/half.d.ts +11 -0
- package/dist/core/half.js +22 -0
- package/dist/core/half.js.map +1 -0
- package/dist/core/index.d.ts +25 -3
- package/dist/core/index.js +23 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/internal.d.ts +17 -1
- package/dist/core/internal.js +18 -1
- package/dist/core/internal.js.map +1 -1
- package/dist/core/pool/image-header.d.ts +13 -2
- package/dist/core/pool/image-header.js +24 -5
- package/dist/core/pool/image-header.js.map +1 -1
- package/dist/core/pool/layout.d.ts +35 -1
- package/dist/core/pool/layout.js +51 -2
- package/dist/core/pool/layout.js.map +1 -1
- package/dist/core/pool/limits.d.ts +1 -0
- package/dist/core/pool/limits.js +1 -0
- package/dist/core/pool/limits.js.map +1 -1
- package/dist/core/pool/pool.d.ts +120 -15
- package/dist/core/pool/pool.js +255 -24
- package/dist/core/pool/pool.js.map +1 -1
- package/dist/core/reference/index.d.ts +6 -0
- package/dist/core/reference/index.js +7 -0
- package/dist/core/reference/index.js.map +1 -0
- package/dist/core/reference/renderer.d.ts +105 -0
- package/dist/core/reference/renderer.js +474 -0
- package/dist/core/reference/renderer.js.map +1 -0
- package/dist/core/reference/wgsl.d.ts +65 -0
- package/dist/core/reference/wgsl.js +803 -0
- package/dist/core/reference/wgsl.js.map +1 -0
- package/dist/{three → core}/sequence.d.ts +32 -2
- package/dist/{three → core}/sequence.js +24 -2
- package/dist/core/sequence.js.map +1 -0
- package/dist/core/source/brick-cache.d.ts +165 -0
- package/dist/core/source/brick-cache.js +627 -0
- package/dist/core/source/brick-cache.js.map +1 -0
- package/dist/core/source/dense-fill.d.ts +53 -0
- package/dist/core/source/dense-fill.js +377 -0
- package/dist/core/source/dense-fill.js.map +1 -0
- package/dist/core/source/dense.d.ts +33 -2
- package/dist/core/source/dense.js +121 -24
- package/dist/core/source/dense.js.map +1 -1
- package/dist/core/source/sparse-wgsl.d.ts +92 -0
- package/dist/core/source/sparse-wgsl.js +481 -0
- package/dist/core/source/sparse-wgsl.js.map +1 -0
- package/dist/core/source/sparse.d.ts +192 -0
- package/dist/core/source/sparse.js +762 -0
- package/dist/core/source/sparse.js.map +1 -0
- package/dist/core/source/types.d.ts +59 -2
- package/dist/core/source/types.js.map +1 -1
- package/dist/core/surface/index.d.ts +10 -0
- package/dist/core/surface/index.js +9 -0
- package/dist/core/surface/index.js.map +1 -0
- package/dist/core/surface/level-set-pass.d.ts +140 -0
- package/dist/core/surface/level-set-pass.js +291 -0
- package/dist/core/surface/level-set-pass.js.map +1 -0
- package/dist/core/surface/level-set-wgsl.d.ts +46 -0
- package/dist/core/surface/level-set-wgsl.js +99 -0
- package/dist/core/surface/level-set-wgsl.js.map +1 -0
- package/dist/core/surface/points.d.ts +109 -0
- package/dist/core/surface/points.js +226 -0
- package/dist/core/surface/points.js.map +1 -0
- package/dist/core/types.d.ts +12 -3
- package/dist/core/types.js +6 -2
- package/dist/core/types.js.map +1 -1
- package/dist/core/wgsl/api.d.ts +29 -5
- package/dist/core/wgsl/api.js +110 -27
- package/dist/core/wgsl/api.js.map +1 -1
- package/dist/core/wgsl/generate.d.ts +8 -0
- package/dist/core/wgsl/generate.js +195 -22
- package/dist/core/wgsl/generate.js.map +1 -1
- package/dist/core/wgsl/lean.d.ts +50 -0
- package/dist/core/wgsl/lean.js +327 -0
- package/dist/core/wgsl/lean.js.map +1 -0
- package/dist/core/wgsl/level-set.d.ts +5 -1
- package/dist/core/wgsl/level-set.js +11 -5
- package/dist/core/wgsl/level-set.js.map +1 -1
- package/dist/core/wgsl/majorant.d.ts +62 -0
- package/dist/core/wgsl/majorant.js +381 -0
- package/dist/core/wgsl/majorant.js.map +1 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +2 -2
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
- package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
- package/dist/core/wgsl/types.d.ts +97 -3
- package/dist/core/wgsl/types.js.map +1 -1
- package/dist/three/coarse-first.d.ts +53 -8
- package/dist/three/coarse-first.js +24 -6
- package/dist/three/coarse-first.js.map +1 -1
- package/dist/three/compute.d.ts +12 -2
- package/dist/three/compute.js +16 -6
- package/dist/three/compute.js.map +1 -1
- package/dist/three/device.d.ts +7 -0
- package/dist/three/device.js +3 -0
- package/dist/three/device.js.map +1 -1
- package/dist/three/frame/core-environment.d.ts +38 -0
- package/dist/three/frame/core-environment.js +154 -0
- package/dist/three/frame/core-environment.js.map +1 -0
- package/dist/three/frame/core-integrate-material.d.ts +34 -0
- package/dist/three/frame/core-integrate-material.js +162 -0
- package/dist/three/frame/core-integrate-material.js.map +1 -0
- package/dist/three/frame/core-occluders.d.ts +53 -0
- package/dist/three/frame/core-occluders.js +193 -0
- package/dist/three/frame/core-occluders.js.map +1 -0
- package/dist/three/frame/core-structs.d.ts +34 -0
- package/dist/three/frame/core-structs.js +61 -0
- package/dist/three/frame/core-structs.js.map +1 -0
- package/dist/three/frame/core-textures.d.ts +41 -0
- package/dist/three/frame/core-textures.js +114 -0
- package/dist/three/frame/core-textures.js.map +1 -0
- package/dist/three/frame/emission-light.d.ts +64 -114
- package/dist/three/frame/emission-light.js +188 -567
- package/dist/three/frame/emission-light.js.map +1 -1
- package/dist/three/frame/index.d.ts +11 -31
- package/dist/three/frame/index.js +9 -29
- package/dist/three/frame/index.js.map +1 -1
- package/dist/three/frame/medium.d.ts +12 -0
- package/dist/three/frame/medium.js.map +1 -1
- package/dist/three/frame/renderer.d.ts +58 -454
- package/dist/three/frame/renderer.js +409 -1427
- package/dist/three/frame/renderer.js.map +1 -1
- package/dist/three/frame/spectrum.d.ts +0 -14
- package/dist/three/frame/spectrum.js +2 -23
- package/dist/three/frame/spectrum.js.map +1 -1
- package/dist/three/frame/three-internals.d.ts +3 -8
- package/dist/three/frame/three-internals.js +13 -11
- package/dist/three/frame/three-internals.js.map +1 -1
- package/dist/three/frame/volume-shadows.d.ts +93 -107
- package/dist/three/frame/volume-shadows.js +278 -631
- package/dist/three/frame/volume-shadows.js.map +1 -1
- package/dist/three/frame/volume.d.ts +91 -33
- package/dist/three/frame/volume.js +63 -51
- package/dist/three/frame/volume.js.map +1 -1
- package/dist/three/grid-node.d.ts +34 -1
- package/dist/three/grid-node.js +36 -1
- package/dist/three/grid-node.js.map +1 -1
- package/dist/three/index.d.ts +20 -11
- package/dist/three/index.js +21 -12
- package/dist/three/index.js.map +1 -1
- package/dist/three/internal.d.ts +14 -8
- package/dist/three/internal.js +11 -7
- package/dist/three/internal.js.map +1 -1
- package/dist/three/level-set-material.d.ts +81 -8
- package/dist/three/level-set-material.js +162 -125
- package/dist/three/level-set-material.js.map +1 -1
- package/dist/three/level-set-physical-material.d.ts +154 -0
- package/dist/three/level-set-physical-material.js +253 -0
- package/dist/three/level-set-physical-material.js.map +1 -0
- package/dist/three/level-set-velocity.d.ts +94 -0
- package/dist/three/level-set-velocity.js +208 -0
- package/dist/three/level-set-velocity.js.map +1 -0
- package/dist/three/material.d.ts +141 -11
- package/dist/three/material.js +161 -18
- package/dist/three/material.js.map +1 -1
- package/dist/three/points.d.ts +60 -4
- package/dist/three/points.js +140 -9
- package/dist/three/points.js.map +1 -1
- package/dist/three/sparse-source.d.ts +49 -117
- package/dist/three/sparse-source.js +109 -580
- package/dist/three/sparse-source.js.map +1 -1
- package/dist/three/volume-source.d.ts +11 -156
- package/dist/three/volume-source.js +29 -272
- package/dist/three/volume-source.js.map +1 -1
- package/dist/tools/cpu/brick-atlas.d.ts +36 -0
- package/dist/tools/cpu/brick-atlas.js +129 -0
- package/dist/tools/cpu/brick-atlas.js.map +1 -0
- package/dist/tools/cpu/compute.d.ts +23 -4
- package/dist/tools/cpu/compute.js +35 -14
- package/dist/tools/cpu/compute.js.map +1 -1
- package/dist/tools/cpu/lean-reads.d.ts +81 -0
- package/dist/tools/cpu/lean-reads.js +262 -0
- package/dist/tools/cpu/lean-reads.js.map +1 -0
- package/dist/tools/cpu/level-set.d.ts +42 -3
- package/dist/tools/cpu/level-set.js +59 -7
- package/dist/tools/cpu/level-set.js.map +1 -1
- package/dist/tools/cpu/majorant.d.ts +265 -0
- package/dist/tools/cpu/majorant.js +541 -0
- package/dist/tools/cpu/majorant.js.map +1 -0
- package/dist/tools/cpu/march.d.ts +93 -2
- package/dist/tools/cpu/march.js +165 -14
- package/dist/tools/cpu/march.js.map +1 -1
- package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
- package/dist/tools/cpu/mesh-decimate.js +1225 -0
- package/dist/tools/cpu/mesh-decimate.js.map +1 -0
- package/dist/tools/cpu/points.d.ts +29 -0
- package/dist/tools/cpu/points.js +38 -0
- package/dist/tools/cpu/points.js.map +1 -0
- package/dist/tools/cpu/read-value.d.ts +19 -6
- package/dist/tools/cpu/read-value.js +32 -17
- package/dist/tools/cpu/read-value.js.map +1 -1
- package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
- package/dist/tools/cpu/sample-trilinear.js +19 -7
- package/dist/tools/cpu/sample-trilinear.js.map +1 -1
- package/dist/tools/cpu/stride-tables.d.ts +2 -2
- package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
- package/dist/tools/cpu/stride-tables.generated.js +7 -6
- package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
- package/dist/tools/cpu/stride-tables.js +1 -1
- package/dist/tools/cpu/stride-tables.js.map +1 -1
- package/dist/tools/cpu/surface-nets.d.ts +90 -0
- package/dist/tools/cpu/surface-nets.js +597 -0
- package/dist/tools/cpu/surface-nets.js.map +1 -0
- package/dist/tools/errors.d.ts +9 -0
- package/dist/tools/errors.js +9 -0
- package/dist/tools/errors.js.map +1 -1
- package/dist/tools/frame/ambient.d.ts +98 -0
- package/dist/tools/frame/ambient.js +274 -0
- package/dist/tools/frame/ambient.js.map +1 -0
- package/dist/tools/frame/blackbody.d.ts +15 -0
- package/dist/tools/frame/blackbody.js +35 -0
- package/dist/tools/frame/blackbody.js.map +1 -1
- package/dist/tools/frame/brick-cache.d.ts +165 -0
- package/dist/tools/frame/brick-cache.js +326 -0
- package/dist/tools/frame/brick-cache.js.map +1 -0
- package/dist/tools/frame/emission.d.ts +9 -0
- package/dist/tools/frame/emission.js +9 -1
- package/dist/tools/frame/emission.js.map +1 -1
- package/dist/tools/frame/environment-gpu.d.ts +111 -0
- package/dist/tools/frame/environment-gpu.js +280 -0
- package/dist/tools/frame/environment-gpu.js.map +1 -0
- package/dist/tools/frame/environment.d.ts +3 -2
- package/dist/tools/frame/environment.js +8 -4
- package/dist/tools/frame/environment.js.map +1 -1
- package/dist/tools/frame/froxel.d.ts +58 -0
- package/dist/tools/frame/froxel.js +115 -0
- package/dist/tools/frame/froxel.js.map +1 -0
- package/dist/tools/frame/grid.d.ts +90 -0
- package/dist/tools/frame/grid.js +112 -13
- package/dist/tools/frame/grid.js.map +1 -1
- package/dist/tools/frame/index.d.ts +14 -0
- package/dist/tools/frame/index.js +45 -4
- package/dist/tools/frame/index.js.map +1 -1
- package/dist/tools/frame/medium.d.ts +16 -0
- package/dist/tools/frame/medium.js +3 -1
- package/dist/tools/frame/medium.js.map +1 -1
- package/dist/tools/frame/mie.d.ts +9 -0
- package/dist/tools/frame/mie.js +18 -0
- package/dist/tools/frame/mie.js.map +1 -1
- package/dist/tools/frame/mlp-nn.d.ts +36 -0
- package/dist/tools/frame/mlp-nn.js +159 -0
- package/dist/tools/frame/mlp-nn.js.map +1 -0
- package/dist/tools/frame/mlp-tza.d.ts +29 -0
- package/dist/tools/frame/mlp-tza.js +186 -0
- package/dist/tools/frame/mlp-tza.js.map +1 -0
- package/dist/tools/frame/mlp.d.ts +183 -0
- package/dist/tools/frame/mlp.js +434 -0
- package/dist/tools/frame/mlp.js.map +1 -0
- package/dist/tools/frame/ms-exit.d.ts +42 -0
- package/dist/tools/frame/ms-exit.js +90 -0
- package/dist/tools/frame/ms-exit.js.map +1 -0
- package/dist/tools/frame/multi-scale.d.ts +152 -0
- package/dist/tools/frame/multi-scale.js +302 -0
- package/dist/tools/frame/multi-scale.js.map +1 -0
- package/dist/tools/frame/neural-weights.d.ts +6 -5
- package/dist/tools/frame/neural-weights.js +234 -235
- package/dist/tools/frame/neural-weights.js.map +1 -1
- package/dist/tools/frame/neural.js +1 -1
- package/dist/tools/frame/neural.js.map +1 -1
- package/dist/tools/frame/occluders.d.ts +51 -0
- package/dist/tools/frame/occluders.js +72 -0
- package/dist/tools/frame/occluders.js.map +1 -0
- package/dist/tools/frame/pyramid-layout.d.ts +17 -0
- package/dist/tools/frame/pyramid-layout.js +47 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -1
- package/dist/tools/frame/shadows.d.ts +110 -0
- package/dist/tools/frame/shadows.js +286 -0
- package/dist/tools/frame/shadows.js.map +1 -1
- package/dist/tools/frame/sparse.d.ts +82 -0
- package/dist/tools/frame/sparse.js +242 -1
- package/dist/tools/frame/sparse.js.map +1 -1
- package/dist/tools/frame/spectral-stack.d.ts +159 -0
- package/dist/tools/frame/spectral-stack.js +391 -0
- package/dist/tools/frame/spectral-stack.js.map +1 -0
- package/dist/tools/frame/spectral.d.ts +21 -2
- package/dist/tools/frame/spectral.js +30 -8
- package/dist/tools/frame/spectral.js.map +1 -1
- package/dist/tools/frame/stack.d.ts +115 -0
- package/dist/tools/frame/stack.js +290 -0
- package/dist/tools/frame/stack.js.map +1 -0
- package/dist/tools/frame/view.d.ts +131 -0
- package/dist/tools/frame/view.js +337 -0
- package/dist/tools/frame/view.js.map +1 -0
- package/dist/tools/index.d.ts +66 -15
- package/dist/tools/index.js +55 -11
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/internal.d.ts +58 -17
- package/dist/tools/internal.js +65 -11
- package/dist/tools/internal.js.map +1 -1
- package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
- package/dist/tools/nanovdb/build-from-vdb.js +10 -2
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
- package/dist/tools/nanovdb/bytes.d.ts +17 -4
- package/dist/tools/nanovdb/bytes.js +46 -3
- package/dist/tools/nanovdb/bytes.js.map +1 -1
- package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
- package/dist/tools/nanovdb/coarse-first.js +7 -1
- package/dist/tools/nanovdb/coarse-first.js.map +1 -1
- package/dist/tools/nanovdb/half.d.ts +22 -0
- package/dist/tools/nanovdb/half.js +73 -0
- package/dist/tools/nanovdb/half.js.map +1 -0
- package/dist/tools/nanovdb/index.d.ts +3 -1
- package/dist/tools/nanovdb/index.js +2 -1
- package/dist/tools/nanovdb/index.js.map +1 -1
- package/dist/tools/nanovdb/inspect.d.ts +10 -1
- package/dist/tools/nanovdb/inspect.js +8 -1
- package/dist/tools/nanovdb/inspect.js.map +1 -1
- package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
- package/dist/tools/nanovdb/leaf-codec.js +40 -4
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
- package/dist/tools/nanovdb/quantize.d.ts +39 -10
- package/dist/tools/nanovdb/quantize.js +96 -44
- package/dist/tools/nanovdb/quantize.js.map +1 -1
- package/dist/tools/nanovdb/resample.d.ts +20 -3
- package/dist/tools/nanovdb/resample.js +20 -7
- package/dist/tools/nanovdb/resample.js.map +1 -1
- package/dist/tools/nanovdb/serialize.d.ts +34 -3
- package/dist/tools/nanovdb/serialize.js +51 -7
- package/dist/tools/nanovdb/serialize.js.map +1 -1
- package/dist/tools/nanovdb/stats.d.ts +34 -5
- package/dist/tools/nanovdb/stats.js +87 -11
- package/dist/tools/nanovdb/stats.js.map +1 -1
- package/dist/tools/nanovdb/transform.d.ts +4 -0
- package/dist/tools/nanovdb/transform.js +3 -0
- package/dist/tools/nanovdb/transform.js.map +1 -1
- package/dist/tools/nanovdb/tree.d.ts +14 -3
- package/dist/tools/nanovdb/tree.js +25 -13
- package/dist/tools/nanovdb/tree.js.map +1 -1
- package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
- package/dist/tools/nanovdb/write-nvdb.js +108 -28
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
- package/dist/tools/nvdb-file.d.ts +77 -7
- package/dist/tools/nvdb-file.js +177 -20
- package/dist/tools/nvdb-file.js.map +1 -1
- package/dist/tools/nvdb-stream.d.ts +23 -7
- package/dist/tools/nvdb-stream.js +78 -34
- package/dist/tools/nvdb-stream.js.map +1 -1
- package/dist/tools/reference/analytic.d.ts +41 -0
- package/dist/tools/reference/analytic.js +95 -0
- package/dist/tools/reference/analytic.js.map +1 -0
- package/dist/tools/reference/environment.d.ts +62 -0
- package/dist/tools/reference/environment.js +154 -0
- package/dist/tools/reference/environment.js.map +1 -0
- package/dist/tools/reference/index.d.ts +12 -0
- package/dist/tools/reference/index.js +13 -0
- package/dist/tools/reference/index.js.map +1 -0
- package/dist/tools/reference/media.d.ts +14 -0
- package/dist/tools/reference/media.js +30 -0
- package/dist/tools/reference/media.js.map +1 -0
- package/dist/tools/reference/rng.d.ts +20 -0
- package/dist/tools/reference/rng.js +30 -0
- package/dist/tools/reference/rng.js.map +1 -0
- package/dist/tools/reference/scene.d.ts +312 -0
- package/dist/tools/reference/scene.js +169 -0
- package/dist/tools/reference/scene.js.map +1 -0
- package/dist/tools/reference/tables.d.ts +98 -0
- package/dist/tools/reference/tables.js +264 -0
- package/dist/tools/reference/tables.js.map +1 -0
- package/dist/tools/reference/trace.d.ts +160 -0
- package/dist/tools/reference/trace.js +497 -0
- package/dist/tools/reference/trace.js.map +1 -0
- package/dist/tools/vdb/blosc-write.d.ts +43 -0
- package/dist/tools/vdb/blosc-write.js +197 -0
- package/dist/tools/vdb/blosc-write.js.map +1 -0
- package/dist/tools/vdb/blosc.d.ts +35 -5
- package/dist/tools/vdb/blosc.js +82 -26
- package/dist/tools/vdb/blosc.js.map +1 -1
- package/dist/tools/vdb/blosclz.d.ts +33 -0
- package/dist/tools/vdb/blosclz.js +112 -0
- package/dist/tools/vdb/blosclz.js.map +1 -0
- package/dist/tools/vdb/byte-reader.d.ts +13 -3
- package/dist/tools/vdb/byte-reader.js +26 -4
- package/dist/tools/vdb/byte-reader.js.map +1 -1
- package/dist/tools/vdb/compression.d.ts +13 -5
- package/dist/tools/vdb/compression.js +13 -2
- package/dist/tools/vdb/compression.js.map +1 -1
- package/dist/tools/vdb/grid.js +8 -2
- package/dist/tools/vdb/grid.js.map +1 -1
- package/dist/tools/vdb/index.d.ts +2 -1
- package/dist/tools/vdb/index.js.map +1 -1
- package/dist/tools/vdb/lz4.d.ts +30 -0
- package/dist/tools/vdb/lz4.js +228 -0
- package/dist/tools/vdb/lz4.js.map +1 -0
- package/dist/tools/vdb/metadata.js +1 -1
- package/dist/tools/vdb/metadata.js.map +1 -1
- package/dist/tools/vdb/parse.d.ts +24 -2
- package/dist/tools/vdb/parse.js +102 -32
- package/dist/tools/vdb/parse.js.map +1 -1
- package/dist/tools/vdb/point-render-data.d.ts +49 -1
- package/dist/tools/vdb/point-render-data.js +91 -11
- package/dist/tools/vdb/point-render-data.js.map +1 -1
- package/dist/tools/vdb/points.d.ts +26 -0
- package/dist/tools/vdb/points.js +46 -5
- package/dist/tools/vdb/points.js.map +1 -1
- package/dist/tools/vdb/types.d.ts +59 -2
- package/dist/tools/vdb/types.js.map +1 -1
- package/dist/tools/wvdb/bake.d.ts +38 -9
- package/dist/tools/wvdb/bake.js +63 -13
- package/dist/tools/wvdb/bake.js.map +1 -1
- package/dist/tools/wvdb/dense.d.ts +80 -1
- package/dist/tools/wvdb/dense.js +67 -8
- package/dist/tools/wvdb/dense.js.map +1 -1
- package/dist/tools/wvdb/format.d.ts +59 -0
- package/dist/tools/wvdb/format.js +3 -0
- package/dist/tools/wvdb/format.js.map +1 -1
- package/dist/tools/wvdb/index.d.ts +1 -0
- package/dist/tools/wvdb/index.js +1 -0
- package/dist/tools/wvdb/index.js.map +1 -1
- package/dist/tools/wvdb/level-set.d.ts +10 -2
- package/dist/tools/wvdb/level-set.js.map +1 -1
- package/dist/tools/wvdb/nanovdb.d.ts +6 -1
- package/dist/tools/wvdb/nanovdb.js +5 -1
- package/dist/tools/wvdb/nanovdb.js.map +1 -1
- package/dist/tools/wvdb/partial.d.ts +74 -0
- package/dist/tools/wvdb/partial.js +233 -0
- package/dist/tools/wvdb/partial.js.map +1 -0
- package/dist/tools/wvdb/read.d.ts +77 -1
- package/dist/tools/wvdb/read.js +30 -7
- package/dist/tools/wvdb/read.js.map +1 -1
- package/dist/tools/wvdb/write.d.ts +23 -1
- package/dist/tools/wvdb/write.js +8 -1
- package/dist/tools/wvdb/write.js.map +1 -1
- package/package.json +2 -1
- package/vendor/VENDOR.md +21 -6
- package/vendor/pnanovdb.wgsl +52 -14
- package/dist/three/frame/blackbody.d.ts +0 -42
- package/dist/three/frame/blackbody.js +0 -74
- package/dist/three/frame/blackbody.js.map +0 -1
- package/dist/three/frame/chunks.d.ts +0 -157
- package/dist/three/frame/chunks.js +0 -559
- package/dist/three/frame/chunks.js.map +0 -1
- package/dist/three/frame/density-material.d.ts +0 -53
- package/dist/three/frame/density-material.js +0 -353
- package/dist/three/frame/density-material.js.map +0 -1
- package/dist/three/frame/environment-grid-material.d.ts +0 -21
- package/dist/three/frame/environment-grid-material.js +0 -184
- package/dist/three/frame/environment-grid-material.js.map +0 -1
- package/dist/three/frame/environment-material.d.ts +0 -22
- package/dist/three/frame/environment-material.js +0 -87
- package/dist/three/frame/environment-material.js.map +0 -1
- package/dist/three/frame/grid-mip-material.d.ts +0 -12
- package/dist/three/frame/grid-mip-material.js +0 -61
- package/dist/three/frame/grid-mip-material.js.map +0 -1
- package/dist/three/frame/inject-material.d.ts +0 -56
- package/dist/three/frame/inject-material.js +0 -424
- package/dist/three/frame/inject-material.js.map +0 -1
- package/dist/three/frame/integrate-material.d.ts +0 -26
- package/dist/three/frame/integrate-material.js +0 -198
- package/dist/three/frame/integrate-material.js.map +0 -1
- package/dist/three/frame/layout.d.ts +0 -34
- package/dist/three/frame/layout.js +0 -48
- package/dist/three/frame/layout.js.map +0 -1
- package/dist/three/frame/lighting-material.d.ts +0 -41
- package/dist/three/frame/lighting-material.js +0 -257
- package/dist/three/frame/lighting-material.js.map +0 -1
- package/dist/three/frame/lights.d.ts +0 -11
- package/dist/three/frame/lights.js +0 -16
- package/dist/three/frame/lights.js.map +0 -1
- package/dist/three/frame/neural.d.ts +0 -14
- package/dist/three/frame/neural.js +0 -105
- package/dist/three/frame/neural.js.map +0 -1
- package/dist/three/frame/phase.d.ts +0 -44
- package/dist/three/frame/phase.js +0 -80
- package/dist/three/frame/phase.js.map +0 -1
- package/dist/three/frame/shadow-density-material.d.ts +0 -30
- package/dist/three/frame/shadow-density-material.js +0 -123
- package/dist/three/frame/shadow-density-material.js.map +0 -1
- package/dist/three/frame/temporal-material.d.ts +0 -29
- package/dist/three/frame/temporal-material.js +0 -152
- package/dist/three/frame/temporal-material.js.map +0 -1
- package/dist/three/frame/transmittance-material.d.ts +0 -31
- package/dist/three/frame/transmittance-material.js +0 -315
- package/dist/three/frame/transmittance-material.js.map +0 -1
- package/dist/three/frame/view.d.ts +0 -103
- package/dist/three/frame/view.js +0 -296
- package/dist/three/frame/view.js.map +0 -1
- package/dist/three/frame/volume-shadow-material.d.ts +0 -36
- package/dist/three/frame/volume-shadow-material.js +0 -128
- package/dist/three/frame/volume-shadow-material.js.map +0 -1
- package/dist/three/sequence.js.map +0 -1
|
@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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAmNtC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAwCc,CAAC,CAAC,UAAU;yBACZ,CAAC,CAAC,UAAU;yBACZ,CAAC,CAAC,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAwCX,CAAC,CAAC,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBA0Kb,eAAe;;;;;;;;;;yBAUf,qBAAqB;;;;;;;;;;;yBAWrB,uBAAuB;;;;;;;;;;yBAUvB,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAyCjB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iEAqDY,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+EpF,CAAC;AACF,CAAC","sourcesContent":["/**\n * K6.R: the reference renderer's compute kernel (`vdbRefTraceCs`) and its uniform layout. The algorithm, the random\n * stream and the draw order are those of the CPU twin (`tools/reference/trace.ts`), which documents them; this file\n * is that code in WGSL. One VDB source at group 2 (`vdbSrc*`, the K6 group-2 contract), so the kernel binds at most\n * the pool's one storage buffer (D10); the accumulation lives in rgba32float textures (group 1).\n *\n * Compile-time care (the K3.7 trap: inlined sample sites cost SwiftShader minutes): the path is a state machine whose\n * every ray query (primary transmittance, path segment, light visibility) goes through ONE call of `vdbRefTrack`, and\n * the source is read at one call site per channel.\n *\n * Group 0: `vdbRefU` (VdbRefUniforms), `vdbRefBatch` (dynamic offset, 256 B stride). Group 1: accumulation in\n * (sum, sum of squares; sampled, unfilterable), out (storage, write), the equirect environment map, and (K6.R1) the\n * table texture (one row per phase table: RGB + CDF; per emission colour table: RGB) and the majorant atlas (r32float\n * 3D: each volume's grid stacked along z). K6.R2: binding 7, the equirect map's sampling table (r32float; layout in\n * `tools/reference/environment.ts`), read when `flags` has `VDB_REF_FLAG_ENV_MIS`.\n */\n\n/** Uniform layout (bytes) of `VdbRefUniforms`; the packer is `core/reference/renderer.ts` `vdbReferencePackUniforms`. */\nexport const VDB_REF_UNIFORM_OFFSETS = Object.freeze({\n cameraToWorld: 0,\n projectionInverse: 64,\n size: 128,\n seed: 136,\n spp: 140,\n maxBounces: 144,\n rrStart: 148,\n volumeCount: 152,\n lightCount: 156,\n hemiCount: 160,\n flags: 164,\n envSize: 168,\n uniformEnv: 176,\n envRotation: 192,\n sh: 240,\n hemis: 384,\n volumes: 576,\n lights: 2112,\n size_: 3136,\n});\nexport const VDB_REF_HEMI_BYTES = 48;\nexport const VDB_REF_VOLUME_BYTES = 192;\nexport const VDB_REF_LIGHT_BYTES = 64;\n/** `flags` bits. */\nexport const VDB_REF_FLAG_BOX_FILTER = 1;\nexport const VDB_REF_FLAG_ORTHOGRAPHIC = 2;\nexport const VDB_REF_FLAG_EQUIRECT = 4;\n/** K6.R1: the environment has a light probe (`sh`). */\nexport const VDB_REF_FLAG_SH = 8;\n/** K6.R2: next-event estimation of the equirect map with MIS (`environmentSampling: 'mis'` and a map with light). */\nexport const VDB_REF_FLAG_ENV_MIS = 16;\n/** Stride of the per-dispatch batch records (dynamic uniform offsets: 256-byte aligned). */\nexport const VDB_REF_BATCH_STRIDE = 256;\n\n/**\n * The fail-before mutations (`?mutate=`): WGSL text patches, one per name, matching the CPU twin's\n * `VDBReferenceMutation`s. Each must make an analytic check fail.\n */\nexport const VDB_REFERENCE_MUTATIONS: Readonly<Record<string, readonly [string, string]>> = Object.freeze({\n \"ratio-weight\": [\"trans = trans * (1.0 - sum / sbar);\", \"trans = trans * (1.0 - 0.9 * sum / sbar);\"],\n \"delta-accept\": [\"let u = vdbRefRand() * sbar;\", \"let u = -1.0;\"],\n \"phase-norm\": [\"return (1.0 - g * g) / (4.0 * VDB_REF_PI * d * sqrt(d));\", \"return (1.0 - g * g) / (d * sqrt(d));\"],\n \"nee-transmittance\": [\"rad = rad + beta * neeLi * hit.trans;\", \"rad = rad + beta * neeLi;\"],\n \"emission-albedo\": [\"rad = rad + beta * le;\", \"rad = rad + beta * le * albedo;\"],\n \"escape-depth\": [\"if (depth > 0u) {\", \"if (depth == 1u) {\"],\n // K6.R1\n \"majorant-cell\": [\"let cellIndex = cell;\", \"let cellIndex = vec3u(cell.x, cell.y, 0u);\"],\n \"phase-table-weight\": [\"return VdbRefPhaseSample(cos(theta), vdbRefTableAt(row, size, u).xyz * s, pdf);\", \"return VdbRefPhaseSample(cos(theta), vdbRefTableAt(row, size, u).yyy * s, pdf);\"],\n falloff: [\"let mode = u32(l.extra.x + 0.5);\", \"let mode = select(u32(l.extra.x + 0.5), 0u, l.extra.x > 1.5);\"],\n // K6.R2: the map's density without each texel's own solid angle; the escape gathering the map with weight 1\n \"env-pdf\": [\"let omega = vdbRefEnvTable(y, h + 4u);\", \"let omega = 4.0 * VDB_REF_PI / f32(w * h);\"],\n \"mis-weight\": [\"w = vdbRefMisWeight(phasePdf, vdbRefEnvPdf(d));\", \"w = 1.0;\"],\n // Issue #2 (stochastic kernel on a sparse source): the upper voxel with probability 1 - frac, not frac.\n \"stochastic-pick\": [\"select(vec3i(0), vec3i(1), xi < p - b);\", \"select(vec3i(0), vec3i(1), xi >= p - b);\"],\n});\n\n/** The kernel's WGSL after the source's (`vdbSrc*`) and module text. */\nexport function vdbReferenceKernelWgsl(o: { maxVolumes: number; maxLights: number; maxHemispheres: number; maxSteps: number; ratioRr: number; stochastic?: boolean }): string {\n // Issue #2: the stochastic density draws xi (x, y, z, in that order) from the shared stream before the read.\n const density = o.stochastic\n ? `let xi0 = vdbRefRand();\n let xi1 = vdbRefRand();\n let xi2 = vdbRefRand();\n let value = vdbSrcDensityStochastic(v, uvw, 0.0, vec3f(xi0, xi1, xi2)) * vdbSrcMask(v, uvw, 0.0);`\n : \"let value = vdbSrcDensity(v, uvw, 0.0) * vdbSrcMask(v, uvw, 0.0);\";\n return /* wgsl */ `\n// ---- K6.R reference renderer (core/reference/wgsl.ts): brute-force volumetric path tracing -------------------\nconst VDB_REF_PI: f32 = 3.14159265358979;\nconst VDB_REF_MAX_STEPS: u32 = ${o.maxSteps}u;\nconst VDB_REF_RATIO_RR: f32 = ${o.ratioRr.toFixed(6)};\nconst VDB_REF_FAR: f32 = 1e30;\n\nstruct VdbRefHemi {\n sky: vec4f,\n ground: vec4f,\n up: vec4f,\n}\n\nstruct VdbRefVolume {\n worldToLocal: mat4x4f,\n params: vec4f,\n albedo: vec4f,\n phase: vec4f,\n emission: vec4f,\n temperature: vec4f,\n ids: vec4u,\n grid: vec4u,\n tables: vec4u,\n}\n\nstruct VdbRefLight {\n position: vec4f,\n direction: vec4f,\n color: vec4f,\n extra: vec4f,\n}\n\nstruct VdbRefUniforms {\n cameraToWorld: mat4x4f,\n projectionInverse: mat4x4f,\n size: vec2u,\n seed: u32,\n spp: u32,\n maxBounces: u32,\n rrStart: u32,\n volumeCount: u32,\n lightCount: u32,\n hemiCount: u32,\n flags: u32,\n envSize: vec2u,\n uniformEnv: vec4f,\n envRotation0: vec4f,\n envRotation1: vec4f,\n envRotation2: vec4f,\n sh: array<vec4f, 9>,\n hemis: array<VdbRefHemi, ${o.maxHemispheres}>,\n volumes: array<VdbRefVolume, ${o.maxVolumes}>,\n lights: array<VdbRefLight, ${o.maxLights}>,\n}\n\nstruct VdbRefBatch {\n batch: u32,\n accumulate: u32,\n pad0: u32,\n pad1: u32,\n}\n\n@group(0) @binding(0) var<uniform> vdbRefU: VdbRefUniforms;\n@group(0) @binding(1) var<uniform> vdbRefBatch: VdbRefBatch;\n@group(1) @binding(0) var vdbRefAccumIn0: texture_2d<f32>;\n@group(1) @binding(1) var vdbRefAccumIn1: texture_2d<f32>;\n@group(1) @binding(2) var vdbRefAccumOut0: texture_storage_2d<rgba32float, write>;\n@group(1) @binding(3) var vdbRefAccumOut1: texture_storage_2d<rgba32float, write>;\n@group(1) @binding(4) var vdbRefEnvMap: texture_2d<f32>;\n@group(1) @binding(5) var vdbRefTables: texture_2d<f32>;\n@group(1) @binding(6) var vdbRefMajorants: texture_3d<f32>;\n@group(1) @binding(7) var vdbRefEnvCdf: texture_2d<f32>;\n\n// ---- random stream (tools/reference/rng.ts) ----\nvar<private> vdbRefState: u32;\n\nfn vdbRefPcg(v: u32) -> u32 {\n let s = v * 747796405u + 2891336453u;\n let w = ((s >> ((s >> 28u) + 4u)) ^ s) * 277803737u;\n return (w >> 22u) ^ w;\n}\n\nfn vdbRefSeed(seed: u32, sampleIndex: u32, pixel: u32) {\n vdbRefState = vdbRefPcg(pixel + vdbRefPcg(seed ^ vdbRefPcg(sampleIndex)));\n}\n\nfn vdbRefRand() -> f32 {\n vdbRefState = vdbRefState * 747796405u + 2891336453u;\n let s = vdbRefState;\n let w = ((s >> ((s >> 28u) + 4u)) ^ s) * 277803737u;\n return f32(((w >> 22u) ^ w) >> 8u) * 5.9604644775390625e-8;\n}\n\n// ---- phase (tools/reference/trace.ts vdbRefHenyeyGreenstein, vdbRefPhase, vdbRefSampleHgCos) ----\nfn vdbRefHg(c: f32, g: f32) -> f32 {\n let d = 1.0 + g * g - 2.0 * g * c;\n return (1.0 - g * g) / (4.0 * VDB_REF_PI * d * sqrt(d));\n}\n\n// ---- tables (tools/reference/tables.ts): row r, linear blend at texel u·(size − 1) ----\nfn vdbRefTableAt(row: u32, size: u32, u: f32) -> vec4f {\n let texel = clamp(u, 0.0, 1.0) * f32(size - 1u);\n let i = min(u32(texel), size - 2u);\n let f = texel - f32(i);\n let a = textureLoad(vdbRefTables, vec2u(i, row), 0);\n let b = textureLoad(vdbRefTables, vec2u(i + 1u, row), 0);\n return a + (b - a) * f;\n}\n\n// The phase per steradian per channel: HG / dual-lobe, or the volume's table (vdbRefPhaseTableEval).\nfn vdbRefPhaseEval(c: f32, i: u32) -> vec3f {\n let rec = vdbRefU.volumes[i];\n if (rec.tables.x > 0u) {\n let u = sqrt(acos(clamp(c, -1.0, 1.0)) / VDB_REF_PI);\n return vdbRefTableAt(rec.tables.x - 1u, rec.tables.y, u).xyz / (4.0 * VDB_REF_PI);\n }\n let ph = rec.phase;\n let a = vdbRefHg(c, ph.x);\n if (ph.z > 0.0) {\n return vec3f(a + (vdbRefHg(c, ph.y) - a) * ph.z);\n }\n return vec3f(a);\n}\n\n// Inverse-CDF sample of a phase table (vdbRefPhaseTableSample): cos theta, the per-channel weight and (K6.R2) the\n// density per steradian.\nstruct VdbRefPhaseSample {\n cosTheta: f32,\n weight: vec3f,\n pdf: f32,\n}\n\nfn vdbRefPhaseTableSample(row: u32, size: u32, xi: f32) -> VdbRefPhaseSample {\n var lo = 0u;\n var hi = size - 1u;\n loop {\n if (hi - lo <= 1u) {\n break;\n }\n let mid = (lo + hi) >> 1u;\n if (textureLoad(vdbRefTables, vec2u(mid, row), 0).w <= xi) {\n lo = mid;\n } else {\n hi = mid;\n }\n }\n let c0 = textureLoad(vdbRefTables, vec2u(lo, row), 0).w;\n let c1 = textureLoad(vdbRefTables, vec2u(lo + 1u, row), 0).w;\n let f = (xi - c0) / (c1 - c0);\n let u = (f32(lo) + f) / f32(size - 1u);\n let pdfU = (c1 - c0) * f32(size - 1u);\n let theta = VDB_REF_PI * u * u;\n let sinTheta = sin(theta);\n let s = VDB_REF_PI * u * sinTheta / pdfU;\n let pdf = pdfU / max(4.0 * VDB_REF_PI * VDB_REF_PI * u * sinTheta, 1e-30);\n return VdbRefPhaseSample(cos(theta), vdbRefTableAt(row, size, u).xyz * s, pdf);\n}\n\n// K6.R2: the density per steradian of the phase sampling at cos theta (vdbRefPhaseTablePdf; HG / dual-lobe: the phase)\nfn vdbRefPhasePdf(c: f32, i: u32) -> f32 {\n let rec = vdbRefU.volumes[i];\n if (rec.tables.x > 0u) {\n let row = rec.tables.x - 1u;\n let size = rec.tables.y;\n let cc = clamp(c, -1.0, 1.0);\n let u = sqrt(acos(cc) / VDB_REF_PI);\n let j = min(u32(u * f32(size - 1u)), size - 2u);\n let pdfU = (textureLoad(vdbRefTables, vec2u(j + 1u, row), 0).w - textureLoad(vdbRefTables, vec2u(j, row), 0).w) * f32(size - 1u);\n return pdfU / max(4.0 * VDB_REF_PI * VDB_REF_PI * u * sqrt(max(0.0, 1.0 - cc * cc)), 1e-30);\n }\n return vdbRefPhaseEval(c, i).x;\n}\n\n// K6.R2: the power heuristic (beta 2) weight of density p against q, as a ratio of at most 1e15 (no f32 overflow)\nfn vdbRefMisWeight(p: f32, q: f32) -> f32 {\n let r = q / max(max(p, q * 1e-15), 1e-30);\n return 1.0 / (1.0 + r * r);\n}\n\nfn vdbRefSampleHgCos(g: f32, u: f32) -> f32 {\n if (abs(g) < 1e-3) {\n return 1.0 - 2.0 * u;\n }\n let s = (1.0 - g * g) / (1.0 - g + 2.0 * g * u);\n return clamp((1.0 + g * g - s * s) / (2.0 * g), -1.0, 1.0);\n}\n\nfn vdbRefDirectionAround(n: vec3f, cosTheta: f32, u: f32) -> vec3f {\n let sgn = select(-1.0, 1.0, n.z >= 0.0);\n let a = -1.0 / (sgn + n.z);\n let b = n.x * n.y * a;\n let b1 = vec3f(1.0 + sgn * n.x * n.x * a, sgn * b, -sgn * n.x);\n let b2 = vec3f(b, sgn + n.y * n.y * a, -n.y);\n let sinTheta = sqrt(max(0.0, 1.0 - cosTheta * cosTheta));\n let phi = 2.0 * VDB_REF_PI * u;\n return cos(phi) * sinTheta * b1 + sin(phi) * sinTheta * b2 + cosTheta * n;\n}\n\nfn vdbRefSmoothstep(e0: f32, e1: f32, x: f32) -> f32 {\n if (!(e1 > e0)) {\n return select(0.0, 1.0, x >= e0);\n }\n let t = clamp((x - e0) / (e1 - e0), 0.0, 1.0);\n return t * t * (3.0 - 2.0 * t);\n}\n\nfn vdbRefMax3(v: vec3f) -> f32 {\n return max(v.x, max(v.y, v.z));\n}\n\n// ---- geometry (vdbRefVolumeInterval, vdbRefCameraRay) ----\nfn vdbRefInterval(i: u32, o: vec3f, d: vec3f, tMax: f32) -> vec2f {\n let m = vdbRefU.volumes[i].worldToLocal;\n let lo = (m * vec4f(o, 1.0)).xyz;\n let ld = (m * vec4f(d, 0.0)).xyz;\n var t0 = -VDB_REF_FAR;\n var t1 = VDB_REF_FAR;\n if (vdbRefU.volumes[i].params.w > 0.5) {\n let a = dot(ld, ld);\n let b = dot(lo, ld);\n let c = dot(lo, lo) - 0.25;\n let disc = b * b - a * c;\n if (disc <= 0.0 || a <= 0.0) {\n return vec2f(1.0, 0.0);\n }\n let q = sqrt(disc);\n t0 = (-b - q) / a;\n t1 = (-b + q) / a;\n } else {\n for (var k = 0u; k < 3u; k = k + 1u) {\n if (abs(ld[k]) < 1e-12) {\n if (abs(lo[k]) > 0.5) {\n return vec2f(1.0, 0.0);\n }\n } else {\n let ta = (-0.5 - lo[k]) / ld[k];\n let tb = (0.5 - lo[k]) / ld[k];\n t0 = max(t0, min(ta, tb));\n t1 = min(t1, max(ta, tb));\n }\n }\n }\n t0 = max(t0, 0.0);\n t1 = min(t1, tMax);\n if (t0 < t1) {\n return vec2f(t0, t1);\n }\n return vec2f(1.0, 0.0);\n}\n\nfn vdbRefUnproject(ndc: vec3f) -> vec3f {\n let p = vdbRefU.projectionInverse * vec4f(ndc, 1.0);\n return p.xyz / p.w;\n}\n\n// ---- the medium (the renderer's sampleExtinction / sampleAlbedo / sampleEmission at level 0) ----\nfn vdbRefUvw(i: u32, x: vec3f) -> vec3f {\n return (vdbRefU.volumes[i].worldToLocal * vec4f(x, 1.0)).xyz + vec3f(0.5);\n}\n\nfn vdbRefSigma(i: u32, x: vec3f) -> f32 {\n let uvw = vdbRefUvw(i, x);\n let v = vdbRefU.volumes[i].ids.x;\n ${density}\n let p = vdbRefU.volumes[i].params;\n return select(0.0, value, value > p.z) * p.x;\n}\n\n// ---- majorant grids (vdbRefMajorantCell): the cell at t of the ray lo + t*ld (unit box), its majorant and exit ----\nfn vdbRefMajorantAt(i: u32, lo: vec3f, ld: vec3f, t: f32, t1: f32) -> vec2f {\n let rec = vdbRefU.volumes[i];\n let dims = rec.ids.yzw;\n if (dims.x == 0u) {\n return vec2f(rec.params.y, t1);\n }\n let n = vec3f(dims);\n let q = (lo + ld * t + vec3f(0.5)) * n;\n let nudge = select(select(vec3f(0.0), vec3f(-1e-4), ld < vec3f(0.0)), vec3f(1e-4), ld > vec3f(0.0));\n let cell = vec3u(clamp(floor(q + nudge), vec3f(0.0), n - vec3f(1.0)));\n var exit = VDB_REF_FAR;\n for (var k = 0u; k < 3u; k = k + 1u) {\n if (abs(ld[k]) > 1e-12) {\n let face = (f32(cell[k]) + select(0.0, 1.0, ld[k] > 0.0)) / n[k] - 0.5;\n exit = min(exit, (face - lo[k]) / ld[k]);\n }\n }\n if (!(exit > t)) {\n exit = t + 1e-6 * max(1.0, abs(t));\n }\n let cellIndex = cell;\n let bound = textureLoad(vdbRefMajorants, vec3u(cellIndex.x, cellIndex.y, cellIndex.z + rec.grid.x), 0).x;\n return vec2f(rec.params.x * bound, min(t1, exit));\n}\n\n// ---- tracking: delta (ratio false: the collision) or ratio (ratio true: T), piecewise majorants ----\nstruct VdbRefHit {\n escaped: bool,\n t: f32,\n vol: u32,\n trans: f32,\n}\n\nfn vdbRefTrack(o: vec3f, d: vec3f, tMax: f32, ratio: bool) -> VdbRefHit {\n var iv: array<vec2f, ${o.maxVolumes}>;\n var lo: array<vec3f, ${o.maxVolumes}>;\n var ld: array<vec3f, ${o.maxVolumes}>;\n let n = vdbRefU.volumeCount;\n for (var i = 0u; i < n; i = i + 1u) {\n iv[i] = vdbRefInterval(i, o, d, tMax);\n let m = vdbRefU.volumes[i].worldToLocal;\n lo[i] = (m * vec4f(o, 1.0)).xyz;\n ld[i] = (m * vec4f(d, 0.0)).xyz;\n }\n var t = 0.0;\n var trans = 1.0;\n for (var step = 0u; step < VDB_REF_MAX_STEPS; step = step + 1u) {\n var sbar = 0.0;\n var tb = tMax;\n for (var i = 0u; i < n; i = i + 1u) {\n let w = iv[i];\n if (w.x <= t && t < w.y) {\n let piece = vdbRefMajorantAt(i, lo[i], ld[i], t, w.y);\n sbar = sbar + piece.x;\n tb = min(tb, piece.y);\n } else if (w.x > t && w.x <= w.y) {\n tb = min(tb, w.x);\n }\n }\n if (!(sbar > 0.0)) {\n if (tb >= tMax) {\n return VdbRefHit(true, tMax, 0u, trans);\n }\n t = tb;\n continue;\n }\n let dt = -log(1.0 - vdbRefRand()) / sbar;\n if (t + dt >= tb) {\n t = tb;\n if (t >= tMax) {\n return VdbRefHit(true, tMax, 0u, trans);\n }\n continue;\n }\n t = t + dt;\n let x = o + t * d;\n var sig: array<f32, ${o.maxVolumes}>;\n var sum = 0.0;\n for (var i = 0u; i < n; i = i + 1u) {\n let w = iv[i];\n var s = 0.0;\n if (w.x <= t && t < w.y) {\n s = vdbRefSigma(i, x);\n }\n sig[i] = s;\n sum = sum + s;\n }\n if (!ratio) {\n let u = vdbRefRand() * sbar;\n var acc = 0.0;\n for (var i = 0u; i < n; i = i + 1u) {\n let w = iv[i];\n if (!(w.x <= t && t < w.y)) {\n continue;\n }\n acc = acc + sig[i];\n if (u < acc) {\n return VdbRefHit(false, t, i, trans);\n }\n }\n } else {\n trans = trans * (1.0 - sum / sbar);\n if (trans < VDB_REF_RATIO_RR) {\n if (vdbRefRand() >= 0.5) {\n return VdbRefHit(false, t, 0u, 0.0);\n }\n trans = trans * 2.0;\n }\n }\n }\n return VdbRefHit(true, t, 0u, select(0.0, trans, ratio));\n}\n\n// ---- lights and environment (vdbRefLightAt, vdbRefEnvironmentRadiance) ----\nstruct VdbRefNee {\n ok: bool,\n dir: vec3f,\n dist: f32,\n li: vec3f,\n}\n\nfn vdbRefLightAt(k: u32, x: vec3f) -> VdbRefNee {\n let l = vdbRefU.lights[k];\n let kind = u32(l.position.w + 0.5);\n if (kind == 0u) {\n return VdbRefNee(vdbRefMax3(l.color.xyz) > 0.0, l.direction.xyz, VDB_REF_FAR, l.color.xyz);\n }\n let to = l.position.xyz - x;\n let dist = length(to);\n if (!(dist > 0.0)) {\n return VdbRefNee(false, vec3f(0.0, 1.0, 0.0), 0.0, vec3f(0.0));\n }\n let dir = to / dist;\n // falloff (extra): mode 0 none ('volume' lighting), 1 inverse square, 2 three's getDistanceAttenuation (cutoff, decay)\n let mode = u32(l.extra.x + 0.5);\n var s = 1.0;\n if (mode == 1u) {\n s = 1.0 / (dist * dist);\n } else if (mode == 2u) {\n s = 1.0 / max(pow(dist, l.extra.z), 0.01);\n if (l.extra.y > 0.0) {\n let w = clamp(1.0 - pow(dist / l.extra.y, 4.0), 0.0, 1.0);\n s = s * w * w;\n }\n }\n if (kind == 2u) {\n s = s * vdbRefSmoothstep(l.direction.w, l.color.w, -dot(dir, l.direction.xyz));\n }\n let li = l.color.xyz * s;\n return VdbRefNee(s > 0.0 && vdbRefMax3(li) > 0.0, dir, dist, li);\n}\n\n// ---- K6.R2: the equirect map's texel lookup and importance sampling (tools/reference/environment.ts) ----\nfn vdbRefEnvTexelOf(d: vec3f) -> vec2u {\n let m = vec3f(dot(vdbRefU.envRotation0.xyz, d), dot(vdbRefU.envRotation1.xyz, d), dot(vdbRefU.envRotation2.xyz, d));\n let u = atan2(m.z, m.x) / (2.0 * VDB_REF_PI) + 0.5;\n let v = asin(clamp(m.y, -1.0, 1.0)) / VDB_REF_PI + 0.5;\n let size = vec2i(vdbRefU.envSize);\n let px = clamp(i32(floor(u * f32(size.x))), 0, size.x - 1);\n let py = clamp(i32(floor((1.0 - v) * f32(size.y))), 0, size.y - 1);\n return vec2u(u32(px), u32(py));\n}\n\nfn vdbRefEnvTable(x: u32, y: u32) -> f32 {\n return textureLoad(vdbRefEnvCdf, vec2u(x, y), 0).x;\n}\n\n// the interval j with t[j] <= xi < t[j + 1] of table row 'row' (t[0 .. n])\nfn vdbRefEnvSearch(row: u32, n: u32, xi: f32) -> u32 {\n var lo = 0u;\n var hi = n;\n loop {\n if (hi - lo <= 1u) {\n break;\n }\n let mid = (lo + hi) >> 1u;\n if (vdbRefEnvTable(mid, row) <= xi) {\n lo = mid;\n } else {\n hi = mid;\n }\n }\n return lo;\n}\n\n// density per steradian of texel (x, y): P(y) P(x | y) / omega_y (vdbRefEnvTexelPdf)\nfn vdbRefEnvTexelPdf(x: u32, y: u32) -> f32 {\n let w = vdbRefU.envSize.x;\n let h = vdbRefU.envSize.y;\n let py = vdbRefEnvTable(y + 1u, h) - vdbRefEnvTable(y, h);\n let px = vdbRefEnvTable(x + 1u, y) - vdbRefEnvTable(x, y);\n let omega = vdbRefEnvTable(y, h + 4u);\n return select(0.0, py * px / max(omega, 1e-30), omega > 0.0);\n}\n\nfn vdbRefEnvPdf(d: vec3f) -> f32 {\n let t = vdbRefEnvTexelOf(d);\n return vdbRefEnvTexelPdf(t.x, t.y);\n}\n\n// sin and cos of |a| <= 2 pi to f32 precision (WGSL sin / cos are only good to 2^-11): Taylor at a / 8, three doublings\nfn vdbRefSinCos(a: f32) -> vec2f {\n let h = a * 0.125;\n let h2 = h * h;\n var s = h * (1.0 - h2 / 6.0 * (1.0 - h2 / 20.0 * (1.0 - h2 / 42.0 * (1.0 - h2 / 72.0))));\n var c = 1.0 - h2 / 2.0 * (1.0 - h2 / 12.0 * (1.0 - h2 / 30.0 * (1.0 - h2 / 56.0 * (1.0 - h2 / 90.0))));\n for (var k = 0u; k < 3u; k = k + 1u) {\n let s2 = 2.0 * s * c;\n c = c * c - s * s;\n s = s2;\n }\n return vec2f(s, c);\n}\n\nstruct VdbRefEnvSample {\n dir: vec3f,\n radiance: vec3f,\n pdf: f32,\n}\n\n// a direction from the map (vdbRefEnvSample): row, column, azimuth and sin latitude in the texel; the SAMPLED texel's\n// radiance and density\nfn vdbRefEnvSample(xi: vec4f) -> VdbRefEnvSample {\n let w = vdbRefU.envSize.x;\n let h = vdbRefU.envSize.y;\n let y = vdbRefEnvSearch(h, h, xi.x);\n let x = vdbRefEnvSearch(y, w, xi.y);\n let sc = vdbRefSinCos(2.0 * VDB_REF_PI / f32(w) * xi.z);\n let c0 = vdbRefEnvTable(x, h + 1u);\n let s0 = vdbRefEnvTable(x, h + 2u);\n let cphi = c0 * sc.y - s0 * sc.x;\n let sphi = s0 * sc.y + c0 * sc.x;\n let top = vdbRefEnvTable(y, h + 3u);\n let bottom = vdbRefEnvTable(y + 1u, h + 3u);\n let my = bottom + (top - bottom) * xi.w;\n let r = sqrt(max(0.0, 1.0 - my * my));\n let m = vec3f(r * cphi, my, r * sphi);\n // d = R^T m (the lookup applies m = R d)\n let dir = normalize(m.x * vdbRefU.envRotation0.xyz + m.y * vdbRefU.envRotation1.xyz + m.z * vdbRefU.envRotation2.xyz);\n let radiance = textureLoad(vdbRefEnvMap, vec2u(x, y), 0).xyz * vdbRefU.uniformEnv.w;\n return VdbRefEnvSample(dir, radiance, vdbRefEnvTexelPdf(x, y));\n}\n\n// K6.R2: the equirect map's part weighted by mapWeight (its MIS weight on an escape)\nfn vdbRefEnvironment(d: vec3f, mapWeight: f32) -> vec3f {\n var e = vdbRefU.uniformEnv.xyz;\n if ((vdbRefU.flags & ${VDB_REF_FLAG_SH}u) != 0u) {\n let sh = vdbRefU.sh;\n e = e + sh[0].xyz * 0.282095 + sh[1].xyz * (0.488603 * d.y) + sh[2].xyz * (0.488603 * d.z) + sh[3].xyz * (0.488603 * d.x);\n e = e + sh[4].xyz * (1.092548 * d.x * d.y) + sh[5].xyz * (1.092548 * d.y * d.z) + sh[6].xyz * (0.315392 * (3.0 * d.z * d.z - 1.0));\n e = e + sh[7].xyz * (1.092548 * d.x * d.z) + sh[8].xyz * (0.546274 * (d.x * d.x - d.y * d.y));\n }\n for (var i = 0u; i < vdbRefU.hemiCount; i = i + 1u) {\n let h = vdbRefU.hemis[i];\n e = e + select(h.ground.xyz, h.sky.xyz, dot(d, h.up.xyz) >= 0.0);\n }\n if ((vdbRefU.flags & ${VDB_REF_FLAG_EQUIRECT}u) != 0u) {\n let t = vdbRefEnvTexelOf(d);\n e = e + textureLoad(vdbRefEnvMap, t, 0).xyz * (vdbRefU.uniformEnv.w * mapWeight);\n }\n return e;\n}\n\n// ---- one sample: the state machine (mode 0 primary T, 1 path segment, 2 light visibility) ----\nfn vdbRefSample(pixel: vec2u, sampleIndex: u32) -> vec4f {\n vdbRefSeed(vdbRefU.seed, sampleIndex, pixel.y * vdbRefU.size.x + pixel.x);\n var j = vec2f(0.5, 0.5);\n if ((vdbRefU.flags & ${VDB_REF_FLAG_BOX_FILTER}u) != 0u) {\n j.x = vdbRefRand();\n j.y = vdbRefRand();\n }\n let size = vec2f(vdbRefU.size);\n let ndc = vec2f((f32(pixel.x) + j.x) / size.x * 2.0 - 1.0, (1.0 - (f32(pixel.y) + j.y) / size.y) * 2.0 - 1.0);\n let pNear = vdbRefUnproject(vec3f(ndc, 0.0));\n let pFar = vdbRefUnproject(vec3f(ndc, 1.0));\n let dv = normalize(pFar - pNear);\n var ov = vec3f(0.0);\n if ((vdbRefU.flags & ${VDB_REF_FLAG_ORTHOGRAPHIC}u) != 0u) {\n ov = vdbRefUnproject(vec3f(ndc, -1.0));\n }\n var o = (vdbRefU.cameraToWorld * vec4f(ov, 1.0)).xyz;\n var d = normalize((vdbRefU.cameraToWorld * vec4f(dv, 0.0)).xyz);\n\n var rad = vec3f(0.0);\n var beta = vec3f(1.0);\n var primaryT = 1.0;\n var mode = 0u;\n var depth = 0u;\n var lightIndex = 0u;\n var x = o;\n var vol = 0u;\n var neeDir = vec3f(0.0, 1.0, 0.0);\n var neeDist = 0.0;\n var neeLi = vec3f(0.0);\n // K6.R2: the density of the phase sampling that gave d (the escape's MIS weight)\n var phasePdf = 0.0;\n loop {\n var ro = o;\n var rd = d;\n var tMax = VDB_REF_FAR;\n if (mode == 2u) {\n ro = x;\n rd = neeDir;\n tMax = neeDist;\n }\n let hit = vdbRefTrack(ro, rd, tMax, mode != 1u);\n if (mode == 0u) {\n primaryT = hit.trans;\n mode = 1u;\n continue;\n }\n if (mode == 2u) {\n rad = rad + beta * neeLi * hit.trans;\n lightIndex = lightIndex + 1u;\n } else {\n if (hit.escaped) {\n if (depth > 0u) {\n var w = 1.0;\n if ((vdbRefU.flags & ${VDB_REF_FLAG_ENV_MIS}u) != 0u) {\n w = vdbRefMisWeight(phasePdf, vdbRefEnvPdf(d));\n }\n rad = rad + beta * vdbRefEnvironment(d, w);\n }\n break;\n }\n // a collision past the cap ends the path (the last bounce's escape still gathered the environment above)\n if (depth >= vdbRefU.maxBounces) {\n break;\n }\n depth = depth + 1u;\n vol = hit.vol;\n x = o + hit.t * d;\n let uvw = vdbRefUvw(vol, x);\n let rec = vdbRefU.volumes[vol];\n let v = rec.ids.x;\n let albedo = rec.albedo.xyz * vdbSrcAlbedo(v, uvw, 0.0);\n var le = vec3f(0.0);\n if (rec.albedo.w > 0.5) {\n let temperature = mix(rec.temperature.x, rec.temperature.y, vdbSrcEmission(v, uvw, 0.0));\n if (temperature > 0.0) {\n le = rec.emission.xyz * pow(temperature / max(rec.temperature.y, 1.0), 4.0);\n if (rec.tables.z > 0u) {\n // the blackbody colour table over log temperature (vdbRefColorTableAt): log range in temperature.zw\n let lx = (log(max(temperature, 1e-3)) - rec.temperature.z) / (rec.temperature.w - rec.temperature.z);\n le = le * vdbRefTableAt(rec.tables.z - 1u, rec.tables.w, lx).xyz;\n }\n }\n }\n rad = rad + beta * le;\n beta = beta * albedo;\n if (!(vdbRefMax3(beta) > 0.0)) {\n break;\n }\n lightIndex = 0u;\n }\n // The next light that reaches x (dark ones draw nothing), then (K6.R2) the map's NEE once (lightIndex ==\n // lightCount; its visibility pass moves lightIndex past it), else finish the collision.\n var found = false;\n loop {\n if (lightIndex < vdbRefU.lightCount) {\n let nee = vdbRefLightAt(lightIndex, x);\n if (nee.ok) {\n neeDir = nee.dir;\n neeDist = nee.dist;\n neeLi = nee.li * vdbRefPhaseEval(dot(d, nee.dir), vol);\n found = true;\n break;\n }\n lightIndex = lightIndex + 1u;\n continue;\n }\n if (lightIndex == vdbRefU.lightCount && (vdbRefU.flags & ${VDB_REF_FLAG_ENV_MIS}u) != 0u) {\n let xi0 = vdbRefRand();\n let xi1 = vdbRefRand();\n let xi2 = vdbRefRand();\n let xi3 = vdbRefRand();\n let smp = vdbRefEnvSample(vec4f(xi0, xi1, xi2, xi3));\n let c = dot(d, smp.dir);\n var k = 0.0;\n if (smp.pdf > 0.0) {\n k = vdbRefMisWeight(smp.pdf, vdbRefPhasePdf(c, vol)) / smp.pdf;\n }\n let li = smp.radiance * vdbRefPhaseEval(c, vol) * k;\n if (vdbRefMax3(li) > 0.0) {\n neeDir = smp.dir;\n neeDist = VDB_REF_FAR;\n neeLi = li;\n found = true;\n break;\n }\n }\n lightIndex = vdbRefU.lightCount + 1u;\n break;\n }\n if (found) {\n mode = 2u;\n continue;\n }\n if (depth >= vdbRefU.rrStart) {\n let q = min(vdbRefMax3(beta), 1.0);\n if (q < 1.0) {\n if (vdbRefRand() >= q) {\n break;\n }\n beta = beta / q;\n }\n }\n let rec = vdbRefU.volumes[vol];\n let ph = rec.phase;\n let lobe = vdbRefRand();\n let u1 = vdbRefRand();\n let u2 = vdbRefRand();\n var cosTheta = 0.0;\n if (rec.tables.x > 0u) {\n let ts = vdbRefPhaseTableSample(rec.tables.x - 1u, rec.tables.y, u1);\n cosTheta = ts.cosTheta;\n beta = beta * ts.weight;\n phasePdf = ts.pdf;\n } else {\n let g = select(ph.x, ph.y, ph.z > 0.0 && lobe < ph.z);\n cosTheta = vdbRefSampleHgCos(g, u1);\n // the lobe mixture is sampled exactly: its density is the phase itself\n phasePdf = vdbRefPhaseEval(cosTheta, vol).x;\n }\n d = normalize(vdbRefDirectionAround(d, cosTheta, u2));\n o = x;\n mode = 1u;\n }\n return vec4f(rad, primaryT);\n}\n\n@compute @workgroup_size(8, 8, 1)\nfn vdbRefTraceCs(@builtin(global_invocation_id) gid: vec3u) {\n if (gid.x >= vdbRefU.size.x || gid.y >= vdbRefU.size.y) {\n return;\n }\n var m = vec4f(0.0);\n for (var s = 0u; s < vdbRefU.spp; s = s + 1u) {\n m = m + vdbRefSample(gid.xy, vdbRefBatch.batch * vdbRefU.spp + s);\n }\n m = m / f32(vdbRefU.spp);\n var s0 = m;\n var s1 = m * m;\n if (vdbRefBatch.accumulate != 0u) {\n s0 = s0 + textureLoad(vdbRefAccumIn0, gid.xy, 0);\n s1 = s1 + textureLoad(vdbRefAccumIn1, gid.xy, 0);\n }\n textureStore(vdbRefAccumOut0, gid.xy, s0);\n textureStore(vdbRefAccumOut1, gid.xy, s1);\n}\n`;\n}\n"]}
|
|
@@ -76,6 +76,12 @@
|
|
|
76
76
|
*/
|
|
77
77
|
/** The part of a `VDBGridPool` the player uses. */
|
|
78
78
|
export interface VDBSequencePoolLike<TFrame = Uint32Array> {
|
|
79
|
+
/**
|
|
80
|
+
* Stages a new image for grid `id` (`VDBGridPool.replace`).
|
|
81
|
+
*
|
|
82
|
+
* @param id The grid's pool id.
|
|
83
|
+
* @param image The frame to show.
|
|
84
|
+
*/
|
|
79
85
|
replace(id: number, image: TFrame): void;
|
|
80
86
|
}
|
|
81
87
|
/**
|
|
@@ -92,7 +98,7 @@ export type VDBSequenceTarget<TFrame = Uint32Array> = {
|
|
|
92
98
|
};
|
|
93
99
|
};
|
|
94
100
|
/** Decodes one frame's URL (or index) into a frame: a NanoVDB grid image by default. */
|
|
95
|
-
export type
|
|
101
|
+
export type VDBSequenceFrameLoader<TFrame = Uint32Array> = (url: string, index: number) => Promise<TFrame>;
|
|
96
102
|
/**
|
|
97
103
|
* What playback does at the end of its range: wrap to the start (`'repeat'`), turn around (`'pingpong'`), or hold
|
|
98
104
|
* the end frame (`'once'`).
|
|
@@ -100,6 +106,7 @@ export type VDBFrameLoader<TFrame = Uint32Array> = (url: string, index: number)
|
|
|
100
106
|
export type VDBSequenceLoopMode = "once" | "repeat" | "pingpong";
|
|
101
107
|
/** An inclusive `[start, end]` frame range. */
|
|
102
108
|
export type VDBSequenceRange = readonly [start: number, end: number];
|
|
109
|
+
/** Options of {@link VDBSequence}. */
|
|
103
110
|
export interface VDBSequenceOptions<TFrame = Uint32Array> {
|
|
104
111
|
/** Per-frame source URLs: an array, or `(i) => url`. Length/`frameCount` gate playback. */
|
|
105
112
|
urls: string[] | ((index: number) => string);
|
|
@@ -125,7 +132,7 @@ export interface VDBSequenceOptions<TFrame = Uint32Array> {
|
|
|
125
132
|
* The demo passes an in-memory loader (build frames on the fly, no fetch);
|
|
126
133
|
* the URL/fetch path is exercised via a Blob-URL manifest + this default.
|
|
127
134
|
*/
|
|
128
|
-
loader?:
|
|
135
|
+
loader?: VDBSequenceFrameLoader<TFrame>;
|
|
129
136
|
/** Clock source. Default `performance.now`. Injected as a fake in tests. */
|
|
130
137
|
now?: () => number;
|
|
131
138
|
/** Fired whenever a NEW frame is shown (after its `pool.replace`). */
|
|
@@ -136,6 +143,7 @@ export interface VDBSequenceOptions<TFrame = Uint32Array> {
|
|
|
136
143
|
*/
|
|
137
144
|
onError?: (error: unknown, index: number) => void;
|
|
138
145
|
}
|
|
146
|
+
/** Playback counters read through {@link VDBSequence.stats}. */
|
|
139
147
|
export interface VDBSequenceStats {
|
|
140
148
|
/** Frame index currently shown. -1 before the first frame binds. */
|
|
141
149
|
frame: number;
|
|
@@ -162,8 +170,11 @@ export interface VDBSequenceStats {
|
|
|
162
170
|
* // per frame: sequence.update(performance.now()); pool.update(encoder); grids.update(); render
|
|
163
171
|
*/
|
|
164
172
|
export declare class VDBSequence<TFrame = Uint32Array> {
|
|
173
|
+
/** Total frames of the clip. */
|
|
165
174
|
readonly frameCount: number;
|
|
175
|
+
/** Playback rate in frames per second. */
|
|
166
176
|
readonly fps: number;
|
|
177
|
+
/** How many frames are decoded ahead of the shown one. */
|
|
167
178
|
readonly prefetch: number;
|
|
168
179
|
private _rangeStart;
|
|
169
180
|
private _rangeEnd;
|
|
@@ -202,8 +213,15 @@ export declare class VDBSequence<TFrame = Uint32Array> {
|
|
|
202
213
|
private _stalls;
|
|
203
214
|
private _replaceMs;
|
|
204
215
|
private _swaps;
|
|
216
|
+
/**
|
|
217
|
+
* Creates the player; nothing is loaded until `start`.
|
|
218
|
+
*
|
|
219
|
+
* @param opts URLs, frame count, rate, prefetch, range, loop mode, loader, clock and callbacks.
|
|
220
|
+
*/
|
|
205
221
|
constructor(opts: VDBSequenceOptions<TFrame>);
|
|
222
|
+
/** A snapshot of the playback counters. */
|
|
206
223
|
get stats(): Readonly<VDBSequenceStats>;
|
|
224
|
+
/** True while the clock is running: after `start` or `resume`, until `stop`. */
|
|
207
225
|
get isPlaying(): boolean;
|
|
208
226
|
/** Wrap a raw (possibly negative or >= frameCount) index into [0, frameCount). */
|
|
209
227
|
private wrap;
|
|
@@ -218,6 +236,9 @@ export declare class VDBSequence<TFrame = Uint32Array> {
|
|
|
218
236
|
* new range (the clock re-anchors there; a ping-pong keeps its direction); the prefetch ring is refilled in the
|
|
219
237
|
* new order.
|
|
220
238
|
*
|
|
239
|
+
* @param range Inclusive `[start, end]` frame range.
|
|
240
|
+
* @param now Clock time in ms to re-anchor at (default: the injected clock).
|
|
241
|
+
*
|
|
221
242
|
* @throws VDBError `VDB_BAD_OPTION` for a bad range; `VDB_DISPOSED` after `dispose()`.
|
|
222
243
|
*/
|
|
223
244
|
setRange(range: VDBSequenceRange, now?: number): void;
|
|
@@ -226,6 +247,9 @@ export declare class VDBSequence<TFrame = Uint32Array> {
|
|
|
226
247
|
* both the old and the new mode are `'pingpong'`, in its current direction. Switching to `'once'` at the range end
|
|
227
248
|
* holds there; switching from `'once'` held at the end to `'repeat'` or `'pingpong'` plays on.
|
|
228
249
|
*
|
|
250
|
+
* @param mode `'once'`, `'repeat'` or `'pingpong'`.
|
|
251
|
+
* @param now Clock time in ms to re-anchor at (default: the injected clock).
|
|
252
|
+
*
|
|
229
253
|
* @throws VDBError `VDB_BAD_OPTION` for an unknown mode; `VDB_DISPOSED` after `dispose()`.
|
|
230
254
|
*/
|
|
231
255
|
setLoopMode(mode: VDBSequenceLoopMode, now?: number): void;
|
|
@@ -271,6 +295,9 @@ export declare class VDBSequence<TFrame = Uint32Array> {
|
|
|
271
295
|
* to the injected clock). Call `update(now)` every animation frame thereafter.
|
|
272
296
|
* Clears the failed set (failed frames are retried).
|
|
273
297
|
*
|
|
298
|
+
* @param target Where frames go: `{ pool, id }` or `{ source }`.
|
|
299
|
+
* @param now Clock time in ms the playback is anchored at (default: the injected clock).
|
|
300
|
+
*
|
|
274
301
|
* @throws VDBError `VDB_DISPOSED` after `dispose()`; `VDB_BAD_OPTION` for a bad target.
|
|
275
302
|
*/
|
|
276
303
|
start(target: VDBSequenceTarget<TFrame>, now?: number): void;
|
|
@@ -293,6 +320,9 @@ export declare class VDBSequence<TFrame = Uint32Array> {
|
|
|
293
320
|
* Jump to `index` (wrapped into the clip, then clamped into the range), re-anchoring the clock there so playback
|
|
294
321
|
* continues from it (a ping-pong keeps its direction). Clears the failed set (failed frames are retried).
|
|
295
322
|
*
|
|
323
|
+
* @param index The frame to jump to.
|
|
324
|
+
* @param now Clock time in ms to re-anchor at (default: the injected clock).
|
|
325
|
+
*
|
|
296
326
|
* @throws VDBError `VDB_DISPOSED` after `dispose()`.
|
|
297
327
|
*/
|
|
298
328
|
seek(index: number, now?: number): void;
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
* `onError`). `start`, `seek`, `resume` and `preload` after `dispose()` throw
|
|
75
75
|
* (or reject with) `VDB_DISPOSED`; `update` returns the last frame.
|
|
76
76
|
*/
|
|
77
|
-
import { VDBError } from "
|
|
78
|
-
import { NvdbFile } from "../tools/
|
|
77
|
+
import { VDBError } from "./errors.js";
|
|
78
|
+
import { NvdbFile } from "../tools/nvdb-file.js";
|
|
79
79
|
const LOOP_MODES = ["once", "repeat", "pingpong"];
|
|
80
80
|
/** Default loader: real fetch + parse of grid 0. */
|
|
81
81
|
async function defaultLoader(url) {
|
|
@@ -94,8 +94,11 @@ async function defaultLoader(url) {
|
|
|
94
94
|
* // per frame: sequence.update(performance.now()); pool.update(encoder); grids.update(); render
|
|
95
95
|
*/
|
|
96
96
|
export class VDBSequence {
|
|
97
|
+
/** Total frames of the clip. */
|
|
97
98
|
frameCount;
|
|
99
|
+
/** Playback rate in frames per second. */
|
|
98
100
|
fps;
|
|
101
|
+
/** How many frames are decoded ahead of the shown one. */
|
|
99
102
|
prefetch;
|
|
100
103
|
_rangeStart = 0;
|
|
101
104
|
_rangeEnd = 0;
|
|
@@ -134,6 +137,11 @@ export class VDBSequence {
|
|
|
134
137
|
_stalls = 0;
|
|
135
138
|
_replaceMs = 0;
|
|
136
139
|
_swaps = 0;
|
|
140
|
+
/**
|
|
141
|
+
* Creates the player; nothing is loaded until `start`.
|
|
142
|
+
*
|
|
143
|
+
* @param opts URLs, frame count, rate, prefetch, range, loop mode, loader, clock and callbacks.
|
|
144
|
+
*/
|
|
137
145
|
constructor(opts) {
|
|
138
146
|
const frameCount = opts.frameCount ?? (Array.isArray(opts.urls) ? opts.urls.length : undefined);
|
|
139
147
|
if (frameCount === undefined || !Number.isInteger(frameCount) || frameCount < 1) {
|
|
@@ -158,6 +166,7 @@ export class VDBSequence {
|
|
|
158
166
|
this.onFrame = opts.onFrame;
|
|
159
167
|
this.onError = opts.onError;
|
|
160
168
|
}
|
|
169
|
+
/** A snapshot of the playback counters. */
|
|
161
170
|
get stats() {
|
|
162
171
|
return {
|
|
163
172
|
frame: this._frame,
|
|
@@ -168,6 +177,7 @@ export class VDBSequence {
|
|
|
168
177
|
failed: this.failed.size,
|
|
169
178
|
};
|
|
170
179
|
}
|
|
180
|
+
/** True while the clock is running: after `start` or `resume`, until `stop`. */
|
|
171
181
|
get isPlaying() {
|
|
172
182
|
return this.playing;
|
|
173
183
|
}
|
|
@@ -203,6 +213,9 @@ export class VDBSequence {
|
|
|
203
213
|
* new range (the clock re-anchors there; a ping-pong keeps its direction); the prefetch ring is refilled in the
|
|
204
214
|
* new order.
|
|
205
215
|
*
|
|
216
|
+
* @param range Inclusive `[start, end]` frame range.
|
|
217
|
+
* @param now Clock time in ms to re-anchor at (default: the injected clock).
|
|
218
|
+
*
|
|
206
219
|
* @throws VDBError `VDB_BAD_OPTION` for a bad range; `VDB_DISPOSED` after `dispose()`.
|
|
207
220
|
*/
|
|
208
221
|
setRange(range, now = this.now()) {
|
|
@@ -215,6 +228,9 @@ export class VDBSequence {
|
|
|
215
228
|
* both the old and the new mode are `'pingpong'`, in its current direction. Switching to `'once'` at the range end
|
|
216
229
|
* holds there; switching from `'once'` held at the end to `'repeat'` or `'pingpong'` plays on.
|
|
217
230
|
*
|
|
231
|
+
* @param mode `'once'`, `'repeat'` or `'pingpong'`.
|
|
232
|
+
* @param now Clock time in ms to re-anchor at (default: the injected clock).
|
|
233
|
+
*
|
|
218
234
|
* @throws VDBError `VDB_BAD_OPTION` for an unknown mode; `VDB_DISPOSED` after `dispose()`.
|
|
219
235
|
*/
|
|
220
236
|
setLoopMode(mode, now = this.now()) {
|
|
@@ -386,6 +402,9 @@ export class VDBSequence {
|
|
|
386
402
|
* to the injected clock). Call `update(now)` every animation frame thereafter.
|
|
387
403
|
* Clears the failed set (failed frames are retried).
|
|
388
404
|
*
|
|
405
|
+
* @param target Where frames go: `{ pool, id }` or `{ source }`.
|
|
406
|
+
* @param now Clock time in ms the playback is anchored at (default: the injected clock).
|
|
407
|
+
*
|
|
389
408
|
* @throws VDBError `VDB_DISPOSED` after `dispose()`; `VDB_BAD_OPTION` for a bad target.
|
|
390
409
|
*/
|
|
391
410
|
start(target, now = this.now()) {
|
|
@@ -445,6 +464,9 @@ export class VDBSequence {
|
|
|
445
464
|
* Jump to `index` (wrapped into the clip, then clamped into the range), re-anchoring the clock there so playback
|
|
446
465
|
* continues from it (a ping-pong keeps its direction). Clears the failed set (failed frames are retried).
|
|
447
466
|
*
|
|
467
|
+
* @param index The frame to jump to.
|
|
468
|
+
* @param now Clock time in ms to re-anchor at (default: the injected clock).
|
|
469
|
+
*
|
|
448
470
|
* @throws VDBError `VDB_DISPOSED` after `dispose()`.
|
|
449
471
|
*/
|
|
450
472
|
seek(index, now = this.now()) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequence.js","sourceRoot":"","sources":["../../src/core/sequence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AA+BjD,MAAM,UAAU,GAAmC,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;AA2DlF,oDAAoD;AACpD,KAAK,UAAU,aAAa,CAAC,GAAW;IACtC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,OAAO,WAAW;IACtB,gCAAgC;IACvB,UAAU,CAAS;IAC5B,0CAA0C;IACjC,GAAG,CAAS;IACrB,0DAA0D;IACjD,QAAQ,CAAS;IAElB,WAAW,GAAG,CAAC,CAAC;IAChB,SAAS,GAAG,CAAC,CAAC;IACd,SAAS,GAAwB,QAAQ,CAAC;IAClD,uFAAuF;IAC/E,IAAI,GAAW,CAAC,CAAC;IACzB,4GAA4G;IACpG,QAAQ,GAAW,CAAC,CAAC;IAEZ,MAAM,CAA4B;IAClC,MAAM,CAAiC;IACvC,SAAS,CAAU;IACnB,GAAG,CAAe;IAClB,OAAO,CAAwC;IAC/C,OAAO,CA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;QACD,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM;YAAE,OAAO;QAElC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChC,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,OAAO;QACL,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAClB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF","sourcesContent":["/**\n * `VDBSequence`: manifest-driven animated-volume playback on a `VDBGridPool`\n * (task K2.3; v1's `NanoVDBSequence`, docs/archive/v1/SPEC.md §3.5). Decodes per-frame grid\n * images ahead of time into a bounded prefetch ring and swaps the shown one\n * into ONE pool id with `pool.replace(id, image)`.\n *\n * ## The pool contract\n *\n * const id = pool.add(firstFrame, { capacity: largestFrameBytes });\n * sequence.start({ pool, id });\n * // every frame:\n * sequence.update(performance.now()); // may call pool.replace(id, frame)\n * pool.update(encoder) / pool.flush(); // writes the frame in place\n * grids.update(); // VDBGridNode: rebinds only after a growth\n * renderer.render(scene, camera);\n *\n * Reserve `capacity` for the largest frame: every `replace` then writes in\n * place (no move, no `pool.version` change, no rebind, no new bind group). A\n * frame larger than the capacity still works, but it moves the image, and the\n * next `update` may grow the pool (a `version` bump), so keep calling\n * `grids.update()` after the pool's update either way.\n *\n * **Frame arrays are held by reference.** `replace` keeps the image until the\n * `update` that writes it, and until `pool.settled()` resolves while a growth\n * is unconfirmed (the pool may have to stage it again after a rollback). The\n * player never writes into a frame array, and its ring only drops references.\n * A custom `loader` that recycles frame buffers must not reuse an array it\n * returned before `await pool.settled()` after the update that wrote it.\n *\n * ## Design for testability (the scheduler is a pure clock consumer)\n *\n * The player never owns the animation loop or reads the wall clock itself.\n * `update(now)` takes the current time in ms; the consumer calls it from its\n * own `requestAnimationFrame` loop with `performance.now()`, and tests call it\n * with a fake, hand-advanced clock. The pool is reached only through\n * `replace(id, image)`, so tests pass a stub.\n *\n * ## Stall policy: never block the render loop\n *\n * If the frame that is due hasn't finished decoding, `update()` does not wait:\n * it holds the last-shown frame, counts a stall, and returns. Decoding\n * continues in the background; the next `update()` that finds the frame ready\n * advances to wherever the clock now points (intermediate frames are dropped:\n * real-time catch-up, not slow motion).\n *\n * ## Frame range and loop mode\n *\n * `range: [start, end]` (inclusive frame indices) limits playback to those frames; the default is all of them.\n * `loopMode: 'repeat'` (default) wraps from `end` to `start`; `'pingpong'` plays forward then backward\n * (`start .. end .. start`), with each end frame shown once per turn (no doubled frame at the ends); `'once'` plays\n * to `end` and holds there. `start()` shows `range[0]`. `seek(i)` wraps `i` into the clip, then clamps it into the\n * range. `setRange()` and `setLoopMode()` change them while playing (playback continues from the shown frame,\n * clamped into the new range). The prefetch ring follows the playback order, so a swap is always a `pool.replace`\n * of a frame the ring already holds.\n *\n * **Direction.** A ping-pong keeps its direction across `stop()` / `resume()`, `seek()` and `setRange()`: paused on\n * the way back, it resumes on the way back. `start()` goes forward; `setLoopMode()` keeps the direction only when the\n * new mode is `'pingpong'` (`'repeat'` and `'once'` only go forward).\n *\n * ## Failed frames: no retry until `seek` / `start`\n *\n * A frame whose loader rejects goes into a failed set: `onError` fires once,\n * and the player does not ask the loader for it again (no retry storm from\n * the per-frame prefetch). While the clock points at it, `update()` holds the\n * last frame and counts stalls; playback moves on when the clock reaches the\n * next decodable frame. `seek()` and `start()` clear the set, so they retry\n * every failed frame (call `seek(stats.frame)` to retry in place).\n * `stats.failed` counts the frames in the set.\n *\n * ## Disposal\n *\n * `dispose()` drops the ring and the in-flight tracking and bumps a\n * generation token: decodes that finish later are dropped (no ring entry, no\n * `onError`). `start`, `seek`, `resume` and `preload` after `dispose()` throw\n * (or reject with) `VDB_DISPOSED`; `update` returns the last frame.\n */\n\nimport { VDBError } from \"./errors.js\";\nimport { NvdbFile } from \"../tools/nvdb-file.js\";\n\n/** The part of a `VDBGridPool` the player uses. */\nexport interface VDBSequencePoolLike<TFrame = Uint32Array> {\n /**\n * Stages a new image for grid `id` (`VDBGridPool.replace`).\n *\n * @param id The grid's pool id.\n * @param image The frame to show.\n */\n replace(id: number, image: TFrame): void;\n}\n\n/**\n * Where frames go: grid `id` of `pool` (added with `capacity` for the largest frame), or (K5.9) a `source` with\n * `replace(frame)`: a dense `.wvdb` source (`vdbDenseTextures`) playing `WvdbDenseVolume` frames, which a\n * `VDBFrameVolume` over it follows by itself.\n */\nexport type VDBSequenceTarget<TFrame = Uint32Array> =\n | { readonly pool: VDBSequencePoolLike<TFrame>; readonly id: number }\n | { readonly source: { replace(frame: TFrame): void } };\n\n/** Decodes one frame's URL (or index) into a frame: a NanoVDB grid image by default. */\nexport type VDBSequenceFrameLoader<TFrame = Uint32Array> = (url: string, index: number) => Promise<TFrame>;\n\n/**\n * What playback does at the end of its range: wrap to the start (`'repeat'`), turn around (`'pingpong'`), or hold\n * the end frame (`'once'`).\n */\nexport type VDBSequenceLoopMode = \"once\" | \"repeat\" | \"pingpong\";\n\nconst LOOP_MODES: readonly VDBSequenceLoopMode[] = [\"once\", \"repeat\", \"pingpong\"];\n\n/** An inclusive `[start, end]` frame range. */\nexport type VDBSequenceRange = readonly [start: number, end: number];\n\n/** Options of {@link VDBSequence}. */\nexport interface VDBSequenceOptions<TFrame = Uint32Array> {\n /** Per-frame source URLs: an array, or `(i) => url`. Length/`frameCount` gate playback. */\n urls: string[] | ((index: number) => string);\n /** Total frame count. Defaults to `urls.length` when `urls` is an array (required otherwise). */\n frameCount?: number;\n /** Playback rate. Default 24. */\n fps?: number;\n /** How many frames to decode ahead of the current one. Default 3. */\n prefetch?: number;\n /**\n * Inclusive `[start, end]` frames to play. Default `[0, frameCount - 1]` (all frames).\n * @throws VDBError `VDB_BAD_OPTION` unless both are integers with `0 <= start <= end < frameCount`.\n */\n range?: VDBSequenceRange;\n /**\n * What playback does at the range end: `'repeat'` (default) wraps to the start; `'pingpong'` plays back to the\n * start and forward again; `'once'` holds the end frame. Change it while playing with `setLoopMode()`.\n * @throws VDBError `VDB_BAD_OPTION` for any other value.\n */\n loopMode?: VDBSequenceLoopMode;\n /**\n * Decode override. Default: `NvdbFile.fromURL(url)` -> `gridImage(0)`.\n * The demo passes an in-memory loader (build frames on the fly, no fetch);\n * the URL/fetch path is exercised via a Blob-URL manifest + this default.\n */\n loader?: VDBSequenceFrameLoader<TFrame>;\n /** Clock source. Default `performance.now`. Injected as a fake in tests. */\n now?: () => number;\n /** Fired whenever a NEW frame is shown (after its `pool.replace`). */\n onFrame?: (stats: Readonly<VDBSequenceStats>) => void;\n /**\n * Fired once when a frame fails to decode. The frame is not retried until\n * `seek` or `start`; playback skips it (a stall while the clock points at it).\n */\n onError?: (error: unknown, index: number) => void;\n}\n\n/** Playback counters read through {@link VDBSequence.stats}. */\nexport interface VDBSequenceStats {\n /** Frame index currently shown. -1 before the first frame binds. */\n frame: number;\n /** Decoded-and-ready frames sitting in the ring ahead of `frame`. */\n decodedAhead: number;\n /** Cumulative count of updates that found the due frame not yet decoded. */\n stalls: number;\n /** CPU time (ms) of the last `pool.replace` (staging only; the GPU write lands in the next pool update). */\n replaceMs: number;\n /** `pool.replace` calls since `start` (the initial frame 0 included). */\n swaps: number;\n /** Frames whose decode failed and that wait for a `seek` / `start` to be retried. */\n failed: number;\n}\n\n/** Default loader: real fetch + parse of grid 0. */\nasync function defaultLoader(url: string): Promise<Uint32Array> {\n const file = await NvdbFile.fromURL(url);\n return file.gridImage(0);\n}\n\n/**\n * Plays a frame sequence into ONE pool grid: decodes frames ahead into a\n * bounded ring and `pool.replace`s the due one, driven by your clock. See the\n * file comment for the pool contract, the stall policy, failed frames and\n * disposal.\n *\n * const id = pool.add(firstFrame, { capacity: largestFrameBytes });\n * const sequence = new VDBSequence({ urls, fps: 24 });\n * sequence.start({ pool, id });\n * // per frame: sequence.update(performance.now()); pool.update(encoder); grids.update(); render\n */\nexport class VDBSequence<TFrame = Uint32Array> {\n /** Total frames of the clip. */\n readonly frameCount: number;\n /** Playback rate in frames per second. */\n readonly fps: number;\n /** How many frames are decoded ahead of the shown one. */\n readonly prefetch: number;\n\n private _rangeStart = 0;\n private _rangeEnd = 0;\n private _loopMode: VDBSequenceLoopMode = \"repeat\";\n /** Playback direction at the shown frame: +1, or -1 on the way back of a ping-pong. */\n private _dir: 1 | -1 = 1;\n /** Direction at the clock anchor (`startFrame`): -1 when it was anchored on the way back of a ping-pong. */\n private startDir: 1 | -1 = 1;\n\n private readonly urlFor: (index: number) => string;\n private readonly loader: VDBSequenceFrameLoader<TFrame>;\n private readonly hasLoader: boolean;\n private readonly now: () => number;\n private readonly onFrame: VDBSequenceOptions<TFrame>[\"onFrame\"];\n private readonly onError: VDBSequenceOptions<TFrame>[\"onError\"];\n private readonly frameDurationMs: number;\n\n /** Decoded frame images by frame index. */\n private readonly ring = new Map<number, TFrame>();\n /** In-flight decode promises by frame index (dedupe + stall detection). */\n private readonly inflight = new Map<number, Promise<void>>();\n /** Frames whose decode failed: not retried until `seek` / `start`. */\n private readonly failed = new Set<number>();\n /** Bumped by `dispose()`: a decode that finishes under an older generation is dropped. */\n private generation = 0;\n private disposed = false;\n\n private replaceFrame: ((frame: TFrame) => void) | undefined;\n /** K5.9: a frame shown by `seek` while stopped once its decode lands. */\n private pendingFrame = -1;\n /** The playback direction at `pendingFrame`. */\n private pendingDir: 1 | -1 = 1;\n /** `pendingFrame` was asked for (start / seek / a range or mode change), not made due by the clock: it survives `stop()`. */\n private pendingExplicit = false;\n private playing = false;\n private startNow = 0;\n private startFrame = 0;\n private _frame = -1;\n private _stalls = 0;\n private _replaceMs = 0;\n private _swaps = 0;\n\n /**\n * Creates the player; nothing is loaded until `start`.\n *\n * @param opts URLs, frame count, rate, prefetch, range, loop mode, loader, clock and callbacks.\n */\n constructor(opts: VDBSequenceOptions<TFrame>) {\n const frameCount = opts.frameCount ?? (Array.isArray(opts.urls) ? opts.urls.length : undefined);\n if (frameCount === undefined || !Number.isInteger(frameCount) || frameCount < 1) {\n throw new VDBError(\n \"VDB_BAD_OPTION\",\n \"VDBSequence: `frameCount` is required (a positive integer) when `urls` is a function; \" +\n \"with an array of urls it defaults to urls.length.\",\n );\n }\n this.frameCount = frameCount;\n this.fps = opts.fps ?? 24;\n if (!(this.fps > 0)) throw new VDBError(\"VDB_BAD_OPTION\", `VDBSequence: fps must be > 0 (got ${this.fps}).`);\n this.prefetch = Math.max(0, opts.prefetch ?? 3);\n this._rangeEnd = frameCount - 1;\n if (opts.range !== undefined) this.checkRange(opts.range, \"VDBSequence\");\n this._loopMode = this.checkLoopMode(opts.loopMode ?? \"repeat\", \"VDBSequence\");\n this.frameDurationMs = 1000 / this.fps;\n\n const urls = opts.urls;\n this.urlFor = typeof urls === \"function\" ? urls : (i: number): string => urls[i] ?? \"\";\n this.hasLoader = !!opts.loader;\n this.loader = opts.loader ?? (defaultLoader as unknown as VDBSequenceFrameLoader<TFrame>);\n this.now = opts.now ?? ((): number => performance.now());\n this.onFrame = opts.onFrame;\n this.onError = opts.onError;\n }\n\n /** A snapshot of the playback counters. */\n get stats(): Readonly<VDBSequenceStats> {\n return {\n frame: this._frame,\n decodedAhead: this.decodedAhead(),\n stalls: this._stalls,\n replaceMs: this._replaceMs,\n swaps: this._swaps,\n failed: this.failed.size,\n };\n }\n\n /** True while the clock is running: after `start` or `resume`, until `stop`. */\n get isPlaying(): boolean {\n return this.playing;\n }\n\n /** Wrap a raw (possibly negative or >= frameCount) index into [0, frameCount). */\n private wrap(index: number): number {\n const n = this.frameCount;\n return ((index % n) + n) % n;\n }\n\n /** The playback range, inclusive: `[0, frameCount - 1]` unless set. */\n get range(): VDBSequenceRange {\n return [this._rangeStart, this._rangeEnd];\n }\n\n /** What playback does at the range end (`'repeat'` unless set). */\n get loopMode(): VDBSequenceLoopMode {\n return this._loopMode;\n }\n\n private checkRange(range: VDBSequenceRange, who: string): void {\n const [a, b] = Array.isArray(range) ? range : [NaN, NaN];\n if (!Number.isInteger(a) || !Number.isInteger(b) || a < 0 || b < a || b >= this.frameCount) {\n throw new VDBError(\n \"VDB_BAD_OPTION\",\n `${who}: range must be [start, end] integers with 0 <= start <= end < frameCount (${this.frameCount}); got ${JSON.stringify(range)}.`,\n );\n }\n this._rangeStart = a;\n this._rangeEnd = b;\n }\n\n private checkLoopMode(mode: unknown, who: string): VDBSequenceLoopMode {\n if (!LOOP_MODES.includes(mode as VDBSequenceLoopMode)) {\n throw new VDBError(\"VDB_BAD_OPTION\", `${who}: loopMode must be 'once', 'repeat' or 'pingpong' (got ${String(mode)}).`);\n }\n return mode as VDBSequenceLoopMode;\n }\n\n /**\n * Change the playback range (inclusive). While playing, playback continues from the shown frame, clamped into the\n * new range (the clock re-anchors there; a ping-pong keeps its direction); the prefetch ring is refilled in the\n * new order.\n *\n * @param range Inclusive `[start, end]` frame range.\n * @param now Clock time in ms to re-anchor at (default: the injected clock).\n *\n * @throws VDBError `VDB_BAD_OPTION` for a bad range; `VDB_DISPOSED` after `dispose()`.\n */\n setRange(range: VDBSequenceRange, now: number = this.now()): void {\n this.assertLive(\"setRange()\");\n this.checkRange(range, \"VDBSequence.setRange\");\n this.reanchor(now);\n }\n\n /**\n * Change what playback does at the range end. Playback continues from the shown frame: going forward, or, when\n * both the old and the new mode are `'pingpong'`, in its current direction. Switching to `'once'` at the range end\n * holds there; switching from `'once'` held at the end to `'repeat'` or `'pingpong'` plays on.\n *\n * @param mode `'once'`, `'repeat'` or `'pingpong'`.\n * @param now Clock time in ms to re-anchor at (default: the injected clock).\n *\n * @throws VDBError `VDB_BAD_OPTION` for an unknown mode; `VDB_DISPOSED` after `dispose()`.\n */\n setLoopMode(mode: VDBSequenceLoopMode, now: number = this.now()): void {\n this.assertLive(\"setLoopMode()\");\n this._loopMode = this.checkLoopMode(mode, \"VDBSequence.setLoopMode\");\n if (this._loopMode !== \"pingpong\") this._dir = 1;\n this.reanchor(now);\n }\n\n /** Re-anchor the clock at the shown frame (clamped into the range) after a range or mode change. */\n private reanchor(now: number): void {\n this.anchor(this._frame < 0 ? this._rangeStart : this._frame, this._dir, now);\n if (!this.replaceFrame) return;\n this.ensurePrefetch(this.startFrame, this.startDir);\n if (this._frame < 0 || this._frame !== this.startFrame) this.showFrame(this.startFrame, this.startDir, true);\n }\n\n /** Anchor the clock at `frame` (clamped into the range) heading `dir` (forward unless ping-ponging) at `now`. */\n private anchor(frame: number, dir: 1 | -1, now: number): void {\n this.startNow = now;\n this.startFrame = this.clampToRange(frame);\n this.startDir = this._loopMode === \"pingpong\" ? dir : 1;\n }\n\n private clampToRange(index: number): number {\n return Math.min(this._rangeEnd, Math.max(this._rangeStart, index));\n }\n\n /** The frame `steps` after `from` (absolute index) heading `dir`, with the direction there. */\n private stepFrom(from: number, dir: 1 | -1, steps: number): { frame: number; dir: 1 | -1 } {\n let frame = this.clampToRange(from);\n let d = dir;\n for (let k = 0; k < steps; k++) {\n let next = frame + d;\n if (next > this._rangeEnd || next < this._rangeStart) {\n if (this._loopMode === \"once\") break;\n if (this._loopMode === \"pingpong\" && this._rangeEnd > this._rangeStart) {\n d = d === 1 ? -1 : 1;\n next = frame + d;\n } else {\n next = d === 1 ? this._rangeStart : this._rangeEnd;\n }\n }\n frame = next;\n }\n return { frame, dir: d };\n }\n\n /**\n * The frame the clock points at `advanced` frames after the anchor, and the direction there.\n *\n * A ping-pong over `len` frames is a cycle of `period = 2 (len - 1)` steps: phase `q` in `[0, len - 1]` is frame\n * `rs + q` on the way out, phase `q` in `(len - 1, period)` is frame `rs + period - q` on the way back. An anchor\n * at offset `o = startFrame - rs` heading forward sits at phase `o`, heading back at phase `period - o` (the two\n * agree at the ends: `o = len - 1` gives `len - 1` either way, `o = 0` gives 0 or `period`, the same phase).\n */\n private frameAt(advanced: number): { frame: number; dir: 1 | -1 } {\n const rs = this._rangeStart;\n const len = this._rangeEnd - rs + 1;\n const o = this.clampToRange(this.startFrame) - rs;\n if (len === 1) return { frame: rs, dir: 1 };\n if (this._loopMode === \"once\") return { frame: rs + Math.min(o + advanced, len - 1), dir: 1 };\n if (this._loopMode === \"repeat\") return { frame: rs + ((o + advanced) % len), dir: 1 };\n const period = 2 * (len - 1);\n const q = ((this.startDir === 1 ? o : period - o) + advanced) % period;\n return { frame: rs + (q < len ? q : period - q), dir: q < len - 1 ? 1 : -1 };\n }\n\n /**\n * Ensure the frames `[from .. from+prefetch]` in playback order (wrapping or turning around in the range when\n * looping) are decoding or decoded, and evict frames outside that window to bound memory.\n */\n private ensurePrefetch(from: number, dir: 1 | -1): void {\n const want = new Set<number>();\n const first = this.clampToRange(from);\n for (let k = 0; k <= this.prefetch; k++) want.add(this.stepFrom(first, dir, k).frame);\n // Keep the current frame available for hold-last-frame even if it slipped\n // out of the forward window (prefetch 0 edge case).\n if (this._frame >= 0) want.add(this._frame);\n\n for (const index of want) this.decodeFrame(index);\n\n // Evict decoded frames we no longer want ahead of us.\n for (const index of [...this.ring.keys()]) {\n if (!want.has(index)) this.ring.delete(index);\n }\n }\n\n /**\n * Start (or return) the decode of one frame; resolves into the ring. A\n * failed frame is not retried (see the file comment); a decode that settles\n * after `dispose()` is dropped.\n */\n private decodeFrame(index: number): Promise<void> {\n if (this.ring.has(index) || this.failed.has(index)) return Promise.resolve();\n const existing = this.inflight.get(index);\n if (existing) return existing;\n\n const generation = this.generation;\n const current = (): boolean => generation === this.generation;\n let load: Promise<TFrame>;\n try {\n load = Promise.resolve(this.loader(this.urlFor(index), index));\n } catch (err) {\n load = Promise.reject(err);\n }\n const p = load\n .then((image) => {\n if (!current()) return;\n this.ring.set(index, image);\n if (index === this.pendingFrame && !this.playing) this.showFrame(index, this.pendingDir);\n })\n .catch((err) => {\n if (!current()) return;\n this.failed.add(index);\n this.onError?.(err, index);\n })\n .finally(() => {\n if (current()) this.inflight.delete(index);\n });\n this.inflight.set(index, p);\n return p;\n }\n\n private assertLive(what: string): void {\n if (this.disposed) throw new VDBError(\"VDB_DISPOSED\", `VDBSequence: ${what} after dispose(). Create a new VDBSequence.`);\n }\n\n private decodedAhead(): number {\n if (this._frame < 0) return this.ring.size;\n let count = 0;\n const seen = new Set<number>([this._frame]);\n for (let k = 1; k <= this.prefetch; k++) {\n const next = this.stepFrom(this._frame, this._dir, k).frame;\n if (seen.has(next)) continue;\n seen.add(next);\n if (this.ring.has(next)) count++;\n }\n return count;\n }\n\n /**\n * Decode the first `count` frames of the range (in playback order) and resolve once all are ready. Useful for\n * a deterministic warm start (the demo's `?test=1` awaits this so playback has\n * zero stalls). Does not start playback.\n */\n async preload(count = Math.min(this.frameCount, this.prefetch + 1)): Promise<void> {\n this.assertLive(\"preload()\");\n const n = Math.min(count, this._rangeEnd - this._rangeStart + 1);\n const ps: Promise<void>[] = [];\n for (let i = 0; i < n; i++) ps.push(this.decodeFrame(this.stepFrom(this._rangeStart, 1, i).frame));\n await Promise.all(ps);\n }\n\n /**\n * Begin playback into grid `target.id` of `target.pool`. Replaces it with\n * the first frame of the range (frame 0 by default) at once if that is decoded (else the first `update` that finds it\n * ready does), kicks off prefetch, and anchors the clock at `now` (defaults\n * to the injected clock). Call `update(now)` every animation frame thereafter.\n * Clears the failed set (failed frames are retried).\n *\n * @param target Where frames go: `{ pool, id }` or `{ source }`.\n * @param now Clock time in ms the playback is anchored at (default: the injected clock).\n *\n * @throws VDBError `VDB_DISPOSED` after `dispose()`; `VDB_BAD_OPTION` for a bad target.\n */\n start(target: VDBSequenceTarget<TFrame>, now: number = this.now()): void {\n this.assertLive(\"start()\");\n const t = target as { pool?: { replace?: unknown }; id?: unknown; source?: { replace?: unknown } } | null;\n if (t !== null && typeof t === \"object\" && !(\"pool\" in t) && typeof t.source?.replace === \"function\") {\n if (!this.hasLoader) throw new VDBError(\"VDB_BAD_OPTION\", \"VDBSequence.start: a { source } target plays the frames your loader returns; pass a loader (the default decodes .nvdb images).\");\n const source = t.source as { replace(frame: TFrame): void };\n this.replaceFrame = (frame) => source.replace(frame);\n } else if (t === null || typeof t !== \"object\" || typeof t.pool?.replace !== \"function\" || !Number.isInteger(t.id) || (t.id as number) < 0) {\n throw new VDBError(\n \"VDB_BAD_OPTION\",\n \"VDBSequence.start: target must be { pool, id } with a VDBGridPool (or an object with replace(id, image)) and a non-negative grid id, or { source } with replace(frame).\");\n } else {\n const { pool, id } = target as { pool: VDBSequencePoolLike<TFrame>; id: number };\n this.replaceFrame = (frame) => pool.replace(id, frame);\n }\n this.playing = true;\n this._dir = 1;\n this.anchor(this._rangeStart, 1, now);\n this._frame = -1;\n this._stalls = 0;\n this._replaceMs = 0;\n this._swaps = 0;\n this.failed.clear();\n this.ensurePrefetch(this._rangeStart, 1);\n this.showFrame(this._rangeStart, 1, true);\n }\n\n /**\n * Stop playback. The ring is preserved so `start`/`resume`/`seek` can resume cheaply. A frame the clock made due\n * that is still decoding does not land after `stop()`; a frame asked for by `start`, `seek`, `setRange` or\n * `setLoopMode` (before or after the stop) is shown when its decode lands.\n */\n stop(): void {\n this.playing = false;\n if (!this.pendingExplicit) this.pendingFrame = -1;\n }\n\n /**\n * Resume after `stop()` WITHOUT resetting to frame 0 or clearing stats:\n * re-anchors the clock at `now` from the currently-shown frame so playback\n * continues from where it paused (a ping-pong in the direction it was going).\n * No-op if `start()` was never called.\n *\n * @throws VDBError `VDB_DISPOSED` after `dispose()`.\n */\n resume(now: number = this.now()): void {\n this.assertLive(\"resume()\");\n if (!this.replaceFrame) return;\n this.playing = true;\n this.anchor(this._frame < 0 ? this._rangeStart : this._frame, this._dir, now);\n this.ensurePrefetch(this.startFrame, this.startDir);\n }\n\n /**\n * Jump to `index` (wrapped into the clip, then clamped into the range), re-anchoring the clock there so playback\n * continues from it (a ping-pong keeps its direction). Clears the failed set (failed frames are retried).\n *\n * @param index The frame to jump to.\n * @param now Clock time in ms to re-anchor at (default: the injected clock).\n *\n * @throws VDBError `VDB_DISPOSED` after `dispose()`.\n */\n seek(index: number, now: number = this.now()): void {\n this.assertLive(\"seek()\");\n this.failed.clear();\n this.anchor(this.wrap(Math.trunc(index)), this._dir, now);\n this.ensurePrefetch(this.startFrame, this.startDir);\n this.showFrame(this.startFrame, this.startDir, true);\n }\n\n /**\n * Advance the scheduler to time `now`. Replaces the grid with the frame the\n * clock points at if it is decoded; otherwise holds the last frame and counts\n * a stall. Never blocks. Returns the frame index currently shown.\n */\n update(now: number): number {\n if (!this.playing || !this.replaceFrame) return this._frame;\n\n const elapsed = now - this.startNow;\n const advanced = Math.floor(elapsed / this.frameDurationMs);\n const { frame: target, dir } = this.frameAt(advanced);\n\n if (target === this._frame) {\n // Same frame is due; just keep prefetch warm.\n this._dir = dir;\n this.pendingFrame = -1;\n this.ensurePrefetch(target, dir);\n return this._frame;\n }\n\n this.showFrame(target, dir);\n return this._frame;\n }\n\n /**\n * Show `index` (playback heading `dir` there) if decoded (`pool.replace`, counts a swap, fires `onFrame`,\n * advances prefetch); otherwise count a stall and hold. Shared by start/seek/update.\n */\n private showFrame(index: number, dir: 1 | -1, explicit = false): void {\n if (!this.replaceFrame) return;\n const image = this.ring.get(index);\n if (image === undefined) {\n // Not decoded yet: hold the last frame, count a stall, keep decoding (a stopped player shows an explicit\n // request, start / seek / a range or mode change, when it lands).\n if (this._frame !== index) this._stalls++;\n this.pendingFrame = index;\n this.pendingDir = dir;\n this.pendingExplicit = explicit;\n this.ensurePrefetch(index, dir);\n return;\n }\n this.pendingFrame = -1;\n this._dir = dir;\n if (index === this._frame) return;\n\n const t0 = this.now();\n this.replaceFrame(image);\n this._replaceMs = this.now() - t0;\n this._frame = index;\n this._swaps++;\n this.ensurePrefetch(index, dir);\n this.onFrame?.(this.stats);\n }\n\n /**\n * Stops playback and drops all decoded frames and in-flight tracking; later\n * decodes are dropped when they settle. The pool keeps the grid (and the\n * frame it shows). Further `start` / `seek` / `resume` / `preload` throw\n * `VDB_DISPOSED`. Idempotent.\n */\n dispose(): void {\n this.disposed = true;\n this.generation++;\n this.playing = false;\n this.replaceFrame = undefined;\n this.pendingFrame = -1;\n this.ring.clear();\n this.inflight.clear();\n this.failed.clear();\n }\n}\n"]}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* K3.2f: the brick cache of the core sparse source (`vdbSparseSource`, internal option `brickCache`; design in
|
|
3
|
+
* docs/archive/handoffs/K3-2d.md, built and measured in K3-2f.md). CPU side and twins: `tools/frame/brick-cache.ts`.
|
|
4
|
+
*
|
|
5
|
+
* The level-0 density samples of a sparse source read the tree: 8 lower-node lookups and value decodes per sample
|
|
6
|
+
* (K3.2d). The cache decodes the 8³ blocks the frames touch into a dense atlas of 9³ bricks (the block plus a
|
|
7
|
+
* +x/+y/+z apron, so the 8 taps of every sample based in the block sit in one brick) and keeps a page table:
|
|
8
|
+
*
|
|
9
|
+
* - **Pages buffer** (storage, read): a header of 4 words per volume slot (first page, pages per axis; first page
|
|
10
|
+
* `0xffffffff` = no pages, the volume reads the tree), then one word per page: 0 = not resident, else brick slot + 1.
|
|
11
|
+
* - **Marks buffer** (storage, read_write): one bit per page, set by the sampler on every page it reads (resident or
|
|
12
|
+
* not). `update()` copies it into a readback buffer and clears it; once mapped, {@link VDBBrickResidency} gives the
|
|
13
|
+
* marked pages without a brick a slot (least recently marked out first) and the next `update()` records the fills.
|
|
14
|
+
* - **Atlas**: `'f32'`: r32float, filled through a storage texture, sampled with 8 `textureLoad`s and the vendored
|
|
15
|
+
* lerp order: bit-identical to the tree sampler. `'f16'`: r16float (core WebGPU has no r16float storage texture:
|
|
16
|
+
* f16 words in a staging buffer, then one `copyBufferToTexture` per brick), sampled with ONE hardware-filtered fetch;
|
|
17
|
+
* not identical (f16 values, quantized filter weights on some GPUs): the bound is `vdbBrickHalfBound`.
|
|
18
|
+
*
|
|
19
|
+
* A page that is not resident is a miss: the sampler reads the tree, so the f32 cache is exact from the first frame
|
|
20
|
+
* and only gets faster; a page marked in frame k is resident from about frame k + 2 (the marks' readback latency).
|
|
21
|
+
* An image change (`imageRevision`) drops the volume's bricks; a layout change (volumes added, removed or re-laid
|
|
22
|
+
* out) keeps the bricks of volumes whose page range is unchanged.
|
|
23
|
+
*/
|
|
24
|
+
import type { VDBGridPool } from "../pool/pool.js";
|
|
25
|
+
import type { VDBGridTypeName } from "../types.js";
|
|
26
|
+
import { type VDBBrickKernels, type VDBBrickPageLayout } from "../../tools/frame/brick-cache.js";
|
|
27
|
+
/** The atlas format of the cache. */
|
|
28
|
+
export type VDBSparseBrickMode = "f32" | "f16";
|
|
29
|
+
/** Internal options of the brick cache (`VDBSparseSourceInternalOptions`). */
|
|
30
|
+
export interface VDBSparseBrickOptions {
|
|
31
|
+
/** `'f32'` (bit-identical to the tree) or `'f16'` (one filtered fetch; bounded). */
|
|
32
|
+
readonly mode: VDBSparseBrickMode;
|
|
33
|
+
/** Most bricks the atlas may hold (default: what fits in 64 MiB of atlas, rows padded to 256 bytes). */
|
|
34
|
+
readonly capacity?: number;
|
|
35
|
+
/** Most bricks filled per `update()` (default 1024 for f32, 256 for f16: its staging is 20.25 KiB a brick). */
|
|
36
|
+
readonly budget?: number;
|
|
37
|
+
/** Most pages over all volumes; volumes past it read the tree (default 2²², 16 MiB of page table). */
|
|
38
|
+
readonly pagesMax?: number;
|
|
39
|
+
/** K3.2f-e: which kernels' marks take bricks (`'all'`, default; else the gather's only). */
|
|
40
|
+
readonly kernels?: VDBBrickKernels;
|
|
41
|
+
/** K3.2f-e: one marks section per kernel, counted per kernel (`kernelMarks`). Default false (one section). */
|
|
42
|
+
readonly markStats?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** K3.2f-e: one kernel's marks in the last applied observation (with `brickMarkStats`). */
|
|
45
|
+
export interface VDBSparseBrickKernelCounters {
|
|
46
|
+
/** Pages it marked (read at level 0) in the window. */
|
|
47
|
+
readonly marked: number;
|
|
48
|
+
/**
|
|
49
|
+
* The most pages it marked in any one observation so far: its working set when it runs (the 'frame' grid density
|
|
50
|
+
* and emission passes run only when their grids are redrawn, so the last window may hold none of their marks).
|
|
51
|
+
*/
|
|
52
|
+
readonly markedPeak: number;
|
|
53
|
+
/** Of those, pages without a brick when the observation was applied (it read the tree there). */
|
|
54
|
+
readonly misses: number;
|
|
55
|
+
/** Pages no other kernel marked in the window. */
|
|
56
|
+
readonly only: number;
|
|
57
|
+
/** Of its marked pages, the ones given a brick by this observation; and the total over all observations. */
|
|
58
|
+
readonly fillsLast: number;
|
|
59
|
+
readonly fills: number;
|
|
60
|
+
}
|
|
61
|
+
/** K3.2f-e: the marks per kernel (with `brickMarkStats`; null without). */
|
|
62
|
+
export interface VDBSparseBrickKernelMarks {
|
|
63
|
+
/** Pages any kernel marked in the window, and the most in any one observation so far. */
|
|
64
|
+
readonly union: number;
|
|
65
|
+
readonly unionPeak: number;
|
|
66
|
+
readonly gather: VDBSparseBrickKernelCounters;
|
|
67
|
+
readonly grid: VDBSparseBrickKernelCounters;
|
|
68
|
+
readonly emission: VDBSparseBrickKernelCounters;
|
|
69
|
+
}
|
|
70
|
+
/** What the cache did (K3.2f counters; `vdbSparseBrickCacheInfo`). */
|
|
71
|
+
export interface VDBSparseBrickCounters {
|
|
72
|
+
readonly mode: VDBSparseBrickMode;
|
|
73
|
+
/** Atlas slots now (grows by layers up to `capacityMax`). */
|
|
74
|
+
readonly capacity: number;
|
|
75
|
+
readonly capacityMax: number;
|
|
76
|
+
/** Pages over all volumes, and the volumes that have none (past `pagesMax`). */
|
|
77
|
+
readonly pages: number;
|
|
78
|
+
readonly volumesWithoutPages: number;
|
|
79
|
+
/** Pages with a brick. */
|
|
80
|
+
readonly resident: number;
|
|
81
|
+
/** The last observation: pages the sampler marked, marked pages without a brick, misses left without one. */
|
|
82
|
+
readonly marked: number;
|
|
83
|
+
readonly misses: number;
|
|
84
|
+
readonly overflow: number;
|
|
85
|
+
/** Totals: bricks filled, bricks evicted, observations applied, bricks dropped by image or layout changes. */
|
|
86
|
+
readonly fills: number;
|
|
87
|
+
readonly fillsLast: number;
|
|
88
|
+
readonly evictions: number;
|
|
89
|
+
readonly observations: number;
|
|
90
|
+
readonly dropped: number;
|
|
91
|
+
/** GPU bytes the cache allocated. */
|
|
92
|
+
readonly bytes: {
|
|
93
|
+
readonly atlas: number;
|
|
94
|
+
readonly pages: number;
|
|
95
|
+
readonly marks: number;
|
|
96
|
+
readonly staging: number;
|
|
97
|
+
readonly readback: number;
|
|
98
|
+
readonly jobs: number;
|
|
99
|
+
};
|
|
100
|
+
/** K3.2f-e: which kernels' marks take bricks, and the marks per kernel (null without `brickMarkStats`). */
|
|
101
|
+
readonly kernels: VDBBrickKernels;
|
|
102
|
+
readonly kernelMarks: VDBSparseBrickKernelMarks | null;
|
|
103
|
+
}
|
|
104
|
+
/** The fill kernels: one workgroup per brick, the 9³ tree values through `vdbReadValue` (twin `vdbBrickFillCpu`). */
|
|
105
|
+
export declare function vdbBrickFillWgsl(mode: VDBSparseBrickMode, types: readonly VDBGridTypeName[]): string;
|
|
106
|
+
/** A volume of the source, as the cache sees it. */
|
|
107
|
+
export interface VDBBrickVolume {
|
|
108
|
+
readonly v: number;
|
|
109
|
+
readonly removed: boolean;
|
|
110
|
+
readonly ids: {
|
|
111
|
+
readonly density: number;
|
|
112
|
+
};
|
|
113
|
+
readonly indexBox: {
|
|
114
|
+
readonly min: readonly number[];
|
|
115
|
+
readonly max: readonly number[];
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** The cache of one sparse source (owned by it; see the file comment). */
|
|
119
|
+
export declare class VDBSparseBrickCache {
|
|
120
|
+
#private;
|
|
121
|
+
readonly mode: VDBSparseBrickMode;
|
|
122
|
+
constructor(device: GPUDevice, pool: VDBGridPool, o: VDBSparseBrickOptions & {
|
|
123
|
+
types: readonly VDBGridTypeName[];
|
|
124
|
+
maxVolumes: number;
|
|
125
|
+
label: string;
|
|
126
|
+
}, hooks: {
|
|
127
|
+
retire: (destroy: () => void) => void;
|
|
128
|
+
rebind: () => void;
|
|
129
|
+
});
|
|
130
|
+
/** The atlas (for probes and readbacks). */
|
|
131
|
+
get atlas(): GPUTexture;
|
|
132
|
+
/** Pages buffer words before the first page entry (the per-volume header). */
|
|
133
|
+
get headerWords(): number;
|
|
134
|
+
/** The CPU mirror of the pages buffer (header, then entries), for tests. */
|
|
135
|
+
get table(): Uint32Array;
|
|
136
|
+
/** The page layout of a volume slot and its first page (-1: no pages), for tests and probes. */
|
|
137
|
+
region(v: number): {
|
|
138
|
+
base: number;
|
|
139
|
+
layout: VDBBrickPageLayout;
|
|
140
|
+
gridId: number;
|
|
141
|
+
} | null;
|
|
142
|
+
get counters(): VDBSparseBrickCounters;
|
|
143
|
+
/** Re-lays the page ranges out over `volumes` (slot order); keeps the bricks of unchanged ranges. */
|
|
144
|
+
layout(volumes: readonly VDBBrickVolume[]): void;
|
|
145
|
+
/**
|
|
146
|
+
* One update (after the pool's, in the same encoder): drops the bricks of changed images, applies the last marks
|
|
147
|
+
* (allocations, evictions, fills recorded into `encoder`), writes the page table, and copies this window's marks out.
|
|
148
|
+
*/
|
|
149
|
+
update(encoder: GPUCommandEncoder): void;
|
|
150
|
+
/** Resolves when the marks readback in flight has landed. */
|
|
151
|
+
settled(): Promise<void>;
|
|
152
|
+
layoutEntries(b: {
|
|
153
|
+
pages: number;
|
|
154
|
+
marks: number;
|
|
155
|
+
atlas: number;
|
|
156
|
+
sampler: number | null;
|
|
157
|
+
}, visibility: GPUShaderStageFlags): GPUBindGroupLayoutEntry[];
|
|
158
|
+
bindEntries(b: {
|
|
159
|
+
pages: number;
|
|
160
|
+
marks: number;
|
|
161
|
+
atlas: number;
|
|
162
|
+
sampler: number | null;
|
|
163
|
+
}): GPUBindGroupEntry[];
|
|
164
|
+
dispose(): void;
|
|
165
|
+
}
|