threedog 0.5.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +276 -1
- package/README.md +18 -13
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +116 -61
- package/core/{Baked.js → assets/Baked.js} +16 -25
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- package/core/{assetLoad.js → assets/assetLoad.js} +66 -29
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +23 -12
- package/core/{assetReport.js → assets/assetReport.js} +9 -15
- package/core/{namedModel.js → assets/namedModel.js} +24 -16
- package/core/{Audio.js → audio/Audio.js} +27 -24
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +10 -10
- package/core/{Random.js → base/Random.js} +5 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +154 -139
- package/core/{errorHints.js → base/errorHints.js} +9 -10
- package/core/{errors.js → base/errors.js} +9 -9
- package/core/{events.generated.js → base/events.generated.js} +2 -0
- package/core/{math.js → base/math.js} +22 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +29 -8
- package/core/{Engine.js → engine/Engine.js} +112 -105
- package/core/{Loading.js → engine/Loading.js} +4 -2
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
- package/core/{lifecycle.js → engine/lifecycle.js} +16 -16
- package/core/{loop.js → engine/loop.js} +80 -52
- package/core/{moduleSlots.js → engine/moduleSlots.js} +35 -10
- package/core/{moduleTypes.js → engine/moduleTypes.js} +30 -18
- package/core/{modules.js → engine/modules.js} +20 -17
- package/core/engine/page.js +125 -0
- package/core/{plugins.js → engine/plugins.js} +68 -103
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +35 -35
- package/core/{Input.js → input/Input.js} +41 -27
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/{inputPad.js → input/inputPad.js} +1 -1
- package/core/{inputPointer.js → input/inputPointer.js} +8 -2
- package/core/{inputTouch.js → input/inputTouch.js} +1 -1
- package/core/{Budget.js → inspect/Budget.js} +23 -22
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +60 -31
- package/core/{Describe.js → inspect/Describe.js} +33 -30
- package/core/{Inspect.js → inspect/Inspect.js} +14 -9
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +8 -10
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +29 -16
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +9 -6
- package/core/inspect/UrlState.js +182 -0
- package/core/{catalog.js → inspect/catalog.js} +18 -5
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +8 -8
- package/core/inspect/describeRender.js +148 -0
- package/core/{describeText.js → inspect/describeText.js} +17 -12
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +11 -9
- package/core/inspect/pictureWriters.js +342 -0
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/{Ops.js → ops/Ops.js} +16 -11
- package/core/{control.js → ops/control.js} +13 -12
- package/core/ops/holds.js +139 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
- package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +7 -4
- package/core/{owned.js → ops/owned.js} +37 -37
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -27
- package/core/{stackFrames.js → ops/stackFrames.js} +17 -6
- package/core/{stacks.js → ops/stacks.js} +18 -20
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
- package/core/{Saves.js → saves/Saves.js} +58 -36
- package/core/{saveApply.js → saves/saveApply.js} +13 -9
- package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
- package/core/{saveValues.js → saves/saveValues.js} +20 -3
- package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
- package/core/{session.js → saves/session.js} +31 -17
- package/core/{Rays.js → scene/Rays.js} +27 -24
- package/core/{Views.js → scene/Views.js} +15 -6
- package/core/{adaptive.js → scene/adaptive.js} +15 -8
- package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
- package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
- package/core/{gameLights.js → scene/gameLights.js} +24 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +4 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/{ground.js → scene/ground.js} +9 -9
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/scene/pictureSlots.js +33 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +14 -6
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -20
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +19 -6
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +1 -1
- package/core/scene/view.js +44 -0
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +62 -33
- package/core/{batchGroups.js → stream/batchGroups.js} +18 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +41 -1
- package/core/{scatter.js → stream/scatter.js} +2 -2
- package/core/{streamSources.js → stream/streamSources.js} +12 -7
- package/core/{Commits.js → threads/Commits.js} +6 -5
- package/core/{Jobs.js → threads/Jobs.js} +12 -10
- package/core/{Threads.js → threads/Threads.js} +16 -16
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +17 -10
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +18 -17
- package/core/{time.js → time/time.js} +18 -12
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +70 -63
- package/docs/API.md +30 -29
- package/docs/CODEMAP.md +98 -223
- package/docs/COMMANDS.md +80 -69
- package/docs/CONVENTIONS.md +87 -41
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +100 -49
- package/docs/api/assets.md +17 -16
- package/docs/api/audio.md +8 -7
- package/docs/api/budget.md +8 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +29 -29
- package/docs/api/characters.md +26 -19
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +14 -11
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +82 -53
- package/docs/api/events.md +5 -3
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +9 -2
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +4 -1
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +10 -9
- package/docs/api/interactions.md +6 -4
- package/docs/api/inventory.md +10 -11
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -8
- package/docs/api/lightPool.md +2 -7
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +8 -5
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +7 -1
- package/docs/api/post.md +24 -5
- package/docs/api/quests.md +3 -3
- package/docs/api/rays.md +5 -7
- package/docs/api/rigid.md +27 -18
- package/docs/api/saves.md +8 -7
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +17 -14
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +17 -12
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +30 -26
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +11 -5
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +11 -6
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +38 -57
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +47 -42
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +72 -66
- package/docs/recipes/06-clock-events.md +30 -21
- package/docs/recipes/07-flow-scenes-pause.md +21 -17
- package/docs/recipes/08-weather-sky.md +117 -75
- package/docs/recipes/09-materials-lights-models.md +171 -0
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +33 -25
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +50 -22
- package/docs/recipes/14-custom-module.md +20 -17
- package/docs/recipes/15-perf.md +52 -29
- package/docs/recipes/16-dev-bridge.md +47 -57
- package/docs/recipes/18-world.md +45 -30
- package/docs/recipes/19-shooting-picking.md +11 -7
- package/docs/recipes/20-content-actions-save.md +36 -37
- package/docs/recipes/21-camera.md +41 -8
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +11 -11
- package/docs/recipes/26-ui-parts.md +56 -22
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +126 -30
- package/docs/recipes/29-grid.md +16 -7
- package/docs/recipes/30-templates.md +62 -21
- package/docs/recipes/31-audio.md +9 -9
- package/docs/recipes/32-action-game.md +32 -9
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +164 -52
- package/docs/recipes/35-picture-from-reference.md +140 -0
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +105 -30
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +74 -106
- package/docs/recipes/44-water-weather-hooks.md +196 -0
- package/docs/recipes/45-cascaded-shadows.md +145 -25
- package/docs/recipes/46-blender-art-route.md +21 -25
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +137 -0
- package/docs/recipes/53-ground-up-close.md +65 -28
- package/docs/recipes/55-mods-time-wrap.md +25 -17
- package/docs/recipes/56-webgpu-tsl.md +73 -28
- package/docs/recipes/57-control.md +47 -1
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +47 -27
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +276 -0
- package/docs/recipes/63-third-person-start.md +90 -0
- package/docs/recipes/64-particles.md +35 -0
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +9 -7
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +18 -14
- package/examples/{sheepisland → perf-island}/assets.js +2 -2
- package/examples/{sheepisland → perf-island}/content/templates.js +1 -1
- package/examples/{sheepisland → perf-island}/content/vegetation.js +3 -1
- package/examples/{sheepisland → perf-island}/main.js +22 -16
- package/examples/{sheepisland/style → perf-island}/models.js +13 -24
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/perf-island/picture/index.js +20 -0
- package/examples/perf-island/picture/lights.js +34 -0
- package/examples/perf-island/picture/materials.js +61 -0
- package/examples/perf-island/picture/palette.js +60 -0
- package/examples/perf-island/picture/sky.js +20 -0
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/GAMEMAP.md +91 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +10 -4
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +26 -36
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -10
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +31 -68
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +8 -6
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +6 -4
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +10 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +16 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +14 -22
- package/index.js +36 -36
- package/llms.txt +19 -21
- package/modules/ambience/Ambience.js +12 -9
- package/modules/calendar/Calendar.js +20 -20
- package/modules/calendar/index.js +14 -13
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +2 -2
- package/modules/camera/FixedCamera.js +14 -15
- package/modules/camera/FollowCamera.js +4 -4
- package/modules/camera/RtsCamera.js +11 -11
- package/modules/camera/common.js +51 -25
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +47 -39
- package/modules/characters/NPC.js +30 -22
- package/modules/characters/assetModel.js +18 -13
- package/modules/characters/astar.js +7 -5
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +172 -193
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +22 -15
- package/modules/characters/movers/manual.js +4 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +32 -18
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +28 -18
- package/modules/characters/npcView.js +6 -5
- package/modules/characters/pathAsync.js +12 -10
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +108 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +19 -5
- package/modules/characters/useModel.js +5 -5
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +30 -22
- package/modules/collision/contract.js +15 -0
- package/modules/content/explain.js +1 -2
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +2 -2
- package/modules/content/index.js +68 -98
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +66 -18
- package/modules/content/packs.js +3 -3
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +35 -0
- package/modules/content/props.js +19 -14
- package/modules/content/rules.js +34 -22
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +24 -22
- package/modules/content/words.js +34 -0
- package/modules/debug/DebugPanel.js +10 -43
- package/modules/flow/contract.js +1 -1
- package/modules/flow/index.js +11 -7
- package/modules/gameplay/Container.js +12 -11
- package/modules/gameplay/Containers.js +14 -5
- package/modules/gameplay/Dialogue.js +13 -11
- package/modules/gameplay/Interactions.js +115 -27
- package/modules/gameplay/Inventory.js +11 -12
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +4 -5
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -3
- package/modules/gameplay/pickups.js +81 -44
- package/modules/gameplay/questLog.js +2 -2
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +16 -3
- package/modules/grid/index.js +47 -19
- package/modules/grid/preview.js +29 -20
- package/modules/grid/tiles.js +19 -23
- package/modules/hlod/index.js +38 -55
- package/modules/hud/index.js +27 -8
- package/modules/hud/parts.js +13 -11
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +48 -152
- package/modules/level/load.js +79 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +6 -7
- package/modules/lights/index.js +34 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +31 -27
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +14 -0
- package/modules/nav/index.js +11 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +5 -4
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +49 -25
- package/modules/particles/effect.js +27 -10
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +26 -27
- package/modules/rigid/RigidBodies.js +66 -43
- package/modules/rigid/Vehicles.js +2 -3
- package/modules/rigid/ragdoll.js +287 -0
- package/modules/rigid/ragdollBones.js +159 -0
- package/modules/rigid/sync.js +6 -6
- package/modules/settings/Settings.js +114 -45
- package/modules/settings/apply.js +10 -10
- package/modules/settings/sections.js +16 -14
- package/modules/settings/strings.js +1 -1
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +125 -103
- package/modules/sky/clouds.js +22 -23
- package/modules/sky/dome.js +113 -0
- package/modules/sky/domeLayers.js +13 -13
- package/modules/sky/environment.js +47 -171
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +42 -97
- package/modules/sky/season.js +9 -3
- package/modules/sky/shader.js +49 -44
- package/modules/sky/skyModule.js +25 -35
- package/modules/sky/tint.js +9 -11
- package/modules/swarm/Swarm.js +346 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +97 -62
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +157 -0
- package/modules/terrain/index.js +60 -88
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +4 -3
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +19 -14
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +19 -15
- package/modules/vegetation/Vegetation.js +87 -39
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +196 -0
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +18 -16
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +140 -93
- package/modules/water/surface.js +56 -56
- package/modules/weather/Weather.js +84 -38
- package/modules/weather/particles.js +18 -10
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +145 -0
- package/modules/world/World.js +10 -10
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -12
- package/modules/world/persist.js +73 -25
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +28 -8
- package/modules/world/sim.js +4 -4
- package/modules/world/state.js +12 -5
- package/modules/world/thingSource.js +4 -2
- package/modules/world/views.js +12 -10
- package/package.json +44 -8
- package/presets.js +3 -5
- package/render/PostFX.js +233 -63
- package/render/backend.js +72 -32
- package/render/cascades.js +200 -0
- package/render/cascades.tsl.js +93 -0
- package/render/daylight.js +56 -0
- package/render/detail.js +13 -12
- package/render/effects.js +60 -42
- package/render/fuse.js +3 -3
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +10 -13
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/patchNodes.tsl.js +6 -16
- package/render/fx/postWebGPU.tsl.js +55 -28
- package/render/fx/sky.tsl.js +34 -109
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/water.tsl.js +1 -1
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +14 -0
- package/render/lighting.js +11 -8
- package/render/lightmap.js +142 -0
- package/render/lights.js +26 -204
- package/render/lit.js +24 -0
- package/render/materials.js +47 -162
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/neutral.js +23 -0
- package/render/occlusion.js +200 -0
- package/render/ownFrame.js +5 -5
- package/render/patches.js +46 -41
- package/render/postWebGL.js +19 -9
- package/render/probes.js +182 -128
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/render/shadows.js +451 -0
- package/render/slots.js +11 -11
- package/render/terms.js +63 -113
- package/render/uniformDecl.js +2 -2
- package/types/core.d.ts +489 -405
- package/types/gameplay.d.ts +225 -114
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +23 -8
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/engine/page.d.ts +24 -0
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +21 -10
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +16 -8
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Layer.d.ts +9 -1
- package/types/generated/modules/grid/index.d.ts +32 -8
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +14 -7
- package/types/generated/modules/sky/Sky.d.ts +101 -23
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +2 -1
- package/types/generated/modules/water/Water.d.ts +51 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -10
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +7 -5
- package/types/generated/render/PostFX.d.ts +69 -20
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +20 -44
- package/types/generated/render/occlusion.d.ts +22 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +11 -11
- package/types/physics.d.ts +104 -73
- package/types/tsl.d.ts +45 -4
- package/types/world.d.ts +372 -86
- package/ui/Focus.js +21 -10
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +12 -7
- package/ui/UI.js +17 -17
- package/ui/cursor.js +1 -1
- package/ui/defaults.js +3 -2
- package/ui/theme.js +36 -28
- package/ui/touchPart.js +1 -1
- package/core/UrlState.js +0 -110
- package/core/assetEntry.js +0 -106
- package/core/describeRender.js +0 -71
- package/core/holds.js +0 -134
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/page.js +0 -79
- package/core/shadowTypes.js +0 -16
- package/core/styleParts.js +0 -114
- package/core/util.js +0 -17
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -228
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/PERF.md +0 -245
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/37-terrain-look-hooks.md +0 -119
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/47-island-snow-backdrop.md +0 -45
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/core/page.d.ts +0 -18
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
- /package/core/{Vars.js → base/Vars.js} +0 -0
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsFail.js → ops/opsFail.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
package/render/backend.js
CHANGED
|
@@ -3,9 +3,14 @@
|
|
|
3
3
|
// read directly in every caller, each one would need its own WebGPU branch and the next renderer change would miss some of them.
|
|
4
4
|
// Plain three.js equivalent: renderer.info.render / .memory / .programs, renderer.shadowMap.autoUpdate / needsUpdate (WebGL) or
|
|
5
5
|
// light.shadow.autoUpdate / needsUpdate (WebGPU), WEBGL_debug_renderer_info (WebGL) or GPUDevice.adapterInfo (WebGPU).
|
|
6
|
-
// Imports nothing from three (only
|
|
6
|
+
// Imports nothing from three (only engine files that do not either): threedog/tsl (render/fx) registers the WebGPU classes here, so WebGL games never load three/webgpu.
|
|
7
7
|
|
|
8
|
-
import { codedError } from '../core/errorHints.js';
|
|
8
|
+
import { codedError } from '../core/base/errorHints.js';
|
|
9
|
+
import { notePatch, patchOn } from '../core/scene/threePatches.js';
|
|
10
|
+
import { isShown } from '../core/base/util.js';
|
|
11
|
+
|
|
12
|
+
/** Samples of the MSAA the post chain's targets use, on both renderers */
|
|
13
|
+
export const MSAA_SAMPLES = 4;
|
|
9
14
|
|
|
10
15
|
/** Whether this is three's WebGPURenderer (either of its backends) @param {any} r */
|
|
11
16
|
export const isWebGPU = r => !!r?.isWebGPURenderer;
|
|
@@ -38,13 +43,15 @@ export const programList = r => isWebGPU(r) ? [] : r.info.programs ?? [];
|
|
|
38
43
|
// last render object built per material is kept (weakly: the material's lifetime) and its NodeBuilderState read on demand.
|
|
39
44
|
// RECENT: the last builds in order, also weak, so a compile error (which three reports without its render object) can be matched back to one.
|
|
40
45
|
const NODE_PROGRAMS = new WeakMap(), RECENT = [], RECENT_MAX = 256;
|
|
41
|
-
|
|
46
|
+
notePatch('node-builder-hook', "renderer.debug.onNodeBuilderCreated of a WebGPURenderer: remembers the render object built per material, a game's own hook still runs (render/backend.js)", () => {},
|
|
47
|
+
{ scope: 'engine renderer', lost: 'on WebGPU: shader errors no longer name the material, and shaderCost and the program costs in inspect.perf stay empty' });
|
|
48
|
+
/** @internal core/engine/Engine.js: on WebGPURenderer, remember the render object three builds per material (a game's own hook still runs) @param {any} r */
|
|
42
49
|
export function watchNodePrograms(r) {
|
|
43
50
|
const d = r?.debug;
|
|
44
51
|
if (!isWebGPU(r) || !d || d._threedogPrograms) return;
|
|
45
52
|
const prev = d.onNodeBuilderCreated;
|
|
46
53
|
d.onNodeBuilderCreated = (builder, ro) => {
|
|
47
|
-
if (ro?.material) { NODE_PROGRAMS.set(ro.material, ro); RECENT.push(new WeakRef(ro)); if (RECENT.length > RECENT_MAX) RECENT.shift(); }
|
|
54
|
+
if (ro?.material && patchOn('node-builder-hook')) { NODE_PROGRAMS.set(ro.material, ro); RECENT.push(new WeakRef(ro)); if (RECENT.length > RECENT_MAX) RECENT.shift(); }
|
|
48
55
|
prev?.(builder, ro);
|
|
49
56
|
};
|
|
50
57
|
d._threedogPrograms = true;
|
|
@@ -85,6 +92,9 @@ export function memory(r) {
|
|
|
85
92
|
/** Start this frame's counters from zero (the engine renders with info.autoReset off: onRender targets count too) @param {any} r */
|
|
86
93
|
export function resetStats(r) { r.info.reset(); }
|
|
87
94
|
|
|
95
|
+
/** Shadows on in the picture right now (the renderer's switch: what a game wrote directly counts too) @param {any} e */
|
|
96
|
+
export const shadowsOn = e => !!e.renderer?.shadowMap?.enabled;
|
|
97
|
+
|
|
88
98
|
/**
|
|
89
99
|
* Shadow-map refresh. auto: redraw every frame (true) or only when asked (false); now: redraw on the next render.
|
|
90
100
|
* WebGLRenderer has one switch for all lights (renderer.shadowMap); WebGPURenderer has it per light (light.shadow), so there every
|
|
@@ -94,7 +104,10 @@ export function resetStats(r) { r.info.reset(); }
|
|
|
94
104
|
export function setShadowUpdate(r, scene, { auto, now } = {}) {
|
|
95
105
|
if (!isWebGPU(r)) {
|
|
96
106
|
if (auto !== undefined) r.shadowMap.autoUpdate = auto;
|
|
97
|
-
if (now)
|
|
107
|
+
if (now) {
|
|
108
|
+
r.shadowMap.needsUpdate = true;
|
|
109
|
+
for (const o of shadowLights(scene)) o.shadow.needsUpdate = true; // a light under a budget (light.shadow.autoUpdate off) skips the pass without its own flag
|
|
110
|
+
}
|
|
98
111
|
return;
|
|
99
112
|
}
|
|
100
113
|
for (const o of shadowLights(scene)) {
|
|
@@ -107,15 +120,15 @@ export function setShadowUpdate(r, scene, { auto, now } = {}) {
|
|
|
107
120
|
}
|
|
108
121
|
|
|
109
122
|
/**
|
|
110
|
-
* The lights with a shadow in a scene, kept up to date on add / remove (core/sceneDelta.js) instead of walking the scene.
|
|
111
|
-
* Why:
|
|
123
|
+
* The lights with a shadow in a scene, kept up to date on add / remove (core/scene/sceneDelta.js) instead of walking the scene.
|
|
124
|
+
* Why: these are asked for every frame (the cascades' early update, the budget's shadow pass count); a full
|
|
112
125
|
* scene walk each time costs more than the frame's game code in a large, streaming world.
|
|
113
126
|
* @param {any} scene @returns {Set<any>}
|
|
114
127
|
*/
|
|
115
128
|
function shadowLights(scene) {
|
|
116
129
|
let w = LIGHTS.get(scene);
|
|
117
130
|
if (!w) {
|
|
118
|
-
if (!VISITOR.fn) throw codedError('engine-misuse', '[threedog] render/backend.js shadowLights: core/sceneDelta.js is not loaded (the engine core registers it)');
|
|
131
|
+
if (!VISITOR.fn) throw codedError('engine-misuse', '[threedog] render/backend.js shadowLights: core/scene/sceneDelta.js is not loaded (the engine core registers it)');
|
|
119
132
|
const set = new Set();
|
|
120
133
|
w = { set, view: VISITOR.fn(scene, { enter: o => { if (o.isLight && o.shadow) set.add(o); }, leave: o => { set.delete(o); } }) };
|
|
121
134
|
LIGHTS.set(scene, w);
|
|
@@ -124,16 +137,16 @@ function shadowLights(scene) {
|
|
|
124
137
|
return w.set;
|
|
125
138
|
}
|
|
126
139
|
const LIGHTS = new WeakMap(); // scene -> { set, view }
|
|
127
|
-
// core/sceneDelta.js hands its sceneVisitor in (it patches three's Object3D, so importing it here would pull 'three' into threedog/tsl)
|
|
140
|
+
// core/scene/sceneDelta.js hands its sceneVisitor in (it patches three's Object3D, so importing it here would pull 'three' into threedog/tsl)
|
|
128
141
|
const VISITOR = { fn: null };
|
|
129
|
-
/** @internal core/sceneDelta.js at load @param {Function} fn */
|
|
142
|
+
/** @internal core/scene/sceneDelta.js at load @param {Function} fn */
|
|
130
143
|
export function useSceneVisitor(fn) { VISITOR.fn = fn; }
|
|
131
144
|
|
|
132
145
|
/**
|
|
133
146
|
* Stop shadow redraws until the returned release() puts the switch back. For renders that draw the scene again within one frame (a post
|
|
134
|
-
* effect's own scene render: ao normals, outline
|
|
147
|
+
* effect's own scene render: ao normals, outline's normals and mask): three redraws every shadow map in each render() while autoUpdate is on, so on
|
|
135
148
|
* WebGL ao drew them twice a frame (tests/specs/shadow-passes.mjs). A redraw already requested (needsUpdate) still happens on the next render;
|
|
136
|
-
* the scene pass before this has used it up in the usual case. WebGPURenderer: a no-op (
|
|
149
|
+
* the scene pass before this has used it up in the usual case. WebGPURenderer: a no-op (three draws a shadow there once per camera and frame by itself, however many passes render the scene).
|
|
137
150
|
* @param {any} r @param {any} scene @returns {() => void}
|
|
138
151
|
*/
|
|
139
152
|
export function holdShadowRedraw(r, scene) {
|
|
@@ -145,8 +158,9 @@ export function holdShadowRedraw(r, scene) {
|
|
|
145
158
|
|
|
146
159
|
/** Whether a shadow redraw is already requested for the next render @param {any} r @param {any} scene @returns {boolean} */
|
|
147
160
|
export function shadowUpdatePending(r, scene) {
|
|
148
|
-
if (!isWebGPU(r)
|
|
161
|
+
if (!isWebGPU(r) && r.shadowMap.needsUpdate) return true;
|
|
149
162
|
for (const o of shadowLights(scene)) {
|
|
163
|
+
if (!isWebGPU(r)) { if (o.castShadow && o.shadow.needsUpdate) return true; continue; }
|
|
150
164
|
// with cascades the light's own map is never drawn, so its needsUpdate is never cleared: only the cascades' flags count
|
|
151
165
|
const c = cascadeShadows(o);
|
|
152
166
|
if ((c.length ? c : [o.shadow]).some(s => s.needsUpdate)) return true;
|
|
@@ -155,15 +169,12 @@ export function shadowUpdatePending(r, scene) {
|
|
|
155
169
|
}
|
|
156
170
|
|
|
157
171
|
/**
|
|
158
|
-
* The per-cascade LightShadow objects of a light whose shadow is a cascade shadow node (three's CSMShadowNode:
|
|
172
|
+
* The per-cascade LightShadow objects of a light whose shadow is a cascade shadow node (three's CSMShadowNode: render/cascades.tsl.js),
|
|
159
173
|
* else []. Its cascade lights are plain Object3Ds, not lights, so a scene walk for lights never reaches their flags.
|
|
160
174
|
* @param {any} light @returns {any[]}
|
|
161
175
|
*/
|
|
162
176
|
const cascadeShadows = light => light.shadow.shadowNode?.lights?.map(l => l.shadow) ?? [];
|
|
163
177
|
|
|
164
|
-
/** visible itself and every parent (what traverseVisible checks), O(depth) @param {any} o */
|
|
165
|
-
const shown = o => { for (let p = o; p; p = p.parent) if (!p.visible) return false; return true; };
|
|
166
|
-
|
|
167
178
|
/**
|
|
168
179
|
* The shadow maps the next render draws, as [{ shadow, faces }] (faces: 6 for a point light's cube map, else 1). Why one list for both
|
|
169
180
|
* renderers: on WebGL every cascade is a DirectionalLight in the scene, while on WebGPURenderer a cascade shadow node draws one map per
|
|
@@ -176,7 +187,7 @@ export function shadowMaps(r, scene) {
|
|
|
176
187
|
/** @type {{ shadow: any, faces: number }[]} */ const out = [];
|
|
177
188
|
if (!r.shadowMap?.enabled) return out;
|
|
178
189
|
for (const o of shadowLights(scene)) {
|
|
179
|
-
if (!o.castShadow || !
|
|
190
|
+
if (!o.castShadow || !isShown(o)) continue;
|
|
180
191
|
const node = isWebGPU(r) ? o.shadow.shadowNode : null;
|
|
181
192
|
if (node?.cascades > 0 && Array.isArray(node.lights)) {
|
|
182
193
|
const c = cascadeShadows(o);
|
|
@@ -193,13 +204,25 @@ export function shadowMaps(r, scene) {
|
|
|
193
204
|
* (known only after init(); '' before). WebGPURenderer on its WebGL2 backend: that backend's context, read like WebGL.
|
|
194
205
|
* @param {any} r @returns {string}
|
|
195
206
|
*/
|
|
196
|
-
|
|
207
|
+
function gpuName(r) {
|
|
197
208
|
if (isWebGPU(r) && r.backend?.isWebGPUBackend) {
|
|
198
209
|
const a = r.backend.device?.adapterInfo;
|
|
199
210
|
return a ? [a.vendor, a.architecture, a.device, a.description].filter(Boolean).join(' ') : '';
|
|
200
211
|
}
|
|
201
212
|
return glName(isWebGPU(r) ? r.backend?.gl : r.getContext());
|
|
202
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* What the renderer in use can run, for describe().renderer: an AI reads here what a game may rely on, instead of learning it from a shader that fails.
|
|
216
|
+
* compute: 'compute-shaders' on WebGPU; 'transform-feedback' on WebGPURenderer's WebGL2 backend, which runs renderer.compute() through vertex shaders, so no
|
|
217
|
+
* storage textures, atomics or workgroup memory; null on WebGLRenderer.
|
|
218
|
+
* @param {any} r @returns {{ gpu: string | null, tsl: boolean, glsl: boolean, compute: 'compute-shaders' | 'transform-feedback' | null }}
|
|
219
|
+
*/
|
|
220
|
+
export function backendFacts(r) {
|
|
221
|
+
const name = backendName(r);
|
|
222
|
+
return { gpu: gpuName(r) || null, tsl: name !== 'webgl', glsl: name === 'webgl',
|
|
223
|
+
compute: name === 'webgpu' ? 'compute-shaders' : name === 'webgl2' ? 'transform-feedback' : null };
|
|
224
|
+
}
|
|
225
|
+
|
|
203
226
|
/** @param {any} gl @returns {string} */
|
|
204
227
|
function glName(gl) {
|
|
205
228
|
if (!gl) return '';
|
|
@@ -261,6 +284,9 @@ const drawnIn = new WeakMap();
|
|
|
261
284
|
export function freshFrame(r) {
|
|
262
285
|
const f = isWebGPU(r) ? r._nodes?.nodeFrame : null; // _nodes exists after init(); before it nothing has been drawn
|
|
263
286
|
if (!f) return;
|
|
287
|
+
// three's first render() starts that tick, and starting it runs one tick at once: left to render(), the id moves inside the first draw, after the
|
|
288
|
+
// line below noted it, so the next draw took the id for new and its scene pass, already done in that id, showed the first draw's picture again
|
|
289
|
+
r._animation.start();
|
|
264
290
|
if (drawnIn.get(r) === f.frameId) { f.update(); r.info.frame = f.frameId; }
|
|
265
291
|
drawnIn.set(r, f.frameId);
|
|
266
292
|
}
|
|
@@ -299,18 +325,32 @@ export function compileThrough(r, draw) {
|
|
|
299
325
|
}
|
|
300
326
|
|
|
301
327
|
/**
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
328
|
+
* The pixels of one layer of a 3D render target, RGBA, row 0 first as the target's writer meant it. Float32Array on WebGLRenderer; on WebGPURenderer
|
|
329
|
+
* whatever its readback gives for the target's type, with rows padded to its copy alignment (use length / h as the row stride).
|
|
330
|
+
* Why the flip: WebGPURenderer's node shaders count rows from the top, and on its WebGL2 backend readPixels counts from the bottom, so without
|
|
331
|
+
* it a probe bake on that backend came back upside down.
|
|
332
|
+
* @param {any} r @param {any} rt @param {number} w @param {number} h @param {number} layer @returns {Promise<any>}
|
|
306
333
|
*/
|
|
307
|
-
export function
|
|
308
|
-
if (
|
|
309
|
-
|
|
334
|
+
export async function readLayer(r, rt, w, h, layer) {
|
|
335
|
+
if (isWebGPU(r)) {
|
|
336
|
+
const px = await r.readRenderTargetPixelsAsync(rt, 0, 0, w, h, 0, layer);
|
|
337
|
+
if (backendName(r) === 'webgpu') return px;
|
|
338
|
+
const out = new /** @type {any} */ (px.constructor)(px.length), row = px.length / h;
|
|
339
|
+
for (let y = 0; y < h; y++) out.set(px.subarray(y * row, (y + 1) * row), (h - 1 - y) * row);
|
|
340
|
+
return out;
|
|
341
|
+
}
|
|
342
|
+
const keep = r.getRenderTarget(), face = r.getActiveCubeFace(), mip = r.getActiveMipmapLevel(), px = new Float32Array(w * h * 4);
|
|
343
|
+
r.setRenderTarget(rt, layer); // on WebGL the layer is chosen by what is attached, readRenderTargetPixels has no layer argument
|
|
344
|
+
r.readRenderTargetPixels(rt, 0, 0, w, h, px);
|
|
345
|
+
r.setRenderTarget(keep, face, mip);
|
|
346
|
+
return px;
|
|
310
347
|
}
|
|
311
348
|
|
|
312
|
-
/**
|
|
313
|
-
export function
|
|
349
|
+
/** Make three's light node drop the shadow it cached (AnalyticLightNode listens for the light's 'dispose'; its version bump recompiles) @param {any} light */
|
|
350
|
+
export function rebuildShadow(light) { light.dispatchEvent({ type: 'dispose' }); }
|
|
351
|
+
|
|
352
|
+
/** A text that changes when the camera's projection does, for "did it change" checks @param {any} cam @returns {string} */
|
|
353
|
+
export const projectionKey = cam => (cam.isPerspectiveCamera ? `${cam.fov},${cam.aspect},${cam.near},${cam.far},${cam.zoom}` : `${cam.left},${cam.right},${cam.top},${cam.bottom},${cam.near},${cam.far},${cam.zoom}`);
|
|
314
354
|
|
|
315
355
|
// ---------- the WebGPU route (createEngine({ renderer: 'webgpu' }); docs/plans/2026-11-03-webgpu-phase2.md section 1) ----------
|
|
316
356
|
|
|
@@ -319,7 +359,7 @@ export function cubeRender(r, scene, cubeCamera) { freshFrame(r); cubeCamera.upd
|
|
|
319
359
|
// a sixth part had nothing to copy. Now a .tsl.js file calls registerWebGPUPart(name, impl) once at load, and every user asks
|
|
320
360
|
// webgpuPart(name, who): the same error code and the same fix line wherever threedog/tsl is missing.
|
|
321
361
|
// Module scope, not a page global: the .tsl.js files import this file, so they always fill the table the engine copy using them reads.
|
|
322
|
-
/** @typedef {'classes' | 'nodePatches' | 'particles' | 'post' | 'sky' | 'cascades'} WebGPUPartName */
|
|
362
|
+
/** @typedef {'classes' | 'nodePatches' | 'particles' | 'post' | 'sky' | 'cascades' | 'shadowCache'} WebGPUPartName */
|
|
323
363
|
/** @type {Map<string, any>} */
|
|
324
364
|
const PARTS = new Map();
|
|
325
365
|
/**
|
|
@@ -344,7 +384,7 @@ export function swapWebGPUPart(name, impl) { const prev = PARTS.get(name) ?? nul
|
|
|
344
384
|
|
|
345
385
|
// Parts built for the renderer before start() knew the backend. createEngine({ renderer: 'webgpu', fallback: 'webgl' }) swaps the
|
|
346
386
|
// WebGPURenderer for a WebGLRenderer inside start(), after modules installed and built node materials (the sky dome). Each such part
|
|
347
|
-
// registers a rebuild here; start() runs them right after the swap (core/startup.js), so no part keeps a node material WebGL cannot draw.
|
|
387
|
+
// registers a rebuild here; start() runs them right after the swap (core/engine/startup.js), so no part keeps a node material WebGL cannot draw.
|
|
348
388
|
const SWAP = new WeakMap(); // engine -> Set of rebuilds
|
|
349
389
|
/**
|
|
350
390
|
* @internal Run fn when the engine's renderer is replaced in start() (fallback 'webgl'); returns { remove() }
|
|
@@ -356,7 +396,7 @@ export function onRendererSwap(engine, fn) {
|
|
|
356
396
|
set.add(fn);
|
|
357
397
|
return { remove: () => { set.delete(fn); } };
|
|
358
398
|
}
|
|
359
|
-
/** @internal core/startup.js after the swap: rebuild every registered part for engine.renderer @param {any} engine */
|
|
399
|
+
/** @internal core/engine/startup.js after the swap: rebuild every registered part for engine.renderer @param {any} engine */
|
|
360
400
|
export function rendererSwapped(engine) { for (const fn of [...(SWAP.get(engine) ?? [])]) fn(); }
|
|
361
401
|
|
|
362
402
|
/**
|
|
@@ -407,7 +447,7 @@ function gameCompileHook(m) {
|
|
|
407
447
|
/**
|
|
408
448
|
* What WebGPURenderer does not run (plan section 1.3), material by material; WebGPURenderer skips these without a word, so the engine names them.
|
|
409
449
|
* Covered: ShaderMaterial / RawShaderMaterial, a game's onBeforeCompile, and (a rule render/patches.js adds) a patched classic material whose
|
|
410
|
-
* patches cannot all run as nodes. three Pass objects in
|
|
450
|
+
* patches cannot all run as nodes. three Pass objects in engine.post are named by the WebGPU post chain itself (render/fx/postWebGPU.tsl.js).
|
|
411
451
|
*/
|
|
412
452
|
const WEBGL_ONLY = [
|
|
413
453
|
{ test: m => m.isShaderMaterial, what: m => m.isRawShaderMaterial ? 'RawShaderMaterial' : 'ShaderMaterial',
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Cascaded shadows of one DirectionalLight: 2-4 maps along the view (three's CSM addon), sharp near the camera, wide far away. The one copy of this
|
|
2
|
+
// engineering: engine.shadows.cascades(light) (render/shadows.js) builds them here, one set per engine (one 'csm' patch per material, and the cascade order
|
|
3
|
+
// is the order of the shadow-casting lights).
|
|
4
|
+
// Design choices, each one because the addon used as-is would break something:
|
|
5
|
+
// - The light handed in stays in charge and is the nearest cascade, so whoever writes it keeps its color / intensity / direction.
|
|
6
|
+
// The other cascades are extra DirectionalLights that copy its color and intensity every frame.
|
|
7
|
+
// - Materials get the cascade lighting through one named patch, 'csm' (render/patches.js), never CSM.setupMaterial: that assigns
|
|
8
|
+
// material.onBeforeCompile and would drop every other patch (wind, clouds, season, detail, lighting), and CSM.dispose deletes it.
|
|
9
|
+
// - The chunk swap is per material (the patch replaces <lights_fragment_begin>): CSM's constructor overwrites ShaderChunk globally and
|
|
10
|
+
// never restores it, which would reach every material and every engine on the page; here _injectInclude does nothing.
|
|
11
|
+
// - Every lit material in the scene must carry the patch: without it the cascade lights would add up (N times the sunlight). So while
|
|
12
|
+
// cascades are on, each frame visits only what entered the scene since the last one (core/scene/sceneDelta.js: an add at any depth, or
|
|
13
|
+
// mesh.material = x) and patches lit materials it has not seen (one Map lookup per mesh); the whole scene is walked once, when they turn on.
|
|
14
|
+
// - Which materials (user decision 4, option A, 2026-11-02): every BUILT-IN lit type, the game's own `new` materials too. This is the one named
|
|
15
|
+
// exception to "the engine does not change what it did not create": unpatched, a lit material is lit by every cascade light (N times as
|
|
16
|
+
// bright, doubled shadows), so leaving it alone is not neutral, it is a wrong picture. describe().owned lists the game materials it patched.
|
|
17
|
+
// A ShaderMaterial with lights: true is the game's own shader code, so it is never patched silently: one warning names
|
|
18
|
+
// engine.shadows.include(mat), which opts it in.
|
|
19
|
+
// - csm.update() runs only on frames whose shadow maps re-render (engine.shadows.budget), else lights move while the maps stay old.
|
|
20
|
+
// On WebGPURenderer all of the above is replaced by three's CSMShadowNode on the light (cascades.tsl.js, registered by threedog/tsl): one light,
|
|
21
|
+
// so no patch, no scene walk, and engine.shadows.include() does nothing. This file only hands over to it, so WebGL bundles never load three/webgpu.
|
|
22
|
+
import * as THREE from 'three';
|
|
23
|
+
import { CSM } from 'three/addons/csm/CSM.js';
|
|
24
|
+
import { CSMShader } from 'three/addons/csm/CSMShader.js';
|
|
25
|
+
import { patchMaterial, unpatchMaterial, isEngineMade } from './patches.js';
|
|
26
|
+
|
|
27
|
+
import { warnOnce } from '../core/base/validate.js';
|
|
28
|
+
import { sceneVisitor } from '../core/scene/sceneDelta.js';
|
|
29
|
+
import { engineOwned } from '../core/scene/things.js';
|
|
30
|
+
import { codedError } from '../core/base/errorHints.js';
|
|
31
|
+
import { setShadowUpdate, shadowUpdatePending, shadowsOn, isWebGPU, webgpuPart, projectionKey } from './backend.js';
|
|
32
|
+
|
|
33
|
+
export const CASCADE_SPLITS = ['practical', 'uniform', 'logarithmic'];
|
|
34
|
+
/** Fields of a cascade set besides its count; both entries start from these */
|
|
35
|
+
export const CASCADE_DEFAULTS = { maxFar: 120, fade: true, lightMargin: 100, split: 'practical' };
|
|
36
|
+
|
|
37
|
+
const LIT = new Set(['MeshLambertMaterial', 'MeshPhongMaterial', 'MeshStandardMaterial', 'MeshPhysicalMaterial', 'MeshToonMaterial']);
|
|
38
|
+
const _cam = new THREE.Vector3();
|
|
39
|
+
const litShader = m => m.isShaderMaterial && m.lights && m.fragmentShader.includes('#include <lights_fragment_begin>');
|
|
40
|
+
/** ShaderMaterials the game opted in with engine.shadows.include(mat), per engine */
|
|
41
|
+
const optedIn = e => e._csmInclude ??= new WeakSet();
|
|
42
|
+
/**
|
|
43
|
+
* engine.shadows.include(material): let the cascades patch a ShaderMaterial (lights: true) of yours. Built-in lit materials need nothing.
|
|
44
|
+
* @example engine.shadows.include(myLitShaderMaterial);
|
|
45
|
+
*/
|
|
46
|
+
export function includeInCascades(e, m) {
|
|
47
|
+
if (!m?.isMaterial) throw codedError('shadow-cascades', `engine.shadows.include(material): needs a three.js Material; got ${m}. Example: engine.shadows.include(myShaderMaterial)`);
|
|
48
|
+
if (m.isShaderMaterial && !litShader(m)) throw codedError('shadow-cascades', "engine.shadows.include(material): this ShaderMaterial has no lights: true + '#include <lights_fragment_begin>', so the cascades cannot reach it; build it on THREE.ShaderLib's lit shaders, or leave it out");
|
|
49
|
+
if (isWebGPU(e.renderer)) { // the cascades are the light's shadow node there: every material is lit once without opting in
|
|
50
|
+
warnOnce('engine.shadows.include(mat) does nothing on WebGPURenderer: cascaded shadows there are one light (three CSMShadowNode) and patch no material');
|
|
51
|
+
return m;
|
|
52
|
+
}
|
|
53
|
+
optedIn(e).add(m);
|
|
54
|
+
if (e._cascades?.mats.has(m)) e._cascades.fit(m); // already looked at and left alone: patch it now (fit is per material, so no scene walk)
|
|
55
|
+
return m;
|
|
56
|
+
}
|
|
57
|
+
const lit = (c, m) => {
|
|
58
|
+
if (LIT.has(m.type)) return true;
|
|
59
|
+
if (!litShader(m)) return false;
|
|
60
|
+
if (optedIn(c.engine).has(m)) return true;
|
|
61
|
+
warnOnce(`cascaded shadows: engine.shadows.include(mat) opts ShaderMaterial '${m.name || m.uuid.slice(0, 8)}' in. Until then it has lights: true and is lit by all ` +
|
|
62
|
+
`${c.lights.length} cascade lights (too bright, doubled shadows): the engine does not patch your own shader code unasked`);
|
|
63
|
+
return false;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// The addon's split / frustum / texel-snapped placement, with the given light as cascade 0 and the chunk swap left to the 'csm' patch
|
|
67
|
+
class LightCSM extends CSM {
|
|
68
|
+
/** @param {any} e @param {any} light @param {{ cascades: number, maxFar: number, fade: boolean, lightMargin: number, split: any }} S */
|
|
69
|
+
constructor(e, light, S) {
|
|
70
|
+
const custom = typeof S.split === 'function';
|
|
71
|
+
// parent: a Group, not the scene. three's constructor adds its lights itself, and a plain scene.add counts them as the game's (describe().scene, the "lights add up" warning)
|
|
72
|
+
super({ camera: e.camera, parent: new THREE.Group(), cascades: S.cascades, maxFar: S.maxFar, mode: custom ? 'custom' : S.split, customSplitsCallback: custom ? S.split : undefined,
|
|
73
|
+
shadowMapSize: light.shadow.mapSize.x, shadowBias: light.shadow.bias, lightMargin: S.lightMargin, lightNear: 1, lightFar: S.lightMargin + 2 * S.maxFar });
|
|
74
|
+
this.parent = e.scene;
|
|
75
|
+
this.lights[0].dispose();
|
|
76
|
+
this.lights[0] = light;
|
|
77
|
+
for (const l of this.lights) if (l !== light) { engineOwned('shadows', l, l.target); e.scene.add(l, l.target); }
|
|
78
|
+
// uniforms shared by every patched material: one write here reaches all of them
|
|
79
|
+
this.uniforms = { CSM_cascades: { value: [] }, cameraNear: { value: 0 }, shadowFar: { value: 0 } };
|
|
80
|
+
this.fade = S.fade;
|
|
81
|
+
this.updateFrustums();
|
|
82
|
+
// cacheKey is new for every build: three keeps a material's old programs and, when a key comes back (cascades off, then on again),
|
|
83
|
+
// reuses that program with the uniforms map of the material's latest compile, which lacks these uniforms, so the GPU would keep the
|
|
84
|
+
// old build's split and far values (shadows vanish where the old cascade 0 ended). One recompile per switch, which the light count
|
|
85
|
+
// change costs anyway; each material keeps one program per switch until it is disposed, so switch on a settings screen, not per frame
|
|
86
|
+
e._csmBuild = (e._csmBuild ?? 0) + 1;
|
|
87
|
+
this.patch = { name: 'csm', cacheKey: `${S.cascades}${S.fade ? 'f' : ''}.${e._csmBuild}`, uniforms: this.uniforms, slot: 'lightingModel',
|
|
88
|
+
pars: `#define USE_CSM 1\n#define CSM_CASCADES ${S.cascades}\n${S.fade ? '#define CSM_FADE\n' : ''}` +
|
|
89
|
+
'uniform vec2 CSM_cascades[CSM_CASCADES];\nuniform float cameraNear;\nuniform float shadowFar;',
|
|
90
|
+
glsl: CSMShader.lights_fragment_begin };
|
|
91
|
+
/**
|
|
92
|
+
* material -> the patch object it carries (null: looked at, left alone), and weak refs to walk them: switching off finds every material still alive.
|
|
93
|
+
* Weak because streamed terrain makes a material per chunk with its own color map, and a strong table would keep them all for as long as cascades run. Not
|
|
94
|
+
* a dispose listener: dispose() is also how a game forces a rebuild of a material it keeps on the mesh, and that one must still lose the patch at drop()
|
|
95
|
+
*/
|
|
96
|
+
this.mats = new WeakMap();
|
|
97
|
+
this.refs = [];
|
|
98
|
+
this.sweepAt = 1024;
|
|
99
|
+
this.engine = e;
|
|
100
|
+
this.light = light;
|
|
101
|
+
this.at = new THREE.Vector3(Infinity, 0, 0); // camera position at the last placement
|
|
102
|
+
this.proj = '';
|
|
103
|
+
/** what entered the scene since the last frame (view.walks: how many full walks ran; tests read it) */
|
|
104
|
+
this.view = sceneVisitor(e.scene, { enter: o => { if (!o.isMesh) return; const ms = o.material; if (Array.isArray(ms)) for (const m of ms) this.fit(m); else if (ms) this.fit(ms); } });
|
|
105
|
+
const sc = light.shadow.camera;
|
|
106
|
+
Object.assign(sc, { near: 1, far: this.lightFar }); sc.updateProjectionMatrix();
|
|
107
|
+
}
|
|
108
|
+
fit(m) {
|
|
109
|
+
const was = this.mats.get(m);
|
|
110
|
+
if (was === this.patch || (was === null && !optedIn(this.engine).has(m))) return;
|
|
111
|
+
if (was === undefined) this.remember(m);
|
|
112
|
+
if (!lit(this, m)) { this.mats.set(m, null); return; } // null: looked at, left alone (no per-frame recheck / rewarn)
|
|
113
|
+
patchMaterial(m, [this.patch], { strict: false }); this.mats.set(m, this.patch);
|
|
114
|
+
}
|
|
115
|
+
/** One weak ref per material; the dead ones go when the list has doubled, so a long walk through a streamed world keeps it at the size of what is alive */
|
|
116
|
+
remember(m) {
|
|
117
|
+
this.refs.push(new WeakRef(m));
|
|
118
|
+
if (this.refs.length < this.sweepAt) return;
|
|
119
|
+
this.refs = this.refs.filter(r => r.deref());
|
|
120
|
+
this.sweepAt = Math.max(1024, this.refs.length * 2);
|
|
121
|
+
}
|
|
122
|
+
/** The materials looked at and still alive, with the patch each carries @returns {[any, any][]} */
|
|
123
|
+
alive() { return this.refs.flatMap(r => { const m = r.deref(); return m ? [[m, this.mats.get(m)]] : []; }); }
|
|
124
|
+
/** describe().owned row: the game's own materials the csm patch went on (the named exception, see the header) */
|
|
125
|
+
gameMaterials() { return this.alive().filter(([m, p]) => p && !isEngineMade(m)).map(([m]) => m.name || m.type); }
|
|
126
|
+
_injectInclude() {}
|
|
127
|
+
_updateUniforms() {
|
|
128
|
+
const U = this.uniforms;
|
|
129
|
+
if (!U) return; // the base constructor calls this before the uniforms exist
|
|
130
|
+
this._getExtendedBreaks(U.CSM_cascades.value);
|
|
131
|
+
U.cameraNear.value = this.camera.near; U.shadowFar.value = Math.min(this.camera.far, this.maxFar);
|
|
132
|
+
}
|
|
133
|
+
/** The light's shadow values reach the extra lights: what is written on the light is the one source */
|
|
134
|
+
shadowParams() {
|
|
135
|
+
const s = this.light.shadow;
|
|
136
|
+
this.shadowMapSize = s.mapSize.x; // the placement snaps to this texel size
|
|
137
|
+
for (const l of this.lights) if (l !== this.light) {
|
|
138
|
+
Object.assign(l.shadow, { bias: s.bias, normalBias: s.normalBias, radius: s.radius, blurSamples: s.blurSamples, intensity: s.intensity, autoUpdate: s.autoUpdate });
|
|
139
|
+
if (s.needsUpdate) l.shadow.needsUpdate = true; // a budget asks on the light handed in; every cascade redraws with it
|
|
140
|
+
if (l.shadow.mapSize.x !== s.mapSize.x) { l.shadow.mapSize.copy(s.mapSize); l.shadow.map?.dispose(); l.shadow.map = null; }
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Per frame: patch materials that entered the scene, follow the camera and the light, place on shadow frames
|
|
145
|
+
* @param {any} lightDir unit vector toward the light @param {number} updateEvery 1 = the shadow maps redraw every frame
|
|
146
|
+
*/
|
|
147
|
+
frame(lightDir, updateEvery) {
|
|
148
|
+
const e = this.engine, cam = e.camera, light = this.light;
|
|
149
|
+
this.view.sync();
|
|
150
|
+
this.shadowParams();
|
|
151
|
+
const proj = projectionKey(cam);
|
|
152
|
+
let force = false;
|
|
153
|
+
if (this.camera !== cam || proj !== this.proj) { this.camera = cam; this.proj = proj; this.updateFrustums(); force = true; }
|
|
154
|
+
this.lightDirection.copy(lightDir).negate(); // CSM points from the light into the scene
|
|
155
|
+
// with no shadow on the light the extra lights would only add light (the patch's bands need the shadow lights): hide them
|
|
156
|
+
const show = light.visible && light.castShadow && !!light.parent && shadowsOn(e);
|
|
157
|
+
for (const l of this.lights) if (l !== light) { l.color.copy(light.color); l.intensity = light.intensity; l.visible = show; }
|
|
158
|
+
cam.updateMatrixWorld();
|
|
159
|
+
_cam.setFromMatrixPosition(cam.matrixWorld); // world: a camera on a rig keeps a small local position while it travels
|
|
160
|
+
// not updating every frame: also place early when the camera left a quarter of the nearest cascade (teleport, fast travel)
|
|
161
|
+
const near = this.breaks[0] * Math.min(cam.far, this.maxFar);
|
|
162
|
+
if (updateEvery <= 1 || shadowUpdatePending(e.renderer, e.scene) || force || this.at.distanceToSquared(_cam) > (near / 4) ** 2) {
|
|
163
|
+
this.update(); this.at.copy(_cam);
|
|
164
|
+
if (updateEvery > 1) setShadowUpdate(e.renderer, e.scene, { now: true });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** Switch off: extra lights out, the 'csm' patch off every material it went on */
|
|
168
|
+
drop() {
|
|
169
|
+
for (const l of this.lights) if (l !== this.light) { this.parent.remove(l, l.target); l.dispose(); }
|
|
170
|
+
this.view.remove();
|
|
171
|
+
for (const [m, p] of this.alive()) if (p) unpatchMaterial(m, 'csm');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Build the cascades of a light. One set per engine, named at the second build: a material holds one 'csm' patch, and on WebGL the cascade
|
|
177
|
+
* order is the order of the shadow-casting lights.
|
|
178
|
+
* @param {any} e @param {any} light @param {{ cascades: number, maxFar: number, fade: boolean, lightMargin: number, split: any }} S
|
|
179
|
+
* @param {string} who the entry, for the errors
|
|
180
|
+
* @returns {any} LightCSM, or the shadow node on WebGPURenderer
|
|
181
|
+
*/
|
|
182
|
+
export function createCascades(e, light, S, who) {
|
|
183
|
+
if (e._cascades) throw codedError('shadow-cascades', `${who}: cascaded shadows are already on for light '${e._cascades.light.name || e._cascades.light.type}', and an engine draws one set. Switch those off first (handle.remove())`);
|
|
184
|
+
const sc = light.shadow.camera, box = { left: sc.left, right: sc.right, top: sc.top, bottom: sc.bottom, near: sc.near, far: sc.far };
|
|
185
|
+
const c = isWebGPU(e.renderer) ? webgpuPart('cascades', `[shadows] cascaded shadows (${who})`).create(e, light, S) : new LightCSM(e, light, S);
|
|
186
|
+
c._box = box;
|
|
187
|
+
c.shadowParams();
|
|
188
|
+
return (e._cascades = c);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Remove the engine's cascades, if any: the light's shadow box comes back and the plain map redraws @param {any} e */
|
|
192
|
+
export function dropCascades(e) {
|
|
193
|
+
const c = e._cascades;
|
|
194
|
+
if (!c) return;
|
|
195
|
+
c.drop();
|
|
196
|
+
const sc = c.light.shadow.camera;
|
|
197
|
+
Object.assign(sc, c._box); sc.updateProjectionMatrix();
|
|
198
|
+
e._cascades = null;
|
|
199
|
+
setShadowUpdate(e.renderer, e.scene, { now: true });
|
|
200
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Cascaded shadows on WebGPURenderer (the WebGPU half of cascades.js; loaded only through threedog/tsl, render/fx/index.js).
|
|
2
|
+
// Why three's CSMShadowNode and not the WebGL design: the cascades become the shadow node of the one light (light.shadow.shadowNode),
|
|
3
|
+
// so a material is lit by that light once and shadowed by whichever cascade covers it. Nothing is patched and the scene is never walked:
|
|
4
|
+
// the 'csm' patch, the per-frame scene visitor and engine.shadows.include() exist on WebGL only because there every cascade is a full
|
|
5
|
+
// DirectionalLight that would light an unpatched material N times (user decision 4, docs/plans/2026-11-03-webgpu-phase2.md).
|
|
6
|
+
// How it differs from the node used as-is, each one because the plain node would break something here:
|
|
7
|
+
// - The light's shadow camera gets near 1 / far lightMargin + 2 * maxFar before the node clones it into the cascades. The node only sizes
|
|
8
|
+
// each cascade sideways and puts its light lightMargin behind the slice; with the old far kept, the far cascades' ground lies past far
|
|
9
|
+
// and draws no shadow at all (what E2 saw). Three's WebGL CSM sets the same lightFar itself.
|
|
10
|
+
// - The cascades are built with engine.camera, never with whatever camera compiles first (a probe or photo render would own them).
|
|
11
|
+
// - Placement waits for frames whose cascade maps redraw (engine.shadows.budget): moving the cascade lights while the maps stay old
|
|
12
|
+
// shifts every shadow, the same reason cascades.js only calls csm.update() on shadow frames.
|
|
13
|
+
// - Switching it on or off tells three's light node to rebuild its shadow (the light's 'dispose' event): the node caches the shadow it
|
|
14
|
+
// built first and would keep drawing the old one.
|
|
15
|
+
import { Object3D } from 'three/webgpu';
|
|
16
|
+
import { CSMShadowNode } from 'three/addons/csm/CSMShadowNode.js';
|
|
17
|
+
import { setShadowUpdate, shadowUpdatePending, registerWebGPUPart, rebuildShadow, projectionKey } from './backend.js';
|
|
18
|
+
|
|
19
|
+
class CascadeNode extends CSMShadowNode {
|
|
20
|
+
/** @param {any} e @param {any} light @param {any} S the cascade fields */
|
|
21
|
+
constructor(e, light, S) {
|
|
22
|
+
const custom = typeof S.split === 'function';
|
|
23
|
+
super(light, { cascades: S.cascades, maxFar: S.maxFar, mode: custom ? 'custom' : S.split, customSplitsCallback: custom ? S.split : undefined, lightMargin: S.lightMargin });
|
|
24
|
+
this.isCascadeNode = true;
|
|
25
|
+
this.fade = S.fade;
|
|
26
|
+
this._engine = e; // underscore names: three walks a node's public fields looking for child nodes
|
|
27
|
+
this._at = { x: Infinity, y: 0, z: 0 }; // camera position at the last early update
|
|
28
|
+
this._aim = new Object3D(); // the light's target in world space, for three's node (updateBefore)
|
|
29
|
+
this._proj = '';
|
|
30
|
+
const sc = light.shadow.camera;
|
|
31
|
+
Object.assign(sc, { near: 1, far: S.lightMargin + 2 * S.maxFar }); sc.updateProjectionMatrix();
|
|
32
|
+
light.shadow.shadowNode = this;
|
|
33
|
+
rebuildShadow(light);
|
|
34
|
+
}
|
|
35
|
+
setup(builder) {
|
|
36
|
+
// _init is the node's own first-build step (cascade stand-in lights, frustums); run it with the engine camera instead of builder.camera
|
|
37
|
+
// (private to three, so not in @types/three)
|
|
38
|
+
if (this.camera === null) /** @type {any} */ (this)._init({ camera: this._engine.camera, renderer: builder.renderer });
|
|
39
|
+
return super.setup(builder);
|
|
40
|
+
}
|
|
41
|
+
/** @param {any} frame @returns {boolean} false would make three call it again this frame (NodeFrame) */
|
|
42
|
+
updateBefore(frame) {
|
|
43
|
+
if (this.lights.length && !this.lights.some(l => l.shadow.autoUpdate || l.shadow.needsUpdate)) return true; // no cascade map redraws this frame
|
|
44
|
+
// three's node aims with light.target.position, a local value: a target under a parent gave shadows another direction than the light's own shading
|
|
45
|
+
// (and than WebGL). The light is a child of the scene (checked at the call), so its position needs no such step
|
|
46
|
+
const light = /** @type {any} */ (this.light), target = light.target;
|
|
47
|
+
target.updateWorldMatrix(true, false);
|
|
48
|
+
this._aim.position.setFromMatrixPosition(target.matrixWorld);
|
|
49
|
+
light.target = this._aim;
|
|
50
|
+
try { return super.updateBefore(frame); } finally { light.target = target; }
|
|
51
|
+
}
|
|
52
|
+
fit() {}
|
|
53
|
+
gameMaterials() { return []; }
|
|
54
|
+
/** The light's shadow values reach the cascades (the node itself scales bias by cascade: bias x (i + 1), kept) */
|
|
55
|
+
shadowParams() {
|
|
56
|
+
const s = /** @type {any} */ (this.light).shadow;
|
|
57
|
+
this.lights.forEach((l, i) => {
|
|
58
|
+
Object.assign(l.shadow, { bias: s.bias * (i + 1), normalBias: s.normalBias, radius: s.radius, blurSamples: s.blurSamples, intensity: s.intensity, autoUpdate: s.autoUpdate });
|
|
59
|
+
l.shadow.mapSize.copy(s.mapSize);
|
|
60
|
+
if (s.needsUpdate) l.shadow.needsUpdate = true; // a budget asks on the light handed in; every cascade redraws with it
|
|
61
|
+
});
|
|
62
|
+
if (this.lights.length) s.needsUpdate = false; // with cascades the light's own map is never drawn, so nothing else clears it
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Per frame: follow a new camera / projection, update early after a jump. The node reads the light's direction itself, so the first argument (the WebGL
|
|
66
|
+
* cascades' direction) is unused @param {any} _ @param {number} updateEvery 1 = the shadow maps redraw every frame
|
|
67
|
+
*/
|
|
68
|
+
frame(_, updateEvery) {
|
|
69
|
+
const e = this._engine, cam = e.camera;
|
|
70
|
+
this.shadowParams();
|
|
71
|
+
if (this.camera === null) return; // not built yet: setup() takes engine.camera
|
|
72
|
+
const proj = projectionKey(cam);
|
|
73
|
+
let force = false;
|
|
74
|
+
if (this.camera !== cam || proj !== this._proj) { this.camera = cam; this._proj = proj; this.updateFrustums(); force = true; }
|
|
75
|
+
cam.updateMatrixWorld();
|
|
76
|
+
if (updateEvery <= 1) return;
|
|
77
|
+
// not updating every frame: also update early when the camera left a quarter of the nearest cascade (teleport, fast travel)
|
|
78
|
+
const near = this.breaks[0] * Math.min(cam.far, this.maxFar), w = cam.matrixWorld.elements, p = { x: w[12], y: w[13], z: w[14] }, d = (p.x - this._at.x) ** 2 + (p.y - this._at.y) ** 2 + (p.z - this._at.z) ** 2;
|
|
79
|
+
if (force || d > (near / 4) ** 2) { setShadowUpdate(e.renderer, e.scene, { now: true }); this._at = p; }
|
|
80
|
+
else if (shadowUpdatePending(e.renderer, e.scene)) this._at = p;
|
|
81
|
+
}
|
|
82
|
+
/** Switch off: the cascade lights and maps go, the light gets its plain shadow back */
|
|
83
|
+
drop() {
|
|
84
|
+
const light = /** @type {any} */ (this.light);
|
|
85
|
+
delete light.shadow.shadowNode; // three tests `!== undefined`: null would count as a node
|
|
86
|
+
for (const n of /** @type {any} */ (this)._shadowNodes) n.dispose(); // the node's own dispose() leaves the cascade maps on the GPU (private field)
|
|
87
|
+
this.dispose();
|
|
88
|
+
rebuildShadow(light);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// cascades.js looks this up when the renderer is a WebGPURenderer (the WebGL bundle never imports three/webgpu); nothing to call
|
|
93
|
+
registerWebGPUPart('cascades', Object.freeze({ create: (e, light, S) => new CascadeNode(e, light, S) }));
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Day and night as a signal. engine.uniforms.uNight is 0 by day and 1 at night; lightPool sources with `dusk` fade on this same curve, so a game's
|
|
2
|
+
// emissive windows that read uNight switch on together with the lamps instead of two curves drifting apart.
|
|
3
|
+
|
|
4
|
+
// default dusk: lights fade in as daylight drops below 0.3 (calendar daylight: about 16:50 -> fully lit at 18:00). It is only a starting value:
|
|
5
|
+
// each lightPool source may pass its own `dusk`, and a game's own fade reads uDaylight with its own edge
|
|
6
|
+
import { DEV, warnOnce } from '../core/base/validate.js';
|
|
7
|
+
import { coded } from '../core/base/errorHints.js';
|
|
8
|
+
export const DUSK = 0.3;
|
|
9
|
+
|
|
10
|
+
/** Daylight 0..1 from the 'daylight' measure (engine.audio.measure): the calendar registers it (gameplay day / night), the sky only when no
|
|
11
|
+
* calendar did (the drawn sun). Read through the measure, not e.calendar / e.sky, so render/ names no module and a game's own clock module counts
|
|
12
|
+
* the same by registering the measure. null when nothing tells day from night */
|
|
13
|
+
export const daylightOf = e => { const d = e.audio?.measures.get('daylight')?.(e); return typeof d === 'number' ? d : null; };
|
|
14
|
+
/**
|
|
15
|
+
* 0 by day, 1 at night for one dusk (daylight below which it fades in); null daylight -> 0 (the day value is kept). dusk 0 has no fade:
|
|
16
|
+
* on only while daylight is 0 (a cave mushroom that glows only in full dark); the d / dusk curve would divide by zero there
|
|
17
|
+
*/
|
|
18
|
+
export function nightOf(d, dusk) {
|
|
19
|
+
if (d === null) return 0;
|
|
20
|
+
if (dusk === 0) return d > 0 ? 0 : 1;
|
|
21
|
+
const t = Math.min(1, Math.max(0, d / dusk));
|
|
22
|
+
return 1 - t * t * (3 - 2 * t); // smoothstep: no visible kink when the fade starts or ends
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Time of day 0..1 from the 'timeOfDay' measure: the calendar registers it (the game clock), the sky only when no calendar did (its fixed time).
|
|
26
|
+
* null when nothing owns a time of day (the uniform keeps its default) */
|
|
27
|
+
const timeOfDayOf = e => { const t = e.audio?.measures.get('timeOfDay')?.(e); return typeof t === 'number' ? t : null; };
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Twice per frame, before the modules' frame hooks (an onFrame reads this frame's signal) and again just before drawing (a time jump in a hook reaches the picture
|
|
31
|
+
* in the same frame as uSunDir): the one writer of uDaylight and uTimeOfDay. They come from the measures, so whoever owns game
|
|
32
|
+
* time (the calendar, else the sky's fixed time) decides them, and a game with no sky() still has them moving. The sky writes neither.
|
|
33
|
+
* @internal core/engine/loop.js
|
|
34
|
+
* @param {any} e
|
|
35
|
+
*/
|
|
36
|
+
export function writeDaylight(e) {
|
|
37
|
+
const d = daylightOf(e), t = timeOfDayOf(e), w = e._daySignals ??= signalWatch(e, { uDaylight: "engine.audio.measure('daylight', () => value)", uTimeOfDay: "engine.audio.measure('timeOfDay', () => value)" });
|
|
38
|
+
w.check();
|
|
39
|
+
e.uniforms.uNight.value = nightOf(d, DUSK);
|
|
40
|
+
if (d !== null) e.uniforms.uDaylight.value = d;
|
|
41
|
+
if (t !== null) e.uniforms.uTimeOfDay.value = t;
|
|
42
|
+
w.mark();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Dev: signals with one writer that rewrites them every frame. These have an entry of their own, so they are not owned values (a write has somewhere better to go),
|
|
47
|
+
* but a direct write used to vanish without a word, the bug core/ops/owned.js exists to prevent: warn once with the entry. Release builds do nothing.
|
|
48
|
+
* @internal @param {any} e @param {Record<string, string>} exits signal name -> the line that changes it
|
|
49
|
+
*/
|
|
50
|
+
export function signalWatch(e, exits) {
|
|
51
|
+
const names = Object.keys(exits), last = new Map(), read = n => { const v = e.uniforms[n].value; return v?.isColor ? v.getHex() : v; };
|
|
52
|
+
return {
|
|
53
|
+
check() { if (DEV) for (const n of names) if (last.has(n) && last.get(n) !== read(n)) warnOnce(coded('signal-overwritten', `engine.uniforms.${n} was written directly, and the engine rewrites it every frame, so the write is lost. Use: ${exits[n]}`), `signal-overwritten:${n}`); },
|
|
54
|
+
mark() { if (DEV) for (const n of names) last.set(n, read(n)); },
|
|
55
|
+
};
|
|
56
|
+
}
|