roamwright 0.20.1 → 0.54.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/.prettierrc.yaml +12 -0
- package/CONTRIBUTING.md +19 -14
- package/README.md +35 -16
- package/examples/animals.html +49 -0
- package/examples/animals.js +209 -0
- package/examples/crowds.html +50 -0
- package/examples/crowds.js +268 -0
- package/examples/effects.html +53 -0
- package/examples/effects.js +343 -0
- package/examples/figure-motion.html +55 -0
- package/examples/figure-motion.js +265 -0
- package/examples/figure.html +49 -0
- package/examples/figure.js +238 -0
- package/examples/fliers.html +53 -0
- package/examples/fliers.js +292 -0
- package/examples/fortification.html +54 -0
- package/examples/fortification.js +288 -0
- package/examples/house-kit.html +48 -0
- package/examples/house-kit.js +175 -0
- package/examples/index.html +26 -16
- package/examples/island.html +48 -0
- package/examples/island.js +134 -52
- package/examples/land.html +54 -0
- package/examples/land.js +392 -0
- package/examples/props-and-plants.html +53 -0
- package/examples/props-and-plants.js +275 -0
- package/examples/rooms.html +48 -0
- package/examples/rooms.js +242 -0
- package/examples/ships.html +51 -0
- package/examples/ships.js +235 -0
- package/examples/showcase.css +320 -0
- package/examples/small-world-land.js +151 -0
- package/examples/small-world-life.js +160 -0
- package/examples/small-world-town.js +127 -0
- package/examples/small-world.html +57 -0
- package/examples/small-world.js +226 -0
- package/examples/soundscape.html +138 -0
- package/examples/soundscape.js +467 -0
- package/examples/stage-kits.js +300 -0
- package/examples/stage.js +374 -0
- package/examples/towns.html +50 -0
- package/examples/towns.js +325 -0
- package/examples/viaduct-camera.js +8 -4
- package/examples/viaduct-landscape.js +28 -17
- package/examples/viaduct.html +45 -43
- package/examples/viaduct.js +68 -92
- package/geometry/animal-camel-body.js +410 -0
- package/geometry/animal-camel-head.js +118 -0
- package/geometry/animal-canine-body.js +361 -0
- package/geometry/animal-canine-breeds.js +316 -0
- package/geometry/animal-canine-head.js +337 -0
- package/geometry/animal-cattle-body.js +391 -0
- package/geometry/animal-cattle-coat.js +42 -0
- package/geometry/animal-cattle-head.js +152 -0
- package/geometry/animal-hen.js +248 -0
- package/geometry/animal-horse-body.js +446 -0
- package/geometry/animal-horse-bridle.js +171 -0
- package/geometry/animal-horse-coat.js +68 -0
- package/geometry/animal-horse-face.js +162 -0
- package/geometry/animal-horse-hair.js +304 -0
- package/geometry/animal-horse-head.js +133 -0
- package/geometry/animal-horse-tack.js +157 -0
- package/geometry/animal-options.js +59 -0
- package/geometry/animal-shapes.js +21 -0
- package/geometry/animal-skin.js +390 -0
- package/geometry/builder-cells.js +10 -2
- package/geometry/builder-frame.js +2 -1
- package/geometry/builder.js +15 -4
- package/geometry/card-emblem.js +437 -0
- package/geometry/catenary-canvas.js +396 -0
- package/geometry/cloth-folds.js +143 -0
- package/geometry/crawl-shapes.js +71 -0
- package/geometry/creased-sheet.js +7 -2
- package/geometry/crowd-dress.js +315 -0
- package/geometry/crowd-far.js +174 -0
- package/geometry/crowd-look.js +42 -0
- package/geometry/crowd-weld.js +218 -0
- package/geometry/ear.js +9 -4
- package/geometry/erosion.js +7 -4
- package/geometry/face-grid.js +26 -6
- package/geometry/field-map.js +59 -0
- package/geometry/figure-arms.js +339 -0
- package/geometry/figure-beard.js +250 -0
- package/geometry/figure-body.js +297 -0
- package/geometry/figure-bow.js +105 -0
- package/geometry/figure-cloak.js +189 -0
- package/geometry/figure-clothes.js +337 -0
- package/geometry/figure-face-grids.js +75 -0
- package/geometry/figure-gear.js +446 -0
- package/geometry/figure-hair-far.js +151 -0
- package/geometry/figure-hair-hangs.js +108 -0
- package/geometry/figure-hair-patch.js +66 -0
- package/geometry/figure-hair.js +320 -0
- package/geometry/figure-hands.js +321 -0
- package/geometry/figure-head-features.js +280 -0
- package/geometry/figure-head.js +375 -0
- package/geometry/figure-headwear.js +223 -0
- package/geometry/figure-legs.js +231 -0
- package/geometry/figure-limbs.js +39 -0
- package/geometry/figure-sculpt.js +82 -0
- package/geometry/figure-skin.js +97 -0
- package/geometry/figure-skirts.js +303 -0
- package/geometry/figure-trunk.js +411 -0
- package/geometry/flier-corvid-body.js +322 -0
- package/geometry/flier-corvid-wings.js +154 -0
- package/geometry/flier-long-body.js +195 -0
- package/geometry/flier-shapes.js +219 -0
- package/geometry/flier-soaring-bird.js +84 -0
- package/geometry/foliage.js +177 -4
- package/geometry/fort-city-walls.js +479 -0
- package/geometry/fort-gate-approach.js +233 -0
- package/geometry/fort-great-walls.js +280 -0
- package/geometry/fort-keep.js +297 -0
- package/geometry/fort-parts.js +261 -0
- package/geometry/fort-polyline.js +261 -0
- package/geometry/fort-portal.js +96 -0
- package/geometry/fort-ring-wall.js +267 -0
- package/geometry/fort-seawall.js +104 -0
- package/geometry/fort-terrace-gates.js +323 -0
- package/geometry/fort-terrace-plan.js +250 -0
- package/geometry/fort-terrace-wall.js +345 -0
- package/geometry/garment-tags.js +11 -3
- package/geometry/grid-gather.js +69 -0
- package/geometry/grid-sample.js +185 -0
- package/geometry/hair-gathers.js +19 -4
- package/geometry/hair-locks.js +1 -1
- package/geometry/hair-patch.js +6 -2
- package/geometry/hair-shell.js +14 -2
- package/geometry/head-presets.js +103 -0
- package/geometry/head-profile.js +13 -2
- package/geometry/head-shape.js +51 -23
- package/geometry/heightfield.js +26 -9
- package/geometry/horizon-angles.js +166 -0
- package/geometry/house-kit-body.js +195 -0
- package/geometry/house-kit-courtyard-parts.js +340 -0
- package/geometry/house-kit-courtyard-roof.js +223 -0
- package/geometry/house-kit-courtyard.js +409 -0
- package/geometry/house-kit-cut.js +29 -0
- package/geometry/house-kit-extras.js +192 -0
- package/geometry/house-kit-forms.js +298 -0
- package/geometry/house-kit-frame.js +74 -0
- package/geometry/house-kit-marks.js +93 -0
- package/geometry/house-kit-openings.js +193 -0
- package/geometry/house-kit-palette.js +54 -0
- package/geometry/house-kit-pool.js +71 -0
- package/geometry/house-kit-roofs.js +151 -0
- package/geometry/house-kit.js +202 -0
- package/geometry/instances.js +4 -4
- package/geometry/lamp-wash.js +65 -0
- package/geometry/land-clearings.js +83 -0
- package/geometry/land-ditches.js +290 -0
- package/geometry/land-dry-basin.js +327 -0
- package/geometry/land-dunes.js +150 -0
- package/geometry/land-earthworks.js +432 -0
- package/geometry/land-edge.js +292 -0
- package/geometry/land-mound-faces.js +349 -0
- package/geometry/land-near-relief.js +102 -0
- package/geometry/land-sheet.js +220 -0
- package/geometry/land-town-ground.js +256 -0
- package/geometry/land-waters.js +228 -0
- package/geometry/land-wildness.js +123 -0
- package/geometry/lathed-vessel.js +293 -0
- package/geometry/outline-grid.js +5 -4
- package/geometry/outline-segments.js +74 -0
- package/geometry/part-ranges.js +35 -0
- package/geometry/path-field.js +35 -1
- package/geometry/planked-floor.js +149 -0
- package/geometry/plant-broadleaf.js +268 -0
- package/geometry/plant-shrub.js +198 -0
- package/geometry/plant-tints.js +80 -0
- package/geometry/plant-trees.js +453 -0
- package/geometry/plant-tussock.js +107 -0
- package/geometry/primitives.js +65 -23
- package/geometry/prop-battlefield.js +69 -0
- package/geometry/prop-camp.js +175 -0
- package/geometry/prop-door.js +26 -0
- package/geometry/prop-harbour.js +105 -0
- package/geometry/prop-haycock.js +60 -0
- package/geometry/prop-sacks.js +74 -0
- package/geometry/prop-sheaf.js +68 -0
- package/geometry/prop-street.js +69 -0
- package/geometry/prop-tents.js +396 -0
- package/geometry/prop-tombs.js +80 -0
- package/geometry/prop-trade.js +393 -0
- package/geometry/prop-vehicles.js +218 -0
- package/geometry/props.js +58 -0
- package/geometry/room-arcade.js +134 -0
- package/geometry/room-dome.js +188 -0
- package/geometry/room-flames.js +138 -0
- package/geometry/room-frame.js +106 -0
- package/geometry/room-furniture.js +260 -0
- package/geometry/room-hearth.js +98 -0
- package/geometry/room-kit.js +59 -0
- package/geometry/room-openings.js +142 -0
- package/geometry/room-stairs.js +180 -0
- package/geometry/room-surfaces.js +272 -0
- package/geometry/sampled-surface.js +24 -10
- package/geometry/scatter-grid.js +6 -3
- package/geometry/sculpt.js +5 -1
- package/geometry/ship-fittings.js +350 -0
- package/geometry/ship-hull.js +460 -0
- package/geometry/ship-kit.js +208 -0
- package/geometry/ship-lines.js +69 -0
- package/geometry/ship-oars.js +150 -0
- package/geometry/ship-presets.js +131 -0
- package/geometry/ship-rig.js +374 -0
- package/geometry/ship-sails.js +148 -0
- package/geometry/shore-grid.js +5 -1
- package/geometry/strata-field.js +44 -11
- package/geometry/strata-tiles.js +20 -6
- package/geometry/stream.js +32 -17
- package/geometry/swept-tube.js +124 -0
- package/geometry/terrain-chunks.js +139 -51
- package/geometry/terrain-extension.js +24 -8
- package/geometry/town-courtyard-inn.js +272 -0
- package/geometry/town-ground.js +76 -0
- package/geometry/town-houses.js +343 -0
- package/geometry/town-lights.js +254 -0
- package/geometry/town-lots.js +172 -0
- package/geometry/town-plan.js +370 -0
- package/geometry/town-works.js +465 -0
- package/geometry/village-layout.js +181 -0
- package/geometry/village-yards.js +167 -0
- package/geometry/wall-runs.js +64 -0
- package/index.js +134 -3
- package/math/cloud-textures.js +3 -7
- package/math/curve.js +5 -1
- package/math/lamp-texels.js +43 -0
- package/math/lit-share.js +22 -0
- package/math/mountain-ranges.js +177 -54
- package/math/periodic.js +6 -0
- package/math/rectangles.js +8 -2
- package/math/rock-texture.js +17 -12
- package/math/surface-textures.js +24 -9
- package/math/wandering-path.js +40 -0
- package/math/ways.js +120 -0
- package/motion/action-dynamics.js +398 -0
- package/motion/animal-bearing.js +247 -0
- package/motion/animal-canine-bearing.js +178 -0
- package/motion/animal-canine-cast.js +131 -0
- package/motion/animal-cattle-cast.js +64 -0
- package/motion/animal-herd-cast.js +154 -0
- package/motion/animal-horse-still.js +161 -0
- package/motion/animal-troop-cast.js +43 -0
- package/motion/arm-reach.js +3 -2
- package/motion/ballistic-arc.js +182 -2
- package/motion/biped-cycle.js +4 -2
- package/motion/biped-leg.js +4 -1
- package/motion/biped-posture.js +459 -0
- package/motion/biped-stride.js +142 -32
- package/motion/boat-sailing.js +214 -0
- package/motion/contact-transition.js +5 -6
- package/motion/crowd-alarms.js +36 -6
- package/motion/crowd-attention.js +108 -0
- package/motion/crowd-beasts.js +203 -0
- package/motion/crowd-camp.js +295 -0
- package/motion/crowd-figure.js +100 -0
- package/motion/crowd-herd.js +86 -0
- package/motion/crowd-hold.js +130 -0
- package/motion/crowd-pose.js +296 -0
- package/motion/crowd-poses.js +481 -0
- package/motion/crowd-routine.js +44 -14
- package/motion/crowd-town.js +166 -0
- package/motion/crowd-water.js +143 -0
- package/motion/deck-surface.js +4 -2
- package/motion/figure-acts.js +411 -0
- package/motion/figure-arms.js +437 -0
- package/motion/figure-blade-slide.js +149 -0
- package/motion/figure-body-place.js +180 -0
- package/motion/figure-bones.js +118 -0
- package/motion/figure-bow-draw.js +70 -0
- package/motion/figure-fingers.js +215 -0
- package/motion/figure-gaze.js +205 -0
- package/motion/figure-gestures.js +452 -0
- package/motion/figure-grip.js +134 -0
- package/motion/figure-head.js +287 -0
- package/motion/figure-legs.js +264 -0
- package/motion/figure-links.js +293 -0
- package/motion/figure-locomotion.js +391 -0
- package/motion/figure-mount-up.js +180 -0
- package/motion/figure-mount.js +201 -0
- package/motion/figure-pose-frame.js +375 -0
- package/motion/figure-pose-table.js +156 -0
- package/motion/figure-pose.js +343 -0
- package/motion/figure-seat.js +267 -0
- package/motion/figure-sway.js +125 -0
- package/motion/flier-corvid-pose.js +74 -0
- package/motion/flier-flight-air.js +122 -0
- package/motion/flier-flight-echelon.js +164 -0
- package/motion/flier-flight-roost.js +131 -0
- package/motion/flier-swarm-flight.js +252 -0
- package/motion/formation.js +193 -0
- package/motion/instance-sight.js +8 -1
- package/motion/melee-contact.js +143 -0
- package/motion/moorings.js +48 -0
- package/motion/path-steering.js +358 -0
- package/motion/player.js +7 -6
- package/motion/quadruped.js +109 -33
- package/motion/spaces.js +58 -6
- package/motion/speech-cadence.js +304 -0
- package/motion/vessel-motion.js +57 -0
- package/motion/walk-grid.js +235 -0
- package/motion/weather.js +70 -12
- package/motion/wind.js +27 -1
- package/package.json +27 -4
- package/rendering/alpha-mips.js +340 -0
- package/rendering/animal-camel-figure.js +29 -0
- package/rendering/animal-canine-figure.js +59 -0
- package/rendering/animal-cattle-figure.js +36 -0
- package/rendering/animal-horse-figure.js +49 -0
- package/rendering/atmosphere.js +86 -0
- package/rendering/camera-track.js +156 -0
- package/rendering/{road-surface.js → cart-track.js} +40 -11
- package/rendering/caster-motion.js +2 -1
- package/rendering/cell-lod-options.js +46 -0
- package/rendering/cell-lod.js +665 -80
- package/rendering/cloth-material.js +140 -0
- package/rendering/cloud-dome.js +2 -2
- package/rendering/compilation-schedule.js +18 -10
- package/rendering/contact-shadows.js +5 -2
- package/rendering/context.js +47 -8
- package/rendering/crowd-batches.js +420 -0
- package/rendering/crowd-herd.js +198 -0
- package/rendering/crowd-rig.js +132 -0
- package/rendering/crowd-skinning.js +52 -9
- package/rendering/crowd-update.js +419 -0
- package/rendering/crowd-visibility.js +107 -0
- package/rendering/day-cycle-defaults.js +200 -0
- package/rendering/day-cycle.js +487 -0
- package/rendering/daylight.js +1 -3
- package/rendering/detail-range.js +6 -5
- package/rendering/dof.js +11 -4
- package/rendering/effects-frame.js +149 -0
- package/rendering/effects-water-rises.js +221 -0
- package/rendering/energy-stream.js +128 -0
- package/rendering/facade-glass-material.js +105 -0
- package/rendering/far-shadow.js +81 -54
- package/rendering/field-surface.js +138 -0
- package/rendering/figure-shield.js +105 -0
- package/rendering/figure-skeleton.js +329 -0
- package/rendering/fire-light-watch.js +197 -0
- package/rendering/fire-pools.js +148 -0
- package/rendering/flame-sources.js +86 -0
- package/rendering/flier-bird-looks.js +97 -0
- package/rendering/flier-corvid-figure.js +67 -0
- package/rendering/flier-long-body-company.js +169 -0
- package/rendering/flier-swarm.js +186 -0
- package/rendering/flocks.js +6 -2
- package/rendering/garment-material.js +145 -49
- package/rendering/glsl-literal.js +19 -0
- package/rendering/ground-marks.js +316 -0
- package/rendering/hair-strands.js +38 -24
- package/rendering/height-haze.js +80 -33
- package/rendering/height-probe.js +15 -3
- package/rendering/house-kit-meshes.js +124 -0
- package/rendering/interior-bake.js +807 -0
- package/rendering/label-layout.js +13 -3
- package/rendering/label-range.js +5 -2
- package/rendering/lamp-light-map.js +159 -0
- package/rendering/lamp-maps.js +62 -0
- package/rendering/lamp-wash.js +51 -0
- package/rendering/light-budget.js +19 -3
- package/rendering/light-points.js +21 -5
- package/rendering/local-lights.js +27 -7
- package/rendering/material-lod.js +5 -6
- package/rendering/memory-estimate.js +84 -0
- package/rendering/moored-fleet.js +186 -0
- package/rendering/part-costs.js +104 -0
- package/rendering/particle-bursts.js +386 -0
- package/rendering/particle-emitters.js +61 -25
- package/rendering/particle-light-bursts.js +189 -0
- package/rendering/particles.js +134 -34
- package/rendering/pen-flocks.js +118 -0
- package/rendering/piece-batch.js +282 -6
- package/rendering/planar-reflection-options.js +159 -0
- package/rendering/planar-reflection.js +780 -77
- package/rendering/plant-cells.js +122 -0
- package/rendering/plant-reeds.js +113 -0
- package/rendering/plant-shade-trees.js +239 -0
- package/rendering/plant-tuft-patch.js +122 -0
- package/rendering/post-shaders.js +84 -21
- package/rendering/post.js +39 -19
- package/rendering/pressed-cover.js +135 -0
- package/rendering/prop-dig.js +136 -0
- package/rendering/room-light.js +250 -0
- package/rendering/room-materials.js +78 -0
- package/rendering/room-space.js +111 -0
- package/rendering/scene-lights.js +106 -0
- package/rendering/sea-shaders.js +83 -26
- package/rendering/settlement-approach.js +226 -0
- package/rendering/settlement-dissolve.js +89 -0
- package/rendering/settlement-quarter-warm.js +55 -0
- package/rendering/settlement-quarter.js +477 -0
- package/rendering/settlement-switch.js +42 -0
- package/rendering/settlement-town.js +110 -0
- package/rendering/shader-warmup.js +80 -36
- package/rendering/shadow-depth.js +40 -18
- package/rendering/ship-meshes.js +150 -0
- package/rendering/shot-cuts.js +68 -0
- package/rendering/sky-occlusion.js +42 -15
- package/rendering/sky-pmrem.js +216 -0
- package/rendering/sky.js +112 -50
- package/rendering/smoke-shadows.js +201 -0
- package/rendering/stage-framing.js +182 -0
- package/rendering/stage-lights.js +46 -39
- package/rendering/stain-material.js +74 -0
- package/rendering/static-point-shadow.js +62 -23
- package/rendering/still-casters.js +77 -27
- package/rendering/strata-material.js +2 -2
- package/rendering/street-lamps.js +166 -0
- package/rendering/sunbeam-motes.js +670 -0
- package/rendering/surface-light.js +65 -6
- package/rendering/surface-material.js +306 -0
- package/rendering/surface-projection.js +32 -0
- package/rendering/surface-snippets.js +314 -0
- package/rendering/taa.js +49 -18
- package/rendering/tree-impostor.js +929 -0
- package/rendering/vehicle-train.js +92 -0
- package/rendering/viewport.js +67 -4
- package/rendering/water-material.js +270 -82
- package/rendering/waypoint-beacons.js +191 -0
- package/rendering/world-matrices.js +0 -2
- package/ruff.toml +20 -0
- package/runtime/cue-cursor.js +21 -0
- package/runtime/device-quality.js +13 -2
- package/runtime/device.js +73 -0
- package/runtime/diagnostic-log.js +11 -3
- package/runtime/effect-sites.js +85 -0
- package/runtime/figure-orders.js +59 -0
- package/runtime/first-use.js +8 -5
- package/runtime/foley-script.js +124 -0
- package/runtime/foley-strides.js +333 -0
- package/runtime/frame-pacing.js +18 -4
- package/runtime/frame-yield.js +18 -0
- package/runtime/gpu-timing.js +8 -4
- package/runtime/grid-cache.js +16 -6
- package/runtime/grid-rows.js +5 -5
- package/runtime/hand-over.js +7 -2
- package/runtime/land-bake.js +78 -0
- package/runtime/lazy-sets.js +105 -0
- package/runtime/pool.js +17 -3
- package/runtime/quality-fit.js +59 -27
- package/runtime/region-pass-lay.js +40 -0
- package/runtime/region-pass.js +78 -0
- package/runtime/search.js +6 -2
- package/runtime/settlement-reach.js +42 -0
- package/runtime/sound-calls.js +113 -0
- package/runtime/sound-impacts.js +297 -0
- package/runtime/sound-voices.js +194 -0
- package/runtime/soundscape.js +282 -0
- package/runtime/spatial-audio.js +69 -20
- package/runtime/steady-frames.js +221 -0
- package/runtime/withdrawable-task.js +19 -8
- package/scripts/app-parts.mjs +118 -0
- package/scripts/bake-revisions.mjs +81 -0
- package/scripts/browser-scripts.mjs +64 -0
- package/scripts/bundle.mjs +192 -0
- package/scripts/check-app.sh +26 -0
- package/scripts/eslint-config.mjs +119 -0
- package/scripts/format.sh +92 -0
- package/scripts/keep-builds.mjs +158 -0
- package/scripts/layers.mjs +112 -0
- package/scripts/lint.sh +49 -0
- package/scripts/module-graph.mjs +123 -0
- package/scripts/pre-commit.sh +38 -0
- package/scripts/serve.py +5 -3
- package/scripts/site.mjs +358 -0
- package/scripts/test-runner.sh +42 -0
- package/scripts/vendor.mjs +221 -0
- package/scripts/verify-publish.mjs +175 -0
- package/scripts/world.mk +59 -0
- package/tools/README.md +73 -0
- package/tools/contact-sheet.cjs +137 -0
- package/tools/cpu-profile.cjs +275 -0
- package/tools/cpu-profile.test.cjs +98 -0
- package/tools/first-draws.cjs +395 -0
- package/tools/flight-guard.cjs +482 -0
- package/tools/flight-guard.test.cjs +153 -0
- package/tools/flight-profile.cjs +145 -0
- package/tools/frame-bench.cjs +336 -0
- package/tools/frame-parts.cjs +365 -0
- package/tools/ios-sim.sh +145 -0
- package/tools/load-audit.cjs +201 -0
- package/tools/look-compare.cjs +304 -0
- package/tools/look-guard.cjs +407 -0
- package/tools/look-guard.test.cjs +93 -0
- package/tools/look-stats.cjs +185 -0
- package/tools/look-stats.test.cjs +71 -0
- package/tools/memory-audit.cjs +323 -0
- package/tools/page-driver.cjs +320 -0
- package/tools/page-driver.test.cjs +219 -0
- package/tools/program-census-report.cjs +191 -0
- package/tools/program-census.cjs +465 -0
- package/tools/program-census.test.cjs +332 -0
- package/tools/remote-runner.sh +265 -0
- package/tools/runners.test.cjs +59 -0
- package/tools/scene-audit-beat.cjs +344 -0
- package/tools/scene-audit-sheet.cjs +282 -0
- package/tools/scene-audit.cjs +471 -0
- package/tools/scene-audit.test.cjs +201 -0
- package/tools/scene-batch.cjs +219 -0
- package/tools/scene-bench.cjs +149 -0
- package/tools/scene-bench.test.cjs +33 -0
- package/tools/scene-run.cjs +443 -0
- package/tools/scene-run.test.cjs +94 -0
- package/tools/servers.sh +59 -0
- package/tools/shader-arrival.cjs +316 -0
- package/tools/shader-renewal.cjs +53 -0
- package/tools/shader-renewal.test.cjs +115 -0
- package/tools/speed-guard.cjs +258 -0
- package/tools/stills.cjs +492 -0
- package/tools/stills.test.cjs +49 -0
- package/tools/turns.sh +7 -0
- package/tools/yaml.cjs +158 -0
- package/examples/viaduct.css +0 -75
- package/rendering/light-shafts.js +0 -131
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedural dust motes suspended inside architectural sun shafts.
|
|
3
|
+
* Each mote tests its ray along `+uSunDir` against window openings and interior box occluders so
|
|
4
|
+
* motes illuminate strictly inside real sunbeams, shaded with Henyey-Greenstein forward scatter,
|
|
5
|
+
* per-flake tumbling wink, an energy-conserving sub-pixel size floor, and actor wake swirl.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as THREE from 'three';
|
|
10
|
+
import { mulberry32 } from '../math/random.js';
|
|
11
|
+
|
|
12
|
+
const MAX_WINDOWS = 24;
|
|
13
|
+
const MAX_OCCLUDERS = 12;
|
|
14
|
+
const ACTOR_SLOTS = 4;
|
|
15
|
+
const MIN_PIXEL_RADIUS = 1.1;
|
|
16
|
+
const MAX_PIXEL_RADIUS = 11.0;
|
|
17
|
+
|
|
18
|
+
function pointInBox(px, py, pz, b) {
|
|
19
|
+
const hy = b.hy ?? 0;
|
|
20
|
+
if (Math.abs(py - b.y) >= hy) return false;
|
|
21
|
+
const rx = px - b.x;
|
|
22
|
+
const rz = pz - b.z;
|
|
23
|
+
const ry = b.ry || 0;
|
|
24
|
+
const cosY = Math.cos(ry);
|
|
25
|
+
const sinY = Math.sin(ry);
|
|
26
|
+
const lx = cosY * rx - sinY * rz;
|
|
27
|
+
const lz = sinY * rx + cosY * rz;
|
|
28
|
+
return Math.abs(lx) < (b.hx ?? 0) && Math.abs(lz) < (b.hz ?? 0);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function buildWindowApertures(windows) {
|
|
32
|
+
const list = windows ? [...windows] : [];
|
|
33
|
+
if (list.length > MAX_WINDOWS) {
|
|
34
|
+
list.sort((a, b) => (b.w ?? 1) * (b.h ?? 1) * (b.weight ?? 1) - (a.w ?? 1) * (a.h ?? 1) * (a.weight ?? 1));
|
|
35
|
+
list.length = MAX_WINDOWS;
|
|
36
|
+
}
|
|
37
|
+
const centers = [];
|
|
38
|
+
const normals = [];
|
|
39
|
+
const parsed = [];
|
|
40
|
+
for (let i = 0; i < MAX_WINDOWS; i++) {
|
|
41
|
+
if (i < list.length) {
|
|
42
|
+
const w = list[i];
|
|
43
|
+
let nx = w.nx ?? 0;
|
|
44
|
+
let ny = w.ny ?? 0;
|
|
45
|
+
let nz = w.nz ?? 0;
|
|
46
|
+
const len = Math.hypot(nx, ny, nz) || 1;
|
|
47
|
+
nx /= len;
|
|
48
|
+
ny /= len;
|
|
49
|
+
nz /= len;
|
|
50
|
+
const hw = Math.max(0.04, (w.w ?? 1) * 0.5);
|
|
51
|
+
const hh = Math.max(0.04, (w.h ?? 1) * 0.5);
|
|
52
|
+
const weight = w.weight ?? 1;
|
|
53
|
+
centers.push(new THREE.Vector4(w.x, w.y, w.z, hw));
|
|
54
|
+
normals.push(new THREE.Vector4(nx, ny, nz, hh * Math.sign(weight >= 0 ? 1 : -1)));
|
|
55
|
+
|
|
56
|
+
let ux;
|
|
57
|
+
let uy;
|
|
58
|
+
let uz;
|
|
59
|
+
if (Math.abs(ny) < 0.85) {
|
|
60
|
+
const hLen = Math.hypot(nx, nz) || 1;
|
|
61
|
+
ux = -nz / hLen;
|
|
62
|
+
uy = 0;
|
|
63
|
+
uz = nx / hLen;
|
|
64
|
+
} else {
|
|
65
|
+
ux = 1;
|
|
66
|
+
uy = 0;
|
|
67
|
+
uz = 0;
|
|
68
|
+
}
|
|
69
|
+
const vx = ny * uz - nz * uy;
|
|
70
|
+
const vy = nz * ux - nx * uz;
|
|
71
|
+
const vz = nx * uy - ny * ux;
|
|
72
|
+
parsed.push({
|
|
73
|
+
x: w.x,
|
|
74
|
+
y: w.y,
|
|
75
|
+
z: w.z,
|
|
76
|
+
nx,
|
|
77
|
+
ny,
|
|
78
|
+
nz,
|
|
79
|
+
ux,
|
|
80
|
+
uy,
|
|
81
|
+
uz,
|
|
82
|
+
vx,
|
|
83
|
+
vy,
|
|
84
|
+
vz,
|
|
85
|
+
hw,
|
|
86
|
+
hh,
|
|
87
|
+
weight: Math.max(0, weight),
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
centers.push(new THREE.Vector4(0, 0, 0, 0));
|
|
91
|
+
normals.push(new THREE.Vector4(0, 1, 0, 0));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return { count: list.length, centers, normals, parsed };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function buildInteriorOccluders(occluders, bounds) {
|
|
98
|
+
const candidates = [];
|
|
99
|
+
const src = occluders ?? [];
|
|
100
|
+
for (let i = 0; i < src.length; i++) {
|
|
101
|
+
const b = src[i];
|
|
102
|
+
const hx = b.hx ?? 0;
|
|
103
|
+
const hy = b.hy ?? 0;
|
|
104
|
+
const hz = b.hz ?? 0;
|
|
105
|
+
if (!(hx > 0.02 && hy > 0.02 && hz > 0.02)) continue;
|
|
106
|
+
// Outer shell walls sit outside or flush with `bounds`; window apertures already mask outer walls cleanly.
|
|
107
|
+
if (bounds) {
|
|
108
|
+
const margin = 0.06;
|
|
109
|
+
if (b.x <= bounds.x0 + margin || b.x >= bounds.x1 - margin || b.z <= bounds.z0 + margin || b.z >= bounds.z1 - margin) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const ry = b.ry || 0;
|
|
114
|
+
const cosY = Math.cos(ry);
|
|
115
|
+
const sinY = Math.sin(ry);
|
|
116
|
+
const worldHx = Math.abs(cosY) * hx + Math.abs(sinY) * hz;
|
|
117
|
+
const worldHz = Math.abs(sinY) * hx + Math.abs(cosY) * hz;
|
|
118
|
+
candidates.push({
|
|
119
|
+
minX: b.x - worldHx,
|
|
120
|
+
minY: b.y - hy,
|
|
121
|
+
minZ: b.z - worldHz,
|
|
122
|
+
maxX: b.x + worldHx,
|
|
123
|
+
maxY: b.y + hy,
|
|
124
|
+
maxZ: b.z + worldHz,
|
|
125
|
+
volume: worldHx * hy * worldHz,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
candidates.sort((a, b) => b.volume - a.volume);
|
|
129
|
+
if (candidates.length > MAX_OCCLUDERS) candidates.length = MAX_OCCLUDERS;
|
|
130
|
+
|
|
131
|
+
const mins = [];
|
|
132
|
+
const maxs = [];
|
|
133
|
+
for (let i = 0; i < MAX_OCCLUDERS; i++) {
|
|
134
|
+
if (i < candidates.length) {
|
|
135
|
+
const c = candidates[i];
|
|
136
|
+
mins.push(new THREE.Vector4(c.minX, c.minY, c.minZ, 1));
|
|
137
|
+
maxs.push(new THREE.Vector4(c.maxX, c.maxY, c.maxZ, 1));
|
|
138
|
+
} else {
|
|
139
|
+
mins.push(new THREE.Vector4(0, 0, 0, 0));
|
|
140
|
+
maxs.push(new THREE.Vector4(0, 0, 0, 0));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return { count: candidates.length, mins, maxs, list: candidates };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function smoothstep(edge0, edge1, x) {
|
|
147
|
+
const t = Math.max(0, Math.min(1, (x - edge0) / (edge1 - edge0)));
|
|
148
|
+
return t * t * (3 - 2 * t);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function rayHitsAabb(px, py, pz, dx, dy, dz, box, maxT) {
|
|
152
|
+
let tMin = 0.04;
|
|
153
|
+
let tMax = maxT;
|
|
154
|
+
|
|
155
|
+
if (Math.abs(dx) < 1e-7) {
|
|
156
|
+
if (px < box.minX || px > box.maxX) return false;
|
|
157
|
+
} else {
|
|
158
|
+
const inv = 1 / dx;
|
|
159
|
+
let t1 = (box.minX - px) * inv;
|
|
160
|
+
let t2 = (box.maxX - px) * inv;
|
|
161
|
+
if (t1 > t2) {
|
|
162
|
+
const tmp = t1;
|
|
163
|
+
t1 = t2;
|
|
164
|
+
t2 = tmp;
|
|
165
|
+
}
|
|
166
|
+
if (t1 > tMin) tMin = t1;
|
|
167
|
+
if (t2 < tMax) tMax = t2;
|
|
168
|
+
if (tMin >= tMax) return false;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (Math.abs(dy) < 1e-7) {
|
|
172
|
+
if (py < box.minY || py > box.maxY) return false;
|
|
173
|
+
} else {
|
|
174
|
+
const inv = 1 / dy;
|
|
175
|
+
let t1 = (box.minY - py) * inv;
|
|
176
|
+
let t2 = (box.maxY - py) * inv;
|
|
177
|
+
if (t1 > t2) {
|
|
178
|
+
const tmp = t1;
|
|
179
|
+
t1 = t2;
|
|
180
|
+
t2 = tmp;
|
|
181
|
+
}
|
|
182
|
+
if (t1 > tMin) tMin = t1;
|
|
183
|
+
if (t2 < tMax) tMax = t2;
|
|
184
|
+
if (tMin >= tMax) return false;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (Math.abs(dz) < 1e-7) {
|
|
188
|
+
if (pz < box.minZ || pz > box.maxZ) return false;
|
|
189
|
+
} else {
|
|
190
|
+
const inv = 1 / dz;
|
|
191
|
+
let t1 = (box.minZ - pz) * inv;
|
|
192
|
+
let t2 = (box.maxZ - pz) * inv;
|
|
193
|
+
if (t1 > t2) {
|
|
194
|
+
const tmp = t1;
|
|
195
|
+
t1 = t2;
|
|
196
|
+
t2 = tmp;
|
|
197
|
+
}
|
|
198
|
+
if (t1 > tMin) tMin = t1;
|
|
199
|
+
if (t2 < tMax) tMax = t2;
|
|
200
|
+
if (tMin >= tMax) return false;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Evaluate sun-shaft visibility [0..1] for a world point `(x, y, z)` along `+sunDir` through
|
|
208
|
+
* `windows` and interior `occluders` (matching the vertex-shader aperture test).
|
|
209
|
+
*
|
|
210
|
+
* @param {number} x
|
|
211
|
+
* @param {number} y
|
|
212
|
+
* @param {number} z
|
|
213
|
+
* @param {{ x: number, y: number, z: number }} sunDir Unit direction toward the sun.
|
|
214
|
+
* @param {Array<{ x: number, y: number, z: number, w: number, h: number, nx: number, ny?: number, nz: number, weight?: number }>} windows
|
|
215
|
+
* @param {Array<{ x: number, y: number, z: number, hx: number, hy: number, hz: number, ry?: number }>} [occluders]
|
|
216
|
+
* @param {{ x0: number, x1: number, y0: number, y1: number, z0: number, z1: number } | null} [bounds]
|
|
217
|
+
*/
|
|
218
|
+
export function sampleSunbeamShaft(x, y, z, sunDir, windows, occluders = [], bounds = null) {
|
|
219
|
+
const sLen = Math.hypot(sunDir.x, sunDir.y, sunDir.z);
|
|
220
|
+
if (sLen < 1e-5) return 0;
|
|
221
|
+
const sx = sunDir.x / sLen;
|
|
222
|
+
const sy = sunDir.y / sLen;
|
|
223
|
+
const sz = sunDir.z / sLen;
|
|
224
|
+
if (sy <= 0.005) return 0;
|
|
225
|
+
|
|
226
|
+
const { parsed } = buildWindowApertures(windows);
|
|
227
|
+
const { list: occList } = buildInteriorOccluders(occluders, bounds);
|
|
228
|
+
|
|
229
|
+
let best = 0;
|
|
230
|
+
for (let i = 0; i < parsed.length; i++) {
|
|
231
|
+
const w = parsed[i];
|
|
232
|
+
if (w.weight <= 0) continue;
|
|
233
|
+
const denom = sx * w.nx + sy * w.ny + sz * w.nz;
|
|
234
|
+
if (denom >= -0.02) continue;
|
|
235
|
+
|
|
236
|
+
const tHit = ((w.x - x) * w.nx + (w.y - y) * w.ny + (w.z - z) * w.nz) / denom;
|
|
237
|
+
if (tHit <= 0.02) continue;
|
|
238
|
+
|
|
239
|
+
const hx = x + sx * tHit - w.x;
|
|
240
|
+
const hy = y + sy * tHit - w.y;
|
|
241
|
+
const hz = z + sz * tHit - w.z;
|
|
242
|
+
const u = Math.abs(hx * w.ux + hy * w.uy + hz * w.uz) / w.hw;
|
|
243
|
+
const v = Math.abs(hx * w.vx + hy * w.vy + hz * w.vz) / w.hh;
|
|
244
|
+
if (u >= 1.04 || v >= 1.04) continue;
|
|
245
|
+
|
|
246
|
+
let blocked = false;
|
|
247
|
+
const maxOccT = tHit - 0.12;
|
|
248
|
+
if (maxOccT > 0.05) {
|
|
249
|
+
for (let j = 0; j < occList.length; j++) {
|
|
250
|
+
if (rayHitsAabb(x, y, z, sx, sy, sz, occList[j], maxOccT)) {
|
|
251
|
+
blocked = true;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (blocked) continue;
|
|
257
|
+
|
|
258
|
+
const aperture = (1 - smoothstep(0.86, 1.02, u)) * (1 - smoothstep(0.86, 1.02, v)) * Math.min(1, w.weight);
|
|
259
|
+
if (aperture > best) best = aperture;
|
|
260
|
+
}
|
|
261
|
+
return best * smoothstep(0.005, 0.09, sy);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const MOTES_VERTEX_SHADER = /* glsl */ `
|
|
265
|
+
uniform float uTime;
|
|
266
|
+
uniform float uPointScale;
|
|
267
|
+
uniform float uIntensity;
|
|
268
|
+
uniform vec3 uSunDir;
|
|
269
|
+
uniform vec3 uSunColor;
|
|
270
|
+
uniform vec3 uBoundsMin;
|
|
271
|
+
uniform vec3 uBoundsSpan;
|
|
272
|
+
uniform int uWinCount;
|
|
273
|
+
uniform vec4 uWinCenter[${MAX_WINDOWS}];
|
|
274
|
+
uniform vec4 uWinNormal[${MAX_WINDOWS}];
|
|
275
|
+
uniform int uOccCount;
|
|
276
|
+
uniform vec4 uOccMin[${MAX_OCCLUDERS}];
|
|
277
|
+
uniform vec4 uOccMax[${MAX_OCCLUDERS}];
|
|
278
|
+
uniform vec4 uActors[${ACTOR_SLOTS}];
|
|
279
|
+
uniform vec4 uActorVel[${ACTOR_SLOTS}];
|
|
280
|
+
|
|
281
|
+
attribute vec4 aMoteSeed;
|
|
282
|
+
varying vec3 vMoteColor;
|
|
283
|
+
|
|
284
|
+
bool moteBlockedByAabb(vec3 origin, vec3 dir, vec3 boxMin, vec3 boxMax, float maxT) {
|
|
285
|
+
vec3 safeDir = vec3(
|
|
286
|
+
abs(dir.x) > 1e-6 ? dir.x : 1e-6,
|
|
287
|
+
abs(dir.y) > 1e-6 ? dir.y : 1e-6,
|
|
288
|
+
abs(dir.z) > 1e-6 ? dir.z : 1e-6
|
|
289
|
+
);
|
|
290
|
+
vec3 invD = 1.0 / safeDir;
|
|
291
|
+
vec3 t0 = (boxMin - origin) * invD;
|
|
292
|
+
vec3 t1 = (boxMax - origin) * invD;
|
|
293
|
+
vec3 tSmaller = min(t0, t1);
|
|
294
|
+
vec3 tBigger = max(t0, t1);
|
|
295
|
+
float tEnter = max(0.04, max(tSmaller.x, max(tSmaller.y, tSmaller.z)));
|
|
296
|
+
float tExit = min(maxT, min(tBigger.x, min(tBigger.y, tBigger.z)));
|
|
297
|
+
return tEnter < tExit;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
float sampleShaftVisibility(vec3 worldPos, vec3 sunDir) {
|
|
301
|
+
float best = 0.0;
|
|
302
|
+
for (int i = 0; i < ${MAX_WINDOWS}; i++) {
|
|
303
|
+
if (i >= uWinCount) break;
|
|
304
|
+
vec3 wCenter = uWinCenter[i].xyz;
|
|
305
|
+
float halfW = uWinCenter[i].w;
|
|
306
|
+
vec3 wNormal = uWinNormal[i].xyz;
|
|
307
|
+
float halfH = abs(uWinNormal[i].w);
|
|
308
|
+
if (halfW <= 0.0 || halfH <= 0.0) continue;
|
|
309
|
+
|
|
310
|
+
float denom = dot(sunDir, wNormal);
|
|
311
|
+
if (denom >= -0.02) continue;
|
|
312
|
+
|
|
313
|
+
float tHit = dot(wCenter - worldPos, wNormal) / denom;
|
|
314
|
+
if (tHit <= 0.02) continue;
|
|
315
|
+
|
|
316
|
+
vec3 hitOffset = worldPos + sunDir * tHit - wCenter;
|
|
317
|
+
vec3 tangentU = abs(wNormal.y) < 0.85
|
|
318
|
+
? normalize(vec3(-wNormal.z, 0.0, wNormal.x))
|
|
319
|
+
: vec3(1.0, 0.0, 0.0);
|
|
320
|
+
vec3 tangentV = cross(wNormal, tangentU);
|
|
321
|
+
|
|
322
|
+
float u = abs(dot(hitOffset, tangentU)) / halfW;
|
|
323
|
+
float v = abs(dot(hitOffset, tangentV)) / halfH;
|
|
324
|
+
if (u >= 1.04 || v >= 1.04) continue;
|
|
325
|
+
|
|
326
|
+
bool blocked = false;
|
|
327
|
+
float maxOccT = tHit - 0.12;
|
|
328
|
+
if (maxOccT > 0.05) {
|
|
329
|
+
for (int j = 0; j < ${MAX_OCCLUDERS}; j++) {
|
|
330
|
+
if (j >= uOccCount) break;
|
|
331
|
+
if (moteBlockedByAabb(worldPos, sunDir, uOccMin[j].xyz, uOccMax[j].xyz, maxOccT)) {
|
|
332
|
+
blocked = true;
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (blocked) continue;
|
|
338
|
+
|
|
339
|
+
float feather = (1.0 - smoothstep(0.86, 1.02, u)) * (1.0 - smoothstep(0.86, 1.02, v));
|
|
340
|
+
best = max(best, feather);
|
|
341
|
+
}
|
|
342
|
+
return best;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
void main() {
|
|
346
|
+
float sunUp = smoothstep(0.005, 0.09, uSunDir.y) * uIntensity;
|
|
347
|
+
if (sunUp <= 0.001 || uWinCount <= 0) {
|
|
348
|
+
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
349
|
+
gl_PointSize = 0.0;
|
|
350
|
+
vMoteColor = vec3(0.0);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
float phase = aMoteSeed.x;
|
|
355
|
+
float radiusMeters = aMoteSeed.y;
|
|
356
|
+
float tumbleRate = aMoteSeed.z;
|
|
357
|
+
float driftScale = aMoteSeed.w;
|
|
358
|
+
|
|
359
|
+
// Lazy indoor thermal convection wrapped seamlessly inside the room's air volume.
|
|
360
|
+
float slowT = uTime * 0.14 * driftScale + phase * 6.2831853;
|
|
361
|
+
vec3 drift = vec3(
|
|
362
|
+
sin(slowT * 1.13 + position.z * 0.7) * 0.36 + cos(slowT * 0.47 + position.y * 1.1) * 0.18,
|
|
363
|
+
uTime * 0.022 * driftScale + sin(slowT * 0.83 + position.x * 0.9) * 0.22,
|
|
364
|
+
cos(slowT * 1.07 + position.x * 0.65) * 0.36 + sin(slowT * 0.53 + position.y * 0.95) * 0.18
|
|
365
|
+
);
|
|
366
|
+
vec3 p = uBoundsMin + mod(position - uBoundsMin + drift + uBoundsSpan * 64.0, uBoundsSpan);
|
|
367
|
+
|
|
368
|
+
// Actor wake & swirl when characters or the player walk through or cross a sun shaft.
|
|
369
|
+
for (int i = 0; i < ${ACTOR_SLOTS}; i++) {
|
|
370
|
+
float strength = uActors[i].w;
|
|
371
|
+
if (strength <= 0.004) continue;
|
|
372
|
+
vec3 delta = p - uActors[i].xyz;
|
|
373
|
+
float radius = max(uActorVel[i].w, 0.45);
|
|
374
|
+
vec3 ellip = vec3(delta.x, delta.y * 0.56, delta.z);
|
|
375
|
+
float fall = exp(-dot(ellip, ellip) / (radius * radius)) * strength;
|
|
376
|
+
if (fall <= 0.002) continue;
|
|
377
|
+
|
|
378
|
+
vec2 horiz = delta.xz;
|
|
379
|
+
float hLen = length(horiz);
|
|
380
|
+
vec2 radial = hLen > 1e-4 ? horiz / hLen : vec2(cos(phase * 6.2831853), sin(phase * 6.2831853));
|
|
381
|
+
float swirlDir = phase > 0.5 ? 1.0 : -1.0;
|
|
382
|
+
vec2 vortex = vec2(-radial.y, radial.x) * swirlDir * (0.65 + 0.35 * sin(uTime * 2.1 + phase * 12.0));
|
|
383
|
+
p.xz += (radial * 0.34 + vortex * 0.38) * fall + uActorVel[i].xz * (0.22 * fall);
|
|
384
|
+
p.y += (0.18 + 0.12 * sin(uTime * 2.7 + phase * 9.0)) * fall + uActorVel[i].y * (0.15 * fall);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
vec4 world4 = modelMatrix * vec4(p, 1.0);
|
|
388
|
+
vec3 worldPos = world4.xyz;
|
|
389
|
+
vec3 sunDir = normalize(uSunDir);
|
|
390
|
+
|
|
391
|
+
float shaft = sampleShaftVisibility(worldPos, sunDir) * sunUp;
|
|
392
|
+
if (shaft <= 0.002) {
|
|
393
|
+
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
394
|
+
gl_PointSize = 0.0;
|
|
395
|
+
vMoteColor = vec3(0.0);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
vec4 mvPosition = viewMatrix * world4;
|
|
400
|
+
float depth = -mvPosition.z;
|
|
401
|
+
if (depth <= 0.12) {
|
|
402
|
+
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
403
|
+
gl_PointSize = 0.0;
|
|
404
|
+
vMoteColor = vec3(0.0);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Energy-conserving sub-pixel size floor: clamp radius >= 1.1 px and dim by (trueRadius / clampedRadius)^2.
|
|
409
|
+
float trueRadius = radiusMeters * uPointScale / depth;
|
|
410
|
+
float clampedRadius = clamp(trueRadius, ${MIN_PIXEL_RADIUS.toFixed(1)}, ${MAX_PIXEL_RADIUS.toFixed(1)});
|
|
411
|
+
float energyRatio = trueRadius / clampedRadius;
|
|
412
|
+
float energyKeep = energyRatio * energyRatio;
|
|
413
|
+
|
|
414
|
+
// Henyey-Greenstein forward scatter toward the sun (g = 0.62) plus mild isotropic side-scatter floor.
|
|
415
|
+
vec3 eyeToMote = normalize(worldPos - cameraPosition);
|
|
416
|
+
float cosTheta = dot(sunDir, eyeToMote);
|
|
417
|
+
float g = 0.62;
|
|
418
|
+
float g2 = g * g;
|
|
419
|
+
float denomHg = max(1.0 + g2 - 2.0 * g * cosTheta, 0.05);
|
|
420
|
+
float hgPhase = (1.0 - g2) / (12.5663706 * denomHg * sqrt(denomHg));
|
|
421
|
+
float scatter = 0.32 + 1.85 * min(hgPhase, 2.6);
|
|
422
|
+
|
|
423
|
+
// Per-flake slow tumbling wink as flat dust facets catch the sunbeam.
|
|
424
|
+
float spin = uTime * tumbleRate + phase * 6.2831853;
|
|
425
|
+
float facet = 0.5 + 0.5 * sin(spin) * cos(spin * 0.618 + phase * 3.7);
|
|
426
|
+
float glint = pow(max(sin(spin * 0.77 + phase * 11.3), 0.0), 8.0);
|
|
427
|
+
float wink = 0.38 + 0.62 * smoothstep(0.2, 0.95, facet) + 0.72 * glint;
|
|
428
|
+
|
|
429
|
+
float nearFade = smoothstep(0.18, 0.75, depth) * (1.0 - smoothstep(18.0, 32.0, depth));
|
|
430
|
+
vMoteColor = uSunColor * (shaft * energyKeep * scatter * wink * nearFade * 0.68);
|
|
431
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
432
|
+
gl_PointSize = clampedRadius * 2.0;
|
|
433
|
+
}
|
|
434
|
+
`;
|
|
435
|
+
|
|
436
|
+
const MOTES_FRAGMENT_SHADER = /* glsl */ `
|
|
437
|
+
varying vec3 vMoteColor;
|
|
438
|
+
|
|
439
|
+
void main() {
|
|
440
|
+
vec2 d = gl_PointCoord * 2.0 - 1.0;
|
|
441
|
+
float r2 = dot(d, d);
|
|
442
|
+
if (r2 > 1.0) discard;
|
|
443
|
+
float spot = exp(-r2 * 3.1) * (1.0 - r2);
|
|
444
|
+
gl_FragColor = vec4(vMoteColor * spot, 1.0);
|
|
445
|
+
#include <tonemapping_fragment>
|
|
446
|
+
#include <colorspace_fragment>
|
|
447
|
+
}
|
|
448
|
+
`;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Create an interior dust-mote cloud whose particles illuminate strictly inside real window sun shafts
|
|
452
|
+
* and swirl aside when actors walk through them.
|
|
453
|
+
*
|
|
454
|
+
* @param {object} options
|
|
455
|
+
* @param {{ x0: number, x1: number, y0: number, y1: number, z0: number, z1: number }} options.bounds Interior volume bounds in world units.
|
|
456
|
+
* @param {Array<{ x: number, y: number, z: number, w: number, h: number, nx: number, ny?: number, nz: number, weight?: number }>} options.windows Window/doorway openings with inward normals.
|
|
457
|
+
* @param {Array<{ x: number, y: number, z: number, hx: number, hy: number, hz: number, ry?: number }>} [options.occluders] Solid box occluders inside the room.
|
|
458
|
+
* @param {number} [options.count] Number of suspended dust motes (~2000 by default).
|
|
459
|
+
* @param {number} [options.seed] Deterministic PRNG seed for mote positions and flake sizes.
|
|
460
|
+
* @param {{ value: number }} [options.pointScale] Optional shared perspective point-scale uniform.
|
|
461
|
+
*/
|
|
462
|
+
export function createSunbeamMotes({ bounds, windows = [], occluders = [], count = 2000, seed = 9137, pointScale = { value: 900 } }) {
|
|
463
|
+
if (!bounds || !(bounds.x1 > bounds.x0 && bounds.y1 > bounds.y0 && bounds.z1 > bounds.z0)) {
|
|
464
|
+
throw new TypeError('createSunbeamMotes requires valid { x0, x1, y0, y1, z0, z1 } bounds');
|
|
465
|
+
}
|
|
466
|
+
const moteCount = Math.max(1, Math.floor(count));
|
|
467
|
+
const rng = mulberry32(seed >>> 0);
|
|
468
|
+
|
|
469
|
+
const spanX = bounds.x1 - bounds.x0;
|
|
470
|
+
const spanY = bounds.y1 - bounds.y0;
|
|
471
|
+
const spanZ = bounds.z1 - bounds.z0;
|
|
472
|
+
|
|
473
|
+
const positions = new Float32Array(moteCount * 3);
|
|
474
|
+
const seeds = new Float32Array(moteCount * 4);
|
|
475
|
+
for (let i = 0; i < moteCount; i++) {
|
|
476
|
+
let px = 0;
|
|
477
|
+
let py = 0;
|
|
478
|
+
let pz = 0;
|
|
479
|
+
for (let attempt = 0; attempt < 6; attempt++) {
|
|
480
|
+
px = bounds.x0 + rng() * spanX;
|
|
481
|
+
py = bounds.y0 + rng() * spanY;
|
|
482
|
+
pz = bounds.z0 + rng() * spanZ;
|
|
483
|
+
let insideSolid = false;
|
|
484
|
+
for (let b = 0; b < occluders.length; b++) {
|
|
485
|
+
if (pointInBox(px, py, pz, occluders[b])) {
|
|
486
|
+
insideSolid = true;
|
|
487
|
+
break;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
if (!insideSolid) break;
|
|
491
|
+
}
|
|
492
|
+
const pi = i * 3;
|
|
493
|
+
positions[pi] = px;
|
|
494
|
+
positions[pi + 1] = py;
|
|
495
|
+
positions[pi + 2] = pz;
|
|
496
|
+
|
|
497
|
+
const si = i * 4;
|
|
498
|
+
const sizeSkew = rng();
|
|
499
|
+
seeds[si] = rng(); // phase [0..1]
|
|
500
|
+
seeds[si + 1] = 0.0014 + 0.003 * sizeSkew * sizeSkew; // physical radius in metres (1.4 mm .. 4.4 mm)
|
|
501
|
+
seeds[si + 2] = 0.85 + 2.35 * rng(); // tumble speed (rad/s)
|
|
502
|
+
seeds[si + 3] = 0.55 + 0.9 * rng(); // convection drift scale
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const geometry = new THREE.BufferGeometry();
|
|
506
|
+
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
|
|
507
|
+
geometry.setAttribute('aMoteSeed', new THREE.BufferAttribute(seeds, 4));
|
|
508
|
+
const cx = (bounds.x0 + bounds.x1) * 0.5;
|
|
509
|
+
const cy = (bounds.y0 + bounds.y1) * 0.5;
|
|
510
|
+
const cz = (bounds.z0 + bounds.z1) * 0.5;
|
|
511
|
+
geometry.boundingSphere = new THREE.Sphere(new THREE.Vector3(cx, cy, cz), Math.hypot(spanX, spanY, spanZ) * 0.5 + 2);
|
|
512
|
+
|
|
513
|
+
const winUniformData = buildWindowApertures(windows);
|
|
514
|
+
const occUniformData = buildInteriorOccluders(occluders, bounds);
|
|
515
|
+
|
|
516
|
+
const actorPositions = [];
|
|
517
|
+
const actorVelocities = [];
|
|
518
|
+
for (let i = 0; i < ACTOR_SLOTS; i++) {
|
|
519
|
+
actorPositions.push(new THREE.Vector4(0, -1000, 0, 0));
|
|
520
|
+
actorVelocities.push(new THREE.Vector4(0, 0, 0, 1.15));
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
const uniforms = {
|
|
524
|
+
uTime: { value: 0 },
|
|
525
|
+
uPointScale: pointScale,
|
|
526
|
+
uIntensity: { value: 1 },
|
|
527
|
+
uSunDir: { value: new THREE.Vector3(0.4, 0.5, 0.3).normalize() },
|
|
528
|
+
uSunColor: { value: new THREE.Color(1, 0.92, 0.76) },
|
|
529
|
+
uBoundsMin: { value: new THREE.Vector3(bounds.x0, bounds.y0, bounds.z0) },
|
|
530
|
+
uBoundsSpan: { value: new THREE.Vector3(spanX, spanY, spanZ) },
|
|
531
|
+
uWinCount: { value: winUniformData.count },
|
|
532
|
+
uWinCenter: { value: winUniformData.centers },
|
|
533
|
+
uWinNormal: { value: winUniformData.normals },
|
|
534
|
+
uOccCount: { value: occUniformData.count },
|
|
535
|
+
uOccMin: { value: occUniformData.mins },
|
|
536
|
+
uOccMax: { value: occUniformData.maxs },
|
|
537
|
+
uActors: { value: actorPositions },
|
|
538
|
+
uActorVel: { value: actorVelocities },
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
const material = new THREE.ShaderMaterial({
|
|
542
|
+
transparent: true,
|
|
543
|
+
depthWrite: false,
|
|
544
|
+
blending: THREE.AdditiveBlending,
|
|
545
|
+
fog: false,
|
|
546
|
+
uniforms,
|
|
547
|
+
vertexShader: MOTES_VERTEX_SHADER,
|
|
548
|
+
fragmentShader: MOTES_FRAGMENT_SHADER,
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
const points = new THREE.Points(geometry, material);
|
|
552
|
+
points.frustumCulled = false;
|
|
553
|
+
points.castShadow = false;
|
|
554
|
+
points.receiveShadow = false;
|
|
555
|
+
points.matrixAutoUpdate = false;
|
|
556
|
+
points.updateMatrix();
|
|
557
|
+
points.renderOrder = 6;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Inject or refresh an actor wake vortex at `(x, y, z)` moving at `(vx, vy, vz)` m/s.
|
|
561
|
+
* Reuses the nearest matching slot or replaces the weakest slot with zero heap allocations.
|
|
562
|
+
*/
|
|
563
|
+
function disturbAt(x, y, z, vx = 0, vy = 0, vz = 0, radius = 1.2) {
|
|
564
|
+
if (
|
|
565
|
+
x < bounds.x0 - 1.5 ||
|
|
566
|
+
x > bounds.x1 + 1.5 ||
|
|
567
|
+
y < bounds.y0 - 1.5 ||
|
|
568
|
+
y > bounds.y1 + 1.5 ||
|
|
569
|
+
z < bounds.z0 - 1.5 ||
|
|
570
|
+
z > bounds.z1 + 1.5
|
|
571
|
+
) {
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
let slot = -1;
|
|
575
|
+
let weakestSlot = 0;
|
|
576
|
+
let weakestStrength = Infinity;
|
|
577
|
+
for (let i = 0; i < ACTOR_SLOTS; i++) {
|
|
578
|
+
const ap = actorPositions[i];
|
|
579
|
+
if (ap.w > 0.01) {
|
|
580
|
+
const dx = ap.x - x;
|
|
581
|
+
const dy = ap.y - y;
|
|
582
|
+
const dz = ap.z - z;
|
|
583
|
+
if (dx * dx + dy * dy + dz * dz < 1.35 * 1.35) {
|
|
584
|
+
slot = i;
|
|
585
|
+
break;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
if (ap.w < weakestStrength) {
|
|
589
|
+
weakestStrength = ap.w;
|
|
590
|
+
weakestSlot = i;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
if (slot < 0) slot = weakestSlot;
|
|
594
|
+
|
|
595
|
+
const speed = Math.hypot(vx, vy, vz);
|
|
596
|
+
const targetStrength = Math.min(1.35, 0.28 + speed * 0.42);
|
|
597
|
+
const ap = actorPositions[slot];
|
|
598
|
+
const av = actorVelocities[slot];
|
|
599
|
+
if (ap.w > 0.02) {
|
|
600
|
+
ap.x += (x - ap.x) * 0.45;
|
|
601
|
+
ap.y += (y - ap.y) * 0.45;
|
|
602
|
+
ap.z += (z - ap.z) * 0.45;
|
|
603
|
+
av.x += (vx - av.x) * 0.38;
|
|
604
|
+
av.y += (vy - av.y) * 0.38;
|
|
605
|
+
av.z += (vz - av.z) * 0.38;
|
|
606
|
+
ap.w = Math.max(ap.w, targetStrength);
|
|
607
|
+
} else {
|
|
608
|
+
ap.set(x, y, z, targetStrength);
|
|
609
|
+
av.set(vx, vy, vz, radius);
|
|
610
|
+
}
|
|
611
|
+
av.w = radius;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Advance mote drift, decay actor wakes smoothly, and update sun direction/colour uniforms.
|
|
616
|
+
*
|
|
617
|
+
* @param {number} dt Frame step in seconds.
|
|
618
|
+
* @param {object} [frameState]
|
|
619
|
+
* @param {number} [frameState.time] Absolute elapsed time in seconds (otherwise accumulated from `dt`).
|
|
620
|
+
* @param {{ x: number, y: number, z: number }} [frameState.sunDir] Unit direction toward the sun.
|
|
621
|
+
* @param {{ r: number, g: number, b: number }} [frameState.sunColor] Linear RGB sun radiance tint.
|
|
622
|
+
* @param {number} [frameState.intensity] Overall beam mote visibility multiplier [0..1+].
|
|
623
|
+
* @param {number} [frameState.pointScale] Optional perspective point-scale override.
|
|
624
|
+
*/
|
|
625
|
+
function update(dt, frameState) {
|
|
626
|
+
const step = Math.max(0, Math.min(0.25, dt || 0));
|
|
627
|
+
const decay = Math.exp(-step * 1.45);
|
|
628
|
+
for (let i = 0; i < ACTOR_SLOTS; i++) {
|
|
629
|
+
actorPositions[i].w *= decay;
|
|
630
|
+
if (actorPositions[i].w < 0.003) actorPositions[i].w = 0;
|
|
631
|
+
actorVelocities[i].x *= decay;
|
|
632
|
+
actorVelocities[i].y *= decay;
|
|
633
|
+
actorVelocities[i].z *= decay;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (frameState) {
|
|
637
|
+
if (typeof frameState.time === 'number') uniforms.uTime.value = frameState.time;
|
|
638
|
+
else uniforms.uTime.value += step;
|
|
639
|
+
if (frameState.sunDir) {
|
|
640
|
+
uniforms.uSunDir.value.set(frameState.sunDir.x, frameState.sunDir.y, frameState.sunDir.z);
|
|
641
|
+
}
|
|
642
|
+
if (frameState.sunColor) {
|
|
643
|
+
uniforms.uSunColor.value.setRGB(frameState.sunColor.r, frameState.sunColor.g, frameState.sunColor.b);
|
|
644
|
+
}
|
|
645
|
+
if (typeof frameState.intensity === 'number') uniforms.uIntensity.value = frameState.intensity;
|
|
646
|
+
if (typeof frameState.pointScale === 'number') uniforms.uPointScale.value = frameState.pointScale;
|
|
647
|
+
} else {
|
|
648
|
+
uniforms.uTime.value += step;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
function sampleShaft(x, y, z, sunDir = uniforms.uSunDir.value) {
|
|
653
|
+
return sampleSunbeamShaft(x, y, z, sunDir, windows, occluders, bounds);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function dispose() {
|
|
657
|
+
geometry.dispose();
|
|
658
|
+
material.dispose();
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
return {
|
|
662
|
+
points,
|
|
663
|
+
uniforms,
|
|
664
|
+
bounds,
|
|
665
|
+
disturbAt,
|
|
666
|
+
update,
|
|
667
|
+
sampleShaft,
|
|
668
|
+
dispose,
|
|
669
|
+
};
|
|
670
|
+
}
|