@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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,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAE,CAAC,MAAM,CAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAC9M,QAAQ;;;;EAIR,2BAA2B,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;EAC5G,iBAAiB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+DA6FqB,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqJxF,MAAM;EACN,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;EAyBP,UAAU;;;;EAIV,KAAK;;CAEN,CAAC;AACF,CAAC","sourcesContent":["// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):\n// src/three-openvdb/frame/webgpu/FrameInjectMaterial.js L142–284 (froxel pre-integration, the shadow\n// march), L395–398 (ambient and light probe), L453–532 (hemisphere and scene lights, radiance,\n// premultiplied output); src/three-openvdb/frame/webgpu/frameShaderChunks.js L894–1017 (wrapUv, gridUv,\n// sampleExtinction, sampleAlbedo, sampleEmission).\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: one compute thread per froxel loops the volumes of a source group (his: one blended draw per\n// volume); the shadow march is one function called from one loop over the hemisphere and scene lights\n// (two density call sites per kernel); the light terms are loops over uniform counts (V55's compiled-in\n// sets go away); overlapping volumes mix order-independently by default ('mixture'); multi-group frames\n// accumulate in packed partials; the environment (K6.2b) reads the GPU environment buffer (its lights, or the\n// 'outward' SH irradiance instead of three's PMREM); K6.3: octaves, two-sided (L270–277, L488–512) and the Lorenz-Mie\n// phases (a LUT in group 0); spectral: K6.4. Divergences: DIVERGES.md (K6.1 rows).\n\n/**\n * `vdbFrameGatherCs`: the 'volume'-lighting gather kernel (design §3.3, §3.4). One thread per froxel of\n * the dispatch box (the union of this frame's froxel area and what the scatter texture last held):\n * outside this frame's area it writes 0; inside it lights every volume of its source group in the froxel\n * (his inject pass) and combines them (order-independently: sums of optical depth and depth-weighted radiance). CPU twins: tools/frame `vdbFrameInjectSlice`,\n * `vdbFrameShadowMarch`, `vdbFrameShadowedLightColor`, `vdbFrameGatherFroxel`.\n */\n\nimport type { VDBVolumeChannels } from \"../../source/types.js\";\nimport { frameChunksWgsl } from \"./chunks.js\";\nimport { vdbFrameEmissionColorWgsl } from \"./emission.js\";\nimport { vdbFrameOccluderWgsl } from \"./occluders.js\";\nimport { VDB_FRAME_AMBIENT_MAX_PAIRS } from \"../../../tools/frame/ambient.js\";\n\n/** Pipeline-key options of the gather kernel. */\nexport interface VDBFrameGatherOptions {\n /** More than one source group this frame: accumulate in the packed r32uint partials (design §3.2). */\n readonly multi: boolean;\n /** The source's channels (absent ones compile to constants). */\n readonly channels: VDBVolumeChannels;\n /** K6.5: a validated user emission colour hook (WGSL), or none. */\n readonly hook?: string | null;\n /** K6.4: spectral media (per-channel extinction, albedo, multiple scattering; the second scatter texture). */\n readonly spectral?: boolean;\n /** Issue #2 step 2: the stochastic density filter in the slice march (V182). */\n readonly stochastic?: boolean;\n}\n\n/** Group-1 bindings of the gather kernel (K6.4: `scatterAlpha` with spectral). */\nexport const GATHER_BINDINGS = { volumes: 0, group: 1, scatter: 2, partials: 3, emissionLut: 4, scatterAlpha: 5 } as const;\n\n/** K6.4: words per froxel of the 'volume' gather's multi-group partials (grey 2: Σ τL rgb, Σ τ; spectral 3: rgb each). */\nexport const VDB_FRAME_GATHER_WORDS = { grey: 2, spectral: 3 } as const;\n\n/**\n * The volume-record functions every source kernel shares (gather 'volume' and 'frame', gridDensity): his gridUv,\n * sampleExtinction, sampleAlbedo and sampleEmission over the group-2 source, reading `vdbFrameVolumes` (group 1).\n */\nexport function vdbFrameSourceFunctionsWgsl(channels: VDBVolumeChannels, color: { lutBinding: number | null; hook: string | null } = { lutBinding: null, hook: null }, stochastic = false): string {\n // K6.5: the colour is the volume's (march.w: white, a LUT row or the user hook; core/frame/wgsl/emission.ts)\n const emission = channels.emission\n ? ` let e = vdbFrameVolumes.v[vi].emission;\n let value = vdbSrcEmission(vdbFrameVolumes.v[vi].slices.z, vdbFrameGridUv(vi, localPosition), lod);\n let temperature = mix(e.y, e.z, value);\n let power = pow(temperature / max(e.z, 1.0), 4.0);\n let color = vdbFrameEmissionColor(vdbFrameVolumes.v[vi].march.w, value, temperature);\n return select(vec3f(0.0), color, temperature > 0.0) * power * e.x;`\n : ` return vec3f(0.0);`;\n return `${channels.emission ? vdbFrameEmissionColorWgsl(color) : \"\"}fn vdbFrameMirror(x: f32) -> f32 {\n let period = x - 2.0 * floor(x / 2.0);\n return select(period, 2.0 - period, period > 1.0);\n}\n// gridUv: the local position as an offset, wrapped uvw (wrap 0 clamp, 1 repeat, 2 mirrored repeat)\nfn vdbFrameGridUv(vi: u32, localPosition: vec3f) -> vec3f {\n let offsetWrap = vdbFrameVolumes.v[vi].offsetWrap;\n let uvw = localPosition + 0.5 + offsetWrap.xyz;\n if (offsetWrap.w > 1.5) {\n return vec3f(vdbFrameMirror(uvw.x), vdbFrameMirror(uvw.y), vdbFrameMirror(uvw.z));\n }\n if (offsetWrap.w > 0.5) {\n return fract(uvw);\n }\n return uvw;\n}\n// sampleExtinction: extinction per world unit (the mask is read at local + 0.5, no offset or wrap)\nfn vdbFrameExtinction(vi: u32, localPosition: vec3f, lod: f32) -> f32 {\n let v = vdbFrameVolumes.v[vi].slices.z;\n let mask = vdbSrcMask(v, localPosition + 0.5, lod);\n let value = vdbSrcDensity(v, vdbFrameGridUv(vi, localPosition), lod) * mask;\n let d = vdbFrameVolumes.v[vi].density;\n return select(0.0, value, value > d.y) * d.x * vdbFrameVolumes.v[vi].baseExtinction.w / d.z;\n}${\n stochastic\n ? `\n// Issue #2 step 2: sampleExtinction with the stochastic density filter (one voxel picked by xi at lod 0; V182)\nfn vdbFrameExtinctionStochastic(vi: u32, localPosition: vec3f, lod: f32, xi: vec3f) -> f32 {\n let v = vdbFrameVolumes.v[vi].slices.z;\n let mask = vdbSrcMask(v, localPosition + 0.5, lod);\n let value = vdbSrcDensityStochastic(v, vdbFrameGridUv(vi, localPosition), lod, xi) * mask;\n let d = vdbFrameVolumes.v[vi].density;\n return select(0.0, value, value > d.y) * d.x * vdbFrameVolumes.v[vi].baseExtinction.w / d.z;\n}`\n : \"\"\n }\n// sampleAlbedo: base colour times the albedo channel\nfn vdbFrameAlbedo(vi: u32, localPosition: vec3f, lod: f32) -> vec3f {\n return vdbFrameVolumes.v[vi].baseExtinction.xyz * vdbSrcAlbedo(vdbFrameVolumes.v[vi].slices.z, vdbFrameGridUv(vi, localPosition), lod);\n}\n// sampleEmission: the volume's emission colour (K6.5) x (temperature / max)^4 x intensity\nfn vdbFrameEmission(vi: u32, localPosition: vec3f, lod: f32) -> vec3f {\n${emission}\n}\n`;\n}\n\n/**\n * The slice pre-integration of one volume in one froxel (his inject / density passes, L142–200): the box segment,\n * the sub-steps at the froxel lod and the visibility-weighted mean position. Shared by the 'volume' and 'frame'\n * gathers (one density call site). K6.4 `spectral`: the transmittance of each channel (the volume's extinction\n * spectrum); the visible position weighs the channel mean (his frameMeanComponent); `alpha3` holds each channel's alpha\n * and `alpha` the largest.\n */\nexport function vdbFrameSliceWgsl(spectral = false, stochastic = false): string {\n // Issue #2 step 2: the stochastic density filter reads one voxel per sub-step (three uniforms per lookup)\n const extinction = stochastic\n ? \"vdbFrameExtinctionStochastic(vi, mix(s.localNear, s.localFar, vec3f(t)), s.readLod, vdbFrameRand3(f.fragCoord, (vi << 16u) | i))\"\n : \"vdbFrameExtinction(vi, mix(s.localNear, s.localFar, vec3f(t)), s.readLod)\";\n return `// One volume's slice: (alpha, visible t, extinction sum / steps * segment, read lod); alpha 0: nothing.\nstruct VdbFrameSlice {\n alpha: f32,\n visibleT: f32,\n extinction: f32,\n readLod: f32,\n lod: f32,\n maxTexels: f32,\n localNear: vec3f,\n localFar: vec3f,${spectral ? \"\\n alpha3: vec3f,\" : \"\"}\n};\nfn vdbFrameSliceOf(vi: u32, cell: vec3u, f: VdbFrameFroxel) -> VdbFrameSlice {\n var s: VdbFrameSlice;\n s.alpha = 0.0;\n let rect = vdbFrameVolumes.v[vi].rect;\n let slices = vdbFrameVolumes.v[vi].slices;\n let p = vec2f(cell.xy);\n if (p.x < rect.x || p.y < rect.y || p.x >= rect.z || p.y >= rect.w || cell.z < slices.x || cell.z >= slices.x + slices.y) {\n return s;\n }\n let v = slices.z;\n let viewToLocal = vdbFrameVolumes.v[vi].viewToLocal;\n s.localNear = (viewToLocal * vec4f(f.viewNear, 1.0)).xyz;\n s.localFar = (viewToLocal * vec4f(f.viewFar, 1.0)).xyz;\n let boxSegment = vdbFrameBoxSegment(s.localNear, s.localFar);\n if (boxSegment.x >= boxSegment.y) {\n return s;\n }\n let segment = boxSegment.y - boxSegment.x;\n let texels = vdbSrcTexels(v);\n s.maxTexels = max(texels.x, max(texels.y, texels.z));\n let worldScale = vdbFrameVolumes.v[vi].density.z;\n let mipmaps = vdbFrameVolumes.v[vi].march.y != 0u;\n let widthLod = vdbFrameFroxelLod(f, 0.0, worldScale, s.maxTexels);\n let sampledLod = select(0.0, min(widthLod, vdbFrameVolumes.v[vi].emission.w), mipmaps);\n let steps = vdbFrameBoxSteps(s.localNear, s.localFar, segment, sampledLod, s.maxTexels);\n let subStepCount = f32(steps);\n let subStepLength = length(f.viewFar - f.viewNear) * segment / subStepCount;\n s.lod = max(widthLod, vdbFrameLod(subStepLength / worldScale, s.maxTexels));\n s.readLod = select(0.0, s.lod, mipmaps);\n let opacity = vdbFrameVolumes.v[vi].scatterOpacity.w;${spectral ? \"\\n let spectrum = vdbFrameVolumes.v[vi].extinctionSpectrum.xyz;\" : \"\"}\n\n // Pre-integrate the slice along the view ray; light the visibility-weighted mean position.\n var transmittance = ${spectral ? \"vec3f(1.0)\" : \"1.0\"};\n var visibleWeight = 0.0;\n var visibleTSum = 0.0;\n var extinctionSum = 0.0;\n let jitter = vdbFrameNoise(vdbFrame.jitterFade.x, f.fragCoord);\n for (var i = 0u; i < steps; i++) {\n let t = boxSegment.x + segment * ((f32(i) + jitter) / subStepCount);\n let extinction = ${extinction} * opacity * vdbFrameDistanceFade(mix(f.viewNear, f.viewFar, vec3f(t)));\n let stepTransmittance = exp(-${spectral ? \"spectrum * \" : \"\"}extinction * subStepLength);\n let weight = ${spectral ? \"vdbFrameMeanComponent(transmittance * (vec3f(1.0) - stepTransmittance))\" : \"transmittance * (1.0 - stepTransmittance)\"};\n visibleWeight += weight;\n visibleTSum += weight * t;\n extinctionSum += extinction;\n transmittance *= stepTransmittance;\n }\n${spectral ? \" s.alpha3 = vec3f(1.0) - transmittance;\\n s.alpha = vdbFrameMaxComponent(s.alpha3);\" : \" s.alpha = 1.0 - transmittance;\"}\n s.extinction = extinctionSum / subStepCount * segment;\n s.visibleT = select(-1.0, visibleTSum / visibleWeight, visibleWeight > 0.0);\n return s;\n}\n`;\n}\n\n/** The grey slice pre-integration ({@link vdbFrameSliceWgsl}). */\nexport const VDB_FRAME_SLICE_WGSL = vdbFrameSliceWgsl(false);\n\n/**\n * K6.4: the inject pass's shadow march in one volume, spectral (his FrameInjectMaterial L393–439): one volume has one\n * spectrum, so the march sums one optical depth and the depths of each channel are linear in it (`unit`); it stops when\n * every channel's march depth is past 8. The same sample lattice and HDDA skip as the grey march.\n */\nconst SPECTRAL_MARCH_WGSL = `fn vdbFrameSpectralShadowMarch(vi: u32, origin: vec3f, localDirection: vec3f, maxLocalDistance: f32, lod: f32, maxTexels: f32, unit: VdbFrameSpectralDepths, noise: f32, stepCount: u32) -> VdbFrameSpectralMarch {\n // K6.Q1a: the shadowed ambient's marches may take fewer steps (0: the volume's)\n let steps = select(vdbFrameVolumes.v[vi].march.x, stepCount, stepCount > 0u && vdbFrameVolumes.v[vi].march.x > 0u);\n let absorbance = vdbFrameVolumes.v[vi].density.w;\n if (absorbance <= 0.0 || steps == 0u) {\n return vdbFrameSpectralUnmarched();\n }\n let direction = normalize(localDirection);\n let marchDistance = min(vdbFrameBoxExit(origin, direction), maxLocalDistance);\n if (marchDistance <= 0.0) {\n return vdbFrameSpectralUnmarched();\n }\n let multipleScattering = vdbFrameVolumes.v[vi].phaseSpectrumMs.w;\n let mipmaps = vdbFrameVolumes.v[vi].march.y != 0u;\n let localStep = marchDistance / f32(steps);\n let stepLod = select(0.0, max(lod, vdbFrameLod(localStep, maxTexels)), mipmaps);\n let worldStep = localStep * length(vdbFrameMat3(vdbFrameVolumes.v[vi].localToView) * direction);\n let stepScale = worldStep * absorbance;\n let offsetWrap = vdbFrameVolumes.v[vi].offsetWrap;\n let skip = vdbFrameVolumes.v[vi].march.z != 0u && offsetWrap.w < 0.5 && all(offsetWrap.xyz == vec3f(0.0));\n let cutoff = max(vdbFrameVolumes.v[vi].density.y, 0.0);\n let tEnd = marchDistance + localStep;\n var opticalDepth = 0.0;\n var cellEnd = -1.0;\n var lastZero = true;\n var k = 0u;\n loop {\n if (k >= steps) {\n break;\n }\n let t = localStep * (f32(k) + noise);\n if (skip && lastZero && t >= cellEnd) {\n let span = vdbSrcSkipSpan(vdbFrameVolumes.v[vi].slices.z, origin + 0.5, direction, t, tEnd, stepLod, cutoff);\n cellEnd = span.y;\n if (span.x > t) {\n k = max(k + 1u, u32(max(ceil(span.x / localStep - noise), 0.0)));\n continue;\n }\n }\n let extinction = vdbFrameExtinction(vi, origin + direction * t, stepLod) * stepScale;\n lastZero = extinction <= 0.0;\n opticalDepth += extinction;\n let d = VdbFrameSpectralDepths(unit.x * opticalDepth, unit.y * opticalDepth, unit.z * opticalDepth);\n if (vdbFrameMinComponent(vdbFrameSpectralShadowMarchDepth(d, multipleScattering, vdbFrame.octaves)) > 8.0) {\n break;\n }\n k++;\n }\n let depths = VdbFrameSpectralDepths(unit.x * opticalDepth, unit.y * opticalDepth, unit.z * opticalDepth);\n let shadow = vdbFrameSpectralShadowTransmittance(depths, multipleScattering, vdbFrame.octaves);\n return VdbFrameSpectralMarch(shadow.x, shadow.y, depths.z, depths.y);\n}\n`;\n\n/**\n * K6.4: one volume in one froxel, spectral (his inject pass with `spectral`): per-channel alpha, march, totals and\n * radiance. The same light loop (one march call site) as the grey `vdbFrameVolumeFroxel`.\n */\nconst SPECTRAL_VOLUME_FROXEL_WGSL = `struct VdbFrameSpectralFroxel {\n radiance: vec3f,\n alpha: vec3f,\n};\nfn vdbFrameVolumeFroxel(vi: u32, cell: vec3u, f: VdbFrameFroxel) -> VdbFrameSpectralFroxel {\n var none: VdbFrameSpectralFroxel;\n let s = vdbFrameSliceOf(vi, cell, f);\n if (s.visibleT < 0.0 || s.alpha <= 1e-5) {\n return none;\n }\n let slices = vdbFrameVolumes.v[vi].slices;\n let lod = s.lod;\n let readLod = s.readLod;\n let maxTexels = s.maxTexels;\n let localPosition = mix(s.localNear, s.localFar, vec3f(s.visibleT));\n let localToView = vdbFrameVolumes.v[vi].localToView;\n let worldToLocal = vdbFrameVolumes.v[vi].worldToLocal;\n let viewPosition = (localToView * vec4f(localPosition, 1.0)).xyz;\n let worldPosition = (vdbFrame.cameraWorld * vec4f(viewPosition, 1.0)).xyz;\n let worldToLocalDirection = vdbFrameMat3(worldToLocal);\n let rayDirection = normalize(vdbFrameMat3(vdbFrame.cameraWorld) * (f.viewFar - f.viewNear));\n let shadowNoise = vdbFrameNoise(vdbFrame.jitterFade.x, f.fragCoord + vec2f(17.0, 31.0));\n let albedo = vdbFrameAlbedo(vi, localPosition, readLod);\n let phase = vdbFrameVolumes.v[vi].phase;\n let phaseSpectrumMs = vdbFrameVolumes.v[vi].phaseSpectrumMs;\n let diffusion = phaseSpectrumMs.w > 0.0;\n let octaves = vdbFrame.octaves;\n let twoSided = vdbFrame.lighting.y > 0.5;\n let lightMask = slices.w;\n // his frameSpectralShadowUnit: the depths of one unit of optical depth for this volume's spectrum and lit albedo\n let unit = vdbFrameSpectralShadowUnit(vdbFrameVolumes.v[vi].extinctionSpectrum.xyz, albedo, phaseSpectrumMs.w);\n\n var outwardNormal = vec3f(0.0, 1.0, 0.0);\n if (length(localPosition) > 1e-4) {\n outwardNormal = normalize(vdbFrameMat3(vdbFrame.cameraWorld) * (vdbFrameMat3(localToView) * localPosition));\n }\n\n // K6.Q1a shadowed ambient (as the grey kernel, per channel): direction pairs marched below (the hemisphere lights' own\n // marches go away); off: his unshadowed ambient and 'outward' probe irradiance\n let ambientPairs = select(0u, min(vdbFrameLights.counts.z, ${VDB_FRAME_AMBIENT_MAX_PAIRS}u), (lightMask & (VDB_FRAME_LIGHT_AMBIENT | VDB_FRAME_LIGHT_HEMISPHERE)) != 0u);\n var irradiance = vec3f(0.0);\n if ((lightMask & VDB_FRAME_LIGHT_AMBIENT) != 0u && ambientPairs == 0u) {\n irradiance += vdbFrameLights.ambient.xyz;\n irradiance += vdbFrameShIrradiance(outwardNormal);\n }\n\n let hemiCount = select(0u, u32(vdbFrameLights.ambient.w), (lightMask & VDB_FRAME_LIGHT_HEMISPHERE) != 0u && ambientPairs == 0u);\n let sceneCount = vdbFrameLights.counts.x;\n let envOn = (lightMask & VDB_FRAME_LIGHT_ENVIRONMENT) != 0u && vdbFrameEnv.info.z != 0u;\n let envLights = select(0u, vdbFrameEnv.info.x, envOn);\n let lightItems = hemiCount + sceneCount + select(0u, max(envLights, 1u), envOn);\n let items = lightItems + ambientPairs;\n var environment = vec3f(0.0);\n var ambientUp = vec3f(0.0);\n var ambientDown = vec3f(0.0);\n // K6.Q1c: the dipole sum b.r of the pairs' totals (M+ / 2 . r, r the view ray; mode 0: unused)\n let dipole = vdbFrameLights.ambientDipole;\n let dipoleRay = vec3f(dot(dipole[0].xyz, rayDirection), dot(dipole[1].xyz, rayDirection), dot(dipole[2].xyz, rayDirection));\n var ambientDipoleSum = vec3f(0.0);\n for (var item = 0u; item < items; item++) {\n var direction = vec3f(0.0, 1.0, 0.0);\n var maxDistance = 1e6;\n var marches = 2u;\n var steps = 0u;\n var lightColor = vec3f(0.0);\n var lightDirection = vec3f(0.0, 1.0, 0.0);\n var spotAttenuation = 1.0;\n let li = item - hemiCount;\n let ambientItem = item >= lightItems;\n if (ambientItem) {\n // K6.Q1a: an ambient direction pair (world -> local)\n direction = worldToLocalDirection * vdbFrameLights.ambientDirections[item - lightItems].xyz;\n steps = vdbFrameLights.counts.w;\n } else if (item < hemiCount) {\n direction = worldToLocalDirection * vdbFrameLights.hemiUp[item].xyz;\n } else if (li >= sceneCount) {\n direction = worldToLocalDirection * select(outwardNormal, vdbFrameEnv.direction[min(li - sceneCount, 11u)].xyz, envLights > 0u);\n marches = select(1u, 2u, diffusion);\n } else {\n let position = vdbFrameLights.position[li];\n let color = vdbFrameLights.color[li];\n let spot = vdbFrameLights.spot[li];\n let isDirectional = position.w < 1.5;\n let isSpot = position.w > 2.5;\n let bit = select(select(VDB_FRAME_LIGHT_POINT, VDB_FRAME_LIGHT_SPOT, isSpot), VDB_FRAME_LIGHT_DIRECTIONAL, isDirectional);\n if (isSpot) {\n spotAttenuation = smoothstep(spot.w, color.w, dot(normalize(position.xyz - worldPosition), spot.xyz));\n }\n if ((lightMask & bit) == 0u || spotAttenuation <= 0.0) {\n continue;\n }\n spotAttenuation *= vdbFrameOccluderVisibility(worldPosition, li);\n if (spotAttenuation <= 0.0) {\n continue;\n }\n let toLight = (worldToLocal * vec4f(position.xyz, 1.0)).xyz - localPosition;\n direction = select(toLight, worldToLocalDirection * position.xyz, isDirectional);\n maxDistance = select(length(toLight), 1e6, isDirectional);\n lightDirection = select(normalize(position.xyz - worldPosition), position.xyz, isDirectional);\n lightColor = color.rgb;\n marches = select(1u, 2u, twoSided);\n }\n var front = vdbFrameSpectralUnmarched();\n var back = vdbFrameSpectralUnmarched();\n for (var k = 0u; k < marches; k++) {\n let shadow = vdbFrameSpectralShadowMarch(vi, localPosition, select(direction, -direction, k == 1u), select(maxDistance, 1e6, k == 1u), lod, maxTexels, unit, shadowNoise, steps);\n if (k == 0u) {\n front = shadow;\n } else {\n back = shadow;\n }\n }\n if (ambientItem) {\n // K6.Q1a: the pair's isotropic-light totals of each channel (diffusion: the two-sided pair, white furnace; octaves:\n // over an open direction's octave total)\n var up = vec3f(0.0);\n var down = vec3f(0.0);\n if (diffusion) {\n up = vdbFrameIsotropicDiffusion3(front.z, back.z, front.w);\n down = vdbFrameIsotropicDiffusion3(back.z, front.z, back.w);\n } else {\n let open = vdbFrameSpectralShadowTotal(vec3f(1.0), octaves, albedo);\n up = vdbFrameSpectralShadowTotal(front.y, octaves, albedo) / open;\n down = vdbFrameSpectralShadowTotal(back.y, octaves, albedo) / open;\n }\n ambientUp += up;\n ambientDown += down;\n ambientDipoleSum += (up - down) * dot(vdbFrameLights.ambientDirections[item - lightItems].xyz, dipoleRay);\n } else if (item < hemiCount) {\n var sky = vdbFrameSpectralShadowTotal(front.y, octaves, albedo);\n var ground = vdbFrameSpectralShadowTotal(back.y, octaves, albedo);\n if (diffusion) {\n sky = vdbFrameIsotropicDiffusion3(front.z, back.z, front.w);\n ground = vdbFrameIsotropicDiffusion3(back.z, front.z, back.w);\n }\n irradiance += vdbFrameLights.hemiSky[item].xyz * 0.5 * sky;\n irradiance += vdbFrameLights.hemiGround[item].xyz * 0.5 * ground;\n } else if (li < sceneCount) {\n var shadow = VdbFrameSpectralShadow(front.x, front.y);\n if (twoSided) {\n shadow.y = vdbFrameTwoSidedDiffusion3(front.x, front.z, front.w, back.z);\n }\n // K7.4c (internal msExit; 0: his isotropic exit): the scattered part (total - direct) x its exit factor\n if (vdbFrame.spectral.z > 0.5 && octaves.x <= 0.0) {\n shadow.y = shadow.x + (shadow.y - shadow.x) * vdbFrameMsExit(vdbFrame.spectral.z, phase, phaseSpectrumMs.xyz, dot(rayDirection, lightDirection), shadow.x, shadow.y - shadow.x, clamp(albedo, vec3f(0.0), vec3f(1.0)));\n }\n let light = vdbFrameSpectralShadowedLight(phase, phaseSpectrumMs.xyz, octaves, dot(rayDirection, lightDirection), shadow, albedo);\n irradiance += lightColor * light * spotAttenuation;\n } else if (envLights > 0u) {\n environment += vdbFrameEnv.color[min(li - sceneCount, 11u)].xyz * select(vdbFrameSpectralShadowTotal(front.y, octaves, albedo), vdbFrameIsotropicDiffusion3(front.z, back.z, front.w), diffusion);\n } else if (diffusion) {\n irradiance += vdbFrameEnvIrradiance(outwardNormal) * (vdbFrameIsotropicDiffusion3(front.z, back.z, front.w) * 0.5);\n irradiance += vdbFrameEnvIrradiance(-outwardNormal) * (vdbFrameIsotropicDiffusion3(back.z, front.z, back.w) * 0.5);\n } else {\n irradiance += vdbFrameEnvIrradiance(outwardNormal) * vdbFrameSpectralShadowTotal(front.y, octaves, albedo);\n }\n }\n irradiance += max(environment, vec3f(0.0));\n // K6.Q1a: the distant light at the hemispherical visibilities of each channel, as 'frame' lighting's sky up / down;\n // K6.Q1c: x the phase weight of the pairs' dipole (mode 1; not on diffusion totals)\n if (ambientPairs > 0u) {\n let weighted = dipole[0].w > 0.5 && !diffusion;\n let factor = select(vec3f(1.0), vdbFrameAmbientPhaseFactor(ambientUp, ambientDown, ambientDipoleSum, ambientPairs, phase, phaseSpectrumMs.xyz), weighted);\n let up = ambientUp / f32(ambientPairs) * 0.5 * factor;\n let down = ambientDown / f32(ambientPairs) * 0.5 * factor;\n let sky = normalize(vdbFrameLights.sky.xyz);\n if ((lightMask & VDB_FRAME_LIGHT_AMBIENT) != 0u) {\n irradiance += vdbFrameLights.ambient.xyz * (up + down) + vdbFrameShIrradiance(sky) * up + vdbFrameShIrradiance(-sky) * down;\n }\n if ((lightMask & VDB_FRAME_LIGHT_HEMISPHERE) != 0u) {\n irradiance += vdbFrameLights.hemiSkySum.xyz * up + vdbFrameLights.hemiGroundSum.xyz * down;\n }\n }\n\n let scatter = vdbFrameVolumes.v[vi].scatterOpacity.xyz;\n let radiance = max(scatter, albedo * irradiance * (1.0 / VDB_FRAME_PI)) + vdbFrameEmission(vi, localPosition, readLod);\n return VdbFrameSpectralFroxel(radiance, s.alpha3);\n}\n`;\n\n/** K6.4: the spectral 'volume' gather (after the source module and the frame uniforms). */\nfunction vdbFrameSpectralGatherWgsl(o: VDBFrameGatherOptions): string {\n const b = GATHER_BINDINGS;\n const bindings = [\n `@group(1) @binding(${b.volumes}) var<uniform> vdbFrameVolumes: VdbFrameVolumes;`,\n `@group(1) @binding(${b.group}) var<uniform> vdbFrameGroup: VdbFrameGroup;`,\n `@group(1) @binding(${b.scatter}) var vdbFrameScatter: texture_storage_3d<rgba16float, write>;`,\n `@group(1) @binding(${b.scatterAlpha}) var vdbFrameScatterAlpha: texture_storage_3d<rgba16float, write>;`,\n ...(o.multi ? [`@group(1) @binding(${b.partials}) var vdbFramePartials: texture_storage_3d<r32uint, read_write>;`] : []),\n vdbFrameOccluderWgsl(),\n ].join(\"\\n\");\n // (light rgb, alpha rgb): Σ τL and Σ τ of each channel\n const accumulate = ` let tau = -log(max(vec3f(1.0) - r.alpha, vec3f(VDB_FRAME_MIN_TRANSMITTANCE)));\n sumL += r.radiance * tau;\n sumA += tau;\n singleL = r.radiance * r.alpha;\n singleA = r.alpha;`;\n const finish = `fn vdbFrameFinish(sumL: vec3f, sumA: vec3f, count: u32, singleL: vec3f, singleA: vec3f) {\n if (count == 1u) {\n vdbFrameStoreOut.l = singleL;\n vdbFrameStoreOut.a = singleA;\n return;\n }\n let alpha = vec3f(1.0) - exp(-sumA);\n vdbFrameStoreOut.l = select(vec3f(0.0), sumL / max(sumA, vec3f(1e-30)) * alpha, sumA > vec3f(0.0));\n vdbFrameStoreOut.a = alpha;\n}`;\n const combine = ` sumL += earlierL;\n sumA += earlierA;`;\n const write = ` textureStore(vdbFrameScatter, cell, vec4f(vdbFrameStoreOut.l, vdbFrameStoreOut.a.y));\n textureStore(vdbFrameScatterAlpha, cell, vec4f(vdbFrameStoreOut.a.x, vdbFrameStoreOut.a.z, 0.0, vdbFrameStoreOut.a.y));`;\n const store = o.multi\n ? ` let role = vdbFrameGroup.range.z;\n let isFirst = (role & 1u) != 0u;\n let isLast = (role & 2u) != 0u;\n let depth = u32(vdbFrame.grid.z);\n if (!inside) {\n if (isLast) {\n textureStore(vdbFrameScatter, cell, vec4f(0.0));\n textureStore(vdbFrameScatterAlpha, cell, vec4f(0.0));\n }\n return;\n }\n if (!isFirst) {\n let w0 = unpack2x16float(textureLoad(vdbFramePartials, cell).x);\n let w1 = unpack2x16float(textureLoad(vdbFramePartials, vec3u(cell.xy, cell.z + depth)).x);\n let w2 = unpack2x16float(textureLoad(vdbFramePartials, vec3u(cell.xy, cell.z + 2u * depth)).x);\n let earlierL = vec3f(w0, w1.x);\n let earlierA = vec3f(w1.y, w2);\n${combine}\n }\n if (isLast) {\n vdbFrameFinish(sumL, sumA, 2u, singleL, singleA);\n${write}\n } else {\n textureStore(vdbFramePartials, cell, vec4u(pack2x16float(sumL.xy), 0u, 0u, 0u));\n textureStore(vdbFramePartials, vec3u(cell.xy, cell.z + depth), vec4u(pack2x16float(vec2f(sumL.z, sumA.x)), 0u, 0u, 0u));\n textureStore(vdbFramePartials, vec3u(cell.xy, cell.z + 2u * depth), vec4u(pack2x16float(sumA.yz), 0u, 0u, 0u));\n }`\n : ` if (inside) {\n vdbFrameFinish(sumL, sumA, count, singleL, singleA);\n }\n${write}`;\n\n return `${frameChunksWgsl([\"constants\", \"mat3\", \"froxel\", \"noise\", \"fade\", \"box\", \"lod\", \"phase\", \"ambientPhase\", \"msExit\", \"shadow\", \"octaves\", \"spectral\", \"sh\", \"envSh\", ...(o.stochastic ? ([\"rand\"] as const) : [])])}\n${bindings}\n\nconst VDB_FRAME_MIN_TRANSMITTANCE: f32 = 1.2664165549e-14; // exp(-32): tau is at most 32\n\n${vdbFrameSourceFunctionsWgsl(o.channels, { lutBinding: b.emissionLut, hook: o.hook ?? null }, !!o.stochastic)}\n${vdbFrameSliceWgsl(true, !!o.stochastic)}\n${SPECTRAL_MARCH_WGSL}\n${SPECTRAL_VOLUME_FROXEL_WGSL}\nstruct VdbFrameStoreOut {\n l: vec3f,\n a: vec3f,\n};\nvar<private> vdbFrameStoreOut: VdbFrameStoreOut;\n${finish}\n\n@compute @workgroup_size(8, 8, 1)\nfn vdbFrameGatherCs(@builtin(global_invocation_id) gid: vec3u) {\n let box = vdbFrame.dispatchBox;\n if (gid.x >= box.z || gid.y >= box.w || f32(gid.z) >= vdbFrame.grid.z) {\n return;\n }\n let cell = vec3u(box.x + gid.x, box.y + gid.y, gid.z);\n let area = vdbFrame.areaRect;\n let areaSlices = vdbFrame.areaSlices;\n let p = vec2f(cell.xy);\n let z = f32(cell.z);\n let inside = p.x >= area.x && p.y >= area.y && p.x < area.z && p.y < area.w && z >= areaSlices.x && z < areaSlices.y;\n var sumL = vec3f(0.0);\n var sumA = vec3f(0.0);\n var singleL = vec3f(0.0);\n var singleA = vec3f(0.0);\n var count = 0u;\n vdbFrameStoreOut = VdbFrameStoreOut(vec3f(0.0), vec3f(0.0));\n if (inside) {\n let f = vdbFrameFroxelAt(cell);\n let group = vdbFrameGroup.range;\n for (var i = 0u; i < group.y; i++) {\n let r = vdbFrameVolumeFroxel(group.x + i, cell, f);\n if (vdbFrameMaxComponent(r.alpha) <= 0.0) {\n continue;\n }\n${accumulate}\n count += 1u;\n }\n }\n${store}\n}\n`;\n}\n\n/** The kernel's WGSL after the source module and `vdbFrameUniformsWgsl()` (group 1 + functions + entry). */\nexport function vdbFrameGatherWgsl(o: VDBFrameGatherOptions): string {\n if (o.spectral) return vdbFrameSpectralGatherWgsl(o);\n const b = GATHER_BINDINGS;\n const bindings = [\n `@group(1) @binding(${b.volumes}) var<uniform> vdbFrameVolumes: VdbFrameVolumes;`,\n `@group(1) @binding(${b.group}) var<uniform> vdbFrameGroup: VdbFrameGroup;`,\n `@group(1) @binding(${b.scatter}) var vdbFrameScatter: texture_storage_3d<rgba16float, write>;`,\n ...(o.multi ? [`@group(1) @binding(${b.partials}) var vdbFramePartials: texture_storage_3d<r32uint, read_write>;`] : []),\n // K6.5b: the host occluder maps (bindings 12–15)\n vdbFrameOccluderWgsl(),\n ].join(\"\\n\");\n\n const accumulate = ` // co-located media: sum optical depths and depth-weighted radiance\n let tau = -log(max(1.0 - r.w, VDB_FRAME_MIN_TRANSMITTANCE));\n sum += vec4f(r.rgb * tau, tau);\n single = vec4f(r.rgb * r.w, r.w);`;\n\n const finish = `fn vdbFrameFinish(sum: vec4f, count: u32, single: vec4f) -> vec4f {\n if (count == 1u) {\n return single;\n }\n if (sum.w <= 0.0) {\n return vec4f(0.0);\n }\n let alpha = 1.0 - exp(-sum.w);\n return vec4f(sum.rgb / sum.w * alpha, alpha);\n}`;\n\n // Partials (multi-group): (sum.xy, sum.zw) as pack2x16float pairs at slice z and z + D.\n const combine = `fn vdbFrameCombine(earlier: vec4f, later: vec4f) -> vec4f {\n return earlier + later;\n}`;\n\n const store = o.multi\n ? ` let role = vdbFrameGroup.range.z;\n let isFirst = (role & 1u) != 0u;\n let isLast = (role & 2u) != 0u;\n let depth = u32(vdbFrame.grid.z);\n if (!inside) {\n if (isLast) {\n textureStore(vdbFrameScatter, cell, vec4f(0.0));\n }\n return;\n }\n var total = sum;\n if (!isFirst) {\n let lo = textureLoad(vdbFramePartials, cell).x;\n let hi = textureLoad(vdbFramePartials, vec3u(cell.xy, cell.z + depth)).x;\n total = vdbFrameCombine(vec4f(unpack2x16float(lo), unpack2x16float(hi)), sum);\n }\n if (isLast) {\n textureStore(vdbFrameScatter, cell, vdbFrameFinish(total, 2u, single));\n } else {\n textureStore(vdbFramePartials, cell, vec4u(pack2x16float(total.xy), 0u, 0u, 0u));\n textureStore(vdbFramePartials, vec3u(cell.xy, cell.z + depth), vec4u(pack2x16float(total.zw), 0u, 0u, 0u));\n }`\n : ` textureStore(vdbFrameScatter, cell, vdbFrameFinish(sum, count, single));`;\n\n return `${frameChunksWgsl([\"constants\", \"mat3\", \"froxel\", \"noise\", \"fade\", \"box\", \"lod\", \"phase\", \"ambientPhase\", \"msExit\", \"shadow\", \"octaves\", \"sh\", \"envSh\", ...(o.stochastic ? ([\"rand\"] as const) : [])])}\n${bindings}\n\nconst VDB_FRAME_MIN_TRANSMITTANCE: f32 = 1.2664165549e-14; // exp(-32): tau is at most 32\n\n${vdbFrameSourceFunctionsWgsl(o.channels, { lutBinding: b.emissionLut, hook: o.hook ?? null }, !!o.stochastic)}\n${vdbFrameSliceWgsl(false, !!o.stochastic)}\n// The inject pass's shadow march inside one volume: (direct, total, reduced depth, effective depth).\n// The one march of the kernel (one density call site), stopping when the depth passes 8. Samples sit at\n// t_k = step (k + noise); with the volume's hdda flag (K6.1d) runs of samples the source proves empty are jumped\n// over (vdbSrcSkipSpan; the dense source never skips). No skipping under wrap or an offset (samples leave the\n// ray's cells). The source is asked only at the start and after a zero sample past the last cell end (K3.2).\nfn vdbFrameShadowMarch(vi: u32, origin: vec3f, localDirection: vec3f, maxLocalDistance: f32, lod: f32, maxTexels: f32, albedo: vec3f, noise: f32, stepCount: u32) -> vec4f {\n // K6.Q1: the shadowed ambient's marches may take fewer steps (0: the volume's)\n let steps = select(vdbFrameVolumes.v[vi].march.x, stepCount, stepCount > 0u && vdbFrameVolumes.v[vi].march.x > 0u);\n let absorbance = vdbFrameVolumes.v[vi].density.w;\n if (absorbance <= 0.0 || steps == 0u) {\n return vec4f(1.0, 1.0, 0.0, 0.0);\n }\n let direction = normalize(localDirection);\n let marchDistance = min(vdbFrameBoxExit(origin, direction), maxLocalDistance);\n if (marchDistance <= 0.0) {\n return vec4f(1.0, 1.0, 0.0, 0.0);\n }\n let multipleScattering = vdbFrameVolumes.v[vi].phaseSpectrumMs.w;\n let mipmaps = vdbFrameVolumes.v[vi].march.y != 0u;\n let localStep = marchDistance / f32(steps);\n let stepLod = select(0.0, max(lod, vdbFrameLod(localStep, maxTexels)), mipmaps);\n let worldStep = localStep * length(vdbFrameMat3(vdbFrameVolumes.v[vi].localToView) * direction);\n let stepScale = worldStep * absorbance;\n let offsetWrap = vdbFrameVolumes.v[vi].offsetWrap;\n let skip = vdbFrameVolumes.v[vi].march.z != 0u && offsetWrap.w < 0.5 && all(offsetWrap.xyz == vec3f(0.0));\n let cutoff = max(vdbFrameVolumes.v[vi].density.y, 0.0);\n let tEnd = marchDistance + localStep;\n var depths = vec3f(0.0);\n var cellEnd = -1.0;\n var lastZero = true;\n var k = 0u;\n loop {\n if (k >= steps) {\n break;\n }\n let t = localStep * (f32(k) + noise);\n if (skip && lastZero && t >= cellEnd) {\n let span = vdbSrcSkipSpan(vdbFrameVolumes.v[vi].slices.z, origin + 0.5, direction, t, tEnd, stepLod, cutoff);\n cellEnd = span.y;\n if (span.x > t) {\n k = max(k + 1u, u32(max(ceil(span.x / localStep - noise), 0.0)));\n continue;\n }\n }\n let extinction = vdbFrameExtinction(vi, origin + direction * t, stepLod) * stepScale;\n lastZero = extinction <= 0.0;\n depths += vdbFrameShadowStep(extinction, vdbFrameShadowAbsorption(extinction, albedo), multipleScattering);\n if (vdbFrameShadowMarchDepth(depths, multipleScattering, vdbFrame.octaves) > 8.0) {\n break;\n }\n k++;\n }\n // K6.3: octaves march to the last octave's depth and keep 1 / (1 + depth) as the total\n let shadow = vdbFrameShadowTransmittance(depths, multipleScattering, vdbFrame.octaves);\n return vec4f(shadow.x, shadow.y, depths.z, depths.y);\n}\n\n// One volume in one froxel (his inject pass): (unpremultiplied radiance, slice alpha); alpha 0: nothing.\nfn vdbFrameVolumeFroxel(vi: u32, cell: vec3u, f: VdbFrameFroxel) -> vec4f {\n let s = vdbFrameSliceOf(vi, cell, f);\n let alpha = s.alpha;\n if (s.visibleT < 0.0 || alpha <= 1e-5) {\n return vec4f(0.0);\n }\n let slices = vdbFrameVolumes.v[vi].slices;\n let lod = s.lod;\n let readLod = s.readLod;\n let maxTexels = s.maxTexels;\n let localPosition = mix(s.localNear, s.localFar, vec3f(s.visibleT));\n let localToView = vdbFrameVolumes.v[vi].localToView;\n let worldToLocal = vdbFrameVolumes.v[vi].worldToLocal;\n let viewPosition = (localToView * vec4f(localPosition, 1.0)).xyz;\n let worldPosition = (vdbFrame.cameraWorld * vec4f(viewPosition, 1.0)).xyz;\n let worldToLocalDirection = vdbFrameMat3(worldToLocal);\n let rayDirection = normalize(vdbFrameMat3(vdbFrame.cameraWorld) * (f.viewFar - f.viewNear));\n let shadowNoise = vdbFrameNoise(vdbFrame.jitterFade.x, f.fragCoord + vec2f(17.0, 31.0));\n let albedo = vdbFrameAlbedo(vi, localPosition, readLod);\n let phase = vdbFrameVolumes.v[vi].phase;\n let phaseSpectrumMs = vdbFrameVolumes.v[vi].phaseSpectrumMs;\n let diffusion = phaseSpectrumMs.w > 0.0;\n // K6.3: octaves (count 0: off) and 'two-sided' (scene lights also march away from the light)\n let octaves = vdbFrame.octaves;\n let twoSided = vdbFrame.lighting.y > 0.5;\n let lightMask = slices.w;\n\n var outwardNormal = vec3f(0.0, 1.0, 0.0);\n if (length(localPosition) > 1e-4) {\n outwardNormal = normalize(vdbFrameMat3(vdbFrame.cameraWorld) * (vdbFrameMat3(localToView) * localPosition));\n }\n\n // K6.Q1 shadowed ambient: direction pairs marched below (the hemisphere lights' own marches go away); off: his\n // unshadowed ambient and 'outward' probe irradiance\n let ambientPairs = select(0u, min(vdbFrameLights.counts.z, ${VDB_FRAME_AMBIENT_MAX_PAIRS}u), (lightMask & (VDB_FRAME_LIGHT_AMBIENT | VDB_FRAME_LIGHT_HEMISPHERE)) != 0u);\n var irradiance = vec3f(0.0);\n if ((lightMask & VDB_FRAME_LIGHT_AMBIENT) != 0u && ambientPairs == 0u) {\n irradiance += vdbFrameLights.ambient.xyz;\n irradiance += vdbFrameShIrradiance(outwardNormal);\n }\n\n // One loop over the hemisphere lights (a sky and ground march pair each), the scene lights (one march each) and\n // the environment (K6.2b: its lights, one march each and the opposite one with diffusion; without lights the\n // 'outward' SH irradiance along the outward normal): the kernel's only shadow-march call site.\n let hemiCount = select(0u, u32(vdbFrameLights.ambient.w), (lightMask & VDB_FRAME_LIGHT_HEMISPHERE) != 0u && ambientPairs == 0u);\n let sceneCount = vdbFrameLights.counts.x;\n let envOn = (lightMask & VDB_FRAME_LIGHT_ENVIRONMENT) != 0u && vdbFrameEnv.info.z != 0u;\n let envLights = select(0u, vdbFrameEnv.info.x, envOn);\n let lightItems = hemiCount + sceneCount + select(0u, max(envLights, 1u), envOn);\n let items = lightItems + ambientPairs;\n var environment = vec3f(0.0);\n var ambientUp = 0.0;\n var ambientDown = 0.0;\n // K6.Q1c: the dipole sum b.r of the pairs' totals (M+ / 2 . r, r the view ray; mode 0: unused)\n let dipole = vdbFrameLights.ambientDipole;\n let dipoleRay = vec3f(dot(dipole[0].xyz, rayDirection), dot(dipole[1].xyz, rayDirection), dot(dipole[2].xyz, rayDirection));\n var ambientDipoleSum = 0.0;\n for (var item = 0u; item < items; item++) {\n var direction = vec3f(0.0, 1.0, 0.0);\n var maxDistance = 1e6;\n var marches = 2u;\n var steps = 0u;\n var lightColor = vec3f(0.0);\n var lightDirection = vec3f(0.0, 1.0, 0.0);\n var spotAttenuation = 1.0;\n let li = item - hemiCount;\n let ambientItem = item >= lightItems;\n if (ambientItem) {\n // K6.Q1: an ambient direction pair (world -> local)\n direction = worldToLocalDirection * vdbFrameLights.ambientDirections[item - lightItems].xyz;\n steps = vdbFrameLights.counts.w;\n } else if (item < hemiCount) {\n direction = worldToLocalDirection * vdbFrameLights.hemiUp[item].xyz;\n } else if (li >= sceneCount) {\n direction = worldToLocalDirection * select(outwardNormal, vdbFrameEnv.direction[min(li - sceneCount, 11u)].xyz, envLights > 0u);\n marches = select(1u, 2u, diffusion);\n } else {\n let position = vdbFrameLights.position[li];\n let color = vdbFrameLights.color[li];\n let spot = vdbFrameLights.spot[li];\n let isDirectional = position.w < 1.5;\n let isSpot = position.w > 2.5;\n let bit = select(select(VDB_FRAME_LIGHT_POINT, VDB_FRAME_LIGHT_SPOT, isSpot), VDB_FRAME_LIGHT_DIRECTIONAL, isDirectional);\n if (isSpot) {\n spotAttenuation = smoothstep(spot.w, color.w, dot(normalize(position.xyz - worldPosition), spot.xyz));\n }\n if ((lightMask & bit) == 0u || spotAttenuation <= 0.0) {\n continue;\n }\n // K6.5b: a host occluder map; behind an occluder the march toward the light stops at once (both terms)\n spotAttenuation *= vdbFrameOccluderVisibility(worldPosition, li);\n if (spotAttenuation <= 0.0) {\n continue;\n }\n let toLight = (worldToLocal * vec4f(position.xyz, 1.0)).xyz - localPosition;\n direction = select(toLight, worldToLocalDirection * position.xyz, isDirectional);\n maxDistance = select(length(toLight), 1e6, isDirectional);\n lightDirection = select(normalize(position.xyz - worldPosition), position.xyz, isDirectional);\n lightColor = color.rgb;\n marches = select(1u, 2u, twoSided);\n }\n var front = vec4f(1.0, 1.0, 0.0, 0.0);\n var back = vec4f(1.0, 1.0, 0.0, 0.0);\n for (var k = 0u; k < marches; k++) {\n let shadow = vdbFrameShadowMarch(vi, localPosition, select(direction, -direction, k == 1u), select(maxDistance, 1e6, k == 1u), lod, maxTexels, albedo, shadowNoise, steps);\n if (k == 0u) {\n front = shadow;\n } else {\n back = shadow;\n }\n }\n if (ambientItem) {\n // K6.Q1: the pair's isotropic-light totals (diffusion: the two-sided pair, white furnace)\n var up = 0.0;\n var down = 0.0;\n if (diffusion) {\n up = vdbFrameIsotropicDiffusion(front.z, back.z, front.w);\n down = vdbFrameIsotropicDiffusion(back.z, front.z, back.w);\n } else {\n up = vdbFrameShadowTotal(front.y, octaves) / vdbFrameShadowTotal(1.0, octaves);\n down = vdbFrameShadowTotal(back.y, octaves) / vdbFrameShadowTotal(1.0, octaves);\n }\n ambientUp += up;\n ambientDown += down;\n ambientDipoleSum += (up - down) * dot(vdbFrameLights.ambientDirections[item - lightItems].xyz, dipoleRay);\n } else if (item < hemiCount) {\n // Diffusion: sky and ground are an opposite pair, two-sided totals\n var sky = vdbFrameShadowTotal(front.y, octaves);\n var ground = vdbFrameShadowTotal(back.y, octaves);\n if (diffusion) {\n sky = vdbFrameIsotropicDiffusion(front.z, back.z, front.w);\n ground = vdbFrameIsotropicDiffusion(back.z, front.z, back.w);\n }\n irradiance += vdbFrameLights.hemiSky[item].xyz * 0.5 * sky;\n irradiance += vdbFrameLights.hemiGround[item].xyz * 0.5 * ground;\n } else if (li < sceneCount) {\n // two-sided: diffusion of the slab between the light side and the far side\n var shadow = front.xy;\n if (twoSided) {\n shadow.y = vdbFrameTwoSidedDiffusion(front.x, front.z, front.w, back.z);\n }\n var light = vdbFrameShadowedLight(phase, phaseSpectrumMs.xyz, octaves, dot(rayDirection, lightDirection), shadow);\n // K7.4c (internal msExit; 0: his isotropic exit): the scattered part (total - direct) x its exit factor of each channel\n if (vdbFrame.spectral.z > 0.5 && octaves.x <= 0.0) {\n let exitAlbedo = clamp(dot(albedo, vec3f(0.2126, 0.7152, 0.0722)), 0.0, 1.0);\n let exit = vdbFrameMsExit(vdbFrame.spectral.z, phase, phaseSpectrumMs.xyz, dot(rayDirection, lightDirection), vec3f(shadow.x), vec3f(shadow.y - shadow.x), vec3f(exitAlbedo));\n light += (shadow.y - shadow.x) * (exit - vec3f(1.0));\n }\n irradiance += lightColor * light * spotAttenuation;\n } else if (envLights > 0u) {\n // an environment light: isotropic, no phase (diffusion: the two-sided total)\n environment += vdbFrameEnv.color[min(li - sceneCount, 11u)].xyz * select(vdbFrameShadowTotal(front.y, octaves), vdbFrameIsotropicDiffusion(front.z, back.z, front.w), diffusion);\n } else if (diffusion) {\n // 'outward': the outward and the inward irradiance, each with its two-sided total (uniform light gives E)\n irradiance += vdbFrameEnvIrradiance(outwardNormal) * (vdbFrameIsotropicDiffusion(front.z, back.z, front.w) * 0.5);\n irradiance += vdbFrameEnvIrradiance(-outwardNormal) * (vdbFrameIsotropicDiffusion(back.z, front.z, back.w) * 0.5);\n } else {\n irradiance += vdbFrameEnvIrradiance(outwardNormal) * vdbFrameShadowTotal(front.y, octaves);\n }\n }\n // SH lights can be negative: the environment sum is clamped (his max(environment, 0))\n irradiance += max(environment, vec3f(0.0));\n // K6.Q1: the distant light at the hemispherical visibilities, as 'frame' lighting's sky up / down totals; K6.Q1c: x the\n // phase weight of the pairs' dipole (mode 1; not on diffusion totals; per channel: a spectral phase g)\n if (ambientPairs > 0u) {\n let weighted = dipole[0].w > 0.5 && !diffusion;\n let factor = select(vec3f(1.0), vdbFrameAmbientPhaseFactor(vec3f(ambientUp), vec3f(ambientDown), vec3f(ambientDipoleSum), ambientPairs, phase, phaseSpectrumMs.xyz), weighted);\n let up = ambientUp / f32(ambientPairs) * 0.5 * factor;\n let down = ambientDown / f32(ambientPairs) * 0.5 * factor;\n let sky = normalize(vdbFrameLights.sky.xyz);\n if ((lightMask & VDB_FRAME_LIGHT_AMBIENT) != 0u) {\n irradiance += vdbFrameLights.ambient.xyz * (up + down) + vdbFrameShIrradiance(sky) * up + vdbFrameShIrradiance(-sky) * down;\n }\n if ((lightMask & VDB_FRAME_LIGHT_HEMISPHERE) != 0u) {\n irradiance += vdbFrameLights.hemiSkySum.xyz * up + vdbFrameLights.hemiGroundSum.xyz * down;\n }\n }\n\n let scatter = vdbFrameVolumes.v[vi].scatterOpacity.xyz;\n let radiance = max(scatter, albedo * irradiance * (1.0 / VDB_FRAME_PI)) + vdbFrameEmission(vi, localPosition, readLod);\n return vec4f(radiance, alpha);\n}\n\n${finish}\n${combine}\n\n@compute @workgroup_size(8, 8, 1)\nfn vdbFrameGatherCs(@builtin(global_invocation_id) gid: vec3u) {\n let box = vdbFrame.dispatchBox;\n if (gid.x >= box.z || gid.y >= box.w || f32(gid.z) >= vdbFrame.grid.z) {\n return;\n }\n let cell = vec3u(box.x + gid.x, box.y + gid.y, gid.z);\n let area = vdbFrame.areaRect;\n let areaSlices = vdbFrame.areaSlices;\n let p = vec2f(cell.xy);\n let z = f32(cell.z);\n let inside = p.x >= area.x && p.y >= area.y && p.x < area.z && p.y < area.w && z >= areaSlices.x && z < areaSlices.y;\n var sum = vec4f(0.0);\n var single = vec4f(0.0);\n var count = 0u;\n if (inside) {\n let f = vdbFrameFroxelAt(cell);\n let group = vdbFrameGroup.range;\n for (var i = 0u; i < group.y; i++) {\n let r = vdbFrameVolumeFroxel(group.x + i, cell, f);\n if (r.w <= 0.0) {\n continue;\n }\n${accumulate}\n count += 1u;\n }\n }\n${store}\n}\n`;\n}\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The composite seam (design §2.5): `vdbFrameIntegrateWgsl()` gives hosts
|
|
3
|
+
*
|
|
4
|
+
* struct VdbFrameIntegrated { radiance: vec3f, transmittance: vec3f }
|
|
5
|
+
* fn vdbFrameIntegrate(screenUv: vec2f, sceneViewDepth: f32) -> VdbFrameIntegrated;
|
|
6
|
+
* fn vdbFrameComposite(i: VdbFrameIntegrated, sceneColor: vec4f, srgbBlending: bool) -> vec4f;
|
|
7
|
+
*
|
|
8
|
+
* over `outputs.froxels.integrated` (bind with `vdbFrameIntegrateEntries`), and the core composite pass
|
|
9
|
+
* calls the same functions. The pure functions (no bindings) are also exported one by one for hosts that
|
|
10
|
+
* sample the prefix themselves (`./three` through `wgslFn`). CPU twins: tools/frame `vdbFrameSliceCoord`,
|
|
11
|
+
* `vdbFrameIntegratePrefix`, `vdbFrameSrgbBlend`.
|
|
12
|
+
*/
|
|
13
|
+
import type { VDBSlot } from "../../types.js";
|
|
14
|
+
/** `fn vdbFrameSliceCoord(viewDepth, range, depth) -> vec2f`: (slice k, his coverage c of slice k). */
|
|
15
|
+
export declare const VDB_FRAME_SLICE_COORD_WGSL = "fn vdbFrameSliceCoord(viewDepth: f32, range: vec2f, depth: f32) -> vec2f {\n let ratio = range.y / range.x;\n let s = clamp(depth * log(max(viewDepth, range.x) / range.x) / log(ratio), 0.0, depth);\n let k = min(floor(s), depth - 1.0);\n let start = range.x * pow(ratio, k / depth);\n let end = range.x * pow(ratio, (k + 1.0) / depth);\n return vec2f(k, clamp((viewDepth - start) / (end - start), 0.0, 1.0));\n}\n";
|
|
16
|
+
/** `fn vdbFrameIntegrateTaps(a, b, c) -> vec4f`: boundaries a, b = (L, 1 − T); returns (radiance, T). */
|
|
17
|
+
export declare const VDB_FRAME_INTEGRATE_TAPS_WGSL = "fn vdbFrameIntegrateTaps(a: vec4f, b: vec4f, c: f32) -> vec4f {\n let ta = 1.0 - a.w;\n let tb = 1.0 - b.w;\n let alpha = clamp(select(0.0, 1.0 - tb / ta, ta > 1e-6), 0.0, 1.0);\n let keep = select(pow(max(1.0 - alpha, 1e-30), c), 1.0, c <= 0.0);\n let w = select(c, (1.0 - keep) / alpha, alpha > 1e-4);\n return vec4f(a.rgb + (b.rgb - a.rgb) * w, max(ta, 0.0) * keep);\n}\n";
|
|
18
|
+
/** three's `sRGBTransferOETF` as `fn vdbFrameSrgbOetfColor(color: vec3f) -> vec3f`. */
|
|
19
|
+
export declare const VDB_FRAME_SRGB_OETF_WGSL = "fn vdbFrameSrgbOetfColor(color: vec3f) -> vec3f {\n let a = pow(color, vec3f(0.41666)) * 1.055 - 0.055;\n return select(a, color * 12.92, color <= vec3f(0.0031308));\n}\n";
|
|
20
|
+
/** three's `sRGBTransferEOTF` as `fn vdbFrameSrgbEotfColor(color: vec3f) -> vec3f`. */
|
|
21
|
+
export declare const VDB_FRAME_SRGB_EOTF_WGSL = "fn vdbFrameSrgbEotfColor(color: vec3f) -> vec3f {\n let a = pow(color * 0.9478672986 + 0.0521327014, vec3f(2.4));\n return select(a, color * 0.0773993808, color <= vec3f(0.04045));\n}\n";
|
|
22
|
+
/**
|
|
23
|
+
* `fn vdbFrameCompositeColor(r: vec4f, sceneColor: vec4f, srgb: u32, clampColors: u32) -> vec4f` (needs the two
|
|
24
|
+
* sRGB functions): r = (radiance, T). sRGB: his WebGLRenderer-like blend; else premultiplied (radiance, α).
|
|
25
|
+
*/
|
|
26
|
+
export declare const VDB_FRAME_COMPOSITE_COLOR_FN_WGSL = "fn vdbFrameCompositeColor(r: vec4f, sceneColor: vec4f, srgb: u32, clampColors: u32) -> vec4f {\n let alpha = 1.0 - r.w;\n if (srgb == 0u) {\n return vec4f(r.rgb, alpha);\n }\n var volumeColor = vdbFrameSrgbOetfColor(r.rgb / alpha);\n var backgroundColor = vdbFrameSrgbOetfColor(sceneColor.rgb);\n if (clampColors != 0u) {\n volumeColor = clamp(volumeColor, vec3f(0.0), vec3f(1.0));\n backgroundColor = clamp(backgroundColor, vec3f(0.0), vec3f(1.0));\n }\n return vec4f(vdbFrameSrgbEotfColor(mix(backgroundColor, volumeColor, vec3f(alpha))), alpha + sceneColor.a * (1.0 - alpha));\n}\n";
|
|
27
|
+
/** The sRGB functions and `vdbFrameCompositeColor`. */
|
|
28
|
+
export declare const VDB_FRAME_COMPOSITE_COLOR_WGSL = "fn vdbFrameSrgbOetfColor(color: vec3f) -> vec3f {\n let a = pow(color, vec3f(0.41666)) * 1.055 - 0.055;\n return select(a, color * 12.92, color <= vec3f(0.0031308));\n}\nfn vdbFrameSrgbEotfColor(color: vec3f) -> vec3f {\n let a = pow(color * 0.9478672986 + 0.0521327014, vec3f(2.4));\n return select(a, color * 0.0773993808, color <= vec3f(0.04045));\n}\nfn vdbFrameCompositeColor(r: vec4f, sceneColor: vec4f, srgb: u32, clampColors: u32) -> vec4f {\n let alpha = 1.0 - r.w;\n if (srgb == 0u) {\n return vec4f(r.rgb, alpha);\n }\n var volumeColor = vdbFrameSrgbOetfColor(r.rgb / alpha);\n var backgroundColor = vdbFrameSrgbOetfColor(sceneColor.rgb);\n if (clampColors != 0u) {\n volumeColor = clamp(volumeColor, vec3f(0.0), vec3f(1.0));\n backgroundColor = clamp(backgroundColor, vec3f(0.0), vec3f(1.0));\n }\n return vec4f(vdbFrameSrgbEotfColor(mix(backgroundColor, volumeColor, vec3f(alpha))), alpha + sceneColor.a * (1.0 - alpha));\n}\n";
|
|
29
|
+
/**
|
|
30
|
+
* K6.4 `fn vdbFrameCompositeSpectralColor(radiance: vec3f, transmittance: vec3f, sceneColor: vec4f, srgb: u32, clampColors: u32)
|
|
31
|
+
* -> vec4f` (needs the two sRGB functions): his spectral composite (FrameIntegrateMaterial L171–216): the scene colour ×
|
|
32
|
+
* the transmittance of each channel + the radiance, or (sRGB) the per-channel mix in sRGB; alpha from green. It blends
|
|
33
|
+
* itself: the pass draws without hardware blending.
|
|
34
|
+
*/
|
|
35
|
+
export declare const VDB_FRAME_COMPOSITE_SPECTRAL_FN_WGSL = "fn vdbFrameCompositeSpectralColor(radiance: vec3f, transmittance: vec3f, sceneColor: vec4f, srgb: u32, clampColors: u32) -> vec4f {\n let alpha = vec3f(1.0) - transmittance;\n let outputAlpha = alpha.y + sceneColor.a * (1.0 - alpha.y);\n if (srgb == 0u) {\n return vec4f(radiance + sceneColor.rgb * transmittance, outputAlpha);\n }\n var volumeColor = vdbFrameSrgbOetfColor(radiance / max(alpha, vec3f(1e-6)));\n var backgroundColor = vdbFrameSrgbOetfColor(sceneColor.rgb);\n if (clampColors != 0u) {\n volumeColor = clamp(volumeColor, vec3f(0.0), vec3f(1.0));\n backgroundColor = clamp(backgroundColor, vec3f(0.0), vec3f(1.0));\n }\n return vec4f(vdbFrameSrgbEotfColor(mix(backgroundColor, volumeColor, alpha)), outputAlpha);\n}\n";
|
|
36
|
+
/** The pure integrate functions, keyed by name (one function each, for `wgslFn`). */
|
|
37
|
+
export declare const VDB_FRAME_INTEGRATE_FUNCTIONS: {
|
|
38
|
+
readonly vdbFrameSliceCoord: "fn vdbFrameSliceCoord(viewDepth: f32, range: vec2f, depth: f32) -> vec2f {\n let ratio = range.y / range.x;\n let s = clamp(depth * log(max(viewDepth, range.x) / range.x) / log(ratio), 0.0, depth);\n let k = min(floor(s), depth - 1.0);\n let start = range.x * pow(ratio, k / depth);\n let end = range.x * pow(ratio, (k + 1.0) / depth);\n return vec2f(k, clamp((viewDepth - start) / (end - start), 0.0, 1.0));\n}\n";
|
|
39
|
+
readonly vdbFrameIntegrateTaps: "fn vdbFrameIntegrateTaps(a: vec4f, b: vec4f, c: f32) -> vec4f {\n let ta = 1.0 - a.w;\n let tb = 1.0 - b.w;\n let alpha = clamp(select(0.0, 1.0 - tb / ta, ta > 1e-6), 0.0, 1.0);\n let keep = select(pow(max(1.0 - alpha, 1e-30), c), 1.0, c <= 0.0);\n let w = select(c, (1.0 - keep) / alpha, alpha > 1e-4);\n return vec4f(a.rgb + (b.rgb - a.rgb) * w, max(ta, 0.0) * keep);\n}\n";
|
|
40
|
+
};
|
|
41
|
+
/** Options of {@link vdbFrameIntegrateWgsl}. */
|
|
42
|
+
export interface VDBFrameIntegrateWgslOptions {
|
|
43
|
+
/**
|
|
44
|
+
* K6.4 spectral: a second prefix (`outputs.froxels.integratedAlpha`: the red and blue opacity) at `alphaBinding`;
|
|
45
|
+
* `vdbFrameIntegrate` returns the transmittance of each channel and `vdbFrameComposite` blends itself (no hardware
|
|
46
|
+
* blending: one alpha cannot carry three transmittances), so the host passes the scene colour.
|
|
47
|
+
*/
|
|
48
|
+
readonly spectral?: boolean;
|
|
49
|
+
/** K6.4: the binding of the spectral alpha prefix in the slot's group (default `slot.firstBinding + 3`). */
|
|
50
|
+
readonly alphaBinding?: number;
|
|
51
|
+
/** Where the three bindings start (texture, sampler, `VdbFrameUniforms`); default group 0, binding 0. */
|
|
52
|
+
readonly slot?: VDBSlot;
|
|
53
|
+
/**
|
|
54
|
+
* Use the frame uniforms already declared as `vdbFrame` (the core composite) instead of declaring the
|
|
55
|
+
* struct and its binding; the texture and sampler are still declared at `slot`.
|
|
56
|
+
*/
|
|
57
|
+
readonly sharedUniforms?: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** The integrate seam's WGSL (design §2.5). */
|
|
60
|
+
export declare function vdbFrameIntegrateWgsl(o?: VDBFrameIntegrateWgslOptions): string;
|
|
61
|
+
/**
|
|
62
|
+
* Bind group layout entries of {@link vdbFrameIntegrateWgsl} at `slot`: texture, filtering sampler, uniforms (K6.4
|
|
63
|
+
* `spectral`: the alpha prefix at `alphaBinding`, default `firstBinding + 3`).
|
|
64
|
+
*/
|
|
65
|
+
export declare function vdbFrameIntegrateEntries(slot?: VDBSlot, visibility?: GPUShaderStageFlags, sharedUniforms?: boolean, spectral?: {
|
|
66
|
+
alphaBinding?: number;
|
|
67
|
+
} | false): GPUBindGroupLayoutEntry[];
|
|
68
|
+
/** Group-1 binding of the composite pass's alpha prefix (K6.4 spectral; 3 is the scene colour). */
|
|
69
|
+
export declare const VDB_FRAME_COMPOSITE_ALPHA_BINDING = 4;
|
|
70
|
+
/**
|
|
71
|
+
* The core composite pass's WGSL (after the frame uniforms): a fullscreen triangle scissored by the host call. K6.4
|
|
72
|
+
* `spectral`: the alpha prefix at binding 4 and the scene colour (binding 3) always; the pass draws without blending.
|
|
73
|
+
*/
|
|
74
|
+
export declare function vdbFrameCompositeWgsl(o: {
|
|
75
|
+
depth: "depth" | "r32float";
|
|
76
|
+
srgb: boolean;
|
|
77
|
+
spectral?: boolean;
|
|
78
|
+
}): string;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
|
|
2
|
+
// src/three-openvdb/frame/webgpu/FrameIntegrateMaterial.js L33–138 (sRGB blending, scene depth, empty
|
|
3
|
+
// depth), L219–294 (the slice march and composite: the `sliceAlpha` coverage of the cut slice).
|
|
4
|
+
// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
|
|
5
|
+
// Changes: two taps of the integrated prefix at the slice boundaries replace the per-pixel slice march
|
|
6
|
+
// (design §3.4; the same partial-slice formula); x, y filtering acts on the prefix. Divergences:
|
|
7
|
+
// DIVERGES.md (K6.1 rows).
|
|
8
|
+
import { VDB_FRAME_UNIFORMS } from "../uniforms.js";
|
|
9
|
+
/** `fn vdbFrameSliceCoord(viewDepth, range, depth) -> vec2f`: (slice k, his coverage c of slice k). */
|
|
10
|
+
export const VDB_FRAME_SLICE_COORD_WGSL = `fn vdbFrameSliceCoord(viewDepth: f32, range: vec2f, depth: f32) -> vec2f {
|
|
11
|
+
let ratio = range.y / range.x;
|
|
12
|
+
let s = clamp(depth * log(max(viewDepth, range.x) / range.x) / log(ratio), 0.0, depth);
|
|
13
|
+
let k = min(floor(s), depth - 1.0);
|
|
14
|
+
let start = range.x * pow(ratio, k / depth);
|
|
15
|
+
let end = range.x * pow(ratio, (k + 1.0) / depth);
|
|
16
|
+
return vec2f(k, clamp((viewDepth - start) / (end - start), 0.0, 1.0));
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
/** `fn vdbFrameIntegrateTaps(a, b, c) -> vec4f`: boundaries a, b = (L, 1 − T); returns (radiance, T). */
|
|
20
|
+
export const VDB_FRAME_INTEGRATE_TAPS_WGSL = `fn vdbFrameIntegrateTaps(a: vec4f, b: vec4f, c: f32) -> vec4f {
|
|
21
|
+
let ta = 1.0 - a.w;
|
|
22
|
+
let tb = 1.0 - b.w;
|
|
23
|
+
let alpha = clamp(select(0.0, 1.0 - tb / ta, ta > 1e-6), 0.0, 1.0);
|
|
24
|
+
let keep = select(pow(max(1.0 - alpha, 1e-30), c), 1.0, c <= 0.0);
|
|
25
|
+
let w = select(c, (1.0 - keep) / alpha, alpha > 1e-4);
|
|
26
|
+
return vec4f(a.rgb + (b.rgb - a.rgb) * w, max(ta, 0.0) * keep);
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
/** three's `sRGBTransferOETF` as `fn vdbFrameSrgbOetfColor(color: vec3f) -> vec3f`. */
|
|
30
|
+
export const VDB_FRAME_SRGB_OETF_WGSL = `fn vdbFrameSrgbOetfColor(color: vec3f) -> vec3f {
|
|
31
|
+
let a = pow(color, vec3f(0.41666)) * 1.055 - 0.055;
|
|
32
|
+
return select(a, color * 12.92, color <= vec3f(0.0031308));
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
/** three's `sRGBTransferEOTF` as `fn vdbFrameSrgbEotfColor(color: vec3f) -> vec3f`. */
|
|
36
|
+
export const VDB_FRAME_SRGB_EOTF_WGSL = `fn vdbFrameSrgbEotfColor(color: vec3f) -> vec3f {
|
|
37
|
+
let a = pow(color * 0.9478672986 + 0.0521327014, vec3f(2.4));
|
|
38
|
+
return select(a, color * 0.0773993808, color <= vec3f(0.04045));
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
/**
|
|
42
|
+
* `fn vdbFrameCompositeColor(r: vec4f, sceneColor: vec4f, srgb: u32, clampColors: u32) -> vec4f` (needs the two
|
|
43
|
+
* sRGB functions): r = (radiance, T). sRGB: his WebGLRenderer-like blend; else premultiplied (radiance, α).
|
|
44
|
+
*/
|
|
45
|
+
export const VDB_FRAME_COMPOSITE_COLOR_FN_WGSL = `fn vdbFrameCompositeColor(r: vec4f, sceneColor: vec4f, srgb: u32, clampColors: u32) -> vec4f {
|
|
46
|
+
let alpha = 1.0 - r.w;
|
|
47
|
+
if (srgb == 0u) {
|
|
48
|
+
return vec4f(r.rgb, alpha);
|
|
49
|
+
}
|
|
50
|
+
var volumeColor = vdbFrameSrgbOetfColor(r.rgb / alpha);
|
|
51
|
+
var backgroundColor = vdbFrameSrgbOetfColor(sceneColor.rgb);
|
|
52
|
+
if (clampColors != 0u) {
|
|
53
|
+
volumeColor = clamp(volumeColor, vec3f(0.0), vec3f(1.0));
|
|
54
|
+
backgroundColor = clamp(backgroundColor, vec3f(0.0), vec3f(1.0));
|
|
55
|
+
}
|
|
56
|
+
return vec4f(vdbFrameSrgbEotfColor(mix(backgroundColor, volumeColor, vec3f(alpha))), alpha + sceneColor.a * (1.0 - alpha));
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
/** The sRGB functions and `vdbFrameCompositeColor`. */
|
|
60
|
+
export const VDB_FRAME_COMPOSITE_COLOR_WGSL = `${VDB_FRAME_SRGB_OETF_WGSL}${VDB_FRAME_SRGB_EOTF_WGSL}${VDB_FRAME_COMPOSITE_COLOR_FN_WGSL}`;
|
|
61
|
+
/**
|
|
62
|
+
* K6.4 `fn vdbFrameCompositeSpectralColor(radiance: vec3f, transmittance: vec3f, sceneColor: vec4f, srgb: u32, clampColors: u32)
|
|
63
|
+
* -> vec4f` (needs the two sRGB functions): his spectral composite (FrameIntegrateMaterial L171–216): the scene colour ×
|
|
64
|
+
* the transmittance of each channel + the radiance, or (sRGB) the per-channel mix in sRGB; alpha from green. It blends
|
|
65
|
+
* itself: the pass draws without hardware blending.
|
|
66
|
+
*/
|
|
67
|
+
export const VDB_FRAME_COMPOSITE_SPECTRAL_FN_WGSL = `fn vdbFrameCompositeSpectralColor(radiance: vec3f, transmittance: vec3f, sceneColor: vec4f, srgb: u32, clampColors: u32) -> vec4f {
|
|
68
|
+
let alpha = vec3f(1.0) - transmittance;
|
|
69
|
+
let outputAlpha = alpha.y + sceneColor.a * (1.0 - alpha.y);
|
|
70
|
+
if (srgb == 0u) {
|
|
71
|
+
return vec4f(radiance + sceneColor.rgb * transmittance, outputAlpha);
|
|
72
|
+
}
|
|
73
|
+
var volumeColor = vdbFrameSrgbOetfColor(radiance / max(alpha, vec3f(1e-6)));
|
|
74
|
+
var backgroundColor = vdbFrameSrgbOetfColor(sceneColor.rgb);
|
|
75
|
+
if (clampColors != 0u) {
|
|
76
|
+
volumeColor = clamp(volumeColor, vec3f(0.0), vec3f(1.0));
|
|
77
|
+
backgroundColor = clamp(backgroundColor, vec3f(0.0), vec3f(1.0));
|
|
78
|
+
}
|
|
79
|
+
return vec4f(vdbFrameSrgbEotfColor(mix(backgroundColor, volumeColor, alpha)), outputAlpha);
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
/** The pure integrate functions, keyed by name (one function each, for `wgslFn`). */
|
|
83
|
+
export const VDB_FRAME_INTEGRATE_FUNCTIONS = {
|
|
84
|
+
vdbFrameSliceCoord: VDB_FRAME_SLICE_COORD_WGSL,
|
|
85
|
+
vdbFrameIntegrateTaps: VDB_FRAME_INTEGRATE_TAPS_WGSL,
|
|
86
|
+
};
|
|
87
|
+
/** The integrate seam's WGSL (design §2.5). */
|
|
88
|
+
export function vdbFrameIntegrateWgsl(o = {}) {
|
|
89
|
+
const slot = o.slot ?? { group: 0, firstBinding: 0 };
|
|
90
|
+
const g = slot.group;
|
|
91
|
+
const b = slot.firstBinding;
|
|
92
|
+
const spectral = !!o.spectral;
|
|
93
|
+
const uniforms = o.sharedUniforms
|
|
94
|
+
? ""
|
|
95
|
+
: `${VDB_FRAME_UNIFORMS.wgsl}@group(${g}) @binding(${b + 2}) var<uniform> vdbFrame: VdbFrameUniforms;\n`;
|
|
96
|
+
// K6.4 spectral: the same two-tap formula for each channel, the opacity of red and blue from the alpha prefix
|
|
97
|
+
const taps = spectral
|
|
98
|
+
? ` let aAlpha = textureSampleLevel(vdbFrameIntegratedAlphaMap, vdbFrameIntegratedSampler, vec3f(xy, (kc.x + 0.5) / (grid.z + 1.0)), 0.0);
|
|
99
|
+
let bAlpha = textureSampleLevel(vdbFrameIntegratedAlphaMap, vdbFrameIntegratedSampler, vec3f(xy, (kc.x + 1.5) / (grid.z + 1.0)), 0.0);
|
|
100
|
+
let r = vdbFrameIntegrateTaps(vec4f(a.x, 0.0, 0.0, aAlpha.x), vec4f(b.x, 0.0, 0.0, bAlpha.x), kc.y);
|
|
101
|
+
let gg = vdbFrameIntegrateTaps(vec4f(a.y, 0.0, 0.0, a.w), vec4f(b.y, 0.0, 0.0, b.w), kc.y);
|
|
102
|
+
let bb = vdbFrameIntegrateTaps(vec4f(a.z, 0.0, 0.0, aAlpha.y), vec4f(b.z, 0.0, 0.0, bAlpha.y), kc.y);
|
|
103
|
+
return VdbFrameIntegrated(vec3f(r.x, gg.x, bb.x), vec3f(r.w, gg.w, bb.w));`
|
|
104
|
+
: ` let r = vdbFrameIntegrateTaps(a, b, kc.y);
|
|
105
|
+
return VdbFrameIntegrated(r.rgb, vec3f(r.w));`;
|
|
106
|
+
const composite = spectral
|
|
107
|
+
? `// K6.4 spectral: the scene colour x the transmittance of each channel + the radiance (or the per-channel sRGB mix); the
|
|
108
|
+
// result replaces the scene colour (draw without blending)
|
|
109
|
+
fn vdbFrameComposite(i: VdbFrameIntegrated, sceneColor: vec4f, srgbBlending: bool) -> vec4f {
|
|
110
|
+
return vdbFrameCompositeSpectralColor(i.radiance, i.transmittance, sceneColor, select(0u, 1u, srgbBlending), select(0u, 1u, vdbFrame.screen.z > 0.5));
|
|
111
|
+
}`
|
|
112
|
+
: `// The volumes over the scene colour: sRGB blending as WebGLRenderer (srgbBlending, clamped to [0, 1]
|
|
113
|
+
// without tone mapping) or premultiplied (blend with one, one-minus-src-alpha).
|
|
114
|
+
fn vdbFrameComposite(i: VdbFrameIntegrated, sceneColor: vec4f, srgbBlending: bool) -> vec4f {
|
|
115
|
+
return vdbFrameCompositeColor(vec4f(i.radiance, i.transmittance.y), sceneColor, select(0u, 1u, srgbBlending), select(0u, 1u, vdbFrame.screen.z > 0.5));
|
|
116
|
+
}`;
|
|
117
|
+
return `${uniforms}@group(${g}) @binding(${b}) var vdbFrameIntegratedMap: texture_3d<f32>;
|
|
118
|
+
@group(${g}) @binding(${b + 1}) var vdbFrameIntegratedSampler: sampler;
|
|
119
|
+
${spectral ? `@group(${g}) @binding(${o.alphaBinding ?? b + 3}) var vdbFrameIntegratedAlphaMap: texture_3d<f32>;\n` : ""}
|
|
120
|
+
struct VdbFrameIntegrated {
|
|
121
|
+
radiance: vec3f,
|
|
122
|
+
transmittance: vec3f,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
${VDB_FRAME_SLICE_COORD_WGSL}
|
|
126
|
+
${VDB_FRAME_INTEGRATE_TAPS_WGSL}
|
|
127
|
+
${VDB_FRAME_COMPOSITE_COLOR_WGSL}${spectral ? VDB_FRAME_COMPOSITE_SPECTRAL_FN_WGSL : ""}
|
|
128
|
+
// The volumes in front of the scene depth at a screen position (bottom-left uv): two taps of the prefix
|
|
129
|
+
// at the boundaries around the depth's slice, bilinear in x, y.
|
|
130
|
+
fn vdbFrameIntegrate(screenUv: vec2f, sceneViewDepth: f32) -> VdbFrameIntegrated {
|
|
131
|
+
let grid = vdbFrame.grid.xyz;
|
|
132
|
+
let kc = vdbFrameSliceCoord(sceneViewDepth, vdbFrame.range.xy, grid.z);
|
|
133
|
+
let xy = clamp(screenUv * grid.xy, vec2f(0.5), grid.xy - 0.5) / grid.xy;
|
|
134
|
+
let a = textureSampleLevel(vdbFrameIntegratedMap, vdbFrameIntegratedSampler, vec3f(xy, (kc.x + 0.5) / (grid.z + 1.0)), 0.0);
|
|
135
|
+
let b = textureSampleLevel(vdbFrameIntegratedMap, vdbFrameIntegratedSampler, vec3f(xy, (kc.x + 1.5) / (grid.z + 1.0)), 0.0);
|
|
136
|
+
${taps}
|
|
137
|
+
}
|
|
138
|
+
${composite}
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Bind group layout entries of {@link vdbFrameIntegrateWgsl} at `slot`: texture, filtering sampler, uniforms (K6.4
|
|
143
|
+
* `spectral`: the alpha prefix at `alphaBinding`, default `firstBinding + 3`).
|
|
144
|
+
*/
|
|
145
|
+
export function vdbFrameIntegrateEntries(slot = { group: 0, firstBinding: 0 }, visibility = 0x2 /* FRAGMENT */, sharedUniforms = false, spectral = false) {
|
|
146
|
+
const b = slot.firstBinding;
|
|
147
|
+
return [
|
|
148
|
+
{ binding: b, visibility, texture: { sampleType: "float", viewDimension: "3d" } },
|
|
149
|
+
{ binding: b + 1, visibility, sampler: { type: "filtering" } },
|
|
150
|
+
...(sharedUniforms ? [] : [{ binding: b + 2, visibility, buffer: { type: "uniform" } }]),
|
|
151
|
+
...(spectral ? [{ binding: spectral.alphaBinding ?? b + 3, visibility, texture: { sampleType: "float", viewDimension: "3d" } }] : []),
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
/** Group-1 binding of the composite pass's alpha prefix (K6.4 spectral; 3 is the scene colour). */
|
|
155
|
+
export const VDB_FRAME_COMPOSITE_ALPHA_BINDING = 4;
|
|
156
|
+
/**
|
|
157
|
+
* The core composite pass's WGSL (after the frame uniforms): a fullscreen triangle scissored by the host call. K6.4
|
|
158
|
+
* `spectral`: the alpha prefix at binding 4 and the scene colour (binding 3) always; the pass draws without blending.
|
|
159
|
+
*/
|
|
160
|
+
export function vdbFrameCompositeWgsl(o) {
|
|
161
|
+
const depthType = o.depth === "depth" ? "texture_depth_2d" : "texture_2d<f32>";
|
|
162
|
+
const depthRead = o.depth === "depth" ? "textureLoad(vdbFrameSceneDepth, pixel, 0)" : "textureLoad(vdbFrameSceneDepth, pixel, 0).r";
|
|
163
|
+
const spectral = !!o.spectral;
|
|
164
|
+
const sceneColor = o.srgb || spectral;
|
|
165
|
+
const result = spectral
|
|
166
|
+
? `if (min(integrated.transmittance.x, min(integrated.transmittance.y, integrated.transmittance.z)) >= 1.0) {
|
|
167
|
+
discard;
|
|
168
|
+
}
|
|
169
|
+
return vdbFrameComposite(integrated, textureLoad(vdbFrameSceneColor, pixel, 0), ${o.srgb ? "true" : "false"});`
|
|
170
|
+
: `if (integrated.transmittance.y >= 1.0) {
|
|
171
|
+
discard;
|
|
172
|
+
}
|
|
173
|
+
${o.srgb ? "return vdbFrameComposite(integrated, textureLoad(vdbFrameSceneColor, pixel, 0), true);" : "return vdbFrameComposite(integrated, vec4f(0.0), false);"}`;
|
|
174
|
+
return `${vdbFrameIntegrateWgsl({ slot: { group: 1, firstBinding: 0 }, sharedUniforms: true, spectral, alphaBinding: VDB_FRAME_COMPOSITE_ALPHA_BINDING })}
|
|
175
|
+
@group(1) @binding(2) var vdbFrameSceneDepth: ${depthType};
|
|
176
|
+
${sceneColor ? "@group(1) @binding(3) var vdbFrameSceneColor: texture_2d<f32>;" : ""}
|
|
177
|
+
|
|
178
|
+
// The scene's view depth (three's perspective / orthographic depthToViewZ); empty depth: 1e20
|
|
179
|
+
fn vdbFrameSceneViewDepth(depth: f32) -> f32 {
|
|
180
|
+
let near = vdbFrame.camera.x;
|
|
181
|
+
let far = vdbFrame.camera.y;
|
|
182
|
+
let reversed = (vdbFrame.flags.z & 1u) != 0u;
|
|
183
|
+
let orthographic = (vdbFrame.flags.z & 2u) != 0u;
|
|
184
|
+
let empty = select(depth >= 1.0, depth <= 0.0, reversed);
|
|
185
|
+
if (empty) {
|
|
186
|
+
return 1e20;
|
|
187
|
+
}
|
|
188
|
+
var viewZ: f32;
|
|
189
|
+
if (orthographic) {
|
|
190
|
+
viewZ = select((near - far) * depth - near, (far - near) * depth - far, reversed);
|
|
191
|
+
} else {
|
|
192
|
+
viewZ = select(near * far / ((far - near) * depth - far), near * far / ((near - far) * depth - near), reversed);
|
|
193
|
+
}
|
|
194
|
+
return -viewZ;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@vertex
|
|
198
|
+
fn vdbFrameCompositeVs(@builtin(vertex_index) index: u32) -> @builtin(position) vec4f {
|
|
199
|
+
let corner = vec2f(f32((index << 1u) & 2u), f32(index & 2u));
|
|
200
|
+
return vec4f(corner * 2.0 - 1.0, 0.0, 1.0);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@fragment
|
|
204
|
+
fn vdbFrameCompositeFs(@builtin(position) fragCoord: vec4f) -> @location(0) vec4f {
|
|
205
|
+
let pixel = vec2i(fragCoord.xy);
|
|
206
|
+
let size = vdbFrame.screen.xy;
|
|
207
|
+
let screenUv = vec2f(fragCoord.x / size.x, 1.0 - fragCoord.y / size.y);
|
|
208
|
+
let integrated = vdbFrameIntegrate(screenUv, vdbFrameSceneViewDepth(${depthRead}));
|
|
209
|
+
${result}
|
|
210
|
+
}
|
|
211
|
+
`;
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=integrate.js.map
|
|
@@ -0,0 +1 @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,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,iCAAiC,EAAE,CAAC;gDAC3G,SAAS;EACvD,UAAU,CAAC,CAAC,CAAC,gEAAgE,CAAC,CAAC,CAAC,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wEAgCZ,SAAS;IAC7E,MAAM;;CAET,CAAC;AACF,CAAC","sourcesContent":["// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):\n// src/three-openvdb/frame/webgpu/FrameIntegrateMaterial.js L33–138 (sRGB blending, scene depth, empty\n// depth), L219–294 (the slice march and composite: the `sliceAlpha` coverage of the cut slice).\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: two taps of the integrated prefix at the slice boundaries replace the per-pixel slice march\n// (design §3.4; the same partial-slice formula); x, y filtering acts on the prefix. Divergences:\n// DIVERGES.md (K6.1 rows).\n\n/**\n * The composite seam (design §2.5): `vdbFrameIntegrateWgsl()` gives hosts\n *\n * struct VdbFrameIntegrated { radiance: vec3f, transmittance: vec3f }\n * fn vdbFrameIntegrate(screenUv: vec2f, sceneViewDepth: f32) -> VdbFrameIntegrated;\n * fn vdbFrameComposite(i: VdbFrameIntegrated, sceneColor: vec4f, srgbBlending: bool) -> vec4f;\n *\n * over `outputs.froxels.integrated` (bind with `vdbFrameIntegrateEntries`), and the core composite pass\n * calls the same functions. The pure functions (no bindings) are also exported one by one for hosts that\n * sample the prefix themselves (`./three` through `wgslFn`). CPU twins: tools/frame `vdbFrameSliceCoord`,\n * `vdbFrameIntegratePrefix`, `vdbFrameSrgbBlend`.\n */\n\nimport type { VDBSlot } from \"../../types.js\";\nimport { VDB_FRAME_UNIFORMS } from \"../uniforms.js\";\n\n/** `fn vdbFrameSliceCoord(viewDepth, range, depth) -> vec2f`: (slice k, his coverage c of slice k). */\nexport const VDB_FRAME_SLICE_COORD_WGSL = `fn vdbFrameSliceCoord(viewDepth: f32, range: vec2f, depth: f32) -> vec2f {\n let ratio = range.y / range.x;\n let s = clamp(depth * log(max(viewDepth, range.x) / range.x) / log(ratio), 0.0, depth);\n let k = min(floor(s), depth - 1.0);\n let start = range.x * pow(ratio, k / depth);\n let end = range.x * pow(ratio, (k + 1.0) / depth);\n return vec2f(k, clamp((viewDepth - start) / (end - start), 0.0, 1.0));\n}\n`;\n\n/** `fn vdbFrameIntegrateTaps(a, b, c) -> vec4f`: boundaries a, b = (L, 1 − T); returns (radiance, T). */\nexport const VDB_FRAME_INTEGRATE_TAPS_WGSL = `fn vdbFrameIntegrateTaps(a: vec4f, b: vec4f, c: f32) -> vec4f {\n let ta = 1.0 - a.w;\n let tb = 1.0 - b.w;\n let alpha = clamp(select(0.0, 1.0 - tb / ta, ta > 1e-6), 0.0, 1.0);\n let keep = select(pow(max(1.0 - alpha, 1e-30), c), 1.0, c <= 0.0);\n let w = select(c, (1.0 - keep) / alpha, alpha > 1e-4);\n return vec4f(a.rgb + (b.rgb - a.rgb) * w, max(ta, 0.0) * keep);\n}\n`;\n\n/** three's `sRGBTransferOETF` as `fn vdbFrameSrgbOetfColor(color: vec3f) -> vec3f`. */\nexport const VDB_FRAME_SRGB_OETF_WGSL = `fn vdbFrameSrgbOetfColor(color: vec3f) -> vec3f {\n let a = pow(color, vec3f(0.41666)) * 1.055 - 0.055;\n return select(a, color * 12.92, color <= vec3f(0.0031308));\n}\n`;\n\n/** three's `sRGBTransferEOTF` as `fn vdbFrameSrgbEotfColor(color: vec3f) -> vec3f`. */\nexport const VDB_FRAME_SRGB_EOTF_WGSL = `fn vdbFrameSrgbEotfColor(color: vec3f) -> vec3f {\n let a = pow(color * 0.9478672986 + 0.0521327014, vec3f(2.4));\n return select(a, color * 0.0773993808, color <= vec3f(0.04045));\n}\n`;\n\n/**\n * `fn vdbFrameCompositeColor(r: vec4f, sceneColor: vec4f, srgb: u32, clampColors: u32) -> vec4f` (needs the two\n * sRGB functions): r = (radiance, T). sRGB: his WebGLRenderer-like blend; else premultiplied (radiance, α).\n */\nexport const VDB_FRAME_COMPOSITE_COLOR_FN_WGSL = `fn vdbFrameCompositeColor(r: vec4f, sceneColor: vec4f, srgb: u32, clampColors: u32) -> vec4f {\n let alpha = 1.0 - r.w;\n if (srgb == 0u) {\n return vec4f(r.rgb, alpha);\n }\n var volumeColor = vdbFrameSrgbOetfColor(r.rgb / alpha);\n var backgroundColor = vdbFrameSrgbOetfColor(sceneColor.rgb);\n if (clampColors != 0u) {\n volumeColor = clamp(volumeColor, vec3f(0.0), vec3f(1.0));\n backgroundColor = clamp(backgroundColor, vec3f(0.0), vec3f(1.0));\n }\n return vec4f(vdbFrameSrgbEotfColor(mix(backgroundColor, volumeColor, vec3f(alpha))), alpha + sceneColor.a * (1.0 - alpha));\n}\n`;\n\n/** The sRGB functions and `vdbFrameCompositeColor`. */\nexport const VDB_FRAME_COMPOSITE_COLOR_WGSL = `${VDB_FRAME_SRGB_OETF_WGSL}${VDB_FRAME_SRGB_EOTF_WGSL}${VDB_FRAME_COMPOSITE_COLOR_FN_WGSL}`;\n\n/**\n * K6.4 `fn vdbFrameCompositeSpectralColor(radiance: vec3f, transmittance: vec3f, sceneColor: vec4f, srgb: u32, clampColors: u32)\n * -> vec4f` (needs the two sRGB functions): his spectral composite (FrameIntegrateMaterial L171–216): the scene colour ×\n * the transmittance of each channel + the radiance, or (sRGB) the per-channel mix in sRGB; alpha from green. It blends\n * itself: the pass draws without hardware blending.\n */\nexport const VDB_FRAME_COMPOSITE_SPECTRAL_FN_WGSL = `fn vdbFrameCompositeSpectralColor(radiance: vec3f, transmittance: vec3f, sceneColor: vec4f, srgb: u32, clampColors: u32) -> vec4f {\n let alpha = vec3f(1.0) - transmittance;\n let outputAlpha = alpha.y + sceneColor.a * (1.0 - alpha.y);\n if (srgb == 0u) {\n return vec4f(radiance + sceneColor.rgb * transmittance, outputAlpha);\n }\n var volumeColor = vdbFrameSrgbOetfColor(radiance / max(alpha, vec3f(1e-6)));\n var backgroundColor = vdbFrameSrgbOetfColor(sceneColor.rgb);\n if (clampColors != 0u) {\n volumeColor = clamp(volumeColor, vec3f(0.0), vec3f(1.0));\n backgroundColor = clamp(backgroundColor, vec3f(0.0), vec3f(1.0));\n }\n return vec4f(vdbFrameSrgbEotfColor(mix(backgroundColor, volumeColor, alpha)), outputAlpha);\n}\n`;\n\n/** The pure integrate functions, keyed by name (one function each, for `wgslFn`). */\nexport const VDB_FRAME_INTEGRATE_FUNCTIONS = {\n vdbFrameSliceCoord: VDB_FRAME_SLICE_COORD_WGSL,\n vdbFrameIntegrateTaps: VDB_FRAME_INTEGRATE_TAPS_WGSL,\n} as const;\n\n/** Options of {@link vdbFrameIntegrateWgsl}. */\nexport interface VDBFrameIntegrateWgslOptions {\n /**\n * K6.4 spectral: a second prefix (`outputs.froxels.integratedAlpha`: the red and blue opacity) at `alphaBinding`;\n * `vdbFrameIntegrate` returns the transmittance of each channel and `vdbFrameComposite` blends itself (no hardware\n * blending: one alpha cannot carry three transmittances), so the host passes the scene colour.\n */\n readonly spectral?: boolean;\n /** K6.4: the binding of the spectral alpha prefix in the slot's group (default `slot.firstBinding + 3`). */\n readonly alphaBinding?: number;\n /** Where the three bindings start (texture, sampler, `VdbFrameUniforms`); default group 0, binding 0. */\n readonly slot?: VDBSlot;\n /**\n * Use the frame uniforms already declared as `vdbFrame` (the core composite) instead of declaring the\n * struct and its binding; the texture and sampler are still declared at `slot`.\n */\n readonly sharedUniforms?: boolean;\n}\n\n/** The integrate seam's WGSL (design §2.5). */\nexport function vdbFrameIntegrateWgsl(o: VDBFrameIntegrateWgslOptions = {}): string {\n const slot = o.slot ?? { group: 0, firstBinding: 0 };\n const g = slot.group;\n const b = slot.firstBinding;\n const spectral = !!o.spectral;\n const uniforms = o.sharedUniforms\n ? \"\"\n : `${VDB_FRAME_UNIFORMS.wgsl}@group(${g}) @binding(${b + 2}) var<uniform> vdbFrame: VdbFrameUniforms;\\n`;\n // K6.4 spectral: the same two-tap formula for each channel, the opacity of red and blue from the alpha prefix\n const taps = spectral\n ? ` let aAlpha = textureSampleLevel(vdbFrameIntegratedAlphaMap, vdbFrameIntegratedSampler, vec3f(xy, (kc.x + 0.5) / (grid.z + 1.0)), 0.0);\n let bAlpha = textureSampleLevel(vdbFrameIntegratedAlphaMap, vdbFrameIntegratedSampler, vec3f(xy, (kc.x + 1.5) / (grid.z + 1.0)), 0.0);\n let r = vdbFrameIntegrateTaps(vec4f(a.x, 0.0, 0.0, aAlpha.x), vec4f(b.x, 0.0, 0.0, bAlpha.x), kc.y);\n let gg = vdbFrameIntegrateTaps(vec4f(a.y, 0.0, 0.0, a.w), vec4f(b.y, 0.0, 0.0, b.w), kc.y);\n let bb = vdbFrameIntegrateTaps(vec4f(a.z, 0.0, 0.0, aAlpha.y), vec4f(b.z, 0.0, 0.0, bAlpha.y), kc.y);\n return VdbFrameIntegrated(vec3f(r.x, gg.x, bb.x), vec3f(r.w, gg.w, bb.w));`\n : ` let r = vdbFrameIntegrateTaps(a, b, kc.y);\n return VdbFrameIntegrated(r.rgb, vec3f(r.w));`;\n const composite = spectral\n ? `// K6.4 spectral: the scene colour x the transmittance of each channel + the radiance (or the per-channel sRGB mix); the\n// result replaces the scene colour (draw without blending)\nfn vdbFrameComposite(i: VdbFrameIntegrated, sceneColor: vec4f, srgbBlending: bool) -> vec4f {\n return vdbFrameCompositeSpectralColor(i.radiance, i.transmittance, sceneColor, select(0u, 1u, srgbBlending), select(0u, 1u, vdbFrame.screen.z > 0.5));\n}`\n : `// The volumes over the scene colour: sRGB blending as WebGLRenderer (srgbBlending, clamped to [0, 1]\n// without tone mapping) or premultiplied (blend with one, one-minus-src-alpha).\nfn vdbFrameComposite(i: VdbFrameIntegrated, sceneColor: vec4f, srgbBlending: bool) -> vec4f {\n return vdbFrameCompositeColor(vec4f(i.radiance, i.transmittance.y), sceneColor, select(0u, 1u, srgbBlending), select(0u, 1u, vdbFrame.screen.z > 0.5));\n}`;\n return `${uniforms}@group(${g}) @binding(${b}) var vdbFrameIntegratedMap: texture_3d<f32>;\n@group(${g}) @binding(${b + 1}) var vdbFrameIntegratedSampler: sampler;\n${spectral ? `@group(${g}) @binding(${o.alphaBinding ?? b + 3}) var vdbFrameIntegratedAlphaMap: texture_3d<f32>;\\n` : \"\"}\nstruct VdbFrameIntegrated {\n radiance: vec3f,\n transmittance: vec3f,\n};\n\n${VDB_FRAME_SLICE_COORD_WGSL}\n${VDB_FRAME_INTEGRATE_TAPS_WGSL}\n${VDB_FRAME_COMPOSITE_COLOR_WGSL}${spectral ? VDB_FRAME_COMPOSITE_SPECTRAL_FN_WGSL : \"\"}\n// The volumes in front of the scene depth at a screen position (bottom-left uv): two taps of the prefix\n// at the boundaries around the depth's slice, bilinear in x, y.\nfn vdbFrameIntegrate(screenUv: vec2f, sceneViewDepth: f32) -> VdbFrameIntegrated {\n let grid = vdbFrame.grid.xyz;\n let kc = vdbFrameSliceCoord(sceneViewDepth, vdbFrame.range.xy, grid.z);\n let xy = clamp(screenUv * grid.xy, vec2f(0.5), grid.xy - 0.5) / grid.xy;\n let a = textureSampleLevel(vdbFrameIntegratedMap, vdbFrameIntegratedSampler, vec3f(xy, (kc.x + 0.5) / (grid.z + 1.0)), 0.0);\n let b = textureSampleLevel(vdbFrameIntegratedMap, vdbFrameIntegratedSampler, vec3f(xy, (kc.x + 1.5) / (grid.z + 1.0)), 0.0);\n${taps}\n}\n${composite}\n`;\n}\n\n/**\n * Bind group layout entries of {@link vdbFrameIntegrateWgsl} at `slot`: texture, filtering sampler, uniforms (K6.4\n * `spectral`: the alpha prefix at `alphaBinding`, default `firstBinding + 3`).\n */\nexport function vdbFrameIntegrateEntries(\n slot: VDBSlot = { group: 0, firstBinding: 0 },\n visibility: GPUShaderStageFlags = 0x2 /* FRAGMENT */,\n sharedUniforms = false,\n spectral: { alphaBinding?: number } | false = false,\n): GPUBindGroupLayoutEntry[] {\n const b = slot.firstBinding;\n return [\n { binding: b, visibility, texture: { sampleType: \"float\", viewDimension: \"3d\" } },\n { binding: b + 1, visibility, sampler: { type: \"filtering\" } },\n ...(sharedUniforms ? [] : [{ binding: b + 2, visibility, buffer: { type: \"uniform\" as const } }]),\n ...(spectral ? [{ binding: spectral.alphaBinding ?? b + 3, visibility, texture: { sampleType: \"float\" as const, viewDimension: \"3d\" as const } }] : []),\n ];\n}\n\n/** Group-1 binding of the composite pass's alpha prefix (K6.4 spectral; 3 is the scene colour). */\nexport const VDB_FRAME_COMPOSITE_ALPHA_BINDING = 4;\n\n/**\n * The core composite pass's WGSL (after the frame uniforms): a fullscreen triangle scissored by the host call. K6.4\n * `spectral`: the alpha prefix at binding 4 and the scene colour (binding 3) always; the pass draws without blending.\n */\nexport function vdbFrameCompositeWgsl(o: { depth: \"depth\" | \"r32float\"; srgb: boolean; spectral?: boolean }): string {\n const depthType = o.depth === \"depth\" ? \"texture_depth_2d\" : \"texture_2d<f32>\";\n const depthRead = o.depth === \"depth\" ? \"textureLoad(vdbFrameSceneDepth, pixel, 0)\" : \"textureLoad(vdbFrameSceneDepth, pixel, 0).r\";\n const spectral = !!o.spectral;\n const sceneColor = o.srgb || spectral;\n const result = spectral\n ? `if (min(integrated.transmittance.x, min(integrated.transmittance.y, integrated.transmittance.z)) >= 1.0) {\n discard;\n }\n return vdbFrameComposite(integrated, textureLoad(vdbFrameSceneColor, pixel, 0), ${o.srgb ? \"true\" : \"false\"});`\n : `if (integrated.transmittance.y >= 1.0) {\n discard;\n }\n ${o.srgb ? \"return vdbFrameComposite(integrated, textureLoad(vdbFrameSceneColor, pixel, 0), true);\" : \"return vdbFrameComposite(integrated, vec4f(0.0), false);\"}`;\n return `${vdbFrameIntegrateWgsl({ slot: { group: 1, firstBinding: 0 }, sharedUniforms: true, spectral, alphaBinding: VDB_FRAME_COMPOSITE_ALPHA_BINDING })}\n@group(1) @binding(2) var vdbFrameSceneDepth: ${depthType};\n${sceneColor ? \"@group(1) @binding(3) var vdbFrameSceneColor: texture_2d<f32>;\" : \"\"}\n\n// The scene's view depth (three's perspective / orthographic depthToViewZ); empty depth: 1e20\nfn vdbFrameSceneViewDepth(depth: f32) -> f32 {\n let near = vdbFrame.camera.x;\n let far = vdbFrame.camera.y;\n let reversed = (vdbFrame.flags.z & 1u) != 0u;\n let orthographic = (vdbFrame.flags.z & 2u) != 0u;\n let empty = select(depth >= 1.0, depth <= 0.0, reversed);\n if (empty) {\n return 1e20;\n }\n var viewZ: f32;\n if (orthographic) {\n viewZ = select((near - far) * depth - near, (far - near) * depth - far, reversed);\n } else {\n viewZ = select(near * far / ((far - near) * depth - far), near * far / ((near - far) * depth - near), reversed);\n }\n return -viewZ;\n}\n\n@vertex\nfn vdbFrameCompositeVs(@builtin(vertex_index) index: u32) -> @builtin(position) vec4f {\n let corner = vec2f(f32((index << 1u) & 2u), f32(index & 2u));\n return vec4f(corner * 2.0 - 1.0, 0.0, 1.0);\n}\n\n@fragment\nfn vdbFrameCompositeFs(@builtin(position) fragCoord: vec4f) -> @location(0) vec4f {\n let pixel = vec2i(fragCoord.xy);\n let size = vdbFrame.screen.xy;\n let screenUv = vec2f(fragCoord.x / size.x, 1.0 - fragCoord.y / size.y);\n let integrated = vdbFrameIntegrate(screenUv, vdbFrameSceneViewDepth(${depthRead}));\n ${result}\n}\n`;\n}\n"]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The 'frame' lighting kernels of the core renderer (K6.2):
|
|
3
|
+
*
|
|
4
|
+
* - `vdbFrameGridDensityCs` (per caster source group, 4×4×4): the extinction and absorption of the group's
|
|
5
|
+
* casters at each shadow grid voxel of every cascade (his shadow density pass, additive).
|
|
6
|
+
* - `vdbFrameTransmittanceCs` (source-free, 4×4×4): from each voxel the march through the grid toward the light
|
|
7
|
+
* slots and the sky up and down; four sub-volumes per cascade (his 4 MRT targets).
|
|
8
|
+
* - `vdbFrameGatherCs` 'frame' (per source group, 8×8×1): his density pass per volume (the slice pre-integration,
|
|
9
|
+
* the visible position, the shadow slots there) summed extinction-weighted in registers, then (last group) his
|
|
10
|
+
* lighting pass on the sums: premultiplied (radiance·α, α) into the scatter texture.
|
|
11
|
+
*/
|
|
12
|
+
import type { VDBVolumeChannels } from "../../source/types.js";
|
|
13
|
+
/** Group-1 bindings of the shadow grid density kernel (K6.4 spectral: the absorption stack beside the extinction one). */
|
|
14
|
+
export declare const GRID_DENSITY_BINDINGS: {
|
|
15
|
+
readonly volumes: 0;
|
|
16
|
+
readonly group: 1;
|
|
17
|
+
readonly grid: 2;
|
|
18
|
+
readonly partials: 3;
|
|
19
|
+
readonly absorption: 4;
|
|
20
|
+
};
|
|
21
|
+
/** Group-1 bindings of the transmittance kernel (K6.4 spectral: the absorption stack). */
|
|
22
|
+
export declare const TRANSMITTANCE_BINDINGS: {
|
|
23
|
+
readonly grid: 0;
|
|
24
|
+
readonly transmittance: 1;
|
|
25
|
+
readonly absorption: 2;
|
|
26
|
+
};
|
|
27
|
+
/** Group-1 bindings of the 'frame' gather kernel (K6.4 spectral: the second scatter texture). */
|
|
28
|
+
export declare const FRAME_GATHER_BINDINGS: {
|
|
29
|
+
readonly volumes: 0;
|
|
30
|
+
readonly group: 1;
|
|
31
|
+
readonly scatter: 2;
|
|
32
|
+
readonly partials: 3;
|
|
33
|
+
readonly transmittance: 4;
|
|
34
|
+
readonly environmentGrid: 5;
|
|
35
|
+
readonly emissionLut: 6;
|
|
36
|
+
readonly scatterAlpha: 7;
|
|
37
|
+
};
|
|
38
|
+
/** K6.4: words per voxel of the spectral shadow grid's multi-group partials (extinction rgb, absorption rgb). */
|
|
39
|
+
export declare const VDB_FRAME_SPECTRAL_GRID_WORDS = 3;
|
|
40
|
+
/** Values per froxel the 'frame' gather sums (4 × vec4f), packed as 8 `pack2x16float` words in the partials. */
|
|
41
|
+
export declare const VDB_FRAME_SUM_WORDS = 8;
|
|
42
|
+
/** The shadow grid density kernel (after the source module, the source WGSL and `vdbFrameUniformsWgsl()`). */
|
|
43
|
+
export declare function vdbFrameGridDensityWgsl(o: {
|
|
44
|
+
multi: boolean;
|
|
45
|
+
channels: VDBVolumeChannels;
|
|
46
|
+
spectral?: boolean;
|
|
47
|
+
}): string;
|
|
48
|
+
/**
|
|
49
|
+
* K6.3: the scattered-light term of the transmittance kernel's light slots, a pipeline key (design §3.6, §5.2). `'none'`
|
|
50
|
+
* covers single scattering, 1D diffusion, 'two-sided' and 'octaves' (uniforms); `'mlp'` and `'multi-scale'` bind their
|
|
51
|
+
* resources in group 2 (the kernel is source-free: the MLP weights are its one storage buffer, D10).
|
|
52
|
+
*/
|
|
53
|
+
export type VDBFrameScatteringKernel = "none" | "mlp" | "mlp-packed" | "multi-scale";
|
|
54
|
+
/** K6.Na: whether a scattered-light kernel runs the MLP (either evaluator: `'mlp'` generic, `'mlp-packed'`). */
|
|
55
|
+
export declare const vdbFrameScatteringIsMlp: (kind: VDBFrameScatteringKernel) => kind is "mlp" | "mlp-packed";
|
|
56
|
+
/**
|
|
57
|
+
* K6.3: group-2 bindings of the transmittance kernel's `'mlp'` and `'multi-scale'` variants. K7.4a spectral `'mlp'`:
|
|
58
|
+
* `mips` holds the extinction rgb, `absorptionMips` the absorption rgb box mips. K7.4a-3 spectral `'multi-scale'`: `mips`
|
|
59
|
+
* is K7.3's chain of the extinction rgb stack, `absorptionMips` the chain of the absorption rgb stack.
|
|
60
|
+
*/
|
|
61
|
+
export declare const TRANSMITTANCE_MLP_BINDINGS: {
|
|
62
|
+
readonly weights: 0;
|
|
63
|
+
readonly shape: 1;
|
|
64
|
+
readonly mips: 2;
|
|
65
|
+
readonly absorptionMips: 3;
|
|
66
|
+
};
|
|
67
|
+
export declare const TRANSMITTANCE_MULTI_SCALE_BINDINGS: {
|
|
68
|
+
readonly params: 0;
|
|
69
|
+
readonly mips: 1;
|
|
70
|
+
readonly absorptionMips: 2;
|
|
71
|
+
};
|
|
72
|
+
/** Most MLP layers and the widest layer the generic evaluator takes (K6.3, design §3.6). */
|
|
73
|
+
export declare const VDB_FRAME_MLP_MAX_LAYERS = 8;
|
|
74
|
+
export declare const VDB_FRAME_MLP_MAX_WIDTH = 64;
|
|
75
|
+
/** K6.3: the box mip kernels of the `'mlp'` feature levels (his grid mip pass, design §3.3 `gridMips`). */
|
|
76
|
+
export declare const GRID_MIP_BINDINGS: {
|
|
77
|
+
readonly source: 0;
|
|
78
|
+
readonly out: 1;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* K6.3 `gridMips` (his FrameGridMipMaterial, the box branch): texel x of mip k is the mean of the 2 × 2 × 2 texels 2x + i
|
|
82
|
+
* of level k − 1, each clamped to that level's last texel. `vdbFrameGridMipFirstCs` reads the last shadow grid cascade
|
|
83
|
+
* in the stack (level 0), `vdbFrameGridMipCs` a one-mip view of the level before. rgba16float (his RG half float in .xy).
|
|
84
|
+
* K7.4a: every channel is boxed (grey: (extinction, absorption, 0, 0); spectral: extinction rgb or absorption rgb, the
|
|
85
|
+
* same kernel on each stack).
|
|
86
|
+
* K7.4d-a `reduce` (the cubic chain, `tools/frame/mlp.ts` `vdbFrameMlpCubicReduce`): adds `vdbFrameGridMipReduceCs`,
|
|
87
|
+
* level 0 of the chain: texel x is the mean of the 2^e.x × 2^e.y × 2^e.z voxels (x << e) + i of the last cascade (a cube of
|
|
88
|
+
* the largest voxel side), each clamped to the cascade's last voxel. The exponents are compile-time constants.
|
|
89
|
+
*/
|
|
90
|
+
export declare function vdbFrameGridMipWgsl(reduce?: readonly number[]): string;
|
|
91
|
+
/** The transmittance kernel (after `vdbFrameUniformsWgsl()`; source-free). K6.3: `scattering` picks the slot term. */
|
|
92
|
+
export declare function vdbFrameTransmittanceWgsl(o?: {
|
|
93
|
+
scattering?: VDBFrameScatteringKernel;
|
|
94
|
+
spectral?: boolean;
|
|
95
|
+
}): string;
|
|
96
|
+
/** The 'frame' gather kernel (after the source module, the source WGSL and `vdbFrameUniformsWgsl()`). */
|
|
97
|
+
export declare function vdbFrameLightingGatherWgsl(o: {
|
|
98
|
+
multi: boolean;
|
|
99
|
+
channels: VDBVolumeChannels;
|
|
100
|
+
hook?: string | null;
|
|
101
|
+
spectral?: boolean;
|
|
102
|
+
stochastic?: boolean;
|
|
103
|
+
}): string;
|