threedog 0.5.0 → 0.7.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 +81 -1
- package/README.md +21 -13
- package/core/Assets.js +23 -12
- package/core/Audio.js +1 -1
- package/core/Baked.js +14 -23
- package/core/Budget.js +2 -2
- package/core/DebugOverrides.js +33 -18
- package/core/Describe.js +10 -11
- package/core/Engine.js +50 -46
- package/core/I18n.js +2 -2
- package/core/Input.js +11 -5
- package/core/Inspect.js +6 -3
- package/core/InspectMaterials.js +2 -3
- package/core/InspectPerf.js +11 -4
- package/core/MaterialInfo.js +7 -5
- package/core/Rays.js +7 -2
- package/core/Stream.js +2 -3
- package/core/UrlState.js +49 -9
- package/core/Views.js +1 -0
- package/core/adaptive.js +2 -2
- package/core/assetEntry.js +5 -2
- package/core/assetLoad.js +13 -15
- package/core/assetManifest.js +6 -3
- package/core/assetReport.js +4 -4
- package/core/batchGroups.js +9 -1
- package/core/catalog.js +16 -3
- package/core/chunkStream.js +1 -1
- package/core/copies.js +1 -1
- package/core/debugView.js +4 -4
- package/core/describeRender.js +104 -28
- package/core/describeText.js +6 -6
- package/core/errorCodes.js +72 -45
- package/core/errorHints.js +4 -1
- package/core/errors.js +4 -4
- package/core/events.generated.js +1 -0
- package/core/gameLights.js +9 -2
- package/core/lifecycle.js +2 -4
- package/core/lightWatch.js +5 -3
- package/core/loop.js +18 -11
- package/core/math.js +7 -0
- package/core/moduleSlots.js +32 -7
- package/core/moduleTypes.js +20 -7
- package/core/modules.js +7 -7
- package/core/namedModel.js +8 -4
- package/core/owned.js +33 -30
- package/core/page.js +43 -10
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +64 -96
- package/core/sceneDelta.js +12 -4
- package/core/sceneMethods.js +2 -9
- package/core/services.js +1 -1
- package/core/shadowTypes.js +1 -1
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +5 -19
- package/core/stackFrames.js +16 -5
- package/core/stacks.js +6 -6
- package/core/startup.js +9 -11
- package/core/thingExplain.js +1 -1
- package/core/things.js +1 -1
- package/core/tier.js +1 -1
- package/core/util.js +1 -1
- package/core/validate.js +1 -1
- package/core/view.js +43 -0
- package/docs/AI.md +62 -58
- package/docs/API.md +15 -15
- package/docs/CODEMAP.md +36 -54
- package/docs/COMMANDS.md +28 -25
- package/docs/CONVENTIONS.md +36 -30
- package/docs/MIGRATING-0.4.md +93 -1
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/THREE.md +24 -22
- package/docs/api/assets.md +5 -3
- package/docs/api/audio.md +2 -2
- package/docs/api/budget.md +4 -0
- package/docs/api/characters.md +3 -1
- package/docs/api/collision.md +2 -2
- package/docs/api/engine.md +47 -20
- package/docs/api/events.md +2 -1
- package/docs/api/grids.md +8 -1
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +3 -0
- package/docs/api/input.md +3 -2
- package/docs/api/interactions.md +3 -1
- package/docs/api/inventory.md +1 -2
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +1 -1
- package/docs/api/occlusion.md +5 -0
- package/docs/api/particles.md +6 -3
- package/docs/api/pickups.md +6 -0
- package/docs/api/post.md +5 -3
- package/docs/api/sky.md +12 -10
- package/docs/api/terrain.md +12 -6
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/tools.md +8 -7
- package/docs/api/triggers.md +2 -0
- package/docs/api/vegetation.md +7 -2
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +6 -2
- package/docs/api/weather.md +5 -0
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +19 -23
- package/docs/recipes/03-items-pickups.md +25 -4
- package/docs/recipes/05-props-bake.md +53 -37
- package/docs/recipes/06-clock-events.md +3 -3
- package/docs/recipes/07-flow-scenes-pause.md +12 -3
- package/docs/recipes/08-weather-sky.md +45 -57
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +2 -2
- package/docs/recipes/11-vehicles.md +3 -3
- package/docs/recipes/13-animation.md +13 -7
- package/docs/recipes/14-custom-module.md +7 -5
- package/docs/recipes/15-perf.md +3 -3
- package/docs/recipes/16-dev-bridge.md +22 -12
- package/docs/recipes/18-world.md +10 -8
- package/docs/recipes/19-shooting-picking.md +7 -5
- package/docs/recipes/20-content-actions-save.md +6 -2
- package/docs/recipes/21-camera.md +8 -3
- package/docs/recipes/23-ops.md +1 -1
- package/docs/recipes/26-ui-parts.md +35 -11
- package/docs/recipes/28-terrain.md +12 -12
- package/docs/recipes/29-grid.md +14 -5
- package/docs/recipes/30-templates.md +8 -3
- package/docs/recipes/31-audio.md +4 -4
- package/docs/recipes/32-action-game.md +18 -4
- package/docs/recipes/34-environment-lighting.md +102 -38
- package/docs/recipes/35-picture-from-reference.md +147 -0
- package/docs/recipes/36-sky-ground-plants.md +158 -0
- package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -13
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +106 -27
- package/docs/recipes/42-terrain-shape.md +1 -1
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +121 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +10 -12
- package/docs/recipes/49-game-module-contract.md +1 -1
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +181 -0
- package/docs/recipes/53-ground-up-close.md +12 -12
- package/docs/recipes/54-three-idioms.md +18 -18
- package/docs/recipes/55-mods-time-wrap.md +17 -5
- package/docs/recipes/56-webgpu-tsl.md +66 -23
- package/docs/recipes/57-control.md +39 -0
- 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 +39 -24
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +244 -0
- package/docs/recipes/63-third-person-start.md +77 -0
- package/docs/recipes/64-particles.md +35 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +7 -5
- 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/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/FINDINGS.md +53 -0
- package/examples/plain-picture/GAMEMAP.md +90 -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 +8 -3
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +25 -33
- 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/sheepisland/.threedog/content-index.json +1 -1
- package/examples/sheepisland/GAMEMAP.md +13 -10
- package/examples/sheepisland/assets.js +2 -2
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +15 -9
- package/examples/sheepisland/{style/models.js → models.js} +13 -24
- package/examples/sheepisland/picture/index.js +20 -0
- package/examples/sheepisland/picture/lights.js +34 -0
- package/examples/sheepisland/picture/materials.js +61 -0
- package/examples/sheepisland/picture/palette.js +60 -0
- package/examples/sheepisland/picture/sky.js +20 -0
- package/examples/sheepisland/views.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -11
- 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 +30 -67
- 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 +4 -3
- 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 +5 -3
- 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 +9 -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 +15 -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 +7 -16
- package/index.js +7 -7
- package/llms.txt +15 -13
- package/modules/ambience/Ambience.js +1 -1
- package/modules/calendar/Calendar.js +1 -1
- package/modules/calendar/index.js +1 -0
- package/modules/camera/FirstPersonCamera.js +1 -1
- package/modules/camera/FixedCamera.js +2 -2
- package/modules/camera/RtsCamera.js +1 -1
- package/modules/camera/common.js +7 -5
- package/modules/characters/Character.js +15 -10
- package/modules/characters/NPC.js +5 -5
- package/modules/characters/assetModel.js +5 -4
- package/modules/characters/index.js +28 -3
- package/modules/characters/movers/common.js +6 -1
- package/modules/characters/movers/manual.js +3 -0
- package/modules/characters/movers/support.js +25 -11
- package/modules/characters/npcSim.js +5 -1
- package/modules/characters/proceduralRig.js +18 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/collision/Collision.js +4 -2
- package/modules/content/index.js +8 -0
- package/modules/content/models.js +56 -11
- package/modules/content/props.js +5 -3
- package/modules/content/rules.js +12 -4
- package/modules/content/templates.js +5 -3
- package/modules/gameplay/Interactions.js +91 -16
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +1 -1
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -2
- package/modules/gameplay/pickups.js +62 -24
- package/modules/gameplay/questLog.js +2 -2
- package/modules/grid/Layer.js +13 -0
- package/modules/grid/index.js +40 -11
- package/modules/grid/preview.js +24 -15
- package/modules/grid/tiles.js +15 -19
- package/modules/hlod/index.js +3 -2
- package/modules/hud/index.js +13 -0
- package/modules/hud/parts.js +9 -7
- package/modules/level/index.js +5 -4
- package/modules/lights/index.js +12 -8
- package/modules/music/Music.js +1 -1
- package/modules/particles/Particles.js +41 -20
- package/modules/particles/effect.js +21 -6
- package/modules/photo/Photo.js +11 -10
- package/modules/settings/Settings.js +7 -7
- package/modules/settings/apply.js +5 -5
- package/modules/settings/sections.js +2 -2
- package/modules/settings/strings.js +1 -1
- package/modules/sky/Sky.js +104 -89
- package/modules/sky/clouds.js +16 -17
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +5 -5
- package/modules/sky/environment.js +45 -169
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +26 -90
- package/modules/sky/season.js +3 -3
- package/modules/sky/shader.js +35 -29
- package/modules/sky/skyModule.js +25 -22
- package/modules/sky/tint.js +9 -11
- package/modules/terrain/ChunkManager.js +29 -12
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +44 -66
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +1 -1
- package/modules/terrain/terrainGen.js +2 -2
- package/modules/triggers/index.js +10 -6
- package/modules/vegetation/Vegetation.js +58 -17
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +1 -1
- package/modules/vegetation/index.js +10 -10
- package/modules/water/Water.js +135 -88
- package/modules/water/surface.js +53 -53
- package/modules/weather/Weather.js +52 -17
- package/modules/weather/particles.js +13 -5
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +2 -2
- package/modules/world/views.js +1 -1
- package/package.json +3 -2
- package/presets.js +2 -2
- package/render/PostFX.js +199 -41
- package/render/backend.js +52 -6
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +5 -5
- package/render/effects.js +41 -26
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/index.js +7 -5
- package/render/fx/patchNodes.tsl.js +1 -1
- package/render/fx/postWebGPU.tsl.js +30 -7
- package/render/fx/sky.tsl.js +19 -92
- package/render/fx/water.tsl.js +1 -1
- package/render/layers.js +14 -0
- package/render/lighting.js +6 -5
- package/render/lightmap.js +142 -0
- package/render/lights.js +23 -201
- package/render/materials.js +44 -160
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +1 -1
- package/render/patches.js +34 -29
- package/render/postWebGL.js +11 -3
- package/render/probes.js +179 -122
- package/render/slots.js +4 -4
- package/render/terms.js +53 -101
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +333 -296
- package/types/gameplay.d.ts +65 -26
- package/types/generated/core/Audio.d.ts +1 -1
- package/types/generated/core/DebugOverrides.d.ts +14 -6
- package/types/generated/core/Input.d.ts +9 -2
- package/types/generated/core/page.d.ts +9 -2
- package/types/generated/modules/grid/Layer.d.ts +8 -0
- package/types/generated/modules/grid/index.d.ts +29 -5
- package/types/generated/modules/particles/Particles.d.ts +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -18
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +33 -3
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +2 -2
- package/types/generated/render/PostFX.d.ts +53 -10
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +19 -44
- package/types/generated/render/occlusion.d.ts +13 -0
- package/types/physics.d.ts +5 -3
- package/types/tsl.d.ts +8 -0
- package/types/world.d.ts +376 -57
- package/ui/Focus.js +12 -2
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +8 -4
- package/ui/UI.js +10 -10
- package/ui/cursor.js +1 -1
- package/ui/theme.js +33 -27
- package/ui/touchPart.js +1 -1
- 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/styleParts.js +0 -114
- 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/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/examples/action/look.js +0 -5
- 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/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// The world example's look: one folder = one style (recipes/09-style.md). Starting values only; the game and effects change them on top
|
|
2
|
-
// (engine.look.<part>.set, weather, settings). The trees, rocks and the humanoid body are this example's art (../art/), not part of the look:
|
|
3
|
-
// the material roles below decide how they are shaded.
|
|
4
|
-
// A style folder also brings look plugins (a sky, a post effect, a material per role...): each file the same shapes as the game's plugins/
|
|
5
|
-
// folder. This one brings its bloom that way (plugins/10-bloom.js); a Vite game lists the folder with import.meta.glob('./plugins/*.js', { eager: true }).
|
|
6
|
-
import * as bloom from './plugins/10-bloom.js';
|
|
7
|
-
import { PALETTE } from '../art/models.js';
|
|
8
|
-
|
|
9
|
-
/** @type {import('threedog').Style} */
|
|
10
|
-
export default {
|
|
11
|
-
name: 'world',
|
|
12
|
-
exposure: 1.05,
|
|
13
|
-
toneMapping: 'aces',
|
|
14
|
-
background: 0xcfe6f2,
|
|
15
|
-
plugins: { './plugins/10-bloom.js': bloom },
|
|
16
|
-
|
|
17
|
-
// the material per role: look.materials' style layer (makeMaterial(role) reads it; the game's look.materials.set goes on top)
|
|
18
|
-
materials: {
|
|
19
|
-
default: { type: 'lambert' },
|
|
20
|
-
water: { type: 'phong', shininess: 90, specular: 0x9ac8e0 },
|
|
21
|
-
pickup: { flatShading: true, emissive: 0x403418 }, // the item's own color is the base color
|
|
22
|
-
// the roles the humanoid body uses (art/humanoid.js)
|
|
23
|
-
cloth: { flatShading: true, color: 0xd9774a }, skin: { flatShading: true, color: 0xf1c9a5 },
|
|
24
|
-
trousers: { flatShading: true, color: 0x3f4a5c }, hair: { flatShading: true, color: 0x4a3426 },
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
palette: PALETTE, // the colors the procedural art reads (art/models.js); style: [style, { palette: { leaf } }] retints every tree
|
|
28
|
-
clouds: { shadow: 0.55, scale: 0.006, speed: [0.012, 0.006] },
|
|
29
|
-
|
|
30
|
-
// ground type colors; the type names come from terrainPreset() of @threedog/terrain-noise
|
|
31
|
-
terrain: {
|
|
32
|
-
config: { shading: 'flat' },
|
|
33
|
-
colors: { sand: 0xe2cf9c, meadowA: 0x95c45e, meadowB: 0x80b350, forestA: 0x6aa04a, forestB: 0x5a9142, savannaA: 0xc9bd6e, savannaB: 0xb3a85c,
|
|
34
|
-
wetland: 0x6f9a5a, riverbank: 0x8fb06a, highGrass: 0x60954a, rock: 0x8f897d, rockDark: 0x77726a, snow: 0xf1efe8 },
|
|
35
|
-
biomeColors: { beach: ['sand'], snow: ['snow'], rock: ['rock', 'rockDark'], riverbank: ['riverbank', 'meadowA'], wetland: ['wetland', 'meadowB'],
|
|
36
|
-
savanna: ['savannaA', 'savannaB'], forest: ['forestA', 'forestB'], highland: ['highGrass', 'meadowB'], meadow: ['meadowA', 'meadowB'] },
|
|
37
|
-
steep: [{ maxNormalY: 0.62, colors: ['rockDark'] }, { maxNormalY: 0.78, colors: ['rock', 'rockDark'] }],
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
// [time 0-1, zenith, horizon (= fog), sun color, sun intensity, ambient intensity]
|
|
41
|
-
sky: {
|
|
42
|
-
keyframes: [
|
|
43
|
-
[0.00, 0x0b1026, 0x1d2747, 0x8fa3d6, 0.45, 0.35],
|
|
44
|
-
[0.25, 0x6f8ec4, 0xf0b48c, 0xffb27a, 1.90, 0.80],
|
|
45
|
-
[0.50, 0x4f95d8, 0xc8e4f6, 0xffffff, 3.00, 1.20],
|
|
46
|
-
[0.75, 0x5a6fb0, 0xf2a07a, 0xff9a5c, 1.90, 0.80],
|
|
47
|
-
[1.00, 0x0b1026, 0x1d2747, 0x8fa3d6, 0.45, 0.35],
|
|
48
|
-
],
|
|
49
|
-
groundTint: 0x4d5a34,
|
|
50
|
-
clouds: { color: 0xf8f6f0, shade: 0xb0b8c4, coverage: 1, scale: 0.35, speed: [0.004, 0.002] },
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
water: { color: 0x4f9cc0, opacity: 0.85, flat: true, fresnel: 0.5 },
|
|
54
|
-
pickup: { color: 0xf0d27a, size: 0.25, lift: 0.4 },
|
|
55
|
-
ui: { bg: 'rgba(24,22,18,.9)', fg: '#f3eee2', muted: '#a8a294', accent: '#f0b450', line: 'rgba(255,255,255,.15)', radius: '12px' },
|
|
56
|
-
particles: {
|
|
57
|
-
dust: { max: 200, lifetime: [0.5, 1.1], speed: [0.6, 1.8], direction: [0, 1, 0], spread: 1.2, gravity: -1.5, drag: 2, size: [0.25, 0.6], color: [0xd8c8a0, 0xc8b890], opacity: [0.6, 0] },
|
|
58
|
-
smoke: { max: 120, rate: 6, lifetime: [3, 5], speed: [0.4, 0.8], direction: [0.2, 1, 0], spread: 0.25, gravity: 0.15, drag: 0.4, size: [0.6, 2.2], color: [0xc8c4bc, 0xe8e6e2], opacity: [0.55, 0] },
|
|
59
|
-
leaves: { max: 150, lifetime: [3, 6], speed: [0.3, 1], direction: [1, -0.4, 0.3], spread: 1, gravity: -0.6, drag: 1.2, size: [0.18, 0.18], color: [0xd99a4a, 0xb86a30], opacity: [1, 0], spin: 3 },
|
|
60
|
-
},
|
|
61
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// The world look's bloom: a post effect plugin of the style (look.post.add puts it in the chain; look.post.set({ bloom: false }) or
|
|
2
|
-
// engine.plugins.off('world/10-bloom') turns it off). Costly: starts off on low-tier devices.
|
|
3
|
-
import { bloom } from '@threedog/post-effects';
|
|
4
|
-
|
|
5
|
-
export default bloom({ strength: 0.35, radius: 0.5, threshold: 0.85 });
|
package/modules/sky/cascades.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
// Sky cascaded shadows (helper of shadow.js), off by default (shadow.cascades 1 = one shadow map, exactly the single-map path).
|
|
2
|
-
// shadow.cascades 2-4 splits the sun's shadow along the view into that many maps (three's CSM addon): sharp near the camera, wide far away.
|
|
3
|
-
// Design choices, each one because the addon used as-is would break something:
|
|
4
|
-
// - engine.lights.sun stays in charge and is the nearest cascade, so the sky keeps driving its color / intensity / direction, the dev
|
|
5
|
-
// guards keep watching it. The other cascades are extra
|
|
6
|
-
// DirectionalLights that copy the sun's 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/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.look.shadow.include(mat), which opts it in.
|
|
19
|
-
// - csm.update() runs only on frames whose shadow maps re-render (shadow.updateEvery), else lights move while the maps stay old.
|
|
20
|
-
// On WebGPURenderer all of the above is replaced by three's CSMShadowNode on the sun (cascades.tsl.js, registered by threedog/tsl): one light,
|
|
21
|
-
// so no patch, no scene walk, and look.shadow.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 '../../render/patches.js';
|
|
26
|
-
|
|
27
|
-
import { warnOnce } from '../../core/validate.js';
|
|
28
|
-
import { sceneVisitor } from '../../core/sceneDelta.js';
|
|
29
|
-
import { codedError } from '../../core/errorHints.js';
|
|
30
|
-
import { setShadowUpdate, shadowUpdatePending, isWebGPU, webgpuPart } from '../../render/backend.js';
|
|
31
|
-
import { shadowsOn } from '../../core/look/shadowPart.js';
|
|
32
|
-
|
|
33
|
-
const LIT = new Set(['MeshLambertMaterial', 'MeshPhongMaterial', 'MeshStandardMaterial', 'MeshPhysicalMaterial', 'MeshToonMaterial']);
|
|
34
|
-
const litShader = m => m.isShaderMaterial && m.lights && m.fragmentShader.includes('#include <lights_fragment_begin>');
|
|
35
|
-
/** ShaderMaterials the game opted in with engine.look.shadow.include(mat) (per engine: the sky owns it) */
|
|
36
|
-
const optedIn = sky => sky._csmInclude ??= new WeakSet();
|
|
37
|
-
/**
|
|
38
|
-
* engine.look.shadow.include(material): let the cascades patch a ShaderMaterial (lights: true) of yours. Built-in lit materials need nothing.
|
|
39
|
-
* @example engine.look.shadow.include(myLitShaderMaterial);
|
|
40
|
-
*/
|
|
41
|
-
export function includeInCascades(sky, m) {
|
|
42
|
-
if (!m?.isMaterial) throw codedError('sky-option', `engine.look.shadow.include(material): needs a three.js Material; got ${m}. Example: engine.look.shadow.include(myShaderMaterial)`);
|
|
43
|
-
if (m.isShaderMaterial && !litShader(m)) throw codedError('sky-option', "engine.look.shadow.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");
|
|
44
|
-
if (isWebGPU(sky.engine.renderer)) { // the cascades are the sun's shadow node there: every material is lit once without opting in
|
|
45
|
-
warnOnce('engine.look.shadow.include(mat) does nothing on WebGPURenderer: cascaded shadows there are one light (three CSMShadowNode) and patch no material');
|
|
46
|
-
return m;
|
|
47
|
-
}
|
|
48
|
-
optedIn(sky).add(m);
|
|
49
|
-
if (sky.csm?.mats.has(m)) sky.csm.fit(m); // already looked at and left alone: patch it now (fit is per material, so no scene walk)
|
|
50
|
-
return m;
|
|
51
|
-
}
|
|
52
|
-
const lit = (sky, m) => {
|
|
53
|
-
if (LIT.has(m.type)) return true;
|
|
54
|
-
if (!litShader(m)) return false;
|
|
55
|
-
if (optedIn(sky).has(m)) return true;
|
|
56
|
-
warnOnce(`cascaded shadows: engine.look.shadow.include(mat) opts ShaderMaterial '${m.name || m.uuid.slice(0, 8)}' in. Until then it has lights: true and is lit by all ` +
|
|
57
|
-
`${sky.csm?.lights.length ?? 'the'} cascade lights (too bright, doubled shadows): the engine does not patch your own shader code unasked`);
|
|
58
|
-
return false;
|
|
59
|
-
};
|
|
60
|
-
const SPLITS = ['practical', 'uniform', 'logarithmic'];
|
|
61
|
-
const STRINGS = {
|
|
62
|
-
count: 'look.shadow.set({ cascades }): a whole number 1 (one shadow map, the default) to 4; got {got}',
|
|
63
|
-
split: "look.shadow.set({ split }): 'practical' (default) | 'uniform' | 'logarithmic' | (count, near, far, out) => void; got {got}",
|
|
64
|
-
maxFar: 'look.shadow.set({ maxFar }): meters from the camera that cascades cover, a number > 0; got {got}',
|
|
65
|
-
noSun: "look.shadow.set({ cascades }): cascaded shadows split the engine sun's shadow, and sky({ sun: false }) has no engine sun. " +
|
|
66
|
-
"With your own lights use three's CSM addon on them, or keep sun: true / 'manual'",
|
|
67
|
-
};
|
|
68
|
-
const bad = (k, v) => { throw codedError('sky-option', STRINGS[k].replace('{got}', JSON.stringify(v) ?? String(v))); };
|
|
69
|
-
|
|
70
|
-
/** Throw on cascade fields a look.shadow.set call gets wrong, before anything is applied */
|
|
71
|
-
export function checkCascades(sky, o) {
|
|
72
|
-
if (o.cascades !== undefined && !(Number.isInteger(o.cascades) && o.cascades >= 1 && o.cascades <= 4)) bad('count', o.cascades);
|
|
73
|
-
if (o.split !== undefined && typeof o.split !== 'function' && !SPLITS.includes(o.split)) bad('split', o.split);
|
|
74
|
-
if (o.maxFar !== undefined && !(o.maxFar > 0)) bad('maxFar', o.maxFar);
|
|
75
|
-
if (o.cascades > 1 && sky._drive.sun === false) bad('noSun');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// The addon's split / frustum / texel-snapped placement, with the sun as cascade 0 and the chunk swap left to the 'csm' patch
|
|
79
|
-
class SkyCSM extends CSM {
|
|
80
|
-
constructor(sky, S) {
|
|
81
|
-
const e = sky.engine, custom = typeof S.split === 'function';
|
|
82
|
-
super({ camera: e.camera, parent: e.scene, cascades: S.cascades, maxFar: S.maxFar, mode: custom ? 'custom' : S.split, customSplitsCallback: custom ? S.split : undefined,
|
|
83
|
-
shadowMapSize: sky._sun.shadow.mapSize.x, shadowBias: S.bias, lightMargin: S.lightMargin, lightNear: 1, lightFar: S.lightMargin + 2 * S.maxFar });
|
|
84
|
-
const first = this.lights[0];
|
|
85
|
-
this.parent.remove(first, first.target); first.dispose();
|
|
86
|
-
this.lights[0] = sky._sun;
|
|
87
|
-
// uniforms shared by every patched material: one write here reaches all of them
|
|
88
|
-
this.uniforms = { CSM_cascades: { value: [] }, cameraNear: { value: 0 }, shadowFar: { value: 0 } };
|
|
89
|
-
this.fade = S.fade;
|
|
90
|
-
this.updateFrustums();
|
|
91
|
-
// cacheKey is new for every build: three keeps a material's old programs and, when a key comes back (cascades off, then on again),
|
|
92
|
-
// reuses that program with the uniforms map of the material's latest compile, which lacks these uniforms, so the GPU would keep the
|
|
93
|
-
// old build's split and far values (shadows vanish where the old cascade 0 ended). One recompile per switch, which the light count
|
|
94
|
-
// change costs anyway; each material keeps one program per switch until it is disposed, so switch on a settings screen, not per frame
|
|
95
|
-
sky._csmBuild = (sky._csmBuild ?? 0) + 1;
|
|
96
|
-
this.patch = { name: 'csm', cacheKey: `${S.cascades}${S.fade ? 'f' : ''}.${sky._csmBuild}`, uniforms: this.uniforms, slot: 'lightingModel',
|
|
97
|
-
pars: `#define USE_CSM 1\n#define CSM_CASCADES ${S.cascades}\n${S.fade ? '#define CSM_FADE\n' : ''}` +
|
|
98
|
-
'uniform vec2 CSM_cascades[CSM_CASCADES];\nuniform float cameraNear;\nuniform float shadowFar;',
|
|
99
|
-
glsl: CSMShader.lights_fragment_begin };
|
|
100
|
-
/** material -> the patch object it carries, so a rebuilt CSM re-patches and switching off finds every material */
|
|
101
|
-
this.mats = new Map();
|
|
102
|
-
this.sky = sky;
|
|
103
|
-
this.at = new THREE.Vector3(Infinity, 0, 0); // camera position at the last placement
|
|
104
|
-
this.proj = '';
|
|
105
|
-
/** what entered the scene since the last frame (view.walks: how many full walks ran; tests read it) */
|
|
106
|
-
this.view = sceneVisitor(sky.engine.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); } });
|
|
107
|
-
}
|
|
108
|
-
fit(m) {
|
|
109
|
-
const was = this.mats.get(m);
|
|
110
|
-
if (was === this.patch || (was === null && !optedIn(this.sky).has(m))) return;
|
|
111
|
-
if (!lit(this.sky, m)) { this.mats.set(m, null); return; } // null: looked at, left alone (no per-frame recheck / rewarn)
|
|
112
|
-
patchMaterial(m, [this.patch], { strict: false }); this.mats.set(m, this.patch);
|
|
113
|
-
}
|
|
114
|
-
/** describe().owned row: the game's own materials the csm patch went on (the named exception, see the header) */
|
|
115
|
-
gameMaterials() { return [...this.mats].filter(([m, p]) => p && !isEngineMade(m)).map(([m]) => m.name || m.type); }
|
|
116
|
-
_injectInclude() {}
|
|
117
|
-
_updateUniforms() {
|
|
118
|
-
const U = this.uniforms;
|
|
119
|
-
if (!U) return; // the base constructor calls this before the uniforms exist
|
|
120
|
-
this._getExtendedBreaks(U.CSM_cascades.value);
|
|
121
|
-
U.cameraNear.value = this.camera.near; U.shadowFar.value = Math.min(this.camera.far, this.maxFar);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Create, rebuild or remove the cascades after look.shadow.set changed shadow fields; copy bias / softness to the extra lights */
|
|
126
|
-
export function syncCascades(sky) {
|
|
127
|
-
const S = sky.shadow, e = sky.engine, want = S.cascades > 1;
|
|
128
|
-
const key = want ? [S.cascades, S.maxFar, S.fade, S.lightMargin, S.split].join('|') : '';
|
|
129
|
-
if (key !== sky._csmKey) {
|
|
130
|
-
dropCascades(sky);
|
|
131
|
-
sky._csmKey = key;
|
|
132
|
-
if (want) {
|
|
133
|
-
const sc = sky._sun.shadow.camera;
|
|
134
|
-
sky._csmSaved = { left: sc.left, right: sc.right, top: sc.top, bottom: sc.bottom, near: sc.near, far: sc.far };
|
|
135
|
-
if (isWebGPU(e.renderer)) { // three's CSMShadowNode on the sun (cascades.tsl.js): no extra lights in the scene, no patches
|
|
136
|
-
let node;
|
|
137
|
-
try { node = webgpuPart('cascades', '[sky] cascaded shadows (style.sky.cascades)'); } catch (err) { sky._csmKey = ''; throw err; }
|
|
138
|
-
sky.csm = node.create(sky, S);
|
|
139
|
-
sky.csm.shadowParams(S);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
sky.csm = new SkyCSM(sky, S);
|
|
143
|
-
Object.assign(sc, { near: 1, far: sky.csm.lightFar });
|
|
144
|
-
// these lights are new to the scene: honor look.shadow enabled false the way it treats existing lights
|
|
145
|
-
for (const l of sky.csm.lights) if (l !== sky._sun) l.castShadow = shadowsOn(e);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (sky.csm?.isSkyCascadeNode) sky.csm.shadowParams(S);
|
|
149
|
-
else if (sky.csm) for (const l of sky.csm.lights) Object.assign(l.shadow, { bias: S.bias, normalBias: S.normalBias, radius: S.radius, blurSamples: S.blurSamples });
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/** Remove the cascades: extra lights out, the 'csm' patch off every material it went on, the sun's shadow box restored */
|
|
153
|
-
export function dropCascades(sky) {
|
|
154
|
-
const c = sky.csm;
|
|
155
|
-
if (!c) return;
|
|
156
|
-
if (c.isSkyCascadeNode) c.drop();
|
|
157
|
-
else {
|
|
158
|
-
for (const l of c.lights) if (l !== sky._sun) { c.parent.remove(l, l.target); l.dispose(); }
|
|
159
|
-
c.view.remove();
|
|
160
|
-
for (const [m, p] of c.mats) if (p) unpatchMaterial(m, 'csm');
|
|
161
|
-
}
|
|
162
|
-
const sc = sky._sun.shadow.camera;
|
|
163
|
-
Object.assign(sc, sky._csmSaved); sc.updateProjectionMatrix();
|
|
164
|
-
sky.csm = null; sky._csmKey = ''; sky._snapKey = '';
|
|
165
|
-
setShadowUpdate(sky.engine.renderer, sky.engine.scene, { now: true });
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** Per frame while cascades are on (instead of _placeShadow): patch materials that entered the scene, follow the camera and the light, place on shadow frames */
|
|
169
|
-
export function cascadeFrame(sky, lightDir) {
|
|
170
|
-
const c = sky.csm, e = sky.engine, cam = e.camera, sun = sky._sun, S = sky.shadow;
|
|
171
|
-
if (c.isSkyCascadeNode) { c.frame(lightDir); return; }
|
|
172
|
-
c.view.sync();
|
|
173
|
-
const proj = cam.isPerspectiveCamera ? `${cam.fov},${cam.aspect},${cam.near},${cam.far},${cam.zoom}` : `${cam.left},${cam.right},${cam.near},${cam.far},${cam.zoom}`;
|
|
174
|
-
let force = false;
|
|
175
|
-
if (c.camera !== cam || proj !== c.proj) { c.camera = cam; c.proj = proj; c.updateFrustums(); force = true; }
|
|
176
|
-
c.lightDirection.copy(lightDir).negate(); // CSM points from the light into the scene
|
|
177
|
-
const show = sun.visible && shadowsOn(e); // with shadows off the extra lights would only add light: hide them
|
|
178
|
-
for (const l of c.lights) if (l !== sun) { l.color.copy(sun.color); l.intensity = sun.intensity; l.visible = show; }
|
|
179
|
-
cam.updateMatrixWorld();
|
|
180
|
-
// not updating every frame: also place early when the camera left a quarter of the nearest cascade (teleport, fast travel)
|
|
181
|
-
const near = c.breaks[0] * Math.min(cam.far, c.maxFar);
|
|
182
|
-
if (S.updateEvery <= 1 || shadowUpdatePending(e.renderer, e.scene) || force || c.at.distanceToSquared(cam.position) > (near / 4) ** 2) {
|
|
183
|
-
c.update(); c.at.copy(cam.position);
|
|
184
|
-
if (S.updateEvery > 1) setShadowUpdate(e.renderer, e.scene, { now: true });
|
|
185
|
-
}
|
|
186
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// Sky 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 sun light (sun.shadow.shadowNode),
|
|
3
|
-
// so a material is lit by the sun 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 look.shadow.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 sun'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 sky's 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 (shadow.updateEvery > 1): 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 { CSMShadowNode } from 'three/addons/csm/CSMShadowNode.js';
|
|
16
|
-
import { setShadowUpdate, shadowUpdatePending, registerWebGPUPart } from '../../render/backend.js';
|
|
17
|
-
|
|
18
|
-
class SkyCascadeNode extends CSMShadowNode {
|
|
19
|
-
/** @param {any} sky @param {any} S sky.shadow */
|
|
20
|
-
constructor(sky, S) {
|
|
21
|
-
const custom = typeof S.split === 'function';
|
|
22
|
-
super(sky._sun, { cascades: S.cascades, maxFar: S.maxFar, mode: custom ? 'custom' : S.split, customSplitsCallback: custom ? S.split : undefined, lightMargin: S.lightMargin });
|
|
23
|
-
this.isSkyCascadeNode = true;
|
|
24
|
-
this.fade = S.fade;
|
|
25
|
-
this._sky = sky; // underscore names: three walks a node's public fields looking for child nodes
|
|
26
|
-
/** the WebGL route's material bookkeeping, empty here (nothing is patched): includeInCascades and the describe().owned row read it */
|
|
27
|
-
this.mats = new Map();
|
|
28
|
-
this._at = { x: Infinity, y: 0, z: 0 }; // camera position at the last early update
|
|
29
|
-
this._proj = '';
|
|
30
|
-
const sc = sky._sun.shadow.camera;
|
|
31
|
-
Object.assign(sc, { near: 1, far: S.lightMargin + 2 * S.maxFar }); sc.updateProjectionMatrix();
|
|
32
|
-
sky._sun.shadow.shadowNode = this;
|
|
33
|
-
rebuildShadow(sky._sun);
|
|
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._sky.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
|
-
return super.updateBefore(frame);
|
|
45
|
-
}
|
|
46
|
-
fit() {}
|
|
47
|
-
gameMaterials() { return []; }
|
|
48
|
-
/** Copy look.shadow fields to the cascades (the node itself scales bias by cascade: bias x (i + 1), kept) @param {any} S */
|
|
49
|
-
shadowParams(S) {
|
|
50
|
-
this.lights.forEach((l, i) => Object.assign(l.shadow, { bias: S.bias * (i + 1), normalBias: S.normalBias, radius: S.radius, blurSamples: S.blurSamples }));
|
|
51
|
-
}
|
|
52
|
-
/** Per frame (cascades.js cascadeFrame): aim the sun, follow a new camera / projection, update early after a jump @param {any} lightDir unit vector toward the light */
|
|
53
|
-
frame(lightDir) {
|
|
54
|
-
const sky = this._sky, e = sky.engine, cam = e.camera, sun = sky._sun, S = sky.shadow;
|
|
55
|
-
sun.position.copy(sun.target.position).addScaledVector(lightDir, sky.orbit.distance);
|
|
56
|
-
sun.updateMatrixWorld(); sun.target.updateMatrixWorld();
|
|
57
|
-
if (this.camera === null) return; // not built yet: setup() takes engine.camera
|
|
58
|
-
const proj = cam.isPerspectiveCamera ? `${cam.fov},${cam.aspect},${cam.near},${cam.far},${cam.zoom}` : `${cam.left},${cam.right},${cam.near},${cam.far},${cam.zoom}`;
|
|
59
|
-
let force = false;
|
|
60
|
-
if (this.camera !== cam || proj !== this._proj) { this.camera = cam; this._proj = proj; this.updateFrustums(); force = true; }
|
|
61
|
-
cam.updateMatrixWorld();
|
|
62
|
-
if (S.updateEvery <= 1) return;
|
|
63
|
-
// not updating every frame: also update early when the camera left a quarter of the nearest cascade (teleport, fast travel)
|
|
64
|
-
const near = this.breaks[0] * Math.min(cam.far, this.maxFar), p = cam.position, d = (p.x - this._at.x) ** 2 + (p.y - this._at.y) ** 2 + (p.z - this._at.z) ** 2;
|
|
65
|
-
if (force || d > (near / 4) ** 2) { setShadowUpdate(e.renderer, e.scene, { now: true }); this._at = { x: p.x, y: p.y, z: p.z }; }
|
|
66
|
-
else if (shadowUpdatePending(e.renderer, e.scene)) this._at = { x: p.x, y: p.y, z: p.z };
|
|
67
|
-
}
|
|
68
|
-
/** Switch off: the cascade lights and maps go, the sun gets its plain shadow back */
|
|
69
|
-
drop() {
|
|
70
|
-
const sun = this._sky._sun;
|
|
71
|
-
delete sun.shadow.shadowNode; // three tests `!== undefined`: null would count as a node
|
|
72
|
-
for (const n of /** @type {any} */ (this)._shadowNodes) n.dispose(); // the node's own dispose() leaves the cascade maps on the GPU (private field)
|
|
73
|
-
this.dispose();
|
|
74
|
-
rebuildShadow(sun);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Make three's light node drop the shadow it cached (AnalyticLightNode listens for the light's 'dispose'; its version bump recompiles) */
|
|
79
|
-
function rebuildShadow(light) { light.dispatchEvent({ type: 'dispose' }); }
|
|
80
|
-
|
|
81
|
-
// cascades.js looks this up when the renderer is a WebGPURenderer (the WebGL bundle never imports three/webgpu); nothing to call
|
|
82
|
-
registerWebGPUPart('cascades', Object.freeze({ create: (sky, S) => new SkyCascadeNode(sky, S) }));
|
package/modules/sky/look.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// Sky look setup (helper of Sky.js): which engine lights the sky drives, the fog model, extra dome layers.
|
|
2
|
-
// Light modes, sky() options only (whether the engine's two lights exist is how the game lights its world, not a swappable look):
|
|
3
|
-
// sky({ sun: true }) default: the sky drives engine.lights.sun (color, intensity, direction, shadow box) from the keyframes
|
|
4
|
-
// sky({ sun: false }) hidden (visible = false, no shadows) and never touched: light the world with your own three.js lights
|
|
5
|
-
// sky({ hemisphere: true | false }) the same for engine.lights.hemi (ambient)
|
|
6
|
-
// sky({ fog: true | false }) scene.fog: true (default) the sky creates it and writes color and distance every frame | false scene.fog = null
|
|
7
|
-
// and never touched. An object here is style.sky.fog settings (= true)
|
|
8
|
-
// Keeping a light / the fog but writing it yourself is not a sky() option: one takeover entry per look value (2026-11-02), engine.look.lights.manual(
|
|
9
|
-
// 'sun' | 'hemi' | 'sun.intensity' ...) and engine.look.fog.manual() (core/owned.js). manual(key, false) hands it back, and a direct write without
|
|
10
|
-
// either takes it too (the sky yields and warns once). The removed 'manual' mode throws and names that call, so old code learns the one way.
|
|
11
|
-
// Hidden lights are left in the scene (visible = false): three skips them, and toggling visible later recompiles like adding a light would.
|
|
12
|
-
import * as THREE from 'three';
|
|
13
|
-
import { resolveFog, DOME_FOG } from './fog.js';
|
|
14
|
-
import { resolveDomeLayers } from './domeLayers.js';
|
|
15
|
-
import { codedError } from '../../core/errorHints.js';
|
|
16
|
-
import { isWebGPU } from '../../render/backend.js';
|
|
17
|
-
|
|
18
|
-
const TAKE = { sun: "engine.look.lights.manual(['sun.intensity', 'sun.color'])", hemisphere: "engine.look.lights.manual('hemi')", fog: 'engine.look.fog.manual()' };
|
|
19
|
-
const modeOf = (name, v = true) => {
|
|
20
|
-
if (v === 'manual') throw codedError('sky-option', `sky({ ${name}: 'manual' }) is not an option; keep the default and take it over after engine.use(sky()) with ${TAKE[name]} (manual(..., false) hands it back)`);
|
|
21
|
-
if (v !== true && v !== false) throw codedError('sky-option', `sky({ ${name} }) must be true (the sky drives it) or false (${name === 'fog' ? 'no fog' : 'hidden, light the world yourself'}); to write it yourself: ${TAKE[name]}; got ${JSON.stringify(v)}`);
|
|
22
|
-
return v;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/** Resolve light modes, fog and dome layers for a new Sky; returns the extra dome uniforms and GLSL ({ uniforms, decl, body }), and the layers for a node dome */
|
|
26
|
-
export function prepareLook(sky, st, over) {
|
|
27
|
-
/** @internal which engine lights / fog the sky writes each frame: true / false */
|
|
28
|
-
// fog is also the look override (an object of style.sky.fog settings, which means true); a boolean picks the mode and keeps the style's settings
|
|
29
|
-
const fogObj = over.fog != null && typeof over.fog === 'object';
|
|
30
|
-
sky._drive = { sun: modeOf('sun', over.sun), hemi: modeOf('hemisphere', over.hemisphere), fog: fogObj ? true : modeOf('fog', over.fog) };
|
|
31
|
-
const { sun, hemi } = sky.engine.lights;
|
|
32
|
-
if (sky._drive.sun === false) { sun.visible = false; sun.castShadow = false; }
|
|
33
|
-
if (sky._drive.hemi === false) hemi.visible = false;
|
|
34
|
-
/** @internal resolved fog settings (fog.js) */
|
|
35
|
-
sky._fogSpec = fogObj || over.fog == null ? st.fog : sky.engine.style.sky?.fog; // look.fog's style layer (lookFog.js)
|
|
36
|
-
sky._fog = resolveFog(sky._fogSpec);
|
|
37
|
-
sky._backdrop = resolveBackdrop(st);
|
|
38
|
-
const f = DOME_FOG, l = resolveDomeLayers(st.layers, { gpu: isWebGPU(sky.engine.renderer) });
|
|
39
|
-
// the fog object is created after the dome and may be replaced by the game: read its color at draw time (fog.js fogBand turns the band on)
|
|
40
|
-
const uniforms = { ...l.uniforms, uFogBand: { value: 0 }, uFogColor: { get value() { return sky.engine.scene.fog?.color ?? sky.uniforms.uHorizon.value; } } };
|
|
41
|
-
return { uniforms, decl: [f.decl, l.decl].filter(Boolean).join('\n'), body: f.body + l.body, layers: l.layers };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// style.sky.backdrop: one flat color (or ({ time, weather, season, state, sky }) => color each frame, core/look/state.js) instead of the dome -- no gradient, horizon, sun / moon disk,
|
|
45
|
-
// stars or clouds. The color goes straight to scene.background (no tone mapping), so what is written is what shows; the keyframes
|
|
46
|
-
// still light the world, and fog in its default 'horizon' color follows the backdrop so far things fade into it.
|
|
47
|
-
export function resolveBackdrop(st) {
|
|
48
|
-
const v = st.backdrop;
|
|
49
|
-
if (v == null) return null;
|
|
50
|
-
const color = typeof v === 'number' || typeof v === 'string' || v.isColor;
|
|
51
|
-
if (!color && typeof v !== 'function') throw codedError('sky-option', `style.sky.backdrop must be a color (0xefebe4, '#efebe4') or ({ time, state }) => color; got ${JSON.stringify(v)}`);
|
|
52
|
-
if (st.skybox) throw codedError('sky-option', 'style.sky: backdrop and skybox both replace the dome; keep one (backdrop for a flat color, skybox for a panorama)');
|
|
53
|
-
return { fn: color ? null : v, color: new THREE.Color(color ? v : 0x000000) };
|
|
54
|
-
}
|
package/modules/sky/lookFog.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// look.fog: the sky's fog as a look part. set({ kind, color, density, near, far, height, falloff, enabled }), patch('fog', glsl); manual() stops the sky writing scene.fog.
|
|
2
|
-
// A fog of your own is plain three.js (scene.fog = new THREE.Fog(...)): the engine yields, there is no look.fog.replace.
|
|
3
|
-
// The sky still writes color and distance every frame (updateFog in fog.js) from the resolved values, so a game set() simply changes what it writes.
|
|
4
|
-
// kind 'exp' / 'height', height, falloff and the 'fog' hook are the 'fog' shader patch (fog.js): changing them re-patches the materials, which
|
|
5
|
-
// recompile once (cost 'shader'), so they work any time but belong on a settings change, not every frame. color, density, near, far, enabled and
|
|
6
|
-
// kind 'linear' <-> 'exp2' are uniforms. Color switches freely at runtime between 'horizon', a fixed color and a function: the dome's fog band (a
|
|
7
|
-
// fog-colored fade so the horizon line hides) follows by a uniform (fog.js DOME_FOG).
|
|
8
|
-
// Who writes scene.fog has one record, the owned 'fog' entry (frame.js): a direct write yields it, manual() takes it on purpose, manual(false) hands it back.
|
|
9
|
-
import { defineLookPart } from '../../core/look/part.js';
|
|
10
|
-
import { FOG_FAR } from '../../core/sceneMethods.js';
|
|
11
|
-
import { resolveFog, makeFog, setFogPatch, FOG_KINDS, FOG_NEAR, FOG_SIGNATURE, startFar } from './fog.js';
|
|
12
|
-
|
|
13
|
-
const NEEDS_GLSL = 'needs GLSL that defines `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)` returning (fog rgb, amount 0..1)';
|
|
14
|
-
/** The 'fog' hook value: GLSL text, or { glsl?, tsl? } with at least one (glsl for WebGLRenderer, tsl: (ctx) => vec4 node for WebGPURenderer) */
|
|
15
|
-
const fogHookProblem = v => {
|
|
16
|
-
if (typeof v === 'string') return FOG_SIGNATURE.test(v) ? null : NEEDS_GLSL;
|
|
17
|
-
if (!v || typeof v !== 'object' || (v.glsl == null && v.tsl == null)) return `${NEEDS_GLSL}, or { glsl, tsl: (ctx) => vec4 node } (tsl draws on WebGPURenderer)`;
|
|
18
|
-
if (v.glsl != null && !(typeof v.glsl === 'string' && FOG_SIGNATURE.test(v.glsl))) return `glsl ${NEEDS_GLSL}`;
|
|
19
|
-
if (v.tsl != null && typeof v.tsl !== 'function') return 'tsl must be (ctx) => vec4 node (fog rgb, amount)';
|
|
20
|
-
const extra = Object.keys(v).filter(k => k !== 'glsl' && k !== 'tsl');
|
|
21
|
-
return extra.length ? `takes { glsl, tsl } only; got ${extra.join(', ')} (no custom uniforms: write constants in the code)` : null;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/** @param {any} sky @param {object} spec the style.sky.fog settings in use (look.js keeps them in sky._fogSpec) */
|
|
25
|
-
export function defineFogLook(sky, spec) {
|
|
26
|
-
const e = sky.engine, scene = e.scene;
|
|
27
|
-
let part;
|
|
28
|
-
|
|
29
|
-
const rebuild = () => {
|
|
30
|
-
const v = part.author.values(), hook = part.value('hook:fog');
|
|
31
|
-
const f = resolveFog({ kind: v.kind, color: v.color, density: v.density ?? undefined, height: v.height, falloff: v.falloff, near: v.near ?? undefined,
|
|
32
|
-
far: v.far ?? undefined, enabled: v.enabled }, hook ?? undefined);
|
|
33
|
-
if (sky._drive.fog !== false) setFogPatch(sky, f); // first: on WebGPU a GLSL hook throws there, before the settings change
|
|
34
|
-
sky._fog = f;
|
|
35
|
-
// linear is three's Fog, every other kind FogExp2: swap the object (materials recompile for it) when the kind crossed that line
|
|
36
|
-
const cur = scene.fog;
|
|
37
|
-
if ((sky._oFog ? sky._oFog.on : sky._drive.fog === true) && cur && // _oFog is registered after the fog part (frame.js)
|
|
38
|
-
(f.kind === 'linear' ? !cur.isFog : !cur.isFogExp2)) {
|
|
39
|
-
scene.fog = makeFog(f, startFar(f, e)); scene.fog.color.copy(cur.color);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
part = defineLookPart(e, {
|
|
44
|
-
id: 'fog', group: 'atmosphere', module: 'sky', object: () => scene.fog, applyAtStart: false, docs: ['recipes/52-look.md', 'recipes/38-environment-look-hooks.md'],
|
|
45
|
-
params: {
|
|
46
|
-
enabled: { type: 'bool', default: true, cost: 'uniform', desc: 'fog on / off without a recompile',
|
|
47
|
-
why: 'distant things melt into the sky and the edge of a streamed world is hidden', off: 'look.fog.set({ enabled: false }), or sky({ fog: false })' },
|
|
48
|
-
kind: { type: 'string', default: 'linear', values: FOG_KINDS, cost: 'shader', desc: "'linear' | 'exp' | 'exp2' | 'height'", neutral: true },
|
|
49
|
-
color: { type: 'any', default: 'horizon', cost: 'uniform', fn: true, desc: "'horizon' (the dome's horizon color, written every frame) | a color | ({ time, weather, season, state, sky }) => either", neutral: true },
|
|
50
|
-
density: { type: 'any', default: null, cost: 'uniform', neutral: true, fn: true, desc: 'per meter for exp / exp2 / height; null = derived so the fog reaches the same distance as linear' },
|
|
51
|
-
far: { type: 'number', default: FOG_FAR, min: 0, cost: 'uniform', fn: true, desc: "fog distance in meters; effects multiply it (weather: engine.mod('look.fog.far', { owner, mul, layer: 'effect' })); terrain({ viewFog: true }) writes its engine layer (owner 'terrainLook')",
|
|
52
|
-
why: `fog reaches full strength at ${FOG_FAR} m unless a style, the terrain view or the game says otherwise, starting at ${FOG_NEAR} x that`, off: 'look.fog.set({ enabled: false })' },
|
|
53
|
-
// not neutral: the start distance is an engine choice, so the catalog shows why and how to change it like any other default
|
|
54
|
-
near: { type: 'any', default: null, cost: 'uniform', fn: true, desc: `linear only: where the fog starts, in meters (or ({ time, weather, season, state, sky }) => meters); null = ${FOG_NEAR} x far`,
|
|
55
|
-
why: `fog starts at ${FOG_NEAR} x far so the near field stays clear while the far edge still hides the world's end`, off: 'look.fog.set({ near: 0 }) (fog from the camera on), or any distance in meters' },
|
|
56
|
-
height: { type: 'number', default: 0, neutral: true, cost: 'shader', desc: "kind 'height': the fog's floor (world y)" },
|
|
57
|
-
falloff: { type: 'number', default: 0.05, min: 0, neutral: true, cost: 'shader', desc: "kind 'height': how fast it thins above the floor (per meter)" },
|
|
58
|
-
},
|
|
59
|
-
style: () => {
|
|
60
|
-
const s = spec ?? {};
|
|
61
|
-
return Object.fromEntries(['enabled', 'kind', 'color', 'density', 'far', 'near', 'height', 'falloff'].filter(k => s[k] != null).map(k => [k, s[k]]));
|
|
62
|
-
},
|
|
63
|
-
// far alone changes every frame under weather: only the distance moves (updateFog reads the point), no fog rebuild
|
|
64
|
-
apply(v, changed) { if (changed.size === 1 && changed.has('far') && sky._fog) { sky._fog.far = v.far; return; } rebuild(); },
|
|
65
|
-
hooks: { fog: { signature: 'vec4 threedogFog(vec3 color, float depth, vec3 worldPos)', scope: ['fogColor', 'cameraPosition', 'fogNear / fogFar (linear)', 'fogDensity (other kinds)', 'THREEDOG_FOG_HEIGHT', 'THREEDOG_FOG_FALLOFF'],
|
|
66
|
-
tsl: 'WebGPU: { glsl, tsl: ({ color, depth, worldPos, cameraPosition, density, near, far, height, falloff, fog, tsl }) => vec4 (fog rgb, amount) }',
|
|
67
|
-
example: 'vec4 threedogFog(vec3 color, float depth, vec3 worldPos){ return vec4(color, 1.0 - exp(-fogDensity * depth)); }' } },
|
|
68
|
-
applyHook() { rebuild(); },
|
|
69
|
-
// wrong hook GLSL stops here, before any layer is written
|
|
70
|
-
validate: (k, v) => (k === 'hook:fog' ? fogHookProblem(v) : null),
|
|
71
|
-
// no replace: a fog of your own is plain three.js. scene.fog = new THREE.Fog(...) is taken as yours (the owned 'fog' entry yields, describe
|
|
72
|
-
// says writer 'three'), so a second spelling of the same thing (look.fog.replace) would only be a second record to keep in step
|
|
73
|
-
noReplace: 'a fog of your own is plain three.js: scene.fog = new THREE.Fog(color, near, far) (or FogExp2); the engine stops writing it. ' +
|
|
74
|
-
'To keep the engine fog and only stop the sky writing it: engine.look.fog.manual(); manual(false) hands it back',
|
|
75
|
-
});
|
|
76
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// look.shadow, sky half: the sun's shadow box (bias, cascades, extent, update rate ...) added to the core part (core/look/shadowPart.js has the
|
|
2
|
-
// master switch and the filter type). Why one part: a game reads and sets every shadow value on engine.look.shadow, with or without a sky, and
|
|
3
|
-
// describe().look.shadow says who set each. The work itself is Sky._applyShadow (shadow.js); dispose takes these keys back out.
|
|
4
|
-
import { includeInCascades } from './cascades.js';
|
|
5
|
-
import { SKY_BIAS } from './shadow.js';
|
|
6
|
-
import { ownedRow } from '../../core/owned.js';
|
|
7
|
-
|
|
8
|
-
const SPLITS = ['practical', 'uniform', 'logarithmic'];
|
|
9
|
-
const KEYS = ['bias', 'normalBias', 'updateEvery', 'snap', 'ahead', 'type', 'radius', 'blurSamples', 'cascades', 'maxFar', 'fade', 'lightMargin', 'split', 'follow', 'extent'];
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {any} sky @param {object} sh shadowFor(...) at start: becomes the style layer (style.sky.shadow, tier-adjusted, merged with sky({ shadow }))
|
|
13
|
-
*/
|
|
14
|
-
export function extendShadowLook(sky, sh) {
|
|
15
|
-
const e = sky.engine, part = e.look.shadow;
|
|
16
|
-
const cost = 'shadow pass';
|
|
17
|
-
const PARAMS = {
|
|
18
|
-
radius: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'edge softness (pcf, vsm)' },
|
|
19
|
-
blurSamples: { type: 'int', default: 8, min: 1, neutral: true, cost, desc: 'blur quality (vsm only)' },
|
|
20
|
-
bias: { type: 'number', default: SKY_BIAS, neutral: true, cost: 'uniform', desc: 'depth bias against acne, in shadow-camera depth (0-1 over near-far: -0.00005 x 419 m = 2 cm); normalBias does most of the work' },
|
|
21
|
-
normalBias: { type: 'number', default: 0.04, neutral: true, cost: 'uniform', desc: 'normal offset against acne (meters)' },
|
|
22
|
-
mapSize: { type: 'int', default: 2048, min: 64, neutral: true, cost: 'gpu', desc: 'shadow map pixels (each cascade with cascades)' },
|
|
23
|
-
updateEvery: { type: 'int', default: 1, min: 1, neutral: true, cost, desc: 'update the shadow map every N frames' },
|
|
24
|
-
snap: { type: 'any', default: 0.5, neutral: true, cost: 'uniform', desc: "shadow center snap grid in meters, or 'texel'" },
|
|
25
|
-
ahead: { type: 'number', default: 0, neutral: true, cost: 'uniform', desc: 'meters the shadow center is shifted in front of the view' },
|
|
26
|
-
cascades: { type: 'int', default: 1, neutral: true, cost, desc: '1 = one shadow map; 2-4 = cascaded shadows (recipes/45)',
|
|
27
|
-
check: v => (v < 1 || v > 4 ? `must be a whole number 1 (one shadow map, the default) to 4; got ${v}` : v > 1 && sky._drive.sun === false ? "cannot be above 1: cascades split the engine sun's shadow, and sky({ sun: false }) has no engine sun" : null) },
|
|
28
|
-
maxFar: { type: 'number', default: 120, min: 0.001, neutral: true, cost: 'uniform', desc: 'meters from the camera that cascades cover' },
|
|
29
|
-
fade: { type: 'bool', default: true, neutral: true, cost: 'uniform', desc: 'cascades blend into each other' },
|
|
30
|
-
lightMargin: { type: 'number', default: 100, neutral: true, cost: 'uniform', desc: 'meters the cascade lights sit behind their frustum' },
|
|
31
|
-
// follow / extent: before these the shadow box always followed engine.focus at the style's size; a game that stages its own scene had no way out
|
|
32
|
-
follow: { type: 'any', default: 'focus', neutral: true, cost: 'uniform', desc: "what the shadow box centers on: 'focus' (engine.focus) | 'camera' | an Object3D | () => Vector3 | false (it stays where you put engine.lights.sun.target)",
|
|
33
|
-
check: v => (v === false || v === 'focus' || v === 'camera' || v?.isObject3D || typeof v === 'function' ? null : `must be 'focus' | 'camera' | an Object3D | () => Vector3 | false; got ${JSON.stringify(v)}`) },
|
|
34
|
-
extent: { type: 'number', default: 70, min: 1, neutral: true, cost: 'uniform', desc: 'half size of the shadow box in meters (one shadow map; cascades size their own)' },
|
|
35
|
-
split: { type: 'any', default: 'practical', neutral: true, cost: 'uniform', desc: "'practical' | 'uniform' | 'logarithmic' | (count, near, far, out) => void",
|
|
36
|
-
check: v => (typeof v === 'function' || SPLITS.includes(v) ? null : `must be ${SPLITS.map(s => `'${s}'`).join(' | ')} or a function (count, near, far, out) => void; got ${JSON.stringify(v)}`) },
|
|
37
|
-
};
|
|
38
|
-
part.author.extend(PARAMS);
|
|
39
|
-
const style = { ...Object.fromEntries(KEYS.filter(k => sh[k] !== undefined).map(k => [k, sh[k]])), ...(sh.mapSize !== undefined ? { mapSize: sh.mapSize } : {}) };
|
|
40
|
-
part.author.restyle(style); // type in style.sky.shadow is the core key's style value; the rest are the keys just added
|
|
41
|
-
part._skyApply = (v, changed) => {
|
|
42
|
-
const o = {};
|
|
43
|
-
for (const k of changed) if (KEYS.includes(k) && k !== 'type') o[k] = v[k];
|
|
44
|
-
if (changed.has('mapSize')) sky.setShadowMapSize(v.mapSize);
|
|
45
|
-
// a filter switch (the core key) still needs the sky's cascades synced and a shadow redraw when updateEvery > 1 (shadow.js)
|
|
46
|
-
if (Object.keys(o).length || changed.has('type')) sky._applyShadow(o);
|
|
47
|
-
};
|
|
48
|
-
part._skyApply(part.author.values(), new Set(Object.keys(PARAMS))); // extend() recomputes without apply: the sun takes the start values now
|
|
49
|
-
// include: the opt-in for a game ShaderMaterial (lights: true) under cascaded shadows; built-in lit materials are patched without it (cascades.js header)
|
|
50
|
-
const noInclude = part.include;
|
|
51
|
-
part.include = m => includeInCascades(sky, m);
|
|
52
|
-
sky._shadowOff = () => {
|
|
53
|
-
part._skyApply = null; part.include = noInclude;
|
|
54
|
-
for (const k of Object.keys(PARAMS)) part.author.retract(k);
|
|
55
|
-
part.author.restyle({}); // the style's type goes with the sky that brought it
|
|
56
|
-
};
|
|
57
|
-
// describe().owned shows which of the game's own materials carry the csm patch (option A patches built-in lit types the game made, too)
|
|
58
|
-
ownedRow(e, 'shadow.csm', () => {
|
|
59
|
-
const g = sky.csm?.gameMaterials();
|
|
60
|
-
return g?.length ? { part: 'shadow', key: 'csm', writer: 'engine (csm patch on your built-in lit materials; recipes/45)', materials: g } : undefined;
|
|
61
|
-
});
|
|
62
|
-
}
|