@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,703 @@
|
|
|
1
|
+
// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
|
|
2
|
+
// src/three-openvdb/frame/core/frameGrid.js L12–223 (signature helpers, updateGridCascades,
|
|
3
|
+
// getGridRange, getCascadeCasters, updateGridSignatures);
|
|
4
|
+
// src/three-openvdb/frame/webgpu/frameShaderChunks.js L403–414 (frameIsotropicDiffusion),
|
|
5
|
+
// L1061–1194 (createGridNodes: gridUvw, insideGrid, findCascade, sampleTiles, sampleShadows,
|
|
6
|
+
// getGridCell);
|
|
7
|
+
// src/three-openvdb/frame/webgpu/FrameTransmittanceMaterial.js L129–190 (gridExtinction, march,
|
|
8
|
+
// skyTotal), L237–269 (near-extinction skip, slot packing);
|
|
9
|
+
// src/three-openvdb/frame/webgpu/FrameTemporalMaterial.js L119–157 (reprojection, motion blend);
|
|
10
|
+
// src/three-openvdb/frame/webgpu/FrameDensityMaterial.js L172–357 (the grey density pass),
|
|
11
|
+
// FrameLightingMaterial.js L296–436 (the grey lighting pass), FrameEnvironmentGridMaterial.js L92–281
|
|
12
|
+
// (the grey environment grid pass), as CPU twins.
|
|
13
|
+
// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
|
|
14
|
+
// Changes: engine-free (plain `{ x, y, z }` vectors and boxes instead of three's `Box3`/`Vector3`,
|
|
15
|
+
// so `tools` stays free of three; the three adapter passes its own objects, which fit); the shader
|
|
16
|
+
// maths as f64 CPU twins (test oracles of the `./three` 'frame' lighting passes); K3.4 adds the octave,
|
|
17
|
+
// two-sided and neural (callback) terms; the spectral twins are in spectral.ts (K3.5; they share
|
|
18
|
+
// `vdbFrameDensityFroxelSteps`). Divergences: DIVERGES.md (K3.3, K3.4 rows).
|
|
19
|
+
/**
|
|
20
|
+
* The world shadow grid of mjurczyk's `'frame'` lighting (K3.3, R1 §6 Step 3), engine-free: the
|
|
21
|
+
* cascade layout (power-of-two voxels, snapped bounds, the last cascade fits every caster), each
|
|
22
|
+
* caster's voxel range in a cascade, the change signatures that skip redraws, and CPU twins of the
|
|
23
|
+
* grid shader maths (atlas cell, cascade search, slice-atlas sampling, the transmittance march,
|
|
24
|
+
* isotropic diffusion, the temporal reprojection). `@pmndrs/vdb/three` `frame/grid.ts` and the
|
|
25
|
+
* 'frame' passes use these; the e2e harness checks the GPU passes against them.
|
|
26
|
+
*/
|
|
27
|
+
import { vdbFrameDistanceFade, vdbFrameFroxel, vdbFrameNoise, vdbFrameOctavesOff, vdbFramePhaseColor, vdbFrameShadowMarchDepth, vdbFrameShadowStep, vdbFrameShadowTotal, vdbFrameShadowTransmittance, vdbFrameShadowedLightColor, vdbFrameTwoSidedDiffusion, vdbFrameViewPosition, } from "./index.js";
|
|
28
|
+
const AXES = ["x", "y", "z"];
|
|
29
|
+
/** His `pushVector`: x, y (, z (, w)) of a vector into a signature. */
|
|
30
|
+
export function vdbSignaturePushVector(values, v) {
|
|
31
|
+
values.push(v.x, v.y);
|
|
32
|
+
if (v.z !== undefined)
|
|
33
|
+
values.push(v.z);
|
|
34
|
+
if (v.w !== undefined)
|
|
35
|
+
values.push(v.w);
|
|
36
|
+
}
|
|
37
|
+
/** His `pushElements`. */
|
|
38
|
+
export function vdbSignaturePushElements(values, elements) {
|
|
39
|
+
for (let i = 0; i < elements.length; i++)
|
|
40
|
+
values.push(elements[i]);
|
|
41
|
+
}
|
|
42
|
+
/** His `sameValues`: signatures are flat arrays compared value by value. */
|
|
43
|
+
export function vdbSameValues(a, b) {
|
|
44
|
+
if (a.length !== b.length)
|
|
45
|
+
return false;
|
|
46
|
+
for (let i = 0; i < a.length; i++)
|
|
47
|
+
if (a[i] !== b[i])
|
|
48
|
+
return false;
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
const box = { min: { x: 0, y: 0, z: 0 }, max: { x: 0, y: 0, z: 0 } };
|
|
52
|
+
const casterBox = { min: { x: 0, y: 0, z: 0 }, max: { x: 0, y: 0, z: 0 } };
|
|
53
|
+
const makeEmpty = (b) => {
|
|
54
|
+
b.min.x = b.min.y = b.min.z = Infinity;
|
|
55
|
+
b.max.x = b.max.y = b.max.z = -Infinity;
|
|
56
|
+
};
|
|
57
|
+
const isEmpty = (b) => b.max.x < b.min.x || b.max.y < b.min.y || b.max.z < b.min.z;
|
|
58
|
+
const copyBox = (to, from) => {
|
|
59
|
+
for (const a of AXES) {
|
|
60
|
+
to.min[a] = from.min[a];
|
|
61
|
+
to.max[a] = from.max[a];
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* His `updateGridCascades`: the last cascade fits all caster boxes (then far volumes get coarse
|
|
66
|
+
* shadows, not none); finer cascades are around the camera within `shadowDistance`, each half the
|
|
67
|
+
* size of the next; voxels are powers of two and bounds snap to them (shadows stay still while the
|
|
68
|
+
* camera moves). A fine cascade equal to the casters' box is skipped (the last one covers it).
|
|
69
|
+
* Writes `gridMin`, `gridSize`, `gridVoxel` (one entry per cascade); returns the count (0: no casters).
|
|
70
|
+
*/
|
|
71
|
+
export function vdbFrameGridCascades(casterBoxes, cameraPosition, shadowDistance, resolution, cascades, gridMin, gridSize, gridVoxel) {
|
|
72
|
+
makeEmpty(casterBox);
|
|
73
|
+
for (const b of casterBoxes) {
|
|
74
|
+
for (const a of AXES) {
|
|
75
|
+
casterBox.min[a] = Math.min(casterBox.min[a], b.min[a]);
|
|
76
|
+
casterBox.max[a] = Math.max(casterBox.max[a], b.max[a]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (isEmpty(casterBox))
|
|
80
|
+
return 0;
|
|
81
|
+
const fineHalfSize = Math.min(shadowDistance, 0.5 * Math.max(casterBox.max.x - casterBox.min.x, casterBox.max.y - casterBox.min.y, casterBox.max.z - casterBox.min.z));
|
|
82
|
+
let count = 0;
|
|
83
|
+
for (let cascade = 0; cascade < cascades; cascade++) {
|
|
84
|
+
if (cascade === cascades - 1) {
|
|
85
|
+
copyBox(box, casterBox);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const halfSize = fineHalfSize / Math.pow(2.0, cascades - 1 - cascade);
|
|
89
|
+
for (const a of AXES) {
|
|
90
|
+
// three Box3.intersect: max of the mins, min of the maxes, then empty when inverted.
|
|
91
|
+
box.min[a] = Math.max(cameraPosition[a] - halfSize, casterBox.min[a]);
|
|
92
|
+
box.max[a] = Math.min(cameraPosition[a] + halfSize, casterBox.max[a]);
|
|
93
|
+
}
|
|
94
|
+
if (isEmpty(box))
|
|
95
|
+
makeEmpty(box);
|
|
96
|
+
}
|
|
97
|
+
const equalsCasters = AXES.every((a) => box.min[a] === casterBox.min[a] && box.max[a] === casterBox.max[a]);
|
|
98
|
+
if (isEmpty(box) || (cascade < cascades - 1 && equalsCasters))
|
|
99
|
+
continue;
|
|
100
|
+
for (const a of AXES) {
|
|
101
|
+
const extent = Math.max(box.max[a] - box.min[a], 1e-6);
|
|
102
|
+
const voxel = Math.pow(2.0, Math.ceil(Math.log2(extent / (resolution - 1))));
|
|
103
|
+
gridVoxel[count][a] = voxel;
|
|
104
|
+
gridMin[count][a] = Math.floor(box.min[a] / voxel) * voxel;
|
|
105
|
+
gridSize[count][a] = voxel * resolution;
|
|
106
|
+
}
|
|
107
|
+
count++;
|
|
108
|
+
}
|
|
109
|
+
return count;
|
|
110
|
+
}
|
|
111
|
+
const toCell = (value, min, voxel, resolution, round) => Math.min(resolution, Math.max(0, round((value - min) / voxel)));
|
|
112
|
+
/**
|
|
113
|
+
* His `getGridRange`: the voxel rectangle (x0, y0, x1, y1) and the atlas slices (first, count) of a
|
|
114
|
+
* world box in one cascade. Writes `target`; returns false when the box is out of the cascade.
|
|
115
|
+
*/
|
|
116
|
+
export function vdbFrameGridRange(worldBox, cascade, resolution, gridMin, gridVoxel, target) {
|
|
117
|
+
const origin = gridMin[cascade];
|
|
118
|
+
const voxel = gridVoxel[cascade];
|
|
119
|
+
const { min, max } = worldBox;
|
|
120
|
+
const x0 = toCell(min.x, origin.x, voxel.x, resolution, Math.floor);
|
|
121
|
+
const y0 = toCell(min.y, origin.y, voxel.y, resolution, Math.floor);
|
|
122
|
+
const z0 = toCell(min.z, origin.z, voxel.z, resolution, Math.floor);
|
|
123
|
+
const x1 = toCell(max.x, origin.x, voxel.x, resolution, Math.ceil);
|
|
124
|
+
const y1 = toCell(max.y, origin.y, voxel.y, resolution, Math.ceil);
|
|
125
|
+
const z1 = toCell(max.z, origin.z, voxel.z, resolution, Math.ceil);
|
|
126
|
+
if (x1 <= x0 || y1 <= y0 || z1 <= z0)
|
|
127
|
+
return false;
|
|
128
|
+
if (Array.isArray(target.rect)) {
|
|
129
|
+
target.rect[0] = x0;
|
|
130
|
+
target.rect[1] = y0;
|
|
131
|
+
target.rect[2] = x1;
|
|
132
|
+
target.rect[3] = y1;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
const r = target.rect;
|
|
136
|
+
r.x = x0;
|
|
137
|
+
r.y = y0;
|
|
138
|
+
r.z = x1;
|
|
139
|
+
r.w = y1;
|
|
140
|
+
}
|
|
141
|
+
target.first = cascade * resolution + z0;
|
|
142
|
+
target.count = z1 - z0;
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
/** His `getCascadeCasters`: one item per caster per cascade from `firstCascade`; `pool` is reused. */
|
|
146
|
+
export function vdbFrameCascadeCasters(casters, firstCascade, count, pool) {
|
|
147
|
+
const { items, entries } = pool;
|
|
148
|
+
items.length = 0;
|
|
149
|
+
for (let cascade = firstCascade; cascade < count; cascade++) {
|
|
150
|
+
for (const caster of casters) {
|
|
151
|
+
if (items.length === entries.length)
|
|
152
|
+
entries.push({ caster, cascade });
|
|
153
|
+
const entry = entries[items.length];
|
|
154
|
+
entry.caster = caster;
|
|
155
|
+
entry.cascade = cascade;
|
|
156
|
+
items.push(entry);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return items;
|
|
160
|
+
}
|
|
161
|
+
/** A fresh {@link VDBFrameGridSignatureState}. */
|
|
162
|
+
export const vdbFrameGridSignatureState = () => ({
|
|
163
|
+
gridSignature: [],
|
|
164
|
+
nextGridSignature: [],
|
|
165
|
+
castSignature: [],
|
|
166
|
+
nextCastSignature: [],
|
|
167
|
+
casterSignature: [],
|
|
168
|
+
gridVersion: 0,
|
|
169
|
+
castVersion: 0,
|
|
170
|
+
});
|
|
171
|
+
/**
|
|
172
|
+
* His `updateGridSignatures`: `gridVersion` changes when the cascades, a caster transform, a caster's
|
|
173
|
+
* data or a caster's shadow props change; `castVersion` only for the last cascade. `pushCaster(values, caster)`
|
|
174
|
+
* adds what the shadow density pass reads of one caster (transform, source identity and version, props).
|
|
175
|
+
* Returns true when `castVersion` changed. Arrays are swapped, never reallocated.
|
|
176
|
+
*/
|
|
177
|
+
export function vdbFrameUpdateGridSignatures(state, casters, count, resolution, spectral, gridMin, gridSize, pushCaster) {
|
|
178
|
+
const casterValues = state.casterSignature;
|
|
179
|
+
const castValues = state.nextCastSignature;
|
|
180
|
+
const gridValues = state.nextGridSignature;
|
|
181
|
+
casterValues.length = 0;
|
|
182
|
+
for (const caster of casters)
|
|
183
|
+
pushCaster(casterValues, caster);
|
|
184
|
+
// NOTE The cascade count changes the atlas layout, so a new count needs a new draw
|
|
185
|
+
castValues.length = 0;
|
|
186
|
+
castValues.push(casters.length, count, resolution, spectral ? 1 : 0);
|
|
187
|
+
if (count > 0) {
|
|
188
|
+
vdbSignaturePushVector(castValues, gridMin[count - 1]);
|
|
189
|
+
vdbSignaturePushVector(castValues, gridSize[count - 1]);
|
|
190
|
+
}
|
|
191
|
+
vdbSignaturePushElements(castValues, casterValues);
|
|
192
|
+
gridValues.length = 0;
|
|
193
|
+
gridValues.push(count);
|
|
194
|
+
for (let i = 0; i < count; i++) {
|
|
195
|
+
vdbSignaturePushVector(gridValues, gridMin[i]);
|
|
196
|
+
vdbSignaturePushVector(gridValues, gridSize[i]);
|
|
197
|
+
}
|
|
198
|
+
vdbSignaturePushElements(gridValues, castValues);
|
|
199
|
+
if (!vdbSameValues(gridValues, state.gridSignature)) {
|
|
200
|
+
state.gridVersion++;
|
|
201
|
+
state.nextGridSignature = state.gridSignature;
|
|
202
|
+
state.gridSignature = gridValues;
|
|
203
|
+
}
|
|
204
|
+
const castChanged = !vdbSameValues(castValues, state.castSignature);
|
|
205
|
+
if (castChanged) {
|
|
206
|
+
state.castVersion++;
|
|
207
|
+
state.nextCastSignature = state.castSignature;
|
|
208
|
+
state.castSignature = castValues;
|
|
209
|
+
}
|
|
210
|
+
return castChanged;
|
|
211
|
+
}
|
|
212
|
+
/** gridUvw: world position → [0, 1]³ of a cascade. */
|
|
213
|
+
export function vdbFrameGridUvw(grid, cascade, world) {
|
|
214
|
+
const m = grid.gridMin[cascade];
|
|
215
|
+
const s = grid.gridSize[cascade];
|
|
216
|
+
return [(world[0] - m[0]) / s[0], (world[1] - m[1]) / s[1], (world[2] - m[2]) / s[2]];
|
|
217
|
+
}
|
|
218
|
+
/** insideGrid: half a voxel inside the cascade (the linear filter then never reads the clamped edge). */
|
|
219
|
+
export function vdbFrameInsideGrid(resolution, uvw) {
|
|
220
|
+
const inset = 0.5 / resolution;
|
|
221
|
+
return Math.min(uvw[0], uvw[1], uvw[2]) >= inset && Math.max(uvw[0], uvw[1], uvw[2]) <= 1 - inset;
|
|
222
|
+
}
|
|
223
|
+
/** findCascade: the finest cascade ≥ `firstCascade` that contains the position, or −1. */
|
|
224
|
+
export function vdbFrameFindCascade(grid, world, firstCascade = 0, maxCascades = 4) {
|
|
225
|
+
let cascade = -1;
|
|
226
|
+
for (let i = maxCascades - 1; i >= 0; i--) {
|
|
227
|
+
if (i < grid.count && i >= firstCascade && vdbFrameInsideGrid(grid.resolution, vdbFrameGridUvw(grid, i, world)))
|
|
228
|
+
cascade = i;
|
|
229
|
+
}
|
|
230
|
+
return cascade;
|
|
231
|
+
}
|
|
232
|
+
/** getGridCell: cascade and grid uvw of an atlas pixel (bottom-left `fragCoord`, a pixel centre). */
|
|
233
|
+
export function vdbFrameGridCell(resolution, columns, fragCoord) {
|
|
234
|
+
const tile = [Math.floor(fragCoord[0] / resolution), Math.floor(fragCoord[1] / resolution)];
|
|
235
|
+
const tileIndex = tile[1] * columns + tile[0];
|
|
236
|
+
const cascade = Math.floor(tileIndex / resolution);
|
|
237
|
+
const z = tileIndex - cascade * resolution;
|
|
238
|
+
return {
|
|
239
|
+
cascade,
|
|
240
|
+
gridUvw: [(fragCoord[0] - tile[0] * resolution) / resolution, (fragCoord[1] - tile[1] * resolution) / resolution, (z + 0.5) / resolution],
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/** Hardware bilinear (texel centres at i + ½, clamp to edge) of a bottom-first atlas at texel coordinates. */
|
|
244
|
+
export function vdbFrameAtlasBilinear(atlas, x, y, out = []) {
|
|
245
|
+
const { data, width, height, channels } = atlas;
|
|
246
|
+
const fx = x - 0.5;
|
|
247
|
+
const fy = y - 0.5;
|
|
248
|
+
const x0 = Math.floor(fx);
|
|
249
|
+
const y0 = Math.floor(fy);
|
|
250
|
+
const ax = fx - x0;
|
|
251
|
+
const ay = fy - y0;
|
|
252
|
+
const cx = (i) => Math.min(width - 1, Math.max(0, i));
|
|
253
|
+
const cy = (i) => Math.min(height - 1, Math.max(0, i));
|
|
254
|
+
const xa = cx(x0);
|
|
255
|
+
const xb = cx(x0 + 1);
|
|
256
|
+
const ya = cy(y0);
|
|
257
|
+
const yb = cy(y0 + 1);
|
|
258
|
+
for (let c = 0; c < channels; c++) {
|
|
259
|
+
const t00 = data[(ya * width + xa) * channels + c];
|
|
260
|
+
const t10 = data[(ya * width + xb) * channels + c];
|
|
261
|
+
const t01 = data[(yb * width + xa) * channels + c];
|
|
262
|
+
const t11 = data[(yb * width + xb) * channels + c];
|
|
263
|
+
out[c] = (t00 * (1 - ax) + t10 * ax) * (1 - ay) + (t01 * (1 - ax) + t11 * ax) * ay;
|
|
264
|
+
}
|
|
265
|
+
out.length = channels;
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
/** sampleTiles: hardware bilinear in a slice, linear between slices (z tiles from `tileOffset`). */
|
|
269
|
+
export function vdbFrameSampleTiles(atlas, resolution, tileOffset, columns, uvw) {
|
|
270
|
+
const z = uvw[2] * resolution - 0.5;
|
|
271
|
+
const z0 = Math.min(Math.max(Math.floor(z), 0), resolution - 1);
|
|
272
|
+
const z1 = Math.min(z0 + 1, resolution - 1);
|
|
273
|
+
const blend = Math.min(Math.max(z - z0, 0), 1);
|
|
274
|
+
const xy = [Math.min(Math.max(uvw[0] * resolution, 0.5), resolution - 0.5), Math.min(Math.max(uvw[1] * resolution, 0.5), resolution - 0.5)];
|
|
275
|
+
const tileTexel = (index) => [(index % columns) * resolution + xy[0], Math.floor(index / columns) * resolution + xy[1]];
|
|
276
|
+
const [ax, ay] = tileTexel(tileOffset + z0);
|
|
277
|
+
const [bx, by] = tileTexel(tileOffset + z1);
|
|
278
|
+
const a = vdbFrameAtlasBilinear(atlas, ax, ay);
|
|
279
|
+
const b = vdbFrameAtlasBilinear(atlas, bx, by);
|
|
280
|
+
return a.map((v, c) => v + (b[c] - v) * blend);
|
|
281
|
+
}
|
|
282
|
+
/** sampleGrid: {@link vdbFrameSampleTiles} of one cascade of the grid atlas. */
|
|
283
|
+
export function vdbFrameSampleGrid(atlas, grid, cascade, uvw) {
|
|
284
|
+
return vdbFrameSampleTiles(atlas, grid.resolution, cascade * grid.resolution, grid.columns, uvw);
|
|
285
|
+
}
|
|
286
|
+
/** gridExtinction of the transmittance pass: (extinction, absorption) at a world position, 0 outside the grid. */
|
|
287
|
+
export function vdbFrameGridExtinction(atlas, grid, world) {
|
|
288
|
+
const found = vdbFrameFindCascade(grid, world, 0);
|
|
289
|
+
if (found < 0)
|
|
290
|
+
return [0, 0];
|
|
291
|
+
const s = vdbFrameSampleGrid(atlas, grid, found, vdbFrameGridUvw(grid, found, world));
|
|
292
|
+
return [s[0], s[1]];
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* The transmittance pass `march` (grey): one voxel of the finest cascade at the probe per step along the
|
|
296
|
+
* direction's fastest axis, coarser cascades after leaving a fine one, stop outside the grid, at
|
|
297
|
+
* `maxDistance` or past march depth 6 (with octaves, the last octave's). Each step samples `jitter` of the
|
|
298
|
+
* way along it. Returns (direct, total, reduced depth, effective depth); `out.opticalDepth` gets the direct
|
|
299
|
+
* optical depth (the neural input).
|
|
300
|
+
*/
|
|
301
|
+
export function vdbFrameGridMarch(extinctionAt, grid, origin, direction, maxDistance, jitter, multipleScattering, octaves = vdbFrameOctavesOff, out) {
|
|
302
|
+
const depths = [0, 0, 0];
|
|
303
|
+
let traveled = 0;
|
|
304
|
+
const probe = [...origin];
|
|
305
|
+
for (let i = 0; i < 1024; i++) {
|
|
306
|
+
const cascade = vdbFrameFindCascade(grid, probe, 0);
|
|
307
|
+
if (cascade < 0 || traveled >= maxDistance || vdbFrameShadowMarchDepth(depths, multipleScattering, octaves) > 6)
|
|
308
|
+
break;
|
|
309
|
+
const voxel = grid.gridVoxel[cascade];
|
|
310
|
+
const perUnit = Math.max(Math.abs(direction[0]) / voxel[0], Math.abs(direction[1]) / voxel[1], Math.abs(direction[2]) / voxel[2]);
|
|
311
|
+
const step = Math.min(1 / perUnit, maxDistance - traveled);
|
|
312
|
+
const s = extinctionAt([probe[0] + direction[0] * step * jitter, probe[1] + direction[1] * step * jitter, probe[2] + direction[2] * step * jitter]);
|
|
313
|
+
const d = vdbFrameShadowStep(s[0], s[1], multipleScattering);
|
|
314
|
+
depths[0] += d[0] * step;
|
|
315
|
+
depths[1] += d[1] * step;
|
|
316
|
+
depths[2] += d[2] * step;
|
|
317
|
+
for (let c = 0; c < 3; c++)
|
|
318
|
+
probe[c] = probe[c] + direction[c] * step;
|
|
319
|
+
traveled += step;
|
|
320
|
+
}
|
|
321
|
+
const t = vdbFrameShadowTransmittance(depths, multipleScattering, octaves);
|
|
322
|
+
if (out)
|
|
323
|
+
out.opticalDepth = depths[0];
|
|
324
|
+
return [t[0], t[1], depths[2], depths[1]];
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* frameIsotropicDiffusion: total transmittance of isotropic light (sky, environment) with diffusion,
|
|
328
|
+
* the two-sided slab 2 (back + z₀) / (front + back + 2 z₀) of the reduced depths (z₀ = ⅔), times
|
|
329
|
+
* exp(−effective front). Opposite directions sum to 2 in a white medium (white furnace).
|
|
330
|
+
*/
|
|
331
|
+
export function vdbFrameIsotropicDiffusion(frontReduced, backReduced, frontEffective) {
|
|
332
|
+
const z0 = 2 / 3;
|
|
333
|
+
return ((backReduced + z0) * 2) / (frontReduced + backReduced + 2 * z0) * Math.exp(-frontEffective);
|
|
334
|
+
}
|
|
335
|
+
/** The shader's `normalize`. */
|
|
336
|
+
const normalize3 = (v) => {
|
|
337
|
+
const l = Math.hypot(v[0], v[1], v[2]);
|
|
338
|
+
return l > 0 ? [v[0] / l, v[1] / l, v[2] / l] : [0, 0, 0];
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* The transmittance pass (grey) at one grid voxel: the 4 MRT outputs (vec4 each) his `colorNode` writes,
|
|
342
|
+
* for `lights` (≤ 6 slots) and the sky direction. `fragCoord` is the voxel's atlas pixel (for the jitter
|
|
343
|
+
* noise; `jitter` < 0 is off). Voxels with no extinction within half a voxel keep 1.0 everywhere, as his
|
|
344
|
+
* pass. `modes`: octaves, two-sided or neural (K3.4).
|
|
345
|
+
*/
|
|
346
|
+
export function vdbFrameTransmittanceVoxel(atlas, grid, fragCoord, lights, skyDirection, multipleScattering, jitterValue, modes = {}) {
|
|
347
|
+
const octaves = modes.octaves ?? vdbFrameOctavesOff;
|
|
348
|
+
const out = [
|
|
349
|
+
[1, 1, 1, 1],
|
|
350
|
+
[1, 1, 1, 1],
|
|
351
|
+
[1, 1, 1, 1],
|
|
352
|
+
[1, 1, 1, 1],
|
|
353
|
+
];
|
|
354
|
+
const cell = vdbFrameGridCell(grid.resolution, grid.columns, fragCoord);
|
|
355
|
+
if (cell.cascade >= grid.count)
|
|
356
|
+
return out;
|
|
357
|
+
const voxel = grid.gridVoxel[cell.cascade];
|
|
358
|
+
const m = grid.gridMin[cell.cascade];
|
|
359
|
+
const s = grid.gridSize[cell.cascade];
|
|
360
|
+
const world = [m[0] + cell.gridUvw[0] * s[0], m[1] + cell.gridUvw[1] * s[1], m[2] + cell.gridUvw[2] * s[2]];
|
|
361
|
+
const extinctionAt = (p) => vdbFrameGridExtinction(atlas, grid, p);
|
|
362
|
+
let near = 0;
|
|
363
|
+
for (let i = 0; i < 8; i++) {
|
|
364
|
+
const c = [(i & 1) - 0.5, ((i >> 1) & 1) - 0.5, ((i >> 2) & 1) - 0.5];
|
|
365
|
+
near += extinctionAt([world[0] + c[0] * voxel[0], world[1] + c[1] * voxel[1], world[2] + c[2] * voxel[2]])[0];
|
|
366
|
+
}
|
|
367
|
+
if (!(near > 0))
|
|
368
|
+
return out;
|
|
369
|
+
const jitter = vdbFrameNoise(jitterValue, fragCoord);
|
|
370
|
+
const sky = normalize3(skyDirection);
|
|
371
|
+
const slot = (i) => {
|
|
372
|
+
if (i >= lights.length)
|
|
373
|
+
return [1, 1, 0, 0];
|
|
374
|
+
const l = lights[i];
|
|
375
|
+
const isDirection = l[3] < 1.5;
|
|
376
|
+
const toLight = [l[0] - world[0], l[1] - world[1], l[2] - world[2]];
|
|
377
|
+
const dir = isDirection ? normalize3([l[0], l[1], l[2]]) : normalize3(toLight);
|
|
378
|
+
const optical = { opticalDepth: 0 };
|
|
379
|
+
const result = vdbFrameGridMarch(extinctionAt, grid, world, dir, isDirection ? 1e20 : Math.hypot(...toLight), jitter, multipleScattering, octaves, optical);
|
|
380
|
+
if (modes.twoSided) {
|
|
381
|
+
const back = vdbFrameGridMarch(extinctionAt, grid, world, [-dir[0], -dir[1], -dir[2]], 1e20, jitter, multipleScattering, octaves);
|
|
382
|
+
result[1] = vdbFrameTwoSidedDiffusion(result[0], result[2], result[3], back[2]);
|
|
383
|
+
}
|
|
384
|
+
if (modes.neural)
|
|
385
|
+
result[1] = result[0] + modes.neural(world, dir, optical.opticalDepth);
|
|
386
|
+
return result;
|
|
387
|
+
};
|
|
388
|
+
const ls = [0, 1, 2, 3, 4, 5].map(slot);
|
|
389
|
+
const up = vdbFrameGridMarch(extinctionAt, grid, world, sky, 1e20, jitter, multipleScattering, octaves);
|
|
390
|
+
const down = vdbFrameGridMarch(extinctionAt, grid, world, [-sky[0], -sky[1], -sky[2]], 1e20, jitter, multipleScattering, octaves);
|
|
391
|
+
const skyTotal = (f, b) => (multipleScattering > 0 ? vdbFrameIsotropicDiffusion(f[2], b[2], f[3]) : f[1]);
|
|
392
|
+
out[0] = [skyTotal(up, down), skyTotal(down, up), ls[0][1], ls[1][1]];
|
|
393
|
+
out[1] = [ls[2][1], ls[3][1], ls[4][1], ls[5][1]];
|
|
394
|
+
out[2] = [ls[0][0], ls[1][0], ls[2][0], ls[3][0]];
|
|
395
|
+
out[3] = [ls[4][0], ls[5][0], 1, 1];
|
|
396
|
+
return out;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* sampleShadows: the slot atlases at a world position, 1 outside the grid, blended toward the next
|
|
400
|
+
* cascade within 10% of a cascade's sides (no visible cascade borders).
|
|
401
|
+
*/
|
|
402
|
+
export function vdbFrameSampleShadows(atlases, grid, world) {
|
|
403
|
+
const out = atlases.map(() => [1, 1, 1, 1]);
|
|
404
|
+
const cascade = vdbFrameFindCascade(grid, world, 0);
|
|
405
|
+
if (cascade < 0)
|
|
406
|
+
return out;
|
|
407
|
+
const uvw = vdbFrameGridUvw(grid, cascade, world);
|
|
408
|
+
atlases.forEach((a, i) => {
|
|
409
|
+
out[i] = vdbFrameSampleGrid(a, grid, cascade, uvw);
|
|
410
|
+
});
|
|
411
|
+
const side = Math.min(uvw[0], uvw[1], uvw[2], 1 - uvw[0], 1 - uvw[1], 1 - uvw[2]);
|
|
412
|
+
const blend = 1 - smoothstep(0, 0.1, side);
|
|
413
|
+
if (blend > 0) {
|
|
414
|
+
const next = vdbFrameFindCascade(grid, world, cascade + 1);
|
|
415
|
+
if (next >= 0) {
|
|
416
|
+
const nextUvw = vdbFrameGridUvw(grid, next, world);
|
|
417
|
+
atlases.forEach((a, i) => {
|
|
418
|
+
const v = vdbFrameSampleGrid(a, grid, next, nextUvw);
|
|
419
|
+
out[i] = out[i].map((x, c) => x + (v[c] - x) * blend);
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return out;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* The density pass of 'frame' lighting at one froxel of one volume (FrameDensityMaterial `buildNodes`,
|
|
427
|
+
* grey, octaves off, no environment term): the slice's sub-step pre-integration through the source,
|
|
428
|
+
* the visible position, and the shadow slots there. Returns the 4 MRT outputs (before additive
|
|
429
|
+
* blending), or null when the froxel is discarded. `fragCoord` is the atlas pixel (bottom-left).
|
|
430
|
+
*/
|
|
431
|
+
export function vdbFrameDensityFroxel(fragCoord, p) {
|
|
432
|
+
const f = vdbFrameDensityFroxelSteps(fragCoord, p);
|
|
433
|
+
if (!f)
|
|
434
|
+
return null;
|
|
435
|
+
const { viewNear, viewFar, localNear, localFar, t0, segment, steps, subStepLength, lod, jitter, mul } = f;
|
|
436
|
+
const lerp3 = (x, y, t) => [x[0] + (y[0] - x[0]) * t, x[1] + (y[1] - x[1]) * t, x[2] + (y[2] - x[2]) * t];
|
|
437
|
+
let extinctionSum = 0;
|
|
438
|
+
let transmittance = 1;
|
|
439
|
+
let visibleWeight = 0;
|
|
440
|
+
let visibleTSum = 0;
|
|
441
|
+
for (let i = 0; i < steps; i++) {
|
|
442
|
+
const t = t0 + segment * ((i + jitter) / steps);
|
|
443
|
+
const e = p.extinctionAt(lerp3(localNear, localFar, t), lod) * p.opacity * vdbFrameDistanceFade(p.fadeRadius, lerp3(viewNear, viewFar, t));
|
|
444
|
+
const stepT = Math.exp(-e * subStepLength);
|
|
445
|
+
const w = transmittance * (1 - stepT);
|
|
446
|
+
visibleWeight += w;
|
|
447
|
+
visibleTSum += w * t;
|
|
448
|
+
extinctionSum += e;
|
|
449
|
+
transmittance *= stepT;
|
|
450
|
+
}
|
|
451
|
+
return densityFroxelTail(p, viewNear, viewFar, mul, extinctionSum, steps, segment, visibleWeight, visibleTSum);
|
|
452
|
+
}
|
|
453
|
+
/** The froxel geometry of the density pass (and the inject pre-integration): box segment, sub-steps, lods. null: discarded. */
|
|
454
|
+
export function vdbFrameDensityFroxelSteps(fragCoord, p) {
|
|
455
|
+
const froxel = vdbFrameFroxel(p.froxelGrid, p.columns, p.range, p.projectionInverse, fragCoord);
|
|
456
|
+
const mul = (m, v) => [0, 1, 2].map((r) => m[r] * v[0] + m[4 + r] * v[1] + m[8 + r] * v[2] + m[12 + r]);
|
|
457
|
+
const { viewNear, viewFar } = froxel;
|
|
458
|
+
const localNear = mul(p.viewToLocal, viewNear);
|
|
459
|
+
const localFar = mul(p.viewToLocal, viewFar);
|
|
460
|
+
// boxSegment of the unit box
|
|
461
|
+
const dir = [localFar[0] - localNear[0], localFar[1] - localNear[1], localFar[2] - localNear[2]];
|
|
462
|
+
let t0 = 0;
|
|
463
|
+
let t1 = 1;
|
|
464
|
+
{
|
|
465
|
+
let lo = -Infinity;
|
|
466
|
+
let hi = Infinity;
|
|
467
|
+
for (let a = 0; a < 3; a++) {
|
|
468
|
+
const inv = 1 / dir[a];
|
|
469
|
+
const ta = (-0.5 - localNear[a]) * inv;
|
|
470
|
+
const tb = (0.5 - localNear[a]) * inv;
|
|
471
|
+
lo = Math.max(lo, Math.min(ta, tb));
|
|
472
|
+
hi = Math.min(hi, Math.max(ta, tb));
|
|
473
|
+
}
|
|
474
|
+
t0 = Math.max(0, lo);
|
|
475
|
+
t1 = Math.min(1, hi);
|
|
476
|
+
}
|
|
477
|
+
if (t0 >= t1)
|
|
478
|
+
return null;
|
|
479
|
+
const segment = t1 - t0;
|
|
480
|
+
const getLod = (size) => Math.max(0, Math.log2(size * p.maxTexels));
|
|
481
|
+
const sliceMiddle = (froxel.sliceNear + froxel.sliceFar) * 0.5;
|
|
482
|
+
const a = vdbFrameViewPosition(p.projectionInverse, [froxel.uv[0] + 1 / p.froxelGrid[0], froxel.uv[1]], sliceMiddle);
|
|
483
|
+
const b = vdbFrameViewPosition(p.projectionInverse, froxel.uv, sliceMiddle);
|
|
484
|
+
const widthLod = getLod(Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]) / p.worldScale);
|
|
485
|
+
const sampledLod = p.mipLevels > 0 ? Math.min(widthLod, p.mipLevels) : 0;
|
|
486
|
+
const boxLength = Math.hypot(...dir) * segment;
|
|
487
|
+
const steps = Math.trunc(Math.min(Math.max(Math.ceil(Math.pow(2, getLod(boxLength) - sampledLod) * 2), 1), p.subSteps));
|
|
488
|
+
const subStepLength = (Math.hypot(viewFar[0] - viewNear[0], viewFar[1] - viewNear[1], viewFar[2] - viewNear[2]) * segment) / steps;
|
|
489
|
+
const lod = Math.max(widthLod, getLod(subStepLength / p.worldScale));
|
|
490
|
+
const jitter = vdbFrameNoise(p.jitter, fragCoord);
|
|
491
|
+
return { froxel, viewNear, viewFar, localNear, localFar, t0, segment, steps, subStepLength, lod, jitter, mul };
|
|
492
|
+
}
|
|
493
|
+
function densityFroxelTail(p, viewNear, viewFar, mul, extinctionSum, steps, segment, visibleWeight, visibleTSum) {
|
|
494
|
+
const lerp3 = (x, y, t) => [x[0] + (y[0] - x[0]) * t, x[1] + (y[1] - x[1]) * t, x[2] + (y[2] - x[2]) * t];
|
|
495
|
+
const extinction = (extinctionSum / steps) * segment;
|
|
496
|
+
if (!(extinction > 0))
|
|
497
|
+
return null;
|
|
498
|
+
const visibleT = visibleWeight > 0 ? visibleTSum / visibleWeight : 0.5;
|
|
499
|
+
const visibleWorld = mul(p.cameraWorld, lerp3(viewNear, viewFar, visibleT));
|
|
500
|
+
const sh = p.shadows ? vdbFrameSampleShadows(p.shadows.atlases, p.shadows.grid, visibleWorld) : [1, 2, 3, 4].map(() => [1, 1, 1, 1]);
|
|
501
|
+
const shadow0 = [...sh[0]];
|
|
502
|
+
const shadow1 = [...sh[1]];
|
|
503
|
+
const directs = [sh[2][0], sh[2][1], sh[2][2], sh[2][3], sh[3][0], sh[3][1]];
|
|
504
|
+
const m = p.cameraWorld;
|
|
505
|
+
const ray = normalize3([0, 1, 2].map((r) => m[r] * (viewFar[0] - viewNear[0]) + m[4 + r] * (viewFar[1] - viewNear[1]) + m[8 + r] * (viewFar[2] - viewNear[2])));
|
|
506
|
+
const slotRef = [
|
|
507
|
+
[shadow0, 2],
|
|
508
|
+
[shadow0, 3],
|
|
509
|
+
[shadow1, 0],
|
|
510
|
+
[shadow1, 1],
|
|
511
|
+
[shadow1, 2],
|
|
512
|
+
[shadow1, 3],
|
|
513
|
+
];
|
|
514
|
+
const octaves = p.octaves ?? vdbFrameOctavesOff;
|
|
515
|
+
const phaseSpectrum = p.phaseSpectrum ?? [1, 1, 0];
|
|
516
|
+
slotRef.forEach(([s, c], index) => {
|
|
517
|
+
if (index < p.sceneLightCount) {
|
|
518
|
+
const l = p.lightPositions[index];
|
|
519
|
+
const lightDir = l[3] < 1.5 ? [l[0], l[1], l[2]] : normalize3([l[0] - visibleWorld[0], l[1] - visibleWorld[1], l[2] - visibleWorld[2]]);
|
|
520
|
+
// frameShadowedLight(...).g: the green phase × direct + the scattered light
|
|
521
|
+
s[c] = vdbFrameShadowedLightColor(p.phase, phaseSpectrum, octaves, ray, lightDir, [directs[index], s[c]])[1];
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
s[c] = vdbFrameShadowTotal(s[c], octaves);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
shadow0[0] = vdbFrameShadowTotal(shadow0[0], octaves);
|
|
528
|
+
shadow0[1] = vdbFrameShadowTotal(shadow0[1], octaves);
|
|
529
|
+
const ext = (v) => v.map((x) => Math.min(x * extinction, 6.0e4));
|
|
530
|
+
const emission = [...p.scatterColor];
|
|
531
|
+
if (p.environmentGrid && p.shadows) {
|
|
532
|
+
// sampleEnvironmentGrid: the last cascade, its own atlas; the unshadowed light (× the octave total) outside it
|
|
533
|
+
const g = p.shadows.grid;
|
|
534
|
+
const uvw = vdbFrameGridUvw(g, g.count - 1, visibleWorld);
|
|
535
|
+
const outside = vdbFrameShadowTotal(1, octaves);
|
|
536
|
+
const env = vdbFrameInsideGrid(g.resolution, uvw) ? vdbFrameSampleTiles(p.environmentGrid.atlas, g.resolution, 0, p.environmentGrid.columns, uvw) : p.environmentGrid.unshadowed.map((v) => v * outside);
|
|
537
|
+
for (let c = 0; c < 3; c++)
|
|
538
|
+
emission[c] = emission[c] + (p.baseColor[c] * env[c]) / Math.PI;
|
|
539
|
+
}
|
|
540
|
+
return [
|
|
541
|
+
[p.baseColor[0] * extinction, p.baseColor[1] * extinction, p.baseColor[2] * extinction, extinction],
|
|
542
|
+
[emission[0] * extinction, emission[1] * extinction, emission[2] * extinction, visibleT * extinction],
|
|
543
|
+
ext(shadow0),
|
|
544
|
+
ext(shadow1),
|
|
545
|
+
];
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* The environment grid pass (FrameEnvironmentGridMaterial, grey) at one voxel of the last
|
|
549
|
+
* cascade: `fragCoord` is the pixel of the environment grid atlas (`envColumns` tile columns), `lights`
|
|
550
|
+
* the environment lights without a shadow slot, `unshadowed` their colour sum (the value outside the
|
|
551
|
+
* casters). One-voxel steps that stay in the last cascade; with diffusion the two-sided total of the
|
|
552
|
+
* march and the opposite march. Returns the RGBA output.
|
|
553
|
+
*/
|
|
554
|
+
export function vdbFrameEnvironmentGridVoxel(atlas, grid, envColumns, fragCoord, lights, unshadowed, multipleScattering, octaves = vdbFrameOctavesOff) {
|
|
555
|
+
const cascade = grid.count - 1;
|
|
556
|
+
const res = grid.resolution;
|
|
557
|
+
const tile = [Math.floor(fragCoord[0] / res), Math.floor(fragCoord[1] / res)];
|
|
558
|
+
const z = tile[1] * envColumns + tile[0];
|
|
559
|
+
const uvw0 = [(fragCoord[0] - tile[0] * res) / res, (fragCoord[1] - tile[1] * res) / res, (z + 0.5) / res];
|
|
560
|
+
const voxel = grid.gridVoxel[cascade];
|
|
561
|
+
const m = grid.gridMin[cascade];
|
|
562
|
+
const s = grid.gridSize[cascade];
|
|
563
|
+
const world = [m[0] + uvw0[0] * s[0], m[1] + uvw0[1] * s[1], m[2] + uvw0[2] * s[2]];
|
|
564
|
+
const uvwOf = (p) => [(p[0] - m[0]) / s[0], (p[1] - m[1]) / s[1], (p[2] - m[2]) / s[2]];
|
|
565
|
+
const sample = (p) => vdbFrameSampleGrid(atlas, grid, cascade, uvwOf(p));
|
|
566
|
+
let near = 0;
|
|
567
|
+
for (let i = 0; i < 8; i++) {
|
|
568
|
+
const c = [(i & 1) - 0.5, ((i >> 1) & 1) - 0.5, ((i >> 2) & 1) - 0.5];
|
|
569
|
+
near += sample([world[0] + c[0] * voxel[0], world[1] + c[1] * voxel[1], world[2] + c[2] * voxel[2]])[0];
|
|
570
|
+
}
|
|
571
|
+
// Octaves: the unshadowed light gets the octaves too
|
|
572
|
+
const outside = vdbFrameShadowTotal(1, octaves);
|
|
573
|
+
if (!(z < res && near > 0))
|
|
574
|
+
return [unshadowed[0] * outside, unshadowed[1] * outside, unshadowed[2] * outside, 1];
|
|
575
|
+
const marchDepths = (dir) => {
|
|
576
|
+
const perUnit = Math.max(Math.abs(dir[0]) / voxel[0], Math.abs(dir[1]) / voxel[1], Math.abs(dir[2]) / voxel[2]);
|
|
577
|
+
const step = 1 / perUnit;
|
|
578
|
+
const probe = [world[0] + dir[0] * step * 0.5, world[1] + dir[1] * step * 0.5, world[2] + dir[2] * step * 0.5];
|
|
579
|
+
const depths = [0, 0, 0];
|
|
580
|
+
for (let i = 0; i < 1024; i++) {
|
|
581
|
+
const uvw = uvwOf(probe);
|
|
582
|
+
if (uvw.some((v) => v < 0 || v > 1) || vdbFrameShadowMarchDepth(depths, multipleScattering, octaves) > 6)
|
|
583
|
+
break;
|
|
584
|
+
const v = vdbFrameSampleGrid(atlas, grid, cascade, uvw);
|
|
585
|
+
const d = vdbFrameShadowStep(v[0], v[1], multipleScattering);
|
|
586
|
+
for (let c = 0; c < 3; c++) {
|
|
587
|
+
depths[c] = depths[c] + d[c] * step;
|
|
588
|
+
probe[c] = probe[c] + dir[c] * step;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return depths;
|
|
592
|
+
};
|
|
593
|
+
const irradiance = [0, 0, 0];
|
|
594
|
+
for (const light of lights) {
|
|
595
|
+
const depths = marchDepths(light.direction);
|
|
596
|
+
const total = multipleScattering > 0
|
|
597
|
+
? vdbFrameIsotropicDiffusion(depths[2], marchDepths([-light.direction[0], -light.direction[1], -light.direction[2]])[2], depths[1])
|
|
598
|
+
: vdbFrameShadowTotal(vdbFrameShadowTransmittance(depths, multipleScattering, octaves)[1], octaves);
|
|
599
|
+
for (let c = 0; c < 3; c++)
|
|
600
|
+
irradiance[c] = irradiance[c] + light.color[c] * total;
|
|
601
|
+
}
|
|
602
|
+
return [Math.max(irradiance[0], 0), Math.max(irradiance[1], 0), Math.max(irradiance[2], 0), 1];
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* The temporal pass reprojection of a froxel centre (FrameTemporalMaterial L123–157): the previous
|
|
606
|
+
* frame's uv and fractional slice of a world position, and the history blend (the motion of a
|
|
607
|
+
* quarter cell or more uses only the current froxel). Returns null when the point is outside the
|
|
608
|
+
* previous froxel grid (or behind its camera).
|
|
609
|
+
*/
|
|
610
|
+
export function vdbFrameReproject(world, previousView, previousProjection, previousRange, grid, current, temporalBlend) {
|
|
611
|
+
const mul = (m, v) => {
|
|
612
|
+
const o = [0, 0, 0, 0];
|
|
613
|
+
for (let r = 0; r < 4; r++)
|
|
614
|
+
o[r] = m[r] * v[0] + m[4 + r] * v[1] + m[8 + r] * v[2] + m[12 + r] * v[3];
|
|
615
|
+
return o;
|
|
616
|
+
};
|
|
617
|
+
const view = mul(previousView, [world[0], world[1], world[2], 1]);
|
|
618
|
+
const clip = mul(previousProjection, view);
|
|
619
|
+
if (!(clip[3] > 0))
|
|
620
|
+
return null;
|
|
621
|
+
const uv = [(clip[0] / clip[3]) * 0.5 + 0.5, (clip[1] / clip[3]) * 0.5 + 0.5];
|
|
622
|
+
const t = Math.log(Math.max(-view[2], 1e-6) / previousRange[0]) / Math.log(previousRange[1] / previousRange[0]);
|
|
623
|
+
const slice = t * grid[2] - 0.5;
|
|
624
|
+
const inside = Math.min(uv[0], uv[1]) >= 0 && Math.max(uv[0], uv[1]) <= 1 && slice >= -0.5 && slice <= grid[2] - 0.5;
|
|
625
|
+
if (!inside)
|
|
626
|
+
return null;
|
|
627
|
+
const motion = Math.hypot((uv[0] - current.uv[0]) * grid[0], (uv[1] - current.uv[1]) * grid[1], slice - current.slice);
|
|
628
|
+
const blend = temporalBlend + (1 - temporalBlend) * Math.min(Math.max(motion * 4, 0), 1);
|
|
629
|
+
return { uv, slice, blend };
|
|
630
|
+
}
|
|
631
|
+
const smoothstep = (e0, e1, x) => {
|
|
632
|
+
const t = Math.min(Math.max((x - e0) / (e1 - e0), 0), 1);
|
|
633
|
+
return t * t * (3 - 2 * t);
|
|
634
|
+
};
|
|
635
|
+
/** three's `getDistanceAttenuation` (Frostbite window). */
|
|
636
|
+
const distanceAttenuation = (d, cutoff, decay) => {
|
|
637
|
+
const falloff = 1 / Math.max(Math.pow(d, decay), 0.01);
|
|
638
|
+
return cutoff > 0 ? falloff * Math.pow(Math.min(Math.max(1 - Math.pow(d / cutoff, 4), 0), 1), 2) : falloff;
|
|
639
|
+
};
|
|
640
|
+
/**
|
|
641
|
+
* The lighting pass of 'frame' lighting at one froxel (FrameLightingMaterial `createFragmentNode`,
|
|
642
|
+
* grey, light probe off): from the 4 density targets
|
|
643
|
+
* (albedo·σ, σ), (emission·σ, t·σ), (sky up, sky down, slot 0, slot 1)·σ, (slots 2–5)·σ, the froxel's
|
|
644
|
+
* view segment and the camera matrix (column-major). Returns the premultiplied (radiance·α, α), or
|
|
645
|
+
* zeros when σ ≤ 0 (the pass discards; the target is cleared).
|
|
646
|
+
*/
|
|
647
|
+
export function vdbFrameLightingFroxel(density, viewNear, viewFar, cameraWorld, inputs) {
|
|
648
|
+
const [albedoT, emissionT, shadow0T, shadow1T] = density;
|
|
649
|
+
const extinction = albedoT[3];
|
|
650
|
+
if (!(extinction > 0))
|
|
651
|
+
return [0, 0, 0, 0];
|
|
652
|
+
const m = cameraWorld;
|
|
653
|
+
const visibleT = Math.min(Math.max(emissionT[3] / extinction, 0), 1);
|
|
654
|
+
const view = [viewNear[0] + (viewFar[0] - viewNear[0]) * visibleT, viewNear[1] + (viewFar[1] - viewNear[1]) * visibleT, viewNear[2] + (viewFar[2] - viewNear[2]) * visibleT];
|
|
655
|
+
const world = [0, 1, 2].map((r) => m[r] * view[0] + m[4 + r] * view[1] + m[8 + r] * view[2] + m[12 + r]);
|
|
656
|
+
const seg = [viewFar[0] - viewNear[0], viewFar[1] - viewNear[1], viewFar[2] - viewNear[2]];
|
|
657
|
+
const ray = normalize3([0, 1, 2].map((r) => m[r] * seg[0] + m[4 + r] * seg[1] + m[8 + r] * seg[2]));
|
|
658
|
+
const s0 = shadow0T.map((v) => v / extinction);
|
|
659
|
+
const s1 = shadow1T.map((v) => v / extinction);
|
|
660
|
+
const slots = [s0[2], s0[3], s1[0], s1[1], s1[2], s1[3]];
|
|
661
|
+
const skyUp = s0[0] * 0.5;
|
|
662
|
+
const skyDown = s0[1] * 0.5;
|
|
663
|
+
const spectrum = inputs.phaseSpectrum ?? [1, 1, 0];
|
|
664
|
+
const colorPhase = spectrum[2] > 0.5;
|
|
665
|
+
const directs = colorPhase && inputs.directAt ? inputs.directAt(world) : [1, 1, 1, 1, 1, 1];
|
|
666
|
+
const irradiance = [0, 1, 2].map((c) => inputs.ambient[c] + inputs.hemiSky[c] * skyUp + inputs.hemiGround[c] * skyDown);
|
|
667
|
+
inputs.lights.forEach((light, i) => {
|
|
668
|
+
const p = light.position;
|
|
669
|
+
const toLight = [p[0] - world[0], p[1] - world[1], p[2] - world[2]];
|
|
670
|
+
const lightDistance = Math.hypot(...toLight);
|
|
671
|
+
const dir = p[3] < 1.5 ? [p[0], p[1], p[2]] : normalize3(toLight);
|
|
672
|
+
const spot = p[3] > 2.5 && light.spot ? smoothstep(light.spot[3], light.penumbra ?? 1, normalize3(toLight)[0] * light.spot[0] + normalize3(toLight)[1] * light.spot[1] + normalize3(toLight)[2] * light.spot[2]) : 1;
|
|
673
|
+
const dist = p[3] > 1.5 ? distanceAttenuation(lightDistance, light.falloff?.[0] ?? 0, light.falloff?.[1] ?? 0) : 1;
|
|
674
|
+
// A light with no shadow slot: no shadow (1, 1); octaves still add their light.
|
|
675
|
+
const unshadowed = vdbFrameShadowedLightColor(inputs.phase, spectrum, inputs.octaves ?? vdbFrameOctavesOff, ray, dir, [1, 1]);
|
|
676
|
+
const hasSlot = i < inputs.shadowLightCount;
|
|
677
|
+
const shadow = i < 6 ? slots[i] : 1;
|
|
678
|
+
const factor = hasSlot ? [shadow, shadow, shadow] : unshadowed;
|
|
679
|
+
// Per-channel phases: the slot holds the green phase; the direct light adds the red and blue difference.
|
|
680
|
+
if (colorPhase && hasSlot) {
|
|
681
|
+
const phase = vdbFramePhaseColor(inputs.phase, spectrum, ray, dir);
|
|
682
|
+
const direct = i < 6 ? directs[i] : 1;
|
|
683
|
+
for (let c = 0; c < 3; c++)
|
|
684
|
+
factor[c] = factor[c] + (phase[c] - phase[1]) * direct;
|
|
685
|
+
}
|
|
686
|
+
for (let c = 0; c < 3; c++)
|
|
687
|
+
irradiance[c] = irradiance[c] + light.color[c] * factor[c] * spot * dist;
|
|
688
|
+
});
|
|
689
|
+
inputs.environmentColors.forEach((color, i) => {
|
|
690
|
+
const slot = inputs.environmentShadowSlot + i;
|
|
691
|
+
const shadow = slot < 6 ? slots[slot] : 1;
|
|
692
|
+
for (let c = 0; c < 3; c++)
|
|
693
|
+
irradiance[c] = irradiance[c] + color[c] * shadow;
|
|
694
|
+
});
|
|
695
|
+
const alpha = 1 - Math.exp(-extinction * Math.hypot(...seg));
|
|
696
|
+
const out = [0, 0, 0, alpha];
|
|
697
|
+
for (let c = 0; c < 3; c++) {
|
|
698
|
+
const radiance = (albedoT[c] / extinction) * irradiance[c] * (1 / Math.PI) + emissionT[c] / extinction;
|
|
699
|
+
out[c] = radiance * alpha;
|
|
700
|
+
}
|
|
701
|
+
return out;
|
|
702
|
+
}
|
|
703
|
+
//# sourceMappingURL=grid.js.map
|