@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunks.js","sourceRoot":"","sources":["../../../../src/core/frame/wgsl/chunks.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,yGAAyG;AACzG,kGAAkG;AAClG,2GAA2G;AAC3G,0FAA0F;AAC1F,mGAAmG;AACnG,2CAA2C;AAC3C,4GAA4G;AAC5G,uGAAuG;AACvG,4HAA4H;AAC5H,uHAAuH;AACvH,gHAAgH;AAChH,0HAA0H;AAC1H,2DAA2D;AAC3D,iCAAiC;AAEjC,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAC7G,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAE7E;;;;GAIG;AAEH,2HAA2H;AAC3H,MAAM,QAAQ,GAAG,oBAAoB,CAAC;AACtC,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAC3C,MAAM,YAAY,GAAG,kBAAkB,CAAC;AACxC,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAOjD,oEAAoE;AACpE,MAAM,MAAM,GAA4C;IACtD;QACE,WAAW;QACX;YACE,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;;;;;;;;CAQX;SACI;KACF;IACD;QACE,MAAM;QACN;YACE,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;;;CAGX;SACI;KACF;IACD;QACE,YAAY;QACZ;YACE,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;;;;CAIX;SACI;KACF;IACD;QACE,cAAc;QACd;YACE,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;;;;;;;;;;CAUX;SACI;KACF;IACD;QACE,QAAQ;QACR;YACE,IAAI,EAAE,CAAC,YAAY,EAAE,cAAc,CAAC;YACpC,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;CAwBX;SACI;KACF;IACD;QACE,OAAO;QACP;YACE,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;;;;;CAKX;SACI;KACF;IACD;QACE,MAAM;QACN;YACE,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;;;;;;;;;;;;;;;;;;;CAmBX;SACI;KACF;IACD;QACE,MAAM;QACN;YACE,IAAI,EAAE,CAAC,WAAW,CAAC;YACnB,IAAI,EAAE;;;;;;;;;CASX;SACI;KACF;IACD;QACE,KAAK;QACL;YACE,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;;;;;;;;;;;;;;;;CAgBX;SACI;KACF;IACD;QACE,KAAK;QACL;YACE,IAAI,EAAE,CAAC,cAAc,CAAC;YACtB,IAAI,EAAE;;;;;;;;;;;;;;;;;CAiBX;SACI;KACF;IACD;QACE,OAAO;QACP;YACE,IAAI,EAAE,CAAC,WAAW,CAAC;YACnB,IAAI,EAAE;;;;;;;;;8EASkE,QAAQ;;;oBAGlE,QAAQ,GAAG,CAAC;;;;;;;;;;oBAUZ,QAAQ,GAAG,CAAC;gCACA,QAAQ,GAAG,CAAC;;;;;;;;;;;;;;;;;kBAiB1B,YAAY,GAAG,GAAG;;;;;;;;;;;;;kEAa8B,aAAa;;CAE9E;SACI;KACF;IACD;QACE,cAAc;QACd;YACE,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;;;;;;mBAMO,aAAa;mBACb,aAAa;kBACd,YAAY,GAAG,GAAG;;;;;;;;;CASnC;SACI;KACF;IACD;QACE,QAAQ;QACR;YACE,IAAI,EAAE,CAAC,OAAO,CAAC;YACf,IAAI,EAAE;;;;;;;;;;;;kBAYM,YAAY,GAAG,GAAG;mBACjB,aAAa;;;kEAGkC,aAAa;;;;;;;;;;;;;;;;;;;;;;;;CAwB9E;SACI;KACF;IACD;QACE,QAAQ;QACR;YACE,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyDX;SACI;KACF;IACD;QACE,aAAa;QACb;YACE,IAAI,EAAE,CAAC,QAAQ,CAAC;YAChB,IAAI,EAAE;;;;;;;;;;yBAUa,WAAW;;;;;;;;;;;;;;;;;;CAkBnC;SACI;KACF;IACD;QACE,SAAS;QACT;YACE,IAAI,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC;YAC9B,IAAI,EAAE;;;;;;yBAMa,WAAW;;;;;;;;;;;;;;;;;;;;CAoBnC;SACI;KACF;IACD;QACE,UAAU;QACV;YACE,IAAI,EAAE,CAAC,QAAQ,EAAE,aAAa,EAAE,OAAO,CAAC;YACxC,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAwFa,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BnC;SACI;KACF;IACD;QACE,IAAI;QACJ;YACE,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;;;;;;;;;;;;;;;;CAgBX;SACI;KACF;IACD;QACE,OAAO;QACP;YACE,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;;;;;;;;;;;;;;;;;CAiBX;SACI;KACF;IACD;QACE,MAAM;QACN;YACE,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCX;SACI;KACF;IACD;QACE,MAAM;QACN;YACE,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;;;;;;;;;CASX;SACI;KACF;CACF,CAAC;AAEF,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;AAKhC,4EAA4E;AAC5E,MAAM,UAAU,eAAe,CAAC,KAA8B;IAC5D,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE;QAC7B,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO;QAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,IAAI,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACf,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI;YAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC,CAAC;IACF,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAChC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;SAC7C,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SACtB,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC","sourcesContent":["// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):\n// src/three-openvdb/frame/webgpu/frameShaderChunks.js L94–107 (frameSliceDepth, frameGetViewPosition),\n// L109–127 (frameGetFroxel), L129–142 (frameDistanceFade), L157–185 (getFroxelLod, getBoxSteps,\n// frameNoise), L187–203 (frameHenyeyGreenstein, frameHenyeyGreensteinColor), L273–315 (framePhaseWeight,\n// framePhaseColor), L330–373 (frameShadowAbsorption, frameShadowStep, frameShadowDepth,\n// frameShadowTransmittance), L403–414 (frameIsotropicDiffusion), L938–958 (boxExit, boxSegment);\n// three.js r187 getShIrradianceAt (MIT).\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: TSL → WGSL for the core compute kernels (K6.1); the froxel of a 3D texel replaces the atlas\n// pixel (the noise keeps his virtual atlas coordinate); K6.3: the Lorenz-Mie table reads (frameMieTexel, L206–271), octaves\n// (L316–399: frameShadowMarchDepth, frameOctaveLight, frameShadowTotal, frameShadowedLight) and frameTwoSidedDiffusion\n// (L416–451); K6.4: the spectral chunks (L483–622: frameMeanComponent, frameSpectralShadowUnit / Step / Depth /\n// Transmittance, frameSpectralGridAlbedo, frameSpectralOctaveLight / ShadowTotal / ShadowedLight). CPU twins: tools/frame\n// (index.ts, froxel.ts, mie.ts, spectral.ts). Divergences:\n// DIVERGES.md (K3.1, K6.1 rows).\n\nimport { vdbFrameMieAsymmetry, vdbFrameMieRgbMode, vdbFrameMieTableSize } from \"../../../tools/frame/mie.js\";\nimport { vdbFrameMaxScatteringOctaves } from \"../../../tools/frame/index.js\";\n\n/**\n * `frameChunksWgsl(roots)`: the source-free `vdbFrame*` WGSL functions the frame kernels share, emitted\n * as the dependency closure of `roots` in one fixed order (same roots, same bytes). They read the group-0\n * uniforms `vdbFrame` / `vdbFrameLights` (`vdbFrameUniformsWgsl`).\n */\n\n/** Lorenz-Mie table texels (his `frameMieTableSize`), its asymmetry and the 'lorenz-mie-rgb' mode (tools/frame/mie.ts). */\nconst MIE_SIZE = vdbFrameMieTableSize;\nconst MIE_ASYMMETRY = vdbFrameMieAsymmetry;\nconst MIE_RGB_MODE = vdbFrameMieRgbMode;\nconst MAX_OCTAVES = vdbFrameMaxScatteringOctaves;\n\ninterface Chunk {\n readonly deps: readonly string[];\n readonly code: string;\n}\n\n/** The chunks in emission order (a chunk's deps come before it). */\nconst CHUNKS: ReadonlyArray<readonly [string, Chunk]> = [\n [\n \"constants\",\n {\n deps: [],\n code: `const VDB_FRAME_PI: f32 = 3.141592653589793;\nconst VDB_FRAME_FADE_END: f32 = 0.018315638888734179; // exp(-4)\nconst VDB_FRAME_LIGHT_AMBIENT: u32 = 32u;\nconst VDB_FRAME_LIGHT_POINT: u32 = 16u;\nconst VDB_FRAME_LIGHT_DIRECTIONAL: u32 = 8u;\nconst VDB_FRAME_LIGHT_SPOT: u32 = 4u;\nconst VDB_FRAME_LIGHT_HEMISPHERE: u32 = 2u;\nconst VDB_FRAME_LIGHT_ENVIRONMENT: u32 = 1u;\n`,\n },\n ],\n [\n \"mat3\",\n {\n deps: [],\n code: `fn vdbFrameMat3(m: mat4x4f) -> mat3x3f {\n return mat3x3f(m[0].xyz, m[1].xyz, m[2].xyz);\n}\n`,\n },\n ],\n [\n \"sliceDepth\",\n {\n deps: [],\n code: `// frameSliceDepth: view depth at the slice fraction t of the log range\nfn vdbFrameSliceDepth(t: f32) -> f32 {\n return vdbFrame.range.x * pow(vdbFrame.range.y / vdbFrame.range.x, t);\n}\n`,\n },\n ],\n [\n \"viewPosition\",\n {\n deps: [],\n code: `// frameGetViewPosition: two points on the pixel ray (NDC depth 0 and 1), the one at viewDepth\nfn vdbFrameViewPosition(uv: vec2f, viewDepth: f32) -> vec3f {\n let ndc = uv * 2.0 - 1.0;\n let nearPoint = vdbFrame.projectionInverse * vec4f(ndc, 0.0, 1.0);\n let farPoint = vdbFrame.projectionInverse * vec4f(ndc, 1.0, 1.0);\n let near = nearPoint.xyz / nearPoint.w;\n let far = farPoint.xyz / farPoint.w;\n let t = (viewDepth + near.z) / (near.z - far.z);\n return mix(near, far, vec3f(t));\n}\n`,\n },\n ],\n [\n \"froxel\",\n {\n deps: [\"sliceDepth\", \"viewPosition\"],\n code: `// frameGetFroxel for the 3D texel cell; fragCoord is his atlas pixel (the noise reads it)\nstruct VdbFrameFroxel {\n fragCoord: vec2f,\n uv: vec2f,\n sliceNear: f32,\n sliceFar: f32,\n viewNear: vec3f,\n viewFar: vec3f,\n};\nfn vdbFrameFroxelAt(cell: vec3u) -> VdbFrameFroxel {\n let grid = vdbFrame.grid;\n let slice = f32(cell.z);\n let row = floor(slice / grid.w);\n let tile = vec2f(slice - grid.w * row, row);\n let xy = vec2f(cell.xy) + 0.5;\n var f: VdbFrameFroxel;\n f.fragCoord = tile * grid.xy + xy;\n f.uv = (f.fragCoord - tile * grid.xy) / grid.xy;\n f.sliceNear = vdbFrameSliceDepth(slice / grid.z);\n f.sliceFar = vdbFrameSliceDepth((slice + 1.0) / grid.z);\n f.viewNear = vdbFrameViewPosition(f.uv, f.sliceNear);\n f.viewFar = vdbFrameViewPosition(f.uv, f.sliceFar);\n return f;\n}\n`,\n },\n ],\n [\n \"noise\",\n {\n deps: [],\n code: `// frameNoise: interleaved gradient noise (Jimenez 2014); 0.5 when jitter is off (negative)\nfn vdbFrameNoise(jitter: f32, pixel: vec2f) -> f32 {\n let noise = fract(52.9829189 * fract(dot(pixel, vec2f(0.06711056, 0.00583715))));\n return select(fract(noise + jitter), 0.5, jitter < 0.0);\n}\n`,\n },\n ],\n [\n \"rand\",\n {\n deps: [],\n code: `// Issue #2 step 2: pcg3d (Jarzynski & Olano 2020)\nfn vdbFramePcg3d(v0: vec3u) -> vec3u {\n var v = v0 * 1664525u + 1013904223u;\n v.x += v.y * v.z;\n v.y += v.z * v.x;\n v.z += v.x * v.y;\n v = v ^ (v >> vec3u(16u));\n v.x += v.y * v.z;\n v.y += v.z * v.x;\n v.z += v.x * v.y;\n return v;\n}\n// the stochastic density filter's three uniforms of one lookup: the froxel's atlas pixel, a key ((volume << 16) | step)\n// and the frame seed (flags.w); 24-bit values (exact in f32)\nfn vdbFrameRand3(pixel: vec2f, key: u32) -> vec3f {\n let seed = vdbFramePcg3d(vec3u(vdbFrame.flags.w, 0x9e3779b9u, 0x7f4a7c15u)).x;\n let h = vdbFramePcg3d(vec3u(vec2u(pixel), key ^ seed));\n return vec3f(h >> vec3u(8u)) * (1.0 / 16777216.0);\n}\n`,\n },\n ],\n [\n \"fade\",\n {\n deps: [\"constants\"],\n code: `// frameDistanceFade: 1 at the camera, 0 at the fade radius; radius 0: no fade\nfn vdbFrameDistanceFade(viewPosition: vec3f) -> f32 {\n let radius = vdbFrame.jitterFade.y;\n if (radius <= 0.0) {\n return 1.0;\n }\n let x = clamp(length(viewPosition) / radius, 0.0, 1.0);\n return (exp(x * x * -4.0) - VDB_FRAME_FADE_END) / (1.0 - VDB_FRAME_FADE_END);\n}\n`,\n },\n ],\n [\n \"box\",\n {\n deps: [],\n code: `// boxExit / boxSegment of the local unit box [-0.5, 0.5]^3\nfn vdbFrameBoxExit(origin: vec3f, direction: vec3f) -> f32 {\n let inverseDirection = vec3f(1.0) / direction;\n let tMin = (vec3f(-0.5) - origin) * inverseDirection;\n let tMax = (vec3f(0.5) - origin) * inverseDirection;\n let far = max(tMin, tMax);\n return max(0.0, min(far.x, min(far.y, far.z)));\n}\nfn vdbFrameBoxSegment(start: vec3f, end: vec3f) -> vec2f {\n let inverseDirection = vec3f(1.0) / (end - start);\n let tMin = (vec3f(-0.5) - start) * inverseDirection;\n let tMax = (vec3f(0.5) - start) * inverseDirection;\n let near = min(tMin, tMax);\n let far = max(tMin, tMax);\n return vec2f(max(0.0, max(near.x, max(near.y, near.z))), min(1.0, min(far.x, min(far.y, far.z))));\n}\n`,\n },\n ],\n [\n \"lod\",\n {\n deps: [\"viewPosition\"],\n code: `// getLod: the level of a footprint of localSize (unit-box units)\nfn vdbFrameLod(localSize: f32, maxTexels: f32) -> f32 {\n return max(0.0, log2(localSize * maxTexels));\n}\n// getFroxelLod: the level of the froxel width at the slice middle or the sub-step, the larger\nfn vdbFrameFroxelLod(f: VdbFrameFroxel, subStepLength: f32, worldScale: f32, maxTexels: f32) -> f32 {\n let sliceMiddle = (f.sliceNear + f.sliceFar) * 0.5;\n let neighborUv = f.uv + vec2f(1.0 / vdbFrame.grid.x, 0.0);\n let froxelWidth = length(vdbFrameViewPosition(neighborUv, sliceMiddle) - vdbFrameViewPosition(f.uv, sliceMiddle));\n return vdbFrameLod(max(froxelWidth, subStepLength) / worldScale, maxTexels);\n}\n// getBoxSteps: two sub-steps per voxel of the read level across the in-box part, at most subSteps\nfn vdbFrameBoxSteps(localNear: vec3f, localFar: vec3f, segment: f32, sampledLod: f32, maxTexels: f32) -> u32 {\n let boxLength = length(localFar - localNear) * segment;\n let steps = ceil(exp2(vdbFrameLod(boxLength, maxTexels) - sampledLod) * 2.0);\n return u32(clamp(steps, 1.0, f32(vdbFrame.flags.x)));\n}\n`,\n },\n ],\n [\n \"phase\",\n {\n deps: [\"constants\"],\n code: `// frameHenyeyGreenstein: HG over the isotropic phase; g = 0 gives 1\nfn vdbFrameHenyeyGreenstein(cosTheta: f32, g: f32) -> f32 {\n let g2 = g * g;\n return (1.0 - g2) / pow(max(1.0 + g2 - 2.0 * g * cosTheta, 1e-4), 1.5);\n}\nfn vdbFrameHenyeyGreensteinColor(cosTheta: f32, g: vec3f) -> vec3f {\n let g2 = g * g;\n return (vec3f(1.0) - g2) / pow(max(vec3f(1.0) + g2 - g * 2.0 * cosTheta, vec3f(1e-4)), vec3f(1.5));\n}\n// K6.3: the Lorenz-Mie tables (V47; rgb 'lorenz-mie-rgb', a 'lorenz-mie'), ${MIE_SIZE} texels at the angle PI u^2, as\n// binary16 in a uniform buffer (two texels per vec4u; no sampled texture), read with a linear blend (his frameMieTexel)\nstruct VdbFrameMieTable {\n t: array<vec4u, ${MIE_SIZE / 2}>,\n};\n@group(0) @binding(4) var<uniform> vdbFrameMie: VdbFrameMieTable;\nfn vdbFrameMieLoad(i: i32) -> vec4f {\n let w = vdbFrameMie.t[u32(i) >> 1u];\n let odd = (u32(i) & 1u) == 1u;\n return vec4f(unpack2x16float(select(w.x, w.z, odd)), unpack2x16float(select(w.y, w.w, odd)));\n}\nfn vdbFrameMieTexel(cosTheta: f32) -> vec4f {\n let u = sqrt(acos(clamp(cosTheta, -1.0, 1.0)) * (1.0 / VDB_FRAME_PI));\n let texel = u * ${MIE_SIZE - 1}.0;\n let index = min(i32(texel), ${MIE_SIZE - 2});\n return mix(vdbFrameMieLoad(index), vdbFrameMieLoad(index + 1), vec4f(texel - f32(index)));\n}\n// framePhaseWeight: (forward g, back g, back weight, Lorenz-Mie mode); mode > 0 mixes the 'lorenz-mie' table in\nfn vdbFramePhaseWeight(phase: vec4f, cosTheta: f32) -> f32 {\n let w = mix(vdbFrameHenyeyGreenstein(cosTheta, phase.x), vdbFrameHenyeyGreenstein(cosTheta, phase.y), phase.z);\n if (phase.w > 0.0) {\n return mix(w, vdbFrameMieTexel(cosTheta).w, phase.w);\n }\n return w;\n}\n// framePhaseColor: spectrum (red g scale, blue g scale, flag); flag 0: one phase for all channels; 'lorenz-mie-rgb'\n// (mode 2): its three tables\nfn vdbFramePhaseColor(phase: vec4f, spectrum: vec3f, cosTheta: f32) -> vec3f {\n if (spectrum.z < 0.5) {\n return vec3f(vdbFramePhaseWeight(phase, cosTheta));\n }\n if (phase.w > ${MIE_RGB_MODE - 0.5}) {\n return vdbFrameMieTexel(cosTheta).xyz;\n }\n let scale = vec3f(spectrum.x, 1.0, spectrum.y);\n return mix(\n vdbFrameHenyeyGreensteinColor(cosTheta, clamp(scale * phase.x, vec3f(-0.99), vec3f(0.99))),\n vdbFrameHenyeyGreensteinColor(cosTheta, clamp(scale * phase.y, vec3f(-0.99), vec3f(0.99))),\n vec3f(phase.z),\n );\n}\n// framePhaseWeightScaled: every g x gScale; the Lorenz-Mie modes use HG with the table asymmetry x gScale\nfn vdbFramePhaseWeightScaled(phase: vec4f, cosTheta: f32, gScale: f32) -> f32 {\n let lobes = mix(vdbFrameHenyeyGreenstein(cosTheta, phase.x * gScale), vdbFrameHenyeyGreenstein(cosTheta, phase.y * gScale), phase.z);\n return mix(lobes, vdbFrameHenyeyGreenstein(cosTheta, gScale * ${MIE_ASYMMETRY}), min(phase.w, 1.0));\n}\n`,\n },\n ],\n [\n \"ambientPhase\",\n {\n deps: [],\n code: `// K6.Q1c (V128): the distant light's phase weight from the pairs' dipole fit (T = a + b.w), from the sums of the up and\n// down totals over the pairs and the dipole sum b.r (r the view ray): each HG lobe's clamp(a + g b.r, 0, 1) (g its mean\n// cosine; spectral: scaled and clamped as vdbFramePhaseColor; the Lorenz-Mie asymmetry for both Mie modes), mixed by the\n// back weight, over a; 1 where a <= 1e-6\nfn vdbFrameAmbientPhaseFactor(sumUp: vec3f, sumDown: vec3f, dipole: vec3f, pairs: u32, phase: vec4f, spectrum: vec3f) -> vec3f {\n let a = (sumUp + sumDown) / f32(2u * pairs);\n var g0 = vec3f(${MIE_ASYMMETRY});\n var g1 = vec3f(${MIE_ASYMMETRY});\n if (phase.w < ${MIE_RGB_MODE - 0.5}) {\n let scale = select(vec3f(1.0), vec3f(spectrum.x, 1.0, spectrum.y), spectrum.z > 0.5);\n let mie = min(phase.w, 1.0);\n g0 = mix(clamp(scale * phase.x, vec3f(-0.99), vec3f(0.99)), g0, mie);\n g1 = mix(clamp(scale * phase.y, vec3f(-0.99), vec3f(0.99)), g1, mie);\n }\n let v = mix(clamp(a + g0 * dipole, vec3f(0.0), vec3f(1.0)), clamp(a + g1 * dipole, vec3f(0.0), vec3f(1.0)), vec3f(phase.z));\n return select(vec3f(1.0), v / max(a, vec3f(1e-6)), a > vec3f(1e-6));\n}\n`,\n },\n ],\n [\n \"msExit\",\n {\n deps: [\"phase\"],\n code: `// K7.4c (internal msExit, V229; tools/frame/ms-exit.ts): the exit of a light's scattered part (total - direct). Its mean\n// cosine along the light's travel: the small-angle first moment D^(1 - albedo g) - D over the scattered total, clamped\n// between 0 and g (the first order's); 0 without scattered light\nfn vdbFrameMsExitMean(direct: f32, scattered: f32, albedo: f32, g: f32) -> f32 {\n if (!(scattered > 1e-6) || !(direct > 0.0)) {\n return 0.0;\n }\n let flux = exp(log(direct) * (1.0 - clamp(albedo, 0.0, 1.0) * g)) - direct;\n return clamp(flux / scattered, min(g, 0.0), max(g, 0.0));\n}\n// one lobe's g of each channel (as vdbFrameAmbientPhaseFactor)\nfn vdbFrameMsExitLobe(phase: vec4f, spectrum: vec3f, g: f32) -> vec3f {\n if (phase.w > ${MIE_RGB_MODE - 0.5}) {\n return vec3f(${MIE_ASYMMETRY});\n }\n let scale = select(vec3f(1.0), vec3f(spectrum.x, 1.0, spectrum.y), spectrum.z > 0.5);\n return mix(clamp(scale * g, vec3f(-0.99), vec3f(0.99)), vec3f(${MIE_ASYMMETRY}), vec3f(min(phase.w, 1.0)));\n}\n// the factor on the scattered light of each channel over the isotropic exit: mode 1 'dipole' mix_i max(1 + 3 g_i m cos, 0),\n// mode 2 'hg' mix_i HG(g_i m, cos) (m the mean cosine above, cos the direct term's); K7.4a-2 mode 3 'hg-chroma': the 'hg'\n// factor over its green channel's (the chromatic part only: green, and every channel of a grey medium, exit as his)\nfn vdbFrameMsExit(mode: f32, phase: vec4f, spectrum: vec3f, cosTheta: f32, direct: vec3f, scattered: vec3f, albedo: vec3f) -> vec3f {\n let g0 = vdbFrameMsExitLobe(phase, spectrum, phase.x);\n let g1 = vdbFrameMsExitLobe(phase, spectrum, phase.y);\n let gMean = mix(g0, g1, vec3f(phase.z));\n let m = vec3f(\n vdbFrameMsExitMean(direct.x, scattered.x, albedo.x, gMean.x),\n vdbFrameMsExitMean(direct.y, scattered.y, albedo.y, gMean.y),\n vdbFrameMsExitMean(direct.z, scattered.z, albedo.z, gMean.z),\n );\n if (mode < 1.5) {\n let k = m * (3.0 * cosTheta);\n return mix(max(vec3f(1.0) + g0 * k, vec3f(0.0)), max(vec3f(1.0) + g1 * k, vec3f(0.0)), vec3f(phase.z));\n }\n let hg = mix(vdbFrameHenyeyGreensteinColor(cosTheta, g0 * m), vdbFrameHenyeyGreensteinColor(cosTheta, g1 * m), vec3f(phase.z));\n if (mode > 2.5) {\n return hg / max(hg.y, 1e-6);\n }\n return hg;\n}\n`,\n },\n ],\n [\n \"shadow\",\n {\n deps: [],\n code: `// frameShadowAbsorption: the extinction the albedo (Rec. 709 luminance) does not scatter\nfn vdbFrameShadowAbsorption(extinction: f32, albedo: vec3f) -> f32 {\n return extinction * (1.0 - clamp(dot(albedo, vec3f(0.2126, 0.7152, 0.0722)), 0.0, 1.0));\n}\n// frameShadowStep: (extinction, effective extinction, reduced scattering) per unit of length\nfn vdbFrameShadowStep(extinction: f32, absorption: f32, multipleScattering: f32) -> vec3f {\n let absorbed = min(absorption, extinction);\n let reducedScattering = (extinction - absorbed) * multipleScattering;\n return vec3f(extinction, sqrt(absorbed * 3.0 * (absorbed + reducedScattering)), reducedScattering);\n}\n// frameShadowDepth: -log of the total transmittance (1D diffusion when multipleScattering > 0)\nfn vdbFrameShadowDepth(depths: vec3f, multipleScattering: f32) -> f32 {\n return select(depths.x, min(depths.x, depths.y + log(depths.z * 0.75 + 1.0)), multipleScattering > 0.0);\n}\n// K6.3 frameShadowMarchDepth: the depth that stops a march; octaves (count, a, b, c): the last octave's sigma a^N depth\nfn vdbFrameShadowMarchDepth(depths: vec3f, multipleScattering: f32, octaves: vec4f) -> f32 {\n if (octaves.x > 0.0) {\n return depths.x * pow(octaves.y, octaves.x);\n }\n return vdbFrameShadowDepth(depths, multipleScattering);\n}\n// frameShadowTransmittance: (direct, total); octaves: total holds 1 / (1 + optical depth) (K6.3)\nfn vdbFrameShadowTransmittance(depths: vec3f, multipleScattering: f32, octaves: vec4f) -> vec2f {\n if (octaves.x > 0.0) {\n return vec2f(exp(-depths.x), 1.0 / (depths.x + 1.0));\n }\n return vec2f(exp(-depths.x), exp(-vdbFrameShadowDepth(depths, multipleScattering)));\n}\n// frameIsotropicDiffusion: two-sided slab total of isotropic light (white furnace), z0 = 2/3\nfn vdbFrameIsotropicDiffusion(frontReduced: f32, backReduced: f32, frontEffective: f32) -> f32 {\n return (backReduced + 2.0 / 3.0) * 2.0 / (frontReduced + backReduced + 4.0 / 3.0) * exp(-frontEffective);\n}\n// K6.3 frameTwoSidedDiffusion ('two-sided'): 1D slab diffusion with a collimated source between the light side (front\n// reduced depth f) and the far side (back b), the lowest side mode k^2 = 2 (PI / (f + b + 2 z0))^2, Robin boundaries\n// z0 = 2/3; the diffuse plus the reduced beam exp(-f), times exp(-effective front), never below the direct light\nfn vdbFrameTwoSidedDiffusion(direct: f32, frontReduced: f32, frontEffective: f32, backReduced: f32) -> f32 {\n let z0 = 2.0 / 3.0;\n let slab = frontReduced + backReduced;\n let k0 = 4.442882938158366 / (slab + 2.0 * z0);\n let k = k0 + (1.0 - step(0.01, abs(1.0 - k0 * k0))) * 0.01;\n let p = -3.0 / (1.0 - k * k);\n let kl = k * slab;\n let coshKl = (exp(kl) + exp(-kl)) * 0.5;\n let sinhKl = (exp(kl) - exp(-kl)) * 0.5;\n let c12 = k * -z0;\n let r1 = p * -(1.0 + z0);\n let c21 = coshKl + k * z0 * sinhKl;\n let c22 = sinhKl + k * z0 * coshKl;\n let r2 = -p * exp(-slab) * (1.0 - z0);\n let det = c22 - c12 * c21;\n let c = (r1 * c22 - c12 * r2) / det;\n let d = (r2 - c21 * r1) / det;\n let kf = k * frontReduced;\n let beam = exp(-frontReduced);\n let diffuse = p * beam + c * (exp(kf) + exp(-kf)) * 0.5 + d * (exp(kf) - exp(-kf)) * 0.5;\n return max(direct, (diffuse + beam) * exp(-frontEffective));\n}\n`,\n },\n ],\n [\n \"octaveTotal\",\n {\n deps: [\"shadow\"],\n code: `// K6.3 multipleScattering 'octaves' (count N, extinction a, contribution b, phase c), isotropic light\n// frameShadowOpticalDepth: the optical depth back from the octave shadow value 1 / (1 + depth)\nfn vdbFrameShadowOpticalDepth(shadowY: f32) -> f32 {\n return max(1.0 / max(shadowY, 1e-6) - 1.0, 0.0);\n}\n// frameOctaveLight of isotropic light: sum over n = 1..N of b^n exp(-a^n depth)\nfn vdbFrameOctaveSum(octaves: vec4f, opticalDepth: f32) -> f32 {\n var light = 0.0;\n var extinctionScale = 1.0;\n var contribution = 1.0;\n for (var i = 0u; i < ${MAX_OCTAVES}u; i++) {\n if (f32(i + 1u) > octaves.x) {\n break;\n }\n extinctionScale *= octaves.y;\n contribution *= octaves.z;\n light += contribution * exp(-opticalDepth * extinctionScale);\n }\n return light;\n}\n// frameShadowTotal: total transmittance of isotropic light from the y shadow value; octaves: exp(-depth) + the octaves\nfn vdbFrameShadowTotal(shadowY: f32, octaves: vec4f) -> f32 {\n if (octaves.x > 0.0) {\n let depth = vdbFrameShadowOpticalDepth(shadowY);\n return exp(-depth) + vdbFrameOctaveSum(octaves, depth);\n }\n return shadowY;\n}\n`,\n },\n ],\n [\n \"octaves\",\n {\n deps: [\"phase\", \"octaveTotal\"],\n code: `// frameOctaveLight: sum over n = 1..N of b^n phase(g c^n) exp(-a^n depth)\nfn vdbFrameOctaveLight(octaves: vec4f, opticalDepth: f32, phase: vec4f, cosTheta: f32) -> f32 {\n var light = 0.0;\n var extinctionScale = 1.0;\n var contribution = 1.0;\n var gScale = 1.0;\n for (var i = 0u; i < ${MAX_OCTAVES}u; i++) {\n if (f32(i + 1u) > octaves.x) {\n break;\n }\n extinctionScale *= octaves.y;\n contribution *= octaves.z;\n gScale *= octaves.w;\n light += contribution * vdbFramePhaseWeightScaled(phase, cosTheta, gScale) * exp(-opticalDepth * extinctionScale);\n }\n return light;\n}\n// frameShadowedLight of each channel: phase x direct + the scattered light (total - direct, isotropic), or with\n// octaves their phased sum from the octave shadow value\nfn vdbFrameShadowedLight(phase: vec4f, spectrum: vec3f, octaves: vec4f, cosTheta: f32, shadow: vec2f) -> vec3f {\n let direct = vdbFramePhaseColor(phase, spectrum, cosTheta) * shadow.x;\n if (octaves.x > 0.0) {\n return direct + vec3f(vdbFrameOctaveLight(octaves, vdbFrameShadowOpticalDepth(shadow.y), phase, cosTheta));\n }\n return direct + vec3f(shadow.y - shadow.x);\n}\n`,\n },\n ],\n [\n \"spectral\",\n {\n deps: [\"shadow\", \"octaveTotal\", \"phase\"],\n code: `// K6.4 spectral media (his frameShaderChunks L483–622): values of each channel (red, green, blue). Depths are\n// (x extinction, y effective extinction, z reduced scattering) of each channel; shadows (x direct, y total).\nstruct VdbFrameSpectralDepths {\n x: vec3f,\n y: vec3f,\n z: vec3f,\n};\nstruct VdbFrameSpectralShadow {\n x: vec3f,\n y: vec3f,\n};\n// A spectral march: direct, total, reduced depth, effective depth of each channel\nstruct VdbFrameSpectralMarch {\n x: vec3f,\n y: vec3f,\n z: vec3f,\n w: vec3f,\n};\nfn vdbFrameMeanComponent(v: vec3f) -> f32 {\n return dot(v, vec3f(1.0 / 3.0));\n}\nfn vdbFrameMinComponent(v: vec3f) -> f32 {\n return min(v.x, min(v.y, v.z));\n}\nfn vdbFrameMaxComponent(v: vec3f) -> f32 {\n return max(v.x, max(v.y, v.z));\n}\nfn vdbFrameSpectralUnmarched() -> VdbFrameSpectralMarch {\n return VdbFrameSpectralMarch(vec3f(1.0), vec3f(1.0), vec3f(0.0), vec3f(0.0));\n}\n// frameSpectralShadowUnit: the depths of one unit of extinction for a volume's spectrum and albedo\nfn vdbFrameSpectralShadowUnit(spectrum: vec3f, albedo: vec3f, multipleScattering: f32) -> VdbFrameSpectralDepths {\n let absorbed = spectrum * (vec3f(1.0) - clamp(albedo, vec3f(0.0), vec3f(1.0)));\n let reduced = (spectrum - absorbed) * multipleScattering;\n return VdbFrameSpectralDepths(spectrum, sqrt(absorbed * 3.0 * (absorbed + reduced)), reduced);\n}\n// frameSpectralShadowStep: the step depths of each channel from the grid's (extinction, absorption) of each channel\nfn vdbFrameSpectralShadowStep(extinction: vec3f, absorption: vec3f, multipleScattering: f32) -> VdbFrameSpectralDepths {\n let absorbed = min(absorption, extinction);\n let reduced = (extinction - absorbed) * multipleScattering;\n return VdbFrameSpectralDepths(extinction, sqrt(absorbed * 3.0 * (absorbed + reduced)), reduced);\n}\n// frameSpectralGridAlbedo: 1 - absorption / extinction of each channel, 1 with no extinction\nfn vdbFrameSpectralGridAlbedo(extinction: vec3f, absorption: vec3f) -> vec3f {\n if (!(vdbFrameMaxComponent(extinction) > 0.0)) {\n return vec3f(1.0);\n }\n return clamp(vec3f(1.0) - absorption / max(extinction, vec3f(1e-8)), vec3f(0.0), vec3f(1.0));\n}\n// frameShadowDepth of each channel\nfn vdbFrameSpectralShadowDepth(d: VdbFrameSpectralDepths, multipleScattering: f32) -> vec3f {\n return select(d.x, min(d.x, d.y + log(d.z * 0.75 + vec3f(1.0))), multipleScattering > 0.0);\n}\n// frameShadowMarchDepth of each channel (a march stops when the smallest is past its limit)\nfn vdbFrameSpectralShadowMarchDepth(d: VdbFrameSpectralDepths, multipleScattering: f32, octaves: vec4f) -> vec3f {\n if (octaves.x > 0.0) {\n return d.x * pow(octaves.y, octaves.x);\n }\n return vdbFrameSpectralShadowDepth(d, multipleScattering);\n}\n// frameSpectralShadowTransmittance: (direct, total) of each channel; octaves: total is 1 / (1 + depth)\nfn vdbFrameSpectralShadowTransmittance(d: VdbFrameSpectralDepths, multipleScattering: f32, octaves: vec4f) -> VdbFrameSpectralShadow {\n if (octaves.x > 0.0) {\n return VdbFrameSpectralShadow(exp(-d.x), vec3f(1.0) / (d.x + vec3f(1.0)));\n }\n return VdbFrameSpectralShadow(exp(-d.x), exp(-vdbFrameSpectralShadowDepth(d, multipleScattering)));\n}\n// frameIsotropicDiffusion of each channel\nfn vdbFrameIsotropicDiffusion3(frontReduced: vec3f, backReduced: vec3f, frontEffective: vec3f) -> vec3f {\n return (backReduced + vec3f(2.0 / 3.0)) * 2.0 / (frontReduced + backReduced + vec3f(4.0 / 3.0)) * exp(-frontEffective);\n}\n// frameTwoSidedDiffusion of each channel\nfn vdbFrameTwoSidedDiffusion3(direct: vec3f, frontReduced: vec3f, frontEffective: vec3f, backReduced: vec3f) -> vec3f {\n return vec3f(\n vdbFrameTwoSidedDiffusion(direct.x, frontReduced.x, frontEffective.x, backReduced.x),\n vdbFrameTwoSidedDiffusion(direct.y, frontReduced.y, frontEffective.y, backReduced.y),\n vdbFrameTwoSidedDiffusion(direct.z, frontReduced.z, frontEffective.z, backReduced.z),\n );\n}\n// frameSpectralOctaveLight: sum over n = 1..N of albedo^n b^n phase(g c^n) exp(-a^n depth) of each channel (each octave\n// is one more scattering); phased false: isotropic (phase 1)\nfn vdbFrameSpectralOctaveLight(octaves: vec4f, opticalDepth: vec3f, albedo: vec3f, phase: vec4f, cosTheta: f32, phased: bool) -> vec3f {\n var light = vec3f(0.0);\n var extinctionScale = 1.0;\n var contribution = 1.0;\n var gScale = 1.0;\n var albedoScale = vec3f(1.0);\n let octaveAlbedo = clamp(albedo, vec3f(0.0), vec3f(1.0));\n for (var i = 0u; i < ${MAX_OCTAVES}u; i++) {\n if (f32(i + 1u) > octaves.x) {\n break;\n }\n extinctionScale *= octaves.y;\n contribution *= octaves.z;\n gScale *= octaves.w;\n albedoScale *= octaveAlbedo;\n let p = select(1.0, vdbFramePhaseWeightScaled(phase, cosTheta, gScale), phased);\n light += albedoScale * (contribution * p) * exp(-opticalDepth * extinctionScale);\n }\n return light;\n}\n// frameSpectralShadowTotal: total transmittance of isotropic light of each channel from the y shadow values\nfn vdbFrameSpectralShadowTotal(shadowY: vec3f, octaves: vec4f, albedo: vec3f) -> vec3f {\n if (octaves.x > 0.0) {\n let depth = max(vec3f(1.0) / max(shadowY, vec3f(1e-6)) - vec3f(1.0), vec3f(0.0));\n return exp(-depth) + vdbFrameSpectralOctaveLight(octaves, depth, albedo, vec4f(0.0), 0.0, false);\n }\n return shadowY;\n}\n// frameSpectralShadowedLight: phase x direct + scattered of each channel (octaves: the spectral octave light)\nfn vdbFrameSpectralShadowedLight(phase: vec4f, spectrum: vec3f, octaves: vec4f, cosTheta: f32, shadow: VdbFrameSpectralShadow, albedo: vec3f) -> vec3f {\n let direct = vdbFramePhaseColor(phase, spectrum, cosTheta) * shadow.x;\n if (octaves.x > 0.0) {\n let depth = max(vec3f(1.0) / max(shadow.y, vec3f(1e-6)) - vec3f(1.0), vec3f(0.0));\n return direct + vdbFrameSpectralOctaveLight(octaves, depth, albedo, phase, cosTheta, true);\n }\n return direct + shadow.y - shadow.x;\n}\n`,\n },\n ],\n [\n \"sh\",\n {\n deps: [],\n code: `// three's getShIrradianceAt: irradiance of the light probe SH9 along a unit normal\nfn vdbFrameShIrradiance(normal: vec3f) -> vec3f {\n let x = normal.x;\n let y = normal.y;\n let z = normal.z;\n var result = vdbFrameLights.probe[0].xyz * 0.886227;\n result += vdbFrameLights.probe[1].xyz * (2.0 * 0.511664) * y;\n result += vdbFrameLights.probe[2].xyz * (2.0 * 0.511664) * z;\n result += vdbFrameLights.probe[3].xyz * (2.0 * 0.511664) * x;\n result += vdbFrameLights.probe[4].xyz * (2.0 * 0.429043) * x * y;\n result += vdbFrameLights.probe[5].xyz * (2.0 * 0.429043) * y * z;\n result += vdbFrameLights.probe[6].xyz * (z * z * 0.743125 - 0.247708);\n result += vdbFrameLights.probe[7].xyz * (2.0 * 0.429043) * x * z;\n result += vdbFrameLights.probe[8].xyz * 0.429043 * (x * x - y * y);\n return result;\n}\n`,\n },\n ],\n [\n \"envSh\",\n {\n deps: [],\n code: `// K6.2b: irradiance of the environment buffer's SH9 along a unit normal (three's getShIrradianceAt; the\n// Ramamoorthi-Hanrahan cosine convolution), clamped at 0\nfn vdbFrameEnvIrradiance(normal: vec3f) -> vec3f {\n let x = normal.x;\n let y = normal.y;\n let z = normal.z;\n var result = vdbFrameEnv.sh[0].xyz * 0.886227;\n result += vdbFrameEnv.sh[1].xyz * (2.0 * 0.511664) * y;\n result += vdbFrameEnv.sh[2].xyz * (2.0 * 0.511664) * z;\n result += vdbFrameEnv.sh[3].xyz * (2.0 * 0.511664) * x;\n result += vdbFrameEnv.sh[4].xyz * (2.0 * 0.429043) * x * y;\n result += vdbFrameEnv.sh[5].xyz * (2.0 * 0.429043) * y * z;\n result += vdbFrameEnv.sh[6].xyz * (z * z * 0.743125 - 0.247708);\n result += vdbFrameEnv.sh[7].xyz * (2.0 * 0.429043) * x * z;\n result += vdbFrameEnv.sh[8].xyz * 0.429043 * (x * x - y * y);\n return max(result, vec3f(0.0));\n}\n`,\n },\n ],\n [\n \"grid\",\n {\n deps: [],\n code: `// The world shadow grid (his createGridNodes): gridUvw, insideGrid (half a voxel in), findCascade\nfn vdbFrameGridUvw(cascade: u32, world: vec3f) -> vec3f {\n return (world - vdbFrame.gridMin[cascade].xyz) / vdbFrame.gridSize[cascade].xyz;\n}\nfn vdbFrameInsideGrid(uvw: vec3f) -> bool {\n let inset = 0.5 / vdbFrame.gridLayout.y;\n return min(uvw.x, min(uvw.y, uvw.z)) >= inset && max(uvw.x, max(uvw.y, uvw.z)) <= 1.0 - inset;\n}\n// the finest cascade from first that holds the position, or -1\nfn vdbFrameFindCascade(world: vec3f, first: u32) -> i32 {\n let count = u32(vdbFrame.gridLayout.x);\n for (var c = first; c < count; c++) {\n if (vdbFrameInsideGrid(vdbFrameGridUvw(c, world))) {\n return i32(c);\n }\n }\n return -1;\n}\n// sampleTiles on a stacked 3D texture: hardware trilinear in the R^3 sub-volume at origin, clamped to its\n// half-texel box (his clamp to edge in a slice and between slices)\nfn vdbFrameStackSample(stack: texture_3d<f32>, origin: vec3f, uvw: vec3f) -> vec4f {\n let r = vdbFrame.gridLayout.y;\n let p = origin + clamp(uvw * r, vec3f(0.5), vec3f(r - 0.5));\n return textureSampleLevel(stack, vdbFrameLinear, p / vec3f(textureDimensions(stack)), 0.0);\n}\n// his grid atlas pixel of a voxel (the jitter noise reads it): tile cascade * R + z of an atlas with gridLayout.z columns\nfn vdbFrameGridFragCoord(cascade: u32, cell: vec3u) -> vec2f {\n let r = u32(vdbFrame.gridLayout.y);\n let columns = u32(vdbFrame.gridLayout.z);\n let tile = cascade * r + cell.z;\n return vec2f(f32((tile % columns) * r + cell.x), f32((tile / columns) * r + cell.y)) + 0.5;\n}\n`,\n },\n ],\n [\n \"srgb\",\n {\n deps: [],\n code: `// three's sRGBTransferOETF / sRGBTransferEOTF\nfn vdbFrameSrgbOetf(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 vdbFrameSrgbEotf(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];\n\nconst BY_NAME = new Map(CHUNKS);\n\n/** Names of the chunks {@link frameChunksWgsl} knows. */\nexport type VDBFrameChunk = \"constants\" | \"mat3\" | \"sliceDepth\" | \"viewPosition\" | \"froxel\" | \"noise\" | \"rand\" | \"fade\" | \"box\" | \"lod\" | \"phase\" | \"ambientPhase\" | \"msExit\" | \"shadow\" | \"octaveTotal\" | \"octaves\" | \"spectral\" | \"sh\" | \"envSh\" | \"grid\" | \"srgb\";\n\n/** The closure of `roots` (with dependencies), in the fixed chunk order. */\nexport function frameChunksWgsl(roots: Iterable<VDBFrameChunk>): string {\n const want = new Set<string>();\n const visit = (name: string) => {\n if (want.has(name)) return;\n const chunk = BY_NAME.get(name);\n if (!chunk) throw new Error(`frameChunksWgsl: unknown chunk ${name}`);\n want.add(name);\n for (const d of chunk.deps) visit(d);\n };\n for (const r of roots) visit(r);\n return CHUNKS.filter(([name]) => want.has(name))\n .map(([, c]) => c.code)\n .join(\"\\n\");\n}\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emission in the core renderer (K6.5):
|
|
3
|
+
*
|
|
4
|
+
* - `vdbFrameEmissionColorWgsl(...)`: the volume record's emission colour (white, a LUT row, or the user hook), used
|
|
5
|
+
* by `vdbFrameEmission` in every source kernel that lights or emits.
|
|
6
|
+
* - `vdbFrameEmissionDirectionCs` (64 lanes = 8² rays; dispatch 16 directions × emitters of a source group): each
|
|
7
|
+
* volume's emitted light along 16 Fibonacci directions (intensity × ray area, radius; luminance-weighted centre).
|
|
8
|
+
* - `vdbFrameEmissionReduceCs` (64 per workgroup; one thread per slot): the mean intensity and the emission centre.
|
|
9
|
+
* - `vdbFrameEmissionProbeCs` (4×4×4 per probe voxel of every cascade): L1 irradiance of all emitters as point lights.
|
|
10
|
+
* - `vdbEmissionProbeWgsl()`: `vdbEmissionIrradiance(probes, smp, grid, world, normal)` for host receivers.
|
|
11
|
+
*/
|
|
12
|
+
import type { VDBVolumeChannels } from "../../source/types.js";
|
|
13
|
+
/** Directions per emitter (his `frameEmissionDirections`). */
|
|
14
|
+
export declare const VDB_FRAME_EMISSION_DIRECTIONS = 16;
|
|
15
|
+
/** Rays per side of the square that covers an emitter (his `frameEmissionRays`); one lane each. */
|
|
16
|
+
export declare const VDB_FRAME_EMISSION_RAYS = 8;
|
|
17
|
+
/** Most emitters per update (one direction-pass item each). */
|
|
18
|
+
export declare const VDB_FRAME_MAX_EMITTERS = 128;
|
|
19
|
+
/** Most probe cascades (his `frameEmissionMaxCascades`). */
|
|
20
|
+
export declare const VDB_FRAME_EMISSION_MAX_CASCADES = 4;
|
|
21
|
+
/** Texels of one emission colour LUT row (over log temperature, 500–40,000 K). */
|
|
22
|
+
export declare const VDB_FRAME_EMISSION_LUT_SIZE = 256;
|
|
23
|
+
/** The LUT's temperature range (his blackbody table's). */
|
|
24
|
+
export declare const VDB_FRAME_EMISSION_LUT_KELVIN: readonly [500, 40000];
|
|
25
|
+
/**
|
|
26
|
+
* The emitters a direction pass reads (group 1): one segment per source group at a dynamic offset
|
|
27
|
+
* ({@link VDB_FRAME_EMITTERS_STRIDE}); per item the volume record and slot, and its bounding sphere.
|
|
28
|
+
*/
|
|
29
|
+
export declare const VDB_FRAME_EMITTERS: import("../uniforms.js").VDBUniformStruct;
|
|
30
|
+
/** Bytes between the emitter list's per-group segments (256-aligned dynamic offsets). */
|
|
31
|
+
export declare const VDB_FRAME_EMITTERS_STRIDE: number;
|
|
32
|
+
/** The probe grid (group 1 of the probe kernel; the receivers' `grid`). */
|
|
33
|
+
export declare const VDB_EMISSION_GRID: import("../uniforms.js").VDBUniformStruct;
|
|
34
|
+
/** Group-1 bindings of the emission kernels. */
|
|
35
|
+
export declare const EMISSION_DIRECTION_BINDINGS: {
|
|
36
|
+
readonly volumes: 0;
|
|
37
|
+
readonly emitters: 2;
|
|
38
|
+
readonly lut: 3;
|
|
39
|
+
readonly directions: 4;
|
|
40
|
+
};
|
|
41
|
+
export declare const EMISSION_REDUCE_BINDINGS: {
|
|
42
|
+
readonly emitters: 0;
|
|
43
|
+
readonly directions: 1;
|
|
44
|
+
readonly out: 2;
|
|
45
|
+
};
|
|
46
|
+
export declare const EMISSION_PROBE_BINDINGS: {
|
|
47
|
+
readonly grid: 0;
|
|
48
|
+
readonly emitters: 1;
|
|
49
|
+
readonly probes: 2;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The emission colour of the source functions: `march.w` of a volume record is its colour code (bits 0–1 the mode: 0
|
|
53
|
+
* white, 1 LUT row, 2 the user hook; bits 2+ the LUT row). `lutBinding`: the kernel's group-1 binding of the LUT
|
|
54
|
+
* texture (null: white only, no binding). `hook`: the validated user WGSL (`fn vdbUserEmissionColor(t: f32,
|
|
55
|
+
* temperature: f32) -> vec3f`, t the normalized temperature), or null.
|
|
56
|
+
*/
|
|
57
|
+
export declare function vdbFrameEmissionColorWgsl(o: {
|
|
58
|
+
lutBinding: number | null;
|
|
59
|
+
hook: string | null;
|
|
60
|
+
}): string;
|
|
61
|
+
/** The direction kernel (after the source module, the source WGSL, `vdbFrameUniformsWgsl()` and the source functions). */
|
|
62
|
+
export declare function vdbFrameEmissionDirectionWgsl(): string;
|
|
63
|
+
/** The reduce kernel (after `vdbFrameUniformsWgsl()`; source-free). */
|
|
64
|
+
export declare function vdbFrameEmissionReduceWgsl(): string;
|
|
65
|
+
/** The probe kernel (after `vdbFrameUniformsWgsl()`; source-free). */
|
|
66
|
+
export declare function vdbFrameEmissionProbeWgsl(): string;
|
|
67
|
+
/**
|
|
68
|
+
* WGSL for hosts that light their surfaces with the volumes' emission (design §2.5): the `VdbEmissionGrid` struct and
|
|
69
|
+
*
|
|
70
|
+
* fn vdbEmissionIrradiance(probes: texture_3d<f32>, smp: sampler, grid: VdbEmissionGrid, world: vec3f, normal: vec3f) -> vec3f
|
|
71
|
+
*
|
|
72
|
+
* Bind `outputs.emissionProbes.texture` (a `'3d'` view), a filtering sampler (linear, clamp to edge) and
|
|
73
|
+
* `outputs.emissionProbes.grid` (`var<uniform>`; it also has `STORAGE` usage, for engines that bind foreign buffers only
|
|
74
|
+
* as storage: `./three` reads it as `array<vec4u>` and unpacks the struct). The result is irradiance (his light node's E(n) before the light's
|
|
75
|
+
* colour × intensity); a Lambert surface adds albedo × E / π. CPU twin: tools/frame `vdbFrameEmissionLookup` +
|
|
76
|
+
* `vdbFrameEmissionIrradiance` (on a stack sampler).
|
|
77
|
+
*/
|
|
78
|
+
export declare function vdbEmissionProbeWgsl(): string;
|
|
79
|
+
/** The `?probe=emission` receiver kernel (harness): rows of (world, 0), (normal, 0) → (E rgb, 0). */
|
|
80
|
+
export declare function vdbEmissionIrradianceProbeWgsl(): string;
|
|
81
|
+
/** Whether `channels` emit (the emission kernels and the LUT binding exist only then). */
|
|
82
|
+
export declare const vdbFrameEmits: (channels: VDBVolumeChannels) => boolean;
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
|
|
2
|
+
// src/three-openvdb/frame/webgpu/FrameEmissionLight.js L59–60 (golden angle), L168–237 (the direction pass),
|
|
3
|
+
// L259–279 (the reduce pass), L310–364 (the probe pass), L457–519 (the light node's irradiance);
|
|
4
|
+
// src/three-openvdb/frame/webgpu/frameShaderChunks.js L222–256 (frameBlackbodyColor, the table read), L1003–1010
|
|
5
|
+
// (the 'planck' / 'soot' branch of sampleEmission).
|
|
6
|
+
// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
|
|
7
|
+
// Changes: compute kernels (K6.5, design §3.3, §3.8): the direction pass is one workgroup per (direction, emitter)
|
|
8
|
+
// with one lane per ray and a workgroup reduction (his: one fragment loops the 64 rays); the probes are a stacked 3D
|
|
9
|
+
// texture (3 sub-volumes per cascade) read with hardware trilinear (his: a 2D atlas with a manual z lerp). Emission
|
|
10
|
+
// colour is data: a 256-texel LUT row per volume over log temperature (his blackbody table pre-blended to the volume's
|
|
11
|
+
// soot exponent) or a validated user WGSL hook. CPU twins: tools/frame (emission.ts, blackbody.ts). Divergences:
|
|
12
|
+
// DIVERGES.md (K6.5 rows).
|
|
13
|
+
import { vdbUniformStruct } from "../uniforms.js";
|
|
14
|
+
/** Directions per emitter (his `frameEmissionDirections`). */
|
|
15
|
+
export const VDB_FRAME_EMISSION_DIRECTIONS = 16;
|
|
16
|
+
/** Rays per side of the square that covers an emitter (his `frameEmissionRays`); one lane each. */
|
|
17
|
+
export const VDB_FRAME_EMISSION_RAYS = 8;
|
|
18
|
+
/** Most emitters per update (one direction-pass item each). */
|
|
19
|
+
export const VDB_FRAME_MAX_EMITTERS = 128;
|
|
20
|
+
/** Most probe cascades (his `frameEmissionMaxCascades`). */
|
|
21
|
+
export const VDB_FRAME_EMISSION_MAX_CASCADES = 4;
|
|
22
|
+
/** Texels of one emission colour LUT row (over log temperature, 500–40,000 K). */
|
|
23
|
+
export const VDB_FRAME_EMISSION_LUT_SIZE = 256;
|
|
24
|
+
/** The LUT's temperature range (his blackbody table's). */
|
|
25
|
+
export const VDB_FRAME_EMISSION_LUT_KELVIN = [500, 40000];
|
|
26
|
+
/**
|
|
27
|
+
* The emitters a direction pass reads (group 1): one segment per source group at a dynamic offset
|
|
28
|
+
* ({@link VDB_FRAME_EMITTERS_STRIDE}); per item the volume record and slot, and its bounding sphere.
|
|
29
|
+
*/
|
|
30
|
+
export const VDB_FRAME_EMITTERS = vdbUniformStruct("VdbFrameEmitterList", [
|
|
31
|
+
// items of this segment, steps per ray, slots, spare
|
|
32
|
+
{ name: "header", type: "vec4u" },
|
|
33
|
+
// (volume record, slot, 0, 0)
|
|
34
|
+
{ name: "info", type: "vec4u", count: VDB_FRAME_MAX_EMITTERS },
|
|
35
|
+
// (centre xyz, radius)
|
|
36
|
+
{ name: "sphere", type: "vec4f", count: VDB_FRAME_MAX_EMITTERS },
|
|
37
|
+
]);
|
|
38
|
+
/** Bytes between the emitter list's per-group segments (256-aligned dynamic offsets). */
|
|
39
|
+
export const VDB_FRAME_EMITTERS_STRIDE = Math.ceil(VDB_FRAME_EMITTERS.size / 256) * 256;
|
|
40
|
+
/** The probe grid (group 1 of the probe kernel; the receivers' `grid`). */
|
|
41
|
+
export const VDB_EMISSION_GRID = vdbUniformStruct("VdbEmissionGrid", [
|
|
42
|
+
{ name: "gridMin", type: "vec4f", count: VDB_FRAME_EMISSION_MAX_CASCADES },
|
|
43
|
+
{ name: "gridSize", type: "vec4f", count: VDB_FRAME_EMISSION_MAX_CASCADES },
|
|
44
|
+
// texel origin of (cascade c, channel k) at [3c + k] in the probe stack (k: red, green, blue)
|
|
45
|
+
{ name: "origin", type: "vec4f", count: 3 * VDB_FRAME_EMISSION_MAX_CASCADES },
|
|
46
|
+
// the centre of all emitters (xyz), active (1 when some emitter is visible)
|
|
47
|
+
{ name: "center", type: "vec4f" },
|
|
48
|
+
// cascade count, probes per axis, emitters, spare
|
|
49
|
+
{ name: "info", type: "vec4f" },
|
|
50
|
+
]);
|
|
51
|
+
/** Group-1 bindings of the emission kernels. */
|
|
52
|
+
export const EMISSION_DIRECTION_BINDINGS = { volumes: 0, emitters: 2, lut: 3, directions: 4 };
|
|
53
|
+
export const EMISSION_REDUCE_BINDINGS = { emitters: 0, directions: 1, out: 2 };
|
|
54
|
+
export const EMISSION_PROBE_BINDINGS = { grid: 0, emitters: 1, probes: 2 };
|
|
55
|
+
const LUT_SCALE = Math.log(VDB_FRAME_EMISSION_LUT_KELVIN[1] / VDB_FRAME_EMISSION_LUT_KELVIN[0]);
|
|
56
|
+
/**
|
|
57
|
+
* The emission colour of the source functions: `march.w` of a volume record is its colour code (bits 0–1 the mode: 0
|
|
58
|
+
* white, 1 LUT row, 2 the user hook; bits 2+ the LUT row). `lutBinding`: the kernel's group-1 binding of the LUT
|
|
59
|
+
* texture (null: white only, no binding). `hook`: the validated user WGSL (`fn vdbUserEmissionColor(t: f32,
|
|
60
|
+
* temperature: f32) -> vec3f`, t the normalized temperature), or null.
|
|
61
|
+
*/
|
|
62
|
+
export function vdbFrameEmissionColorWgsl(o) {
|
|
63
|
+
if (o.lutBinding === null) {
|
|
64
|
+
return `fn vdbFrameEmissionColor(code: u32, t: f32, temperature: f32) -> vec3f {
|
|
65
|
+
return vec3f(1.0);
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
}
|
|
69
|
+
return `${o.hook ? `${o.hook}\n` : ""}@group(1) @binding(${o.lutBinding}) var vdbFrameEmissionLut: texture_2d<f32>;
|
|
70
|
+
// frameBlackbodyColor on one LUT row: linear in log temperature between texels (textureLoad, no sampler)
|
|
71
|
+
fn vdbFrameEmissionLutColor(row: u32, temperature: f32) -> vec3f {
|
|
72
|
+
let x = clamp(log(max(temperature, 1e-3) / ${VDB_FRAME_EMISSION_LUT_KELVIN[0].toFixed(1)}) / ${LUT_SCALE}, 0.0, 1.0) * ${(VDB_FRAME_EMISSION_LUT_SIZE - 1).toFixed(1)};
|
|
73
|
+
let column = min(u32(x), ${VDB_FRAME_EMISSION_LUT_SIZE - 2}u);
|
|
74
|
+
let blend = x - f32(column);
|
|
75
|
+
return mix(textureLoad(vdbFrameEmissionLut, vec2u(column, row), 0).rgb, textureLoad(vdbFrameEmissionLut, vec2u(column + 1u, row), 0).rgb, blend);
|
|
76
|
+
}
|
|
77
|
+
// The colour of a volume's emission: white (mode 0), a LUT row (1), the user hook (2)
|
|
78
|
+
fn vdbFrameEmissionColor(code: u32, t: f32, temperature: f32) -> vec3f {
|
|
79
|
+
let mode = code & 3u;
|
|
80
|
+
if (mode == 1u) {
|
|
81
|
+
return vdbFrameEmissionLutColor(code >> 2u, temperature);
|
|
82
|
+
}
|
|
83
|
+
${o.hook ? ` if (mode == 2u) {
|
|
84
|
+
return vdbUserEmissionColor(t, temperature);
|
|
85
|
+
}
|
|
86
|
+
` : ""} return vec3f(1.0);
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
}
|
|
90
|
+
/** The direction kernel (after the source module, the source WGSL, `vdbFrameUniformsWgsl()` and the source functions). */
|
|
91
|
+
export function vdbFrameEmissionDirectionWgsl() {
|
|
92
|
+
const b = EMISSION_DIRECTION_BINDINGS;
|
|
93
|
+
const D = VDB_FRAME_EMISSION_DIRECTIONS;
|
|
94
|
+
const R = VDB_FRAME_EMISSION_RAYS;
|
|
95
|
+
return `${VDB_FRAME_EMITTERS.wgsl}@group(1) @binding(${b.emitters}) var<uniform> vdbFrameEmitters: VdbFrameEmitterList;
|
|
96
|
+
@group(1) @binding(${b.directions}) var vdbFrameEmissionDirectionsOut: texture_storage_2d<rgba32float, write>;
|
|
97
|
+
|
|
98
|
+
const VDB_FRAME_GOLDEN_ANGLE: f32 = ${Math.PI * (3 - Math.sqrt(5))};
|
|
99
|
+
var<workgroup> vdbFrameEmissionLanes: array<vec4f, ${2 * R * R}>;
|
|
100
|
+
|
|
101
|
+
// His direction pass for one (direction, emitter): lane r is ray r of the 8x8 square over the bounding sphere; each
|
|
102
|
+
// adds emission x alpha x the transmittance so far (absorbance scales the transmittance) and stops below 1%.
|
|
103
|
+
@compute @workgroup_size(${R * R}, 1, 1)
|
|
104
|
+
fn vdbFrameEmissionDirectionCs(@builtin(workgroup_id) wg: vec3u, @builtin(local_invocation_index) lane: u32) {
|
|
105
|
+
// the list segment of this source group (a dynamic offset): its items are this dispatch's emitters
|
|
106
|
+
if (wg.y >= vdbFrameEmitters.header.x || wg.x >= ${D}u) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
let item = wg.y;
|
|
110
|
+
let vi = vdbFrameEmitters.info[item].x;
|
|
111
|
+
let slot = vdbFrameEmitters.info[item].y;
|
|
112
|
+
let sphere = vdbFrameEmitters.sphere[item];
|
|
113
|
+
let index = f32(wg.x);
|
|
114
|
+
let y = 1.0 - (index * 2.0 + 1.0) / ${D}.0;
|
|
115
|
+
let ring = sqrt(max(0.0, 1.0 - y * y));
|
|
116
|
+
let phi = index * VDB_FRAME_GOLDEN_ANGLE;
|
|
117
|
+
let direction = vec3f(cos(phi) * ring, y, sin(phi) * ring);
|
|
118
|
+
let helper = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 1.0, 0.0), abs(direction.y) < 0.999);
|
|
119
|
+
let tangent = normalize(cross(helper, direction));
|
|
120
|
+
let bitangent = cross(direction, tangent);
|
|
121
|
+
let radius = sphere.w;
|
|
122
|
+
let diameter = radius * 2.0;
|
|
123
|
+
let spacing = diameter / ${R}.0;
|
|
124
|
+
let steps = vdbFrameEmitters.header.y;
|
|
125
|
+
let stepCount = f32(steps);
|
|
126
|
+
let u = (f32(lane % ${R}u) + 0.5) / ${R}.0 * 2.0 - 1.0;
|
|
127
|
+
let v = (f32(lane / ${R}u) + 0.5) / ${R}.0 * 2.0 - 1.0;
|
|
128
|
+
let worldStart = sphere.xyz + direction * radius + tangent * (u * radius) + bitangent * (v * radius);
|
|
129
|
+
let worldEnd = worldStart - direction * diameter;
|
|
130
|
+
let worldToLocal = vdbFrameVolumes.v[vi].worldToLocal;
|
|
131
|
+
let localStart = (worldToLocal * vec4f(worldStart, 1.0)).xyz;
|
|
132
|
+
let localEnd = (worldToLocal * vec4f(worldEnd, 1.0)).xyz;
|
|
133
|
+
let segment = vdbFrameBoxSegment(localStart, localEnd);
|
|
134
|
+
var intensity = vec3f(0.0);
|
|
135
|
+
var center = vec4f(0.0);
|
|
136
|
+
if (segment.x < segment.y) {
|
|
137
|
+
let segmentLength = segment.y - segment.x;
|
|
138
|
+
let stepLength = segmentLength * diameter / stepCount;
|
|
139
|
+
let texels = vdbSrcTexels(vdbFrameVolumes.v[vi].slices.z);
|
|
140
|
+
let maxTexels = max(texels.x, max(texels.y, texels.z));
|
|
141
|
+
// Smoke reads the mip level of the step; emission level 0 (power grows with temperature^4, mipmaps lose it)
|
|
142
|
+
let lod = select(0.0, vdbFrameLod(stepLength / vdbFrameVolumes.v[vi].density.z, maxTexels), vdbFrameVolumes.v[vi].march.y != 0u);
|
|
143
|
+
let absorbance = vdbFrameVolumes.v[vi].density.w;
|
|
144
|
+
var transmittance = 1.0;
|
|
145
|
+
for (var s = 0u; s < steps; s++) {
|
|
146
|
+
let t = segment.x + segmentLength * ((f32(s) + 0.5) / stepCount);
|
|
147
|
+
let localPoint = mix(localStart, localEnd, vec3f(t));
|
|
148
|
+
let extinction = vdbFrameExtinction(vi, localPoint, lod);
|
|
149
|
+
if (extinction > 0.0) {
|
|
150
|
+
let alpha = 1.0 - exp(-extinction * stepLength);
|
|
151
|
+
let radiance = vdbFrameEmission(vi, localPoint, 0.0) * (transmittance * alpha);
|
|
152
|
+
intensity += radiance;
|
|
153
|
+
center += vec4f(mix(worldStart, worldEnd, vec3f(t)), 1.0) * dot(radiance, vec3f(0.2126, 0.7152, 0.0722));
|
|
154
|
+
transmittance *= exp(-extinction * absorbance * stepLength);
|
|
155
|
+
if (transmittance < 0.01) {
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
vdbFrameEmissionLanes[lane] = vec4f(intensity, 0.0);
|
|
162
|
+
vdbFrameEmissionLanes[lane + ${R * R}u] = center;
|
|
163
|
+
workgroupBarrier();
|
|
164
|
+
for (var width = ${(R * R) / 2}u; width > 0u; width = width >> 1u) {
|
|
165
|
+
if (lane < width) {
|
|
166
|
+
vdbFrameEmissionLanes[lane] += vdbFrameEmissionLanes[lane + width];
|
|
167
|
+
vdbFrameEmissionLanes[lane + ${R * R}u] += vdbFrameEmissionLanes[lane + ${R * R}u + width];
|
|
168
|
+
}
|
|
169
|
+
workgroupBarrier();
|
|
170
|
+
}
|
|
171
|
+
if (lane == 0u) {
|
|
172
|
+
let area = spacing * spacing;
|
|
173
|
+
textureStore(vdbFrameEmissionDirectionsOut, vec2u(wg.x, slot), vec4f(vdbFrameEmissionLanes[0].xyz * area, radius));
|
|
174
|
+
textureStore(vdbFrameEmissionDirectionsOut, vec2u(wg.x + ${D}u, slot), vdbFrameEmissionLanes[${R * R}u] * area);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
`;
|
|
178
|
+
}
|
|
179
|
+
/** The reduce kernel (after `vdbFrameUniformsWgsl()`; source-free). */
|
|
180
|
+
export function vdbFrameEmissionReduceWgsl() {
|
|
181
|
+
const b = EMISSION_REDUCE_BINDINGS;
|
|
182
|
+
const D = VDB_FRAME_EMISSION_DIRECTIONS;
|
|
183
|
+
return `${VDB_FRAME_EMITTERS.wgsl}@group(1) @binding(${b.emitters}) var<uniform> vdbFrameEmitters: VdbFrameEmitterList;
|
|
184
|
+
@group(1) @binding(${b.directions}) var vdbFrameEmissionDirections: texture_2d<f32>;
|
|
185
|
+
@group(1) @binding(${b.out}) var vdbFrameEmitterOut: texture_storage_2d<rgba32float, write>;
|
|
186
|
+
|
|
187
|
+
// His reduce pass for one slot: the mean intensity of the 16 directions; the centre of the visible emission
|
|
188
|
+
@compute @workgroup_size(64, 1, 1)
|
|
189
|
+
fn vdbFrameEmissionReduceCs(@builtin(global_invocation_id) gid: vec3u) {
|
|
190
|
+
let slot = gid.x;
|
|
191
|
+
if (slot >= vdbFrameEmitters.header.z) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
var intensity = vec4f(0.0);
|
|
195
|
+
var center = vec4f(0.0);
|
|
196
|
+
for (var i = 0u; i < ${D}u; i++) {
|
|
197
|
+
intensity += textureLoad(vdbFrameEmissionDirections, vec2u(i, slot), 0);
|
|
198
|
+
center += textureLoad(vdbFrameEmissionDirections, vec2u(i + ${D}u, slot), 0);
|
|
199
|
+
}
|
|
200
|
+
textureStore(vdbFrameEmitterOut, vec2u(0u, slot), intensity / ${D}.0);
|
|
201
|
+
textureStore(vdbFrameEmitterOut, vec2u(1u, slot), select(vec4f(0.0), vec4f(center.xyz / max(center.w, 1e-12), 1.0), center.w > 0.0));
|
|
202
|
+
}
|
|
203
|
+
`;
|
|
204
|
+
}
|
|
205
|
+
/** The probe kernel (after `vdbFrameUniformsWgsl()`; source-free). */
|
|
206
|
+
export function vdbFrameEmissionProbeWgsl() {
|
|
207
|
+
const b = EMISSION_PROBE_BINDINGS;
|
|
208
|
+
return `${VDB_EMISSION_GRID.wgsl}@group(1) @binding(${b.grid}) var<uniform> vdbEmissionGrid: VdbEmissionGrid;
|
|
209
|
+
@group(1) @binding(${b.emitters}) var vdbFrameEmitterIn: texture_2d<f32>;
|
|
210
|
+
@group(1) @binding(${b.probes}) var vdbFrameEmissionProbesOut: texture_storage_3d<rgba16float, write>;
|
|
211
|
+
|
|
212
|
+
// His probe pass at one probe: every emitter a point light at its emission centre, softened near it by a quarter of
|
|
213
|
+
// its radius; L1 projection E(n) = E/4 + E/2 dot(l, n), the direction fading near the centre
|
|
214
|
+
@compute @workgroup_size(4, 4, 4)
|
|
215
|
+
fn vdbFrameEmissionProbeCs(@builtin(global_invocation_id) gid: vec3u) {
|
|
216
|
+
let r = u32(vdbEmissionGrid.info.y);
|
|
217
|
+
let count = u32(vdbEmissionGrid.info.x);
|
|
218
|
+
if (gid.x >= r || gid.y >= r || gid.z >= r * count) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
let cascade = gid.z / r;
|
|
222
|
+
let cell = vec3u(gid.xy, gid.z - cascade * r);
|
|
223
|
+
let uvw = (vec3f(cell) + 0.5) / f32(r);
|
|
224
|
+
let probe = vdbEmissionGrid.gridMin[cascade].xyz + uvw * vdbEmissionGrid.gridSize[cascade].xyz;
|
|
225
|
+
var constant = vec3f(0.0);
|
|
226
|
+
var red = vec3f(0.0);
|
|
227
|
+
var green = vec3f(0.0);
|
|
228
|
+
var blue = vec3f(0.0);
|
|
229
|
+
let emitters = u32(vdbEmissionGrid.info.z);
|
|
230
|
+
for (var i = 0u; i < emitters; i++) {
|
|
231
|
+
let center = textureLoad(vdbFrameEmitterIn, vec2u(1u, i), 0);
|
|
232
|
+
if (center.w > 0.0) {
|
|
233
|
+
let emitter = textureLoad(vdbFrameEmitterIn, vec2u(0u, i), 0);
|
|
234
|
+
let toProbe = probe - center.xyz;
|
|
235
|
+
let distanceSquared = dot(toProbe, toProbe);
|
|
236
|
+
let soft = emitter.w * 0.25;
|
|
237
|
+
let softDistanceSquared = distanceSquared + soft * soft;
|
|
238
|
+
let irradiance = emitter.rgb / softDistanceSquared;
|
|
239
|
+
let toLight = toProbe * inverseSqrt(max(distanceSquared, 1e-12)) * (distanceSquared / softDistanceSquared * -0.5);
|
|
240
|
+
constant += irradiance * 0.25;
|
|
241
|
+
red += toLight * irradiance.r;
|
|
242
|
+
green += toLight * irradiance.g;
|
|
243
|
+
blue += toLight * irradiance.b;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
let base = cascade * 3u;
|
|
247
|
+
textureStore(vdbFrameEmissionProbesOut, vec3u(vdbEmissionGrid.origin[base].xyz) + cell, vec4f(constant.r, red));
|
|
248
|
+
textureStore(vdbFrameEmissionProbesOut, vec3u(vdbEmissionGrid.origin[base + 1u].xyz) + cell, vec4f(constant.g, green));
|
|
249
|
+
textureStore(vdbFrameEmissionProbesOut, vec3u(vdbEmissionGrid.origin[base + 2u].xyz) + cell, vec4f(constant.b, blue));
|
|
250
|
+
}
|
|
251
|
+
`;
|
|
252
|
+
}
|
|
253
|
+
const RECEIVER = `fn vdbEmissionGridUvw(grid: VdbEmissionGrid, cascade: u32, world: vec3f) -> vec3f {
|
|
254
|
+
return (world - grid.gridMin[cascade].xyz) / grid.gridSize[cascade].xyz;
|
|
255
|
+
}
|
|
256
|
+
// the finest cascade from first that holds the position half a probe in, or -1
|
|
257
|
+
fn vdbEmissionFindCascade(grid: VdbEmissionGrid, world: vec3f, first: u32) -> i32 {
|
|
258
|
+
let inset = 0.5 / grid.info.y;
|
|
259
|
+
for (var c = first; c < u32(grid.info.x); c++) {
|
|
260
|
+
let uvw = vdbEmissionGridUvw(grid, c, world);
|
|
261
|
+
if (min(uvw.x, min(uvw.y, uvw.z)) >= inset && max(uvw.x, max(uvw.y, uvw.z)) <= 1.0 - inset) {
|
|
262
|
+
return i32(c);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return -1;
|
|
266
|
+
}
|
|
267
|
+
// one channel's L1 probe of a cascade: hardware trilinear in its sub-volume, clamped to the half-texel box
|
|
268
|
+
fn vdbEmissionProbeSample(probes: texture_3d<f32>, smp: sampler, grid: VdbEmissionGrid, cascade: u32, channel: u32, uvw: vec3f) -> vec4f {
|
|
269
|
+
let r = grid.info.y;
|
|
270
|
+
let p = grid.origin[cascade * 3u + channel].xyz + clamp(uvw * r, vec3f(0.5), vec3f(r - 0.5));
|
|
271
|
+
return textureSampleLevel(probes, smp, p / vec3f(textureDimensions(probes)), 0.0);
|
|
272
|
+
}
|
|
273
|
+
// The irradiance of the volumes' emission at a lit point: the finest cascade that holds it, blended into the next one
|
|
274
|
+
// within a tenth of its sides; past the last cascade its clamped edge probes fall off with distance squared
|
|
275
|
+
fn vdbEmissionIrradiance(probes: texture_3d<f32>, smp: sampler, grid: VdbEmissionGrid, world: vec3f, normal: vec3f) -> vec3f {
|
|
276
|
+
if (grid.info.x < 0.5) {
|
|
277
|
+
return vec3f(0.0);
|
|
278
|
+
}
|
|
279
|
+
var red = vec4f(0.0);
|
|
280
|
+
var green = vec4f(0.0);
|
|
281
|
+
var blue = vec4f(0.0);
|
|
282
|
+
var falloff = 1.0;
|
|
283
|
+
let found = vdbEmissionFindCascade(grid, world, 0u);
|
|
284
|
+
if (found >= 0) {
|
|
285
|
+
let cascade = u32(found);
|
|
286
|
+
let uvw = vdbEmissionGridUvw(grid, cascade, world);
|
|
287
|
+
red = vdbEmissionProbeSample(probes, smp, grid, cascade, 0u, uvw);
|
|
288
|
+
green = vdbEmissionProbeSample(probes, smp, grid, cascade, 1u, uvw);
|
|
289
|
+
blue = vdbEmissionProbeSample(probes, smp, grid, cascade, 2u, uvw);
|
|
290
|
+
let side = min(uvw, vec3f(1.0) - uvw);
|
|
291
|
+
let blend = 1.0 - smoothstep(0.0, 0.1, min(side.x, min(side.y, side.z)));
|
|
292
|
+
if (blend > 0.0) {
|
|
293
|
+
let next = vdbEmissionFindCascade(grid, world, cascade + 1u);
|
|
294
|
+
if (next >= 0) {
|
|
295
|
+
let n = u32(next);
|
|
296
|
+
let nextUvw = vdbEmissionGridUvw(grid, n, world);
|
|
297
|
+
red = mix(red, vdbEmissionProbeSample(probes, smp, grid, n, 0u, nextUvw), vec4f(blend));
|
|
298
|
+
green = mix(green, vdbEmissionProbeSample(probes, smp, grid, n, 1u, nextUvw), vec4f(blend));
|
|
299
|
+
blue = mix(blue, vdbEmissionProbeSample(probes, smp, grid, n, 2u, nextUvw), vec4f(blend));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
let last = u32(grid.info.x) - 1u;
|
|
304
|
+
let inset = 0.5 / grid.info.y;
|
|
305
|
+
let uvw = clamp(vdbEmissionGridUvw(grid, last, world), vec3f(inset), vec3f(1.0 - inset));
|
|
306
|
+
let toEdge = grid.gridMin[last].xyz + uvw * grid.gridSize[last].xyz - grid.center.xyz;
|
|
307
|
+
let toPoint = world - grid.center.xyz;
|
|
308
|
+
red = vdbEmissionProbeSample(probes, smp, grid, last, 0u, uvw);
|
|
309
|
+
green = vdbEmissionProbeSample(probes, smp, grid, last, 1u, uvw);
|
|
310
|
+
blue = vdbEmissionProbeSample(probes, smp, grid, last, 2u, uvw);
|
|
311
|
+
falloff = min(1.0, dot(toEdge, toEdge) / max(dot(toPoint, toPoint), 1e-6));
|
|
312
|
+
}
|
|
313
|
+
let e = vec3f(red.x + dot(red.yzw, normal), green.x + dot(green.yzw, normal), blue.x + dot(blue.yzw, normal));
|
|
314
|
+
return max(e, vec3f(0.0)) * (falloff * grid.center.w);
|
|
315
|
+
}
|
|
316
|
+
`;
|
|
317
|
+
/**
|
|
318
|
+
* WGSL for hosts that light their surfaces with the volumes' emission (design §2.5): the `VdbEmissionGrid` struct and
|
|
319
|
+
*
|
|
320
|
+
* fn vdbEmissionIrradiance(probes: texture_3d<f32>, smp: sampler, grid: VdbEmissionGrid, world: vec3f, normal: vec3f) -> vec3f
|
|
321
|
+
*
|
|
322
|
+
* Bind `outputs.emissionProbes.texture` (a `'3d'` view), a filtering sampler (linear, clamp to edge) and
|
|
323
|
+
* `outputs.emissionProbes.grid` (`var<uniform>`; it also has `STORAGE` usage, for engines that bind foreign buffers only
|
|
324
|
+
* as storage: `./three` reads it as `array<vec4u>` and unpacks the struct). The result is irradiance (his light node's E(n) before the light's
|
|
325
|
+
* colour × intensity); a Lambert surface adds albedo × E / π. CPU twin: tools/frame `vdbFrameEmissionLookup` +
|
|
326
|
+
* `vdbFrameEmissionIrradiance` (on a stack sampler).
|
|
327
|
+
*/
|
|
328
|
+
export function vdbEmissionProbeWgsl() {
|
|
329
|
+
return `${VDB_EMISSION_GRID.wgsl}${RECEIVER}`;
|
|
330
|
+
}
|
|
331
|
+
/** The `?probe=emission` receiver kernel (harness): rows of (world, 0), (normal, 0) → (E rgb, 0). */
|
|
332
|
+
export function vdbEmissionIrradianceProbeWgsl() {
|
|
333
|
+
return `${vdbEmissionProbeWgsl()}
|
|
334
|
+
@group(0) @binding(0) var<uniform> vdbProbeGrid: VdbEmissionGrid;
|
|
335
|
+
@group(0) @binding(1) var vdbProbeStack: texture_3d<f32>;
|
|
336
|
+
@group(0) @binding(2) var vdbProbeSampler: sampler;
|
|
337
|
+
@group(0) @binding(3) var<storage, read_write> vdbProbeRows: array<vec4f>;
|
|
338
|
+
|
|
339
|
+
@compute @workgroup_size(64, 1, 1)
|
|
340
|
+
fn vdbEmissionIrradianceProbeCs(@builtin(global_invocation_id) gid: vec3u) {
|
|
341
|
+
let rows = arrayLength(&vdbProbeRows) / 2u;
|
|
342
|
+
if (gid.x >= rows) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
let world = vdbProbeRows[gid.x * 2u].xyz;
|
|
346
|
+
let normal = vdbProbeRows[gid.x * 2u + 1u].xyz;
|
|
347
|
+
vdbProbeRows[gid.x * 2u] = vec4f(vdbEmissionIrradiance(vdbProbeStack, vdbProbeSampler, vdbProbeGrid, world, normal), 0.0);
|
|
348
|
+
}
|
|
349
|
+
`;
|
|
350
|
+
}
|
|
351
|
+
/** Whether `channels` emit (the emission kernels and the LUT binding exist only then). */
|
|
352
|
+
export const vdbFrameEmits = (channels) => !!channels.emission;
|
|
353
|
+
//# sourceMappingURL=emission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emission.js","sourceRoot":"","sources":["../../../../src/core/frame/wgsl/emission.ts"],"names":[],"mappings":"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","sourcesContent":["// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):\n// src/three-openvdb/frame/webgpu/FrameEmissionLight.js L59–60 (golden angle), L168–237 (the direction pass),\n// L259–279 (the reduce pass), L310–364 (the probe pass), L457–519 (the light node's irradiance);\n// src/three-openvdb/frame/webgpu/frameShaderChunks.js L222–256 (frameBlackbodyColor, the table read), L1003–1010\n// (the 'planck' / 'soot' branch of sampleEmission).\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: compute kernels (K6.5, design §3.3, §3.8): the direction pass is one workgroup per (direction, emitter)\n// with one lane per ray and a workgroup reduction (his: one fragment loops the 64 rays); the probes are a stacked 3D\n// texture (3 sub-volumes per cascade) read with hardware trilinear (his: a 2D atlas with a manual z lerp). Emission\n// colour is data: a 256-texel LUT row per volume over log temperature (his blackbody table pre-blended to the volume's\n// soot exponent) or a validated user WGSL hook. CPU twins: tools/frame (emission.ts, blackbody.ts). Divergences:\n// DIVERGES.md (K6.5 rows).\n\n/**\n * Emission in the core renderer (K6.5):\n *\n * - `vdbFrameEmissionColorWgsl(...)`: the volume record's emission colour (white, a LUT row, or the user hook), used\n * by `vdbFrameEmission` in every source kernel that lights or emits.\n * - `vdbFrameEmissionDirectionCs` (64 lanes = 8² rays; dispatch 16 directions × emitters of a source group): each\n * volume's emitted light along 16 Fibonacci directions (intensity × ray area, radius; luminance-weighted centre).\n * - `vdbFrameEmissionReduceCs` (64 per workgroup; one thread per slot): the mean intensity and the emission centre.\n * - `vdbFrameEmissionProbeCs` (4×4×4 per probe voxel of every cascade): L1 irradiance of all emitters as point lights.\n * - `vdbEmissionProbeWgsl()`: `vdbEmissionIrradiance(probes, smp, grid, world, normal)` for host receivers.\n */\n\nimport type { VDBVolumeChannels } from \"../../source/types.js\";\nimport { vdbUniformStruct } from \"../uniforms.js\";\n\n/** Directions per emitter (his `frameEmissionDirections`). */\nexport const VDB_FRAME_EMISSION_DIRECTIONS = 16;\n/** Rays per side of the square that covers an emitter (his `frameEmissionRays`); one lane each. */\nexport const VDB_FRAME_EMISSION_RAYS = 8;\n/** Most emitters per update (one direction-pass item each). */\nexport const VDB_FRAME_MAX_EMITTERS = 128;\n/** Most probe cascades (his `frameEmissionMaxCascades`). */\nexport const VDB_FRAME_EMISSION_MAX_CASCADES = 4;\n/** Texels of one emission colour LUT row (over log temperature, 500–40,000 K). */\nexport const VDB_FRAME_EMISSION_LUT_SIZE = 256;\n/** The LUT's temperature range (his blackbody table's). */\nexport const VDB_FRAME_EMISSION_LUT_KELVIN = [500, 40000] as const;\n\n/**\n * The emitters a direction pass reads (group 1): one segment per source group at a dynamic offset\n * ({@link VDB_FRAME_EMITTERS_STRIDE}); per item the volume record and slot, and its bounding sphere.\n */\nexport const VDB_FRAME_EMITTERS = vdbUniformStruct(\"VdbFrameEmitterList\", [\n // items of this segment, steps per ray, slots, spare\n { name: \"header\", type: \"vec4u\" },\n // (volume record, slot, 0, 0)\n { name: \"info\", type: \"vec4u\", count: VDB_FRAME_MAX_EMITTERS },\n // (centre xyz, radius)\n { name: \"sphere\", type: \"vec4f\", count: VDB_FRAME_MAX_EMITTERS },\n]);\n\n/** Bytes between the emitter list's per-group segments (256-aligned dynamic offsets). */\nexport const VDB_FRAME_EMITTERS_STRIDE = Math.ceil(VDB_FRAME_EMITTERS.size / 256) * 256;\n\n/** The probe grid (group 1 of the probe kernel; the receivers' `grid`). */\nexport const VDB_EMISSION_GRID = vdbUniformStruct(\"VdbEmissionGrid\", [\n { name: \"gridMin\", type: \"vec4f\", count: VDB_FRAME_EMISSION_MAX_CASCADES },\n { name: \"gridSize\", type: \"vec4f\", count: VDB_FRAME_EMISSION_MAX_CASCADES },\n // texel origin of (cascade c, channel k) at [3c + k] in the probe stack (k: red, green, blue)\n { name: \"origin\", type: \"vec4f\", count: 3 * VDB_FRAME_EMISSION_MAX_CASCADES },\n // the centre of all emitters (xyz), active (1 when some emitter is visible)\n { name: \"center\", type: \"vec4f\" },\n // cascade count, probes per axis, emitters, spare\n { name: \"info\", type: \"vec4f\" },\n]);\n\n/** Group-1 bindings of the emission kernels. */\nexport const EMISSION_DIRECTION_BINDINGS = { volumes: 0, emitters: 2, lut: 3, directions: 4 } as const;\nexport const EMISSION_REDUCE_BINDINGS = { emitters: 0, directions: 1, out: 2 } as const;\nexport const EMISSION_PROBE_BINDINGS = { grid: 0, emitters: 1, probes: 2 } as const;\n\nconst LUT_SCALE = Math.log(VDB_FRAME_EMISSION_LUT_KELVIN[1] / VDB_FRAME_EMISSION_LUT_KELVIN[0]);\n\n/**\n * The emission colour of the source functions: `march.w` of a volume record is its colour code (bits 0–1 the mode: 0\n * white, 1 LUT row, 2 the user hook; bits 2+ the LUT row). `lutBinding`: the kernel's group-1 binding of the LUT\n * texture (null: white only, no binding). `hook`: the validated user WGSL (`fn vdbUserEmissionColor(t: f32,\n * temperature: f32) -> vec3f`, t the normalized temperature), or null.\n */\nexport function vdbFrameEmissionColorWgsl(o: { lutBinding: number | null; hook: string | null }): string {\n if (o.lutBinding === null) {\n return `fn vdbFrameEmissionColor(code: u32, t: f32, temperature: f32) -> vec3f {\n return vec3f(1.0);\n}\n`;\n }\n return `${o.hook ? `${o.hook}\\n` : \"\"}@group(1) @binding(${o.lutBinding}) var vdbFrameEmissionLut: texture_2d<f32>;\n// frameBlackbodyColor on one LUT row: linear in log temperature between texels (textureLoad, no sampler)\nfn vdbFrameEmissionLutColor(row: u32, temperature: f32) -> vec3f {\n let x = clamp(log(max(temperature, 1e-3) / ${VDB_FRAME_EMISSION_LUT_KELVIN[0].toFixed(1)}) / ${LUT_SCALE}, 0.0, 1.0) * ${(VDB_FRAME_EMISSION_LUT_SIZE - 1).toFixed(1)};\n let column = min(u32(x), ${VDB_FRAME_EMISSION_LUT_SIZE - 2}u);\n let blend = x - f32(column);\n return mix(textureLoad(vdbFrameEmissionLut, vec2u(column, row), 0).rgb, textureLoad(vdbFrameEmissionLut, vec2u(column + 1u, row), 0).rgb, blend);\n}\n// The colour of a volume's emission: white (mode 0), a LUT row (1), the user hook (2)\nfn vdbFrameEmissionColor(code: u32, t: f32, temperature: f32) -> vec3f {\n let mode = code & 3u;\n if (mode == 1u) {\n return vdbFrameEmissionLutColor(code >> 2u, temperature);\n }\n${o.hook ? ` if (mode == 2u) {\n return vdbUserEmissionColor(t, temperature);\n }\n` : \"\"} return vec3f(1.0);\n}\n`;\n}\n\n/** The direction kernel (after the source module, the source WGSL, `vdbFrameUniformsWgsl()` and the source functions). */\nexport function vdbFrameEmissionDirectionWgsl(): string {\n const b = EMISSION_DIRECTION_BINDINGS;\n const D = VDB_FRAME_EMISSION_DIRECTIONS;\n const R = VDB_FRAME_EMISSION_RAYS;\n return `${VDB_FRAME_EMITTERS.wgsl}@group(1) @binding(${b.emitters}) var<uniform> vdbFrameEmitters: VdbFrameEmitterList;\n@group(1) @binding(${b.directions}) var vdbFrameEmissionDirectionsOut: texture_storage_2d<rgba32float, write>;\n\nconst VDB_FRAME_GOLDEN_ANGLE: f32 = ${Math.PI * (3 - Math.sqrt(5))};\nvar<workgroup> vdbFrameEmissionLanes: array<vec4f, ${2 * R * R}>;\n\n// His direction pass for one (direction, emitter): lane r is ray r of the 8x8 square over the bounding sphere; each\n// adds emission x alpha x the transmittance so far (absorbance scales the transmittance) and stops below 1%.\n@compute @workgroup_size(${R * R}, 1, 1)\nfn vdbFrameEmissionDirectionCs(@builtin(workgroup_id) wg: vec3u, @builtin(local_invocation_index) lane: u32) {\n // the list segment of this source group (a dynamic offset): its items are this dispatch's emitters\n if (wg.y >= vdbFrameEmitters.header.x || wg.x >= ${D}u) {\n return;\n }\n let item = wg.y;\n let vi = vdbFrameEmitters.info[item].x;\n let slot = vdbFrameEmitters.info[item].y;\n let sphere = vdbFrameEmitters.sphere[item];\n let index = f32(wg.x);\n let y = 1.0 - (index * 2.0 + 1.0) / ${D}.0;\n let ring = sqrt(max(0.0, 1.0 - y * y));\n let phi = index * VDB_FRAME_GOLDEN_ANGLE;\n let direction = vec3f(cos(phi) * ring, y, sin(phi) * ring);\n let helper = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 1.0, 0.0), abs(direction.y) < 0.999);\n let tangent = normalize(cross(helper, direction));\n let bitangent = cross(direction, tangent);\n let radius = sphere.w;\n let diameter = radius * 2.0;\n let spacing = diameter / ${R}.0;\n let steps = vdbFrameEmitters.header.y;\n let stepCount = f32(steps);\n let u = (f32(lane % ${R}u) + 0.5) / ${R}.0 * 2.0 - 1.0;\n let v = (f32(lane / ${R}u) + 0.5) / ${R}.0 * 2.0 - 1.0;\n let worldStart = sphere.xyz + direction * radius + tangent * (u * radius) + bitangent * (v * radius);\n let worldEnd = worldStart - direction * diameter;\n let worldToLocal = vdbFrameVolumes.v[vi].worldToLocal;\n let localStart = (worldToLocal * vec4f(worldStart, 1.0)).xyz;\n let localEnd = (worldToLocal * vec4f(worldEnd, 1.0)).xyz;\n let segment = vdbFrameBoxSegment(localStart, localEnd);\n var intensity = vec3f(0.0);\n var center = vec4f(0.0);\n if (segment.x < segment.y) {\n let segmentLength = segment.y - segment.x;\n let stepLength = segmentLength * diameter / stepCount;\n let texels = vdbSrcTexels(vdbFrameVolumes.v[vi].slices.z);\n let maxTexels = max(texels.x, max(texels.y, texels.z));\n // Smoke reads the mip level of the step; emission level 0 (power grows with temperature^4, mipmaps lose it)\n let lod = select(0.0, vdbFrameLod(stepLength / vdbFrameVolumes.v[vi].density.z, maxTexels), vdbFrameVolumes.v[vi].march.y != 0u);\n let absorbance = vdbFrameVolumes.v[vi].density.w;\n var transmittance = 1.0;\n for (var s = 0u; s < steps; s++) {\n let t = segment.x + segmentLength * ((f32(s) + 0.5) / stepCount);\n let localPoint = mix(localStart, localEnd, vec3f(t));\n let extinction = vdbFrameExtinction(vi, localPoint, lod);\n if (extinction > 0.0) {\n let alpha = 1.0 - exp(-extinction * stepLength);\n let radiance = vdbFrameEmission(vi, localPoint, 0.0) * (transmittance * alpha);\n intensity += radiance;\n center += vec4f(mix(worldStart, worldEnd, vec3f(t)), 1.0) * dot(radiance, vec3f(0.2126, 0.7152, 0.0722));\n transmittance *= exp(-extinction * absorbance * stepLength);\n if (transmittance < 0.01) {\n break;\n }\n }\n }\n }\n vdbFrameEmissionLanes[lane] = vec4f(intensity, 0.0);\n vdbFrameEmissionLanes[lane + ${R * R}u] = center;\n workgroupBarrier();\n for (var width = ${(R * R) / 2}u; width > 0u; width = width >> 1u) {\n if (lane < width) {\n vdbFrameEmissionLanes[lane] += vdbFrameEmissionLanes[lane + width];\n vdbFrameEmissionLanes[lane + ${R * R}u] += vdbFrameEmissionLanes[lane + ${R * R}u + width];\n }\n workgroupBarrier();\n }\n if (lane == 0u) {\n let area = spacing * spacing;\n textureStore(vdbFrameEmissionDirectionsOut, vec2u(wg.x, slot), vec4f(vdbFrameEmissionLanes[0].xyz * area, radius));\n textureStore(vdbFrameEmissionDirectionsOut, vec2u(wg.x + ${D}u, slot), vdbFrameEmissionLanes[${R * R}u] * area);\n }\n}\n`;\n}\n\n/** The reduce kernel (after `vdbFrameUniformsWgsl()`; source-free). */\nexport function vdbFrameEmissionReduceWgsl(): string {\n const b = EMISSION_REDUCE_BINDINGS;\n const D = VDB_FRAME_EMISSION_DIRECTIONS;\n return `${VDB_FRAME_EMITTERS.wgsl}@group(1) @binding(${b.emitters}) var<uniform> vdbFrameEmitters: VdbFrameEmitterList;\n@group(1) @binding(${b.directions}) var vdbFrameEmissionDirections: texture_2d<f32>;\n@group(1) @binding(${b.out}) var vdbFrameEmitterOut: texture_storage_2d<rgba32float, write>;\n\n// His reduce pass for one slot: the mean intensity of the 16 directions; the centre of the visible emission\n@compute @workgroup_size(64, 1, 1)\nfn vdbFrameEmissionReduceCs(@builtin(global_invocation_id) gid: vec3u) {\n let slot = gid.x;\n if (slot >= vdbFrameEmitters.header.z) {\n return;\n }\n var intensity = vec4f(0.0);\n var center = vec4f(0.0);\n for (var i = 0u; i < ${D}u; i++) {\n intensity += textureLoad(vdbFrameEmissionDirections, vec2u(i, slot), 0);\n center += textureLoad(vdbFrameEmissionDirections, vec2u(i + ${D}u, slot), 0);\n }\n textureStore(vdbFrameEmitterOut, vec2u(0u, slot), intensity / ${D}.0);\n textureStore(vdbFrameEmitterOut, vec2u(1u, slot), select(vec4f(0.0), vec4f(center.xyz / max(center.w, 1e-12), 1.0), center.w > 0.0));\n}\n`;\n}\n\n/** The probe kernel (after `vdbFrameUniformsWgsl()`; source-free). */\nexport function vdbFrameEmissionProbeWgsl(): string {\n const b = EMISSION_PROBE_BINDINGS;\n return `${VDB_EMISSION_GRID.wgsl}@group(1) @binding(${b.grid}) var<uniform> vdbEmissionGrid: VdbEmissionGrid;\n@group(1) @binding(${b.emitters}) var vdbFrameEmitterIn: texture_2d<f32>;\n@group(1) @binding(${b.probes}) var vdbFrameEmissionProbesOut: texture_storage_3d<rgba16float, write>;\n\n// His probe pass at one probe: every emitter a point light at its emission centre, softened near it by a quarter of\n// its radius; L1 projection E(n) = E/4 + E/2 dot(l, n), the direction fading near the centre\n@compute @workgroup_size(4, 4, 4)\nfn vdbFrameEmissionProbeCs(@builtin(global_invocation_id) gid: vec3u) {\n let r = u32(vdbEmissionGrid.info.y);\n let count = u32(vdbEmissionGrid.info.x);\n if (gid.x >= r || gid.y >= r || gid.z >= r * count) {\n return;\n }\n let cascade = gid.z / r;\n let cell = vec3u(gid.xy, gid.z - cascade * r);\n let uvw = (vec3f(cell) + 0.5) / f32(r);\n let probe = vdbEmissionGrid.gridMin[cascade].xyz + uvw * vdbEmissionGrid.gridSize[cascade].xyz;\n var constant = vec3f(0.0);\n var red = vec3f(0.0);\n var green = vec3f(0.0);\n var blue = vec3f(0.0);\n let emitters = u32(vdbEmissionGrid.info.z);\n for (var i = 0u; i < emitters; i++) {\n let center = textureLoad(vdbFrameEmitterIn, vec2u(1u, i), 0);\n if (center.w > 0.0) {\n let emitter = textureLoad(vdbFrameEmitterIn, vec2u(0u, i), 0);\n let toProbe = probe - center.xyz;\n let distanceSquared = dot(toProbe, toProbe);\n let soft = emitter.w * 0.25;\n let softDistanceSquared = distanceSquared + soft * soft;\n let irradiance = emitter.rgb / softDistanceSquared;\n let toLight = toProbe * inverseSqrt(max(distanceSquared, 1e-12)) * (distanceSquared / softDistanceSquared * -0.5);\n constant += irradiance * 0.25;\n red += toLight * irradiance.r;\n green += toLight * irradiance.g;\n blue += toLight * irradiance.b;\n }\n }\n let base = cascade * 3u;\n textureStore(vdbFrameEmissionProbesOut, vec3u(vdbEmissionGrid.origin[base].xyz) + cell, vec4f(constant.r, red));\n textureStore(vdbFrameEmissionProbesOut, vec3u(vdbEmissionGrid.origin[base + 1u].xyz) + cell, vec4f(constant.g, green));\n textureStore(vdbFrameEmissionProbesOut, vec3u(vdbEmissionGrid.origin[base + 2u].xyz) + cell, vec4f(constant.b, blue));\n}\n`;\n}\n\nconst RECEIVER = `fn vdbEmissionGridUvw(grid: VdbEmissionGrid, cascade: u32, world: vec3f) -> vec3f {\n return (world - grid.gridMin[cascade].xyz) / grid.gridSize[cascade].xyz;\n}\n// the finest cascade from first that holds the position half a probe in, or -1\nfn vdbEmissionFindCascade(grid: VdbEmissionGrid, world: vec3f, first: u32) -> i32 {\n let inset = 0.5 / grid.info.y;\n for (var c = first; c < u32(grid.info.x); c++) {\n let uvw = vdbEmissionGridUvw(grid, c, world);\n if (min(uvw.x, min(uvw.y, uvw.z)) >= inset && max(uvw.x, max(uvw.y, uvw.z)) <= 1.0 - inset) {\n return i32(c);\n }\n }\n return -1;\n}\n// one channel's L1 probe of a cascade: hardware trilinear in its sub-volume, clamped to the half-texel box\nfn vdbEmissionProbeSample(probes: texture_3d<f32>, smp: sampler, grid: VdbEmissionGrid, cascade: u32, channel: u32, uvw: vec3f) -> vec4f {\n let r = grid.info.y;\n let p = grid.origin[cascade * 3u + channel].xyz + clamp(uvw * r, vec3f(0.5), vec3f(r - 0.5));\n return textureSampleLevel(probes, smp, p / vec3f(textureDimensions(probes)), 0.0);\n}\n// The irradiance of the volumes' emission at a lit point: the finest cascade that holds it, blended into the next one\n// within a tenth of its sides; past the last cascade its clamped edge probes fall off with distance squared\nfn vdbEmissionIrradiance(probes: texture_3d<f32>, smp: sampler, grid: VdbEmissionGrid, world: vec3f, normal: vec3f) -> vec3f {\n if (grid.info.x < 0.5) {\n return vec3f(0.0);\n }\n var red = vec4f(0.0);\n var green = vec4f(0.0);\n var blue = vec4f(0.0);\n var falloff = 1.0;\n let found = vdbEmissionFindCascade(grid, world, 0u);\n if (found >= 0) {\n let cascade = u32(found);\n let uvw = vdbEmissionGridUvw(grid, cascade, world);\n red = vdbEmissionProbeSample(probes, smp, grid, cascade, 0u, uvw);\n green = vdbEmissionProbeSample(probes, smp, grid, cascade, 1u, uvw);\n blue = vdbEmissionProbeSample(probes, smp, grid, cascade, 2u, uvw);\n let side = min(uvw, vec3f(1.0) - uvw);\n let blend = 1.0 - smoothstep(0.0, 0.1, min(side.x, min(side.y, side.z)));\n if (blend > 0.0) {\n let next = vdbEmissionFindCascade(grid, world, cascade + 1u);\n if (next >= 0) {\n let n = u32(next);\n let nextUvw = vdbEmissionGridUvw(grid, n, world);\n red = mix(red, vdbEmissionProbeSample(probes, smp, grid, n, 0u, nextUvw), vec4f(blend));\n green = mix(green, vdbEmissionProbeSample(probes, smp, grid, n, 1u, nextUvw), vec4f(blend));\n blue = mix(blue, vdbEmissionProbeSample(probes, smp, grid, n, 2u, nextUvw), vec4f(blend));\n }\n }\n } else {\n let last = u32(grid.info.x) - 1u;\n let inset = 0.5 / grid.info.y;\n let uvw = clamp(vdbEmissionGridUvw(grid, last, world), vec3f(inset), vec3f(1.0 - inset));\n let toEdge = grid.gridMin[last].xyz + uvw * grid.gridSize[last].xyz - grid.center.xyz;\n let toPoint = world - grid.center.xyz;\n red = vdbEmissionProbeSample(probes, smp, grid, last, 0u, uvw);\n green = vdbEmissionProbeSample(probes, smp, grid, last, 1u, uvw);\n blue = vdbEmissionProbeSample(probes, smp, grid, last, 2u, uvw);\n falloff = min(1.0, dot(toEdge, toEdge) / max(dot(toPoint, toPoint), 1e-6));\n }\n let e = vec3f(red.x + dot(red.yzw, normal), green.x + dot(green.yzw, normal), blue.x + dot(blue.yzw, normal));\n return max(e, vec3f(0.0)) * (falloff * grid.center.w);\n}\n`;\n\n/**\n * WGSL for hosts that light their surfaces with the volumes' emission (design §2.5): the `VdbEmissionGrid` struct and\n *\n * fn vdbEmissionIrradiance(probes: texture_3d<f32>, smp: sampler, grid: VdbEmissionGrid, world: vec3f, normal: vec3f) -> vec3f\n *\n * Bind `outputs.emissionProbes.texture` (a `'3d'` view), a filtering sampler (linear, clamp to edge) and\n * `outputs.emissionProbes.grid` (`var<uniform>`; it also has `STORAGE` usage, for engines that bind foreign buffers only\n * as storage: `./three` reads it as `array<vec4u>` and unpacks the struct). The result is irradiance (his light node's E(n) before the light's\n * colour × intensity); a Lambert surface adds albedo × E / π. CPU twin: tools/frame `vdbFrameEmissionLookup` +\n * `vdbFrameEmissionIrradiance` (on a stack sampler).\n */\nexport function vdbEmissionProbeWgsl(): string {\n return `${VDB_EMISSION_GRID.wgsl}${RECEIVER}`;\n}\n\n/** The `?probe=emission` receiver kernel (harness): rows of (world, 0), (normal, 0) → (E rgb, 0). */\nexport function vdbEmissionIrradianceProbeWgsl(): string {\n return `${vdbEmissionProbeWgsl()}\n@group(0) @binding(0) var<uniform> vdbProbeGrid: VdbEmissionGrid;\n@group(0) @binding(1) var vdbProbeStack: texture_3d<f32>;\n@group(0) @binding(2) var vdbProbeSampler: sampler;\n@group(0) @binding(3) var<storage, read_write> vdbProbeRows: array<vec4f>;\n\n@compute @workgroup_size(64, 1, 1)\nfn vdbEmissionIrradianceProbeCs(@builtin(global_invocation_id) gid: vec3u) {\n let rows = arrayLength(&vdbProbeRows) / 2u;\n if (gid.x >= rows) {\n return;\n }\n let world = vdbProbeRows[gid.x * 2u].xyz;\n let normal = vdbProbeRows[gid.x * 2u + 1u].xyz;\n vdbProbeRows[gid.x * 2u] = vec4f(vdbEmissionIrradiance(vdbProbeStack, vdbProbeSampler, vdbProbeGrid, world, normal), 0.0);\n}\n`;\n}\n\n/** Whether `channels` emit (the emission kernels and the LUT binding exist only then). */\nexport const vdbFrameEmits = (channels: VDBVolumeChannels): boolean => !!channels.emission;\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Group-1 bindings of the prefilter kernels (area / cube). */
|
|
2
|
+
export declare const ENV_PREFILTER_BINDINGS: {
|
|
3
|
+
readonly source: 0;
|
|
4
|
+
readonly work: 1;
|
|
5
|
+
};
|
|
6
|
+
/** Group-1 bindings of the blur kernel. */
|
|
7
|
+
export declare const ENV_BLUR_BINDINGS: {
|
|
8
|
+
readonly work: 0;
|
|
9
|
+
readonly map: 1;
|
|
10
|
+
};
|
|
11
|
+
/** Group-1 bindings of the reduce kernel. */
|
|
12
|
+
export declare const ENV_REDUCE_BINDINGS: {
|
|
13
|
+
readonly work: 0;
|
|
14
|
+
readonly map: 1;
|
|
15
|
+
readonly environment: 2;
|
|
16
|
+
};
|
|
17
|
+
/** Group-1 bindings of the environment grid kernel (K6.4 spectral: the absorption stack). */
|
|
18
|
+
export declare const ENV_GRID_BINDINGS: {
|
|
19
|
+
readonly grid: 0;
|
|
20
|
+
readonly out: 1;
|
|
21
|
+
readonly absorption: 2;
|
|
22
|
+
};
|
|
23
|
+
/** `envPrefilter` for an equirect source: the exact-area solid-angle mean of the source over each work texel. */
|
|
24
|
+
export declare function vdbFrameEnvAreaWgsl(): string;
|
|
25
|
+
/** `envPrefilter` for a cube source (a 6-layer 2D array view, WebGPU's faces): k × k nearest sub-samples per texel. */
|
|
26
|
+
export declare function vdbFrameEnvCubeWgsl(): string;
|
|
27
|
+
/** The GGX roughness-0.4 convolution of the work map into his 64 × 32 map (world space). */
|
|
28
|
+
export declare function vdbFrameEnvBlurWgsl(): string;
|
|
29
|
+
/**
|
|
30
|
+
* `envReduce`: one workgroup of 64 threads (compatibility devices allow 128). His setTexels (clamped radiance, midpoint solid angles, finite and
|
|
31
|
+
* positive energy), 'directional' (brightest texel, fixed sky seeds, nearest seed, energy centroids, sorted by
|
|
32
|
+
* power) or 'spherical-harmonics' lights (SH L1 / L2 at octahedron / icosahedron directions) from the 64 × 32 map;
|
|
33
|
+
* SH9 of the work map in world space; colours and SH × intensity. Every reduction runs in uniform control flow.
|
|
34
|
+
*/
|
|
35
|
+
export declare function vdbFrameEnvReduceWgsl(): string;
|
|
36
|
+
/**
|
|
37
|
+
* The environment grid kernel (after `vdbFrameUniformsWgsl(…, { environment: true })`; source-free): his grey
|
|
38
|
+
* environment grid pass at each voxel of the last cascade, from the environment lights without a shadow slot.
|
|
39
|
+
*/
|
|
40
|
+
export declare function vdbFrameEnvironmentGridWgsl(o?: {
|
|
41
|
+
spectral?: boolean;
|
|
42
|
+
}): string;
|