@pmndrs/vdb 0.0.0-stage → 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 +727 -0
- package/LICENSE +21 -0
- package/README.md +496 -2
- package/THIRD_PARTY_NOTICES.md +315 -0
- package/dist/core/compute/atlas.d.ts +102 -0
- package/dist/core/compute/atlas.js +103 -0
- package/dist/core/compute/atlas.js.map +1 -0
- package/dist/core/compute/index.d.ts +13 -0
- package/dist/core/compute/index.js +9 -0
- package/dist/core/compute/index.js.map +1 -0
- 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 +120 -0
- package/dist/core/compute/pyramid.js +468 -0
- package/dist/core/compute/pyramid.js.map +1 -0
- package/dist/core/compute/shared.d.ts +116 -0
- package/dist/core/compute/shared.js +211 -0
- package/dist/core/compute/shared.js.map +1 -0
- package/dist/core/compute/stats.d.ts +78 -0
- package/dist/core/compute/stats.js +193 -0
- package/dist/core/compute/stats.js.map +1 -0
- package/dist/core/compute/value-transform.d.ts +30 -0
- package/dist/core/compute/value-transform.js +64 -0
- package/dist/core/compute/value-transform.js.map +1 -0
- package/dist/core/errors.d.ts +21 -0
- package/dist/core/errors.js +17 -0
- package/dist/core/errors.js.map +1 -0
- 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 +52 -0
- package/dist/core/index.js +46 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/internal.d.ts +31 -0
- package/dist/core/internal.js +32 -0
- package/dist/core/internal.js.map +1 -0
- package/dist/core/pool/affine.d.ts +34 -0
- package/dist/core/pool/affine.js +100 -0
- package/dist/core/pool/affine.js.map +1 -0
- package/dist/core/pool/allocator.d.ts +32 -0
- package/dist/core/pool/allocator.js +81 -0
- package/dist/core/pool/allocator.js.map +1 -0
- package/dist/core/pool/image-header.d.ts +93 -0
- package/dist/core/pool/image-header.js +194 -0
- package/dist/core/pool/image-header.js.map +1 -0
- package/dist/core/pool/layout.d.ts +198 -0
- package/dist/core/pool/layout.js +316 -0
- package/dist/core/pool/layout.js.map +1 -0
- package/dist/core/pool/limits.d.ts +41 -0
- package/dist/core/pool/limits.js +80 -0
- package/dist/core/pool/limits.js.map +1 -0
- package/dist/core/pool/pool.d.ts +384 -0
- package/dist/core/pool/pool.js +1184 -0
- package/dist/core/pool/pool.js.map +1 -0
- 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/core/sequence.d.ts +347 -0
- package/dist/core/sequence.js +548 -0
- 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 +50 -0
- package/dist/core/source/dense.js +384 -0
- package/dist/core/source/dense.js.map +1 -0
- 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 +120 -0
- package/dist/core/source/types.js +9 -0
- package/dist/core/source/types.js.map +1 -0
- 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 +37 -0
- package/dist/core/types.js +32 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/wgsl/api.d.ts +65 -0
- package/dist/core/wgsl/api.js +546 -0
- package/dist/core/wgsl/api.js.map +1 -0
- package/dist/core/wgsl/generate.d.ts +90 -0
- package/dist/core/wgsl/generate.js +678 -0
- package/dist/core/wgsl/generate.js.map +1 -0
- 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 +58 -0
- package/dist/core/wgsl/level-set.js +200 -0
- package/dist/core/wgsl/level-set.js.map +1 -0
- 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 +14 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +333 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
- package/dist/core/wgsl/reserved.d.ts +9 -0
- package/dist/core/wgsl/reserved.js +26 -0
- package/dist/core/wgsl/reserved.js.map +1 -0
- package/dist/core/wgsl/types.d.ts +198 -0
- package/dist/core/wgsl/types.js +2 -0
- package/dist/core/wgsl/types.js.map +1 -0
- package/dist/three/coarse-first.d.ts +207 -0
- package/dist/three/coarse-first.js +205 -0
- package/dist/three/coarse-first.js.map +1 -0
- package/dist/three/compute.d.ts +73 -0
- package/dist/three/compute.js +66 -0
- package/dist/three/compute.js.map +1 -0
- package/dist/three/device.d.ts +66 -0
- package/dist/three/device.js +62 -0
- package/dist/three/device.js.map +1 -0
- 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 +117 -0
- package/dist/three/frame/emission-light.js +276 -0
- package/dist/three/frame/emission-light.js.map +1 -0
- package/dist/three/frame/index.d.ts +19 -0
- package/dist/three/frame/index.js +15 -0
- package/dist/three/frame/index.js.map +1 -0
- package/dist/three/frame/medium.d.ts +33 -0
- package/dist/three/frame/medium.js +29 -0
- package/dist/three/frame/medium.js.map +1 -0
- package/dist/three/frame/renderer.d.ts +97 -0
- package/dist/three/frame/renderer.js +480 -0
- package/dist/three/frame/renderer.js.map +1 -0
- package/dist/three/frame/spectrum.d.ts +4 -0
- package/dist/three/frame/spectrum.js +15 -0
- package/dist/three/frame/spectrum.js.map +1 -0
- package/dist/three/frame/three-internals.d.ts +60 -0
- package/dist/three/frame/three-internals.js +152 -0
- package/dist/three/frame/three-internals.js.map +1 -0
- package/dist/three/frame/volume-shadows.d.ts +139 -0
- package/dist/three/frame/volume-shadows.js +403 -0
- package/dist/three/frame/volume-shadows.js.map +1 -0
- package/dist/three/frame/volume.d.ts +230 -0
- package/dist/three/frame/volume.js +268 -0
- package/dist/three/frame/volume.js.map +1 -0
- package/dist/three/grid-node.d.ts +229 -0
- package/dist/three/grid-node.js +545 -0
- package/dist/three/grid-node.js.map +1 -0
- package/dist/three/index.d.ts +52 -0
- package/dist/three/index.js +58 -0
- package/dist/three/index.js.map +1 -0
- package/dist/three/internal.d.ts +20 -0
- package/dist/three/internal.js +18 -0
- package/dist/three/internal.js.map +1 -0
- package/dist/three/level-set-material.d.ts +185 -0
- package/dist/three/level-set-material.js +241 -0
- package/dist/three/level-set-material.js.map +1 -0
- 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 +324 -0
- package/dist/three/material.js +502 -0
- package/dist/three/material.js.map +1 -0
- package/dist/three/points.d.ts +140 -0
- package/dist/three/points.js +261 -0
- package/dist/three/points.js.map +1 -0
- package/dist/three/sparse-source.d.ts +165 -0
- package/dist/three/sparse-source.js +405 -0
- package/dist/three/sparse-source.js.map +1 -0
- package/dist/three/volume-source.d.ts +22 -0
- package/dist/three/volume-source.js +110 -0
- package/dist/three/volume-source.js.map +1 -0
- 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 +116 -0
- package/dist/tools/cpu/compute.js +239 -0
- package/dist/tools/cpu/compute.js.map +1 -0
- 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 +111 -0
- package/dist/tools/cpu/level-set.js +313 -0
- package/dist/tools/cpu/level-set.js.map +1 -0
- 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 +297 -0
- package/dist/tools/cpu/march.js +726 -0
- package/dist/tools/cpu/march.js.map +1 -0
- 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/probe-coords.d.ts +70 -0
- package/dist/tools/cpu/probe-coords.js +116 -0
- package/dist/tools/cpu/probe-coords.js.map +1 -0
- package/dist/tools/cpu/read-value.d.ts +44 -0
- package/dist/tools/cpu/read-value.js +351 -0
- package/dist/tools/cpu/read-value.js.map +1 -0
- package/dist/tools/cpu/sample-trilinear.d.ts +43 -0
- package/dist/tools/cpu/sample-trilinear.js +168 -0
- package/dist/tools/cpu/sample-trilinear.js.map +1 -0
- package/dist/tools/cpu/stride-tables.d.ts +56 -0
- package/dist/tools/cpu/stride-tables.generated.d.ts +1059 -0
- package/dist/tools/cpu/stride-tables.generated.js +1267 -0
- package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
- package/dist/tools/cpu/stride-tables.js +78 -0
- package/dist/tools/cpu/stride-tables.js.map +1 -0
- 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 +66 -0
- package/dist/tools/errors.js +67 -0
- package/dist/tools/errors.js.map +1 -0
- 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 +57 -0
- package/dist/tools/frame/blackbody.js +151 -0
- package/dist/tools/frame/blackbody.js.map +1 -0
- 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 +137 -0
- package/dist/tools/frame/emission.js +290 -0
- package/dist/tools/frame/emission.js.map +1 -0
- 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 +106 -0
- package/dist/tools/frame/environment.js +272 -0
- package/dist/tools/frame/environment.js.map +1 -0
- 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 +392 -0
- package/dist/tools/frame/grid.js +802 -0
- package/dist/tools/frame/grid.js.map +1 -0
- package/dist/tools/frame/index.d.ts +150 -0
- package/dist/tools/frame/index.js +389 -0
- package/dist/tools/frame/index.js.map +1 -0
- package/dist/tools/frame/medium.d.ts +77 -0
- package/dist/tools/frame/medium.js +101 -0
- package/dist/tools/frame/medium.js.map +1 -0
- package/dist/tools/frame/mie-table.d.ts +6 -0
- package/dist/tools/frame/mie-table.js +16 -0
- package/dist/tools/frame/mie-table.js.map +1 -0
- package/dist/tools/frame/mie.d.ts +63 -0
- package/dist/tools/frame/mie.js +194 -0
- package/dist/tools/frame/mie.js.map +1 -0
- 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 +10 -0
- package/dist/tools/frame/neural-weights.js +244 -0
- package/dist/tools/frame/neural-weights.js.map +1 -0
- package/dist/tools/frame/neural.d.ts +80 -0
- package/dist/tools/frame/neural.js +150 -0
- package/dist/tools/frame/neural.js.map +1 -0
- 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 +55 -0
- package/dist/tools/frame/pyramid-layout.js +100 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -0
- package/dist/tools/frame/shadows.d.ts +190 -0
- package/dist/tools/frame/shadows.js +468 -0
- package/dist/tools/frame/shadows.js.map +1 -0
- package/dist/tools/frame/sparse.d.ts +147 -0
- package/dist/tools/frame/sparse.js +432 -0
- package/dist/tools/frame/sparse.js.map +1 -0
- 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 +222 -0
- package/dist/tools/frame/spectral.js +572 -0
- package/dist/tools/frame/spectral.js.map +1 -0
- 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 +157 -0
- package/dist/tools/index.js +132 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/internal.d.ts +87 -0
- package/dist/tools/internal.js +85 -0
- package/dist/tools/internal.js.map +1 -0
- package/dist/tools/nanovdb/build-from-vdb.d.ts +59 -0
- package/dist/tools/nanovdb/build-from-vdb.js +100 -0
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
- package/dist/tools/nanovdb/bytes.d.ts +233 -0
- package/dist/tools/nanovdb/bytes.js +388 -0
- package/dist/tools/nanovdb/bytes.js.map +1 -0
- package/dist/tools/nanovdb/coarse-first.d.ts +78 -0
- package/dist/tools/nanovdb/coarse-first.js +92 -0
- package/dist/tools/nanovdb/coarse-first.js.map +1 -0
- 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 +34 -0
- package/dist/tools/nanovdb/index.js +25 -0
- package/dist/tools/nanovdb/index.js.map +1 -0
- package/dist/tools/nanovdb/inspect.d.ts +33 -0
- package/dist/tools/nanovdb/inspect.js +70 -0
- package/dist/tools/nanovdb/inspect.js.map +1 -0
- package/dist/tools/nanovdb/leaf-codec.d.ts +119 -0
- package/dist/tools/nanovdb/leaf-codec.js +356 -0
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
- package/dist/tools/nanovdb/quantize.d.ts +72 -0
- package/dist/tools/nanovdb/quantize.js +329 -0
- package/dist/tools/nanovdb/quantize.js.map +1 -0
- package/dist/tools/nanovdb/resample.d.ts +177 -0
- package/dist/tools/nanovdb/resample.js +692 -0
- package/dist/tools/nanovdb/resample.js.map +1 -0
- package/dist/tools/nanovdb/serialize.d.ts +176 -0
- package/dist/tools/nanovdb/serialize.js +439 -0
- package/dist/tools/nanovdb/serialize.js.map +1 -0
- package/dist/tools/nanovdb/stats.d.ts +87 -0
- package/dist/tools/nanovdb/stats.js +225 -0
- package/dist/tools/nanovdb/stats.js.map +1 -0
- package/dist/tools/nanovdb/transform.d.ts +30 -0
- package/dist/tools/nanovdb/transform.js +94 -0
- package/dist/tools/nanovdb/transform.js.map +1 -0
- package/dist/tools/nanovdb/tree.d.ts +186 -0
- package/dist/tools/nanovdb/tree.js +530 -0
- package/dist/tools/nanovdb/tree.js.map +1 -0
- package/dist/tools/nanovdb/write-nvdb.d.ts +74 -0
- package/dist/tools/nanovdb/write-nvdb.js +290 -0
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
- package/dist/tools/nvdb-file.d.ts +265 -0
- package/dist/tools/nvdb-file.js +763 -0
- package/dist/tools/nvdb-file.js.map +1 -0
- package/dist/tools/nvdb-stream.d.ts +154 -0
- package/dist/tools/nvdb-stream.js +409 -0
- package/dist/tools/nvdb-stream.js.map +1 -0
- 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/bit-utils.d.ts +20 -0
- package/dist/tools/vdb/bit-utils.js +42 -0
- package/dist/tools/vdb/bit-utils.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 +86 -0
- package/dist/tools/vdb/blosc.js +287 -0
- package/dist/tools/vdb/blosc.js.map +1 -0
- 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 +50 -0
- package/dist/tools/vdb/byte-reader.js +161 -0
- package/dist/tools/vdb/byte-reader.js.map +1 -0
- package/dist/tools/vdb/compression.d.ts +81 -0
- package/dist/tools/vdb/compression.js +260 -0
- package/dist/tools/vdb/compression.js.map +1 -0
- package/dist/tools/vdb/errors.d.ts +10 -0
- package/dist/tools/vdb/errors.js +11 -0
- package/dist/tools/vdb/errors.js.map +1 -0
- package/dist/tools/vdb/grid.d.ts +37 -0
- package/dist/tools/vdb/grid.js +153 -0
- package/dist/tools/vdb/grid.js.map +1 -0
- package/dist/tools/vdb/half-float.d.ts +9 -0
- package/dist/tools/vdb/half-float.js +24 -0
- package/dist/tools/vdb/half-float.js.map +1 -0
- package/dist/tools/vdb/index.d.ts +4 -0
- package/dist/tools/vdb/index.js +3 -0
- package/dist/tools/vdb/index.js.map +1 -0
- package/dist/tools/vdb/inflate.d.ts +24 -0
- package/dist/tools/vdb/inflate.js +334 -0
- package/dist/tools/vdb/inflate.js.map +1 -0
- 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.d.ts +17 -0
- package/dist/tools/vdb/metadata.js +72 -0
- package/dist/tools/vdb/metadata.js.map +1 -0
- package/dist/tools/vdb/parse.d.ts +47 -0
- package/dist/tools/vdb/parse.js +241 -0
- package/dist/tools/vdb/parse.js.map +1 -0
- package/dist/tools/vdb/point-render-data.d.ts +79 -0
- package/dist/tools/vdb/point-render-data.js +137 -0
- package/dist/tools/vdb/point-render-data.js.map +1 -0
- package/dist/tools/vdb/points.d.ts +186 -0
- package/dist/tools/vdb/points.js +835 -0
- package/dist/tools/vdb/points.js.map +1 -0
- package/dist/tools/vdb/transform.d.ts +23 -0
- package/dist/tools/vdb/transform.js +54 -0
- package/dist/tools/vdb/transform.js.map +1 -0
- package/dist/tools/vdb/tree.d.ts +111 -0
- package/dist/tools/vdb/tree.js +228 -0
- package/dist/tools/vdb/tree.js.map +1 -0
- package/dist/tools/vdb/types.d.ts +195 -0
- package/dist/tools/vdb/types.js +3 -0
- package/dist/tools/vdb/types.js.map +1 -0
- package/dist/tools/wvdb/bake.d.ts +145 -0
- package/dist/tools/wvdb/bake.js +361 -0
- package/dist/tools/wvdb/bake.js.map +1 -0
- package/dist/tools/wvdb/dense.d.ts +191 -0
- package/dist/tools/wvdb/dense.js +368 -0
- package/dist/tools/wvdb/dense.js.map +1 -0
- package/dist/tools/wvdb/format.d.ts +220 -0
- package/dist/tools/wvdb/format.js +306 -0
- package/dist/tools/wvdb/format.js.map +1 -0
- package/dist/tools/wvdb/index.d.ts +14 -0
- package/dist/tools/wvdb/index.js +15 -0
- package/dist/tools/wvdb/index.js.map +1 -0
- package/dist/tools/wvdb/level-set.d.ts +56 -0
- package/dist/tools/wvdb/level-set.js +153 -0
- package/dist/tools/wvdb/level-set.js.map +1 -0
- package/dist/tools/wvdb/nanovdb.d.ts +59 -0
- package/dist/tools/wvdb/nanovdb.js +64 -0
- package/dist/tools/wvdb/nanovdb.js.map +1 -0
- 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 +336 -0
- package/dist/tools/wvdb/read.js +766 -0
- package/dist/tools/wvdb/read.js.map +1 -0
- package/dist/tools/wvdb/sha256.d.ts +7 -0
- package/dist/tools/wvdb/sha256.js +76 -0
- package/dist/tools/wvdb/sha256.js.map +1 -0
- package/dist/tools/wvdb/write.d.ts +149 -0
- package/dist/tools/wvdb/write.js +403 -0
- package/dist/tools/wvdb/write.js.map +1 -0
- package/package.json +83 -4
- package/vendor/LICENSE +201 -0
- package/vendor/NOTICE +19 -0
- package/vendor/VENDOR.md +100 -0
- package/vendor/pnanovdb.wgsl +1577 -0
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `VDBVolumeMaterial`: the fragment raymarch of one grid in a `VDBGridPool`,
|
|
3
|
+
* through a `VDBGridNode` (task K2.3, docs/archive/handoffs/K2.md). It replaces v1's
|
|
4
|
+
* `NanoVDBVolumeMaterial`, which bound one grid image as its own storage
|
|
5
|
+
* attribute and rewrote the vendored library's buffer global.
|
|
6
|
+
*
|
|
7
|
+
* const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });
|
|
8
|
+
* const material = new VDBVolumeMaterial(renderer, grids, id);
|
|
9
|
+
* scene.add(new Mesh(vdbProxyGeometry(pool.info(id)), material));
|
|
10
|
+
* // per frame: pool.update(encoder) (or pool.flush()), then grids.update(), then render.
|
|
11
|
+
*
|
|
12
|
+
* The march is one entry `wgslFn` over the public `vdb*` WGSL API, with
|
|
13
|
+
* `grids.module` as its include (the module carries the pool binding):
|
|
14
|
+
* - the world ray goes into the grid's index space through the record's
|
|
15
|
+
* affine (`vdbWorldToIndex`/`vdbWorldToIndexDir`), so `pool.setTransform`
|
|
16
|
+
* instances render where they are;
|
|
17
|
+
* - it is clipped to the sampler's support box (`vdbRayClipSupport`,
|
|
18
|
+
* `[min - 1, max + 1]` for trilinear), not the voxel-cell box, so the
|
|
19
|
+
* min-side half voxel the trilinear taps reach is marched too;
|
|
20
|
+
* - fixed-step density accumulation with `vdbSample` (the node's sampler),
|
|
21
|
+
* premultiplied front-to-back compositing, early-out at low transmittance.
|
|
22
|
+
* The step lattice is anchored at the voxel-box entry (`vdbRayClip`, where
|
|
23
|
+
* v1 started) and extended back over the support shell, so samples inside
|
|
24
|
+
* the box sit where v1's did; only the shell samples are new (v1 skipped
|
|
25
|
+
* that half voxel, which shows where a grid's min-side voxels are dense);
|
|
26
|
+
* - lighting as in v1: Henyey-Greenstein phase on a directional sun, an
|
|
27
|
+
* N-step shadow march toward the sun (a second accessor), a constant
|
|
28
|
+
* ambient floor, and a per-fragment budget on the total samples;
|
|
29
|
+
* - the look is sized to the grid by default (EX1a, DIVERGES V291): the
|
|
30
|
+
* extinction is `opticalDepth` across the grid's longest index side at the
|
|
31
|
+
* grid's mean density, and the shadow ray spans `shadowReach` of that side.
|
|
32
|
+
* The side is read from the pool record per fragment (`vdbIndexMin` /
|
|
33
|
+
* `vdbIndexMax`), so it follows a `gridId` change, a `pool.replace` and a
|
|
34
|
+
* coarse-first swap; the mean (`densityReference`) is the root node's
|
|
35
|
+
* average statistic, read from `pool.info(id)` at each render. An explicit
|
|
36
|
+
* `densityScale` (> 0) is extinction per index voxel, as in 0.1.
|
|
37
|
+
*
|
|
38
|
+
* Rendered on a proxy box with `side: BackSide` (the camera can be inside);
|
|
39
|
+
* entry and exit come from the analytic clip, not the rasterized faces. The
|
|
40
|
+
* material is `transparent`, `depthWrite: false`, premultiplied alpha. Scene
|
|
41
|
+
* depth compositing is not done (v1 neither).
|
|
42
|
+
*
|
|
43
|
+
* Every tunable is a live TSL uniform (`material.densityScale.value = ...`).
|
|
44
|
+
* The grid is a `uint` uniform too when the constructor got a number
|
|
45
|
+
* (`material.gridId.value = otherId`), so one material can show any grid of
|
|
46
|
+
* the types its `VDBGridNode` compiles without a rebuild.
|
|
47
|
+
*
|
|
48
|
+
* Units and assumptions:
|
|
49
|
+
* - The march runs in the grid's **index space**: `stepSize` is in index
|
|
50
|
+
* voxels, `opticalDepth` is relative to the index box and `densityScale`
|
|
51
|
+
* integrates per index voxel. Opacity therefore does not change with the
|
|
52
|
+
* world size of the grid: `pool.setTransform` (or a NanoVDB map) that scales
|
|
53
|
+
* the grid scales its footprint, not how opaque it looks.
|
|
54
|
+
* - `densityReference` follows the grid: a sequence that replaces the grid
|
|
55
|
+
* each frame is normalised per frame. Pass a number to pin it.
|
|
56
|
+
* - The proxy mesh is not tied to the grid: after `material.gridId.value = id`
|
|
57
|
+
* or `pool.setTransform(id, ...)`, build a new `vdbProxyGeometry(pool.info(id))`
|
|
58
|
+
* for the mesh, or fragments outside the old box are never rasterized.
|
|
59
|
+
* - The view ray is `positionWorld - cameraPosition`: a perspective camera.
|
|
60
|
+
* An orthographic camera's rays are parallel and do not start at
|
|
61
|
+
* `cameraPosition`, so it renders wrongly.
|
|
62
|
+
*/
|
|
63
|
+
import * as THREE from "three";
|
|
64
|
+
import { NodeMaterial } from "three/webgpu";
|
|
65
|
+
import { cameraPosition, code, positionWorld, screenCoordinate, uniform, wgslFn } from "three/tsl";
|
|
66
|
+
import { VDBError } from "../core/errors.js";
|
|
67
|
+
import { getDevice } from "./device.js";
|
|
68
|
+
import { VDBGridNode } from "./grid-node.js";
|
|
69
|
+
/** Default hard caps of the compiled loops (the live uniforms clamp under them). */
|
|
70
|
+
export const VDB_VOLUME_MAX_STEPS_CAP = 1024;
|
|
71
|
+
/** Default compiled cap on `shadowSteps`. */
|
|
72
|
+
export const VDB_VOLUME_SHADOW_STEPS_CAP = 128;
|
|
73
|
+
/**
|
|
74
|
+
* Default cap on the total samples (primary + shadow) one fragment takes.
|
|
75
|
+
* `maxSteps` and `shadowSteps` are independent live uniforms, so their product
|
|
76
|
+
* can reach `maxStepsCap * shadowStepsCap` (~131k at the defaults), a driver
|
|
77
|
+
* timeout risk. Once the budget is spent the shadow loop stops first, then the
|
|
78
|
+
* primary loop, and the fragment returns its partial march.
|
|
79
|
+
*/
|
|
80
|
+
export const VDB_VOLUME_SAMPLE_BUDGET_CAP = 16384;
|
|
81
|
+
/** Default `opticalDepth`: the optical depth across the grid's longest index side at its mean density (EX1a). */
|
|
82
|
+
export const VDB_VOLUME_OPTICAL_DEPTH = 6;
|
|
83
|
+
/** Default `shadowReach`: the shadow ray spans this fraction of the grid's longest index side (EX1a). */
|
|
84
|
+
export const VDB_VOLUME_SHADOW_REACH = 0.3;
|
|
85
|
+
/** Default `sunIntensity` (EX1a): about 4π × 1.25, so the sun reads against the ambient term (a phase is about 1 / 4π). */
|
|
86
|
+
export const VDB_VOLUME_SUN_INTENSITY = 16;
|
|
87
|
+
const DEFAULTS = {
|
|
88
|
+
densityScale: 0,
|
|
89
|
+
opticalDepth: VDB_VOLUME_OPTICAL_DEPTH,
|
|
90
|
+
stepSize: 0.75,
|
|
91
|
+
maxSteps: 512,
|
|
92
|
+
sunIntensity: VDB_VOLUME_SUN_INTENSITY,
|
|
93
|
+
anisotropy: 0.3,
|
|
94
|
+
shadowSteps: 12,
|
|
95
|
+
shadowDensity: 1,
|
|
96
|
+
shadowReach: VDB_VOLUME_SHADOW_REACH,
|
|
97
|
+
ambient: 0.15,
|
|
98
|
+
};
|
|
99
|
+
/** The smallest `densityReference` the march divides by. */
|
|
100
|
+
export const VDB_VOLUME_MIN_REFERENCE = 1e-20;
|
|
101
|
+
/**
|
|
102
|
+
* The `densityReference` of a grid: its root average statistic when the image has one above 0, else 1 (no
|
|
103
|
+
* statistics, an empty grid, or a grid of non-positive values).
|
|
104
|
+
*
|
|
105
|
+
* @param rootAverage `pool.info(id).rootAverage`.
|
|
106
|
+
*/
|
|
107
|
+
export function vdbVolumeDensityReference(rootAverage) {
|
|
108
|
+
return typeof rootAverage === "number" && Number.isFinite(rootAverage) && rootAverage > 0 ? rootAverage : 1;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The CPU twin of the scale lines of the march entry (EX1a): what `VDBVolumeMaterial` derives from the grid's
|
|
112
|
+
* longest index side. `densityScale > 0` is the extinction as given, else
|
|
113
|
+
* `opticalDepth / (longest * densityReference)`;
|
|
114
|
+
* `shadowReach > 0` spreads the shadow steps over that fraction of the side (midpoint samples), else they step
|
|
115
|
+
* by `stepSize` (0.1's march).
|
|
116
|
+
*
|
|
117
|
+
* @param longest The grid's longest index side in voxels (`max(indexBBox.max - indexBBox.min) + 1`).
|
|
118
|
+
* @param u The material's uniform values.
|
|
119
|
+
*/
|
|
120
|
+
export function vdbVolumeMarchScales(longest, u) {
|
|
121
|
+
const side = Math.max(longest, 1);
|
|
122
|
+
const extinction = u.densityScale > 0 ? u.densityScale : u.opticalDepth / (side * Math.max(u.densityReference ?? 1, VDB_VOLUME_MIN_REFERENCE));
|
|
123
|
+
const steps = Math.trunc(Math.min(Math.max(u.shadowSteps, 0), u.shadowStepsCap ?? VDB_VOLUME_SHADOW_STEPS_CAP));
|
|
124
|
+
if (u.shadowReach > 0) {
|
|
125
|
+
const shadowStep = (u.shadowReach * side) / Math.max(steps, 1);
|
|
126
|
+
return { extinction, shadowStep, shadowStart: shadowStep * 0.5 };
|
|
127
|
+
}
|
|
128
|
+
return { extinction, shadowStep: u.stepSize, shadowStart: u.stepSize };
|
|
129
|
+
}
|
|
130
|
+
/** Entry name of the march `wgslFn`. */
|
|
131
|
+
const ENTRY = "vdbThreeVolumeMarch";
|
|
132
|
+
/**
|
|
133
|
+
* Module-scope helpers of the march, a second include next to `grids.module`
|
|
134
|
+
* (`wgslFn` parses only its first `fn`, so the entry can't hold them).
|
|
135
|
+
*/
|
|
136
|
+
const VOLUME_HELPERS_WGSL = /* wgsl */ `
|
|
137
|
+
fn vdbThreeHgPhase(cos_theta: f32, g: f32) -> f32 {
|
|
138
|
+
let gg = g * g;
|
|
139
|
+
let denom = 1.0 + gg - 2.0 * g * cos_theta;
|
|
140
|
+
return (1.0 - gg) / (12.566370614359172 * pow(max(denom, 1.0e-4), 1.5));
|
|
141
|
+
}
|
|
142
|
+
fn vdbThreeHash12(p: vec2f) -> f32 {
|
|
143
|
+
var p3 = fract(vec3f(p.x, p.y, p.x) * 0.1031);
|
|
144
|
+
p3 = p3 + dot(p3, p3.yzx + 33.33);
|
|
145
|
+
return fract((p3.x + p3.y) * p3.z);
|
|
146
|
+
}
|
|
147
|
+
`;
|
|
148
|
+
/** The march entry, the one `fn` of its `wgslFn`. Caps are compiled in. */
|
|
149
|
+
function marchWgsl(maxStepsCap, shadowStepsCap, sampleBudgetCap) {
|
|
150
|
+
return /* wgsl */ `fn ${ENTRY}(
|
|
151
|
+
grid_id: u32,
|
|
152
|
+
ray_origin_w: vec3f,
|
|
153
|
+
ray_dir_w: vec3f,
|
|
154
|
+
sun_dir_w: vec3f,
|
|
155
|
+
sun_color: vec3f,
|
|
156
|
+
sun_intensity: f32,
|
|
157
|
+
density_scale: f32,
|
|
158
|
+
optical_depth: f32,
|
|
159
|
+
density_reference: f32,
|
|
160
|
+
step_size: f32,
|
|
161
|
+
max_steps: f32,
|
|
162
|
+
g: f32,
|
|
163
|
+
shadow_steps: f32,
|
|
164
|
+
shadow_density: f32,
|
|
165
|
+
shadow_reach: f32,
|
|
166
|
+
ambient: f32,
|
|
167
|
+
jitter: f32,
|
|
168
|
+
pix: vec2f
|
|
169
|
+
) -> vec4f {
|
|
170
|
+
// World -> index through the pool record (instance transform included).
|
|
171
|
+
let o_idx = vdbWorldToIndex(grid_id, ray_origin_w);
|
|
172
|
+
let d_idx = normalize(vdbWorldToIndexDir(grid_id, ray_dir_w));
|
|
173
|
+
let sun_idx = normalize(vdbWorldToIndexDir(grid_id, sun_dir_w));
|
|
174
|
+
|
|
175
|
+
// Clip to the trilinear support box; a dead id misses.
|
|
176
|
+
var span = vec2f(0.0, 1.0e30);
|
|
177
|
+
if !vdbRayClipSupport(grid_id, o_idx, d_idx, &span) {
|
|
178
|
+
return vec4f(0.0);
|
|
179
|
+
}
|
|
180
|
+
// t0 >= 0: no sample behind the eye (camera inside the support box).
|
|
181
|
+
let t0 = max(span.x, 0.0);
|
|
182
|
+
let t1 = span.y;
|
|
183
|
+
|
|
184
|
+
var acc = vdbAccessorInit(grid_id);
|
|
185
|
+
var sacc = vdbAccessorInit(grid_id);
|
|
186
|
+
|
|
187
|
+
// The phase uses the world-space view/sun angle.
|
|
188
|
+
let phase = vdbThreeHgPhase(dot(normalize(ray_dir_w), normalize(sun_dir_w)), g);
|
|
189
|
+
|
|
190
|
+
// The step lattice is anchored where the ray enters the voxel box
|
|
191
|
+
// (vdbRayClip, v1's entry) and extended back to the support entry, so the
|
|
192
|
+
// samples inside the box sit exactly where v1's did.
|
|
193
|
+
var t = t0;
|
|
194
|
+
var cell = vec2f(0.0, 1.0e30);
|
|
195
|
+
if vdbRayClip(grid_id, o_idx, d_idx, &cell) {
|
|
196
|
+
let anchor = max(cell.x, 0.0);
|
|
197
|
+
t = anchor - ceil((anchor - t0) / step_size) * step_size;
|
|
198
|
+
}
|
|
199
|
+
t += step_size * jitter * vdbThreeHash12(pix);
|
|
200
|
+
// The lattice can start before t0 (the anchor is stepped back in whole
|
|
201
|
+
// steps, plus jitter). Skip those steps on the lattice: they are behind the
|
|
202
|
+
// eye (camera in the support shell) or outside the support box.
|
|
203
|
+
if t < t0 {
|
|
204
|
+
t += ceil((t0 - t) / step_size) * step_size;
|
|
205
|
+
}
|
|
206
|
+
var transmittance = 1.0;
|
|
207
|
+
var color = vec3f(0.0);
|
|
208
|
+
let max_i = i32(clamp(max_steps, 1.0, ${maxStepsCap}.0));
|
|
209
|
+
let shadow_n = i32(clamp(shadow_steps, 0.0, ${shadowStepsCap}.0));
|
|
210
|
+
|
|
211
|
+
// What the look takes from the grid's size (CPU twin: vdbVolumeMarchScales). The extinction per index voxel
|
|
212
|
+
// is the explicit scale as given, else the optical depth across the longest index side at the reference
|
|
213
|
+
// density; the shadow ray steps by the march step, or spans the reach fraction of the side (midpoint samples).
|
|
214
|
+
let dims = vec3f(vdbIndexMax(grid_id) - vdbIndexMin(grid_id) + vec3i(1));
|
|
215
|
+
let longest = max(max(dims.x, max(dims.y, dims.z)), 1.0);
|
|
216
|
+
var extinction = density_scale;
|
|
217
|
+
if !(extinction > 0.0) {
|
|
218
|
+
extinction = optical_depth / (longest * max(density_reference, 1.0e-20));
|
|
219
|
+
}
|
|
220
|
+
var shadow_step = step_size;
|
|
221
|
+
var shadow_start = step_size;
|
|
222
|
+
if shadow_reach > 0.0 {
|
|
223
|
+
shadow_step = shadow_reach * longest / f32(max(shadow_n, 1));
|
|
224
|
+
shadow_start = shadow_step * 0.5;
|
|
225
|
+
}
|
|
226
|
+
let budget = ${sampleBudgetCap};
|
|
227
|
+
var samples = 0;
|
|
228
|
+
|
|
229
|
+
for (var i = 0; i < max_i; i++) {
|
|
230
|
+
if t > t1 || transmittance < 0.003 || samples >= budget {
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
let pos = o_idx + d_idx * t;
|
|
234
|
+
let density = max(vdbSample(&acc, pos), 0.0) * extinction;
|
|
235
|
+
samples++;
|
|
236
|
+
if density > 0.0 {
|
|
237
|
+
let a = 1.0 - exp(-density * step_size);
|
|
238
|
+
var tau = 0.0;
|
|
239
|
+
var st = shadow_start;
|
|
240
|
+
for (var s = 0; s < shadow_n; s++) {
|
|
241
|
+
if samples >= budget {
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
let sd = max(vdbSample(&sacc, pos + sun_idx * st), 0.0) * extinction * shadow_density;
|
|
245
|
+
samples++;
|
|
246
|
+
tau += sd * shadow_step;
|
|
247
|
+
st += shadow_step;
|
|
248
|
+
}
|
|
249
|
+
let lit = sun_color * (sun_intensity * exp(-tau) * phase) + vec3f(ambient);
|
|
250
|
+
color += transmittance * a * lit;
|
|
251
|
+
transmittance *= 1.0 - a;
|
|
252
|
+
}
|
|
253
|
+
t += step_size;
|
|
254
|
+
}
|
|
255
|
+
return vec4f(color, 1.0 - transmittance);
|
|
256
|
+
}`;
|
|
257
|
+
}
|
|
258
|
+
function bad(message) {
|
|
259
|
+
return new VDBError("VDB_BAD_OPTION", `VDBVolumeMaterial: ${message}`);
|
|
260
|
+
}
|
|
261
|
+
function positiveInt(name, value, fallback) {
|
|
262
|
+
const v = value ?? fallback;
|
|
263
|
+
if (!Number.isInteger(v) || v < 1)
|
|
264
|
+
throw bad(`${name} must be an integer >= 1, got ${JSON.stringify(value)}.`);
|
|
265
|
+
return v;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* A fragment raymarch of one grid of a `VDBGridPool` (see the file comment for
|
|
269
|
+
* the march). Put it on a `vdbProxyGeometry(pool.info(id))` mesh; each frame
|
|
270
|
+
* run `pool.update(encoder)` (or `pool.flush()`), then `grids.update()`, then
|
|
271
|
+
* render.
|
|
272
|
+
*
|
|
273
|
+
* const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });
|
|
274
|
+
* const material = new VDBVolumeMaterial(renderer, grids, id);
|
|
275
|
+
* const mesh = new Mesh(vdbProxyGeometry(pool.info(id)), material);
|
|
276
|
+
*
|
|
277
|
+
* - The defaults are sized to the grid: `opticalDepth` (6) is the optical
|
|
278
|
+
* depth across the grid's longest index side at its mean density
|
|
279
|
+
* (`densityReference`), and the shadow ray spans `shadowReach` (0.3) of
|
|
280
|
+
* that side, so a grid of any resolution and value range draws as a lit
|
|
281
|
+
* volume. `densityScale` > 0 replaces them with an extinction per index
|
|
282
|
+
* voxel; 0.1's look is `{ densityScale: 40, sunIntensity: 3, shadowReach: 0 }`.
|
|
283
|
+
* - `stepSize` is in index voxels and the density integrates in index
|
|
284
|
+
* space, so opacity ignores the grid's world scale (`setTransform` scaling
|
|
285
|
+
* changes the size on screen, not the opacity).
|
|
286
|
+
* - After `gridId.value = otherId` or `pool.setTransform(id, ...)`, give the
|
|
287
|
+
* mesh a new `vdbProxyGeometry(pool.info(id))`.
|
|
288
|
+
* - Perspective cameras only (the ray starts at `cameraPosition`).
|
|
289
|
+
* - The material must be rendered by the renderer `grids` was made with.
|
|
290
|
+
*
|
|
291
|
+
* @typeParam TGridId What the constructor got as the id: a number (default)
|
|
292
|
+
* makes {@link gridId} a `uint` uniform; a node is kept as given.
|
|
293
|
+
*/
|
|
294
|
+
export class VDBVolumeMaterial extends NodeMaterial {
|
|
295
|
+
/** Type flag: true. */
|
|
296
|
+
isVDBVolumeMaterial = true;
|
|
297
|
+
/** The pool node this material reads (its `module` is the march's include). */
|
|
298
|
+
grids;
|
|
299
|
+
/**
|
|
300
|
+
* The grid id: a `uint` uniform when the constructor got a number
|
|
301
|
+
* (`material.gridId.value = otherId`; then give the mesh a new
|
|
302
|
+
* `vdbProxyGeometry`), else the caller's node.
|
|
303
|
+
*/
|
|
304
|
+
gridId;
|
|
305
|
+
/** The entry `fn` text (for inspection and tests). */
|
|
306
|
+
entrySource;
|
|
307
|
+
/**
|
|
308
|
+
* Extinction per index voxel at density 1 (opacity of a step: `1 - exp(-density * densityScale * stepSize)`).
|
|
309
|
+
* Default 0: the extinction comes from `opticalDepth` instead. To hide the volume, hide its mesh.
|
|
310
|
+
*/
|
|
311
|
+
densityScale;
|
|
312
|
+
/**
|
|
313
|
+
* Optical depth across the grid's longest index side at the density `densityReference`, used while
|
|
314
|
+
* `densityScale` is 0. It follows the grid (a `gridId` change, a coarse-first swap). Default 6.
|
|
315
|
+
*/
|
|
316
|
+
opticalDepth;
|
|
317
|
+
/**
|
|
318
|
+
* The density `opticalDepth` refers to. While {@link densityReferenceAuto} is true it is set at each render
|
|
319
|
+
* to the mean of the grid's active values (`pool.info(id).rootAverage`; 1 without statistics).
|
|
320
|
+
*/
|
|
321
|
+
densityReference;
|
|
322
|
+
/**
|
|
323
|
+
* True (the default, unless the constructor got a `densityReference`) while the material reads
|
|
324
|
+
* `densityReference` from the pool at each render. It needs a numeric grid id and a pool with `info(id)`
|
|
325
|
+
* (a `VDBGridPool`); otherwise the uniform keeps its value.
|
|
326
|
+
*/
|
|
327
|
+
densityReferenceAuto;
|
|
328
|
+
/** The pool revision and grid id `densityReference` was last read for. */
|
|
329
|
+
#referenceKey = null;
|
|
330
|
+
/** March step in index voxels (live; the lattice re-anchors per fragment). Default 0.75. */
|
|
331
|
+
stepSize;
|
|
332
|
+
/** Primary march steps, clamped to `[1, maxStepsCap]`. Default 512. */
|
|
333
|
+
maxSteps;
|
|
334
|
+
/** Direction toward the sun, world space (normalized at construction; keep it normalized). */
|
|
335
|
+
sunDirection;
|
|
336
|
+
/** Sun colour (linear). Default (1, 0.95, 0.9). */
|
|
337
|
+
sunColor;
|
|
338
|
+
/** Sun intensity; the sun term is `sunColor * sunIntensity * phase * shadow` (phase ≈ 1 / 4π). Default 16. */
|
|
339
|
+
sunIntensity;
|
|
340
|
+
/** Henyey-Greenstein anisotropy g in (-1, 1). Default 0.3. */
|
|
341
|
+
anisotropy;
|
|
342
|
+
/** Shadow-ray steps toward the sun per lit sample, clamped to `[0, shadowStepsCap]`. Default 12. */
|
|
343
|
+
shadowSteps;
|
|
344
|
+
/** Density multiplier along the shadow ray only. Default 1. */
|
|
345
|
+
shadowDensity;
|
|
346
|
+
/**
|
|
347
|
+
* Length of the shadow ray as a fraction of the grid's longest index side. Default 0.3. 0 steps the shadow
|
|
348
|
+
* ray by `stepSize` (`shadowSteps * stepSize` voxels, 0.1's march).
|
|
349
|
+
*/
|
|
350
|
+
shadowReach;
|
|
351
|
+
/** Constant ambient term added to the sun light. Default 0.15. */
|
|
352
|
+
ambient;
|
|
353
|
+
/** 1 = per-pixel jitter of the first sample on, 0 = off. */
|
|
354
|
+
jitter;
|
|
355
|
+
/**
|
|
356
|
+
*
|
|
357
|
+
* @param params Initial uniform values and compile-time caps ({@link VDBVolumeMaterialParameters}).
|
|
358
|
+
*
|
|
359
|
+
* @param renderer The initialized `WebGPURenderer` the pool and `grids` live on.
|
|
360
|
+
* @param grids A `VDBGridNode` made on this same renderer, with profile
|
|
361
|
+
* `sample` or `march` and `helpers: ['rayClipSupport']`. Share one per
|
|
362
|
+
* pool: one module per shader.
|
|
363
|
+
* @param gridId The grid's pool id (a number, made a `uint` uniform) or a `uint` node.
|
|
364
|
+
* @throws VDBError `VDB_BAD_OPTION` for a `grids` this material can't use
|
|
365
|
+
* (another renderer, profile, helpers), a bad id or cap;
|
|
366
|
+
* `VDB_UNSUPPORTED_DEVICE` for an uninitialized renderer.
|
|
367
|
+
*/
|
|
368
|
+
constructor(renderer, grids, gridId, params = {}) {
|
|
369
|
+
super();
|
|
370
|
+
if (!(grids instanceof VDBGridNode))
|
|
371
|
+
throw bad("grids must be a VDBGridNode.");
|
|
372
|
+
getDevice(renderer); // VDB_UNSUPPORTED_DEVICE before init
|
|
373
|
+
if (grids.renderer !== renderer) {
|
|
374
|
+
throw bad("grids was made for another renderer. A VDBGridNode binds the pool through the renderer it was made with " +
|
|
375
|
+
"(another renderer, even on the same GPUDevice, would read 0): create one VDBGridNode per renderer " +
|
|
376
|
+
"(new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] })).");
|
|
377
|
+
}
|
|
378
|
+
if (grids.options.profile === "read") {
|
|
379
|
+
throw bad("grids needs profile 'sample' or 'march' (vdbSample); this VDBGridNode was made with profile 'read'.");
|
|
380
|
+
}
|
|
381
|
+
if (!grids.options.helpers?.includes("rayClipSupport")) {
|
|
382
|
+
throw bad("grids must compile the 'rayClipSupport' helper: new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] }).");
|
|
383
|
+
}
|
|
384
|
+
if (typeof gridId === "number") {
|
|
385
|
+
if (!Number.isInteger(gridId) || gridId < 0)
|
|
386
|
+
throw bad(`gridId must be a non-negative integer, got ${gridId}.`);
|
|
387
|
+
}
|
|
388
|
+
else if (gridId === null || typeof gridId !== "object") {
|
|
389
|
+
throw bad("gridId must be a number or a uint TSL node.");
|
|
390
|
+
}
|
|
391
|
+
const maxStepsCap = positiveInt("maxStepsCap", params.maxStepsCap, VDB_VOLUME_MAX_STEPS_CAP);
|
|
392
|
+
const shadowStepsCap = positiveInt("shadowStepsCap", params.shadowStepsCap, VDB_VOLUME_SHADOW_STEPS_CAP);
|
|
393
|
+
const sampleBudgetCap = positiveInt("sampleBudgetCap", params.sampleBudgetCap, VDB_VOLUME_SAMPLE_BUDGET_CAP);
|
|
394
|
+
this.grids = grids;
|
|
395
|
+
this.gridId = (typeof gridId === "number" ? uniform(gridId, "uint") : gridId);
|
|
396
|
+
this.entrySource = marchWgsl(maxStepsCap, shadowStepsCap, sampleBudgetCap);
|
|
397
|
+
this.densityScale = uniform(params.densityScale ?? DEFAULTS.densityScale);
|
|
398
|
+
this.opticalDepth = uniform(params.opticalDepth ?? DEFAULTS.opticalDepth);
|
|
399
|
+
this.densityReferenceAuto = params.densityReference === undefined;
|
|
400
|
+
// A render-updated uniform: the callback's return value is assigned (undefined keeps the value).
|
|
401
|
+
this.densityReference = uniform(params.densityReference ?? 1).onRenderUpdate(() => this.#readDensityReference());
|
|
402
|
+
const reference = this.#readDensityReference();
|
|
403
|
+
if (reference !== undefined)
|
|
404
|
+
this.densityReference.value = reference;
|
|
405
|
+
this.stepSize = uniform(params.stepSize ?? DEFAULTS.stepSize);
|
|
406
|
+
this.maxSteps = uniform(params.maxSteps ?? DEFAULTS.maxSteps);
|
|
407
|
+
this.sunDirection = uniform((params.sunDirection ?? new THREE.Vector3(0.5, 0.8, 0.3)).clone().normalize());
|
|
408
|
+
this.sunColor = uniform(params.sunColor ?? new THREE.Color(1, 0.95, 0.9));
|
|
409
|
+
this.sunIntensity = uniform(params.sunIntensity ?? DEFAULTS.sunIntensity);
|
|
410
|
+
this.anisotropy = uniform(params.anisotropy ?? DEFAULTS.anisotropy);
|
|
411
|
+
this.shadowSteps = uniform(params.shadowSteps ?? DEFAULTS.shadowSteps);
|
|
412
|
+
this.shadowDensity = uniform(params.shadowDensity ?? DEFAULTS.shadowDensity);
|
|
413
|
+
this.shadowReach = uniform(params.shadowReach ?? DEFAULTS.shadowReach);
|
|
414
|
+
this.ambient = uniform(params.ambient ?? DEFAULTS.ambient);
|
|
415
|
+
this.jitter = uniform(params.jitter === false ? 0 : 1);
|
|
416
|
+
const march = wgslFn(this.entrySource, [grids.module, code(VOLUME_HELPERS_WGSL)]);
|
|
417
|
+
this.fragmentNode = march({
|
|
418
|
+
grid_id: this.gridId,
|
|
419
|
+
ray_origin_w: cameraPosition,
|
|
420
|
+
ray_dir_w: positionWorld.sub(cameraPosition).normalize(),
|
|
421
|
+
sun_dir_w: this.sunDirection,
|
|
422
|
+
sun_color: this.sunColor,
|
|
423
|
+
sun_intensity: this.sunIntensity,
|
|
424
|
+
density_scale: this.densityScale,
|
|
425
|
+
optical_depth: this.opticalDepth,
|
|
426
|
+
density_reference: this.densityReference,
|
|
427
|
+
step_size: this.stepSize,
|
|
428
|
+
max_steps: this.maxSteps,
|
|
429
|
+
g: this.anisotropy,
|
|
430
|
+
shadow_steps: this.shadowSteps,
|
|
431
|
+
shadow_density: this.shadowDensity,
|
|
432
|
+
shadow_reach: this.shadowReach,
|
|
433
|
+
ambient: this.ambient,
|
|
434
|
+
jitter: this.jitter,
|
|
435
|
+
pix: screenCoordinate,
|
|
436
|
+
});
|
|
437
|
+
this.transparent = true;
|
|
438
|
+
this.depthWrite = false;
|
|
439
|
+
this.depthTest = true;
|
|
440
|
+
this.side = THREE.BackSide;
|
|
441
|
+
this.premultipliedAlpha = true;
|
|
442
|
+
this.toneMapped = false;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* The grid's `densityReference` when it must be (re)read: auto mode, a numeric id, a pool with `info`, and a
|
|
446
|
+
* pool revision or id other than the last read's. `undefined` keeps the uniform's value (a dead id too).
|
|
447
|
+
*/
|
|
448
|
+
#readDensityReference() {
|
|
449
|
+
if (!this.densityReferenceAuto)
|
|
450
|
+
return undefined;
|
|
451
|
+
const id = this.gridId.value;
|
|
452
|
+
const pool = this.grids.pool;
|
|
453
|
+
if (typeof id !== "number" || typeof pool.info !== "function")
|
|
454
|
+
return undefined;
|
|
455
|
+
const key = this.#referenceKey;
|
|
456
|
+
if (key && pool.revision !== undefined && key[0] === pool.revision && key[1] === id)
|
|
457
|
+
return undefined;
|
|
458
|
+
let average;
|
|
459
|
+
try {
|
|
460
|
+
average = pool.info(id).rootAverage;
|
|
461
|
+
}
|
|
462
|
+
catch {
|
|
463
|
+
return undefined; // the id is not in the pool (yet)
|
|
464
|
+
}
|
|
465
|
+
this.#referenceKey = [pool.revision, id];
|
|
466
|
+
return vdbVolumeDensityReference(average);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* A world-space box for a grid's proxy mesh (add it with an identity
|
|
471
|
+
* transform): the AABB of the index box's voxels `[min - pad, max + 1 + pad]`
|
|
472
|
+
* through the grid's index-to-world affine. `pad: 0` (default) is
|
|
473
|
+
* `pool.info(id).worldBBox`, the box v1 used; `pad: 1` also covers the
|
|
474
|
+
* min-side half voxel of the trilinear support that `VDBVolumeMaterial`
|
|
475
|
+
* marches (rays that cross only that shell are otherwise not rasterized).
|
|
476
|
+
*
|
|
477
|
+
* @param info The grid's `pool.info(id)`.
|
|
478
|
+
* @param options `pad`: voxels added on every side of the index box (default 0).
|
|
479
|
+
*/
|
|
480
|
+
export function vdbProxyGeometry(info, options = {}) {
|
|
481
|
+
const pad = options.pad ?? 0;
|
|
482
|
+
if (!Number.isFinite(pad) || pad < 0)
|
|
483
|
+
throw bad(`vdbProxyGeometry pad must be a finite number >= 0, got ${pad}.`);
|
|
484
|
+
const m = info.indexToWorld;
|
|
485
|
+
const lo = [0, 1, 2].map((a) => info.indexBBox.min[a] - pad);
|
|
486
|
+
const hi = [0, 1, 2].map((a) => info.indexBBox.max[a] + 1 + pad);
|
|
487
|
+
const box = new THREE.Box3();
|
|
488
|
+
const p = new THREE.Vector3();
|
|
489
|
+
for (let k = 0; k < 8; k++) {
|
|
490
|
+
const x = k & 1 ? hi[0] : lo[0];
|
|
491
|
+
const y = k & 2 ? hi[1] : lo[1];
|
|
492
|
+
const z = k & 4 ? hi[2] : lo[2];
|
|
493
|
+
p.set(m[0] * x + m[1] * y + m[2] * z + m[3], m[4] * x + m[5] * y + m[6] * z + m[7], m[8] * x + m[9] * y + m[10] * z + m[11]);
|
|
494
|
+
box.expandByPoint(p);
|
|
495
|
+
}
|
|
496
|
+
const size = box.getSize(new THREE.Vector3());
|
|
497
|
+
const center = box.getCenter(new THREE.Vector3());
|
|
498
|
+
const geometry = new THREE.BoxGeometry(size.x, size.y, size.z);
|
|
499
|
+
geometry.translate(center.x, center.y, center.z);
|
|
500
|
+
return geometry;
|
|
501
|
+
}
|
|
502
|
+
//# sourceMappingURL=material.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"material.js","sourceRoot":"","sources":["../../src/three/material.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,EAAE,gBAAgB,EAA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E,CAAE,CAC5C,CAAC;QACF,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IACD,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/D,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACjD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * `VDBVolumeMaterial`: the fragment raymarch of one grid in a `VDBGridPool`,\n * through a `VDBGridNode` (task K2.3, docs/archive/handoffs/K2.md). It replaces v1's\n * `NanoVDBVolumeMaterial`, which bound one grid image as its own storage\n * attribute and rewrote the vendored library's buffer global.\n *\n * const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });\n * const material = new VDBVolumeMaterial(renderer, grids, id);\n * scene.add(new Mesh(vdbProxyGeometry(pool.info(id)), material));\n * // per frame: pool.update(encoder) (or pool.flush()), then grids.update(), then render.\n *\n * The march is one entry `wgslFn` over the public `vdb*` WGSL API, with\n * `grids.module` as its include (the module carries the pool binding):\n * - the world ray goes into the grid's index space through the record's\n * affine (`vdbWorldToIndex`/`vdbWorldToIndexDir`), so `pool.setTransform`\n * instances render where they are;\n * - it is clipped to the sampler's support box (`vdbRayClipSupport`,\n * `[min - 1, max + 1]` for trilinear), not the voxel-cell box, so the\n * min-side half voxel the trilinear taps reach is marched too;\n * - fixed-step density accumulation with `vdbSample` (the node's sampler),\n * premultiplied front-to-back compositing, early-out at low transmittance.\n * The step lattice is anchored at the voxel-box entry (`vdbRayClip`, where\n * v1 started) and extended back over the support shell, so samples inside\n * the box sit where v1's did; only the shell samples are new (v1 skipped\n * that half voxel, which shows where a grid's min-side voxels are dense);\n * - lighting as in v1: Henyey-Greenstein phase on a directional sun, an\n * N-step shadow march toward the sun (a second accessor), a constant\n * ambient floor, and a per-fragment budget on the total samples;\n * - the look is sized to the grid by default (EX1a, DIVERGES V291): the\n * extinction is `opticalDepth` across the grid's longest index side at the\n * grid's mean density, and the shadow ray spans `shadowReach` of that side.\n * The side is read from the pool record per fragment (`vdbIndexMin` /\n * `vdbIndexMax`), so it follows a `gridId` change, a `pool.replace` and a\n * coarse-first swap; the mean (`densityReference`) is the root node's\n * average statistic, read from `pool.info(id)` at each render. An explicit\n * `densityScale` (> 0) is extinction per index voxel, as in 0.1.\n *\n * Rendered on a proxy box with `side: BackSide` (the camera can be inside);\n * entry and exit come from the analytic clip, not the rasterized faces. The\n * material is `transparent`, `depthWrite: false`, premultiplied alpha. Scene\n * depth compositing is not done (v1 neither).\n *\n * Every tunable is a live TSL uniform (`material.densityScale.value = ...`).\n * The grid is a `uint` uniform too when the constructor got a number\n * (`material.gridId.value = otherId`), so one material can show any grid of\n * the types its `VDBGridNode` compiles without a rebuild.\n *\n * Units and assumptions:\n * - The march runs in the grid's **index space**: `stepSize` is in index\n * voxels, `opticalDepth` is relative to the index box and `densityScale`\n * integrates per index voxel. Opacity therefore does not change with the\n * world size of the grid: `pool.setTransform` (or a NanoVDB map) that scales\n * the grid scales its footprint, not how opaque it looks.\n * - `densityReference` follows the grid: a sequence that replaces the grid\n * each frame is normalised per frame. Pass a number to pin it.\n * - The proxy mesh is not tied to the grid: after `material.gridId.value = id`\n * or `pool.setTransform(id, ...)`, build a new `vdbProxyGeometry(pool.info(id))`\n * for the mesh, or fragments outside the old box are never rasterized.\n * - The view ray is `positionWorld - cameraPosition`: a perspective camera.\n * An orthographic camera's rays are parallel and do not start at\n * `cameraPosition`, so it renders wrongly.\n */\n\nimport * as THREE from \"three\";\nimport { NodeMaterial } from \"three/webgpu\";\nimport { cameraPosition, code, positionWorld, screenCoordinate, uniform, wgslFn } from \"three/tsl\";\nimport { VDBError } from \"../core/errors.js\";\nimport { getDevice, type VDBThreeRendererLike } from \"./device.js\";\nimport { VDBGridNode, type VDBTslNode } from \"./grid-node.js\";\n\n/** Default hard caps of the compiled loops (the live uniforms clamp under them). */\nexport const VDB_VOLUME_MAX_STEPS_CAP = 1024;\n/** Default compiled cap on `shadowSteps`. */\nexport const VDB_VOLUME_SHADOW_STEPS_CAP = 128;\n/**\n * Default cap on the total samples (primary + shadow) one fragment takes.\n * `maxSteps` and `shadowSteps` are independent live uniforms, so their product\n * can reach `maxStepsCap * shadowStepsCap` (~131k at the defaults), a driver\n * timeout risk. Once the budget is spent the shadow loop stops first, then the\n * primary loop, and the fragment returns its partial march.\n */\nexport const VDB_VOLUME_SAMPLE_BUDGET_CAP = 16384;\n\n/** Parameters of {@link VDBVolumeMaterial}: initial uniform values and compile-time caps. */\nexport interface VDBVolumeMaterialParameters {\n /**\n * Extinction per index voxel at density 1. Default 0: the material uses {@link opticalDepth} instead, which\n * suits a grid of any resolution. A value > 0 is used as given (0.1's meaning; 0.1's default was 40).\n */\n densityScale?: number;\n /**\n * Optical depth of a ray that crosses the grid's longest index side at the density `densityReference`, used\n * while `densityScale` is 0: the extinction per index voxel at density 1 is\n * `opticalDepth / (longest side * densityReference)`. Default 6.\n */\n opticalDepth?: number;\n /**\n * The density `opticalDepth` refers to. Default: the mean of the grid's active values (the root node's average\n * statistic, `pool.info(id).rootAverage`), read again at each render, so the default look does not depend on\n * the grid's resolution or value range; 1 for a grid without statistics. A number pins it: for a sequence whose\n * frames should share one scale, or 1 to make `opticalDepth` refer to density 1.\n */\n densityReference?: number;\n /** March step in index voxels. */\n stepSize?: number;\n /** Primary march steps (live, clamped to `maxStepsCap`). Default 512. */\n maxSteps?: number;\n /** Direction toward the sun in world space; normalized at construction. */\n sunDirection?: THREE.Vector3;\n /** Sun colour (linear). Default (1, 0.95, 0.9). */\n sunColor?: THREE.Color;\n /**\n * Sun intensity: the sun term is `sunColor * sunIntensity * phase * shadow`, and a phase function integrates to\n * 1 over the sphere (1 / 4π ≈ 0.08 for isotropic scattering), so 4π lights an unshadowed isotropic sample with\n * `sunColor`. Default 16 (0.1's was 3).\n */\n sunIntensity?: number;\n /** Henyey-Greenstein anisotropy g in (-1, 1). */\n anisotropy?: number;\n /** Shadow-ray steps per lit sample (live, clamped to `shadowStepsCap`). Default 12. */\n shadowSteps?: number;\n /** Density multiplier along the shadow ray only. */\n shadowDensity?: number;\n /**\n * Length of the shadow ray as a fraction of the grid's longest index side: `shadowSteps` steps of\n * `shadowReach * longest side / shadowSteps` voxels, sampled at their midpoints. Default 0.3. 0 steps the\n * shadow ray by `stepSize` (0.1's march: `shadowSteps * stepSize` voxels).\n */\n shadowReach?: number;\n /** Constant ambient term added to the sun light. Default 0.15. */\n ambient?: number;\n /** Per-pixel jitter of the first sample. Default true. */\n jitter?: boolean;\n /** Hard cap on the primary loop. Default {@link VDB_VOLUME_MAX_STEPS_CAP}. */\n maxStepsCap?: number;\n /** Hard cap on the shadow loop. Default {@link VDB_VOLUME_SHADOW_STEPS_CAP}. */\n shadowStepsCap?: number;\n /** Hard cap on the total samples per fragment. Default {@link VDB_VOLUME_SAMPLE_BUDGET_CAP}. */\n sampleBudgetCap?: number;\n}\n\n/** Default `opticalDepth`: the optical depth across the grid's longest index side at its mean density (EX1a). */\nexport const VDB_VOLUME_OPTICAL_DEPTH = 6;\n/** Default `shadowReach`: the shadow ray spans this fraction of the grid's longest index side (EX1a). */\nexport const VDB_VOLUME_SHADOW_REACH = 0.3;\n/** Default `sunIntensity` (EX1a): about 4π × 1.25, so the sun reads against the ambient term (a phase is about 1 / 4π). */\nexport const VDB_VOLUME_SUN_INTENSITY = 16;\n\nconst DEFAULTS = {\n densityScale: 0,\n opticalDepth: VDB_VOLUME_OPTICAL_DEPTH,\n stepSize: 0.75,\n maxSteps: 512,\n sunIntensity: VDB_VOLUME_SUN_INTENSITY,\n anisotropy: 0.3,\n shadowSteps: 12,\n shadowDensity: 1,\n shadowReach: VDB_VOLUME_SHADOW_REACH,\n ambient: 0.15,\n} as const;\n\n/** The smallest `densityReference` the march divides by. */\nexport const VDB_VOLUME_MIN_REFERENCE = 1e-20;\n\n/**\n * The `densityReference` of a grid: its root average statistic when the image has one above 0, else 1 (no\n * statistics, an empty grid, or a grid of non-positive values).\n *\n * @param rootAverage `pool.info(id).rootAverage`.\n */\nexport function vdbVolumeDensityReference(rootAverage: number | undefined): number {\n return typeof rootAverage === \"number\" && Number.isFinite(rootAverage) && rootAverage > 0 ? rootAverage : 1;\n}\n\n/** What {@link vdbVolumeMarchScales} reads: the uniform values of a `VDBVolumeMaterial`. */\nexport interface VDBVolumeMarchScaleInputs {\n densityScale: number;\n opticalDepth: number;\n /** The density `opticalDepth` refers to. Default 1. */\n densityReference?: number;\n stepSize: number;\n shadowSteps: number;\n shadowReach: number;\n /** Compiled cap on `shadowSteps`. Default {@link VDB_VOLUME_SHADOW_STEPS_CAP}. */\n shadowStepsCap?: number;\n}\n\n/** What the march derives from the grid's size. */\nexport interface VDBVolumeMarchScales {\n /** Extinction per index voxel at density 1. */\n extinction: number;\n /** Shadow-ray step, in index voxels. */\n shadowStep: number;\n /** Distance of the first shadow sample from the lit sample, in index voxels. */\n shadowStart: number;\n}\n\n/**\n * The CPU twin of the scale lines of the march entry (EX1a): what `VDBVolumeMaterial` derives from the grid's\n * longest index side. `densityScale > 0` is the extinction as given, else\n * `opticalDepth / (longest * densityReference)`;\n * `shadowReach > 0` spreads the shadow steps over that fraction of the side (midpoint samples), else they step\n * by `stepSize` (0.1's march).\n *\n * @param longest The grid's longest index side in voxels (`max(indexBBox.max - indexBBox.min) + 1`).\n * @param u The material's uniform values.\n */\nexport function vdbVolumeMarchScales(longest: number, u: VDBVolumeMarchScaleInputs): VDBVolumeMarchScales {\n const side = Math.max(longest, 1);\n const extinction = u.densityScale > 0 ? u.densityScale : u.opticalDepth / (side * Math.max(u.densityReference ?? 1, VDB_VOLUME_MIN_REFERENCE));\n const steps = Math.trunc(Math.min(Math.max(u.shadowSteps, 0), u.shadowStepsCap ?? VDB_VOLUME_SHADOW_STEPS_CAP));\n if (u.shadowReach > 0) {\n const shadowStep = (u.shadowReach * side) / Math.max(steps, 1);\n return { extinction, shadowStep, shadowStart: shadowStep * 0.5 };\n }\n return { extinction, shadowStep: u.stepSize, shadowStart: u.stepSize };\n}\n\n/** A live TSL uniform with its value typed (three types `uniform()`'s value as unknown). */\ntype ScalarUniform = ReturnType<typeof uniform> & { value: number };\ntype Vec3Uniform = ReturnType<typeof uniform> & { value: THREE.Vector3 };\ntype ColorUniform = ReturnType<typeof uniform> & { value: THREE.Color };\n/** The `uint` uniform `VDBVolumeMaterial` makes for a numeric grid id (`material.gridId.value = otherId`). */\nexport type VDBUintUniform = ReturnType<typeof uniform> & { value: number };\n\n/** Entry name of the march `wgslFn`. */\nconst ENTRY = \"vdbThreeVolumeMarch\";\n\n/**\n * Module-scope helpers of the march, a second include next to `grids.module`\n * (`wgslFn` parses only its first `fn`, so the entry can't hold them).\n */\nconst VOLUME_HELPERS_WGSL = /* wgsl */ `\nfn vdbThreeHgPhase(cos_theta: f32, g: f32) -> f32 {\n let gg = g * g;\n let denom = 1.0 + gg - 2.0 * g * cos_theta;\n return (1.0 - gg) / (12.566370614359172 * pow(max(denom, 1.0e-4), 1.5));\n}\nfn vdbThreeHash12(p: vec2f) -> f32 {\n var p3 = fract(vec3f(p.x, p.y, p.x) * 0.1031);\n p3 = p3 + dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n}\n`;\n\n/** The march entry, the one `fn` of its `wgslFn`. Caps are compiled in. */\nfunction marchWgsl(maxStepsCap: number, shadowStepsCap: number, sampleBudgetCap: number): string {\n return /* wgsl */ `fn ${ENTRY}(\n grid_id: u32,\n ray_origin_w: vec3f,\n ray_dir_w: vec3f,\n sun_dir_w: vec3f,\n sun_color: vec3f,\n sun_intensity: f32,\n density_scale: f32,\n optical_depth: f32,\n density_reference: f32,\n step_size: f32,\n max_steps: f32,\n g: f32,\n shadow_steps: f32,\n shadow_density: f32,\n shadow_reach: f32,\n ambient: f32,\n jitter: f32,\n pix: vec2f\n) -> vec4f {\n // World -> index through the pool record (instance transform included).\n let o_idx = vdbWorldToIndex(grid_id, ray_origin_w);\n let d_idx = normalize(vdbWorldToIndexDir(grid_id, ray_dir_w));\n let sun_idx = normalize(vdbWorldToIndexDir(grid_id, sun_dir_w));\n\n // Clip to the trilinear support box; a dead id misses.\n var span = vec2f(0.0, 1.0e30);\n if !vdbRayClipSupport(grid_id, o_idx, d_idx, &span) {\n return vec4f(0.0);\n }\n // t0 >= 0: no sample behind the eye (camera inside the support box).\n let t0 = max(span.x, 0.0);\n let t1 = span.y;\n\n var acc = vdbAccessorInit(grid_id);\n var sacc = vdbAccessorInit(grid_id);\n\n // The phase uses the world-space view/sun angle.\n let phase = vdbThreeHgPhase(dot(normalize(ray_dir_w), normalize(sun_dir_w)), g);\n\n // The step lattice is anchored where the ray enters the voxel box\n // (vdbRayClip, v1's entry) and extended back to the support entry, so the\n // samples inside the box sit exactly where v1's did.\n var t = t0;\n var cell = vec2f(0.0, 1.0e30);\n if vdbRayClip(grid_id, o_idx, d_idx, &cell) {\n let anchor = max(cell.x, 0.0);\n t = anchor - ceil((anchor - t0) / step_size) * step_size;\n }\n t += step_size * jitter * vdbThreeHash12(pix);\n // The lattice can start before t0 (the anchor is stepped back in whole\n // steps, plus jitter). Skip those steps on the lattice: they are behind the\n // eye (camera in the support shell) or outside the support box.\n if t < t0 {\n t += ceil((t0 - t) / step_size) * step_size;\n }\n var transmittance = 1.0;\n var color = vec3f(0.0);\n let max_i = i32(clamp(max_steps, 1.0, ${maxStepsCap}.0));\n let shadow_n = i32(clamp(shadow_steps, 0.0, ${shadowStepsCap}.0));\n\n // What the look takes from the grid's size (CPU twin: vdbVolumeMarchScales). The extinction per index voxel\n // is the explicit scale as given, else the optical depth across the longest index side at the reference\n // density; the shadow ray steps by the march step, or spans the reach fraction of the side (midpoint samples).\n let dims = vec3f(vdbIndexMax(grid_id) - vdbIndexMin(grid_id) + vec3i(1));\n let longest = max(max(dims.x, max(dims.y, dims.z)), 1.0);\n var extinction = density_scale;\n if !(extinction > 0.0) {\n extinction = optical_depth / (longest * max(density_reference, 1.0e-20));\n }\n var shadow_step = step_size;\n var shadow_start = step_size;\n if shadow_reach > 0.0 {\n shadow_step = shadow_reach * longest / f32(max(shadow_n, 1));\n shadow_start = shadow_step * 0.5;\n }\n let budget = ${sampleBudgetCap};\n var samples = 0;\n\n for (var i = 0; i < max_i; i++) {\n if t > t1 || transmittance < 0.003 || samples >= budget {\n break;\n }\n let pos = o_idx + d_idx * t;\n let density = max(vdbSample(&acc, pos), 0.0) * extinction;\n samples++;\n if density > 0.0 {\n let a = 1.0 - exp(-density * step_size);\n var tau = 0.0;\n var st = shadow_start;\n for (var s = 0; s < shadow_n; s++) {\n if samples >= budget {\n break;\n }\n let sd = max(vdbSample(&sacc, pos + sun_idx * st), 0.0) * extinction * shadow_density;\n samples++;\n tau += sd * shadow_step;\n st += shadow_step;\n }\n let lit = sun_color * (sun_intensity * exp(-tau) * phase) + vec3f(ambient);\n color += transmittance * a * lit;\n transmittance *= 1.0 - a;\n }\n t += step_size;\n }\n return vec4f(color, 1.0 - transmittance);\n}`;\n}\n\nfunction bad(message: string): VDBError {\n return new VDBError(\"VDB_BAD_OPTION\", `VDBVolumeMaterial: ${message}`);\n}\n\nfunction positiveInt(name: string, value: number | undefined, fallback: number): number {\n const v = value ?? fallback;\n if (!Number.isInteger(v) || v < 1) throw bad(`${name} must be an integer >= 1, got ${JSON.stringify(value)}.`);\n return v;\n}\n\n/**\n * A fragment raymarch of one grid of a `VDBGridPool` (see the file comment for\n * the march). Put it on a `vdbProxyGeometry(pool.info(id))` mesh; each frame\n * run `pool.update(encoder)` (or `pool.flush()`), then `grids.update()`, then\n * render.\n *\n * const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });\n * const material = new VDBVolumeMaterial(renderer, grids, id);\n * const mesh = new Mesh(vdbProxyGeometry(pool.info(id)), material);\n *\n * - The defaults are sized to the grid: `opticalDepth` (6) is the optical\n * depth across the grid's longest index side at its mean density\n * (`densityReference`), and the shadow ray spans `shadowReach` (0.3) of\n * that side, so a grid of any resolution and value range draws as a lit\n * volume. `densityScale` > 0 replaces them with an extinction per index\n * voxel; 0.1's look is `{ densityScale: 40, sunIntensity: 3, shadowReach: 0 }`.\n * - `stepSize` is in index voxels and the density integrates in index\n * space, so opacity ignores the grid's world scale (`setTransform` scaling\n * changes the size on screen, not the opacity).\n * - After `gridId.value = otherId` or `pool.setTransform(id, ...)`, give the\n * mesh a new `vdbProxyGeometry(pool.info(id))`.\n * - Perspective cameras only (the ray starts at `cameraPosition`).\n * - The material must be rendered by the renderer `grids` was made with.\n *\n * @typeParam TGridId What the constructor got as the id: a number (default)\n * makes {@link gridId} a `uint` uniform; a node is kept as given.\n */\nexport class VDBVolumeMaterial<TGridId extends number | VDBTslNode = number> extends NodeMaterial {\n /** Type flag: true. */\n readonly isVDBVolumeMaterial = true;\n\n /** The pool node this material reads (its `module` is the march's include). */\n readonly grids: VDBGridNode;\n /**\n * The grid id: a `uint` uniform when the constructor got a number\n * (`material.gridId.value = otherId`; then give the mesh a new\n * `vdbProxyGeometry`), else the caller's node.\n */\n readonly gridId: TGridId extends number ? VDBUintUniform : VDBTslNode;\n /** The entry `fn` text (for inspection and tests). */\n readonly entrySource: string;\n\n /**\n * Extinction per index voxel at density 1 (opacity of a step: `1 - exp(-density * densityScale * stepSize)`).\n * Default 0: the extinction comes from `opticalDepth` instead. To hide the volume, hide its mesh.\n */\n readonly densityScale: ScalarUniform;\n /**\n * Optical depth across the grid's longest index side at the density `densityReference`, used while\n * `densityScale` is 0. It follows the grid (a `gridId` change, a coarse-first swap). Default 6.\n */\n readonly opticalDepth: ScalarUniform;\n /**\n * The density `opticalDepth` refers to. While {@link densityReferenceAuto} is true it is set at each render\n * to the mean of the grid's active values (`pool.info(id).rootAverage`; 1 without statistics).\n */\n readonly densityReference: ScalarUniform;\n /**\n * True (the default, unless the constructor got a `densityReference`) while the material reads\n * `densityReference` from the pool at each render. It needs a numeric grid id and a pool with `info(id)`\n * (a `VDBGridPool`); otherwise the uniform keeps its value.\n */\n densityReferenceAuto: boolean;\n /** The pool revision and grid id `densityReference` was last read for. */\n #referenceKey: readonly [unknown, unknown] | null = null;\n /** March step in index voxels (live; the lattice re-anchors per fragment). Default 0.75. */\n readonly stepSize: ScalarUniform;\n /** Primary march steps, clamped to `[1, maxStepsCap]`. Default 512. */\n readonly maxSteps: ScalarUniform;\n /** Direction toward the sun, world space (normalized at construction; keep it normalized). */\n readonly sunDirection: Vec3Uniform;\n /** Sun colour (linear). Default (1, 0.95, 0.9). */\n readonly sunColor: ColorUniform;\n /** Sun intensity; the sun term is `sunColor * sunIntensity * phase * shadow` (phase ≈ 1 / 4π). Default 16. */\n readonly sunIntensity: ScalarUniform;\n /** Henyey-Greenstein anisotropy g in (-1, 1). Default 0.3. */\n readonly anisotropy: ScalarUniform;\n /** Shadow-ray steps toward the sun per lit sample, clamped to `[0, shadowStepsCap]`. Default 12. */\n readonly shadowSteps: ScalarUniform;\n /** Density multiplier along the shadow ray only. Default 1. */\n readonly shadowDensity: ScalarUniform;\n /**\n * Length of the shadow ray as a fraction of the grid's longest index side. Default 0.3. 0 steps the shadow\n * ray by `stepSize` (`shadowSteps * stepSize` voxels, 0.1's march).\n */\n readonly shadowReach: ScalarUniform;\n /** Constant ambient term added to the sun light. Default 0.15. */\n readonly ambient: ScalarUniform;\n /** 1 = per-pixel jitter of the first sample on, 0 = off. */\n readonly jitter: ScalarUniform;\n\n /**\n *\n * @param params Initial uniform values and compile-time caps ({@link VDBVolumeMaterialParameters}).\n *\n * @param renderer The initialized `WebGPURenderer` the pool and `grids` live on.\n * @param grids A `VDBGridNode` made on this same renderer, with profile\n * `sample` or `march` and `helpers: ['rayClipSupport']`. Share one per\n * pool: one module per shader.\n * @param gridId The grid's pool id (a number, made a `uint` uniform) or a `uint` node.\n * @throws VDBError `VDB_BAD_OPTION` for a `grids` this material can't use\n * (another renderer, profile, helpers), a bad id or cap;\n * `VDB_UNSUPPORTED_DEVICE` for an uninitialized renderer.\n */\n constructor(renderer: VDBThreeRendererLike, grids: VDBGridNode, gridId: TGridId, params: VDBVolumeMaterialParameters = {}) {\n super();\n if (!(grids instanceof VDBGridNode)) throw bad(\"grids must be a VDBGridNode.\");\n getDevice(renderer); // VDB_UNSUPPORTED_DEVICE before init\n if (grids.renderer !== renderer) {\n throw bad(\n \"grids was made for another renderer. A VDBGridNode binds the pool through the renderer it was made with \" +\n \"(another renderer, even on the same GPUDevice, would read 0): create one VDBGridNode per renderer \" +\n \"(new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] })).\",\n );\n }\n if (grids.options.profile === \"read\") {\n throw bad(\"grids needs profile 'sample' or 'march' (vdbSample); this VDBGridNode was made with profile 'read'.\");\n }\n if (!grids.options.helpers?.includes(\"rayClipSupport\")) {\n throw bad(\"grids must compile the 'rayClipSupport' helper: new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] }).\");\n }\n if (typeof gridId === \"number\") {\n if (!Number.isInteger(gridId) || gridId < 0) throw bad(`gridId must be a non-negative integer, got ${gridId}.`);\n } else if (gridId === null || typeof gridId !== \"object\") {\n throw bad(\"gridId must be a number or a uint TSL node.\");\n }\n const maxStepsCap = positiveInt(\"maxStepsCap\", params.maxStepsCap, VDB_VOLUME_MAX_STEPS_CAP);\n const shadowStepsCap = positiveInt(\"shadowStepsCap\", params.shadowStepsCap, VDB_VOLUME_SHADOW_STEPS_CAP);\n const sampleBudgetCap = positiveInt(\"sampleBudgetCap\", params.sampleBudgetCap, VDB_VOLUME_SAMPLE_BUDGET_CAP);\n\n this.grids = grids;\n this.gridId = (typeof gridId === \"number\" ? uniform(gridId, \"uint\") : gridId) as this[\"gridId\"];\n this.entrySource = marchWgsl(maxStepsCap, shadowStepsCap, sampleBudgetCap);\n\n this.densityScale = uniform(params.densityScale ?? DEFAULTS.densityScale) as ScalarUniform;\n this.opticalDepth = uniform(params.opticalDepth ?? DEFAULTS.opticalDepth) as ScalarUniform;\n this.densityReferenceAuto = params.densityReference === undefined;\n // A render-updated uniform: the callback's return value is assigned (undefined keeps the value).\n this.densityReference = (\n uniform(params.densityReference ?? 1) as ScalarUniform & { onRenderUpdate(callback: () => number | undefined): ScalarUniform }\n ).onRenderUpdate(() => this.#readDensityReference());\n const reference = this.#readDensityReference();\n if (reference !== undefined) this.densityReference.value = reference;\n this.stepSize = uniform(params.stepSize ?? DEFAULTS.stepSize) as ScalarUniform;\n this.maxSteps = uniform(params.maxSteps ?? DEFAULTS.maxSteps) as ScalarUniform;\n this.sunDirection = uniform((params.sunDirection ?? new THREE.Vector3(0.5, 0.8, 0.3)).clone().normalize()) as Vec3Uniform;\n this.sunColor = uniform(params.sunColor ?? new THREE.Color(1, 0.95, 0.9)) as ColorUniform;\n this.sunIntensity = uniform(params.sunIntensity ?? DEFAULTS.sunIntensity) as ScalarUniform;\n this.anisotropy = uniform(params.anisotropy ?? DEFAULTS.anisotropy) as ScalarUniform;\n this.shadowSteps = uniform(params.shadowSteps ?? DEFAULTS.shadowSteps) as ScalarUniform;\n this.shadowDensity = uniform(params.shadowDensity ?? DEFAULTS.shadowDensity) as ScalarUniform;\n this.shadowReach = uniform(params.shadowReach ?? DEFAULTS.shadowReach) as ScalarUniform;\n this.ambient = uniform(params.ambient ?? DEFAULTS.ambient) as ScalarUniform;\n this.jitter = uniform(params.jitter === false ? 0 : 1) as ScalarUniform;\n\n const march = wgslFn(this.entrySource, [grids.module, code(VOLUME_HELPERS_WGSL)] as never);\n this.fragmentNode = march({\n grid_id: this.gridId,\n ray_origin_w: cameraPosition,\n ray_dir_w: positionWorld.sub(cameraPosition).normalize(),\n sun_dir_w: this.sunDirection,\n sun_color: this.sunColor,\n sun_intensity: this.sunIntensity,\n density_scale: this.densityScale,\n optical_depth: this.opticalDepth,\n density_reference: this.densityReference,\n step_size: this.stepSize,\n max_steps: this.maxSteps,\n g: this.anisotropy,\n shadow_steps: this.shadowSteps,\n shadow_density: this.shadowDensity,\n shadow_reach: this.shadowReach,\n ambient: this.ambient,\n jitter: this.jitter,\n pix: screenCoordinate,\n });\n\n this.transparent = true;\n this.depthWrite = false;\n this.depthTest = true;\n this.side = THREE.BackSide;\n this.premultipliedAlpha = true;\n this.toneMapped = false;\n }\n\n /**\n * The grid's `densityReference` when it must be (re)read: auto mode, a numeric id, a pool with `info`, and a\n * pool revision or id other than the last read's. `undefined` keeps the uniform's value (a dead id too).\n */\n #readDensityReference(): number | undefined {\n if (!this.densityReferenceAuto) return undefined;\n const id = (this.gridId as { value?: unknown }).value;\n const pool = this.grids.pool as { info?: (id: number) => { rootAverage?: number }; revision?: unknown };\n if (typeof id !== \"number\" || typeof pool.info !== \"function\") return undefined;\n const key = this.#referenceKey;\n if (key && pool.revision !== undefined && key[0] === pool.revision && key[1] === id) return undefined;\n let average: number | undefined;\n try {\n average = pool.info(id).rootAverage;\n } catch {\n return undefined; // the id is not in the pool (yet)\n }\n this.#referenceKey = [pool.revision, id];\n return vdbVolumeDensityReference(average);\n }\n}\n\n/** What {@link vdbProxyGeometry} reads from `pool.info(id)`. */\nexport interface VDBProxyGridInfo {\n /** Inclusive index-space box of the active voxels (`pool.info(id).indexBBox`). */\n readonly indexBBox: { readonly min: readonly number[]; readonly max: readonly number[] };\n /** 3x4 row-major index-to-world affine (`pool.info(id).indexToWorld`). */\n readonly indexToWorld: ArrayLike<number>;\n}\n\n/**\n * A world-space box for a grid's proxy mesh (add it with an identity\n * transform): the AABB of the index box's voxels `[min - pad, max + 1 + pad]`\n * through the grid's index-to-world affine. `pad: 0` (default) is\n * `pool.info(id).worldBBox`, the box v1 used; `pad: 1` also covers the\n * min-side half voxel of the trilinear support that `VDBVolumeMaterial`\n * marches (rays that cross only that shell are otherwise not rasterized).\n *\n * @param info The grid's `pool.info(id)`.\n * @param options `pad`: voxels added on every side of the index box (default 0).\n */\nexport function vdbProxyGeometry(info: VDBProxyGridInfo, options: { pad?: number } = {}): THREE.BoxGeometry {\n const pad = options.pad ?? 0;\n if (!Number.isFinite(pad) || pad < 0) throw bad(`vdbProxyGeometry pad must be a finite number >= 0, got ${pad}.`);\n const m = info.indexToWorld;\n const lo = [0, 1, 2].map((a) => info.indexBBox.min[a]! - pad);\n const hi = [0, 1, 2].map((a) => info.indexBBox.max[a]! + 1 + pad);\n const box = new THREE.Box3();\n const p = new THREE.Vector3();\n for (let k = 0; k < 8; k++) {\n const x = k & 1 ? hi[0]! : lo[0]!;\n const y = k & 2 ? hi[1]! : lo[1]!;\n const z = k & 4 ? hi[2]! : lo[2]!;\n p.set(\n m[0]! * x + m[1]! * y + m[2]! * z + m[3]!,\n m[4]! * x + m[5]! * y + m[6]! * z + m[7]!,\n m[8]! * x + m[9]! * y + m[10]! * z + m[11]!,\n );\n box.expandByPoint(p);\n }\n const size = box.getSize(new THREE.Vector3());\n const center = box.getCenter(new THREE.Vector3());\n const geometry = new THREE.BoxGeometry(size.x, size.y, size.z);\n geometry.translate(center.x, center.y, center.z);\n return geometry;\n}\n"]}
|