@pmndrs/vdb 0.0.0-stage → 0.1.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 +137 -0
- package/LICENSE +21 -0
- package/README.md +448 -2
- package/THIRD_PARTY_NOTICES.md +147 -0
- package/dist/core/compute/atlas.d.ts +94 -0
- package/dist/core/compute/atlas.js +98 -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/pyramid.d.ts +105 -0
- package/dist/core/compute/pyramid.js +455 -0
- package/dist/core/compute/pyramid.js.map +1 -0
- package/dist/core/compute/shared.d.ts +115 -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 +71 -0
- package/dist/core/compute/stats.js +188 -0
- package/dist/core/compute/stats.js.map +1 -0
- package/dist/core/compute/value-transform.d.ts +23 -0
- package/dist/core/compute/value-transform.js +58 -0
- package/dist/core/compute/value-transform.js.map +1 -0
- package/dist/core/errors.d.ts +11 -0
- package/dist/core/errors.js +9 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +30 -0
- package/dist/core/index.js +27 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/internal.d.ts +15 -0
- package/dist/core/internal.js +15 -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 +82 -0
- package/dist/core/pool/image-header.js +175 -0
- package/dist/core/pool/image-header.js.map +1 -0
- package/dist/core/pool/layout.d.ts +164 -0
- package/dist/core/pool/layout.js +267 -0
- package/dist/core/pool/layout.js.map +1 -0
- package/dist/core/pool/limits.d.ts +40 -0
- package/dist/core/pool/limits.js +79 -0
- package/dist/core/pool/limits.js.map +1 -0
- package/dist/core/pool/pool.d.ts +279 -0
- package/dist/core/pool/pool.js +953 -0
- package/dist/core/pool/pool.js.map +1 -0
- package/dist/core/source/dense.d.ts +19 -0
- package/dist/core/source/dense.js +287 -0
- package/dist/core/source/dense.js.map +1 -0
- package/dist/core/source/types.d.ts +63 -0
- package/dist/core/source/types.js +9 -0
- package/dist/core/source/types.js.map +1 -0
- package/dist/core/types.d.ts +28 -0
- package/dist/core/types.js +28 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/wgsl/api.d.ts +41 -0
- package/dist/core/wgsl/api.js +463 -0
- package/dist/core/wgsl/api.js.map +1 -0
- package/dist/core/wgsl/generate.d.ts +82 -0
- package/dist/core/wgsl/generate.js +505 -0
- package/dist/core/wgsl/generate.js.map +1 -0
- package/dist/core/wgsl/level-set.d.ts +54 -0
- package/dist/core/wgsl/level-set.js +194 -0
- package/dist/core/wgsl/level-set.js.map +1 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +330 -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 +104 -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 +162 -0
- package/dist/three/coarse-first.js +187 -0
- package/dist/three/coarse-first.js.map +1 -0
- package/dist/three/compute.d.ts +63 -0
- package/dist/three/compute.js +56 -0
- package/dist/three/compute.js.map +1 -0
- package/dist/three/device.d.ts +59 -0
- package/dist/three/device.js +59 -0
- package/dist/three/device.js.map +1 -0
- package/dist/three/frame/blackbody.d.ts +42 -0
- package/dist/three/frame/blackbody.js +74 -0
- package/dist/three/frame/blackbody.js.map +1 -0
- package/dist/three/frame/chunks.d.ts +157 -0
- package/dist/three/frame/chunks.js +559 -0
- package/dist/three/frame/chunks.js.map +1 -0
- package/dist/three/frame/density-material.d.ts +53 -0
- package/dist/three/frame/density-material.js +353 -0
- package/dist/three/frame/density-material.js.map +1 -0
- package/dist/three/frame/emission-light.d.ts +167 -0
- package/dist/three/frame/emission-light.js +655 -0
- package/dist/three/frame/emission-light.js.map +1 -0
- package/dist/three/frame/environment-grid-material.d.ts +21 -0
- package/dist/three/frame/environment-grid-material.js +184 -0
- package/dist/three/frame/environment-grid-material.js.map +1 -0
- package/dist/three/frame/environment-material.d.ts +22 -0
- package/dist/three/frame/environment-material.js +87 -0
- package/dist/three/frame/environment-material.js.map +1 -0
- package/dist/three/frame/grid-mip-material.d.ts +12 -0
- package/dist/three/frame/grid-mip-material.js +61 -0
- package/dist/three/frame/grid-mip-material.js.map +1 -0
- package/dist/three/frame/index.d.ts +39 -0
- package/dist/three/frame/index.js +35 -0
- package/dist/three/frame/index.js.map +1 -0
- package/dist/three/frame/inject-material.d.ts +56 -0
- package/dist/three/frame/inject-material.js +424 -0
- package/dist/three/frame/inject-material.js.map +1 -0
- package/dist/three/frame/integrate-material.d.ts +26 -0
- package/dist/three/frame/integrate-material.js +198 -0
- package/dist/three/frame/integrate-material.js.map +1 -0
- package/dist/three/frame/layout.d.ts +34 -0
- package/dist/three/frame/layout.js +48 -0
- package/dist/three/frame/layout.js.map +1 -0
- package/dist/three/frame/lighting-material.d.ts +41 -0
- package/dist/three/frame/lighting-material.js +257 -0
- package/dist/three/frame/lighting-material.js.map +1 -0
- package/dist/three/frame/lights.d.ts +11 -0
- package/dist/three/frame/lights.js +16 -0
- package/dist/three/frame/lights.js.map +1 -0
- package/dist/three/frame/medium.d.ts +21 -0
- package/dist/three/frame/medium.js +29 -0
- package/dist/three/frame/medium.js.map +1 -0
- package/dist/three/frame/neural.d.ts +14 -0
- package/dist/three/frame/neural.js +105 -0
- package/dist/three/frame/neural.js.map +1 -0
- package/dist/three/frame/phase.d.ts +44 -0
- package/dist/three/frame/phase.js +80 -0
- package/dist/three/frame/phase.js.map +1 -0
- package/dist/three/frame/renderer.d.ts +493 -0
- package/dist/three/frame/renderer.js +1498 -0
- package/dist/three/frame/renderer.js.map +1 -0
- package/dist/three/frame/shadow-density-material.d.ts +30 -0
- package/dist/three/frame/shadow-density-material.js +123 -0
- package/dist/three/frame/shadow-density-material.js.map +1 -0
- package/dist/three/frame/spectrum.d.ts +18 -0
- package/dist/three/frame/spectrum.js +36 -0
- package/dist/three/frame/spectrum.js.map +1 -0
- package/dist/three/frame/temporal-material.d.ts +29 -0
- package/dist/three/frame/temporal-material.js +152 -0
- package/dist/three/frame/temporal-material.js.map +1 -0
- package/dist/three/frame/three-internals.d.ts +65 -0
- package/dist/three/frame/three-internals.js +150 -0
- package/dist/three/frame/three-internals.js.map +1 -0
- package/dist/three/frame/transmittance-material.d.ts +31 -0
- package/dist/three/frame/transmittance-material.js +315 -0
- package/dist/three/frame/transmittance-material.js.map +1 -0
- package/dist/three/frame/view.d.ts +103 -0
- package/dist/three/frame/view.js +296 -0
- package/dist/three/frame/view.js.map +1 -0
- package/dist/three/frame/volume-shadow-material.d.ts +36 -0
- package/dist/three/frame/volume-shadow-material.js +128 -0
- package/dist/three/frame/volume-shadow-material.js.map +1 -0
- package/dist/three/frame/volume-shadows.d.ts +153 -0
- package/dist/three/frame/volume-shadows.js +756 -0
- package/dist/three/frame/volume-shadows.js.map +1 -0
- package/dist/three/frame/volume.d.ts +172 -0
- package/dist/three/frame/volume.js +256 -0
- package/dist/three/frame/volume.js.map +1 -0
- package/dist/three/grid-node.d.ts +196 -0
- package/dist/three/grid-node.js +510 -0
- package/dist/three/grid-node.js.map +1 -0
- package/dist/three/index.d.ts +43 -0
- package/dist/three/index.js +49 -0
- package/dist/three/index.js.map +1 -0
- package/dist/three/internal.d.ts +14 -0
- package/dist/three/internal.js +14 -0
- package/dist/three/internal.js.map +1 -0
- package/dist/three/level-set-material.d.ts +112 -0
- package/dist/three/level-set-material.js +204 -0
- package/dist/three/level-set-material.js.map +1 -0
- package/dist/three/material.d.ts +194 -0
- package/dist/three/material.js +359 -0
- package/dist/three/material.js.map +1 -0
- package/dist/three/points.d.ts +84 -0
- package/dist/three/points.js +130 -0
- package/dist/three/points.js.map +1 -0
- package/dist/three/sequence.d.ts +317 -0
- package/dist/three/sequence.js +526 -0
- package/dist/three/sequence.js.map +1 -0
- package/dist/three/sparse-source.d.ts +233 -0
- package/dist/three/sparse-source.js +876 -0
- package/dist/three/sparse-source.js.map +1 -0
- package/dist/three/volume-source.d.ts +167 -0
- package/dist/three/volume-source.js +353 -0
- package/dist/three/volume-source.js.map +1 -0
- package/dist/tools/cpu/compute.d.ts +97 -0
- package/dist/tools/cpu/compute.js +218 -0
- package/dist/tools/cpu/compute.js.map +1 -0
- package/dist/tools/cpu/level-set.d.ts +72 -0
- package/dist/tools/cpu/level-set.js +261 -0
- package/dist/tools/cpu/level-set.js.map +1 -0
- package/dist/tools/cpu/march.d.ts +206 -0
- package/dist/tools/cpu/march.js +575 -0
- package/dist/tools/cpu/march.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 +31 -0
- package/dist/tools/cpu/read-value.js +336 -0
- package/dist/tools/cpu/read-value.js.map +1 -0
- package/dist/tools/cpu/sample-trilinear.d.ts +30 -0
- package/dist/tools/cpu/sample-trilinear.js +156 -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 +1058 -0
- package/dist/tools/cpu/stride-tables.generated.js +1266 -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/errors.d.ts +57 -0
- package/dist/tools/errors.js +58 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/frame/blackbody.d.ts +42 -0
- package/dist/tools/frame/blackbody.js +116 -0
- package/dist/tools/frame/blackbody.js.map +1 -0
- package/dist/tools/frame/emission.d.ts +128 -0
- package/dist/tools/frame/emission.js +282 -0
- package/dist/tools/frame/emission.js.map +1 -0
- package/dist/tools/frame/environment.d.ts +105 -0
- package/dist/tools/frame/environment.js +268 -0
- package/dist/tools/frame/environment.js.map +1 -0
- package/dist/tools/frame/grid.d.ts +302 -0
- package/dist/tools/frame/grid.js +703 -0
- package/dist/tools/frame/grid.js.map +1 -0
- package/dist/tools/frame/index.d.ts +136 -0
- package/dist/tools/frame/index.js +348 -0
- package/dist/tools/frame/index.js.map +1 -0
- package/dist/tools/frame/medium.d.ts +61 -0
- package/dist/tools/frame/medium.js +99 -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 +54 -0
- package/dist/tools/frame/mie.js +176 -0
- package/dist/tools/frame/mie.js.map +1 -0
- package/dist/tools/frame/neural-weights.d.ts +9 -0
- package/dist/tools/frame/neural-weights.js +245 -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/pyramid-layout.d.ts +38 -0
- package/dist/tools/frame/pyramid-layout.js +53 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -0
- package/dist/tools/frame/shadows.d.ts +80 -0
- package/dist/tools/frame/shadows.js +182 -0
- package/dist/tools/frame/shadows.js.map +1 -0
- package/dist/tools/frame/sparse.d.ts +65 -0
- package/dist/tools/frame/sparse.js +191 -0
- package/dist/tools/frame/sparse.js.map +1 -0
- package/dist/tools/frame/spectral.d.ts +203 -0
- package/dist/tools/frame/spectral.js +550 -0
- package/dist/tools/frame/spectral.js.map +1 -0
- package/dist/tools/index.d.ts +106 -0
- package/dist/tools/index.js +88 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/internal.d.ts +46 -0
- package/dist/tools/internal.js +31 -0
- package/dist/tools/internal.js.map +1 -0
- package/dist/tools/nanovdb/build-from-vdb.d.ts +50 -0
- package/dist/tools/nanovdb/build-from-vdb.js +92 -0
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
- package/dist/tools/nanovdb/bytes.d.ts +220 -0
- package/dist/tools/nanovdb/bytes.js +345 -0
- package/dist/tools/nanovdb/bytes.js.map +1 -0
- package/dist/tools/nanovdb/coarse-first.d.ts +62 -0
- package/dist/tools/nanovdb/coarse-first.js +86 -0
- package/dist/tools/nanovdb/coarse-first.js.map +1 -0
- package/dist/tools/nanovdb/index.d.ts +32 -0
- package/dist/tools/nanovdb/index.js +24 -0
- package/dist/tools/nanovdb/index.js.map +1 -0
- package/dist/tools/nanovdb/inspect.d.ts +24 -0
- package/dist/tools/nanovdb/inspect.js +63 -0
- package/dist/tools/nanovdb/inspect.js.map +1 -0
- package/dist/tools/nanovdb/leaf-codec.d.ts +85 -0
- package/dist/tools/nanovdb/leaf-codec.js +320 -0
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
- package/dist/tools/nanovdb/quantize.d.ts +43 -0
- package/dist/tools/nanovdb/quantize.js +277 -0
- package/dist/tools/nanovdb/quantize.js.map +1 -0
- package/dist/tools/nanovdb/resample.d.ts +160 -0
- package/dist/tools/nanovdb/resample.js +679 -0
- package/dist/tools/nanovdb/resample.js.map +1 -0
- package/dist/tools/nanovdb/serialize.d.ts +145 -0
- package/dist/tools/nanovdb/serialize.js +395 -0
- package/dist/tools/nanovdb/serialize.js.map +1 -0
- package/dist/tools/nanovdb/stats.d.ts +58 -0
- package/dist/tools/nanovdb/stats.js +149 -0
- package/dist/tools/nanovdb/stats.js.map +1 -0
- package/dist/tools/nanovdb/transform.d.ts +26 -0
- package/dist/tools/nanovdb/transform.js +91 -0
- package/dist/tools/nanovdb/transform.js.map +1 -0
- package/dist/tools/nanovdb/tree.d.ts +175 -0
- package/dist/tools/nanovdb/tree.js +518 -0
- package/dist/tools/nanovdb/tree.js.map +1 -0
- package/dist/tools/nanovdb/write-nvdb.d.ts +39 -0
- package/dist/tools/nanovdb/write-nvdb.js +210 -0
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
- package/dist/tools/nvdb-file.d.ts +195 -0
- package/dist/tools/nvdb-file.js +606 -0
- package/dist/tools/nvdb-file.js.map +1 -0
- package/dist/tools/nvdb-stream.d.ts +138 -0
- package/dist/tools/nvdb-stream.js +365 -0
- package/dist/tools/nvdb-stream.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.d.ts +56 -0
- package/dist/tools/vdb/blosc.js +231 -0
- package/dist/tools/vdb/blosc.js.map +1 -0
- package/dist/tools/vdb/byte-reader.d.ts +40 -0
- package/dist/tools/vdb/byte-reader.js +139 -0
- package/dist/tools/vdb/byte-reader.js.map +1 -0
- package/dist/tools/vdb/compression.d.ts +73 -0
- package/dist/tools/vdb/compression.js +249 -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 +147 -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 +3 -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/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 +25 -0
- package/dist/tools/vdb/parse.js +171 -0
- package/dist/tools/vdb/parse.js.map +1 -0
- package/dist/tools/vdb/point-render-data.d.ts +31 -0
- package/dist/tools/vdb/point-render-data.js +57 -0
- package/dist/tools/vdb/point-render-data.js.map +1 -0
- package/dist/tools/vdb/points.d.ts +160 -0
- package/dist/tools/vdb/points.js +794 -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 +138 -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 +116 -0
- package/dist/tools/wvdb/bake.js +311 -0
- package/dist/tools/wvdb/bake.js.map +1 -0
- package/dist/tools/wvdb/dense.d.ts +112 -0
- package/dist/tools/wvdb/dense.js +309 -0
- package/dist/tools/wvdb/dense.js.map +1 -0
- package/dist/tools/wvdb/format.d.ts +161 -0
- package/dist/tools/wvdb/format.js +303 -0
- package/dist/tools/wvdb/format.js.map +1 -0
- package/dist/tools/wvdb/index.d.ts +13 -0
- package/dist/tools/wvdb/index.js +14 -0
- package/dist/tools/wvdb/index.js.map +1 -0
- package/dist/tools/wvdb/level-set.d.ts +48 -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 +54 -0
- package/dist/tools/wvdb/nanovdb.js +60 -0
- package/dist/tools/wvdb/nanovdb.js.map +1 -0
- package/dist/tools/wvdb/read.d.ts +260 -0
- package/dist/tools/wvdb/read.js +743 -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 +127 -0
- package/dist/tools/wvdb/write.js +396 -0
- package/dist/tools/wvdb/write.js.map +1 -0
- package/package.json +82 -4
- package/vendor/LICENSE +201 -0
- package/vendor/NOTICE +19 -0
- package/vendor/VENDOR.md +85 -0
- package/vendor/pnanovdb.wgsl +1539 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
|
|
2
|
+
// src/three-openvdb/frame/webgpu/frameShaderChunks.js L65–66 (min/maxComponent), L729–763
|
|
3
|
+
// (createVolumeUniforms), L765–798 (setMipUniforms), L834–1028 (createVolumeNodes);
|
|
4
|
+
// src/three-openvdb/frame/core/FrameVolume.js L14–22, L357–405 (Data3DTexture setup);
|
|
5
|
+
// src/three-openvdb/frame/webgpu/FrameRenderer.js L483–487 (configureTexture);
|
|
6
|
+
// src/three-openvdb/frame/webgpu/frameMipmaps.js L183–189 (mip atlas texture).
|
|
7
|
+
// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
|
|
8
|
+
// Changes: TypeScript; absent channels compile to constants instead of runtime flags; the
|
|
9
|
+
// Shadertoy blackbody is not ported (emission colour is a caller hook; his 'planck' / 'soot' table is
|
|
10
|
+
// `vdbFrameBlackbodyEmission`, on an analytic CIE fit: D33).
|
|
11
|
+
// Divergences: DIVERGES.md V23–V25.
|
|
12
|
+
/**
|
|
13
|
+
* The dense `.wvdb` volume source in three (K3.0, R1 §4.2).
|
|
14
|
+
*
|
|
15
|
+
* const file = readWvdb(bytes);
|
|
16
|
+
* const volume = wvdbDenseVolume(file); // @pmndrs/vdb/tools: his 8-bit texels + mip atlas
|
|
17
|
+
* const source = vdbDenseTextures(volume); // three Data3DTextures, set up as his FrameVolume
|
|
18
|
+
* const uniforms = vdbVolumeUniforms(source, { extinction: 100 });
|
|
19
|
+
* const nodes = vdbVolumeNodes(source, uniforms, { useMipmaps: true });
|
|
20
|
+
* // inside a TSL Fn: nodes.sampleExtinction(localPos, lod), nodes.sampleAlbedo(...), nodes.boxSegment(...)
|
|
21
|
+
*
|
|
22
|
+
* `vdbVolumeNodes` returns the shape of his `createVolumeNodes()` (`getLod`,
|
|
23
|
+
* `sampleExtinction`, `sampleAlbedo`, `sampleEmission`, `insideBox`, `boxExit`,
|
|
24
|
+
* `boxSegment`), so the K3 port of his materials changes one import per file.
|
|
25
|
+
* Positions are in the local unit box [-0.5, 0.5]³.
|
|
26
|
+
*/
|
|
27
|
+
import * as THREE from "three";
|
|
28
|
+
import { If, abs, ceil, clamp, exp2, float, floor, fract, log2, max, min, mix, mod, pow, select, texture3D, uniform, vec2, vec3, vec4, } from "three/tsl";
|
|
29
|
+
import { VDBError } from "../core/errors.js";
|
|
30
|
+
const CHANNELS = ["density", "mask", "albedo", "emission"];
|
|
31
|
+
/**
|
|
32
|
+
* FrameVolume.js L14–22 `createTexture3D` + FrameRenderer.js L483–487
|
|
33
|
+
* `configureTexture` (and frameMipmaps.js L183–189 for the atlas): an 8-bit
|
|
34
|
+
* `Data3DTexture`, `RedFormat` or `RGBAFormat`, `unpackAlignment` 1, linear
|
|
35
|
+
* min/mag, no mipmaps, default clamp-to-edge wrapping.
|
|
36
|
+
*/
|
|
37
|
+
function texture3DFrom(data, dims, texelBytes) {
|
|
38
|
+
const [w, h, d] = dims;
|
|
39
|
+
const texture = new THREE.Data3DTexture(data, w, h, d);
|
|
40
|
+
texture.format = texelBytes === 4 ? THREE.RGBAFormat : THREE.RedFormat;
|
|
41
|
+
texture.type = THREE.UnsignedByteType;
|
|
42
|
+
texture.unpackAlignment = 1;
|
|
43
|
+
texture.minFilter = THREE.LinearFilter;
|
|
44
|
+
texture.magFilter = THREE.LinearFilter;
|
|
45
|
+
texture.generateMipmaps = false;
|
|
46
|
+
texture.needsUpdate = true;
|
|
47
|
+
return texture;
|
|
48
|
+
}
|
|
49
|
+
function channelTextures(tex) {
|
|
50
|
+
if (!tex)
|
|
51
|
+
return null;
|
|
52
|
+
return {
|
|
53
|
+
map: texture3DFrom(tex.data, tex.dimensions, tex.texelBytes),
|
|
54
|
+
mip: tex.mip ? texture3DFrom(tex.mip.data, tex.mip.dimensions, tex.texelBytes) : null,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** K5.9: a channel's absent value (mask and albedo 1, emission 0) as a texture of the density's size (and mip atlas). */
|
|
58
|
+
function constantChannel(name, t, density) {
|
|
59
|
+
const texelBytes = t.map.format === THREE.RGBAFormat ? 4 : 1;
|
|
60
|
+
const value = name === "emission" ? 0 : 255;
|
|
61
|
+
const fill = (dims) => new Uint8Array(dims[0] * dims[1] * dims[2] * texelBytes).fill(value);
|
|
62
|
+
const mip = t.mip && density.mip ? { data: fill(density.mip.dimensions), dimensions: density.mip.dimensions, levels: density.mip.levels } : null;
|
|
63
|
+
return { data: fill(density.dimensions), dimensions: density.dimensions, format: texelBytes === 4 ? "rgba8unorm" : "r8unorm", texelBytes, mip };
|
|
64
|
+
}
|
|
65
|
+
const channelsOf = (v) => ({
|
|
66
|
+
density: v.density,
|
|
67
|
+
mask: v.mask,
|
|
68
|
+
albedo: v.albedo,
|
|
69
|
+
emission: v.emission,
|
|
70
|
+
});
|
|
71
|
+
class ThreeDenseSource {
|
|
72
|
+
kind = "dense";
|
|
73
|
+
boxToSource = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.5, 0.5, 0.5, 1]);
|
|
74
|
+
channels;
|
|
75
|
+
volume;
|
|
76
|
+
textures;
|
|
77
|
+
texels;
|
|
78
|
+
lodLevels;
|
|
79
|
+
stats;
|
|
80
|
+
version = 0;
|
|
81
|
+
warnedExtra = new Set();
|
|
82
|
+
constructor(volume) {
|
|
83
|
+
this.volume = volume;
|
|
84
|
+
this.channels = { mask: !!volume.mask, albedo: !!volume.albedo, emission: !!volume.emission };
|
|
85
|
+
const c = channelsOf(volume);
|
|
86
|
+
this.textures = { density: channelTextures(c.density), mask: channelTextures(c.mask), albedo: channelTextures(c.albedo), emission: channelTextures(c.emission) };
|
|
87
|
+
this.texels = [...volume.dimensions];
|
|
88
|
+
this.lodLevels = volume.density.mip?.levels ?? 0;
|
|
89
|
+
this.stats = { meanNonZero: volume.meanDensity, max: volume.maxDensity, activeVoxels: volume.activeTexels };
|
|
90
|
+
}
|
|
91
|
+
replace(volume) {
|
|
92
|
+
if (!volume || volume.kind !== "dense" || !volume.density) {
|
|
93
|
+
throw new VDBError("VDB_BAD_OPTION", "vdbDenseTextures.replace: pass a dense volume from wvdbDenseVolume() (@pmndrs/vdb/tools).");
|
|
94
|
+
}
|
|
95
|
+
const next = channelsOf(volume);
|
|
96
|
+
const densityMip = next.density.mip;
|
|
97
|
+
if (!!this.textures.density.mip !== !!densityMip && this.textures.density.mip) {
|
|
98
|
+
throw new VDBError("VDB_BAD_OPTION", "vdbDenseTextures.replace: the frame's density has no mip atlas but the source's has; bake every frame with mipmaps, or make the source without.");
|
|
99
|
+
}
|
|
100
|
+
// K5.9 (sequences): a channel the source has and the frame lacks reads its absent value (mask and albedo 1,
|
|
101
|
+
// emission 0) from a constant texture of the frame's size; a channel (or mip atlas) the source lacks is ignored,
|
|
102
|
+
// since the shaders were built without it (warned once: make the source from a frame that has every channel).
|
|
103
|
+
for (const name of CHANNELS) {
|
|
104
|
+
const t = this.textures[name];
|
|
105
|
+
const v = next[name];
|
|
106
|
+
if (!t && v) {
|
|
107
|
+
if (!this.warnedExtra.has(name)) {
|
|
108
|
+
this.warnedExtra.add(name);
|
|
109
|
+
console.warn(`vdbDenseTextures.replace: the frame has a ${name} channel the source was made without; it is ignored.`);
|
|
110
|
+
}
|
|
111
|
+
next[name] = null;
|
|
112
|
+
}
|
|
113
|
+
else if (t && !v) {
|
|
114
|
+
next[name] = constantChannel(name, t, next.density);
|
|
115
|
+
}
|
|
116
|
+
else if (t && v && !!t.mip !== !!v.mip) {
|
|
117
|
+
if (t.mip)
|
|
118
|
+
throw new VDBError("VDB_BAD_OPTION", `vdbDenseTextures.replace: the frame's ${name} channel has no mip atlas but the source's has; make a new source.`);
|
|
119
|
+
next[name] = { ...v, mip: null };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// WVDBLoader.js L37–48 updateTexture: a new size disposes the GPU texture first.
|
|
123
|
+
let resized = false;
|
|
124
|
+
for (const name of CHANNELS) {
|
|
125
|
+
const t = this.textures[name];
|
|
126
|
+
const v = next[name];
|
|
127
|
+
if (!t || !v)
|
|
128
|
+
continue;
|
|
129
|
+
const set = (tex, data, dims) => {
|
|
130
|
+
const [width, height, depth] = dims;
|
|
131
|
+
const img = tex.image;
|
|
132
|
+
const changed = img.width !== width || img.height !== height || img.depth !== depth;
|
|
133
|
+
tex.image = { data, width, height, depth };
|
|
134
|
+
if (changed) {
|
|
135
|
+
tex.dispose();
|
|
136
|
+
resized = true;
|
|
137
|
+
}
|
|
138
|
+
tex.needsUpdate = true;
|
|
139
|
+
};
|
|
140
|
+
set(t.map, v.data, v.dimensions);
|
|
141
|
+
if (t.mip && v.mip)
|
|
142
|
+
set(t.mip, v.mip.data, v.mip.dimensions);
|
|
143
|
+
}
|
|
144
|
+
// A frame with another world box (his WVDB sequences give each frame its own) also bumps `version`, so a
|
|
145
|
+
// VDBFrameVolume whose box is the source's moves its box (an empty frame's null box keeps the last one).
|
|
146
|
+
const a = this.volume.bbox;
|
|
147
|
+
const b = volume.bbox;
|
|
148
|
+
const moved = !!b && (!a || a.some((corner, i) => corner.some((v, k) => v !== b[i][k])));
|
|
149
|
+
if (resized || moved)
|
|
150
|
+
this.version++;
|
|
151
|
+
this.volume = volume;
|
|
152
|
+
this.texels = [...volume.dimensions];
|
|
153
|
+
this.lodLevels = this.textures.density.mip ? (volume.density.mip?.levels ?? 0) : 0;
|
|
154
|
+
this.stats = { meanNonZero: volume.meanDensity, max: volume.maxDensity, activeVoxels: volume.activeTexels };
|
|
155
|
+
}
|
|
156
|
+
dispose() {
|
|
157
|
+
for (const t of Object.values(this.textures)) {
|
|
158
|
+
t?.map.dispose();
|
|
159
|
+
t?.mip?.dispose();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** Upload a dense volume (`wvdbDenseVolume`, `@pmndrs/vdb/tools`) as three textures, set up as his `FrameVolume` does. */
|
|
164
|
+
export function vdbDenseTextures(volume) {
|
|
165
|
+
if (!volume || volume.kind !== "dense" || !volume.density) {
|
|
166
|
+
throw new VDBError("VDB_BAD_OPTION", "vdbDenseTextures: pass a dense volume from wvdbDenseVolume() (@pmndrs/vdb/tools).");
|
|
167
|
+
}
|
|
168
|
+
return new ThreeDenseSource(volume);
|
|
169
|
+
}
|
|
170
|
+
/** FrameVolume.js L561–568 `getDensityScale`. */
|
|
171
|
+
export const vdbDensityScaleOf = (source, densityScale, normalize) => normalize && source.stats.meanNonZero > 0 ? densityScale / source.stats.meanNonZero : densityScale;
|
|
172
|
+
const densityScaleOf = vdbDensityScaleOf;
|
|
173
|
+
/**
|
|
174
|
+
* Live uniforms for one source (his `createVolumeUniforms` + `setVolumeUniforms` + `setMipUniforms`).
|
|
175
|
+
* A sparse source makes its own (`source.createUniforms`), with the same fields.
|
|
176
|
+
*/
|
|
177
|
+
export function vdbVolumeUniforms(source, p = {}) {
|
|
178
|
+
if (source.kind === "sparse")
|
|
179
|
+
return source.createUniforms(p);
|
|
180
|
+
const tex = source.textures;
|
|
181
|
+
let densityScale = p.densityScale ?? 1.0;
|
|
182
|
+
let normalize = p.normalizeDensity ?? true;
|
|
183
|
+
const maps = {};
|
|
184
|
+
const mipMaps = {};
|
|
185
|
+
const mipLevels = {};
|
|
186
|
+
for (const name of CHANNELS) {
|
|
187
|
+
maps[name] = tex[name] ? texture3D(tex[name].map) : null;
|
|
188
|
+
mipMaps[name] = tex[name]?.mip ? texture3D(tex[name].mip) : null;
|
|
189
|
+
mipLevels[name] = uniform(0.0);
|
|
190
|
+
}
|
|
191
|
+
const gridTexels = uniform(new THREE.Vector3(1, 1, 1));
|
|
192
|
+
const mipAtlasSize = uniform(new THREE.Vector3(1, 1, 1));
|
|
193
|
+
const densityScaleU = uniform(densityScaleOf(source, densityScale, normalize));
|
|
194
|
+
const u = {
|
|
195
|
+
worldScale: uniform(p.worldScale ?? 1.0),
|
|
196
|
+
gridTexels,
|
|
197
|
+
mipAtlasSize,
|
|
198
|
+
maps,
|
|
199
|
+
mipMaps,
|
|
200
|
+
mipLevels,
|
|
201
|
+
baseColor: uniform(new THREE.Color(p.baseColor ?? 0xffffff)),
|
|
202
|
+
extinction: uniform(p.extinction ?? 100.0),
|
|
203
|
+
densityScale: densityScaleU,
|
|
204
|
+
densityCutoff: uniform(p.densityCutoff ?? 0.0),
|
|
205
|
+
emissiveIntensity: uniform(p.emissiveIntensity ?? 1.0),
|
|
206
|
+
temperatureRange: uniform(new THREE.Vector2(...(p.temperatureRange ?? [0.0, 6500.0]))),
|
|
207
|
+
offset3D: uniform(new THREE.Vector3().copy((p.offset3D ?? { x: 0, y: 0, z: 0 }))),
|
|
208
|
+
wrap3D: uniform(p.wrap3D ?? THREE.ClampToEdgeWrapping, "int"),
|
|
209
|
+
update(s0, o = {}) {
|
|
210
|
+
if (s0.kind !== "dense")
|
|
211
|
+
throw new VDBError("VDB_BAD_OPTION", "vdbVolumeUniforms: these uniforms belong to a dense source.");
|
|
212
|
+
const s = s0;
|
|
213
|
+
if (o.densityScale !== undefined)
|
|
214
|
+
densityScale = o.densityScale;
|
|
215
|
+
if (o.normalizeDensity !== undefined)
|
|
216
|
+
normalize = o.normalizeDensity;
|
|
217
|
+
densityScaleU.value = densityScaleOf(s, densityScale, normalize);
|
|
218
|
+
const [w, h, d] = s.texels;
|
|
219
|
+
gridTexels.value.set(w, h, d);
|
|
220
|
+
const densityMip = s.textures.density?.mip;
|
|
221
|
+
if (densityMip) {
|
|
222
|
+
const img = densityMip.image;
|
|
223
|
+
mipAtlasSize.value.set(img.width, img.height, img.depth);
|
|
224
|
+
}
|
|
225
|
+
for (const name of CHANNELS) {
|
|
226
|
+
const t = s.textures[name];
|
|
227
|
+
if (t && maps[name])
|
|
228
|
+
maps[name].value = t.map;
|
|
229
|
+
if (t?.mip && mipMaps[name])
|
|
230
|
+
mipMaps[name].value = t.mip;
|
|
231
|
+
// Every channel shares the density size (wvdbDenseVolume checks it), so all levels are the mip's.
|
|
232
|
+
// A channel the frame lacks (K5.9: a constant texture) has the density's levels.
|
|
233
|
+
mipLevels[name].value = densityMip && t?.mip ? (s.volume[name]?.mip?.levels ?? s.volume.density.mip?.levels ?? 0) : 0;
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
dispose() {
|
|
237
|
+
// A dense source registers nothing.
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
u.update(source);
|
|
241
|
+
return u;
|
|
242
|
+
}
|
|
243
|
+
/** frameShaderChunks.js L65–66. */
|
|
244
|
+
export const vdbMinComponent = (v) => min(v.x, min(v.y, v.z));
|
|
245
|
+
export const vdbMaxComponent = (v) => max(v.x, max(v.y, v.z));
|
|
246
|
+
/**
|
|
247
|
+
* Sampling of one dense source, in his `createVolumeNodes` shape. Call the
|
|
248
|
+
* sample functions inside a TSL `Fn` body. Absent channels give his fallbacks
|
|
249
|
+
* (mask 1, albedo `baseColor`, emission 0) without sampling.
|
|
250
|
+
*/
|
|
251
|
+
/**
|
|
252
|
+
* His mip sampling (frameShaderChunks.js L838–872) over one texture and its box mip atlas:
|
|
253
|
+
* `sampleMipAtlas` (level 1 and up, frameMipmaps.js layout) and `sampleMipmapped` (linear between
|
|
254
|
+
* two levels). `gridTexels` is the size of `map` (level 0 of this chain), `mipAtlasSize` the atlas's.
|
|
255
|
+
* Shared by the dense source and the sparse source's coarse pyramid. Call in a TSL Fn body.
|
|
256
|
+
*/
|
|
257
|
+
export function vdbMipSampler(gridTexels, mipAtlasSize) {
|
|
258
|
+
// L838–846: level 1 and up of the mip atlas (layout of frameMipmaps.js).
|
|
259
|
+
const sampleMipAtlas = (mipMap, level, uvw) => {
|
|
260
|
+
const size = max(vec3(1.0), ceil(gridTexels.div(exp2(level))));
|
|
261
|
+
const offset = mipAtlasSize.x.sub(mipAtlasSize.x.div(exp2(level.sub(1.0))));
|
|
262
|
+
const texel = clamp(uvw.mul(size), vec3(0.5), size.sub(0.5));
|
|
263
|
+
return mipMap.sample(vec3(texel.x.add(offset), texel.y, texel.z).div(mipAtlasSize)).level(float(0.0));
|
|
264
|
+
};
|
|
265
|
+
// L849–872: linear between two mip levels (LinearMipmapLinearFilter).
|
|
266
|
+
const sampleMipmapped = (map, mipMap, levels, position, lod) => {
|
|
267
|
+
const uvw = vec3(position).toVar();
|
|
268
|
+
const result = vec4(0.0).toVar();
|
|
269
|
+
const level = min(lod, levels).toVar();
|
|
270
|
+
If(level.lessThanEqual(0.0), () => {
|
|
271
|
+
result.assign(map.sample(uvw).level(float(0.0)));
|
|
272
|
+
}).Else(() => {
|
|
273
|
+
const level0 = floor(level).toVar();
|
|
274
|
+
const low = vec4(0.0).toVar();
|
|
275
|
+
If(level0.lessThan(0.5), () => {
|
|
276
|
+
low.assign(map.sample(uvw).level(float(0.0)));
|
|
277
|
+
}).Else(() => {
|
|
278
|
+
low.assign(sampleMipAtlas(mipMap, level0, uvw));
|
|
279
|
+
});
|
|
280
|
+
const high = sampleMipAtlas(mipMap, min(level0.add(1.0), levels), uvw);
|
|
281
|
+
result.assign(mix(low, high, level.sub(level0)));
|
|
282
|
+
});
|
|
283
|
+
return result;
|
|
284
|
+
};
|
|
285
|
+
return { sampleMipAtlas, sampleMipmapped };
|
|
286
|
+
}
|
|
287
|
+
/** His `wrapUv` / `gridUv` (frameShaderChunks.js L894–911): the local position as a wrapped, offset uvw. */
|
|
288
|
+
export function vdbGridUv(u) {
|
|
289
|
+
const T = THREE;
|
|
290
|
+
const mirrorAxis = (value) => {
|
|
291
|
+
const period = mod(value, 2.0);
|
|
292
|
+
return select(period.greaterThan(1.0), float(2.0).sub(period), period);
|
|
293
|
+
};
|
|
294
|
+
const wrapUv = (uvw) => select(u.wrap3D.equal(T.RepeatWrapping), fract(uvw), select(u.wrap3D.equal(T.MirroredRepeatWrapping), vec3(mirrorAxis(uvw.x), mirrorAxis(uvw.y), mirrorAxis(uvw.z)), uvw));
|
|
295
|
+
return (localPosition) => wrapUv(localPosition.add(0.5).add(u.offset3D));
|
|
296
|
+
}
|
|
297
|
+
/** His box geometry (frameShaderChunks.js L938–958): `insideBox`, `boxExit`, `boxSegment` of the local unit box. */
|
|
298
|
+
export const vdbBoxNodes = {
|
|
299
|
+
insideBox: (localPosition) => vdbMaxComponent(abs(localPosition)).lessThanEqual(0.5),
|
|
300
|
+
boxExit: (origin, direction) => {
|
|
301
|
+
const inverseDirection = vec3(1.0).div(direction);
|
|
302
|
+
const tMin = vec3(-0.5).sub(origin).mul(inverseDirection);
|
|
303
|
+
const tMax = vec3(0.5).sub(origin).mul(inverseDirection);
|
|
304
|
+
return max(0.0, vdbMinComponent(max(tMin, tMax)));
|
|
305
|
+
},
|
|
306
|
+
boxSegment: (start, end) => {
|
|
307
|
+
const inverseDirection = vec3(1.0).div(end.sub(start));
|
|
308
|
+
const tMin = vec3(-0.5).sub(start).mul(inverseDirection);
|
|
309
|
+
const tMax = vec3(0.5).sub(start).mul(inverseDirection);
|
|
310
|
+
return vec2(max(0.0, vdbMaxComponent(min(tMin, tMax))), min(1.0, vdbMinComponent(max(tMin, tMax))));
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
export function vdbVolumeNodes(source, u, o = {}) {
|
|
314
|
+
if (source.kind === "sparse")
|
|
315
|
+
return source.createNodes(u, o);
|
|
316
|
+
const useMipmaps = o.useMipmaps ?? source.lodLevels > 0;
|
|
317
|
+
const { gridTexels, mipAtlasSize } = u;
|
|
318
|
+
const { sampleMipmapped } = vdbMipSampler(gridTexels, mipAtlasSize);
|
|
319
|
+
// L874–877 sample3D (a channel without a mip atlas samples level 0).
|
|
320
|
+
const sample3D = (name, uvw, lod) => {
|
|
321
|
+
const map = u.maps[name];
|
|
322
|
+
const mip = u.mipMaps[name];
|
|
323
|
+
return useMipmaps && mip ? sampleMipmapped(map, mip, u.mipLevels[name], uvw, lod) : map.sample(uvw).level(float(0.0));
|
|
324
|
+
};
|
|
325
|
+
// L892
|
|
326
|
+
const getLod = (localSize) => max(0.0, log2(localSize.mul(vdbMaxComponent(gridTexels))));
|
|
327
|
+
// L894–911
|
|
328
|
+
const gridUv = vdbGridUv(u);
|
|
329
|
+
// L914–936: extinction per world unit. The mask is read at local + 0.5 (no offset or wrap), as his.
|
|
330
|
+
const sampleExtinction = (localPosition, lod) => {
|
|
331
|
+
const mask = source.channels.mask ? sample3D("mask", localPosition.add(0.5), lod).r : float(1.0);
|
|
332
|
+
const value = sample3D("density", gridUv(localPosition), lod).r.mul(mask);
|
|
333
|
+
return select(value.greaterThan(u.densityCutoff), value, float(0.0)).mul(u.densityScale).mul(u.extinction).div(u.worldScale);
|
|
334
|
+
};
|
|
335
|
+
// L938–958
|
|
336
|
+
const { insideBox, boxExit, boxSegment } = vdbBoxNodes;
|
|
337
|
+
// L960–971
|
|
338
|
+
const sampleAlbedo = (localPosition, lod) => source.channels.albedo ? u.baseColor.mul(sample3D("albedo", gridUv(localPosition), lod).rgb) : u.baseColor.mul(vec3(1.0));
|
|
339
|
+
// L990–1017, colour via the caller's hook (see VDBVolumeNodesOptions.emissionColor).
|
|
340
|
+
const emissionColor = o.emissionColor ?? (() => vec3(1.0));
|
|
341
|
+
const sampleEmission = (localPosition, lod) => {
|
|
342
|
+
if (!source.channels.emission)
|
|
343
|
+
return vec3(0.0);
|
|
344
|
+
const range = u.temperatureRange;
|
|
345
|
+
const value = sample3D("emission", gridUv(localPosition), lod).r;
|
|
346
|
+
const temperature = mix(range.x, range.y, value);
|
|
347
|
+
const power = pow(temperature.div(max(range.y, 1.0)), 4.0);
|
|
348
|
+
const color = select(temperature.greaterThan(0.0), emissionColor(temperature), vec3(0.0));
|
|
349
|
+
return color.mul(power).mul(u.emissiveIntensity);
|
|
350
|
+
};
|
|
351
|
+
return { getLod, sampleExtinction, sampleAlbedo, sampleEmission, insideBox, boxExit, boxSegment };
|
|
352
|
+
}
|
|
353
|
+
//# sourceMappingURL=volume-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volume-source.js","sourceRoot":"","sources":["../../src/three/volume-source.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,4FAA4F;AAC5F,sFAAsF;AACtF,wFAAwF;AACxF,iFAAiF;AACjF,iFAAiF;AACjF,4GAA4G;AAC5G,0FAA0F;AAC1F,sGAAsG;AACtG,6DAA6D;AAC7D,oCAAoC;AAEpC;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,EAAE,EACF,GAAG,EACH,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,EACN,SAAS,EACT,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,IAAI,GACL,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAM7C,MAAM,QAAQ,GAA2B,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;AAwBnF;;;;;GAKG;AACH,SAAS,aAAa,CAAC,IAA6B,EAAE,IAAuB,EAAE,UAAiB;IAC9F,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CA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C,CAAC,gBAAgB,CAAC;QACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,aAAa,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;QACjE,MAAM,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QACjD,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAC3D,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1F,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACnD,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AACpG,CAAC","sourcesContent":["// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):\n// src/three-openvdb/frame/webgpu/frameShaderChunks.js L65–66 (min/maxComponent), L729–763\n// (createVolumeUniforms), L765–798 (setMipUniforms), L834–1028 (createVolumeNodes);\n// src/three-openvdb/frame/core/FrameVolume.js L14–22, L357–405 (Data3DTexture setup);\n// src/three-openvdb/frame/webgpu/FrameRenderer.js L483–487 (configureTexture);\n// src/three-openvdb/frame/webgpu/frameMipmaps.js L183–189 (mip atlas texture).\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: TypeScript; absent channels compile to constants instead of runtime flags; the\n// Shadertoy blackbody is not ported (emission colour is a caller hook; his 'planck' / 'soot' table is\n// `vdbFrameBlackbodyEmission`, on an analytic CIE fit: D33).\n// Divergences: DIVERGES.md V23–V25.\n\n/**\n * The dense `.wvdb` volume source in three (K3.0, R1 §4.2).\n *\n * const file = readWvdb(bytes);\n * const volume = wvdbDenseVolume(file); // @pmndrs/vdb/tools: his 8-bit texels + mip atlas\n * const source = vdbDenseTextures(volume); // three Data3DTextures, set up as his FrameVolume\n * const uniforms = vdbVolumeUniforms(source, { extinction: 100 });\n * const nodes = vdbVolumeNodes(source, uniforms, { useMipmaps: true });\n * // inside a TSL Fn: nodes.sampleExtinction(localPos, lod), nodes.sampleAlbedo(...), nodes.boxSegment(...)\n *\n * `vdbVolumeNodes` returns the shape of his `createVolumeNodes()` (`getLod`,\n * `sampleExtinction`, `sampleAlbedo`, `sampleEmission`, `insideBox`, `boxExit`,\n * `boxSegment`), so the K3 port of his materials changes one import per file.\n * Positions are in the local unit box [-0.5, 0.5]³.\n */\n\nimport * as THREE from \"three\";\nimport {\n If,\n abs,\n ceil,\n clamp,\n exp2,\n float,\n floor,\n fract,\n log2,\n max,\n min,\n mix,\n mod,\n pow,\n select,\n texture3D,\n uniform,\n vec2,\n vec3,\n vec4,\n} from \"three/tsl\";\nimport { VDBError } from \"../core/errors.js\";\nimport type { VDBVolumeChannels, VDBVolumeSourceInfo } from \"../core/source/types.js\";\nimport type { WvdbDenseTexture, WvdbDenseVolume } from \"../tools/wvdb/dense.js\";\nimport type { VDBTslNode } from \"./grid-node.js\";\n\ntype ChannelName = \"density\" | \"mask\" | \"albedo\" | \"emission\";\nconst CHANNELS: readonly ChannelName[] = [\"density\", \"mask\", \"albedo\", \"emission\"];\n\n/** The three textures of one channel. */\nexport interface VDBDenseChannelTextures {\n readonly map: THREE.Data3DTexture;\n readonly mip: THREE.Data3DTexture | null;\n}\n\n/** A dense source as three textures (the descriptive part of `VDBVolumeSource`; no raw bindings). */\nexport interface VDBThreeDenseSource extends VDBVolumeSourceInfo {\n readonly kind: \"dense\";\n readonly volume: WvdbDenseVolume;\n readonly textures: Readonly<Record<ChannelName, VDBDenseChannelTextures | null>>;\n /**\n * Swap in another LOD or sequence frame. New sizes make new textures and bump `version`, and so does a frame with\n * another `.wvdb` box (a `VDBFrameVolume` follows by itself, its box too unless it was given a `bbox`; other users\n * call `uniforms.update(source)`). A channel the source has and the frame lacks reads its\n * absent value (mask and albedo 1, emission 0); a channel the source lacks is ignored (warned once). The density's\n * mip atlas must stay if the source has one.\n */\n replace(volume: WvdbDenseVolume): void;\n dispose(): void;\n}\n\n/**\n * FrameVolume.js L14–22 `createTexture3D` + FrameRenderer.js L483–487\n * `configureTexture` (and frameMipmaps.js L183–189 for the atlas): an 8-bit\n * `Data3DTexture`, `RedFormat` or `RGBAFormat`, `unpackAlignment` 1, linear\n * min/mag, no mipmaps, default clamp-to-edge wrapping.\n */\nfunction texture3DFrom(data: Uint8Array<ArrayBuffer>, dims: readonly number[], texelBytes: 1 | 4): THREE.Data3DTexture {\n const [w, h, d] = dims as [number, number, number];\n const texture = new THREE.Data3DTexture(data, w, h, d);\n texture.format = texelBytes === 4 ? THREE.RGBAFormat : THREE.RedFormat;\n texture.type = THREE.UnsignedByteType;\n texture.unpackAlignment = 1;\n texture.minFilter = THREE.LinearFilter;\n texture.magFilter = THREE.LinearFilter;\n texture.generateMipmaps = false;\n texture.needsUpdate = true;\n return texture;\n}\n\nfunction channelTextures(tex: WvdbDenseTexture | null): VDBDenseChannelTextures | null {\n if (!tex) return null;\n return {\n map: texture3DFrom(tex.data, tex.dimensions, tex.texelBytes),\n mip: tex.mip ? texture3DFrom(tex.mip.data, tex.mip.dimensions, tex.texelBytes) : null,\n };\n}\n\n/** K5.9: a channel's absent value (mask and albedo 1, emission 0) as a texture of the density's size (and mip atlas). */\nfunction constantChannel(name: ChannelName, t: VDBDenseChannelTextures, density: WvdbDenseTexture): WvdbDenseTexture {\n const texelBytes: 1 | 4 = t.map.format === THREE.RGBAFormat ? 4 : 1;\n const value = name === \"emission\" ? 0 : 255;\n const fill = (dims: readonly number[]) => new Uint8Array(dims[0]! * dims[1]! * dims[2]! * texelBytes).fill(value);\n const mip = t.mip && density.mip ? { data: fill(density.mip.dimensions), dimensions: density.mip.dimensions, levels: density.mip.levels } : null;\n return { data: fill(density.dimensions), dimensions: density.dimensions, format: texelBytes === 4 ? \"rgba8unorm\" : \"r8unorm\", texelBytes, mip };\n}\n\nconst channelsOf = (v: WvdbDenseVolume): Record<ChannelName, WvdbDenseTexture | null> => ({\n density: v.density,\n mask: v.mask,\n albedo: v.albedo,\n emission: v.emission,\n});\n\nclass ThreeDenseSource implements VDBThreeDenseSource {\n readonly kind = \"dense\" as const;\n readonly boxToSource = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.5, 0.5, 0.5, 1]);\n readonly channels: VDBVolumeChannels;\n volume: WvdbDenseVolume;\n textures: Record<ChannelName, VDBDenseChannelTextures | null>;\n texels: [number, number, number];\n lodLevels: number;\n stats: { meanNonZero: number; max: number; activeVoxels: number };\n version = 0;\n private readonly warnedExtra = new Set<ChannelName>();\n\n constructor(volume: WvdbDenseVolume) {\n this.volume = volume;\n this.channels = { mask: !!volume.mask, albedo: !!volume.albedo, emission: !!volume.emission };\n const c = channelsOf(volume);\n this.textures = { density: channelTextures(c.density), mask: channelTextures(c.mask), albedo: channelTextures(c.albedo), emission: channelTextures(c.emission) };\n this.texels = [...volume.dimensions] as [number, number, number];\n this.lodLevels = volume.density.mip?.levels ?? 0;\n this.stats = { meanNonZero: volume.meanDensity, max: volume.maxDensity, activeVoxels: volume.activeTexels };\n }\n\n replace(volume: WvdbDenseVolume): void {\n if (!volume || volume.kind !== \"dense\" || !volume.density) {\n throw new VDBError(\"VDB_BAD_OPTION\", \"vdbDenseTextures.replace: pass a dense volume from wvdbDenseVolume() (@pmndrs/vdb/tools).\");\n }\n const next = channelsOf(volume);\n const densityMip = next.density!.mip;\n if (!!this.textures.density!.mip !== !!densityMip && this.textures.density!.mip) {\n throw new VDBError(\"VDB_BAD_OPTION\", \"vdbDenseTextures.replace: the frame's density has no mip atlas but the source's has; bake every frame with mipmaps, or make the source without.\");\n }\n // K5.9 (sequences): a channel the source has and the frame lacks reads its absent value (mask and albedo 1,\n // emission 0) from a constant texture of the frame's size; a channel (or mip atlas) the source lacks is ignored,\n // since the shaders were built without it (warned once: make the source from a frame that has every channel).\n for (const name of CHANNELS) {\n const t = this.textures[name];\n const v = next[name];\n if (!t && v) {\n if (!this.warnedExtra.has(name)) {\n this.warnedExtra.add(name);\n console.warn(`vdbDenseTextures.replace: the frame has a ${name} channel the source was made without; it is ignored.`);\n }\n next[name] = null;\n } else if (t && !v) {\n next[name] = constantChannel(name, t, next.density!);\n } else if (t && v && !!t.mip !== !!v.mip) {\n if (t.mip) throw new VDBError(\"VDB_BAD_OPTION\", `vdbDenseTextures.replace: the frame's ${name} channel has no mip atlas but the source's has; make a new source.`);\n next[name] = { ...v, mip: null };\n }\n }\n // WVDBLoader.js L37–48 updateTexture: a new size disposes the GPU texture first.\n let resized = false;\n for (const name of CHANNELS) {\n const t = this.textures[name];\n const v = next[name];\n if (!t || !v) continue;\n const set = (tex: THREE.Data3DTexture, data: Uint8Array<ArrayBuffer>, dims: readonly number[]) => {\n const [width, height, depth] = dims as [number, number, number];\n const img = tex.image as { width: number; height: number; depth: number };\n const changed = img.width !== width || img.height !== height || img.depth !== depth;\n tex.image = { data, width, height, depth } as never;\n if (changed) {\n tex.dispose();\n resized = true;\n }\n tex.needsUpdate = true;\n };\n set(t.map, v.data, v.dimensions);\n if (t.mip && v.mip) set(t.mip, v.mip.data, v.mip.dimensions);\n }\n // A frame with another world box (his WVDB sequences give each frame its own) also bumps `version`, so a\n // VDBFrameVolume whose box is the source's moves its box (an empty frame's null box keeps the last one).\n const a = this.volume.bbox;\n const b = volume.bbox;\n const moved = !!b && (!a || a.some((corner, i) => corner.some((v, k) => v !== b[i]![k])));\n if (resized || moved) this.version++;\n this.volume = volume;\n this.texels = [...volume.dimensions] as [number, number, number];\n this.lodLevels = this.textures.density!.mip ? (volume.density.mip?.levels ?? 0) : 0;\n this.stats = { meanNonZero: volume.meanDensity, max: volume.maxDensity, activeVoxels: volume.activeTexels };\n }\n\n dispose(): void {\n for (const t of Object.values(this.textures)) {\n t?.map.dispose();\n t?.mip?.dispose();\n }\n }\n}\n\n/** Upload a dense volume (`wvdbDenseVolume`, `@pmndrs/vdb/tools`) as three textures, set up as his `FrameVolume` does. */\nexport function vdbDenseTextures(volume: WvdbDenseVolume): VDBThreeDenseSource {\n if (!volume || volume.kind !== \"dense\" || !volume.density) {\n throw new VDBError(\"VDB_BAD_OPTION\", \"vdbDenseTextures: pass a dense volume from wvdbDenseVolume() (@pmndrs/vdb/tools).\");\n }\n return new ThreeDenseSource(volume);\n}\n\n/**\n * The sparse source (`vdbSparseSource`, `./sparse-source.ts`) as far as this file needs it: it makes\n * its own uniforms and nodes (the K3.1 brief's `nodes(uniforms, options)` factory), so the frame\n * passes take either kind through {@link vdbVolumeUniforms} / {@link vdbVolumeNodes}.\n */\nexport interface VDBThreeSourceFactory extends VDBVolumeSourceInfo {\n readonly kind: \"sparse\";\n /** World box of the volume (`[min, max]`), the default `VDBFrameVolume` box. */\n readonly bbox: [[number, number, number], [number, number, number]];\n createUniforms(p: VDBVolumeUniformParameters): VDBVolumeUniforms;\n createNodes(u: VDBVolumeUniforms, o: VDBVolumeNodesOptions): VDBVolumeNodes;\n dispose(): void;\n}\n\n/** A volume source the three frame passes read: dense textures or the sparse pool. */\nexport type VDBThreeVolumeSource = VDBThreeDenseSource | VDBThreeSourceFactory;\n\n/** Initial values of {@link vdbVolumeUniforms} (his `FrameVolume` props of the same names and defaults). */\nexport interface VDBVolumeUniformParameters {\n /** Optical depth of the longest box side at the mean density, with `normalizeDensity` (default 100). */\n extinction?: number;\n /** Density multiplier (default 1); with `normalizeDensity` it divides by `stats.meanNonZero`. */\n densityScale?: number;\n normalizeDensity?: boolean;\n densityCutoff?: number;\n baseColor?: THREE.ColorRepresentation;\n emissiveIntensity?: number;\n /** Kelvin at emission values 0 and 1 (default [0, 6500]). */\n temperatureRange?: [number, number];\n offset3D?: THREE.Vector3Like;\n wrap3D?: THREE.Wrapping;\n /** `matrixWorld.getMaxScaleOnAxis()` of the volume (default 1). */\n worldScale?: number;\n}\n\n/** His `createVolumeUniforms()` subset the source reads (frameShaderChunks.js L729–763), as live TSL uniforms. */\nexport interface VDBVolumeUniforms {\n readonly worldScale: VDBTslNode;\n readonly gridTexels: VDBTslNode;\n readonly mipAtlasSize: VDBTslNode;\n readonly maps: Readonly<Record<ChannelName, VDBTslNode | null>>;\n readonly mipMaps: Readonly<Record<ChannelName, VDBTslNode | null>>;\n readonly mipLevels: Readonly<Record<ChannelName, VDBTslNode>>;\n readonly baseColor: VDBTslNode;\n readonly extinction: VDBTslNode;\n readonly densityScale: VDBTslNode;\n readonly densityCutoff: VDBTslNode;\n readonly emissiveIntensity: VDBTslNode;\n readonly temperatureRange: VDBTslNode;\n readonly offset3D: VDBTslNode;\n readonly wrap3D: VDBTslNode;\n /** Re-read textures, sizes and the normalized density scale after `source.replace` (setMipUniforms, L773–798). */\n update(source: VDBThreeVolumeSource, o?: { densityScale?: number; normalizeDensity?: boolean }): void;\n /**\n * Stops following the source: a sparse source drops the listeners these uniforms registered (its stats and, with\n * `followImage`, its layout), which it otherwise keeps for its lifetime. `VDBFrameVolume.dispose()` calls it; call it\n * yourself for uniforms you made with `vdbVolumeUniforms`. A no-op for a dense source. Idempotent.\n */\n dispose(): void;\n}\n\n/** FrameVolume.js L561–568 `getDensityScale`. */\nexport const vdbDensityScaleOf = (source: VDBVolumeSourceInfo, densityScale: number, normalize: boolean): number =>\n normalize && source.stats.meanNonZero > 0 ? densityScale / source.stats.meanNonZero : densityScale;\nconst densityScaleOf = vdbDensityScaleOf;\n\n/**\n * Live uniforms for one source (his `createVolumeUniforms` + `setVolumeUniforms` + `setMipUniforms`).\n * A sparse source makes its own (`source.createUniforms`), with the same fields.\n */\nexport function vdbVolumeUniforms(source: VDBThreeVolumeSource, p: VDBVolumeUniformParameters = {}): VDBVolumeUniforms {\n if (source.kind === \"sparse\") return source.createUniforms(p);\n const tex = source.textures;\n let densityScale = p.densityScale ?? 1.0;\n let normalize = p.normalizeDensity ?? true;\n const maps = {} as Record<ChannelName, VDBTslNode | null>;\n const mipMaps = {} as Record<ChannelName, VDBTslNode | null>;\n const mipLevels = {} as Record<ChannelName, VDBTslNode>;\n for (const name of CHANNELS) {\n maps[name] = tex[name] ? texture3D(tex[name]!.map) : null;\n mipMaps[name] = tex[name]?.mip ? texture3D(tex[name]!.mip!) : null;\n mipLevels[name] = uniform(0.0);\n }\n const gridTexels = uniform(new THREE.Vector3(1, 1, 1));\n const mipAtlasSize = uniform(new THREE.Vector3(1, 1, 1));\n const densityScaleU = uniform(densityScaleOf(source, densityScale, normalize));\n const u: VDBVolumeUniforms = {\n worldScale: uniform(p.worldScale ?? 1.0),\n gridTexels,\n mipAtlasSize,\n maps,\n mipMaps,\n mipLevels,\n baseColor: uniform(new THREE.Color(p.baseColor ?? 0xffffff)),\n extinction: uniform(p.extinction ?? 100.0),\n densityScale: densityScaleU,\n densityCutoff: uniform(p.densityCutoff ?? 0.0),\n emissiveIntensity: uniform(p.emissiveIntensity ?? 1.0),\n temperatureRange: uniform(new THREE.Vector2(...(p.temperatureRange ?? [0.0, 6500.0]))),\n offset3D: uniform(new THREE.Vector3().copy((p.offset3D ?? { x: 0, y: 0, z: 0 }) as THREE.Vector3)),\n wrap3D: uniform(p.wrap3D ?? THREE.ClampToEdgeWrapping, \"int\"),\n update(s0, o = {}) {\n if (s0.kind !== \"dense\") throw new VDBError(\"VDB_BAD_OPTION\", \"vdbVolumeUniforms: these uniforms belong to a dense source.\");\n const s = s0;\n if (o.densityScale !== undefined) densityScale = o.densityScale;\n if (o.normalizeDensity !== undefined) normalize = o.normalizeDensity;\n densityScaleU.value = densityScaleOf(s, densityScale, normalize);\n const [w, h, d] = s.texels;\n gridTexels.value.set(w, h, d);\n const densityMip = s.textures.density?.mip;\n if (densityMip) {\n const img = densityMip.image as { width: number; height: number; depth: number };\n mipAtlasSize.value.set(img.width, img.height, img.depth);\n }\n for (const name of CHANNELS) {\n const t = s.textures[name];\n if (t && maps[name]) maps[name].value = t.map;\n if (t?.mip && mipMaps[name]) mipMaps[name].value = t.mip;\n // Every channel shares the density size (wvdbDenseVolume checks it), so all levels are the mip's.\n // A channel the frame lacks (K5.9: a constant texture) has the density's levels.\n mipLevels[name].value = densityMip && t?.mip ? (s.volume[name]?.mip?.levels ?? s.volume.density.mip?.levels ?? 0) : 0;\n }\n },\n dispose() {\n // A dense source registers nothing.\n },\n };\n u.update(source);\n return u;\n}\n\n/** Options of {@link vdbVolumeNodes}. */\nexport interface VDBVolumeNodesOptions {\n /** Sample the CPU mip atlas at `lod` (his shaders built with `useMipmaps`). Default: the source has mips. */\n useMipmaps?: boolean;\n /**\n * Emission colour from temperature (Kelvin node) → vec3 node. Default: white.\n * His `'approximate'` blackbody is from Shadertoy (CC BY-NC-SA unless stated) and is not\n * ported (R1 §7); his `'planck'`/`'soot'` table is the hook `vdbFrameBlackbodyEmission` (K3.6; its CIE 1931\n * colour matching functions are the Wyman–Sloan–Shirley 2013 analytic fit, D33).\n */\n emissionColor?: (temperature: VDBTslNode) => VDBTslNode;\n}\n\n/** The node factory of his `createVolumeNodes()` (frameShaderChunks.js L834–1028). */\nexport interface VDBVolumeNodes {\n getLod(localSize: VDBTslNode): VDBTslNode;\n sampleExtinction(localPosition: VDBTslNode, lod: VDBTslNode): VDBTslNode;\n sampleAlbedo(localPosition: VDBTslNode, lod: VDBTslNode): VDBTslNode;\n sampleEmission(localPosition: VDBTslNode, lod: VDBTslNode): VDBTslNode;\n insideBox(localPosition: VDBTslNode): VDBTslNode;\n boxExit(origin: VDBTslNode, direction: VDBTslNode): VDBTslNode;\n boxSegment(start: VDBTslNode, end: VDBTslNode): VDBTslNode;\n /**\n * Sparse sources only (K3.2): the empty-space query of a march along `origin + direction·t`\n * (local units) whose samples are read at `lod`. Returns `vec2(ts, te)`: every sample with\n * `t < ts` is exactly 0 (skip it), the samples in `[ts, te)` must be read, ask again from `te`.\n * When no safe bound exists (a coarse level, wrapping, an offset) it returns `(t0, 1e30)`.\n * Call in the Fn body. Absent for dense sources (no skipping).\n */\n skipEmpty?(origin: VDBTslNode, direction: VDBTslNode, t0: VDBTslNode, t1: VDBTslNode, lod: VDBTslNode): VDBTslNode;\n}\n\n/** frameShaderChunks.js L65–66. */\nexport const vdbMinComponent = (v: VDBTslNode): VDBTslNode => min(v.x, min(v.y, v.z));\nexport const vdbMaxComponent = (v: VDBTslNode): VDBTslNode => max(v.x, max(v.y, v.z));\n\n/**\n * Sampling of one dense source, in his `createVolumeNodes` shape. Call the\n * sample functions inside a TSL `Fn` body. Absent channels give his fallbacks\n * (mask 1, albedo `baseColor`, emission 0) without sampling.\n */\n/**\n * His mip sampling (frameShaderChunks.js L838–872) over one texture and its box mip atlas:\n * `sampleMipAtlas` (level 1 and up, frameMipmaps.js layout) and `sampleMipmapped` (linear between\n * two levels). `gridTexels` is the size of `map` (level 0 of this chain), `mipAtlasSize` the atlas's.\n * Shared by the dense source and the sparse source's coarse pyramid. Call in a TSL Fn body.\n */\nexport function vdbMipSampler(gridTexels: VDBTslNode, mipAtlasSize: VDBTslNode): {\n sampleMipAtlas(mipMap: VDBTslNode, level: VDBTslNode, uvw: VDBTslNode): VDBTslNode;\n sampleMipmapped(map: VDBTslNode, mipMap: VDBTslNode, levels: VDBTslNode, position: VDBTslNode, lod: VDBTslNode): VDBTslNode;\n} {\n // L838–846: level 1 and up of the mip atlas (layout of frameMipmaps.js).\n const sampleMipAtlas = (mipMap: VDBTslNode, level: VDBTslNode, uvw: VDBTslNode): VDBTslNode => {\n const size = max(vec3(1.0), ceil(gridTexels.div(exp2(level))));\n const offset = mipAtlasSize.x.sub(mipAtlasSize.x.div(exp2(level.sub(1.0))));\n const texel = clamp(uvw.mul(size), vec3(0.5), size.sub(0.5));\n return mipMap.sample(vec3(texel.x.add(offset), texel.y, texel.z).div(mipAtlasSize)).level(float(0.0));\n };\n\n // L849–872: linear between two mip levels (LinearMipmapLinearFilter).\n const sampleMipmapped = (map: VDBTslNode, mipMap: VDBTslNode, levels: VDBTslNode, position: VDBTslNode, lod: VDBTslNode): VDBTslNode => {\n const uvw = vec3(position).toVar();\n const result = vec4(0.0).toVar();\n const level = min(lod, levels).toVar();\n If(level.lessThanEqual(0.0), () => {\n result.assign(map.sample(uvw).level(float(0.0)));\n }).Else(() => {\n const level0 = floor(level).toVar();\n const low = vec4(0.0).toVar();\n If(level0.lessThan(0.5), () => {\n low.assign(map.sample(uvw).level(float(0.0)));\n }).Else(() => {\n low.assign(sampleMipAtlas(mipMap, level0, uvw));\n });\n const high = sampleMipAtlas(mipMap, min(level0.add(1.0), levels), uvw);\n result.assign(mix(low, high, level.sub(level0)));\n });\n return result;\n };\n return { sampleMipAtlas, sampleMipmapped };\n}\n\n/** His `wrapUv` / `gridUv` (frameShaderChunks.js L894–911): the local position as a wrapped, offset uvw. */\nexport function vdbGridUv(u: Pick<VDBVolumeUniforms, \"wrap3D\" | \"offset3D\">): (localPosition: VDBTslNode) => VDBTslNode {\n const T = THREE as unknown as Record<string, number>;\n const mirrorAxis = (value: VDBTslNode) => {\n const period = mod(value, 2.0);\n return select(period.greaterThan(1.0), float(2.0).sub(period), period);\n };\n const wrapUv = (uvw: VDBTslNode) =>\n select(\n u.wrap3D.equal(T.RepeatWrapping!),\n fract(uvw),\n select(u.wrap3D.equal(T.MirroredRepeatWrapping!), vec3(mirrorAxis(uvw.x), mirrorAxis(uvw.y), mirrorAxis(uvw.z)), uvw),\n );\n return (localPosition: VDBTslNode) => wrapUv(localPosition.add(0.5).add(u.offset3D));\n}\n\n/** His box geometry (frameShaderChunks.js L938–958): `insideBox`, `boxExit`, `boxSegment` of the local unit box. */\nexport const vdbBoxNodes = {\n insideBox: (localPosition: VDBTslNode) => vdbMaxComponent(abs(localPosition)).lessThanEqual(0.5),\n boxExit: (origin: VDBTslNode, direction: VDBTslNode) => {\n const inverseDirection = vec3(1.0).div(direction);\n const tMin = vec3(-0.5).sub(origin).mul(inverseDirection);\n const tMax = vec3(0.5).sub(origin).mul(inverseDirection);\n return max(0.0, vdbMinComponent(max(tMin, tMax)));\n },\n boxSegment: (start: VDBTslNode, end: VDBTslNode) => {\n const inverseDirection = vec3(1.0).div(end.sub(start));\n const tMin = vec3(-0.5).sub(start).mul(inverseDirection);\n const tMax = vec3(0.5).sub(start).mul(inverseDirection);\n return vec2(max(0.0, vdbMaxComponent(min(tMin, tMax))), min(1.0, vdbMinComponent(max(tMin, tMax))));\n },\n};\n\nexport function vdbVolumeNodes(source: VDBThreeVolumeSource, u: VDBVolumeUniforms, o: VDBVolumeNodesOptions = {}): VDBVolumeNodes {\n if (source.kind === \"sparse\") return source.createNodes(u, o);\n const useMipmaps = o.useMipmaps ?? source.lodLevels > 0;\n const { gridTexels, mipAtlasSize } = u;\n const { sampleMipmapped } = vdbMipSampler(gridTexels, mipAtlasSize);\n\n // L874–877 sample3D (a channel without a mip atlas samples level 0).\n const sample3D = (name: ChannelName, uvw: VDBTslNode, lod: VDBTslNode): VDBTslNode => {\n const map = u.maps[name]!;\n const mip = u.mipMaps[name];\n return useMipmaps && mip ? sampleMipmapped(map, mip, u.mipLevels[name], uvw, lod) : map.sample(uvw).level(float(0.0));\n };\n\n // L892\n const getLod = (localSize: VDBTslNode) => max(0.0, log2(localSize.mul(vdbMaxComponent(gridTexels))));\n\n // L894–911\n const gridUv = vdbGridUv(u);\n\n // L914–936: extinction per world unit. The mask is read at local + 0.5 (no offset or wrap), as his.\n const sampleExtinction = (localPosition: VDBTslNode, lod: VDBTslNode) => {\n const mask = source.channels.mask ? sample3D(\"mask\", localPosition.add(0.5), lod).r : float(1.0);\n const value = sample3D(\"density\", gridUv(localPosition), lod).r.mul(mask);\n return select(value.greaterThan(u.densityCutoff), value, float(0.0)).mul(u.densityScale).mul(u.extinction).div(u.worldScale);\n };\n\n // L938–958\n const { insideBox, boxExit, boxSegment } = vdbBoxNodes;\n\n // L960–971\n const sampleAlbedo = (localPosition: VDBTslNode, lod: VDBTslNode) =>\n source.channels.albedo ? u.baseColor.mul(sample3D(\"albedo\", gridUv(localPosition), lod).rgb) : u.baseColor.mul(vec3(1.0));\n\n // L990–1017, colour via the caller's hook (see VDBVolumeNodesOptions.emissionColor).\n const emissionColor = o.emissionColor ?? (() => vec3(1.0));\n const sampleEmission = (localPosition: VDBTslNode, lod: VDBTslNode) => {\n if (!source.channels.emission) return vec3(0.0);\n const range = u.temperatureRange;\n const value = sample3D(\"emission\", gridUv(localPosition), lod).r;\n const temperature = mix(range.x, range.y, value);\n const power = pow(temperature.div(max(range.y, 1.0)), 4.0);\n const color = select(temperature.greaterThan(0.0), emissionColor(temperature), vec3(0.0));\n return color.mul(power).mul(u.emissiveIntensity);\n };\n\n return { getLod, sampleExtinction, sampleAlbedo, sampleEmission, insideBox, boxExit, boxSegment };\n}\n"]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/** Fixed-point scale of the GPU fast path's 64-bit sum (2^20). */
|
|
2
|
+
export declare const GRID_STATS_SUM_SCALE = 1048576;
|
|
3
|
+
/** Index bbox, inclusive on both ends. */
|
|
4
|
+
export interface IndexBBox {
|
|
5
|
+
min: readonly [number, number, number];
|
|
6
|
+
max: readonly [number, number, number];
|
|
7
|
+
}
|
|
8
|
+
/** Per-axis voxel count of an inclusive-max index bbox (`max - min + 1`). */
|
|
9
|
+
export declare function bboxSize(bbox: IndexBBox): [number, number, number];
|
|
10
|
+
/**
|
|
11
|
+
* `decodeToAtlas` output resolution: each axis of the index bbox clamped to
|
|
12
|
+
* `maxDim` (a literal per-axis clamp, not a proportional downscale; v1).
|
|
13
|
+
*/
|
|
14
|
+
export declare function atlasDims(bbox: IndexBBox, maxDim: number): [number, number, number];
|
|
15
|
+
/** The root node's stored min/max statistics (f32), meaningful when the grid has stats. */
|
|
16
|
+
export declare function rootStats(gridWords: Uint32Array): {
|
|
17
|
+
min: number;
|
|
18
|
+
max: number;
|
|
19
|
+
};
|
|
20
|
+
export interface VDBGridStatsCpuOptions {
|
|
21
|
+
/** Histogram bins (default 256). */
|
|
22
|
+
histogramBins?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface VDBGridStatsCpuResult {
|
|
25
|
+
min: number;
|
|
26
|
+
max: number;
|
|
27
|
+
mean: number;
|
|
28
|
+
histogram: Uint32Array;
|
|
29
|
+
activeVoxelCount: number;
|
|
30
|
+
/** The path the GPU takes for this grid: `true` when the root min is ≥ 0 (atomics). */
|
|
31
|
+
usedAtomicFastPath: boolean;
|
|
32
|
+
/** The histogram range: the root min/max statistics. */
|
|
33
|
+
range: {
|
|
34
|
+
min: number;
|
|
35
|
+
max: number;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Twin of `gridStats`: min, max, mean and a histogram over the ACTIVE voxels of
|
|
40
|
+
* the dense index bbox, read as the GPU reads them (`vdbIsActive`,
|
|
41
|
+
* `vdbReadValue`). The histogram spans the root statistics `[rootMin,
|
|
42
|
+
* rootMax]`.
|
|
43
|
+
*
|
|
44
|
+
* Both GPU paths are reproduced: the atomics path (root min ≥ 0) normalizes in
|
|
45
|
+
* f32 and sums `u32(norm * 2^20)` in a 64-bit integer; the dump path (root min
|
|
46
|
+
* < 0) reduces f32 values in f64 on the CPU. The f32 normalization divides, so
|
|
47
|
+
* a GPU with an inexact division may put a voxel in the neighbouring bin or
|
|
48
|
+
* shift the mean by a fixed-point step.
|
|
49
|
+
*/
|
|
50
|
+
export declare function vdbGridStatsCpu(gridWords: Uint32Array, options?: VDBGridStatsCpuOptions): VDBGridStatsCpuResult;
|
|
51
|
+
export type VDBAtlasFilter = "nearest" | "trilinear";
|
|
52
|
+
export type VDBAtlasFormat = "uint8" | "float32";
|
|
53
|
+
export interface AtlasFromRawOptions {
|
|
54
|
+
format: VDBAtlasFormat;
|
|
55
|
+
normalize: boolean;
|
|
56
|
+
range: {
|
|
57
|
+
min: number;
|
|
58
|
+
max: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Post-readback step of `decodeToAtlas` (v1, in f64): `uint8` maps `[min,
|
|
63
|
+
* max]` to `[0, 255]` with `Math.round` (or clamps the raw value when not
|
|
64
|
+
* normalizing); `float32` maps to `[0, 1]` or returns `raw` itself.
|
|
65
|
+
*/
|
|
66
|
+
export declare function atlasFromRaw(raw: Float32Array, o: AtlasFromRawOptions): Uint8Array | Float32Array;
|
|
67
|
+
export interface VDBDecodeToAtlasCpuOptions {
|
|
68
|
+
maxDim?: number;
|
|
69
|
+
filter?: VDBAtlasFilter;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Twin of the `decodeToAtlas` pass before normalization: one f32 per output
|
|
73
|
+
* voxel (x fastest), sampled at index position `min + (i + 0.5) * size / dims
|
|
74
|
+
* - 0.5` (cell `i` of `dims` over `[min, max]`, `size = max - min + 1`; voxel
|
|
75
|
+
* centres at full resolution, K2.6) with `vdbReadValue(floor(p + 0.5))` (`'nearest'`) or
|
|
76
|
+
* the vendored trilinear (`'trilinear'`, the default). Feed the result to
|
|
77
|
+
* {@link atlasFromRaw} for the formatted atlas.
|
|
78
|
+
*/
|
|
79
|
+
export declare function vdbDecodeToAtlasCpu(gridWords: Uint32Array, options?: VDBDecodeToAtlasCpuOptions): {
|
|
80
|
+
raw: Float32Array;
|
|
81
|
+
dims: [number, number, number];
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Returns a copy of a Float grid image with `fn` applied to every leaf voxel
|
|
85
|
+
* value inside the index bbox (active or inactive), rounded to f32. Tile,
|
|
86
|
+
* background and out-of-bbox leaf values are left alone, exactly as v1's GPU
|
|
87
|
+
* `valueTransform` did (it visited the dense bbox and rewrote level-0
|
|
88
|
+
* addresses only).
|
|
89
|
+
*
|
|
90
|
+
* The image's statistics (root/node min, max, average, deviation) are NOT
|
|
91
|
+
* recomputed: they describe the source values. Tools that trust them
|
|
92
|
+
* (`gridStats`' range, `vdbNodeMax` skipping) see stale bounds; rebuild the
|
|
93
|
+
* grid (e.g. `vdbBuildFromDense`) when they matter.
|
|
94
|
+
*
|
|
95
|
+
* Float (GridType 1) only: quantized leaves would need re-encoding.
|
|
96
|
+
*/
|
|
97
|
+
export declare function transformLeafValues(gridWords: Uint32Array, fn: (value: number) => number): Uint32Array;
|