@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,272 @@
|
|
|
1
|
+
// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
|
|
2
|
+
// src/three-openvdb/frame/core/frameEnvironment.js (all, 331 lines).
|
|
3
|
+
// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
|
|
4
|
+
// Changes: TypeScript; `isFrameDiffusion` inlined (tools does not import the three adapter);
|
|
5
|
+
// the readback promise may also resolve to a Uint16Array of half floats (decoded here). Same
|
|
6
|
+
// directions, cells, colours and SH quadrature. Divergences: DIVERGES.md (K3.3 rows).
|
|
7
|
+
/**
|
|
8
|
+
* Multi-directional environment light (Disney "Deep Scattering", §4.4 and §7), engine-free (K3.3):
|
|
9
|
+
* the scene environment is read once into a small lat-long map (64 × 32, PMREM roughness 0.4); the
|
|
10
|
+
* CPU turns it into ≤ 12 directional lights. `'directional'`: the brightest texel plus fixed sky
|
|
11
|
+
* directions (zenith, nadir, a horizon ring; opposite pairs with diffusion), each texel to its
|
|
12
|
+
* nearest seed, a light at the energy centroid with energy / 4. `'spherical-harmonics'`: SH L1/L2
|
|
13
|
+
* projection evaluated at quadrature directions. The three adapter draws the map and passes the
|
|
14
|
+
* readback through `extract`.
|
|
15
|
+
*/
|
|
16
|
+
export const frameMaxEnvironmentLights = 12;
|
|
17
|
+
export const frameMaxEnvironmentSamples = 8;
|
|
18
|
+
export const frameEnvironmentMapWidth = 64;
|
|
19
|
+
export const frameEnvironmentMapHeight = 32;
|
|
20
|
+
/** PMREM blur of the map: a small sun covers more than one texel and is not lost between texels. */
|
|
21
|
+
export const frameEnvironmentMapRoughness = 0.4;
|
|
22
|
+
export const frameEnvironmentModes = {
|
|
23
|
+
outward: "outward",
|
|
24
|
+
directional: "directional",
|
|
25
|
+
sphericalHarmonics: "spherical-harmonics",
|
|
26
|
+
};
|
|
27
|
+
// NOTE Retry an empty map (environment or PMREM not ready) after this number of updates
|
|
28
|
+
const retryInterval = 30;
|
|
29
|
+
const normalize = (x, y, z) => {
|
|
30
|
+
const length = Math.hypot(x, y, z) || 1.0;
|
|
31
|
+
return [x / length, y / length, z / length];
|
|
32
|
+
};
|
|
33
|
+
/** His `isFrameDiffusion` (three `frame/phase.ts`): true, 'two-sided' and 'neural'. */
|
|
34
|
+
const isDiffusion = (mode) => !!mode && mode !== "octaves";
|
|
35
|
+
/** The same direction as the map shaders. u and v are 0 to 1; v = 0 is +Y. */
|
|
36
|
+
export const vdbFrameEnvironmentMapDirection = (u, v) => {
|
|
37
|
+
const phi = u * 2.0 * Math.PI;
|
|
38
|
+
const theta = v * Math.PI;
|
|
39
|
+
return [Math.sin(theta) * Math.cos(phi), Math.cos(theta), Math.sin(theta) * Math.sin(phi)];
|
|
40
|
+
};
|
|
41
|
+
// NOTE Real SH basis, bands 0 to 2. Same constants as three.js SphericalHarmonics3.
|
|
42
|
+
const getShBasis = ([x, y, z], count) => [0.282095, 0.488603 * y, 0.488603 * z, 0.488603 * x, 1.092548 * x * y, 1.092548 * y * z, 0.315392 * (3.0 * z * z - 1.0), 1.092548 * x * z, 0.546274 * (x * x - y * y)].slice(0, count);
|
|
43
|
+
// NOTE Quadrature directions. Octahedron (spherical 3-design) for L1, icosahedron (5-design) for L2.
|
|
44
|
+
const goldenRatio = (1.0 + Math.sqrt(5.0)) / 2.0;
|
|
45
|
+
const octahedron = [
|
|
46
|
+
[1, 0, 0],
|
|
47
|
+
[-1, 0, 0],
|
|
48
|
+
[0, 1, 0],
|
|
49
|
+
[0, -1, 0],
|
|
50
|
+
[0, 0, 1],
|
|
51
|
+
[0, 0, -1],
|
|
52
|
+
];
|
|
53
|
+
const icosahedron = [
|
|
54
|
+
[0, 1, goldenRatio],
|
|
55
|
+
[0, -1, goldenRatio],
|
|
56
|
+
[0, 1, -goldenRatio],
|
|
57
|
+
[0, -1, -goldenRatio],
|
|
58
|
+
[1, goldenRatio, 0],
|
|
59
|
+
[-1, goldenRatio, 0],
|
|
60
|
+
[1, -goldenRatio, 0],
|
|
61
|
+
[-1, -goldenRatio, 0],
|
|
62
|
+
[goldenRatio, 0, 1],
|
|
63
|
+
[-goldenRatio, 0, 1],
|
|
64
|
+
[goldenRatio, 0, -1],
|
|
65
|
+
[-goldenRatio, 0, -1],
|
|
66
|
+
].map(([x, y, z]) => normalize(x, y, z));
|
|
67
|
+
const luminance = (r, g, b) => 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
68
|
+
export const vdbFrameEnvironmentMode = (settings) => {
|
|
69
|
+
const mode = settings.environmentLighting;
|
|
70
|
+
return mode === frameEnvironmentModes.directional || mode === frameEnvironmentModes.sphericalHarmonics ? mode : frameEnvironmentModes.outward;
|
|
71
|
+
};
|
|
72
|
+
const halfToFloat = (h) => {
|
|
73
|
+
const s = h & 0x8000 ? -1 : 1;
|
|
74
|
+
const e = (h >> 10) & 0x1f;
|
|
75
|
+
const f = h & 0x3ff;
|
|
76
|
+
if (e === 0)
|
|
77
|
+
return s * Math.pow(2, -14) * (f / 1024);
|
|
78
|
+
if (e === 31)
|
|
79
|
+
return f ? NaN : s * Infinity;
|
|
80
|
+
return s * Math.pow(2, e - 15) * (1 + f / 1024);
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* His `FrameEnvironmentLights`: holds the lat-long map of the scene environment and the lights made
|
|
84
|
+
* from it. `extract(renderer, scene)` is the engine part: it draws the map (RGB radiance, A the
|
|
85
|
+
* texel's v, so the readback row order does not matter) and resolves RGBA floats.
|
|
86
|
+
*/
|
|
87
|
+
export class VDBFrameEnvironmentLights {
|
|
88
|
+
extract;
|
|
89
|
+
key = null;
|
|
90
|
+
pending = false;
|
|
91
|
+
retryAt = 0;
|
|
92
|
+
updates = 0;
|
|
93
|
+
texels = null;
|
|
94
|
+
texelsVersion = 0;
|
|
95
|
+
warned = false;
|
|
96
|
+
lightsKey = null;
|
|
97
|
+
lights = [];
|
|
98
|
+
result = {
|
|
99
|
+
mode: frameEnvironmentModes.outward,
|
|
100
|
+
count: 0,
|
|
101
|
+
directions: Array.from({ length: frameMaxEnvironmentLights }, () => [0.0, 1.0, 0.0]),
|
|
102
|
+
colors: Array.from({ length: frameMaxEnvironmentLights }, () => [0.0, 0.0, 0.0]),
|
|
103
|
+
};
|
|
104
|
+
constructor(extract) {
|
|
105
|
+
this.extract = extract;
|
|
106
|
+
}
|
|
107
|
+
getKey(scene) {
|
|
108
|
+
const { environment, environmentRotation: rotation } = scene;
|
|
109
|
+
return `${environment.uuid}:${environment.version}:${rotation.x}:${rotation.y}:${rotation.z}:${rotation.order}`;
|
|
110
|
+
}
|
|
111
|
+
/** Null when the 'outward' path must be used: another mode, no environment, or no map yet. */
|
|
112
|
+
update(renderer, scene, settings) {
|
|
113
|
+
const mode = vdbFrameEnvironmentMode(settings);
|
|
114
|
+
this.updates++;
|
|
115
|
+
if (mode === frameEnvironmentModes.outward || !scene.environment)
|
|
116
|
+
return null;
|
|
117
|
+
const key = this.getKey(scene);
|
|
118
|
+
if (key !== this.key && !this.pending && this.updates >= this.retryAt)
|
|
119
|
+
this.requestMap(renderer, scene, key);
|
|
120
|
+
if (!this.texels)
|
|
121
|
+
return null;
|
|
122
|
+
// NOTE Diffusion multiple scattering needs the directions in opposite pairs (getDirectionalLights)
|
|
123
|
+
const pairs = isDiffusion(settings.multipleScattering);
|
|
124
|
+
const lightsKey = `${mode}:${settings.environmentSamples}:${settings.environmentShOrder}:${this.texelsVersion}:${pairs}`;
|
|
125
|
+
if (lightsKey !== this.lightsKey) {
|
|
126
|
+
this.lights = mode === frameEnvironmentModes.directional ? this.getDirectionalLights(settings.environmentSamples, pairs) : this.getShLights(settings.environmentShOrder);
|
|
127
|
+
this.lightsKey = lightsKey;
|
|
128
|
+
}
|
|
129
|
+
const { result } = this;
|
|
130
|
+
const intensity = scene.environmentIntensity;
|
|
131
|
+
result.mode = mode;
|
|
132
|
+
result.count = this.lights.length;
|
|
133
|
+
this.lights.forEach(({ direction, color }, index) => {
|
|
134
|
+
result.directions[index] = direction;
|
|
135
|
+
result.colors[index] = color.map((value) => value * intensity);
|
|
136
|
+
});
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
/** Resolves when a pending map readback has settled (tests and harnesses; not his). */
|
|
140
|
+
settled = Promise.resolve();
|
|
141
|
+
requestMap(renderer, scene, key) {
|
|
142
|
+
this.pending = true;
|
|
143
|
+
this.settled = this.extract(renderer, scene)
|
|
144
|
+
.then((pixels) => {
|
|
145
|
+
this.pending = false;
|
|
146
|
+
if (this.setTexels(pixels))
|
|
147
|
+
this.key = key;
|
|
148
|
+
else
|
|
149
|
+
this.retryAt = this.updates + retryInterval;
|
|
150
|
+
})
|
|
151
|
+
.catch((error) => {
|
|
152
|
+
this.pending = false;
|
|
153
|
+
this.retryAt = this.updates + retryInterval;
|
|
154
|
+
if (!this.warned) {
|
|
155
|
+
console.warn("VDBFrameRenderer: could not read the environment map.", error);
|
|
156
|
+
this.warned = true;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/** Radiance, direction and solid angle of each texel. Returns false for an empty map. Half floats (Uint16Array) are decoded. */
|
|
161
|
+
setTexels(pixels) {
|
|
162
|
+
const width = frameEnvironmentMapWidth;
|
|
163
|
+
const height = frameEnvironmentMapHeight;
|
|
164
|
+
const half = pixels instanceof Uint16Array;
|
|
165
|
+
const at = (i) => (half ? halfToFloat(pixels[i]) : pixels[i]);
|
|
166
|
+
const texels = [];
|
|
167
|
+
let energy = 0.0;
|
|
168
|
+
for (let i = 0; i < width * height; i++) {
|
|
169
|
+
const r = Math.max(0.0, at(i * 4));
|
|
170
|
+
const g = Math.max(0.0, at(i * 4 + 1));
|
|
171
|
+
const b = Math.max(0.0, at(i * 4 + 2));
|
|
172
|
+
const v = at(i * 4 + 3);
|
|
173
|
+
const u = ((i % width) + 0.5) / width;
|
|
174
|
+
const theta = v * Math.PI;
|
|
175
|
+
const solidAngle = ((2.0 * Math.PI) / width) * (Math.PI / height) * Math.sin(theta);
|
|
176
|
+
if (!Number.isFinite(r + g + b + v))
|
|
177
|
+
return false;
|
|
178
|
+
energy += luminance(r, g, b) * solidAngle;
|
|
179
|
+
texels.push({ radiance: [r, g, b], luminance: luminance(r, g, b), direction: vdbFrameEnvironmentMapDirection(u, v), solidAngle });
|
|
180
|
+
}
|
|
181
|
+
if (energy <= 0.0)
|
|
182
|
+
return false;
|
|
183
|
+
this.texels = texels;
|
|
184
|
+
this.texelsVersion++;
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Dominant direction (brightest texel) and fixed sky directions: zenith, nadir, then a horizon ring.
|
|
189
|
+
* Each texel goes to the nearest direction; a light is at the energy centroid of its texels with
|
|
190
|
+
* their energy; colour is energy / 4 (a uniform environment then gives the 'outward' light).
|
|
191
|
+
* `pairs`: seeds in opposite pairs (diffusion weights of a pair sum to 2). `tie` (K6.2b, the core): near-ties go to
|
|
192
|
+
* the first candidate.
|
|
193
|
+
*/
|
|
194
|
+
getDirectionalLights(samples, pairs = false, tie = 0) {
|
|
195
|
+
const texels = this.texels;
|
|
196
|
+
const count = Math.min(frameMaxEnvironmentSamples, Math.max(1, Math.round(samples) || 1));
|
|
197
|
+
// K6.2b `tie` (the core twin): the first texel within `tie` (relative) of the maximum, and a seed must be nearer
|
|
198
|
+
// by more than `tie`; 0 is his (the first exact maximum, strictly nearer)
|
|
199
|
+
const brightest = Math.max(...texels.map((texel) => texel.luminance));
|
|
200
|
+
const peak = tie > 0 ? texels.find((texel) => texel.luminance >= brightest * (1 - tie)) : texels.reduce((best, texel) => (texel.luminance > best.luminance ? texel : best));
|
|
201
|
+
const seeds = [peak.direction];
|
|
202
|
+
const ringCount = pairs ? Math.max(0, count - 4) - (Math.max(0, count - 4) % 2) : count - 3;
|
|
203
|
+
if (pairs) {
|
|
204
|
+
if (count >= 2)
|
|
205
|
+
seeds.push(peak.direction.map((value) => -value));
|
|
206
|
+
if (count >= 4)
|
|
207
|
+
seeds.push([0.0, 1.0, 0.0], [0.0, -1.0, 0.0]);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
if (count >= 2)
|
|
211
|
+
seeds.push([0.0, 1.0, 0.0]);
|
|
212
|
+
if (count >= 3)
|
|
213
|
+
seeds.push([0.0, -1.0, 0.0]);
|
|
214
|
+
}
|
|
215
|
+
// NOTE The horizon ring starts opposite the dominant direction
|
|
216
|
+
const peakAzimuth = Math.atan2(peak.direction[2], peak.direction[0]);
|
|
217
|
+
for (let i = 0; i < ringCount; i++) {
|
|
218
|
+
const azimuth = peakAzimuth + Math.PI + (2.0 * Math.PI * i) / ringCount;
|
|
219
|
+
seeds.push([Math.cos(azimuth), 0.0, Math.sin(azimuth)]);
|
|
220
|
+
}
|
|
221
|
+
const cells = seeds.map((seed) => ({ seed, energy: [0.0, 0.0, 0.0], centroid: [0.0, 0.0, 0.0] }));
|
|
222
|
+
for (const { radiance, luminance: texelLuminance, direction, solidAngle } of texels) {
|
|
223
|
+
let nearest = cells[0];
|
|
224
|
+
let nearestDot = -Infinity;
|
|
225
|
+
for (const cell of cells) {
|
|
226
|
+
const dot = cell.seed[0] * direction[0] + cell.seed[1] * direction[1] + cell.seed[2] * direction[2];
|
|
227
|
+
if (dot > nearestDot + tie) {
|
|
228
|
+
nearest = cell;
|
|
229
|
+
nearestDot = dot;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
for (let c = 0; c < 3; c++) {
|
|
233
|
+
nearest.energy[c] = nearest.energy[c] + radiance[c] * solidAngle;
|
|
234
|
+
nearest.centroid[c] = nearest.centroid[c] + direction[c] * texelLuminance * solidAngle;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return cells
|
|
238
|
+
.filter(({ energy }) => luminance(...energy) > 0.0)
|
|
239
|
+
.map(({ seed, energy, centroid }) => ({
|
|
240
|
+
direction: Math.hypot(...centroid) > 1e-6 ? normalize(...centroid) : seed,
|
|
241
|
+
color: energy.map((value) => value / 4.0),
|
|
242
|
+
power: luminance(...energy),
|
|
243
|
+
}))
|
|
244
|
+
.sort((a, b) => b.power - a.power);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* SH projection of the environment (L1: 4, L2: 9 coefficients) evaluated at quadrature directions:
|
|
248
|
+
* direction m gets the colour (4π / M) L_sh(w_m) / 4. The shaders clamp the sum to ≥ 0.
|
|
249
|
+
*/
|
|
250
|
+
getShLights(order) {
|
|
251
|
+
const texels = this.texels;
|
|
252
|
+
const coefficientCount = Number(order) === 1 ? 4 : 9;
|
|
253
|
+
const directions = coefficientCount === 4 ? octahedron : icosahedron;
|
|
254
|
+
const coefficients = Array.from({ length: coefficientCount }, () => [0.0, 0.0, 0.0]);
|
|
255
|
+
for (const { radiance, direction, solidAngle } of texels) {
|
|
256
|
+
getShBasis(direction, coefficientCount).forEach((basis, index) => {
|
|
257
|
+
for (let c = 0; c < 3; c++)
|
|
258
|
+
coefficients[index][c] = coefficients[index][c] + radiance[c] * basis * solidAngle;
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
const weight = (4.0 * Math.PI) / directions.length / 4.0;
|
|
262
|
+
return directions.map((direction) => {
|
|
263
|
+
const color = [0.0, 0.0, 0.0];
|
|
264
|
+
getShBasis(direction, coefficientCount).forEach((basis, index) => {
|
|
265
|
+
for (let c = 0; c < 3; c++)
|
|
266
|
+
color[c] = color[c] + coefficients[index][c] * basis * weight;
|
|
267
|
+
});
|
|
268
|
+
return { direction, color };
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../src/tools/frame/environment.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,uEAAuE;AACvE,4GAA4G;AAC5G,6FAA6F;AAC7F,6FAA6F;AAC7F,sFAAsF;AAEtF;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAC5C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAC5C,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAC3C,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAC5C,oGAAoG;AACpG,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC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E,CAAC,GAAG,UAAU,CAAC,MAAM,GAAG,GAAG,CAAC;QACzD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;YAClC,MAAM,KAAK,GAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;YAClC,UAAU,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;gBAC/D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;oBAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAE,GAAG,YAAY,CAAC,KAAK,CAAE,CAAC,CAAC,CAAE,GAAG,KAAK,GAAG,MAAM,CAAC;YAC/F,CAAC,CAAC,CAAC;YACH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):\n// src/three-openvdb/frame/core/frameEnvironment.js (all, 331 lines).\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: TypeScript; `isFrameDiffusion` inlined (tools does not import the three adapter);\n// the readback promise may also resolve to a Uint16Array of half floats (decoded here). Same\n// directions, cells, colours and SH quadrature. Divergences: DIVERGES.md (K3.3 rows).\n\n/**\n * Multi-directional environment light (Disney \"Deep Scattering\", §4.4 and §7), engine-free (K3.3):\n * the scene environment is read once into a small lat-long map (64 × 32, PMREM roughness 0.4); the\n * CPU turns it into ≤ 12 directional lights. `'directional'`: the brightest texel plus fixed sky\n * directions (zenith, nadir, a horizon ring; opposite pairs with diffusion), each texel to its\n * nearest seed, a light at the energy centroid with energy / 4. `'spherical-harmonics'`: SH L1/L2\n * projection evaluated at quadrature directions. The three adapter draws the map and passes the\n * readback through `extract`.\n */\n\nexport const frameMaxEnvironmentLights = 12;\nexport const frameMaxEnvironmentSamples = 8;\nexport const frameEnvironmentMapWidth = 64;\nexport const frameEnvironmentMapHeight = 32;\n/** PMREM blur of the map: a small sun covers more than one texel and is not lost between texels. */\nexport const frameEnvironmentMapRoughness = 0.4;\n\nexport const frameEnvironmentModes = {\n outward: \"outward\",\n directional: \"directional\",\n sphericalHarmonics: \"spherical-harmonics\",\n} as const;\n\nexport type VDBFrameEnvironmentMode = (typeof frameEnvironmentModes)[keyof typeof frameEnvironmentModes];\n\n/** The renderer settings the environment lights read. */\nexport interface VDBFrameEnvironmentSettings {\n environmentLighting: string;\n environmentSamples: number;\n environmentShOrder: number;\n multipleScattering: boolean | string;\n}\n\n/** The scene fields the environment lights read (three's `Scene` fits). */\nexport interface VDBFrameEnvironmentScene {\n environment: { uuid: string; version: number } | null;\n environmentRotation: { x: number; y: number; z: number; order: string };\n environmentIntensity: number;\n}\n\n// NOTE Retry an empty map (environment or PMREM not ready) after this number of updates\nconst retryInterval = 30;\n\ntype V3 = [number, number, number];\n\nconst normalize = (x: number, y: number, z: number): V3 => {\n const length = Math.hypot(x, y, z) || 1.0;\n return [x / length, y / length, z / length];\n};\n\n/** His `isFrameDiffusion` (three `frame/phase.ts`): true, 'two-sided' and 'neural'. */\nconst isDiffusion = (mode: boolean | string) => !!mode && mode !== \"octaves\";\n\n/** The same direction as the map shaders. u and v are 0 to 1; v = 0 is +Y. */\nexport const vdbFrameEnvironmentMapDirection = (u: number, v: number): V3 => {\n const phi = u * 2.0 * Math.PI;\n const theta = v * Math.PI;\n return [Math.sin(theta) * Math.cos(phi), Math.cos(theta), Math.sin(theta) * Math.sin(phi)];\n};\n\n// NOTE Real SH basis, bands 0 to 2. Same constants as three.js SphericalHarmonics3.\nconst getShBasis = ([x, y, z]: V3, count: number) =>\n [0.282095, 0.488603 * y, 0.488603 * z, 0.488603 * x, 1.092548 * x * y, 1.092548 * y * z, 0.315392 * (3.0 * z * z - 1.0), 1.092548 * x * z, 0.546274 * (x * x - y * y)].slice(0, count);\n\n// NOTE Quadrature directions. Octahedron (spherical 3-design) for L1, icosahedron (5-design) for L2.\nconst goldenRatio = (1.0 + Math.sqrt(5.0)) / 2.0;\nconst octahedron: V3[] = [\n [1, 0, 0],\n [-1, 0, 0],\n [0, 1, 0],\n [0, -1, 0],\n [0, 0, 1],\n [0, 0, -1],\n];\nconst icosahedron: V3[] = (\n [\n [0, 1, goldenRatio],\n [0, -1, goldenRatio],\n [0, 1, -goldenRatio],\n [0, -1, -goldenRatio],\n [1, goldenRatio, 0],\n [-1, goldenRatio, 0],\n [1, -goldenRatio, 0],\n [-1, -goldenRatio, 0],\n [goldenRatio, 0, 1],\n [-goldenRatio, 0, 1],\n [goldenRatio, 0, -1],\n [-goldenRatio, 0, -1],\n ] as V3[]\n).map(([x, y, z]) => normalize(x, y, z));\n\nconst luminance = (r: number, g: number, b: number) => 0.2126 * r + 0.7152 * g + 0.0722 * b;\n\nexport const vdbFrameEnvironmentMode = (settings: Pick<VDBFrameEnvironmentSettings, \"environmentLighting\">): VDBFrameEnvironmentMode => {\n const mode = settings.environmentLighting;\n return mode === frameEnvironmentModes.directional || mode === frameEnvironmentModes.sphericalHarmonics ? mode : frameEnvironmentModes.outward;\n};\n\ninterface Texel {\n radiance: V3;\n luminance: number;\n direction: V3;\n solidAngle: number;\n}\n\n/** One environment light: world direction to the light and its isotropic irradiance colour (energy / 4). */\nexport interface VDBFrameEnvironmentLight {\n direction: V3;\n color: V3;\n power?: number;\n}\n\n/** Output of {@link VDBFrameEnvironmentLights.update}. Colours include `scene.environmentIntensity`. */\nexport interface VDBFrameEnvironmentResult {\n mode: VDBFrameEnvironmentMode;\n count: number;\n directions: V3[];\n colors: V3[];\n}\n\nconst halfToFloat = (h: number): number => {\n const s = h & 0x8000 ? -1 : 1;\n const e = (h >> 10) & 0x1f;\n const f = h & 0x3ff;\n if (e === 0) return s * Math.pow(2, -14) * (f / 1024);\n if (e === 31) return f ? NaN : s * Infinity;\n return s * Math.pow(2, e - 15) * (1 + f / 1024);\n};\n\n/**\n * His `FrameEnvironmentLights`: holds the lat-long map of the scene environment and the lights made\n * from it. `extract(renderer, scene)` is the engine part: it draws the map (RGB radiance, A the\n * texel's v, so the readback row order does not matter) and resolves RGBA floats.\n */\nexport class VDBFrameEnvironmentLights<R = unknown, S extends VDBFrameEnvironmentScene = VDBFrameEnvironmentScene> {\n key: string | null = null;\n pending = false;\n retryAt = 0;\n updates = 0;\n texels: Texel[] | null = null;\n texelsVersion = 0;\n warned = false;\n lightsKey: string | null = null;\n lights: VDBFrameEnvironmentLight[] = [];\n\n readonly result: VDBFrameEnvironmentResult = {\n mode: frameEnvironmentModes.outward,\n count: 0,\n directions: Array.from({ length: frameMaxEnvironmentLights }, () => [0.0, 1.0, 0.0] as V3),\n colors: Array.from({ length: frameMaxEnvironmentLights }, () => [0.0, 0.0, 0.0] as V3),\n };\n\n constructor(readonly extract: (renderer: R, scene: S) => Promise<ArrayLike<number>>) {}\n\n getKey(scene: S): string {\n const { environment, environmentRotation: rotation } = scene;\n return `${environment!.uuid}:${environment!.version}:${rotation.x}:${rotation.y}:${rotation.z}:${rotation.order}`;\n }\n\n /** Null when the 'outward' path must be used: another mode, no environment, or no map yet. */\n update(renderer: R, scene: S, settings: VDBFrameEnvironmentSettings): VDBFrameEnvironmentResult | null {\n const mode = vdbFrameEnvironmentMode(settings);\n this.updates++;\n if (mode === frameEnvironmentModes.outward || !scene.environment) return null;\n\n const key = this.getKey(scene);\n if (key !== this.key && !this.pending && this.updates >= this.retryAt) this.requestMap(renderer, scene, key);\n if (!this.texels) return null;\n\n // NOTE Diffusion multiple scattering needs the directions in opposite pairs (getDirectionalLights)\n const pairs = isDiffusion(settings.multipleScattering);\n const lightsKey = `${mode}:${settings.environmentSamples}:${settings.environmentShOrder}:${this.texelsVersion}:${pairs}`;\n if (lightsKey !== this.lightsKey) {\n this.lights = mode === frameEnvironmentModes.directional ? this.getDirectionalLights(settings.environmentSamples, pairs) : this.getShLights(settings.environmentShOrder);\n this.lightsKey = lightsKey;\n }\n\n const { result } = this;\n const intensity = scene.environmentIntensity;\n result.mode = mode;\n result.count = this.lights.length;\n this.lights.forEach(({ direction, color }, index) => {\n result.directions[index] = direction;\n result.colors[index] = color.map((value) => value * intensity) as V3;\n });\n return result;\n }\n\n /** Resolves when a pending map readback has settled (tests and harnesses; not his). */\n settled: Promise<void> = Promise.resolve();\n\n requestMap(renderer: R, scene: S, key: string): void {\n this.pending = true;\n this.settled = this.extract(renderer, scene)\n .then((pixels) => {\n this.pending = false;\n if (this.setTexels(pixels)) this.key = key;\n else this.retryAt = this.updates + retryInterval;\n })\n .catch((error: unknown) => {\n this.pending = false;\n this.retryAt = this.updates + retryInterval;\n if (!this.warned) {\n console.warn(\"VDBFrameRenderer: could not read the environment map.\", error);\n this.warned = true;\n }\n });\n }\n\n /** Radiance, direction and solid angle of each texel. Returns false for an empty map. Half floats (Uint16Array) are decoded. */\n setTexels(pixels: ArrayLike<number>): boolean {\n const width = frameEnvironmentMapWidth;\n const height = frameEnvironmentMapHeight;\n const half = pixels instanceof Uint16Array;\n const at = (i: number) => (half ? halfToFloat(pixels[i]!) : pixels[i]!);\n const texels: Texel[] = [];\n let energy = 0.0;\n\n for (let i = 0; i < width * height; i++) {\n const r = Math.max(0.0, at(i * 4));\n const g = Math.max(0.0, at(i * 4 + 1));\n const b = Math.max(0.0, at(i * 4 + 2));\n const v = at(i * 4 + 3);\n const u = ((i % width) + 0.5) / width;\n const theta = v * Math.PI;\n const solidAngle = ((2.0 * Math.PI) / width) * (Math.PI / height) * Math.sin(theta);\n if (!Number.isFinite(r + g + b + v)) return false;\n energy += luminance(r, g, b) * solidAngle;\n texels.push({ radiance: [r, g, b], luminance: luminance(r, g, b), direction: vdbFrameEnvironmentMapDirection(u, v), solidAngle });\n }\n if (energy <= 0.0) return false;\n this.texels = texels;\n this.texelsVersion++;\n return true;\n }\n\n /**\n * Dominant direction (brightest texel) and fixed sky directions: zenith, nadir, then a horizon ring.\n * Each texel goes to the nearest direction; a light is at the energy centroid of its texels with\n * their energy; colour is energy / 4 (a uniform environment then gives the 'outward' light).\n * `pairs`: seeds in opposite pairs (diffusion weights of a pair sum to 2). `tie` (K6.2b, the core): near-ties go to\n * the first candidate.\n */\n getDirectionalLights(samples: number, pairs = false, tie = 0): VDBFrameEnvironmentLight[] {\n const texels = this.texels!;\n const count = Math.min(frameMaxEnvironmentSamples, Math.max(1, Math.round(samples) || 1));\n // K6.2b `tie` (the core twin): the first texel within `tie` (relative) of the maximum, and a seed must be nearer\n // by more than `tie`; 0 is his (the first exact maximum, strictly nearer)\n const brightest = Math.max(...texels.map((texel) => texel.luminance));\n const peak = tie > 0 ? texels.find((texel) => texel.luminance >= brightest * (1 - tie))! : texels.reduce((best, texel) => (texel.luminance > best.luminance ? texel : best));\n const seeds: V3[] = [peak.direction];\n const ringCount = pairs ? Math.max(0, count - 4) - (Math.max(0, count - 4) % 2) : count - 3;\n\n if (pairs) {\n if (count >= 2) seeds.push(peak.direction.map((value) => -value) as V3);\n if (count >= 4) seeds.push([0.0, 1.0, 0.0], [0.0, -1.0, 0.0]);\n } else {\n if (count >= 2) seeds.push([0.0, 1.0, 0.0]);\n if (count >= 3) seeds.push([0.0, -1.0, 0.0]);\n }\n\n // NOTE The horizon ring starts opposite the dominant direction\n const peakAzimuth = Math.atan2(peak.direction[2], peak.direction[0]);\n for (let i = 0; i < ringCount; i++) {\n const azimuth = peakAzimuth + Math.PI + (2.0 * Math.PI * i) / ringCount;\n seeds.push([Math.cos(azimuth), 0.0, Math.sin(azimuth)]);\n }\n\n const cells = seeds.map((seed) => ({ seed, energy: [0.0, 0.0, 0.0] as V3, centroid: [0.0, 0.0, 0.0] as V3 }));\n for (const { radiance, luminance: texelLuminance, direction, solidAngle } of texels) {\n let nearest = cells[0]!;\n let nearestDot = -Infinity;\n for (const cell of cells) {\n const dot = cell.seed[0] * direction[0] + cell.seed[1] * direction[1] + cell.seed[2] * direction[2];\n if (dot > nearestDot + tie) {\n nearest = cell;\n nearestDot = dot;\n }\n }\n for (let c = 0; c < 3; c++) {\n nearest.energy[c] = nearest.energy[c]! + radiance[c]! * solidAngle;\n nearest.centroid[c] = nearest.centroid[c]! + direction[c]! * texelLuminance * solidAngle;\n }\n }\n\n return cells\n .filter(({ energy }) => luminance(...energy) > 0.0)\n .map(({ seed, energy, centroid }) => ({\n direction: Math.hypot(...centroid) > 1e-6 ? normalize(...centroid) : seed,\n color: energy.map((value) => value / 4.0) as V3,\n power: luminance(...energy),\n }))\n .sort((a, b) => b.power - a.power);\n }\n\n /**\n * SH projection of the environment (L1: 4, L2: 9 coefficients) evaluated at quadrature directions:\n * direction m gets the colour (4π / M) L_sh(w_m) / 4. The shaders clamp the sum to ≥ 0.\n */\n getShLights(order: number): VDBFrameEnvironmentLight[] {\n const texels = this.texels!;\n const coefficientCount = Number(order) === 1 ? 4 : 9;\n const directions = coefficientCount === 4 ? octahedron : icosahedron;\n const coefficients = Array.from({ length: coefficientCount }, () => [0.0, 0.0, 0.0] as V3);\n for (const { radiance, direction, solidAngle } of texels) {\n getShBasis(direction, coefficientCount).forEach((basis, index) => {\n for (let c = 0; c < 3; c++) coefficients[index]![c] = coefficients[index]![c]! + radiance[c]! * basis * solidAngle;\n });\n }\n const weight = (4.0 * Math.PI) / directions.length / 4.0;\n return directions.map((direction) => {\n const color: V3 = [0.0, 0.0, 0.0];\n getShBasis(direction, coefficientCount).forEach((basis, index) => {\n for (let c = 0; c < 3; c++) color[c] = color[c]! + coefficients[index]![c]! * basis * weight;\n });\n return { direction, color };\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CPU twins (f64) of the core frame renderer's froxel stages (K6.1): `vdbFrameGatherCs`'s combine of
|
|
3
|
+
* the volumes in one froxel, `vdbFrameResolveCs`'s temporal blend and column scan, and
|
|
4
|
+
* `vdbFrameIntegrate`'s two-tap composite. Engine-free; the oracles of `e2e/k6-core.spec.ts`.
|
|
5
|
+
*/
|
|
6
|
+
import { type Vec2, type Vec3, type Vec4 } from "./index.js";
|
|
7
|
+
/** One volume's lit froxel: unpremultiplied slice radiance and slice alpha (`vdbFrameInjectSlice` + lights). */
|
|
8
|
+
export interface VDBFrameVolumeFroxel {
|
|
9
|
+
radiance: Vec3;
|
|
10
|
+
alpha: number;
|
|
11
|
+
}
|
|
12
|
+
/** Optical depths above this are clamped (T = 1.3e-14), so an opaque volume gives a finite τ. */
|
|
13
|
+
export declare const vdbFrameMaxOpticalDepth = 32;
|
|
14
|
+
/**
|
|
15
|
+
* The gather kernel's combine of the volumes in one froxel, premultiplied (rgb = L·α, a = α).
|
|
16
|
+
*
|
|
17
|
+
* Design §3.4: co-located media; τᵢ = −log(1 − αᵢ), α = 1 − exp(−Στᵢ),
|
|
18
|
+
* L = Σ τᵢLᵢ / Στᵢ. Order-independent; one volume gives exactly (Lα, α).
|
|
19
|
+
* Volumes with α ≤ 0 do not count (discarded froxels).
|
|
20
|
+
*/
|
|
21
|
+
export declare function vdbFrameGatherFroxel(volumes: readonly VDBFrameVolumeFroxel[]): Vec4;
|
|
22
|
+
/**
|
|
23
|
+
* His temporal blend of one froxel (`FrameTemporalMaterial`): the reprojected history clamped to the
|
|
24
|
+
* per-channel min and max of the current froxel and its neighbours, then `mix(history, current, blend)`
|
|
25
|
+
* (`blend` from `vdbFrameReproject`).
|
|
26
|
+
*/
|
|
27
|
+
export declare function vdbFrameTemporalFroxel(current: Vec4, history: Vec4, neighbours: readonly Vec4[], blend: number): Vec4;
|
|
28
|
+
/** Transmittance below which the scan stops adding slices (his integrate's break). */
|
|
29
|
+
export declare const vdbFrameScanStop = 0.001;
|
|
30
|
+
/**
|
|
31
|
+
* The resolve kernel's column scan (his integrate loop over whole slices): boundary k holds the
|
|
32
|
+
* radiance of slices 0..k−1 and their opacity A = 1 − T. `froxels[z]` is the premultiplied
|
|
33
|
+
* (rgb, α) of slice z (α clamped to [0, 1]); a slice whose start has T < 0.001 adds nothing (his break).
|
|
34
|
+
* Returns `froxels.length + 1` boundaries; boundary 0 is (0, 0, 0, 0).
|
|
35
|
+
*/
|
|
36
|
+
export declare function vdbFrameScanColumn(froxels: readonly Vec4[], o?: {
|
|
37
|
+
stop?: number;
|
|
38
|
+
}): Vec4[];
|
|
39
|
+
/** What the composite reads at a pixel: radiance and transmittance (grey: one T). */
|
|
40
|
+
export interface VDBFrameIntegrated {
|
|
41
|
+
radiance: Vec3;
|
|
42
|
+
transmittance: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The composite's two taps (design §3.4): the scene depth falls `c` ∈ [0, 1] into the slice between
|
|
46
|
+
* boundaries `a` and `b` (each (L rgb, A = 1 − T)). With α = 1 − T_b / T_a:
|
|
47
|
+
* radiance = L_a + (L_b − L_a)·(1 − (1 − α)^c)/α (→ c as α → 0), T = T_a·(1 − α)^c: his `sliceAlpha`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function vdbFrameIntegratePrefix(a: Vec4, b: Vec4, c: number): VDBFrameIntegrated;
|
|
50
|
+
/**
|
|
51
|
+
* The composite's slice of a scene view depth: the slice `k` it falls in on his log slices (`range` the
|
|
52
|
+
* froxel near and far; ≤ depth − 1) and his coverage `c` of that slice, linear in view depth:
|
|
53
|
+
* (depth − sliceStart) / (sliceEnd − sliceStart), clamped to [0, 1].
|
|
54
|
+
*/
|
|
55
|
+
export declare function vdbFrameSliceCoord(viewDepth: number, range: Vec2, depth: number): {
|
|
56
|
+
k: number;
|
|
57
|
+
c: number;
|
|
58
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
|
|
2
|
+
// src/three-openvdb/frame/webgpu/FrameInjectMaterial.js L59–101 (the premultiplied "over" blend of
|
|
3
|
+
// overlapping volumes), src/three-openvdb/frame/webgpu/FrameTemporalMaterial.js L120–200 (the
|
|
4
|
+
// neighbourhood clamp and blend), src/three-openvdb/frame/webgpu/FrameIntegrateMaterial.js L219–294
|
|
5
|
+
// (the slice march with the T < 0.001 stop and the `sliceAlpha` coverage of the last slice).
|
|
6
|
+
// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
|
|
7
|
+
// Changes: the core renderer's froxel stages (K6.1, design §3.4): an order-independent 'mixture' of the
|
|
8
|
+
// volumes in a froxel beside his 'over'; his integrate split into a per-column prefix scan and a two-tap
|
|
9
|
+
// composite. Divergences: DIVERGES.md (K6.1 rows).
|
|
10
|
+
/**
|
|
11
|
+
* CPU twins (f64) of the core frame renderer's froxel stages (K6.1): `vdbFrameGatherCs`'s combine of
|
|
12
|
+
* the volumes in one froxel, `vdbFrameResolveCs`'s temporal blend and column scan, and
|
|
13
|
+
* `vdbFrameIntegrate`'s two-tap composite. Engine-free; the oracles of `e2e/k6-core.spec.ts`.
|
|
14
|
+
*/
|
|
15
|
+
import { vdbFrameFroxelSlice, vdbFrameSliceDepth } from "./index.js";
|
|
16
|
+
/** Optical depths above this are clamped (T = 1.3e-14), so an opaque volume gives a finite τ. */
|
|
17
|
+
export const vdbFrameMaxOpticalDepth = 32;
|
|
18
|
+
/**
|
|
19
|
+
* The gather kernel's combine of the volumes in one froxel, premultiplied (rgb = L·α, a = α).
|
|
20
|
+
*
|
|
21
|
+
* Design §3.4: co-located media; τᵢ = −log(1 − αᵢ), α = 1 − exp(−Στᵢ),
|
|
22
|
+
* L = Σ τᵢLᵢ / Στᵢ. Order-independent; one volume gives exactly (Lα, α).
|
|
23
|
+
* Volumes with α ≤ 0 do not count (discarded froxels).
|
|
24
|
+
*/
|
|
25
|
+
export function vdbFrameGatherFroxel(volumes) {
|
|
26
|
+
const lit = volumes.filter((v) => v.alpha > 0);
|
|
27
|
+
if (lit.length === 0)
|
|
28
|
+
return [0, 0, 0, 0];
|
|
29
|
+
if (lit.length === 1) {
|
|
30
|
+
const v = lit[0];
|
|
31
|
+
return [v.radiance[0] * v.alpha, v.radiance[1] * v.alpha, v.radiance[2] * v.alpha, v.alpha];
|
|
32
|
+
}
|
|
33
|
+
let tau = 0;
|
|
34
|
+
const tl = [0, 0, 0];
|
|
35
|
+
for (const v of lit) {
|
|
36
|
+
const t = Math.min(-Math.log(Math.max(1 - v.alpha, 0)), vdbFrameMaxOpticalDepth);
|
|
37
|
+
tau += t;
|
|
38
|
+
for (let c = 0; c < 3; c++)
|
|
39
|
+
tl[c] = tl[c] + t * v.radiance[c];
|
|
40
|
+
}
|
|
41
|
+
const alpha = 1 - Math.exp(-tau);
|
|
42
|
+
return [(tl[0] / tau) * alpha, (tl[1] / tau) * alpha, (tl[2] / tau) * alpha, alpha];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* His temporal blend of one froxel (`FrameTemporalMaterial`): the reprojected history clamped to the
|
|
46
|
+
* per-channel min and max of the current froxel and its neighbours, then `mix(history, current, blend)`
|
|
47
|
+
* (`blend` from `vdbFrameReproject`).
|
|
48
|
+
*/
|
|
49
|
+
export function vdbFrameTemporalFroxel(current, history, neighbours, blend) {
|
|
50
|
+
const lo = [...current];
|
|
51
|
+
const hi = [...current];
|
|
52
|
+
for (const n of neighbours) {
|
|
53
|
+
for (let c = 0; c < 4; c++) {
|
|
54
|
+
lo[c] = Math.min(lo[c], n[c]);
|
|
55
|
+
hi[c] = Math.max(hi[c], n[c]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return [0, 1, 2, 3].map((c) => {
|
|
59
|
+
const h = Math.min(Math.max(history[c], lo[c]), hi[c]);
|
|
60
|
+
return h + (current[c] - h) * blend;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/** Transmittance below which the scan stops adding slices (his integrate's break). */
|
|
64
|
+
export const vdbFrameScanStop = 0.001;
|
|
65
|
+
/**
|
|
66
|
+
* The resolve kernel's column scan (his integrate loop over whole slices): boundary k holds the
|
|
67
|
+
* radiance of slices 0..k−1 and their opacity A = 1 − T. `froxels[z]` is the premultiplied
|
|
68
|
+
* (rgb, α) of slice z (α clamped to [0, 1]); a slice whose start has T < 0.001 adds nothing (his break).
|
|
69
|
+
* Returns `froxels.length + 1` boundaries; boundary 0 is (0, 0, 0, 0).
|
|
70
|
+
*/
|
|
71
|
+
export function vdbFrameScanColumn(froxels, o = {}) {
|
|
72
|
+
const stop = o.stop ?? vdbFrameScanStop;
|
|
73
|
+
const out = [[0, 0, 0, 0]];
|
|
74
|
+
const L = [0, 0, 0];
|
|
75
|
+
let T = 1;
|
|
76
|
+
for (const f of froxels) {
|
|
77
|
+
const a = Math.min(Math.max(f[3], 0), 1);
|
|
78
|
+
if (T >= stop && a > 0) {
|
|
79
|
+
for (let c = 0; c < 3; c++)
|
|
80
|
+
L[c] = L[c] + T * f[c];
|
|
81
|
+
T *= 1 - a;
|
|
82
|
+
}
|
|
83
|
+
out.push([L[0], L[1], L[2], 1 - T]);
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The composite's two taps (design §3.4): the scene depth falls `c` ∈ [0, 1] into the slice between
|
|
89
|
+
* boundaries `a` and `b` (each (L rgb, A = 1 − T)). With α = 1 − T_b / T_a:
|
|
90
|
+
* radiance = L_a + (L_b − L_a)·(1 − (1 − α)^c)/α (→ c as α → 0), T = T_a·(1 − α)^c: his `sliceAlpha`.
|
|
91
|
+
*/
|
|
92
|
+
export function vdbFrameIntegratePrefix(a, b, c) {
|
|
93
|
+
const ta = 1 - a[3];
|
|
94
|
+
const tb = 1 - b[3];
|
|
95
|
+
const alpha = Math.min(Math.max(ta > 1e-6 ? 1 - tb / ta : 0, 0), 1);
|
|
96
|
+
const keep = Math.pow(1 - alpha, c);
|
|
97
|
+
const w = alpha > 1e-4 ? (1 - keep) / alpha : c;
|
|
98
|
+
return {
|
|
99
|
+
radiance: [a[0] + (b[0] - a[0]) * w, a[1] + (b[1] - a[1]) * w, a[2] + (b[2] - a[2]) * w],
|
|
100
|
+
transmittance: Math.max(ta, 0) * keep,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The composite's slice of a scene view depth: the slice `k` it falls in on his log slices (`range` the
|
|
105
|
+
* froxel near and far; ≤ depth − 1) and his coverage `c` of that slice, linear in view depth:
|
|
106
|
+
* (depth − sliceStart) / (sliceEnd − sliceStart), clamped to [0, 1].
|
|
107
|
+
*/
|
|
108
|
+
export function vdbFrameSliceCoord(viewDepth, range, depth) {
|
|
109
|
+
const s = Math.min(Math.max(vdbFrameFroxelSlice(viewDepth, range, depth), 0), depth);
|
|
110
|
+
const k = Math.min(Math.floor(s), depth - 1);
|
|
111
|
+
const start = vdbFrameSliceDepth(range, k / depth);
|
|
112
|
+
const end = vdbFrameSliceDepth(range, (k + 1) / depth);
|
|
113
|
+
return { k, c: Math.min(Math.max((viewDepth - start) / (end - start), 0), 1) };
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=froxel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"froxel.js","sourceRoot":"","sources":["../../../src/tools/frame/froxel.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qGAAqG;AACrG,gGAAgG;AAChG,sGAAsG;AACtG,+FAA+F;AAC/F,4GAA4G;AAC5G,wGAAwG;AACxG,yGAAyG;AACzG,mDAAmD;AAEnD;;;;GAIG;AAEH,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAmC,MAAM,YAAY,CAAC;AAQtG,iGAAiG;AACjG,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAwC;IAC3E,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC/C,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC,EAAE,CAAC,EAA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AC7C,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC;IACnD,MAAM,GAAG,GAAG,kBAAkB,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;IACvD,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AACjF,CAAC","sourcesContent":["// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):\n// src/three-openvdb/frame/webgpu/FrameInjectMaterial.js L59–101 (the premultiplied \"over\" blend of\n// overlapping volumes), src/three-openvdb/frame/webgpu/FrameTemporalMaterial.js L120–200 (the\n// neighbourhood clamp and blend), src/three-openvdb/frame/webgpu/FrameIntegrateMaterial.js L219–294\n// (the slice march with the T < 0.001 stop and the `sliceAlpha` coverage of the last slice).\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: the core renderer's froxel stages (K6.1, design §3.4): an order-independent 'mixture' of the\n// volumes in a froxel beside his 'over'; his integrate split into a per-column prefix scan and a two-tap\n// composite. Divergences: DIVERGES.md (K6.1 rows).\n\n/**\n * CPU twins (f64) of the core frame renderer's froxel stages (K6.1): `vdbFrameGatherCs`'s combine of\n * the volumes in one froxel, `vdbFrameResolveCs`'s temporal blend and column scan, and\n * `vdbFrameIntegrate`'s two-tap composite. Engine-free; the oracles of `e2e/k6-core.spec.ts`.\n */\n\nimport { vdbFrameFroxelSlice, vdbFrameSliceDepth, type Vec2, type Vec3, type Vec4 } from \"./index.js\";\n\n/** One volume's lit froxel: unpremultiplied slice radiance and slice alpha (`vdbFrameInjectSlice` + lights). */\nexport interface VDBFrameVolumeFroxel {\n radiance: Vec3;\n alpha: number;\n}\n\n/** Optical depths above this are clamped (T = 1.3e-14), so an opaque volume gives a finite τ. */\nexport const vdbFrameMaxOpticalDepth = 32;\n\n/**\n * The gather kernel's combine of the volumes in one froxel, premultiplied (rgb = L·α, a = α).\n *\n * Design §3.4: co-located media; τᵢ = −log(1 − αᵢ), α = 1 − exp(−Στᵢ),\n * L = Σ τᵢLᵢ / Στᵢ. Order-independent; one volume gives exactly (Lα, α).\n * Volumes with α ≤ 0 do not count (discarded froxels).\n */\nexport function vdbFrameGatherFroxel(volumes: readonly VDBFrameVolumeFroxel[]): Vec4 {\n const lit = volumes.filter((v) => v.alpha > 0);\n if (lit.length === 0) return [0, 0, 0, 0];\n if (lit.length === 1) {\n const v = lit[0]!;\n return [v.radiance[0] * v.alpha, v.radiance[1] * v.alpha, v.radiance[2] * v.alpha, v.alpha];\n }\n let tau = 0;\n const tl: Vec3 = [0, 0, 0];\n for (const v of lit) {\n const t = Math.min(-Math.log(Math.max(1 - v.alpha, 0)), vdbFrameMaxOpticalDepth);\n tau += t;\n for (let c = 0; c < 3; c++) tl[c] = tl[c]! + t * v.radiance[c]!;\n }\n const alpha = 1 - Math.exp(-tau);\n return [(tl[0] / tau) * alpha, (tl[1] / tau) * alpha, (tl[2] / tau) * alpha, alpha];\n}\n\n/**\n * His temporal blend of one froxel (`FrameTemporalMaterial`): the reprojected history clamped to the\n * per-channel min and max of the current froxel and its neighbours, then `mix(history, current, blend)`\n * (`blend` from `vdbFrameReproject`).\n */\nexport function vdbFrameTemporalFroxel(current: Vec4, history: Vec4, neighbours: readonly Vec4[], blend: number): Vec4 {\n const lo = [...current] as Vec4;\n const hi = [...current] as Vec4;\n for (const n of neighbours) {\n for (let c = 0; c < 4; c++) {\n lo[c] = Math.min(lo[c]!, n[c]!);\n hi[c] = Math.max(hi[c]!, n[c]!);\n }\n }\n return [0, 1, 2, 3].map((c) => {\n const h = Math.min(Math.max(history[c]!, lo[c]!), hi[c]!);\n return h + (current[c]! - h) * blend;\n }) as Vec4;\n}\n\n/** Transmittance below which the scan stops adding slices (his integrate's break). */\nexport const vdbFrameScanStop = 0.001;\n\n/**\n * The resolve kernel's column scan (his integrate loop over whole slices): boundary k holds the\n * radiance of slices 0..k−1 and their opacity A = 1 − T. `froxels[z]` is the premultiplied\n * (rgb, α) of slice z (α clamped to [0, 1]); a slice whose start has T < 0.001 adds nothing (his break).\n * Returns `froxels.length + 1` boundaries; boundary 0 is (0, 0, 0, 0).\n */\nexport function vdbFrameScanColumn(froxels: readonly Vec4[], o: { stop?: number } = {}): Vec4[] {\n const stop = o.stop ?? vdbFrameScanStop;\n const out: Vec4[] = [[0, 0, 0, 0]];\n const L: Vec3 = [0, 0, 0];\n let T = 1;\n for (const f of froxels) {\n const a = Math.min(Math.max(f[3], 0), 1);\n if (T >= stop && a > 0) {\n for (let c = 0; c < 3; c++) L[c] = L[c]! + T * f[c]!;\n T *= 1 - a;\n }\n out.push([L[0], L[1], L[2], 1 - T]);\n }\n return out;\n}\n\n/** What the composite reads at a pixel: radiance and transmittance (grey: one T). */\nexport interface VDBFrameIntegrated {\n radiance: Vec3;\n transmittance: number;\n}\n\n/**\n * The composite's two taps (design §3.4): the scene depth falls `c` ∈ [0, 1] into the slice between\n * boundaries `a` and `b` (each (L rgb, A = 1 − T)). With α = 1 − T_b / T_a:\n * radiance = L_a + (L_b − L_a)·(1 − (1 − α)^c)/α (→ c as α → 0), T = T_a·(1 − α)^c: his `sliceAlpha`.\n */\nexport function vdbFrameIntegratePrefix(a: Vec4, b: Vec4, c: number): VDBFrameIntegrated {\n const ta = 1 - a[3];\n const tb = 1 - b[3];\n const alpha = Math.min(Math.max(ta > 1e-6 ? 1 - tb / ta : 0, 0), 1);\n const keep = Math.pow(1 - alpha, c);\n const w = alpha > 1e-4 ? (1 - keep) / alpha : c;\n return {\n radiance: [a[0] + (b[0] - a[0]) * w, a[1] + (b[1] - a[1]) * w, a[2] + (b[2] - a[2]) * w],\n transmittance: Math.max(ta, 0) * keep,\n };\n}\n\n/**\n * The composite's slice of a scene view depth: the slice `k` it falls in on his log slices (`range` the\n * froxel near and far; ≤ depth − 1) and his coverage `c` of that slice, linear in view depth:\n * (depth − sliceStart) / (sliceEnd − sliceStart), clamped to [0, 1].\n */\nexport function vdbFrameSliceCoord(viewDepth: number, range: Vec2, depth: number): { k: number; c: number } {\n const s = Math.min(Math.max(vdbFrameFroxelSlice(viewDepth, range, depth), 0), depth);\n const k = Math.min(Math.floor(s), depth - 1);\n const start = vdbFrameSliceDepth(range, k / depth);\n const end = vdbFrameSliceDepth(range, (k + 1) / depth);\n return { k, c: Math.min(Math.max((viewDepth - start) / (end - start), 0), 1) };\n}\n"]}
|