@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,803 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* K6.R: the reference renderer's compute kernel (`vdbRefTraceCs`) and its uniform layout. The algorithm, the random
|
|
3
|
+
* stream and the draw order are those of the CPU twin (`tools/reference/trace.ts`), which documents them; this file
|
|
4
|
+
* is that code in WGSL. One VDB source at group 2 (`vdbSrc*`, the K6 group-2 contract), so the kernel binds at most
|
|
5
|
+
* the pool's one storage buffer (D10); the accumulation lives in rgba32float textures (group 1).
|
|
6
|
+
*
|
|
7
|
+
* Compile-time care (the K3.7 trap: inlined sample sites cost SwiftShader minutes): the path is a state machine whose
|
|
8
|
+
* every ray query (primary transmittance, path segment, light visibility) goes through ONE call of `vdbRefTrack`, and
|
|
9
|
+
* the source is read at one call site per channel.
|
|
10
|
+
*
|
|
11
|
+
* Group 0: `vdbRefU` (VdbRefUniforms), `vdbRefBatch` (dynamic offset, 256 B stride). Group 1: accumulation in
|
|
12
|
+
* (sum, sum of squares; sampled, unfilterable), out (storage, write), the equirect environment map, and (K6.R1) the
|
|
13
|
+
* table texture (one row per phase table: RGB + CDF; per emission colour table: RGB) and the majorant atlas (r32float
|
|
14
|
+
* 3D: each volume's grid stacked along z). K6.R2: binding 7, the equirect map's sampling table (r32float; layout in
|
|
15
|
+
* `tools/reference/environment.ts`), read when `flags` has `VDB_REF_FLAG_ENV_MIS`.
|
|
16
|
+
*/
|
|
17
|
+
/** Uniform layout (bytes) of `VdbRefUniforms`; the packer is `core/reference/renderer.ts` `vdbReferencePackUniforms`. */
|
|
18
|
+
export const VDB_REF_UNIFORM_OFFSETS = Object.freeze({
|
|
19
|
+
cameraToWorld: 0,
|
|
20
|
+
projectionInverse: 64,
|
|
21
|
+
size: 128,
|
|
22
|
+
seed: 136,
|
|
23
|
+
spp: 140,
|
|
24
|
+
maxBounces: 144,
|
|
25
|
+
rrStart: 148,
|
|
26
|
+
volumeCount: 152,
|
|
27
|
+
lightCount: 156,
|
|
28
|
+
hemiCount: 160,
|
|
29
|
+
flags: 164,
|
|
30
|
+
envSize: 168,
|
|
31
|
+
uniformEnv: 176,
|
|
32
|
+
envRotation: 192,
|
|
33
|
+
sh: 240,
|
|
34
|
+
hemis: 384,
|
|
35
|
+
volumes: 576,
|
|
36
|
+
lights: 2112,
|
|
37
|
+
size_: 3136,
|
|
38
|
+
});
|
|
39
|
+
export const VDB_REF_HEMI_BYTES = 48;
|
|
40
|
+
export const VDB_REF_VOLUME_BYTES = 192;
|
|
41
|
+
export const VDB_REF_LIGHT_BYTES = 64;
|
|
42
|
+
/** `flags` bits. */
|
|
43
|
+
export const VDB_REF_FLAG_BOX_FILTER = 1;
|
|
44
|
+
export const VDB_REF_FLAG_ORTHOGRAPHIC = 2;
|
|
45
|
+
export const VDB_REF_FLAG_EQUIRECT = 4;
|
|
46
|
+
/** K6.R1: the environment has a light probe (`sh`). */
|
|
47
|
+
export const VDB_REF_FLAG_SH = 8;
|
|
48
|
+
/** K6.R2: next-event estimation of the equirect map with MIS (`environmentSampling: 'mis'` and a map with light). */
|
|
49
|
+
export const VDB_REF_FLAG_ENV_MIS = 16;
|
|
50
|
+
/** Stride of the per-dispatch batch records (dynamic uniform offsets: 256-byte aligned). */
|
|
51
|
+
export const VDB_REF_BATCH_STRIDE = 256;
|
|
52
|
+
/**
|
|
53
|
+
* The fail-before mutations (`?mutate=`): WGSL text patches, one per name, matching the CPU twin's
|
|
54
|
+
* `VDBReferenceMutation`s. Each must make an analytic check fail.
|
|
55
|
+
*/
|
|
56
|
+
export const VDB_REFERENCE_MUTATIONS = Object.freeze({
|
|
57
|
+
"ratio-weight": ["trans = trans * (1.0 - sum / sbar);", "trans = trans * (1.0 - 0.9 * sum / sbar);"],
|
|
58
|
+
"delta-accept": ["let u = vdbRefRand() * sbar;", "let u = -1.0;"],
|
|
59
|
+
"phase-norm": ["return (1.0 - g * g) / (4.0 * VDB_REF_PI * d * sqrt(d));", "return (1.0 - g * g) / (d * sqrt(d));"],
|
|
60
|
+
"nee-transmittance": ["rad = rad + beta * neeLi * hit.trans;", "rad = rad + beta * neeLi;"],
|
|
61
|
+
"emission-albedo": ["rad = rad + beta * le;", "rad = rad + beta * le * albedo;"],
|
|
62
|
+
"escape-depth": ["if (depth > 0u) {", "if (depth == 1u) {"],
|
|
63
|
+
// K6.R1
|
|
64
|
+
"majorant-cell": ["let cellIndex = cell;", "let cellIndex = vec3u(cell.x, cell.y, 0u);"],
|
|
65
|
+
"phase-table-weight": ["return VdbRefPhaseSample(cos(theta), vdbRefTableAt(row, size, u).xyz * s, pdf);", "return VdbRefPhaseSample(cos(theta), vdbRefTableAt(row, size, u).yyy * s, pdf);"],
|
|
66
|
+
falloff: ["let mode = u32(l.extra.x + 0.5);", "let mode = select(u32(l.extra.x + 0.5), 0u, l.extra.x > 1.5);"],
|
|
67
|
+
// K6.R2: the map's density without each texel's own solid angle; the escape gathering the map with weight 1
|
|
68
|
+
"env-pdf": ["let omega = vdbRefEnvTable(y, h + 4u);", "let omega = 4.0 * VDB_REF_PI / f32(w * h);"],
|
|
69
|
+
"mis-weight": ["w = vdbRefMisWeight(phasePdf, vdbRefEnvPdf(d));", "w = 1.0;"],
|
|
70
|
+
// Issue #2 (stochastic kernel on a sparse source): the upper voxel with probability 1 - frac, not frac.
|
|
71
|
+
"stochastic-pick": ["select(vec3i(0), vec3i(1), xi < p - b);", "select(vec3i(0), vec3i(1), xi >= p - b);"],
|
|
72
|
+
});
|
|
73
|
+
/** The kernel's WGSL after the source's (`vdbSrc*`) and module text. */
|
|
74
|
+
export function vdbReferenceKernelWgsl(o) {
|
|
75
|
+
// Issue #2: the stochastic density draws xi (x, y, z, in that order) from the shared stream before the read.
|
|
76
|
+
const density = o.stochastic
|
|
77
|
+
? `let xi0 = vdbRefRand();
|
|
78
|
+
let xi1 = vdbRefRand();
|
|
79
|
+
let xi2 = vdbRefRand();
|
|
80
|
+
let value = vdbSrcDensityStochastic(v, uvw, 0.0, vec3f(xi0, xi1, xi2)) * vdbSrcMask(v, uvw, 0.0);`
|
|
81
|
+
: "let value = vdbSrcDensity(v, uvw, 0.0) * vdbSrcMask(v, uvw, 0.0);";
|
|
82
|
+
return /* wgsl */ `
|
|
83
|
+
// ---- K6.R reference renderer (core/reference/wgsl.ts): brute-force volumetric path tracing -------------------
|
|
84
|
+
const VDB_REF_PI: f32 = 3.14159265358979;
|
|
85
|
+
const VDB_REF_MAX_STEPS: u32 = ${o.maxSteps}u;
|
|
86
|
+
const VDB_REF_RATIO_RR: f32 = ${o.ratioRr.toFixed(6)};
|
|
87
|
+
const VDB_REF_FAR: f32 = 1e30;
|
|
88
|
+
|
|
89
|
+
struct VdbRefHemi {
|
|
90
|
+
sky: vec4f,
|
|
91
|
+
ground: vec4f,
|
|
92
|
+
up: vec4f,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
struct VdbRefVolume {
|
|
96
|
+
worldToLocal: mat4x4f,
|
|
97
|
+
params: vec4f,
|
|
98
|
+
albedo: vec4f,
|
|
99
|
+
phase: vec4f,
|
|
100
|
+
emission: vec4f,
|
|
101
|
+
temperature: vec4f,
|
|
102
|
+
ids: vec4u,
|
|
103
|
+
grid: vec4u,
|
|
104
|
+
tables: vec4u,
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
struct VdbRefLight {
|
|
108
|
+
position: vec4f,
|
|
109
|
+
direction: vec4f,
|
|
110
|
+
color: vec4f,
|
|
111
|
+
extra: vec4f,
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
struct VdbRefUniforms {
|
|
115
|
+
cameraToWorld: mat4x4f,
|
|
116
|
+
projectionInverse: mat4x4f,
|
|
117
|
+
size: vec2u,
|
|
118
|
+
seed: u32,
|
|
119
|
+
spp: u32,
|
|
120
|
+
maxBounces: u32,
|
|
121
|
+
rrStart: u32,
|
|
122
|
+
volumeCount: u32,
|
|
123
|
+
lightCount: u32,
|
|
124
|
+
hemiCount: u32,
|
|
125
|
+
flags: u32,
|
|
126
|
+
envSize: vec2u,
|
|
127
|
+
uniformEnv: vec4f,
|
|
128
|
+
envRotation0: vec4f,
|
|
129
|
+
envRotation1: vec4f,
|
|
130
|
+
envRotation2: vec4f,
|
|
131
|
+
sh: array<vec4f, 9>,
|
|
132
|
+
hemis: array<VdbRefHemi, ${o.maxHemispheres}>,
|
|
133
|
+
volumes: array<VdbRefVolume, ${o.maxVolumes}>,
|
|
134
|
+
lights: array<VdbRefLight, ${o.maxLights}>,
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
struct VdbRefBatch {
|
|
138
|
+
batch: u32,
|
|
139
|
+
accumulate: u32,
|
|
140
|
+
pad0: u32,
|
|
141
|
+
pad1: u32,
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
@group(0) @binding(0) var<uniform> vdbRefU: VdbRefUniforms;
|
|
145
|
+
@group(0) @binding(1) var<uniform> vdbRefBatch: VdbRefBatch;
|
|
146
|
+
@group(1) @binding(0) var vdbRefAccumIn0: texture_2d<f32>;
|
|
147
|
+
@group(1) @binding(1) var vdbRefAccumIn1: texture_2d<f32>;
|
|
148
|
+
@group(1) @binding(2) var vdbRefAccumOut0: texture_storage_2d<rgba32float, write>;
|
|
149
|
+
@group(1) @binding(3) var vdbRefAccumOut1: texture_storage_2d<rgba32float, write>;
|
|
150
|
+
@group(1) @binding(4) var vdbRefEnvMap: texture_2d<f32>;
|
|
151
|
+
@group(1) @binding(5) var vdbRefTables: texture_2d<f32>;
|
|
152
|
+
@group(1) @binding(6) var vdbRefMajorants: texture_3d<f32>;
|
|
153
|
+
@group(1) @binding(7) var vdbRefEnvCdf: texture_2d<f32>;
|
|
154
|
+
|
|
155
|
+
// ---- random stream (tools/reference/rng.ts) ----
|
|
156
|
+
var<private> vdbRefState: u32;
|
|
157
|
+
|
|
158
|
+
fn vdbRefPcg(v: u32) -> u32 {
|
|
159
|
+
let s = v * 747796405u + 2891336453u;
|
|
160
|
+
let w = ((s >> ((s >> 28u) + 4u)) ^ s) * 277803737u;
|
|
161
|
+
return (w >> 22u) ^ w;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
fn vdbRefSeed(seed: u32, sampleIndex: u32, pixel: u32) {
|
|
165
|
+
vdbRefState = vdbRefPcg(pixel + vdbRefPcg(seed ^ vdbRefPcg(sampleIndex)));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
fn vdbRefRand() -> f32 {
|
|
169
|
+
vdbRefState = vdbRefState * 747796405u + 2891336453u;
|
|
170
|
+
let s = vdbRefState;
|
|
171
|
+
let w = ((s >> ((s >> 28u) + 4u)) ^ s) * 277803737u;
|
|
172
|
+
return f32(((w >> 22u) ^ w) >> 8u) * 5.9604644775390625e-8;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ---- phase (tools/reference/trace.ts vdbRefHenyeyGreenstein, vdbRefPhase, vdbRefSampleHgCos) ----
|
|
176
|
+
fn vdbRefHg(c: f32, g: f32) -> f32 {
|
|
177
|
+
let d = 1.0 + g * g - 2.0 * g * c;
|
|
178
|
+
return (1.0 - g * g) / (4.0 * VDB_REF_PI * d * sqrt(d));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ---- tables (tools/reference/tables.ts): row r, linear blend at texel u·(size − 1) ----
|
|
182
|
+
fn vdbRefTableAt(row: u32, size: u32, u: f32) -> vec4f {
|
|
183
|
+
let texel = clamp(u, 0.0, 1.0) * f32(size - 1u);
|
|
184
|
+
let i = min(u32(texel), size - 2u);
|
|
185
|
+
let f = texel - f32(i);
|
|
186
|
+
let a = textureLoad(vdbRefTables, vec2u(i, row), 0);
|
|
187
|
+
let b = textureLoad(vdbRefTables, vec2u(i + 1u, row), 0);
|
|
188
|
+
return a + (b - a) * f;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// The phase per steradian per channel: HG / dual-lobe, or the volume's table (vdbRefPhaseTableEval).
|
|
192
|
+
fn vdbRefPhaseEval(c: f32, i: u32) -> vec3f {
|
|
193
|
+
let rec = vdbRefU.volumes[i];
|
|
194
|
+
if (rec.tables.x > 0u) {
|
|
195
|
+
let u = sqrt(acos(clamp(c, -1.0, 1.0)) / VDB_REF_PI);
|
|
196
|
+
return vdbRefTableAt(rec.tables.x - 1u, rec.tables.y, u).xyz / (4.0 * VDB_REF_PI);
|
|
197
|
+
}
|
|
198
|
+
let ph = rec.phase;
|
|
199
|
+
let a = vdbRefHg(c, ph.x);
|
|
200
|
+
if (ph.z > 0.0) {
|
|
201
|
+
return vec3f(a + (vdbRefHg(c, ph.y) - a) * ph.z);
|
|
202
|
+
}
|
|
203
|
+
return vec3f(a);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Inverse-CDF sample of a phase table (vdbRefPhaseTableSample): cos theta, the per-channel weight and (K6.R2) the
|
|
207
|
+
// density per steradian.
|
|
208
|
+
struct VdbRefPhaseSample {
|
|
209
|
+
cosTheta: f32,
|
|
210
|
+
weight: vec3f,
|
|
211
|
+
pdf: f32,
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
fn vdbRefPhaseTableSample(row: u32, size: u32, xi: f32) -> VdbRefPhaseSample {
|
|
215
|
+
var lo = 0u;
|
|
216
|
+
var hi = size - 1u;
|
|
217
|
+
loop {
|
|
218
|
+
if (hi - lo <= 1u) {
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
let mid = (lo + hi) >> 1u;
|
|
222
|
+
if (textureLoad(vdbRefTables, vec2u(mid, row), 0).w <= xi) {
|
|
223
|
+
lo = mid;
|
|
224
|
+
} else {
|
|
225
|
+
hi = mid;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
let c0 = textureLoad(vdbRefTables, vec2u(lo, row), 0).w;
|
|
229
|
+
let c1 = textureLoad(vdbRefTables, vec2u(lo + 1u, row), 0).w;
|
|
230
|
+
let f = (xi - c0) / (c1 - c0);
|
|
231
|
+
let u = (f32(lo) + f) / f32(size - 1u);
|
|
232
|
+
let pdfU = (c1 - c0) * f32(size - 1u);
|
|
233
|
+
let theta = VDB_REF_PI * u * u;
|
|
234
|
+
let sinTheta = sin(theta);
|
|
235
|
+
let s = VDB_REF_PI * u * sinTheta / pdfU;
|
|
236
|
+
let pdf = pdfU / max(4.0 * VDB_REF_PI * VDB_REF_PI * u * sinTheta, 1e-30);
|
|
237
|
+
return VdbRefPhaseSample(cos(theta), vdbRefTableAt(row, size, u).xyz * s, pdf);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// K6.R2: the density per steradian of the phase sampling at cos theta (vdbRefPhaseTablePdf; HG / dual-lobe: the phase)
|
|
241
|
+
fn vdbRefPhasePdf(c: f32, i: u32) -> f32 {
|
|
242
|
+
let rec = vdbRefU.volumes[i];
|
|
243
|
+
if (rec.tables.x > 0u) {
|
|
244
|
+
let row = rec.tables.x - 1u;
|
|
245
|
+
let size = rec.tables.y;
|
|
246
|
+
let cc = clamp(c, -1.0, 1.0);
|
|
247
|
+
let u = sqrt(acos(cc) / VDB_REF_PI);
|
|
248
|
+
let j = min(u32(u * f32(size - 1u)), size - 2u);
|
|
249
|
+
let pdfU = (textureLoad(vdbRefTables, vec2u(j + 1u, row), 0).w - textureLoad(vdbRefTables, vec2u(j, row), 0).w) * f32(size - 1u);
|
|
250
|
+
return pdfU / max(4.0 * VDB_REF_PI * VDB_REF_PI * u * sqrt(max(0.0, 1.0 - cc * cc)), 1e-30);
|
|
251
|
+
}
|
|
252
|
+
return vdbRefPhaseEval(c, i).x;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// K6.R2: the power heuristic (beta 2) weight of density p against q, as a ratio of at most 1e15 (no f32 overflow)
|
|
256
|
+
fn vdbRefMisWeight(p: f32, q: f32) -> f32 {
|
|
257
|
+
let r = q / max(max(p, q * 1e-15), 1e-30);
|
|
258
|
+
return 1.0 / (1.0 + r * r);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
fn vdbRefSampleHgCos(g: f32, u: f32) -> f32 {
|
|
262
|
+
if (abs(g) < 1e-3) {
|
|
263
|
+
return 1.0 - 2.0 * u;
|
|
264
|
+
}
|
|
265
|
+
let s = (1.0 - g * g) / (1.0 - g + 2.0 * g * u);
|
|
266
|
+
return clamp((1.0 + g * g - s * s) / (2.0 * g), -1.0, 1.0);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
fn vdbRefDirectionAround(n: vec3f, cosTheta: f32, u: f32) -> vec3f {
|
|
270
|
+
let sgn = select(-1.0, 1.0, n.z >= 0.0);
|
|
271
|
+
let a = -1.0 / (sgn + n.z);
|
|
272
|
+
let b = n.x * n.y * a;
|
|
273
|
+
let b1 = vec3f(1.0 + sgn * n.x * n.x * a, sgn * b, -sgn * n.x);
|
|
274
|
+
let b2 = vec3f(b, sgn + n.y * n.y * a, -n.y);
|
|
275
|
+
let sinTheta = sqrt(max(0.0, 1.0 - cosTheta * cosTheta));
|
|
276
|
+
let phi = 2.0 * VDB_REF_PI * u;
|
|
277
|
+
return cos(phi) * sinTheta * b1 + sin(phi) * sinTheta * b2 + cosTheta * n;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
fn vdbRefSmoothstep(e0: f32, e1: f32, x: f32) -> f32 {
|
|
281
|
+
if (!(e1 > e0)) {
|
|
282
|
+
return select(0.0, 1.0, x >= e0);
|
|
283
|
+
}
|
|
284
|
+
let t = clamp((x - e0) / (e1 - e0), 0.0, 1.0);
|
|
285
|
+
return t * t * (3.0 - 2.0 * t);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
fn vdbRefMax3(v: vec3f) -> f32 {
|
|
289
|
+
return max(v.x, max(v.y, v.z));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// ---- geometry (vdbRefVolumeInterval, vdbRefCameraRay) ----
|
|
293
|
+
fn vdbRefInterval(i: u32, o: vec3f, d: vec3f, tMax: f32) -> vec2f {
|
|
294
|
+
let m = vdbRefU.volumes[i].worldToLocal;
|
|
295
|
+
let lo = (m * vec4f(o, 1.0)).xyz;
|
|
296
|
+
let ld = (m * vec4f(d, 0.0)).xyz;
|
|
297
|
+
var t0 = -VDB_REF_FAR;
|
|
298
|
+
var t1 = VDB_REF_FAR;
|
|
299
|
+
if (vdbRefU.volumes[i].params.w > 0.5) {
|
|
300
|
+
let a = dot(ld, ld);
|
|
301
|
+
let b = dot(lo, ld);
|
|
302
|
+
let c = dot(lo, lo) - 0.25;
|
|
303
|
+
let disc = b * b - a * c;
|
|
304
|
+
if (disc <= 0.0 || a <= 0.0) {
|
|
305
|
+
return vec2f(1.0, 0.0);
|
|
306
|
+
}
|
|
307
|
+
let q = sqrt(disc);
|
|
308
|
+
t0 = (-b - q) / a;
|
|
309
|
+
t1 = (-b + q) / a;
|
|
310
|
+
} else {
|
|
311
|
+
for (var k = 0u; k < 3u; k = k + 1u) {
|
|
312
|
+
if (abs(ld[k]) < 1e-12) {
|
|
313
|
+
if (abs(lo[k]) > 0.5) {
|
|
314
|
+
return vec2f(1.0, 0.0);
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
let ta = (-0.5 - lo[k]) / ld[k];
|
|
318
|
+
let tb = (0.5 - lo[k]) / ld[k];
|
|
319
|
+
t0 = max(t0, min(ta, tb));
|
|
320
|
+
t1 = min(t1, max(ta, tb));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
t0 = max(t0, 0.0);
|
|
325
|
+
t1 = min(t1, tMax);
|
|
326
|
+
if (t0 < t1) {
|
|
327
|
+
return vec2f(t0, t1);
|
|
328
|
+
}
|
|
329
|
+
return vec2f(1.0, 0.0);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
fn vdbRefUnproject(ndc: vec3f) -> vec3f {
|
|
333
|
+
let p = vdbRefU.projectionInverse * vec4f(ndc, 1.0);
|
|
334
|
+
return p.xyz / p.w;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// ---- the medium (the renderer's sampleExtinction / sampleAlbedo / sampleEmission at level 0) ----
|
|
338
|
+
fn vdbRefUvw(i: u32, x: vec3f) -> vec3f {
|
|
339
|
+
return (vdbRefU.volumes[i].worldToLocal * vec4f(x, 1.0)).xyz + vec3f(0.5);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
fn vdbRefSigma(i: u32, x: vec3f) -> f32 {
|
|
343
|
+
let uvw = vdbRefUvw(i, x);
|
|
344
|
+
let v = vdbRefU.volumes[i].ids.x;
|
|
345
|
+
${density}
|
|
346
|
+
let p = vdbRefU.volumes[i].params;
|
|
347
|
+
return select(0.0, value, value > p.z) * p.x;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// ---- majorant grids (vdbRefMajorantCell): the cell at t of the ray lo + t*ld (unit box), its majorant and exit ----
|
|
351
|
+
fn vdbRefMajorantAt(i: u32, lo: vec3f, ld: vec3f, t: f32, t1: f32) -> vec2f {
|
|
352
|
+
let rec = vdbRefU.volumes[i];
|
|
353
|
+
let dims = rec.ids.yzw;
|
|
354
|
+
if (dims.x == 0u) {
|
|
355
|
+
return vec2f(rec.params.y, t1);
|
|
356
|
+
}
|
|
357
|
+
let n = vec3f(dims);
|
|
358
|
+
let q = (lo + ld * t + vec3f(0.5)) * n;
|
|
359
|
+
let nudge = select(select(vec3f(0.0), vec3f(-1e-4), ld < vec3f(0.0)), vec3f(1e-4), ld > vec3f(0.0));
|
|
360
|
+
let cell = vec3u(clamp(floor(q + nudge), vec3f(0.0), n - vec3f(1.0)));
|
|
361
|
+
var exit = VDB_REF_FAR;
|
|
362
|
+
for (var k = 0u; k < 3u; k = k + 1u) {
|
|
363
|
+
if (abs(ld[k]) > 1e-12) {
|
|
364
|
+
let face = (f32(cell[k]) + select(0.0, 1.0, ld[k] > 0.0)) / n[k] - 0.5;
|
|
365
|
+
exit = min(exit, (face - lo[k]) / ld[k]);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (!(exit > t)) {
|
|
369
|
+
exit = t + 1e-6 * max(1.0, abs(t));
|
|
370
|
+
}
|
|
371
|
+
let cellIndex = cell;
|
|
372
|
+
let bound = textureLoad(vdbRefMajorants, vec3u(cellIndex.x, cellIndex.y, cellIndex.z + rec.grid.x), 0).x;
|
|
373
|
+
return vec2f(rec.params.x * bound, min(t1, exit));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// ---- tracking: delta (ratio false: the collision) or ratio (ratio true: T), piecewise majorants ----
|
|
377
|
+
struct VdbRefHit {
|
|
378
|
+
escaped: bool,
|
|
379
|
+
t: f32,
|
|
380
|
+
vol: u32,
|
|
381
|
+
trans: f32,
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
fn vdbRefTrack(o: vec3f, d: vec3f, tMax: f32, ratio: bool) -> VdbRefHit {
|
|
385
|
+
var iv: array<vec2f, ${o.maxVolumes}>;
|
|
386
|
+
var lo: array<vec3f, ${o.maxVolumes}>;
|
|
387
|
+
var ld: array<vec3f, ${o.maxVolumes}>;
|
|
388
|
+
let n = vdbRefU.volumeCount;
|
|
389
|
+
for (var i = 0u; i < n; i = i + 1u) {
|
|
390
|
+
iv[i] = vdbRefInterval(i, o, d, tMax);
|
|
391
|
+
let m = vdbRefU.volumes[i].worldToLocal;
|
|
392
|
+
lo[i] = (m * vec4f(o, 1.0)).xyz;
|
|
393
|
+
ld[i] = (m * vec4f(d, 0.0)).xyz;
|
|
394
|
+
}
|
|
395
|
+
var t = 0.0;
|
|
396
|
+
var trans = 1.0;
|
|
397
|
+
for (var step = 0u; step < VDB_REF_MAX_STEPS; step = step + 1u) {
|
|
398
|
+
var sbar = 0.0;
|
|
399
|
+
var tb = tMax;
|
|
400
|
+
for (var i = 0u; i < n; i = i + 1u) {
|
|
401
|
+
let w = iv[i];
|
|
402
|
+
if (w.x <= t && t < w.y) {
|
|
403
|
+
let piece = vdbRefMajorantAt(i, lo[i], ld[i], t, w.y);
|
|
404
|
+
sbar = sbar + piece.x;
|
|
405
|
+
tb = min(tb, piece.y);
|
|
406
|
+
} else if (w.x > t && w.x <= w.y) {
|
|
407
|
+
tb = min(tb, w.x);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (!(sbar > 0.0)) {
|
|
411
|
+
if (tb >= tMax) {
|
|
412
|
+
return VdbRefHit(true, tMax, 0u, trans);
|
|
413
|
+
}
|
|
414
|
+
t = tb;
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
let dt = -log(1.0 - vdbRefRand()) / sbar;
|
|
418
|
+
if (t + dt >= tb) {
|
|
419
|
+
t = tb;
|
|
420
|
+
if (t >= tMax) {
|
|
421
|
+
return VdbRefHit(true, tMax, 0u, trans);
|
|
422
|
+
}
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
t = t + dt;
|
|
426
|
+
let x = o + t * d;
|
|
427
|
+
var sig: array<f32, ${o.maxVolumes}>;
|
|
428
|
+
var sum = 0.0;
|
|
429
|
+
for (var i = 0u; i < n; i = i + 1u) {
|
|
430
|
+
let w = iv[i];
|
|
431
|
+
var s = 0.0;
|
|
432
|
+
if (w.x <= t && t < w.y) {
|
|
433
|
+
s = vdbRefSigma(i, x);
|
|
434
|
+
}
|
|
435
|
+
sig[i] = s;
|
|
436
|
+
sum = sum + s;
|
|
437
|
+
}
|
|
438
|
+
if (!ratio) {
|
|
439
|
+
let u = vdbRefRand() * sbar;
|
|
440
|
+
var acc = 0.0;
|
|
441
|
+
for (var i = 0u; i < n; i = i + 1u) {
|
|
442
|
+
let w = iv[i];
|
|
443
|
+
if (!(w.x <= t && t < w.y)) {
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
acc = acc + sig[i];
|
|
447
|
+
if (u < acc) {
|
|
448
|
+
return VdbRefHit(false, t, i, trans);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
} else {
|
|
452
|
+
trans = trans * (1.0 - sum / sbar);
|
|
453
|
+
if (trans < VDB_REF_RATIO_RR) {
|
|
454
|
+
if (vdbRefRand() >= 0.5) {
|
|
455
|
+
return VdbRefHit(false, t, 0u, 0.0);
|
|
456
|
+
}
|
|
457
|
+
trans = trans * 2.0;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return VdbRefHit(true, t, 0u, select(0.0, trans, ratio));
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// ---- lights and environment (vdbRefLightAt, vdbRefEnvironmentRadiance) ----
|
|
465
|
+
struct VdbRefNee {
|
|
466
|
+
ok: bool,
|
|
467
|
+
dir: vec3f,
|
|
468
|
+
dist: f32,
|
|
469
|
+
li: vec3f,
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
fn vdbRefLightAt(k: u32, x: vec3f) -> VdbRefNee {
|
|
473
|
+
let l = vdbRefU.lights[k];
|
|
474
|
+
let kind = u32(l.position.w + 0.5);
|
|
475
|
+
if (kind == 0u) {
|
|
476
|
+
return VdbRefNee(vdbRefMax3(l.color.xyz) > 0.0, l.direction.xyz, VDB_REF_FAR, l.color.xyz);
|
|
477
|
+
}
|
|
478
|
+
let to = l.position.xyz - x;
|
|
479
|
+
let dist = length(to);
|
|
480
|
+
if (!(dist > 0.0)) {
|
|
481
|
+
return VdbRefNee(false, vec3f(0.0, 1.0, 0.0), 0.0, vec3f(0.0));
|
|
482
|
+
}
|
|
483
|
+
let dir = to / dist;
|
|
484
|
+
// falloff (extra): mode 0 none ('volume' lighting), 1 inverse square, 2 three's getDistanceAttenuation (cutoff, decay)
|
|
485
|
+
let mode = u32(l.extra.x + 0.5);
|
|
486
|
+
var s = 1.0;
|
|
487
|
+
if (mode == 1u) {
|
|
488
|
+
s = 1.0 / (dist * dist);
|
|
489
|
+
} else if (mode == 2u) {
|
|
490
|
+
s = 1.0 / max(pow(dist, l.extra.z), 0.01);
|
|
491
|
+
if (l.extra.y > 0.0) {
|
|
492
|
+
let w = clamp(1.0 - pow(dist / l.extra.y, 4.0), 0.0, 1.0);
|
|
493
|
+
s = s * w * w;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (kind == 2u) {
|
|
497
|
+
s = s * vdbRefSmoothstep(l.direction.w, l.color.w, -dot(dir, l.direction.xyz));
|
|
498
|
+
}
|
|
499
|
+
let li = l.color.xyz * s;
|
|
500
|
+
return VdbRefNee(s > 0.0 && vdbRefMax3(li) > 0.0, dir, dist, li);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// ---- K6.R2: the equirect map's texel lookup and importance sampling (tools/reference/environment.ts) ----
|
|
504
|
+
fn vdbRefEnvTexelOf(d: vec3f) -> vec2u {
|
|
505
|
+
let m = vec3f(dot(vdbRefU.envRotation0.xyz, d), dot(vdbRefU.envRotation1.xyz, d), dot(vdbRefU.envRotation2.xyz, d));
|
|
506
|
+
let u = atan2(m.z, m.x) / (2.0 * VDB_REF_PI) + 0.5;
|
|
507
|
+
let v = asin(clamp(m.y, -1.0, 1.0)) / VDB_REF_PI + 0.5;
|
|
508
|
+
let size = vec2i(vdbRefU.envSize);
|
|
509
|
+
let px = clamp(i32(floor(u * f32(size.x))), 0, size.x - 1);
|
|
510
|
+
let py = clamp(i32(floor((1.0 - v) * f32(size.y))), 0, size.y - 1);
|
|
511
|
+
return vec2u(u32(px), u32(py));
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
fn vdbRefEnvTable(x: u32, y: u32) -> f32 {
|
|
515
|
+
return textureLoad(vdbRefEnvCdf, vec2u(x, y), 0).x;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// the interval j with t[j] <= xi < t[j + 1] of table row 'row' (t[0 .. n])
|
|
519
|
+
fn vdbRefEnvSearch(row: u32, n: u32, xi: f32) -> u32 {
|
|
520
|
+
var lo = 0u;
|
|
521
|
+
var hi = n;
|
|
522
|
+
loop {
|
|
523
|
+
if (hi - lo <= 1u) {
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
let mid = (lo + hi) >> 1u;
|
|
527
|
+
if (vdbRefEnvTable(mid, row) <= xi) {
|
|
528
|
+
lo = mid;
|
|
529
|
+
} else {
|
|
530
|
+
hi = mid;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return lo;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// density per steradian of texel (x, y): P(y) P(x | y) / omega_y (vdbRefEnvTexelPdf)
|
|
537
|
+
fn vdbRefEnvTexelPdf(x: u32, y: u32) -> f32 {
|
|
538
|
+
let w = vdbRefU.envSize.x;
|
|
539
|
+
let h = vdbRefU.envSize.y;
|
|
540
|
+
let py = vdbRefEnvTable(y + 1u, h) - vdbRefEnvTable(y, h);
|
|
541
|
+
let px = vdbRefEnvTable(x + 1u, y) - vdbRefEnvTable(x, y);
|
|
542
|
+
let omega = vdbRefEnvTable(y, h + 4u);
|
|
543
|
+
return select(0.0, py * px / max(omega, 1e-30), omega > 0.0);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
fn vdbRefEnvPdf(d: vec3f) -> f32 {
|
|
547
|
+
let t = vdbRefEnvTexelOf(d);
|
|
548
|
+
return vdbRefEnvTexelPdf(t.x, t.y);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// sin and cos of |a| <= 2 pi to f32 precision (WGSL sin / cos are only good to 2^-11): Taylor at a / 8, three doublings
|
|
552
|
+
fn vdbRefSinCos(a: f32) -> vec2f {
|
|
553
|
+
let h = a * 0.125;
|
|
554
|
+
let h2 = h * h;
|
|
555
|
+
var s = h * (1.0 - h2 / 6.0 * (1.0 - h2 / 20.0 * (1.0 - h2 / 42.0 * (1.0 - h2 / 72.0))));
|
|
556
|
+
var c = 1.0 - h2 / 2.0 * (1.0 - h2 / 12.0 * (1.0 - h2 / 30.0 * (1.0 - h2 / 56.0 * (1.0 - h2 / 90.0))));
|
|
557
|
+
for (var k = 0u; k < 3u; k = k + 1u) {
|
|
558
|
+
let s2 = 2.0 * s * c;
|
|
559
|
+
c = c * c - s * s;
|
|
560
|
+
s = s2;
|
|
561
|
+
}
|
|
562
|
+
return vec2f(s, c);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
struct VdbRefEnvSample {
|
|
566
|
+
dir: vec3f,
|
|
567
|
+
radiance: vec3f,
|
|
568
|
+
pdf: f32,
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// a direction from the map (vdbRefEnvSample): row, column, azimuth and sin latitude in the texel; the SAMPLED texel's
|
|
572
|
+
// radiance and density
|
|
573
|
+
fn vdbRefEnvSample(xi: vec4f) -> VdbRefEnvSample {
|
|
574
|
+
let w = vdbRefU.envSize.x;
|
|
575
|
+
let h = vdbRefU.envSize.y;
|
|
576
|
+
let y = vdbRefEnvSearch(h, h, xi.x);
|
|
577
|
+
let x = vdbRefEnvSearch(y, w, xi.y);
|
|
578
|
+
let sc = vdbRefSinCos(2.0 * VDB_REF_PI / f32(w) * xi.z);
|
|
579
|
+
let c0 = vdbRefEnvTable(x, h + 1u);
|
|
580
|
+
let s0 = vdbRefEnvTable(x, h + 2u);
|
|
581
|
+
let cphi = c0 * sc.y - s0 * sc.x;
|
|
582
|
+
let sphi = s0 * sc.y + c0 * sc.x;
|
|
583
|
+
let top = vdbRefEnvTable(y, h + 3u);
|
|
584
|
+
let bottom = vdbRefEnvTable(y + 1u, h + 3u);
|
|
585
|
+
let my = bottom + (top - bottom) * xi.w;
|
|
586
|
+
let r = sqrt(max(0.0, 1.0 - my * my));
|
|
587
|
+
let m = vec3f(r * cphi, my, r * sphi);
|
|
588
|
+
// d = R^T m (the lookup applies m = R d)
|
|
589
|
+
let dir = normalize(m.x * vdbRefU.envRotation0.xyz + m.y * vdbRefU.envRotation1.xyz + m.z * vdbRefU.envRotation2.xyz);
|
|
590
|
+
let radiance = textureLoad(vdbRefEnvMap, vec2u(x, y), 0).xyz * vdbRefU.uniformEnv.w;
|
|
591
|
+
return VdbRefEnvSample(dir, radiance, vdbRefEnvTexelPdf(x, y));
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// K6.R2: the equirect map's part weighted by mapWeight (its MIS weight on an escape)
|
|
595
|
+
fn vdbRefEnvironment(d: vec3f, mapWeight: f32) -> vec3f {
|
|
596
|
+
var e = vdbRefU.uniformEnv.xyz;
|
|
597
|
+
if ((vdbRefU.flags & ${VDB_REF_FLAG_SH}u) != 0u) {
|
|
598
|
+
let sh = vdbRefU.sh;
|
|
599
|
+
e = e + sh[0].xyz * 0.282095 + sh[1].xyz * (0.488603 * d.y) + sh[2].xyz * (0.488603 * d.z) + sh[3].xyz * (0.488603 * d.x);
|
|
600
|
+
e = e + sh[4].xyz * (1.092548 * d.x * d.y) + sh[5].xyz * (1.092548 * d.y * d.z) + sh[6].xyz * (0.315392 * (3.0 * d.z * d.z - 1.0));
|
|
601
|
+
e = e + sh[7].xyz * (1.092548 * d.x * d.z) + sh[8].xyz * (0.546274 * (d.x * d.x - d.y * d.y));
|
|
602
|
+
}
|
|
603
|
+
for (var i = 0u; i < vdbRefU.hemiCount; i = i + 1u) {
|
|
604
|
+
let h = vdbRefU.hemis[i];
|
|
605
|
+
e = e + select(h.ground.xyz, h.sky.xyz, dot(d, h.up.xyz) >= 0.0);
|
|
606
|
+
}
|
|
607
|
+
if ((vdbRefU.flags & ${VDB_REF_FLAG_EQUIRECT}u) != 0u) {
|
|
608
|
+
let t = vdbRefEnvTexelOf(d);
|
|
609
|
+
e = e + textureLoad(vdbRefEnvMap, t, 0).xyz * (vdbRefU.uniformEnv.w * mapWeight);
|
|
610
|
+
}
|
|
611
|
+
return e;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// ---- one sample: the state machine (mode 0 primary T, 1 path segment, 2 light visibility) ----
|
|
615
|
+
fn vdbRefSample(pixel: vec2u, sampleIndex: u32) -> vec4f {
|
|
616
|
+
vdbRefSeed(vdbRefU.seed, sampleIndex, pixel.y * vdbRefU.size.x + pixel.x);
|
|
617
|
+
var j = vec2f(0.5, 0.5);
|
|
618
|
+
if ((vdbRefU.flags & ${VDB_REF_FLAG_BOX_FILTER}u) != 0u) {
|
|
619
|
+
j.x = vdbRefRand();
|
|
620
|
+
j.y = vdbRefRand();
|
|
621
|
+
}
|
|
622
|
+
let size = vec2f(vdbRefU.size);
|
|
623
|
+
let ndc = vec2f((f32(pixel.x) + j.x) / size.x * 2.0 - 1.0, (1.0 - (f32(pixel.y) + j.y) / size.y) * 2.0 - 1.0);
|
|
624
|
+
let pNear = vdbRefUnproject(vec3f(ndc, 0.0));
|
|
625
|
+
let pFar = vdbRefUnproject(vec3f(ndc, 1.0));
|
|
626
|
+
let dv = normalize(pFar - pNear);
|
|
627
|
+
var ov = vec3f(0.0);
|
|
628
|
+
if ((vdbRefU.flags & ${VDB_REF_FLAG_ORTHOGRAPHIC}u) != 0u) {
|
|
629
|
+
ov = vdbRefUnproject(vec3f(ndc, -1.0));
|
|
630
|
+
}
|
|
631
|
+
var o = (vdbRefU.cameraToWorld * vec4f(ov, 1.0)).xyz;
|
|
632
|
+
var d = normalize((vdbRefU.cameraToWorld * vec4f(dv, 0.0)).xyz);
|
|
633
|
+
|
|
634
|
+
var rad = vec3f(0.0);
|
|
635
|
+
var beta = vec3f(1.0);
|
|
636
|
+
var primaryT = 1.0;
|
|
637
|
+
var mode = 0u;
|
|
638
|
+
var depth = 0u;
|
|
639
|
+
var lightIndex = 0u;
|
|
640
|
+
var x = o;
|
|
641
|
+
var vol = 0u;
|
|
642
|
+
var neeDir = vec3f(0.0, 1.0, 0.0);
|
|
643
|
+
var neeDist = 0.0;
|
|
644
|
+
var neeLi = vec3f(0.0);
|
|
645
|
+
// K6.R2: the density of the phase sampling that gave d (the escape's MIS weight)
|
|
646
|
+
var phasePdf = 0.0;
|
|
647
|
+
loop {
|
|
648
|
+
var ro = o;
|
|
649
|
+
var rd = d;
|
|
650
|
+
var tMax = VDB_REF_FAR;
|
|
651
|
+
if (mode == 2u) {
|
|
652
|
+
ro = x;
|
|
653
|
+
rd = neeDir;
|
|
654
|
+
tMax = neeDist;
|
|
655
|
+
}
|
|
656
|
+
let hit = vdbRefTrack(ro, rd, tMax, mode != 1u);
|
|
657
|
+
if (mode == 0u) {
|
|
658
|
+
primaryT = hit.trans;
|
|
659
|
+
mode = 1u;
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
if (mode == 2u) {
|
|
663
|
+
rad = rad + beta * neeLi * hit.trans;
|
|
664
|
+
lightIndex = lightIndex + 1u;
|
|
665
|
+
} else {
|
|
666
|
+
if (hit.escaped) {
|
|
667
|
+
if (depth > 0u) {
|
|
668
|
+
var w = 1.0;
|
|
669
|
+
if ((vdbRefU.flags & ${VDB_REF_FLAG_ENV_MIS}u) != 0u) {
|
|
670
|
+
w = vdbRefMisWeight(phasePdf, vdbRefEnvPdf(d));
|
|
671
|
+
}
|
|
672
|
+
rad = rad + beta * vdbRefEnvironment(d, w);
|
|
673
|
+
}
|
|
674
|
+
break;
|
|
675
|
+
}
|
|
676
|
+
// a collision past the cap ends the path (the last bounce's escape still gathered the environment above)
|
|
677
|
+
if (depth >= vdbRefU.maxBounces) {
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
depth = depth + 1u;
|
|
681
|
+
vol = hit.vol;
|
|
682
|
+
x = o + hit.t * d;
|
|
683
|
+
let uvw = vdbRefUvw(vol, x);
|
|
684
|
+
let rec = vdbRefU.volumes[vol];
|
|
685
|
+
let v = rec.ids.x;
|
|
686
|
+
let albedo = rec.albedo.xyz * vdbSrcAlbedo(v, uvw, 0.0);
|
|
687
|
+
var le = vec3f(0.0);
|
|
688
|
+
if (rec.albedo.w > 0.5) {
|
|
689
|
+
let temperature = mix(rec.temperature.x, rec.temperature.y, vdbSrcEmission(v, uvw, 0.0));
|
|
690
|
+
if (temperature > 0.0) {
|
|
691
|
+
le = rec.emission.xyz * pow(temperature / max(rec.temperature.y, 1.0), 4.0);
|
|
692
|
+
if (rec.tables.z > 0u) {
|
|
693
|
+
// the blackbody colour table over log temperature (vdbRefColorTableAt): log range in temperature.zw
|
|
694
|
+
let lx = (log(max(temperature, 1e-3)) - rec.temperature.z) / (rec.temperature.w - rec.temperature.z);
|
|
695
|
+
le = le * vdbRefTableAt(rec.tables.z - 1u, rec.tables.w, lx).xyz;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
rad = rad + beta * le;
|
|
700
|
+
beta = beta * albedo;
|
|
701
|
+
if (!(vdbRefMax3(beta) > 0.0)) {
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
lightIndex = 0u;
|
|
705
|
+
}
|
|
706
|
+
// The next light that reaches x (dark ones draw nothing), then (K6.R2) the map's NEE once (lightIndex ==
|
|
707
|
+
// lightCount; its visibility pass moves lightIndex past it), else finish the collision.
|
|
708
|
+
var found = false;
|
|
709
|
+
loop {
|
|
710
|
+
if (lightIndex < vdbRefU.lightCount) {
|
|
711
|
+
let nee = vdbRefLightAt(lightIndex, x);
|
|
712
|
+
if (nee.ok) {
|
|
713
|
+
neeDir = nee.dir;
|
|
714
|
+
neeDist = nee.dist;
|
|
715
|
+
neeLi = nee.li * vdbRefPhaseEval(dot(d, nee.dir), vol);
|
|
716
|
+
found = true;
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
lightIndex = lightIndex + 1u;
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
if (lightIndex == vdbRefU.lightCount && (vdbRefU.flags & ${VDB_REF_FLAG_ENV_MIS}u) != 0u) {
|
|
723
|
+
let xi0 = vdbRefRand();
|
|
724
|
+
let xi1 = vdbRefRand();
|
|
725
|
+
let xi2 = vdbRefRand();
|
|
726
|
+
let xi3 = vdbRefRand();
|
|
727
|
+
let smp = vdbRefEnvSample(vec4f(xi0, xi1, xi2, xi3));
|
|
728
|
+
let c = dot(d, smp.dir);
|
|
729
|
+
var k = 0.0;
|
|
730
|
+
if (smp.pdf > 0.0) {
|
|
731
|
+
k = vdbRefMisWeight(smp.pdf, vdbRefPhasePdf(c, vol)) / smp.pdf;
|
|
732
|
+
}
|
|
733
|
+
let li = smp.radiance * vdbRefPhaseEval(c, vol) * k;
|
|
734
|
+
if (vdbRefMax3(li) > 0.0) {
|
|
735
|
+
neeDir = smp.dir;
|
|
736
|
+
neeDist = VDB_REF_FAR;
|
|
737
|
+
neeLi = li;
|
|
738
|
+
found = true;
|
|
739
|
+
break;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
lightIndex = vdbRefU.lightCount + 1u;
|
|
743
|
+
break;
|
|
744
|
+
}
|
|
745
|
+
if (found) {
|
|
746
|
+
mode = 2u;
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
if (depth >= vdbRefU.rrStart) {
|
|
750
|
+
let q = min(vdbRefMax3(beta), 1.0);
|
|
751
|
+
if (q < 1.0) {
|
|
752
|
+
if (vdbRefRand() >= q) {
|
|
753
|
+
break;
|
|
754
|
+
}
|
|
755
|
+
beta = beta / q;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
let rec = vdbRefU.volumes[vol];
|
|
759
|
+
let ph = rec.phase;
|
|
760
|
+
let lobe = vdbRefRand();
|
|
761
|
+
let u1 = vdbRefRand();
|
|
762
|
+
let u2 = vdbRefRand();
|
|
763
|
+
var cosTheta = 0.0;
|
|
764
|
+
if (rec.tables.x > 0u) {
|
|
765
|
+
let ts = vdbRefPhaseTableSample(rec.tables.x - 1u, rec.tables.y, u1);
|
|
766
|
+
cosTheta = ts.cosTheta;
|
|
767
|
+
beta = beta * ts.weight;
|
|
768
|
+
phasePdf = ts.pdf;
|
|
769
|
+
} else {
|
|
770
|
+
let g = select(ph.x, ph.y, ph.z > 0.0 && lobe < ph.z);
|
|
771
|
+
cosTheta = vdbRefSampleHgCos(g, u1);
|
|
772
|
+
// the lobe mixture is sampled exactly: its density is the phase itself
|
|
773
|
+
phasePdf = vdbRefPhaseEval(cosTheta, vol).x;
|
|
774
|
+
}
|
|
775
|
+
d = normalize(vdbRefDirectionAround(d, cosTheta, u2));
|
|
776
|
+
o = x;
|
|
777
|
+
mode = 1u;
|
|
778
|
+
}
|
|
779
|
+
return vec4f(rad, primaryT);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
@compute @workgroup_size(8, 8, 1)
|
|
783
|
+
fn vdbRefTraceCs(@builtin(global_invocation_id) gid: vec3u) {
|
|
784
|
+
if (gid.x >= vdbRefU.size.x || gid.y >= vdbRefU.size.y) {
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
var m = vec4f(0.0);
|
|
788
|
+
for (var s = 0u; s < vdbRefU.spp; s = s + 1u) {
|
|
789
|
+
m = m + vdbRefSample(gid.xy, vdbRefBatch.batch * vdbRefU.spp + s);
|
|
790
|
+
}
|
|
791
|
+
m = m / f32(vdbRefU.spp);
|
|
792
|
+
var s0 = m;
|
|
793
|
+
var s1 = m * m;
|
|
794
|
+
if (vdbRefBatch.accumulate != 0u) {
|
|
795
|
+
s0 = s0 + textureLoad(vdbRefAccumIn0, gid.xy, 0);
|
|
796
|
+
s1 = s1 + textureLoad(vdbRefAccumIn1, gid.xy, 0);
|
|
797
|
+
}
|
|
798
|
+
textureStore(vdbRefAccumOut0, gid.xy, s0);
|
|
799
|
+
textureStore(vdbRefAccumOut1, gid.xy, s1);
|
|
800
|
+
}
|
|
801
|
+
`;
|
|
802
|
+
}
|
|
803
|
+
//# sourceMappingURL=wgsl.js.map
|