roamwright 0.4.0 → 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 +21 -14
- package/README.md +38 -42
- 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/bedding.js +141 -0
- package/geometry/builder-cells.js +50 -0
- package/geometry/builder-frame.js +48 -0
- package/geometry/builder.js +200 -177
- package/geometry/card-emblem.js +437 -0
- package/geometry/catenary-canvas.js +396 -0
- package/geometry/cell-mask.js +25 -0
- package/geometry/cloth-folds.js +143 -0
- package/geometry/crawl-shapes.js +71 -0
- package/geometry/creased-sheet.js +40 -35
- 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 +44 -39
- package/geometry/erosion.js +71 -45
- package/geometry/face-grid.js +85 -65
- 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 +187 -14
- 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 +57 -42
- package/geometry/hair-locks.js +42 -42
- package/geometry/hair-patch.js +24 -20
- package/geometry/hair-shell.js +43 -31
- package/geometry/head-presets.js +103 -0
- package/geometry/head-profile.js +26 -15
- package/geometry/head-shape.js +123 -95
- package/geometry/heightfield.js +50 -24
- 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/index-parts.js +2 -2
- package/geometry/instance-visibility.js +12 -12
- package/geometry/instances.js +17 -17
- 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 +11 -10
- package/geometry/outline-segments.js +74 -0
- package/geometry/part-ranges.js +38 -3
- package/geometry/path-field.js +98 -34
- package/geometry/placement.js +52 -52
- 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/point-buckets.js +50 -0
- package/geometry/primitives.js +117 -59
- 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/sagging-tube.js +27 -27
- package/geometry/sampled-surface.js +123 -77
- package/geometry/scatter-grid.js +49 -6
- package/geometry/sculpt.js +97 -93
- 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 +81 -34
- package/geometry/strata-field.js +131 -98
- package/geometry/strata-tiles.js +108 -94
- package/geometry/stream.js +96 -59
- package/geometry/swept-tube.js +124 -0
- package/geometry/terrain-chunks.js +216 -123
- package/geometry/terrain-extension.js +29 -13
- 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 +138 -2
- package/math/cell-edge.js +16 -16
- package/math/cell-key.js +6 -0
- package/math/circle-clearances.js +19 -0
- package/math/cloth-textures.js +6 -6
- package/math/cloud-textures.js +22 -26
- package/math/color.js +14 -14
- package/math/curve.js +26 -22
- package/math/lamp-texels.js +43 -0
- package/math/lit-share.js +22 -0
- package/math/mountain-ranges.js +379 -205
- package/math/noise.js +101 -49
- package/math/particle-noise.js +28 -28
- package/math/periodic.js +11 -5
- package/math/random.js +24 -15
- package/math/rectangles.js +58 -0
- package/math/rock-texture.js +22 -17
- package/math/scalar.js +5 -5
- package/math/surface-textures.js +74 -59
- 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 +27 -26
- package/motion/ballistic-arc.js +191 -0
- package/motion/biped-cycle.js +46 -0
- package/motion/biped-leg.js +40 -0
- package/motion/biped-posture.js +459 -0
- package/motion/biped-stride.js +226 -140
- package/motion/boat-sailing.js +214 -0
- package/motion/contact-transition.js +32 -0
- package/motion/crowd-alarms.js +72 -42
- 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 +126 -67
- package/motion/crowd-town.js +166 -0
- package/motion/crowd-water.js +143 -0
- package/motion/daily-clock.js +9 -9
- package/motion/deck-surface.js +40 -0
- 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/ground-lookahead.js +5 -5
- package/motion/instance-sight.js +15 -8
- package/motion/melee-contact.js +143 -0
- package/motion/moorings.js +48 -0
- package/motion/path-steering.js +358 -0
- package/motion/player.js +41 -32
- package/motion/quadruped.js +244 -168
- package/motion/spaces.js +90 -38
- 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 +133 -26
- package/motion/wind.js +58 -13
- package/package.json +33 -6
- 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/cart-track.js +92 -0
- package/rendering/caster-motion.js +6 -5
- package/rendering/cell-lod-options.js +46 -0
- package/rendering/cell-lod.js +754 -113
- package/rendering/cloth-material.js +140 -0
- package/rendering/cloud-dome.js +30 -30
- package/rendering/cloud-field.js +2 -2
- package/rendering/compilation-schedule.js +79 -14
- package/rendering/contact-shadows.js +7 -4
- package/rendering/context.js +57 -6
- 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 +62 -19
- package/rendering/crowd-update.js +419 -0
- package/rendering/crowd-visibility.js +107 -0
- package/rendering/crust.js +18 -12
- package/rendering/day-cycle-defaults.js +200 -0
- package/rendering/day-cycle.js +487 -0
- package/rendering/daylight.js +4 -6
- package/rendering/detail-range.js +29 -0
- package/rendering/dispose-meshes.js +18 -0
- package/rendering/dof.js +20 -13
- package/rendering/effects-frame.js +149 -0
- package/rendering/effects-water-rises.js +221 -0
- package/rendering/energy-stream.js +128 -0
- package/rendering/eye-adapt.js +14 -14
- package/rendering/facade-glass-material.js +105 -0
- package/rendering/far-shadow.js +89 -62
- 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 +82 -78
- package/rendering/garment-material.js +147 -51
- package/rendering/glow-lines.js +13 -13
- package/rendering/glsl-literal.js +19 -0
- package/rendering/ground-marks.js +316 -0
- package/rendering/hair-strands.js +45 -31
- package/rendering/height-haze.js +80 -33
- package/rendering/height-probe.js +164 -22
- package/rendering/house-kit-meshes.js +124 -0
- package/rendering/interior-bake.js +807 -0
- package/rendering/label-layout.js +56 -0
- package/rendering/label-range.js +41 -0
- 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 +71 -55
- package/rendering/light-points.js +21 -5
- package/rendering/local-lights.js +39 -8
- package/rendering/material-lod.js +49 -50
- 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 +135 -99
- package/rendering/particle-light-bursts.js +189 -0
- package/rendering/particles.js +212 -101
- package/rendering/pen-flocks.js +118 -0
- package/rendering/piece-batch.js +298 -11
- package/rendering/planar-reflection-options.js +159 -0
- package/rendering/planar-reflection.js +806 -103
- 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 +98 -31
- package/rendering/post.js +107 -87
- package/rendering/pressed-cover.js +135 -0
- package/rendering/prop-dig.js +136 -0
- package/rendering/rain-streaks.js +67 -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 +94 -37
- 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 +101 -44
- package/rendering/shadow-alignment.js +4 -4
- package/rendering/shadow-depth.js +47 -25
- package/rendering/ship-meshes.js +150 -0
- package/rendering/shot-cuts.js +68 -0
- package/rendering/sky-occlusion.js +56 -29
- package/rendering/sky-pmrem.js +216 -0
- package/rendering/sky.js +126 -54
- 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 +65 -26
- package/rendering/still-casters.js +77 -27
- package/rendering/strata-material.js +12 -12
- package/rendering/stream-flow.js +10 -10
- 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 +75 -44
- package/rendering/talus.js +15 -15
- package/rendering/terrain-rock.js +7 -7
- package/rendering/texture-fills.js +8 -8
- package/rendering/textures.js +28 -28
- package/rendering/tree-impostor.js +929 -0
- package/rendering/vehicle-train.js +92 -0
- package/rendering/viewport.js +67 -4
- package/rendering/wakes.js +24 -24
- package/rendering/water-material.js +304 -103
- package/rendering/waypoint-beacons.js +191 -0
- package/rendering/world-matrices.js +38 -40
- 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 +12 -4
- package/runtime/effect-sites.js +85 -0
- package/runtime/figure-orders.js +59 -0
- package/runtime/first-use.js +36 -28
- package/runtime/foley-script.js +124 -0
- package/runtime/foley-strides.js +333 -0
- package/runtime/frame-pacing.js +47 -0
- package/runtime/frame-yield.js +18 -0
- package/runtime/gpu-timing.js +15 -11
- package/runtime/grid-cache.js +16 -6
- package/runtime/grid-rows.js +44 -5
- package/runtime/hand-over.js +47 -24
- package/runtime/land-bake.js +78 -0
- package/runtime/lazy-sets.js +105 -0
- package/runtime/pool.js +73 -17
- package/runtime/quality-fit.js +60 -28
- package/runtime/region-pass-lay.js +40 -0
- package/runtime/region-pass.js +78 -0
- package/runtime/search.js +26 -22
- 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 +79 -30
- package/runtime/steady-frames.js +221 -0
- package/runtime/withdrawable-task.js +46 -0
- package/runtime/worker.js +7 -0
- 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
- package/rendering/road-surface.js +0 -63
|
@@ -0,0 +1,807 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CPU interior light baker and material shader patch for enclosed architectural spaces.
|
|
3
|
+
* Computes per-vertex corner ambient occlusion, directional per-side window sky light with single-bounce
|
|
4
|
+
* room fill, and box-occluded lamp/hearth irradiance at build time using allocation-free slab ray-casting.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { releaseArray } from '../geometry/builder.js';
|
|
10
|
+
|
|
11
|
+
const AO_RAY_COUNT = 14;
|
|
12
|
+
const GOLDEN_ANGLE = Math.PI * (3 - Math.sqrt(5));
|
|
13
|
+
const NORMAL_BIAS_METERS = 0.035;
|
|
14
|
+
const LAMP_STOP_MARGIN_METERS = 0.12;
|
|
15
|
+
const WINDOW_STOP_MARGIN_METERS = 0.08;
|
|
16
|
+
const PARTITION_HALF_HEIGHT_METERS = 1.05;
|
|
17
|
+
const AO_MIN_FLOOR = 0.28;
|
|
18
|
+
|
|
19
|
+
// Cosine-weighted Fibonacci hemisphere samples in tangent space (+Y along vertex normal).
|
|
20
|
+
// Because elevation follows sqrt((i + 0.5) / N), every ray carries equal 1 / N Monte Carlo weight.
|
|
21
|
+
const HEMI_X = new Float32Array(AO_RAY_COUNT);
|
|
22
|
+
const HEMI_Y = new Float32Array(AO_RAY_COUNT);
|
|
23
|
+
const HEMI_Z = new Float32Array(AO_RAY_COUNT);
|
|
24
|
+
for (let i = 0; i < AO_RAY_COUNT; i++) {
|
|
25
|
+
const ny = Math.sqrt((i + 0.5) / AO_RAY_COUNT);
|
|
26
|
+
const radial = Math.sqrt(Math.max(0, 1 - ny * ny));
|
|
27
|
+
const phi = i * GOLDEN_ANGLE;
|
|
28
|
+
HEMI_X[i] = Math.cos(phi) * radial;
|
|
29
|
+
HEMI_Y[i] = ny;
|
|
30
|
+
HEMI_Z[i] = Math.sin(phi) * radial;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Stratified 5-point aperture quadrature in normalized window coordinates [-0.5, 0.5]^2.
|
|
34
|
+
const WIN_SAMPLE_U = new Float32Array([0, -0.32, 0.32, -0.32, 0.32]);
|
|
35
|
+
const WIN_SAMPLE_V = new Float32Array([0, -0.32, -0.32, 0.32, 0.32]);
|
|
36
|
+
const WIN_SAMPLE_W = new Float32Array([0.28, 0.18, 0.18, 0.18, 0.18]);
|
|
37
|
+
|
|
38
|
+
const OCC_STRIDE = 8; // cx, cy, cz, hx, hy, hz, cosY, sinY
|
|
39
|
+
const AABB_STRIDE = 6; // minX, maxX, minY, maxY, minZ, maxZ
|
|
40
|
+
|
|
41
|
+
// Module-level reusable buffers grown only when an interior exceeds prior occluder counts.
|
|
42
|
+
let scratchOcc = new Float32Array(64 * OCC_STRIDE);
|
|
43
|
+
let scratchAabb = new Float32Array(64 * AABB_STRIDE);
|
|
44
|
+
let scratchNearIdx = new Int32Array(64);
|
|
45
|
+
let scratchActiveIdx = new Int32Array(64);
|
|
46
|
+
let scratchPartitionIdx = new Int32Array(64);
|
|
47
|
+
|
|
48
|
+
function ensureScratchCapacity(boxCount) {
|
|
49
|
+
if (boxCount <= scratchNearIdx.length) return;
|
|
50
|
+
let cap = scratchNearIdx.length;
|
|
51
|
+
while (cap < boxCount) cap *= 2;
|
|
52
|
+
scratchOcc = new Float32Array(cap * OCC_STRIDE);
|
|
53
|
+
scratchAabb = new Float32Array(cap * AABB_STRIDE);
|
|
54
|
+
scratchNearIdx = new Int32Array(cap);
|
|
55
|
+
scratchActiveIdx = new Int32Array(cap);
|
|
56
|
+
scratchPartitionIdx = new Int32Array(cap);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function packOccluders(occluders) {
|
|
60
|
+
const count = occluders ? occluders.length : 0;
|
|
61
|
+
ensureScratchCapacity(count);
|
|
62
|
+
let valid = 0;
|
|
63
|
+
for (let i = 0; i < count; i++) {
|
|
64
|
+
const b = occluders[i];
|
|
65
|
+
const hx = b.hx ?? 0;
|
|
66
|
+
const hy = b.hy ?? 0;
|
|
67
|
+
const hz = b.hz ?? 0;
|
|
68
|
+
if (!(hx > 1e-4 && hy > 1e-4 && hz > 1e-4)) continue;
|
|
69
|
+
const ry = b.ry || 0;
|
|
70
|
+
const cosY = Math.cos(ry);
|
|
71
|
+
const sinY = Math.sin(ry);
|
|
72
|
+
const base = valid * OCC_STRIDE;
|
|
73
|
+
scratchOcc[base] = b.x;
|
|
74
|
+
scratchOcc[base + 1] = b.y;
|
|
75
|
+
scratchOcc[base + 2] = b.z;
|
|
76
|
+
scratchOcc[base + 3] = hx;
|
|
77
|
+
scratchOcc[base + 4] = hy;
|
|
78
|
+
scratchOcc[base + 5] = hz;
|
|
79
|
+
scratchOcc[base + 6] = cosY;
|
|
80
|
+
scratchOcc[base + 7] = sinY;
|
|
81
|
+
|
|
82
|
+
const worldHx = Math.abs(cosY) * hx + Math.abs(sinY) * hz;
|
|
83
|
+
const worldHz = Math.abs(sinY) * hx + Math.abs(cosY) * hz;
|
|
84
|
+
const ab = valid * AABB_STRIDE;
|
|
85
|
+
scratchAabb[ab] = b.x - worldHx;
|
|
86
|
+
scratchAabb[ab + 1] = b.x + worldHx;
|
|
87
|
+
scratchAabb[ab + 2] = b.y - hy;
|
|
88
|
+
scratchAabb[ab + 3] = b.y + hy;
|
|
89
|
+
scratchAabb[ab + 4] = b.z - worldHz;
|
|
90
|
+
scratchAabb[ab + 5] = b.z + worldHz;
|
|
91
|
+
valid++;
|
|
92
|
+
}
|
|
93
|
+
return valid;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Slab intersection distance along a unit/non-unit ray (ox, oy, oz) + t * (dx, dy, dz) against packed OBB `boxIndex`.
|
|
97
|
+
// Returns hit t in (0, maxT), or maxT when missed.
|
|
98
|
+
function intersectPackedBox(boxIndex, ox, oy, oz, dx, dy, dz, maxT) {
|
|
99
|
+
const base = boxIndex * OCC_STRIDE;
|
|
100
|
+
const rx = ox - scratchOcc[base];
|
|
101
|
+
const ry = oy - scratchOcc[base + 1];
|
|
102
|
+
const rz = oz - scratchOcc[base + 2];
|
|
103
|
+
const hx = scratchOcc[base + 3];
|
|
104
|
+
const hy = scratchOcc[base + 4];
|
|
105
|
+
const hz = scratchOcc[base + 5];
|
|
106
|
+
const cosY = scratchOcc[base + 6];
|
|
107
|
+
const sinY = scratchOcc[base + 7];
|
|
108
|
+
|
|
109
|
+
// Rotate ray into box-local frame (inverse of +ry yaw about +Y).
|
|
110
|
+
const lx = cosY * rx - sinY * rz;
|
|
111
|
+
const lz = sinY * rx + cosY * rz;
|
|
112
|
+
const ldx = cosY * dx - sinY * dz;
|
|
113
|
+
const ldz = sinY * dx + cosY * dz;
|
|
114
|
+
|
|
115
|
+
let tMin = 0;
|
|
116
|
+
let tMax = maxT;
|
|
117
|
+
|
|
118
|
+
if (Math.abs(ldx) < 1e-7) {
|
|
119
|
+
if (lx < -hx || lx > hx) return maxT;
|
|
120
|
+
} else {
|
|
121
|
+
const inv = 1 / ldx;
|
|
122
|
+
let t1 = (-hx - lx) * inv;
|
|
123
|
+
let t2 = (hx - lx) * inv;
|
|
124
|
+
if (t1 > t2) {
|
|
125
|
+
const tmp = t1;
|
|
126
|
+
t1 = t2;
|
|
127
|
+
t2 = tmp;
|
|
128
|
+
}
|
|
129
|
+
if (t1 > tMin) tMin = t1;
|
|
130
|
+
if (t2 < tMax) tMax = t2;
|
|
131
|
+
if (tMin >= tMax) return maxT;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (Math.abs(dy) < 1e-7) {
|
|
135
|
+
if (ry < -hy || ry > hy) return maxT;
|
|
136
|
+
} else {
|
|
137
|
+
const inv = 1 / dy;
|
|
138
|
+
let t1 = (-hy - ry) * inv;
|
|
139
|
+
let t2 = (hy - ry) * inv;
|
|
140
|
+
if (t1 > t2) {
|
|
141
|
+
const tmp = t1;
|
|
142
|
+
t1 = t2;
|
|
143
|
+
t2 = tmp;
|
|
144
|
+
}
|
|
145
|
+
if (t1 > tMin) tMin = t1;
|
|
146
|
+
if (t2 < tMax) tMax = t2;
|
|
147
|
+
if (tMin >= tMax) return maxT;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (Math.abs(ldz) < 1e-7) {
|
|
151
|
+
if (lz < -hz || lz > hz) return maxT;
|
|
152
|
+
} else {
|
|
153
|
+
const inv = 1 / ldz;
|
|
154
|
+
let t1 = (-hz - lz) * inv;
|
|
155
|
+
let t2 = (hz - lz) * inv;
|
|
156
|
+
if (t1 > t2) {
|
|
157
|
+
const tmp = t1;
|
|
158
|
+
t1 = t2;
|
|
159
|
+
t2 = tmp;
|
|
160
|
+
}
|
|
161
|
+
if (t1 > tMin) tMin = t1;
|
|
162
|
+
if (t2 < tMax) tMax = t2;
|
|
163
|
+
if (tMin >= tMax) return maxT;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return tMin > 0 ? tMin : tMax > 0 ? tMax : maxT;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Fast segment occlusion test from (ox, oy, oz) to (ox + dx * maxT, ...) against a filtered index list.
|
|
170
|
+
function isSegmentBlocked(indices, indexCount, ox, oy, oz, dx, dy, dz, maxT) {
|
|
171
|
+
if (maxT <= 1e-4 || indexCount === 0) return false;
|
|
172
|
+
const ex = ox + dx * maxT;
|
|
173
|
+
const ey = oy + dy * maxT;
|
|
174
|
+
const ez = oz + dz * maxT;
|
|
175
|
+
const segMinX = ox < ex ? ox : ex;
|
|
176
|
+
const segMaxX = ox > ex ? ox : ex;
|
|
177
|
+
const segMinY = oy < ey ? oy : ey;
|
|
178
|
+
const segMaxY = oy > ey ? oy : ey;
|
|
179
|
+
const segMinZ = oz < ez ? oz : ez;
|
|
180
|
+
const segMaxZ = oz > ez ? oz : ez;
|
|
181
|
+
|
|
182
|
+
for (let i = 0; i < indexCount; i++) {
|
|
183
|
+
const idx = indices[i];
|
|
184
|
+
const ab = idx * AABB_STRIDE;
|
|
185
|
+
if (
|
|
186
|
+
segMaxX < scratchAabb[ab] ||
|
|
187
|
+
segMinX > scratchAabb[ab + 1] ||
|
|
188
|
+
segMaxY < scratchAabb[ab + 2] ||
|
|
189
|
+
segMinY > scratchAabb[ab + 3] ||
|
|
190
|
+
segMaxZ < scratchAabb[ab + 4] ||
|
|
191
|
+
segMinZ > scratchAabb[ab + 5]
|
|
192
|
+
) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (intersectPackedBox(idx, ox, oy, oz, dx, dy, dz, maxT) < maxT) return true;
|
|
196
|
+
}
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function pointInsidePackedBox(boxIndex, px, py, pz) {
|
|
201
|
+
const base = boxIndex * OCC_STRIDE;
|
|
202
|
+
const hy = scratchOcc[base + 4] - 0.004;
|
|
203
|
+
const ry = py - scratchOcc[base + 1];
|
|
204
|
+
if (ry < -hy || ry > hy) return false;
|
|
205
|
+
const rx = px - scratchOcc[base];
|
|
206
|
+
const rz = pz - scratchOcc[base + 2];
|
|
207
|
+
const hx = scratchOcc[base + 3] - 0.004;
|
|
208
|
+
const hz = scratchOcc[base + 5] - 0.004;
|
|
209
|
+
const cosY = scratchOcc[base + 6];
|
|
210
|
+
const sinY = scratchOcc[base + 7];
|
|
211
|
+
const lx = cosY * rx - sinY * rz;
|
|
212
|
+
const lz = sinY * rx + cosY * rz;
|
|
213
|
+
return lx > -hx && lx < hx && lz > -hz && lz < hz;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Create uniform wrappers shared by materials patched with {@link patchInteriorMaterial}.
|
|
218
|
+
*
|
|
219
|
+
* @param {object} [options]
|
|
220
|
+
* @param {THREE.Color} [options.windowSky] Sky irradiance tint entering window apertures.
|
|
221
|
+
* @param {THREE.Color} [options.windowSun] Warm bounce tint entering sun-facing windows.
|
|
222
|
+
* @param {number} [options.lampGlow] Multiplier on baked lamp and hearth irradiance.
|
|
223
|
+
* @param {THREE.Color} [options.shadowLift] Subtle ambient floor keeping deep stone/timber shadows readable.
|
|
224
|
+
* @param {THREE.Vector3} [options.sunDir] Unit direction toward the sun in world coordinates.
|
|
225
|
+
* @param {number} [options.sunBend] Fraction [0..1] by which level floors/tables bend toward low sun for direct light.
|
|
226
|
+
*/
|
|
227
|
+
export function createInteriorLightUniforms({
|
|
228
|
+
windowSky = new THREE.Color(0.55, 0.66, 0.82),
|
|
229
|
+
windowSun = new THREE.Color(0.32, 0.24, 0.14),
|
|
230
|
+
lampGlow = 1,
|
|
231
|
+
shadowLift = new THREE.Color(0.035, 0.036, 0.042),
|
|
232
|
+
sunDir = new THREE.Vector3(0.4, 0.6, 0.3).normalize(),
|
|
233
|
+
sunBend = 0.38,
|
|
234
|
+
} = {}) {
|
|
235
|
+
return {
|
|
236
|
+
uWindowSky: { value: windowSky.clone() },
|
|
237
|
+
uWindowSun: { value: windowSun.clone() },
|
|
238
|
+
uLampGlow: { value: lampGlow },
|
|
239
|
+
uShadowLift: { value: shadowLift.clone() },
|
|
240
|
+
uSunDir: { value: sunDir.clone() },
|
|
241
|
+
uSunBend: { value: sunBend },
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Bake per-vertex interior ambient occlusion, cosine-weighted per-side window sky light, and
|
|
247
|
+
* box-occluded RGB lamp/hearth irradiance onto a `BufferGeometry` or `{ position, normal }` buffer set.
|
|
248
|
+
* Writes `aInteriorSky` (`vec4`: `ao`, `windowLight`, `winDirX`, `winDirZ`) and `aInteriorLamp` (`vec3`: RGB).
|
|
249
|
+
*
|
|
250
|
+
* @param {THREE.BufferGeometry | { position: Float32Array, normal: Float32Array | Int8Array, aInteriorSky?: Float32Array, aInteriorLamp?: Float32Array }} target
|
|
251
|
+
* @param {object} [options]
|
|
252
|
+
* @param {{ x0: number, x1: number, y0: number, y1: number, z0: number, z1: number } | null} [options.bounds] Room interior AABB in world units.
|
|
253
|
+
* @param {Array<{ x: number, y: number, z: number, hx: number, hy: number, hz: number, ry?: number }>} [options.occluders] Oriented box occluders centred at `(x, y, z)`.
|
|
254
|
+
* @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 unit normal `(nx, ny, nz)`.
|
|
255
|
+
* @param {Array<{ x: number, y: number, z: number, r?: number, g?: number, b?: number, power?: number, range?: number }>} [options.lamps] Point/hearth light emitters.
|
|
256
|
+
* @param {number} [options.aoRadius] Maximum corner occlusion ray reach in world units.
|
|
257
|
+
* @param {number} [options.aoStrength] Corner occlusion strength in [0..1].
|
|
258
|
+
* @param {number} [options.aoMin] Minimum ambient occlusion floor in [0.05..1].
|
|
259
|
+
* @param {number} [options.windowBounce] Single-bounce diffuse daylight fill weight inside the room.
|
|
260
|
+
* @param {number} [options.lampBounce] Single-bounce diffuse lamp/hearth fill weight inside each emitter's range.
|
|
261
|
+
* @param {boolean} [options.releaseOnUpload] Release CPU typed arrays once Three.js uploads the attributes to the GPU.
|
|
262
|
+
*/
|
|
263
|
+
export function bakeInteriorLight(
|
|
264
|
+
target,
|
|
265
|
+
{
|
|
266
|
+
bounds = null,
|
|
267
|
+
occluders = [],
|
|
268
|
+
windows = [],
|
|
269
|
+
lamps = [],
|
|
270
|
+
aoRadius = 1.7,
|
|
271
|
+
aoStrength = 0.66,
|
|
272
|
+
aoMin = AO_MIN_FLOOR,
|
|
273
|
+
windowBounce = 0.18,
|
|
274
|
+
lampBounce = 0.15,
|
|
275
|
+
releaseOnUpload = false,
|
|
276
|
+
} = {},
|
|
277
|
+
) {
|
|
278
|
+
const isGeometry = Boolean(target && target.isBufferGeometry);
|
|
279
|
+
const posAttr = isGeometry ? target.getAttribute('position') : null;
|
|
280
|
+
const normAttr = isGeometry ? target.getAttribute('normal') : null;
|
|
281
|
+
const posArray = isGeometry ? posAttr?.array : target?.position;
|
|
282
|
+
const normArray = isGeometry ? normAttr?.array : target?.normal;
|
|
283
|
+
if (!posArray || !normArray) {
|
|
284
|
+
throw new TypeError('bakeInteriorLight requires position and normal vertex buffers');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const posStride = isGeometry ? posAttr.itemSize : 3;
|
|
288
|
+
const normStride = isGeometry ? normAttr.itemSize : Math.max(3, Math.round(normArray.length / (posArray.length / 3)) || 3);
|
|
289
|
+
const vertexCount = isGeometry ? posAttr.count : Math.floor(posArray.length / posStride);
|
|
290
|
+
const normScale = normArray instanceof Int8Array ? 1 / 127 : 1;
|
|
291
|
+
|
|
292
|
+
const sky = new Float32Array(vertexCount * 4);
|
|
293
|
+
const lamp = new Float32Array(vertexCount * 3);
|
|
294
|
+
if (vertexCount === 0) {
|
|
295
|
+
if (isGeometry) {
|
|
296
|
+
target.setAttribute('aInteriorSky', new THREE.BufferAttribute(sky, 4));
|
|
297
|
+
target.setAttribute('aInteriorLamp', new THREE.BufferAttribute(lamp, 3));
|
|
298
|
+
} else {
|
|
299
|
+
target.aInteriorSky = sky;
|
|
300
|
+
target.aInteriorLamp = lamp;
|
|
301
|
+
}
|
|
302
|
+
return { sky, lamp };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const boxCount = packOccluders(occluders);
|
|
306
|
+
const clampedAoMin = Math.max(0.05, Math.min(1, aoMin));
|
|
307
|
+
const invAoRadius = aoRadius > 1e-4 ? 1 / aoRadius : 0;
|
|
308
|
+
|
|
309
|
+
// Precompute window tangent axes and areas once per room.
|
|
310
|
+
const winCount = windows ? windows.length : 0;
|
|
311
|
+
const winData = new Float32Array(winCount * 15);
|
|
312
|
+
for (let w = 0; w < winCount; w++) {
|
|
313
|
+
const win = windows[w];
|
|
314
|
+
let wnx = win.nx ?? 0;
|
|
315
|
+
let wny = win.ny ?? 0;
|
|
316
|
+
let wnz = win.nz ?? 0;
|
|
317
|
+
const nLen = Math.hypot(wnx, wny, wnz) || 1;
|
|
318
|
+
wnx /= nLen;
|
|
319
|
+
wny /= nLen;
|
|
320
|
+
wnz /= nLen;
|
|
321
|
+
|
|
322
|
+
// Horizontal tangent U and vertical/in-plane tangent V across the window opening.
|
|
323
|
+
let ux;
|
|
324
|
+
let uy;
|
|
325
|
+
let uz;
|
|
326
|
+
if (Math.abs(wny) < 0.85) {
|
|
327
|
+
const hLen = Math.hypot(wnx, wnz) || 1;
|
|
328
|
+
ux = -wnz / hLen;
|
|
329
|
+
uy = 0;
|
|
330
|
+
uz = wnx / hLen;
|
|
331
|
+
} else {
|
|
332
|
+
ux = 1;
|
|
333
|
+
uy = 0;
|
|
334
|
+
uz = 0;
|
|
335
|
+
}
|
|
336
|
+
const vx = wny * uz - wnz * uy;
|
|
337
|
+
const vy = wnz * ux - wnx * uz;
|
|
338
|
+
const vz = wnx * uy - wny * ux;
|
|
339
|
+
|
|
340
|
+
const width = Math.max(0.05, win.w ?? 1);
|
|
341
|
+
const height = Math.max(0.05, win.h ?? 1);
|
|
342
|
+
const base = w * 15;
|
|
343
|
+
winData[base] = win.x;
|
|
344
|
+
winData[base + 1] = win.y;
|
|
345
|
+
winData[base + 2] = win.z;
|
|
346
|
+
winData[base + 3] = wnx;
|
|
347
|
+
winData[base + 4] = wny;
|
|
348
|
+
winData[base + 5] = wnz;
|
|
349
|
+
winData[base + 6] = ux * width;
|
|
350
|
+
winData[base + 7] = uy * width;
|
|
351
|
+
winData[base + 8] = uz * width;
|
|
352
|
+
winData[base + 9] = vx * height;
|
|
353
|
+
winData[base + 10] = vy * height;
|
|
354
|
+
winData[base + 11] = vz * height;
|
|
355
|
+
winData[base + 12] = width * height;
|
|
356
|
+
winData[base + 13] = win.weight ?? 1;
|
|
357
|
+
// Virtual floor/opposite-wall bounce patch 2.1 m inside the room from the opening.
|
|
358
|
+
winData[base + 14] = bounds ? Math.max(bounds.y0 + 0.25, win.y - 0.55) : win.y - 0.55;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const lampCount = lamps ? lamps.length : 0;
|
|
362
|
+
const lampData = new Float32Array(lampCount * 8);
|
|
363
|
+
for (let l = 0; l < lampCount; l++) {
|
|
364
|
+
const src = lamps[l];
|
|
365
|
+
const power = src.power ?? 1;
|
|
366
|
+
const range = Math.max(0.5, src.range ?? 6);
|
|
367
|
+
const base = l * 8;
|
|
368
|
+
lampData[base] = src.x;
|
|
369
|
+
lampData[base + 1] = src.y;
|
|
370
|
+
lampData[base + 2] = src.z;
|
|
371
|
+
lampData[base + 3] = src.r ?? 1;
|
|
372
|
+
lampData[base + 4] = src.g ?? 0.66;
|
|
373
|
+
lampData[base + 5] = src.b ?? 0.32;
|
|
374
|
+
lampData[base + 6] = power;
|
|
375
|
+
lampData[base + 7] = range;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const hasBounds = Boolean(bounds && bounds.x1 > bounds.x0 && bounds.y1 > bounds.y0 && bounds.z1 > bounds.z0);
|
|
379
|
+
const bx0 = hasBounds ? bounds.x0 : 0;
|
|
380
|
+
const bx1 = hasBounds ? bounds.x1 : 0;
|
|
381
|
+
const by0 = hasBounds ? bounds.y0 : 0;
|
|
382
|
+
const by1 = hasBounds ? bounds.y1 : 0;
|
|
383
|
+
const bz0 = hasBounds ? bounds.z0 : 0;
|
|
384
|
+
const bz1 = hasBounds ? bounds.z1 : 0;
|
|
385
|
+
|
|
386
|
+
for (let v = 0; v < vertexCount; v++) {
|
|
387
|
+
const pi = v * posStride;
|
|
388
|
+
const ni = v * normStride;
|
|
389
|
+
const px = posArray[pi];
|
|
390
|
+
const py = posArray[pi + 1];
|
|
391
|
+
const pz = posArray[pi + 2];
|
|
392
|
+
|
|
393
|
+
let nx = normArray[ni] * normScale;
|
|
394
|
+
let ny = normArray[ni + 1] * normScale;
|
|
395
|
+
let nz = normArray[ni + 2] * normScale;
|
|
396
|
+
const nLen = Math.hypot(nx, ny, nz);
|
|
397
|
+
if (nLen > 1e-6) {
|
|
398
|
+
const invN = 1 / nLen;
|
|
399
|
+
nx *= invN;
|
|
400
|
+
ny *= invN;
|
|
401
|
+
nz *= invN;
|
|
402
|
+
} else {
|
|
403
|
+
nx = 0;
|
|
404
|
+
ny = 1;
|
|
405
|
+
nz = 0;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const ox = px + nx * NORMAL_BIAS_METERS;
|
|
409
|
+
const oy = py + ny * NORMAL_BIAS_METERS;
|
|
410
|
+
const oz = pz + nz * NORMAL_BIAS_METERS;
|
|
411
|
+
|
|
412
|
+
// Filter occluders once for this vertex: skip any box containing (ox, oy, oz) to prevent self-occlusion.
|
|
413
|
+
let nearCount = 0;
|
|
414
|
+
let activeCount = 0;
|
|
415
|
+
let partitionCount = 0;
|
|
416
|
+
for (let b = 0; b < boxCount; b++) {
|
|
417
|
+
const ab = b * AABB_STRIDE;
|
|
418
|
+
const inAabb =
|
|
419
|
+
ox > scratchAabb[ab] &&
|
|
420
|
+
ox < scratchAabb[ab + 1] &&
|
|
421
|
+
oy > scratchAabb[ab + 2] &&
|
|
422
|
+
oy < scratchAabb[ab + 3] &&
|
|
423
|
+
oz > scratchAabb[ab + 4] &&
|
|
424
|
+
oz < scratchAabb[ab + 5];
|
|
425
|
+
if (inAabb && pointInsidePackedBox(b, ox, oy, oz)) continue;
|
|
426
|
+
|
|
427
|
+
scratchActiveIdx[activeCount++] = b;
|
|
428
|
+
if (scratchOcc[b * OCC_STRIDE + 4] >= PARTITION_HALF_HEIGHT_METERS) {
|
|
429
|
+
scratchPartitionIdx[partitionCount++] = b;
|
|
430
|
+
}
|
|
431
|
+
if (
|
|
432
|
+
aoRadius > 0 &&
|
|
433
|
+
ox + aoRadius >= scratchAabb[ab] &&
|
|
434
|
+
ox - aoRadius <= scratchAabb[ab + 1] &&
|
|
435
|
+
oy + aoRadius >= scratchAabb[ab + 2] &&
|
|
436
|
+
oy - aoRadius <= scratchAabb[ab + 3] &&
|
|
437
|
+
oz + aoRadius >= scratchAabb[ab + 4] &&
|
|
438
|
+
oz - aoRadius <= scratchAabb[ab + 5]
|
|
439
|
+
) {
|
|
440
|
+
scratchNearIdx[nearCount++] = b;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// Orthonormal tangent basis (T, B, N) using Duff's branch-safe construction.
|
|
445
|
+
const signZ = nz >= 0 ? 1 : -1;
|
|
446
|
+
const a = -1 / (signZ + nz);
|
|
447
|
+
const bTerm = nx * ny * a;
|
|
448
|
+
const tx = 1 + signZ * nx * nx * a;
|
|
449
|
+
const ty = signZ * bTerm;
|
|
450
|
+
const tz = -signZ * nx;
|
|
451
|
+
const bx = bTerm;
|
|
452
|
+
const by = signZ + ny * ny * a;
|
|
453
|
+
const bz = -ny;
|
|
454
|
+
|
|
455
|
+
// 1. Corner & furniture ambient occlusion.
|
|
456
|
+
let ao = 1;
|
|
457
|
+
if (aoRadius > 0 && aoStrength > 0) {
|
|
458
|
+
const inShell =
|
|
459
|
+
hasBounds && ox >= bx0 - 0.08 && ox <= bx1 + 0.08 && oy >= by0 - 0.08 && oy <= by1 + 0.08 && oz >= bz0 - 0.08 && oz <= bz1 + 0.08;
|
|
460
|
+
let occSum = 0;
|
|
461
|
+
if (inShell || nearCount > 0) {
|
|
462
|
+
for (let s = 0; s < AO_RAY_COUNT; s++) {
|
|
463
|
+
const hx = HEMI_X[s];
|
|
464
|
+
const hy = HEMI_Y[s];
|
|
465
|
+
const hz = HEMI_Z[s];
|
|
466
|
+
const dx = hx * tx + hy * nx + hz * bx;
|
|
467
|
+
const dy = hx * ty + hy * ny + hz * by;
|
|
468
|
+
const dz = hx * tz + hy * nz + hz * bz;
|
|
469
|
+
let nearest = aoRadius;
|
|
470
|
+
|
|
471
|
+
if (inShell) {
|
|
472
|
+
if (dx > 1e-5 && ox < bx1) {
|
|
473
|
+
const t = (bx1 - ox) / dx;
|
|
474
|
+
if (t > 0.02 && t < nearest) nearest = t;
|
|
475
|
+
} else if (dx < -1e-5 && ox > bx0) {
|
|
476
|
+
const t = (bx0 - ox) / dx;
|
|
477
|
+
if (t > 0.02 && t < nearest) nearest = t;
|
|
478
|
+
}
|
|
479
|
+
if (dy > 1e-5 && oy < by1) {
|
|
480
|
+
const t = (by1 - oy) / dy;
|
|
481
|
+
if (t > 0.02 && t < nearest) nearest = t;
|
|
482
|
+
} else if (dy < -1e-5 && oy > by0) {
|
|
483
|
+
const t = (by0 - oy) / dy;
|
|
484
|
+
if (t > 0.02 && t < nearest) nearest = t;
|
|
485
|
+
}
|
|
486
|
+
if (dz > 1e-5 && oz < bz1) {
|
|
487
|
+
const t = (bz1 - oz) / dz;
|
|
488
|
+
if (t > 0.02 && t < nearest) nearest = t;
|
|
489
|
+
} else if (dz < -1e-5 && oz > bz0) {
|
|
490
|
+
const t = (bz0 - oz) / dz;
|
|
491
|
+
if (t > 0.02 && t < nearest) nearest = t;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
for (let j = 0; j < nearCount; j++) {
|
|
496
|
+
const t = intersectPackedBox(scratchNearIdx[j], ox, oy, oz, dx, dy, dz, nearest);
|
|
497
|
+
if (t < nearest) nearest = t;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
if (nearest < aoRadius) {
|
|
501
|
+
const u = nearest * invAoRadius;
|
|
502
|
+
occSum += 1 - u * u;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
ao = Math.max(clampedAoMin, 1 - (occSum / AO_RAY_COUNT) * aoStrength);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// 2. Cosine-weighted window sky light + single-bounce daylight fill + weighted compass side.
|
|
510
|
+
let winIrradiance = 0;
|
|
511
|
+
let sideSumX = 0;
|
|
512
|
+
let sideSumZ = 0;
|
|
513
|
+
let sideWeightSum = 0;
|
|
514
|
+
for (let w = 0; w < winCount; w++) {
|
|
515
|
+
const wb = w * 15;
|
|
516
|
+
const wx = winData[wb];
|
|
517
|
+
const wy = winData[wb + 1];
|
|
518
|
+
const wz = winData[wb + 2];
|
|
519
|
+
const wnx = winData[wb + 3];
|
|
520
|
+
const wny = winData[wb + 4];
|
|
521
|
+
const wnz = winData[wb + 5];
|
|
522
|
+
const area = winData[wb + 12];
|
|
523
|
+
const wWeight = winData[wb + 13];
|
|
524
|
+
|
|
525
|
+
const toCenterX = wx - ox;
|
|
526
|
+
const toCenterY = wy - oy;
|
|
527
|
+
const toCenterZ = wz - oz;
|
|
528
|
+
// Signed distance inward from the window plane.
|
|
529
|
+
const inwardDepth = -(toCenterX * wnx + toCenterY * wny + toCenterZ * wnz);
|
|
530
|
+
if (inwardDepth < -0.25) continue;
|
|
531
|
+
|
|
532
|
+
const centerDistSq = toCenterX * toCenterX + toCenterY * toCenterY + toCenterZ * toCenterZ;
|
|
533
|
+
const multiSample = area > 0.32 && centerDistSq < area * 22;
|
|
534
|
+
const sampleCount = multiSample ? 5 : 1;
|
|
535
|
+
|
|
536
|
+
let directWin = 0;
|
|
537
|
+
for (let s = 0; s < sampleCount; s++) {
|
|
538
|
+
const su = multiSample ? WIN_SAMPLE_U[s] : 0;
|
|
539
|
+
const sv = multiSample ? WIN_SAMPLE_V[s] : 0;
|
|
540
|
+
const sw = multiSample ? WIN_SAMPLE_W[s] : 1;
|
|
541
|
+
const sx = wx + winData[wb + 6] * su + winData[wb + 9] * sv - ox;
|
|
542
|
+
const sy = wy + winData[wb + 7] * su + winData[wb + 10] * sv - oy;
|
|
543
|
+
const sz = wz + winData[wb + 8] * su + winData[wb + 11] * sv - oz;
|
|
544
|
+
const dSq = sx * sx + sy * sy + sz * sz;
|
|
545
|
+
if (dSq < 1e-5) continue;
|
|
546
|
+
const dist = Math.sqrt(dSq);
|
|
547
|
+
const invD = 1 / dist;
|
|
548
|
+
const dx = sx * invD;
|
|
549
|
+
const dy = sy * invD;
|
|
550
|
+
const dz = sz * invD;
|
|
551
|
+
|
|
552
|
+
const cosSurf = dx * nx + dy * ny + dz * nz;
|
|
553
|
+
const cosWin = -(dx * wnx + dy * wny + dz * wnz);
|
|
554
|
+
if (cosSurf <= 0.001 || cosWin <= 0.02) continue;
|
|
555
|
+
|
|
556
|
+
const maxT = dist - WINDOW_STOP_MARGIN_METERS;
|
|
557
|
+
if (maxT > 0.04 && isSegmentBlocked(scratchActiveIdx, activeCount, ox, oy, oz, dx, dy, dz, maxT)) {
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
const solidAngle = Math.min(2.1, (area * cosWin) / (dSq + 0.35 * area));
|
|
561
|
+
directWin += sw * cosSurf * solidAngle;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// Single-bounce room daylight reflected from the lit floor/interior patch in front of the opening.
|
|
565
|
+
let bounceWin = 0;
|
|
566
|
+
if (windowBounce > 0) {
|
|
567
|
+
const vbx = wx + wnx * 2.1 - ox;
|
|
568
|
+
const vby = winData[wb + 14] - oy;
|
|
569
|
+
const vbz = wz + wnz * 2.1 - oz;
|
|
570
|
+
const bDistSq = vbx * vbx + vby * vby + vbz * vbz;
|
|
571
|
+
const bDist = Math.sqrt(bDistSq) + 1e-5;
|
|
572
|
+
// Partition walls block indirect room bounce unless the doorway between rooms is clear.
|
|
573
|
+
const blockedByWall = isSegmentBlocked(
|
|
574
|
+
scratchPartitionIdx,
|
|
575
|
+
partitionCount,
|
|
576
|
+
ox,
|
|
577
|
+
oy,
|
|
578
|
+
oz,
|
|
579
|
+
vbx / bDist,
|
|
580
|
+
vby / bDist,
|
|
581
|
+
vbz / bDist,
|
|
582
|
+
bDist - 0.15,
|
|
583
|
+
);
|
|
584
|
+
if (!blockedByWall) {
|
|
585
|
+
const cosBounce = 0.45 + 0.55 * Math.max(0, (vbx * nx + vby * ny + vbz * nz) / bDist);
|
|
586
|
+
bounceWin = windowBounce * (area / (3.8 + bDistSq * 0.32)) * cosBounce * ao;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const contrib = (directWin + bounceWin) * wWeight;
|
|
591
|
+
if (contrib > 0) {
|
|
592
|
+
winIrradiance += contrib;
|
|
593
|
+
const sideW = directWin * wWeight + bounceWin * wWeight * 0.5;
|
|
594
|
+
sideSumX += sideW * wnx;
|
|
595
|
+
sideSumZ += sideW * wnz;
|
|
596
|
+
sideWeightSum += sideW;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// Softly compress very close window-reveal peaks while preserving smooth falloff across the room.
|
|
601
|
+
const compressedWin = winIrradiance / (1 + 0.28 * winIrradiance);
|
|
602
|
+
const invSide = sideWeightSum > 1e-5 ? 1 / sideWeightSum : 0;
|
|
603
|
+
const si = v * 4;
|
|
604
|
+
sky[si] = ao;
|
|
605
|
+
sky[si + 1] = compressedWin;
|
|
606
|
+
sky[si + 2] = Math.max(-1, Math.min(1, sideSumX * invSide));
|
|
607
|
+
sky[si + 3] = Math.max(-1, Math.min(1, sideSumZ * invSide));
|
|
608
|
+
|
|
609
|
+
// 3. Box-occluded RGB lamp & hearth light + partition-gated room bounce.
|
|
610
|
+
let lr = 0;
|
|
611
|
+
let lg = 0;
|
|
612
|
+
let lb = 0;
|
|
613
|
+
for (let l = 0; l < lampCount; l++) {
|
|
614
|
+
const lBase = l * 8;
|
|
615
|
+
const lx = lampData[lBase] - ox;
|
|
616
|
+
const ly = lampData[lBase + 1] - oy;
|
|
617
|
+
const lz = lampData[lBase + 2] - oz;
|
|
618
|
+
const range = lampData[lBase + 7];
|
|
619
|
+
const dSq = lx * lx + ly * ly + lz * lz;
|
|
620
|
+
if (dSq >= range * range) continue;
|
|
621
|
+
|
|
622
|
+
const dist = Math.sqrt(dSq);
|
|
623
|
+
const invD = 1 / (dist + 1e-6);
|
|
624
|
+
const dx = lx * invD;
|
|
625
|
+
const dy = ly * invD;
|
|
626
|
+
const dz = lz * invD;
|
|
627
|
+
|
|
628
|
+
const q = dist / range;
|
|
629
|
+
const rangeFall = (1 - q * q) * (1 - q * q);
|
|
630
|
+
const atten = (lampData[lBase + 6] * rangeFall) / (0.38 + dSq * 0.55);
|
|
631
|
+
if (atten <= 1e-4) continue;
|
|
632
|
+
|
|
633
|
+
const cosL = dx * nx + dy * ny + dz * nz;
|
|
634
|
+
let directL = 0;
|
|
635
|
+
if (cosL > -0.14) {
|
|
636
|
+
const maxT = dist - LAMP_STOP_MARGIN_METERS;
|
|
637
|
+
if (!(maxT > 0.04 && isSegmentBlocked(scratchActiveIdx, activeCount, ox, oy, oz, dx, dy, dz, maxT))) {
|
|
638
|
+
directL = ((cosL + 0.14) / 1.14) * atten;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
let bounceL = 0;
|
|
643
|
+
if (lampBounce > 0) {
|
|
644
|
+
const maxT = dist - LAMP_STOP_MARGIN_METERS;
|
|
645
|
+
const wallBlocked = maxT > 0.1 && isSegmentBlocked(scratchPartitionIdx, partitionCount, ox, oy, oz, dx, dy, dz, maxT);
|
|
646
|
+
if (!wallBlocked) {
|
|
647
|
+
bounceL = lampBounce * atten * ao * (0.52 + 0.48 * Math.max(0, cosL));
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
const totalL = directL + bounceL;
|
|
652
|
+
if (totalL > 0) {
|
|
653
|
+
lr += totalL * lampData[lBase + 3];
|
|
654
|
+
lg += totalL * lampData[lBase + 4];
|
|
655
|
+
lb += totalL * lampData[lBase + 5];
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const li = v * 3;
|
|
660
|
+
lamp[li] = lr;
|
|
661
|
+
lamp[li + 1] = lg;
|
|
662
|
+
lamp[li + 2] = lb;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
if (isGeometry) {
|
|
666
|
+
const skyAttr = new THREE.BufferAttribute(sky, 4);
|
|
667
|
+
const lampAttr = new THREE.BufferAttribute(lamp, 3);
|
|
668
|
+
if (releaseOnUpload) {
|
|
669
|
+
skyAttr.onUpload(releaseArray);
|
|
670
|
+
lampAttr.onUpload(releaseArray);
|
|
671
|
+
}
|
|
672
|
+
target.setAttribute('aInteriorSky', skyAttr);
|
|
673
|
+
target.setAttribute('aInteriorLamp', lampAttr);
|
|
674
|
+
} else {
|
|
675
|
+
target.aInteriorSky = sky;
|
|
676
|
+
target.aInteriorLamp = lamp;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
return { sky, lamp };
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function expandDirectionalSunBendChunk() {
|
|
683
|
+
const chunk = THREE.ShaderChunk.lights_fragment_begin;
|
|
684
|
+
const dirMarker = '#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )';
|
|
685
|
+
const dirStart = chunk.indexOf(dirMarker);
|
|
686
|
+
if (dirStart < 0) return chunk;
|
|
687
|
+
const dirEnd = chunk.indexOf('#endif', chunk.indexOf('#pragma unroll_loop_end', dirStart));
|
|
688
|
+
if (dirEnd < 0) return chunk;
|
|
689
|
+
|
|
690
|
+
const dirSection = chunk.slice(dirStart, dirEnd);
|
|
691
|
+
const targetCall =
|
|
692
|
+
'RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );';
|
|
693
|
+
if (!dirSection.includes(targetCall)) return chunk;
|
|
694
|
+
|
|
695
|
+
const bentSetup = /* glsl */ `
|
|
696
|
+
vec3 interiorWorldN = inverseTransformDirection( geometryNormal, viewMatrix );
|
|
697
|
+
float interiorLevelBend = smoothstep( 0.75, 0.92, interiorWorldN.y ) * clamp( uSunBend, 0.0, 0.85 ) * step( 0.005, uSunDir.y );
|
|
698
|
+
vec3 interiorSunTarget = normalize( vec3( uSunDir.x, max( uSunDir.y, 0.36 ), uSunDir.z ) + vec3( 0.0, 1e-5, 0.0 ) );
|
|
699
|
+
vec3 interiorDirectNormal = interiorLevelBend > 0.001
|
|
700
|
+
? transformDirection( normalize( mix( interiorWorldN, interiorSunTarget, interiorLevelBend ) ), viewMatrix )
|
|
701
|
+
: geometryNormal;`;
|
|
702
|
+
|
|
703
|
+
const patchedDirSection = dirSection
|
|
704
|
+
.replace(dirMarker, dirMarker + '\n' + bentSetup)
|
|
705
|
+
.replace(
|
|
706
|
+
targetCall,
|
|
707
|
+
'RE_Direct( directLight, geometryPosition, interiorDirectNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );',
|
|
708
|
+
);
|
|
709
|
+
return chunk.slice(0, dirStart) + patchedDirSection + chunk.slice(dirEnd);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
let cachedBentLightsBegin = null;
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* Patch a `MeshStandardMaterial` (or clone it first when `options.clone` is true) so shaders combine
|
|
716
|
+
* CPU-baked corner AO, compass-weighted window sky/sun bounce, box-occluded lamp/hearth glow,
|
|
717
|
+
* a subtle unlit shadow lift, and a level-surface (`N.y > 0.75`) direct-sun normal bend.
|
|
718
|
+
*
|
|
719
|
+
* @param {THREE.MeshStandardMaterial} material
|
|
720
|
+
* @param {ReturnType<typeof createInteriorLightUniforms>} uniforms
|
|
721
|
+
* @param {object} [options]
|
|
722
|
+
* @param {boolean} [options.clone] Clone `material` before attaching the interior shader hook so shared outdoor materials stay untouched.
|
|
723
|
+
* @param {string} [options.cacheKey] Optional suffix distinguishing shader variants.
|
|
724
|
+
*/
|
|
725
|
+
export function patchInteriorMaterial(material, uniforms, { clone = false, cacheKey = 'interior-bake' } = {}) {
|
|
726
|
+
// The material's own hook and cache key, taken as they are now, the key bound to the material. A material patched in place
|
|
727
|
+
// (no clone) has both replaced on it below: read through the material's property after that, the new key would call itself
|
|
728
|
+
// and never return.
|
|
729
|
+
const baseOnBeforeCompile = material.onBeforeCompile;
|
|
730
|
+
const baseCacheKey = material.customProgramCacheKey ? material.customProgramCacheKey.bind(material) : () => 'meshstandard';
|
|
731
|
+
|
|
732
|
+
const target = clone ? material.clone() : material;
|
|
733
|
+
cachedBentLightsBegin ??= expandDirectionalSunBendChunk();
|
|
734
|
+
|
|
735
|
+
target.onBeforeCompile = (shader, renderer) => {
|
|
736
|
+
if (baseOnBeforeCompile) baseOnBeforeCompile.call(target, shader, renderer);
|
|
737
|
+
shader.uniforms.uWindowSky = uniforms.uWindowSky;
|
|
738
|
+
shader.uniforms.uWindowSun = uniforms.uWindowSun;
|
|
739
|
+
shader.uniforms.uLampGlow = uniforms.uLampGlow;
|
|
740
|
+
shader.uniforms.uShadowLift = uniforms.uShadowLift;
|
|
741
|
+
shader.uniforms.uSunDir = uniforms.uSunDir;
|
|
742
|
+
shader.uniforms.uSunBend = uniforms.uSunBend;
|
|
743
|
+
|
|
744
|
+
shader.vertexShader = shader.vertexShader
|
|
745
|
+
.replace(
|
|
746
|
+
'#include <common>',
|
|
747
|
+
/* glsl */ `#include <common>
|
|
748
|
+
attribute vec4 aInteriorSky;
|
|
749
|
+
attribute vec3 aInteriorLamp;
|
|
750
|
+
varying vec4 vInteriorSky;
|
|
751
|
+
varying vec3 vInteriorLamp;`,
|
|
752
|
+
)
|
|
753
|
+
.replace(
|
|
754
|
+
'#include <begin_vertex>',
|
|
755
|
+
/* glsl */ `#include <begin_vertex>
|
|
756
|
+
vInteriorSky = aInteriorSky;
|
|
757
|
+
vInteriorLamp = aInteriorLamp;`,
|
|
758
|
+
);
|
|
759
|
+
|
|
760
|
+
shader.fragmentShader = shader.fragmentShader
|
|
761
|
+
.replace(
|
|
762
|
+
'#include <common>',
|
|
763
|
+
/* glsl */ `#include <common>
|
|
764
|
+
uniform vec3 uWindowSky;
|
|
765
|
+
uniform vec3 uWindowSun;
|
|
766
|
+
uniform float uLampGlow;
|
|
767
|
+
uniform vec3 uShadowLift;
|
|
768
|
+
uniform vec3 uSunDir;
|
|
769
|
+
uniform float uSunBend;
|
|
770
|
+
varying vec4 vInteriorSky;
|
|
771
|
+
varying vec3 vInteriorLamp;`,
|
|
772
|
+
)
|
|
773
|
+
.replace('#include <lights_fragment_begin>', cachedBentLightsBegin)
|
|
774
|
+
.replace(
|
|
775
|
+
'#include <aomap_fragment>',
|
|
776
|
+
/* glsl */ `#include <aomap_fragment>
|
|
777
|
+
{
|
|
778
|
+
// Unbaked meshes have default attribute aInteriorSky.x == 0.0 and fall back cleanly to ao = 1.0.
|
|
779
|
+
float intAo = vInteriorSky.x < 0.01 ? 1.0 : vInteriorSky.x;
|
|
780
|
+
reflectedLight.indirectDiffuse *= intAo;
|
|
781
|
+
|
|
782
|
+
// Outward horizontal direction of the window(s) lighting this vertex (-inwardNormal.xz).
|
|
783
|
+
float intSideLen = length( vInteriorSky.zw );
|
|
784
|
+
vec2 intSunHoriz = length( uSunDir.xz ) > 1e-4 ? normalize( uSunDir.xz ) : vec2( 1.0, 0.0 );
|
|
785
|
+
float intSunSide = intSideLen > 0.05 ? dot( -vInteriorSky.zw / intSideLen, intSunHoriz ) : 0.0;
|
|
786
|
+
float intSunUp = smoothstep( -0.05, 0.25, uSunDir.y );
|
|
787
|
+
vec3 intWinIrradiance = (
|
|
788
|
+
uWindowSky * ( 0.80 + 0.30 * ( 0.5 + 0.5 * intSunSide ) ) +
|
|
789
|
+
uWindowSun * ( max( intSunSide, 0.0 ) * intSunUp )
|
|
790
|
+
) * vInteriorSky.y;
|
|
791
|
+
|
|
792
|
+
vec3 intLampIrradiance = vInteriorLamp * max( uLampGlow, 0.0 );
|
|
793
|
+
|
|
794
|
+
// Micro-surface neutral scatter keeps dark timber and rough stone readable in dim rooms without flattening contrast.
|
|
795
|
+
float intLuma = max( dot( material.diffuseContribution, vec3( 0.2126, 0.7152, 0.0722 ) ), 0.008 );
|
|
796
|
+
vec3 intSoftAlbedo = mix( material.diffuseContribution, vec3( sqrt( intLuma ) ), 0.14 );
|
|
797
|
+
vec3 intLiftAlbedo = mix( material.diffuseContribution, vec3( sqrt( intLuma ) ), 0.34 );
|
|
798
|
+
|
|
799
|
+
reflectedLight.indirectDiffuse += intSoftAlbedo * ( intWinIrradiance + intLampIrradiance );
|
|
800
|
+
reflectedLight.indirectDiffuse += intLiftAlbedo * uShadowLift * ( 0.42 + 0.58 * intAo );
|
|
801
|
+
}`,
|
|
802
|
+
);
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
target.customProgramCacheKey = () => `${baseCacheKey()}:${cacheKey}`;
|
|
806
|
+
return target;
|
|
807
|
+
}
|