@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,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `VDBVolumeMaterial`: the fragment raymarch of one grid in a `VDBGridPool`,
|
|
3
|
+
* through a `VDBGridNode` (task K2.3, docs/archive/handoffs/K2.md). It replaces v1's
|
|
4
|
+
* `NanoVDBVolumeMaterial`, which bound one grid image as its own storage
|
|
5
|
+
* attribute and rewrote the vendored library's buffer global.
|
|
6
|
+
*
|
|
7
|
+
* const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });
|
|
8
|
+
* const material = new VDBVolumeMaterial(renderer, grids, id, { densityScale: 40 });
|
|
9
|
+
* scene.add(new Mesh(vdbProxyGeometry(pool.info(id)), material));
|
|
10
|
+
* // per frame: pool.update(encoder) (or pool.flush()), then grids.update(), then render.
|
|
11
|
+
*
|
|
12
|
+
* The march is one entry `wgslFn` over the public `vdb*` WGSL API, with
|
|
13
|
+
* `grids.module` as its include (the module carries the pool binding):
|
|
14
|
+
* - the world ray goes into the grid's index space through the record's
|
|
15
|
+
* affine (`vdbWorldToIndex`/`vdbWorldToIndexDir`), so `pool.setTransform`
|
|
16
|
+
* instances render where they are;
|
|
17
|
+
* - it is clipped to the sampler's support box (`vdbRayClipSupport`,
|
|
18
|
+
* `[min - 1, max + 1]` for trilinear), not the voxel-cell box, so the
|
|
19
|
+
* min-side half voxel the trilinear taps reach is marched too;
|
|
20
|
+
* - fixed-step density accumulation with `vdbSample` (the node's sampler),
|
|
21
|
+
* premultiplied front-to-back compositing, early-out at low transmittance.
|
|
22
|
+
* The step lattice is anchored at the voxel-box entry (`vdbRayClip`, where
|
|
23
|
+
* v1 started) and extended back over the support shell, so samples inside
|
|
24
|
+
* the box sit where v1's did; only the shell samples are new (v1 skipped
|
|
25
|
+
* that half voxel, which shows where a grid's min-side voxels are dense);
|
|
26
|
+
* - lighting as in v1: Henyey-Greenstein phase on a directional sun, an
|
|
27
|
+
* N-step shadow march toward the sun (a second accessor), a constant
|
|
28
|
+
* ambient floor, and a per-fragment budget on the total samples.
|
|
29
|
+
*
|
|
30
|
+
* Rendered on a proxy box with `side: BackSide` (the camera can be inside);
|
|
31
|
+
* entry and exit come from the analytic clip, not the rasterized faces. The
|
|
32
|
+
* material is `transparent`, `depthWrite: false`, premultiplied alpha. Scene
|
|
33
|
+
* depth compositing is not done (v1 neither).
|
|
34
|
+
*
|
|
35
|
+
* Every tunable is a live TSL uniform (`material.densityScale.value = ...`).
|
|
36
|
+
* The grid is a `uint` uniform too when the constructor got a number
|
|
37
|
+
* (`material.gridId.value = otherId`), so one material can show any grid of
|
|
38
|
+
* the types its `VDBGridNode` compiles without a rebuild.
|
|
39
|
+
*
|
|
40
|
+
* Units and assumptions:
|
|
41
|
+
* - The march runs in the grid's **index space**: `stepSize` is in index
|
|
42
|
+
* voxels, and `densityScale` integrates per index voxel. Opacity therefore
|
|
43
|
+
* does not change with the world size of the grid: `pool.setTransform` (or
|
|
44
|
+
* a NanoVDB map) that scales the grid scales its footprint, not how opaque
|
|
45
|
+
* it looks.
|
|
46
|
+
* - The proxy mesh is not tied to the grid: after `material.gridId.value = id`
|
|
47
|
+
* or `pool.setTransform(id, ...)`, build a new `vdbProxyGeometry(pool.info(id))`
|
|
48
|
+
* for the mesh, or fragments outside the old box are never rasterized.
|
|
49
|
+
* - The view ray is `positionWorld - cameraPosition`: a perspective camera.
|
|
50
|
+
* An orthographic camera's rays are parallel and do not start at
|
|
51
|
+
* `cameraPosition`, so it renders wrongly.
|
|
52
|
+
*/
|
|
53
|
+
import * as THREE from "three";
|
|
54
|
+
import { NodeMaterial } from "three/webgpu";
|
|
55
|
+
import { uniform } from "three/tsl";
|
|
56
|
+
import { type VDBThreeRendererLike } from "./device.js";
|
|
57
|
+
import { VDBGridNode, type VDBTslNode } from "./grid-node.js";
|
|
58
|
+
/** Default hard caps of the compiled loops (the live uniforms clamp under them). */
|
|
59
|
+
export declare const VDB_VOLUME_MAX_STEPS_CAP = 1024;
|
|
60
|
+
export declare const VDB_VOLUME_SHADOW_STEPS_CAP = 128;
|
|
61
|
+
/**
|
|
62
|
+
* Default cap on the total samples (primary + shadow) one fragment takes.
|
|
63
|
+
* `maxSteps` and `shadowSteps` are independent live uniforms, so their product
|
|
64
|
+
* can reach `maxStepsCap * shadowStepsCap` (~131k at the defaults), a driver
|
|
65
|
+
* timeout risk. Once the budget is spent the shadow loop stops first, then the
|
|
66
|
+
* primary loop, and the fragment returns its partial march.
|
|
67
|
+
*/
|
|
68
|
+
export declare const VDB_VOLUME_SAMPLE_BUDGET_CAP = 16384;
|
|
69
|
+
/** Parameters of {@link VDBVolumeMaterial}: initial uniform values and compile-time caps. */
|
|
70
|
+
export interface VDBVolumeMaterialParameters {
|
|
71
|
+
densityScale?: number;
|
|
72
|
+
/** March step in index voxels. */
|
|
73
|
+
stepSize?: number;
|
|
74
|
+
maxSteps?: number;
|
|
75
|
+
sunDirection?: THREE.Vector3;
|
|
76
|
+
sunColor?: THREE.Color;
|
|
77
|
+
sunIntensity?: number;
|
|
78
|
+
/** Henyey-Greenstein anisotropy g in (-1, 1). */
|
|
79
|
+
anisotropy?: number;
|
|
80
|
+
shadowSteps?: number;
|
|
81
|
+
/** Density multiplier along the shadow ray only. */
|
|
82
|
+
shadowDensity?: number;
|
|
83
|
+
ambient?: number;
|
|
84
|
+
/** Per-pixel jitter of the first sample. Default true. */
|
|
85
|
+
jitter?: boolean;
|
|
86
|
+
/** Hard cap on the primary loop. Default {@link VDB_VOLUME_MAX_STEPS_CAP}. */
|
|
87
|
+
maxStepsCap?: number;
|
|
88
|
+
/** Hard cap on the shadow loop. Default {@link VDB_VOLUME_SHADOW_STEPS_CAP}. */
|
|
89
|
+
shadowStepsCap?: number;
|
|
90
|
+
/** Hard cap on the total samples per fragment. Default {@link VDB_VOLUME_SAMPLE_BUDGET_CAP}. */
|
|
91
|
+
sampleBudgetCap?: number;
|
|
92
|
+
}
|
|
93
|
+
/** A live TSL uniform with its value typed (three types `uniform()`'s value as unknown). */
|
|
94
|
+
type ScalarUniform = ReturnType<typeof uniform> & {
|
|
95
|
+
value: number;
|
|
96
|
+
};
|
|
97
|
+
type Vec3Uniform = ReturnType<typeof uniform> & {
|
|
98
|
+
value: THREE.Vector3;
|
|
99
|
+
};
|
|
100
|
+
type ColorUniform = ReturnType<typeof uniform> & {
|
|
101
|
+
value: THREE.Color;
|
|
102
|
+
};
|
|
103
|
+
/** The `uint` uniform `VDBVolumeMaterial` makes for a numeric grid id (`material.gridId.value = otherId`). */
|
|
104
|
+
export type VDBUintUniform = ReturnType<typeof uniform> & {
|
|
105
|
+
value: number;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* A fragment raymarch of one grid of a `VDBGridPool` (see the file comment for
|
|
109
|
+
* the march). Put it on a `vdbProxyGeometry(pool.info(id))` mesh; each frame
|
|
110
|
+
* run `pool.update(encoder)` (or `pool.flush()`), then `grids.update()`, then
|
|
111
|
+
* render.
|
|
112
|
+
*
|
|
113
|
+
* const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });
|
|
114
|
+
* const material = new VDBVolumeMaterial(renderer, grids, id, { densityScale: 40 });
|
|
115
|
+
* const mesh = new Mesh(vdbProxyGeometry(pool.info(id)), material);
|
|
116
|
+
*
|
|
117
|
+
* - `stepSize` is in index voxels and `densityScale` integrates per index
|
|
118
|
+
* voxel, so opacity ignores the grid's world scale (`setTransform` scaling
|
|
119
|
+
* changes the size on screen, not the opacity).
|
|
120
|
+
* - After `gridId.value = otherId` or `pool.setTransform(id, ...)`, give the
|
|
121
|
+
* mesh a new `vdbProxyGeometry(pool.info(id))`.
|
|
122
|
+
* - Perspective cameras only (the ray starts at `cameraPosition`).
|
|
123
|
+
* - The material must be rendered by the renderer `grids` was made with.
|
|
124
|
+
*
|
|
125
|
+
* @typeParam TGridId What the constructor got as the id: a number (default)
|
|
126
|
+
* makes {@link gridId} a `uint` uniform; a node is kept as given.
|
|
127
|
+
*/
|
|
128
|
+
export declare class VDBVolumeMaterial<TGridId extends number | VDBTslNode = number> extends NodeMaterial {
|
|
129
|
+
readonly isVDBVolumeMaterial = true;
|
|
130
|
+
/** The pool node this material reads (its `module` is the march's include). */
|
|
131
|
+
readonly grids: VDBGridNode;
|
|
132
|
+
/**
|
|
133
|
+
* The grid id: a `uint` uniform when the constructor got a number
|
|
134
|
+
* (`material.gridId.value = otherId`; then give the mesh a new
|
|
135
|
+
* `vdbProxyGeometry`), else the caller's node.
|
|
136
|
+
*/
|
|
137
|
+
readonly gridId: TGridId extends number ? VDBUintUniform : VDBTslNode;
|
|
138
|
+
/** The entry `fn` text (for inspection and tests). */
|
|
139
|
+
readonly entrySource: string;
|
|
140
|
+
/** Extinction per index voxel at density 1 (opacity of a step: `1 - exp(-density * densityScale * stepSize)`). Default 40. */
|
|
141
|
+
readonly densityScale: ScalarUniform;
|
|
142
|
+
/** March step in index voxels (live; the lattice re-anchors per fragment). Default 0.75. */
|
|
143
|
+
readonly stepSize: ScalarUniform;
|
|
144
|
+
/** Primary march steps, clamped to `[1, maxStepsCap]`. Default 512. */
|
|
145
|
+
readonly maxSteps: ScalarUniform;
|
|
146
|
+
/** Direction toward the sun, world space (normalized at construction; keep it normalized). */
|
|
147
|
+
readonly sunDirection: Vec3Uniform;
|
|
148
|
+
/** Sun colour (linear). Default (1, 0.95, 0.9). */
|
|
149
|
+
readonly sunColor: ColorUniform;
|
|
150
|
+
/** Sun intensity. Default 3. */
|
|
151
|
+
readonly sunIntensity: ScalarUniform;
|
|
152
|
+
/** Henyey-Greenstein anisotropy g in (-1, 1). Default 0.3. */
|
|
153
|
+
readonly anisotropy: ScalarUniform;
|
|
154
|
+
/** Shadow-ray steps toward the sun per lit sample, clamped to `[0, shadowStepsCap]`. Default 12. */
|
|
155
|
+
readonly shadowSteps: ScalarUniform;
|
|
156
|
+
/** Density multiplier along the shadow ray only. Default 1. */
|
|
157
|
+
readonly shadowDensity: ScalarUniform;
|
|
158
|
+
/** Constant ambient term added to the sun light. Default 0.15. */
|
|
159
|
+
readonly ambient: ScalarUniform;
|
|
160
|
+
/** 1 = per-pixel jitter of the first sample on, 0 = off. */
|
|
161
|
+
readonly jitter: ScalarUniform;
|
|
162
|
+
/**
|
|
163
|
+
* @param renderer The initialized `WebGPURenderer` the pool and `grids` live on.
|
|
164
|
+
* @param grids A `VDBGridNode` made on this same renderer, with profile
|
|
165
|
+
* `sample` or `march` and `helpers: ['rayClipSupport']`. Share one per
|
|
166
|
+
* pool: one module per shader.
|
|
167
|
+
* @param gridId The grid's pool id (a number, made a `uint` uniform) or a `uint` node.
|
|
168
|
+
* @throws VDBError `VDB_BAD_OPTION` for a `grids` this material can't use
|
|
169
|
+
* (another renderer, profile, helpers), a bad id or cap;
|
|
170
|
+
* `VDB_UNSUPPORTED_DEVICE` for an uninitialized renderer.
|
|
171
|
+
*/
|
|
172
|
+
constructor(renderer: VDBThreeRendererLike, grids: VDBGridNode, gridId: TGridId, params?: VDBVolumeMaterialParameters);
|
|
173
|
+
}
|
|
174
|
+
/** What {@link vdbProxyGeometry} reads from `pool.info(id)`. */
|
|
175
|
+
export interface VDBProxyGridInfo {
|
|
176
|
+
readonly indexBBox: {
|
|
177
|
+
readonly min: readonly number[];
|
|
178
|
+
readonly max: readonly number[];
|
|
179
|
+
};
|
|
180
|
+
/** 3x4 row-major index-to-world affine (`pool.info(id).indexToWorld`). */
|
|
181
|
+
readonly indexToWorld: ArrayLike<number>;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* A world-space box for a grid's proxy mesh (add it with an identity
|
|
185
|
+
* transform): the AABB of the index box's voxels `[min - pad, max + 1 + pad]`
|
|
186
|
+
* through the grid's index-to-world affine. `pad: 0` (default) is
|
|
187
|
+
* `pool.info(id).worldBBox`, the box v1 used; `pad: 1` also covers the
|
|
188
|
+
* min-side half voxel of the trilinear support that `VDBVolumeMaterial`
|
|
189
|
+
* marches (rays that cross only that shell are otherwise not rasterized).
|
|
190
|
+
*/
|
|
191
|
+
export declare function vdbProxyGeometry(info: VDBProxyGridInfo, options?: {
|
|
192
|
+
pad?: number;
|
|
193
|
+
}): THREE.BoxGeometry;
|
|
194
|
+
export {};
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `VDBVolumeMaterial`: the fragment raymarch of one grid in a `VDBGridPool`,
|
|
3
|
+
* through a `VDBGridNode` (task K2.3, docs/archive/handoffs/K2.md). It replaces v1's
|
|
4
|
+
* `NanoVDBVolumeMaterial`, which bound one grid image as its own storage
|
|
5
|
+
* attribute and rewrote the vendored library's buffer global.
|
|
6
|
+
*
|
|
7
|
+
* const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });
|
|
8
|
+
* const material = new VDBVolumeMaterial(renderer, grids, id, { densityScale: 40 });
|
|
9
|
+
* scene.add(new Mesh(vdbProxyGeometry(pool.info(id)), material));
|
|
10
|
+
* // per frame: pool.update(encoder) (or pool.flush()), then grids.update(), then render.
|
|
11
|
+
*
|
|
12
|
+
* The march is one entry `wgslFn` over the public `vdb*` WGSL API, with
|
|
13
|
+
* `grids.module` as its include (the module carries the pool binding):
|
|
14
|
+
* - the world ray goes into the grid's index space through the record's
|
|
15
|
+
* affine (`vdbWorldToIndex`/`vdbWorldToIndexDir`), so `pool.setTransform`
|
|
16
|
+
* instances render where they are;
|
|
17
|
+
* - it is clipped to the sampler's support box (`vdbRayClipSupport`,
|
|
18
|
+
* `[min - 1, max + 1]` for trilinear), not the voxel-cell box, so the
|
|
19
|
+
* min-side half voxel the trilinear taps reach is marched too;
|
|
20
|
+
* - fixed-step density accumulation with `vdbSample` (the node's sampler),
|
|
21
|
+
* premultiplied front-to-back compositing, early-out at low transmittance.
|
|
22
|
+
* The step lattice is anchored at the voxel-box entry (`vdbRayClip`, where
|
|
23
|
+
* v1 started) and extended back over the support shell, so samples inside
|
|
24
|
+
* the box sit where v1's did; only the shell samples are new (v1 skipped
|
|
25
|
+
* that half voxel, which shows where a grid's min-side voxels are dense);
|
|
26
|
+
* - lighting as in v1: Henyey-Greenstein phase on a directional sun, an
|
|
27
|
+
* N-step shadow march toward the sun (a second accessor), a constant
|
|
28
|
+
* ambient floor, and a per-fragment budget on the total samples.
|
|
29
|
+
*
|
|
30
|
+
* Rendered on a proxy box with `side: BackSide` (the camera can be inside);
|
|
31
|
+
* entry and exit come from the analytic clip, not the rasterized faces. The
|
|
32
|
+
* material is `transparent`, `depthWrite: false`, premultiplied alpha. Scene
|
|
33
|
+
* depth compositing is not done (v1 neither).
|
|
34
|
+
*
|
|
35
|
+
* Every tunable is a live TSL uniform (`material.densityScale.value = ...`).
|
|
36
|
+
* The grid is a `uint` uniform too when the constructor got a number
|
|
37
|
+
* (`material.gridId.value = otherId`), so one material can show any grid of
|
|
38
|
+
* the types its `VDBGridNode` compiles without a rebuild.
|
|
39
|
+
*
|
|
40
|
+
* Units and assumptions:
|
|
41
|
+
* - The march runs in the grid's **index space**: `stepSize` is in index
|
|
42
|
+
* voxels, and `densityScale` integrates per index voxel. Opacity therefore
|
|
43
|
+
* does not change with the world size of the grid: `pool.setTransform` (or
|
|
44
|
+
* a NanoVDB map) that scales the grid scales its footprint, not how opaque
|
|
45
|
+
* it looks.
|
|
46
|
+
* - The proxy mesh is not tied to the grid: after `material.gridId.value = id`
|
|
47
|
+
* or `pool.setTransform(id, ...)`, build a new `vdbProxyGeometry(pool.info(id))`
|
|
48
|
+
* for the mesh, or fragments outside the old box are never rasterized.
|
|
49
|
+
* - The view ray is `positionWorld - cameraPosition`: a perspective camera.
|
|
50
|
+
* An orthographic camera's rays are parallel and do not start at
|
|
51
|
+
* `cameraPosition`, so it renders wrongly.
|
|
52
|
+
*/
|
|
53
|
+
import * as THREE from "three";
|
|
54
|
+
import { NodeMaterial } from "three/webgpu";
|
|
55
|
+
import { cameraPosition, code, positionWorld, screenCoordinate, uniform, wgslFn } from "three/tsl";
|
|
56
|
+
import { VDBError } from "../core/errors.js";
|
|
57
|
+
import { getDevice } from "./device.js";
|
|
58
|
+
import { VDBGridNode } from "./grid-node.js";
|
|
59
|
+
/** Default hard caps of the compiled loops (the live uniforms clamp under them). */
|
|
60
|
+
export const VDB_VOLUME_MAX_STEPS_CAP = 1024;
|
|
61
|
+
export const VDB_VOLUME_SHADOW_STEPS_CAP = 128;
|
|
62
|
+
/**
|
|
63
|
+
* Default cap on the total samples (primary + shadow) one fragment takes.
|
|
64
|
+
* `maxSteps` and `shadowSteps` are independent live uniforms, so their product
|
|
65
|
+
* can reach `maxStepsCap * shadowStepsCap` (~131k at the defaults), a driver
|
|
66
|
+
* timeout risk. Once the budget is spent the shadow loop stops first, then the
|
|
67
|
+
* primary loop, and the fragment returns its partial march.
|
|
68
|
+
*/
|
|
69
|
+
export const VDB_VOLUME_SAMPLE_BUDGET_CAP = 16384;
|
|
70
|
+
const DEFAULTS = {
|
|
71
|
+
densityScale: 40,
|
|
72
|
+
stepSize: 0.75,
|
|
73
|
+
maxSteps: 512,
|
|
74
|
+
sunIntensity: 3,
|
|
75
|
+
anisotropy: 0.3,
|
|
76
|
+
shadowSteps: 12,
|
|
77
|
+
shadowDensity: 1,
|
|
78
|
+
ambient: 0.15,
|
|
79
|
+
};
|
|
80
|
+
/** Entry name of the march `wgslFn`. */
|
|
81
|
+
const ENTRY = "vdbThreeVolumeMarch";
|
|
82
|
+
/**
|
|
83
|
+
* Module-scope helpers of the march, a second include next to `grids.module`
|
|
84
|
+
* (`wgslFn` parses only its first `fn`, so the entry can't hold them).
|
|
85
|
+
*/
|
|
86
|
+
const VOLUME_HELPERS_WGSL = /* wgsl */ `
|
|
87
|
+
fn vdbThreeHgPhase(cos_theta: f32, g: f32) -> f32 {
|
|
88
|
+
let gg = g * g;
|
|
89
|
+
let denom = 1.0 + gg - 2.0 * g * cos_theta;
|
|
90
|
+
return (1.0 - gg) / (12.566370614359172 * pow(max(denom, 1.0e-4), 1.5));
|
|
91
|
+
}
|
|
92
|
+
fn vdbThreeHash12(p: vec2f) -> f32 {
|
|
93
|
+
var p3 = fract(vec3f(p.x, p.y, p.x) * 0.1031);
|
|
94
|
+
p3 = p3 + dot(p3, p3.yzx + 33.33);
|
|
95
|
+
return fract((p3.x + p3.y) * p3.z);
|
|
96
|
+
}
|
|
97
|
+
`;
|
|
98
|
+
/** The march entry, the one `fn` of its `wgslFn`. Caps are compiled in. */
|
|
99
|
+
function marchWgsl(maxStepsCap, shadowStepsCap, sampleBudgetCap) {
|
|
100
|
+
return /* wgsl */ `fn ${ENTRY}(
|
|
101
|
+
grid_id: u32,
|
|
102
|
+
ray_origin_w: vec3f,
|
|
103
|
+
ray_dir_w: vec3f,
|
|
104
|
+
sun_dir_w: vec3f,
|
|
105
|
+
sun_color: vec3f,
|
|
106
|
+
sun_intensity: f32,
|
|
107
|
+
density_scale: f32,
|
|
108
|
+
step_size: f32,
|
|
109
|
+
max_steps: f32,
|
|
110
|
+
g: f32,
|
|
111
|
+
shadow_steps: f32,
|
|
112
|
+
shadow_density: f32,
|
|
113
|
+
ambient: f32,
|
|
114
|
+
jitter: f32,
|
|
115
|
+
pix: vec2f
|
|
116
|
+
) -> vec4f {
|
|
117
|
+
// World -> index through the pool record (instance transform included).
|
|
118
|
+
let o_idx = vdbWorldToIndex(grid_id, ray_origin_w);
|
|
119
|
+
let d_idx = normalize(vdbWorldToIndexDir(grid_id, ray_dir_w));
|
|
120
|
+
let sun_idx = normalize(vdbWorldToIndexDir(grid_id, sun_dir_w));
|
|
121
|
+
|
|
122
|
+
// Clip to the trilinear support box; a dead id misses.
|
|
123
|
+
var span = vec2f(0.0, 1.0e30);
|
|
124
|
+
if !vdbRayClipSupport(grid_id, o_idx, d_idx, &span) {
|
|
125
|
+
return vec4f(0.0);
|
|
126
|
+
}
|
|
127
|
+
// t0 >= 0: no sample behind the eye (camera inside the support box).
|
|
128
|
+
let t0 = max(span.x, 0.0);
|
|
129
|
+
let t1 = span.y;
|
|
130
|
+
|
|
131
|
+
var acc = vdbAccessorInit(grid_id);
|
|
132
|
+
var sacc = vdbAccessorInit(grid_id);
|
|
133
|
+
|
|
134
|
+
// The phase uses the world-space view/sun angle.
|
|
135
|
+
let phase = vdbThreeHgPhase(dot(normalize(ray_dir_w), normalize(sun_dir_w)), g);
|
|
136
|
+
|
|
137
|
+
// The step lattice is anchored where the ray enters the voxel box
|
|
138
|
+
// (vdbRayClip, v1's entry) and extended back to the support entry, so the
|
|
139
|
+
// samples inside the box sit exactly where v1's did.
|
|
140
|
+
var t = t0;
|
|
141
|
+
var cell = vec2f(0.0, 1.0e30);
|
|
142
|
+
if vdbRayClip(grid_id, o_idx, d_idx, &cell) {
|
|
143
|
+
let anchor = max(cell.x, 0.0);
|
|
144
|
+
t = anchor - ceil((anchor - t0) / step_size) * step_size;
|
|
145
|
+
}
|
|
146
|
+
t += step_size * jitter * vdbThreeHash12(pix);
|
|
147
|
+
// The lattice can start before t0 (the anchor is stepped back in whole
|
|
148
|
+
// steps, plus jitter). Skip those steps on the lattice: they are behind the
|
|
149
|
+
// eye (camera in the support shell) or outside the support box.
|
|
150
|
+
if t < t0 {
|
|
151
|
+
t += ceil((t0 - t) / step_size) * step_size;
|
|
152
|
+
}
|
|
153
|
+
var transmittance = 1.0;
|
|
154
|
+
var color = vec3f(0.0);
|
|
155
|
+
let max_i = i32(clamp(max_steps, 1.0, ${maxStepsCap}.0));
|
|
156
|
+
let shadow_n = i32(clamp(shadow_steps, 0.0, ${shadowStepsCap}.0));
|
|
157
|
+
let budget = ${sampleBudgetCap};
|
|
158
|
+
var samples = 0;
|
|
159
|
+
|
|
160
|
+
for (var i = 0; i < max_i; i++) {
|
|
161
|
+
if t > t1 || transmittance < 0.003 || samples >= budget {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
let pos = o_idx + d_idx * t;
|
|
165
|
+
let density = max(vdbSample(&acc, pos), 0.0) * density_scale;
|
|
166
|
+
samples++;
|
|
167
|
+
if density > 0.0 {
|
|
168
|
+
let a = 1.0 - exp(-density * step_size);
|
|
169
|
+
var tau = 0.0;
|
|
170
|
+
var st = step_size;
|
|
171
|
+
for (var s = 0; s < shadow_n; s++) {
|
|
172
|
+
if samples >= budget {
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
let sd = max(vdbSample(&sacc, pos + sun_idx * st), 0.0) * density_scale * shadow_density;
|
|
176
|
+
samples++;
|
|
177
|
+
tau += sd * step_size;
|
|
178
|
+
st += step_size;
|
|
179
|
+
}
|
|
180
|
+
let lit = sun_color * (sun_intensity * exp(-tau) * phase) + vec3f(ambient);
|
|
181
|
+
color += transmittance * a * lit;
|
|
182
|
+
transmittance *= 1.0 - a;
|
|
183
|
+
}
|
|
184
|
+
t += step_size;
|
|
185
|
+
}
|
|
186
|
+
return vec4f(color, 1.0 - transmittance);
|
|
187
|
+
}`;
|
|
188
|
+
}
|
|
189
|
+
function bad(message) {
|
|
190
|
+
return new VDBError("VDB_BAD_OPTION", `VDBVolumeMaterial: ${message}`);
|
|
191
|
+
}
|
|
192
|
+
function positiveInt(name, value, fallback) {
|
|
193
|
+
const v = value ?? fallback;
|
|
194
|
+
if (!Number.isInteger(v) || v < 1)
|
|
195
|
+
throw bad(`${name} must be an integer >= 1, got ${JSON.stringify(value)}.`);
|
|
196
|
+
return v;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* A fragment raymarch of one grid of a `VDBGridPool` (see the file comment for
|
|
200
|
+
* the march). Put it on a `vdbProxyGeometry(pool.info(id))` mesh; each frame
|
|
201
|
+
* run `pool.update(encoder)` (or `pool.flush()`), then `grids.update()`, then
|
|
202
|
+
* render.
|
|
203
|
+
*
|
|
204
|
+
* const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });
|
|
205
|
+
* const material = new VDBVolumeMaterial(renderer, grids, id, { densityScale: 40 });
|
|
206
|
+
* const mesh = new Mesh(vdbProxyGeometry(pool.info(id)), material);
|
|
207
|
+
*
|
|
208
|
+
* - `stepSize` is in index voxels and `densityScale` integrates per index
|
|
209
|
+
* voxel, so opacity ignores the grid's world scale (`setTransform` scaling
|
|
210
|
+
* changes the size on screen, not the opacity).
|
|
211
|
+
* - After `gridId.value = otherId` or `pool.setTransform(id, ...)`, give the
|
|
212
|
+
* mesh a new `vdbProxyGeometry(pool.info(id))`.
|
|
213
|
+
* - Perspective cameras only (the ray starts at `cameraPosition`).
|
|
214
|
+
* - The material must be rendered by the renderer `grids` was made with.
|
|
215
|
+
*
|
|
216
|
+
* @typeParam TGridId What the constructor got as the id: a number (default)
|
|
217
|
+
* makes {@link gridId} a `uint` uniform; a node is kept as given.
|
|
218
|
+
*/
|
|
219
|
+
export class VDBVolumeMaterial extends NodeMaterial {
|
|
220
|
+
isVDBVolumeMaterial = true;
|
|
221
|
+
/** The pool node this material reads (its `module` is the march's include). */
|
|
222
|
+
grids;
|
|
223
|
+
/**
|
|
224
|
+
* The grid id: a `uint` uniform when the constructor got a number
|
|
225
|
+
* (`material.gridId.value = otherId`; then give the mesh a new
|
|
226
|
+
* `vdbProxyGeometry`), else the caller's node.
|
|
227
|
+
*/
|
|
228
|
+
gridId;
|
|
229
|
+
/** The entry `fn` text (for inspection and tests). */
|
|
230
|
+
entrySource;
|
|
231
|
+
/** Extinction per index voxel at density 1 (opacity of a step: `1 - exp(-density * densityScale * stepSize)`). Default 40. */
|
|
232
|
+
densityScale;
|
|
233
|
+
/** March step in index voxels (live; the lattice re-anchors per fragment). Default 0.75. */
|
|
234
|
+
stepSize;
|
|
235
|
+
/** Primary march steps, clamped to `[1, maxStepsCap]`. Default 512. */
|
|
236
|
+
maxSteps;
|
|
237
|
+
/** Direction toward the sun, world space (normalized at construction; keep it normalized). */
|
|
238
|
+
sunDirection;
|
|
239
|
+
/** Sun colour (linear). Default (1, 0.95, 0.9). */
|
|
240
|
+
sunColor;
|
|
241
|
+
/** Sun intensity. Default 3. */
|
|
242
|
+
sunIntensity;
|
|
243
|
+
/** Henyey-Greenstein anisotropy g in (-1, 1). Default 0.3. */
|
|
244
|
+
anisotropy;
|
|
245
|
+
/** Shadow-ray steps toward the sun per lit sample, clamped to `[0, shadowStepsCap]`. Default 12. */
|
|
246
|
+
shadowSteps;
|
|
247
|
+
/** Density multiplier along the shadow ray only. Default 1. */
|
|
248
|
+
shadowDensity;
|
|
249
|
+
/** Constant ambient term added to the sun light. Default 0.15. */
|
|
250
|
+
ambient;
|
|
251
|
+
/** 1 = per-pixel jitter of the first sample on, 0 = off. */
|
|
252
|
+
jitter;
|
|
253
|
+
/**
|
|
254
|
+
* @param renderer The initialized `WebGPURenderer` the pool and `grids` live on.
|
|
255
|
+
* @param grids A `VDBGridNode` made on this same renderer, with profile
|
|
256
|
+
* `sample` or `march` and `helpers: ['rayClipSupport']`. Share one per
|
|
257
|
+
* pool: one module per shader.
|
|
258
|
+
* @param gridId The grid's pool id (a number, made a `uint` uniform) or a `uint` node.
|
|
259
|
+
* @throws VDBError `VDB_BAD_OPTION` for a `grids` this material can't use
|
|
260
|
+
* (another renderer, profile, helpers), a bad id or cap;
|
|
261
|
+
* `VDB_UNSUPPORTED_DEVICE` for an uninitialized renderer.
|
|
262
|
+
*/
|
|
263
|
+
constructor(renderer, grids, gridId, params = {}) {
|
|
264
|
+
super();
|
|
265
|
+
if (!(grids instanceof VDBGridNode))
|
|
266
|
+
throw bad("grids must be a VDBGridNode.");
|
|
267
|
+
getDevice(renderer); // VDB_UNSUPPORTED_DEVICE before init
|
|
268
|
+
if (grids.renderer !== renderer) {
|
|
269
|
+
throw bad("grids was made for another renderer. A VDBGridNode binds the pool through the renderer it was made with " +
|
|
270
|
+
"(another renderer, even on the same GPUDevice, would read 0): create one VDBGridNode per renderer " +
|
|
271
|
+
"(new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] })).");
|
|
272
|
+
}
|
|
273
|
+
if (grids.options.profile === "read") {
|
|
274
|
+
throw bad("grids needs profile 'sample' or 'march' (vdbSample); this VDBGridNode was made with profile 'read'.");
|
|
275
|
+
}
|
|
276
|
+
if (!grids.options.helpers?.includes("rayClipSupport")) {
|
|
277
|
+
throw bad("grids must compile the 'rayClipSupport' helper: new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] }).");
|
|
278
|
+
}
|
|
279
|
+
if (typeof gridId === "number") {
|
|
280
|
+
if (!Number.isInteger(gridId) || gridId < 0)
|
|
281
|
+
throw bad(`gridId must be a non-negative integer, got ${gridId}.`);
|
|
282
|
+
}
|
|
283
|
+
else if (gridId === null || typeof gridId !== "object") {
|
|
284
|
+
throw bad("gridId must be a number or a uint TSL node.");
|
|
285
|
+
}
|
|
286
|
+
const maxStepsCap = positiveInt("maxStepsCap", params.maxStepsCap, VDB_VOLUME_MAX_STEPS_CAP);
|
|
287
|
+
const shadowStepsCap = positiveInt("shadowStepsCap", params.shadowStepsCap, VDB_VOLUME_SHADOW_STEPS_CAP);
|
|
288
|
+
const sampleBudgetCap = positiveInt("sampleBudgetCap", params.sampleBudgetCap, VDB_VOLUME_SAMPLE_BUDGET_CAP);
|
|
289
|
+
this.grids = grids;
|
|
290
|
+
this.gridId = (typeof gridId === "number" ? uniform(gridId, "uint") : gridId);
|
|
291
|
+
this.entrySource = marchWgsl(maxStepsCap, shadowStepsCap, sampleBudgetCap);
|
|
292
|
+
this.densityScale = uniform(params.densityScale ?? DEFAULTS.densityScale);
|
|
293
|
+
this.stepSize = uniform(params.stepSize ?? DEFAULTS.stepSize);
|
|
294
|
+
this.maxSteps = uniform(params.maxSteps ?? DEFAULTS.maxSteps);
|
|
295
|
+
this.sunDirection = uniform((params.sunDirection ?? new THREE.Vector3(0.5, 0.8, 0.3)).clone().normalize());
|
|
296
|
+
this.sunColor = uniform(params.sunColor ?? new THREE.Color(1, 0.95, 0.9));
|
|
297
|
+
this.sunIntensity = uniform(params.sunIntensity ?? DEFAULTS.sunIntensity);
|
|
298
|
+
this.anisotropy = uniform(params.anisotropy ?? DEFAULTS.anisotropy);
|
|
299
|
+
this.shadowSteps = uniform(params.shadowSteps ?? DEFAULTS.shadowSteps);
|
|
300
|
+
this.shadowDensity = uniform(params.shadowDensity ?? DEFAULTS.shadowDensity);
|
|
301
|
+
this.ambient = uniform(params.ambient ?? DEFAULTS.ambient);
|
|
302
|
+
this.jitter = uniform(params.jitter === false ? 0 : 1);
|
|
303
|
+
const march = wgslFn(this.entrySource, [grids.module, code(VOLUME_HELPERS_WGSL)]);
|
|
304
|
+
this.fragmentNode = march({
|
|
305
|
+
grid_id: this.gridId,
|
|
306
|
+
ray_origin_w: cameraPosition,
|
|
307
|
+
ray_dir_w: positionWorld.sub(cameraPosition).normalize(),
|
|
308
|
+
sun_dir_w: this.sunDirection,
|
|
309
|
+
sun_color: this.sunColor,
|
|
310
|
+
sun_intensity: this.sunIntensity,
|
|
311
|
+
density_scale: this.densityScale,
|
|
312
|
+
step_size: this.stepSize,
|
|
313
|
+
max_steps: this.maxSteps,
|
|
314
|
+
g: this.anisotropy,
|
|
315
|
+
shadow_steps: this.shadowSteps,
|
|
316
|
+
shadow_density: this.shadowDensity,
|
|
317
|
+
ambient: this.ambient,
|
|
318
|
+
jitter: this.jitter,
|
|
319
|
+
pix: screenCoordinate,
|
|
320
|
+
});
|
|
321
|
+
this.transparent = true;
|
|
322
|
+
this.depthWrite = false;
|
|
323
|
+
this.depthTest = true;
|
|
324
|
+
this.side = THREE.BackSide;
|
|
325
|
+
this.premultipliedAlpha = true;
|
|
326
|
+
this.toneMapped = false;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* A world-space box for a grid's proxy mesh (add it with an identity
|
|
331
|
+
* transform): the AABB of the index box's voxels `[min - pad, max + 1 + pad]`
|
|
332
|
+
* through the grid's index-to-world affine. `pad: 0` (default) is
|
|
333
|
+
* `pool.info(id).worldBBox`, the box v1 used; `pad: 1` also covers the
|
|
334
|
+
* min-side half voxel of the trilinear support that `VDBVolumeMaterial`
|
|
335
|
+
* marches (rays that cross only that shell are otherwise not rasterized).
|
|
336
|
+
*/
|
|
337
|
+
export function vdbProxyGeometry(info, options = {}) {
|
|
338
|
+
const pad = options.pad ?? 0;
|
|
339
|
+
if (!Number.isFinite(pad) || pad < 0)
|
|
340
|
+
throw bad(`vdbProxyGeometry pad must be a finite number >= 0, got ${pad}.`);
|
|
341
|
+
const m = info.indexToWorld;
|
|
342
|
+
const lo = [0, 1, 2].map((a) => info.indexBBox.min[a] - pad);
|
|
343
|
+
const hi = [0, 1, 2].map((a) => info.indexBBox.max[a] + 1 + pad);
|
|
344
|
+
const box = new THREE.Box3();
|
|
345
|
+
const p = new THREE.Vector3();
|
|
346
|
+
for (let k = 0; k < 8; k++) {
|
|
347
|
+
const x = k & 1 ? hi[0] : lo[0];
|
|
348
|
+
const y = k & 2 ? hi[1] : lo[1];
|
|
349
|
+
const z = k & 4 ? hi[2] : lo[2];
|
|
350
|
+
p.set(m[0] * x + m[1] * y + m[2] * z + m[3], m[4] * x + m[5] * y + m[6] * z + m[7], m[8] * x + m[9] * y + m[10] * z + m[11]);
|
|
351
|
+
box.expandByPoint(p);
|
|
352
|
+
}
|
|
353
|
+
const size = box.getSize(new THREE.Vector3());
|
|
354
|
+
const center = box.getCenter(new THREE.Vector3());
|
|
355
|
+
const geometry = new THREE.BoxGeometry(size.x, size.y, size.z);
|
|
356
|
+
geometry.translate(center.x, center.y, center.z);
|
|
357
|
+
return geometry;
|
|
358
|
+
}
|
|
359
|
+
//# sourceMapping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":["/**\n * `VDBVolumeMaterial`: the fragment raymarch of one grid in a `VDBGridPool`,\n * through a `VDBGridNode` (task K2.3, docs/archive/handoffs/K2.md). It replaces v1's\n * `NanoVDBVolumeMaterial`, which bound one grid image as its own storage\n * attribute and rewrote the vendored library's buffer global.\n *\n * const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });\n * const material = new VDBVolumeMaterial(renderer, grids, id, { densityScale: 40 });\n * scene.add(new Mesh(vdbProxyGeometry(pool.info(id)), material));\n * // per frame: pool.update(encoder) (or pool.flush()), then grids.update(), then render.\n *\n * The march is one entry `wgslFn` over the public `vdb*` WGSL API, with\n * `grids.module` as its include (the module carries the pool binding):\n * - the world ray goes into the grid's index space through the record's\n * affine (`vdbWorldToIndex`/`vdbWorldToIndexDir`), so `pool.setTransform`\n * instances render where they are;\n * - it is clipped to the sampler's support box (`vdbRayClipSupport`,\n * `[min - 1, max + 1]` for trilinear), not the voxel-cell box, so the\n * min-side half voxel the trilinear taps reach is marched too;\n * - fixed-step density accumulation with `vdbSample` (the node's sampler),\n * premultiplied front-to-back compositing, early-out at low transmittance.\n * The step lattice is anchored at the voxel-box entry (`vdbRayClip`, where\n * v1 started) and extended back over the support shell, so samples inside\n * the box sit where v1's did; only the shell samples are new (v1 skipped\n * that half voxel, which shows where a grid's min-side voxels are dense);\n * - lighting as in v1: Henyey-Greenstein phase on a directional sun, an\n * N-step shadow march toward the sun (a second accessor), a constant\n * ambient floor, and a per-fragment budget on the total samples.\n *\n * Rendered on a proxy box with `side: BackSide` (the camera can be inside);\n * entry and exit come from the analytic clip, not the rasterized faces. The\n * material is `transparent`, `depthWrite: false`, premultiplied alpha. Scene\n * depth compositing is not done (v1 neither).\n *\n * Every tunable is a live TSL uniform (`material.densityScale.value = ...`).\n * The grid is a `uint` uniform too when the constructor got a number\n * (`material.gridId.value = otherId`), so one material can show any grid of\n * the types its `VDBGridNode` compiles without a rebuild.\n *\n * Units and assumptions:\n * - The march runs in the grid's **index space**: `stepSize` is in index\n * voxels, and `densityScale` integrates per index voxel. Opacity therefore\n * does not change with the world size of the grid: `pool.setTransform` (or\n * a NanoVDB map) that scales the grid scales its footprint, not how opaque\n * it looks.\n * - The proxy mesh is not tied to the grid: after `material.gridId.value = id`\n * or `pool.setTransform(id, ...)`, build a new `vdbProxyGeometry(pool.info(id))`\n * for the mesh, or fragments outside the old box are never rasterized.\n * - The view ray is `positionWorld - cameraPosition`: a perspective camera.\n * An orthographic camera's rays are parallel and do not start at\n * `cameraPosition`, so it renders wrongly.\n */\n\nimport * as THREE from \"three\";\nimport { NodeMaterial } from \"three/webgpu\";\nimport { cameraPosition, code, positionWorld, screenCoordinate, uniform, wgslFn } from \"three/tsl\";\nimport { VDBError } from \"../core/errors.js\";\nimport { getDevice, type VDBThreeRendererLike } from \"./device.js\";\nimport { VDBGridNode, type VDBTslNode } from \"./grid-node.js\";\n\n/** Default hard caps of the compiled loops (the live uniforms clamp under them). */\nexport const VDB_VOLUME_MAX_STEPS_CAP = 1024;\nexport const VDB_VOLUME_SHADOW_STEPS_CAP = 128;\n/**\n * Default cap on the total samples (primary + shadow) one fragment takes.\n * `maxSteps` and `shadowSteps` are independent live uniforms, so their product\n * can reach `maxStepsCap * shadowStepsCap` (~131k at the defaults), a driver\n * timeout risk. Once the budget is spent the shadow loop stops first, then the\n * primary loop, and the fragment returns its partial march.\n */\nexport const VDB_VOLUME_SAMPLE_BUDGET_CAP = 16384;\n\n/** Parameters of {@link VDBVolumeMaterial}: initial uniform values and compile-time caps. */\nexport interface VDBVolumeMaterialParameters {\n densityScale?: number;\n /** March step in index voxels. */\n stepSize?: number;\n maxSteps?: number;\n sunDirection?: THREE.Vector3;\n sunColor?: THREE.Color;\n sunIntensity?: number;\n /** Henyey-Greenstein anisotropy g in (-1, 1). */\n anisotropy?: number;\n shadowSteps?: number;\n /** Density multiplier along the shadow ray only. */\n shadowDensity?: number;\n ambient?: number;\n /** Per-pixel jitter of the first sample. Default true. */\n jitter?: boolean;\n /** Hard cap on the primary loop. Default {@link VDB_VOLUME_MAX_STEPS_CAP}. */\n maxStepsCap?: number;\n /** Hard cap on the shadow loop. Default {@link VDB_VOLUME_SHADOW_STEPS_CAP}. */\n shadowStepsCap?: number;\n /** Hard cap on the total samples per fragment. Default {@link VDB_VOLUME_SAMPLE_BUDGET_CAP}. */\n sampleBudgetCap?: number;\n}\n\nconst DEFAULTS = {\n densityScale: 40,\n stepSize: 0.75,\n maxSteps: 512,\n sunIntensity: 3,\n anisotropy: 0.3,\n shadowSteps: 12,\n shadowDensity: 1,\n ambient: 0.15,\n} as const;\n\n/** A live TSL uniform with its value typed (three types `uniform()`'s value as unknown). */\ntype ScalarUniform = ReturnType<typeof uniform> & { value: number };\ntype Vec3Uniform = ReturnType<typeof uniform> & { value: THREE.Vector3 };\ntype ColorUniform = ReturnType<typeof uniform> & { value: THREE.Color };\n/** The `uint` uniform `VDBVolumeMaterial` makes for a numeric grid id (`material.gridId.value = otherId`). */\nexport type VDBUintUniform = ReturnType<typeof uniform> & { value: number };\n\n/** Entry name of the march `wgslFn`. */\nconst ENTRY = \"vdbThreeVolumeMarch\";\n\n/**\n * Module-scope helpers of the march, a second include next to `grids.module`\n * (`wgslFn` parses only its first `fn`, so the entry can't hold them).\n */\nconst VOLUME_HELPERS_WGSL = /* wgsl */ `\nfn vdbThreeHgPhase(cos_theta: f32, g: f32) -> f32 {\n let gg = g * g;\n let denom = 1.0 + gg - 2.0 * g * cos_theta;\n return (1.0 - gg) / (12.566370614359172 * pow(max(denom, 1.0e-4), 1.5));\n}\nfn vdbThreeHash12(p: vec2f) -> f32 {\n var p3 = fract(vec3f(p.x, p.y, p.x) * 0.1031);\n p3 = p3 + dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n}\n`;\n\n/** The march entry, the one `fn` of its `wgslFn`. Caps are compiled in. */\nfunction marchWgsl(maxStepsCap: number, shadowStepsCap: number, sampleBudgetCap: number): string {\n return /* wgsl */ `fn ${ENTRY}(\n grid_id: u32,\n ray_origin_w: vec3f,\n ray_dir_w: vec3f,\n sun_dir_w: vec3f,\n sun_color: vec3f,\n sun_intensity: f32,\n density_scale: f32,\n step_size: f32,\n max_steps: f32,\n g: f32,\n shadow_steps: f32,\n shadow_density: f32,\n ambient: f32,\n jitter: f32,\n pix: vec2f\n) -> vec4f {\n // World -> index through the pool record (instance transform included).\n let o_idx = vdbWorldToIndex(grid_id, ray_origin_w);\n let d_idx = normalize(vdbWorldToIndexDir(grid_id, ray_dir_w));\n let sun_idx = normalize(vdbWorldToIndexDir(grid_id, sun_dir_w));\n\n // Clip to the trilinear support box; a dead id misses.\n var span = vec2f(0.0, 1.0e30);\n if !vdbRayClipSupport(grid_id, o_idx, d_idx, &span) {\n return vec4f(0.0);\n }\n // t0 >= 0: no sample behind the eye (camera inside the support box).\n let t0 = max(span.x, 0.0);\n let t1 = span.y;\n\n var acc = vdbAccessorInit(grid_id);\n var sacc = vdbAccessorInit(grid_id);\n\n // The phase uses the world-space view/sun angle.\n let phase = vdbThreeHgPhase(dot(normalize(ray_dir_w), normalize(sun_dir_w)), g);\n\n // The step lattice is anchored where the ray enters the voxel box\n // (vdbRayClip, v1's entry) and extended back to the support entry, so the\n // samples inside the box sit exactly where v1's did.\n var t = t0;\n var cell = vec2f(0.0, 1.0e30);\n if vdbRayClip(grid_id, o_idx, d_idx, &cell) {\n let anchor = max(cell.x, 0.0);\n t = anchor - ceil((anchor - t0) / step_size) * step_size;\n }\n t += step_size * jitter * vdbThreeHash12(pix);\n // The lattice can start before t0 (the anchor is stepped back in whole\n // steps, plus jitter). Skip those steps on the lattice: they are behind the\n // eye (camera in the support shell) or outside the support box.\n if t < t0 {\n t += ceil((t0 - t) / step_size) * step_size;\n }\n var transmittance = 1.0;\n var color = vec3f(0.0);\n let max_i = i32(clamp(max_steps, 1.0, ${maxStepsCap}.0));\n let shadow_n = i32(clamp(shadow_steps, 0.0, ${shadowStepsCap}.0));\n let budget = ${sampleBudgetCap};\n var samples = 0;\n\n for (var i = 0; i < max_i; i++) {\n if t > t1 || transmittance < 0.003 || samples >= budget {\n break;\n }\n let pos = o_idx + d_idx * t;\n let density = max(vdbSample(&acc, pos), 0.0) * density_scale;\n samples++;\n if density > 0.0 {\n let a = 1.0 - exp(-density * step_size);\n var tau = 0.0;\n var st = step_size;\n for (var s = 0; s < shadow_n; s++) {\n if samples >= budget {\n break;\n }\n let sd = max(vdbSample(&sacc, pos + sun_idx * st), 0.0) * density_scale * shadow_density;\n samples++;\n tau += sd * step_size;\n st += step_size;\n }\n let lit = sun_color * (sun_intensity * exp(-tau) * phase) + vec3f(ambient);\n color += transmittance * a * lit;\n transmittance *= 1.0 - a;\n }\n t += step_size;\n }\n return vec4f(color, 1.0 - transmittance);\n}`;\n}\n\nfunction bad(message: string): VDBError {\n return new VDBError(\"VDB_BAD_OPTION\", `VDBVolumeMaterial: ${message}`);\n}\n\nfunction positiveInt(name: string, value: number | undefined, fallback: number): number {\n const v = value ?? fallback;\n if (!Number.isInteger(v) || v < 1) throw bad(`${name} must be an integer >= 1, got ${JSON.stringify(value)}.`);\n return v;\n}\n\n/**\n * A fragment raymarch of one grid of a `VDBGridPool` (see the file comment for\n * the march). Put it on a `vdbProxyGeometry(pool.info(id))` mesh; each frame\n * run `pool.update(encoder)` (or `pool.flush()`), then `grids.update()`, then\n * render.\n *\n * const grids = new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] });\n * const material = new VDBVolumeMaterial(renderer, grids, id, { densityScale: 40 });\n * const mesh = new Mesh(vdbProxyGeometry(pool.info(id)), material);\n *\n * - `stepSize` is in index voxels and `densityScale` integrates per index\n * voxel, so opacity ignores the grid's world scale (`setTransform` scaling\n * changes the size on screen, not the opacity).\n * - After `gridId.value = otherId` or `pool.setTransform(id, ...)`, give the\n * mesh a new `vdbProxyGeometry(pool.info(id))`.\n * - Perspective cameras only (the ray starts at `cameraPosition`).\n * - The material must be rendered by the renderer `grids` was made with.\n *\n * @typeParam TGridId What the constructor got as the id: a number (default)\n * makes {@link gridId} a `uint` uniform; a node is kept as given.\n */\nexport class VDBVolumeMaterial<TGridId extends number | VDBTslNode = number> extends NodeMaterial {\n readonly isVDBVolumeMaterial = true;\n\n /** The pool node this material reads (its `module` is the march's include). */\n readonly grids: VDBGridNode;\n /**\n * The grid id: a `uint` uniform when the constructor got a number\n * (`material.gridId.value = otherId`; then give the mesh a new\n * `vdbProxyGeometry`), else the caller's node.\n */\n readonly gridId: TGridId extends number ? VDBUintUniform : VDBTslNode;\n /** The entry `fn` text (for inspection and tests). */\n readonly entrySource: string;\n\n /** Extinction per index voxel at density 1 (opacity of a step: `1 - exp(-density * densityScale * stepSize)`). Default 40. */\n readonly densityScale: ScalarUniform;\n /** March step in index voxels (live; the lattice re-anchors per fragment). Default 0.75. */\n readonly stepSize: ScalarUniform;\n /** Primary march steps, clamped to `[1, maxStepsCap]`. Default 512. */\n readonly maxSteps: ScalarUniform;\n /** Direction toward the sun, world space (normalized at construction; keep it normalized). */\n readonly sunDirection: Vec3Uniform;\n /** Sun colour (linear). Default (1, 0.95, 0.9). */\n readonly sunColor: ColorUniform;\n /** Sun intensity. Default 3. */\n readonly sunIntensity: ScalarUniform;\n /** Henyey-Greenstein anisotropy g in (-1, 1). Default 0.3. */\n readonly anisotropy: ScalarUniform;\n /** Shadow-ray steps toward the sun per lit sample, clamped to `[0, shadowStepsCap]`. Default 12. */\n readonly shadowSteps: ScalarUniform;\n /** Density multiplier along the shadow ray only. Default 1. */\n readonly shadowDensity: ScalarUniform;\n /** Constant ambient term added to the sun light. Default 0.15. */\n readonly ambient: ScalarUniform;\n /** 1 = per-pixel jitter of the first sample on, 0 = off. */\n readonly jitter: ScalarUniform;\n\n /**\n * @param renderer The initialized `WebGPURenderer` the pool and `grids` live on.\n * @param grids A `VDBGridNode` made on this same renderer, with profile\n * `sample` or `march` and `helpers: ['rayClipSupport']`. Share one per\n * pool: one module per shader.\n * @param gridId The grid's pool id (a number, made a `uint` uniform) or a `uint` node.\n * @throws VDBError `VDB_BAD_OPTION` for a `grids` this material can't use\n * (another renderer, profile, helpers), a bad id or cap;\n * `VDB_UNSUPPORTED_DEVICE` for an uninitialized renderer.\n */\n constructor(renderer: VDBThreeRendererLike, grids: VDBGridNode, gridId: TGridId, params: VDBVolumeMaterialParameters = {}) {\n super();\n if (!(grids instanceof VDBGridNode)) throw bad(\"grids must be a VDBGridNode.\");\n getDevice(renderer); // VDB_UNSUPPORTED_DEVICE before init\n if (grids.renderer !== renderer) {\n throw bad(\n \"grids was made for another renderer. A VDBGridNode binds the pool through the renderer it was made with \" +\n \"(another renderer, even on the same GPUDevice, would read 0): create one VDBGridNode per renderer \" +\n \"(new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] })).\",\n );\n }\n if (grids.options.profile === \"read\") {\n throw bad(\"grids needs profile 'sample' or 'march' (vdbSample); this VDBGridNode was made with profile 'read'.\");\n }\n if (!grids.options.helpers?.includes(\"rayClipSupport\")) {\n throw bad(\"grids must compile the 'rayClipSupport' helper: new VDBGridNode(renderer, pool, { helpers: ['rayClipSupport'] }).\");\n }\n if (typeof gridId === \"number\") {\n if (!Number.isInteger(gridId) || gridId < 0) throw bad(`gridId must be a non-negative integer, got ${gridId}.`);\n } else if (gridId === null || typeof gridId !== \"object\") {\n throw bad(\"gridId must be a number or a uint TSL node.\");\n }\n const maxStepsCap = positiveInt(\"maxStepsCap\", params.maxStepsCap, VDB_VOLUME_MAX_STEPS_CAP);\n const shadowStepsCap = positiveInt(\"shadowStepsCap\", params.shadowStepsCap, VDB_VOLUME_SHADOW_STEPS_CAP);\n const sampleBudgetCap = positiveInt(\"sampleBudgetCap\", params.sampleBudgetCap, VDB_VOLUME_SAMPLE_BUDGET_CAP);\n\n this.grids = grids;\n this.gridId = (typeof gridId === \"number\" ? uniform(gridId, \"uint\") : gridId) as this[\"gridId\"];\n this.entrySource = marchWgsl(maxStepsCap, shadowStepsCap, sampleBudgetCap);\n\n this.densityScale = uniform(params.densityScale ?? DEFAULTS.densityScale) as ScalarUniform;\n this.stepSize = uniform(params.stepSize ?? DEFAULTS.stepSize) as ScalarUniform;\n this.maxSteps = uniform(params.maxSteps ?? DEFAULTS.maxSteps) as ScalarUniform;\n this.sunDirection = uniform((params.sunDirection ?? new THREE.Vector3(0.5, 0.8, 0.3)).clone().normalize()) as Vec3Uniform;\n this.sunColor = uniform(params.sunColor ?? new THREE.Color(1, 0.95, 0.9)) as ColorUniform;\n this.sunIntensity = uniform(params.sunIntensity ?? DEFAULTS.sunIntensity) as ScalarUniform;\n this.anisotropy = uniform(params.anisotropy ?? DEFAULTS.anisotropy) as ScalarUniform;\n this.shadowSteps = uniform(params.shadowSteps ?? DEFAULTS.shadowSteps) as ScalarUniform;\n this.shadowDensity = uniform(params.shadowDensity ?? DEFAULTS.shadowDensity) as ScalarUniform;\n this.ambient = uniform(params.ambient ?? DEFAULTS.ambient) as ScalarUniform;\n this.jitter = uniform(params.jitter === false ? 0 : 1) as ScalarUniform;\n\n const march = wgslFn(this.entrySource, [grids.module, code(VOLUME_HELPERS_WGSL)] as never);\n this.fragmentNode = march({\n grid_id: this.gridId,\n ray_origin_w: cameraPosition,\n ray_dir_w: positionWorld.sub(cameraPosition).normalize(),\n sun_dir_w: this.sunDirection,\n sun_color: this.sunColor,\n sun_intensity: this.sunIntensity,\n density_scale: this.densityScale,\n step_size: this.stepSize,\n max_steps: this.maxSteps,\n g: this.anisotropy,\n shadow_steps: this.shadowSteps,\n shadow_density: this.shadowDensity,\n ambient: this.ambient,\n jitter: this.jitter,\n pix: screenCoordinate,\n });\n\n this.transparent = true;\n this.depthWrite = false;\n this.depthTest = true;\n this.side = THREE.BackSide;\n this.premultipliedAlpha = true;\n this.toneMapped = false;\n }\n}\n\n/** What {@link vdbProxyGeometry} reads from `pool.info(id)`. */\nexport interface VDBProxyGridInfo {\n readonly indexBBox: { readonly min: readonly number[]; readonly max: readonly number[] };\n /** 3x4 row-major index-to-world affine (`pool.info(id).indexToWorld`). */\n readonly indexToWorld: ArrayLike<number>;\n}\n\n/**\n * A world-space box for a grid's proxy mesh (add it with an identity\n * transform): the AABB of the index box's voxels `[min - pad, max + 1 + pad]`\n * through the grid's index-to-world affine. `pad: 0` (default) is\n * `pool.info(id).worldBBox`, the box v1 used; `pad: 1` also covers the\n * min-side half voxel of the trilinear support that `VDBVolumeMaterial`\n * marches (rays that cross only that shell are otherwise not rasterized).\n */\nexport function vdbProxyGeometry(info: VDBProxyGridInfo, options: { pad?: number } = {}): THREE.BoxGeometry {\n const pad = options.pad ?? 0;\n if (!Number.isFinite(pad) || pad < 0) throw bad(`vdbProxyGeometry pad must be a finite number >= 0, got ${pad}.`);\n const m = info.indexToWorld;\n const lo = [0, 1, 2].map((a) => info.indexBBox.min[a]! - pad);\n const hi = [0, 1, 2].map((a) => info.indexBBox.max[a]! + 1 + pad);\n const box = new THREE.Box3();\n const p = new THREE.Vector3();\n for (let k = 0; k < 8; k++) {\n const x = k & 1 ? hi[0]! : lo[0]!;\n const y = k & 2 ? hi[1]! : lo[1]!;\n const z = k & 4 ? hi[2]! : lo[2]!;\n p.set(\n m[0]! * x + m[1]! * y + m[2]! * z + m[3]!,\n m[4]! * x + m[5]! * y + m[6]! * z + m[7]!,\n m[8]! * x + m[9]! * y + m[10]! * z + m[11]!,\n );\n box.expandByPoint(p);\n }\n const size = box.getSize(new THREE.Vector3());\n const center = box.getCenter(new THREE.Vector3());\n const geometry = new THREE.BoxGeometry(size.x, size.y, size.z);\n geometry.translate(center.x, center.y, center.z);\n return geometry;\n}\n"]}
|