threedog 0.2.1 → 0.5.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 +290 -0
- package/README.md +9 -8
- package/core/Animator.js +15 -12
- package/core/Assets.js +71 -16
- package/core/Audio.js +45 -38
- package/core/Baked.js +32 -8
- package/core/Batching.js +102 -15
- package/core/Budget.js +39 -18
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +45 -10
- package/core/Describe.js +104 -43
- package/core/Engine.js +183 -59
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +168 -79
- package/core/Inspect.js +2 -2
- package/core/InspectMaterials.js +85 -0
- package/core/InspectPerf.js +61 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +5 -5
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +14 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +25 -9
- package/core/Views.js +9 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +22 -5
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +38 -11
- package/core/assetManifest.js +48 -9
- package/core/assetReport.js +1 -1
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +5 -2
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +82 -15
- package/core/describeRender.js +37 -17
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +438 -19
- package/core/errorHints.js +37 -141
- package/core/errors.js +31 -8
- package/core/events.generated.js +12 -7
- package/core/gameLights.js +62 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +14 -13
- package/core/gridLoad.js +2 -1
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +48 -12
- package/core/lightWatch.js +6 -4
- package/core/look/coreParts.js +137 -30
- package/core/look/part.js +175 -95
- package/core/look/points.js +255 -0
- package/core/look/report.js +34 -17
- package/core/look/shadowPart.js +63 -0
- package/core/look/state.js +45 -0
- package/core/look/write.js +12 -28
- package/core/loop.js +100 -41
- package/core/math.js +11 -3
- package/core/moduleSlots.js +75 -0
- package/core/moduleTypes.js +73 -0
- package/core/modules.js +145 -27
- package/core/movement.js +2 -2
- package/core/namedModel.js +70 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +168 -0
- package/core/page.js +2 -1
- package/core/params.js +30 -8
- package/core/plugins.js +277 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +203 -0
- package/core/sceneMethods.js +35 -30
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +2 -1
- package/core/sharedPoint.js +317 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +34 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -11
- package/core/streamSources.js +0 -11
- package/core/styleParts.js +63 -47
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +2 -2
- package/core/thingOps.js +29 -6
- package/core/things.js +21 -11
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +7 -1
- package/core/validate.js +65 -86
- package/core/wrap.js +106 -0
- package/docs/AI.md +87 -100
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +220 -147
- package/docs/COMMANDS.md +56 -35
- package/docs/CONVENTIONS.md +90 -28
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +228 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +79 -27
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +11 -9
- package/docs/api/audio.md +10 -14
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +38 -23
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +9 -6
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +63 -60
- package/docs/api/events.md +19 -14
- package/docs/api/grids.md +3 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +11 -6
- package/docs/api/interactions.md +7 -5
- package/docs/api/inventory.md +17 -16
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +15 -0
- package/docs/api/post.md +5 -4
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +11 -44
- package/docs/api/stream.md +1 -1
- package/docs/api/style.md +28 -26
- package/docs/api/terrain.md +9 -6
- package/docs/api/terrainLook.md +10 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +29 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +11 -8
- package/docs/api/vegetationLook.md +10 -0
- package/docs/api/water.md +4 -20
- package/docs/api/weather.md +5 -15
- package/docs/api/weatherLook.md +10 -0
- package/docs/api/world.md +2 -1
- package/docs/recipes/01-new-game.md +48 -34
- package/docs/recipes/02-npc.md +24 -7
- package/docs/recipes/03-items-pickups.md +35 -21
- package/docs/recipes/04-quests.md +12 -5
- package/docs/recipes/05-props-bake.md +151 -15
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +40 -9
- package/docs/recipes/08-weather-sky.md +145 -36
- package/docs/recipes/{09-style-pack.md → 09-style.md} +101 -52
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +14 -6
- package/docs/recipes/14-custom-module.md +61 -29
- package/docs/recipes/15-perf.md +30 -9
- package/docs/recipes/16-dev-bridge.md +61 -37
- package/docs/recipes/18-world.md +16 -6
- package/docs/recipes/19-shooting-picking.md +6 -6
- package/docs/recipes/20-content-actions-save.md +55 -17
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +3 -3
- package/docs/recipes/23-ops.md +16 -10
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +11 -5
- package/docs/recipes/28-terrain.md +34 -1
- package/docs/recipes/29-grid.md +34 -16
- package/docs/recipes/30-templates.md +64 -12
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +35 -2
- package/docs/recipes/34-environment-lighting.md +26 -3
- package/docs/recipes/35-style-from-reference.md +88 -19
- package/docs/recipes/36-sky-ground-plant-looks.md +18 -18
- package/docs/recipes/37-terrain-look-hooks.md +3 -2
- package/docs/recipes/38-environment-look-hooks.md +37 -26
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +2 -2
- package/docs/recipes/43-shader-patches-surface-looks.md +158 -76
- package/docs/recipes/44-water-weather-look-hooks.md +26 -17
- package/docs/recipes/45-cascaded-shadows.md +16 -7
- package/docs/recipes/47-island-snow-backdrop.md +7 -7
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +30 -17
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +3 -3
- package/docs/recipes/52-look.md +197 -61
- package/docs/recipes/53-ground-up-close.md +1 -1
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +112 -0
- package/docs/recipes/56-webgpu-tsl.md +260 -0
- package/docs/recipes/57-control.md +65 -0
- package/docs/recipes/58-input.md +57 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +55 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +17 -13
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/look.js +1 -1
- package/examples/action/main.js +10 -14
- package/examples/action/models.js +24 -23
- package/examples/pullable.json +111 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +83 -0
- package/examples/rc2d/README.md +52 -0
- package/examples/rc2d/main.js +63 -0
- package/examples/rc2d/rc2d.js +197 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +13 -11
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/main.js +17 -12
- package/examples/sheepisland/style/index.js +6 -6
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +15 -16
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +17 -16
- package/examples/styletest/models.js +1 -1
- package/examples/styletest/params.js +3 -3
- package/examples/techniques/contact-shadows/README.md +92 -0
- package/examples/techniques/contact-shadows/contactShadows.js +51 -0
- package/examples/techniques/contact-shadows/main.js +53 -0
- package/examples/techniques/day-night-grade/README.md +86 -0
- package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
- package/examples/techniques/day-night-grade/main.js +51 -0
- package/examples/techniques/interior-light/README.md +103 -0
- package/examples/techniques/interior-light/interiorLight.js +45 -0
- package/examples/techniques/interior-light/main.js +124 -0
- package/examples/techniques/modular-building/README.md +125 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +47 -0
- package/examples/techniques/night-lights/README.md +94 -0
- package/examples/techniques/night-lights/main.js +70 -0
- package/examples/techniques/night-lights/nightLights.js +91 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +84 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/procedural-animation/README.md +77 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +45 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +67 -0
- package/examples/techniques/procedural-surface/main.js +103 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +75 -0
- package/examples/techniques/stylized-shading/main.js +93 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +135 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
- package/examples/techniques/sun-and-key-light/main.js +95 -0
- package/examples/techniques/wet-road/README.md +99 -0
- package/examples/techniques/wet-road/main.js +68 -0
- package/examples/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +84 -0
- package/examples/webgpu-tsl/README.md +42 -0
- package/examples/webgpu-tsl/main.js +21 -0
- package/examples/webgpu-tsl/tslScene.js +75 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +22 -15
- package/examples/world/art/humanoid.js +42 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +58 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/npcs.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +17 -13
- package/examples/world/style/index.js +61 -0
- package/examples/world/style/plugins/10-bloom.js +5 -0
- package/index.d.ts +44 -45
- package/index.js +26 -22
- package/llms.txt +11 -4
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +81 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +70 -19
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +177 -42
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +4 -13
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +87 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +97 -19
- package/modules/characters/movers/manual.js +20 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +172 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +12 -8
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +2 -1
- package/modules/characters/useModel.js +1 -1
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +65 -25
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +96 -27
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +11 -40
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +16 -9
- package/modules/content/rules.js +58 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +121 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +193 -67
- package/modules/gameplay/Inventory.js +69 -73
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +18 -16
- package/modules/gameplay/pickups.js +268 -85
- package/modules/gameplay/questLog.js +4 -4
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +14 -13
- package/modules/grid/index.js +60 -36
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +15 -16
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +6 -5
- package/modules/hlod/index.js +51 -19
- package/modules/hud/index.js +35 -20
- package/modules/hud/parts.js +20 -7
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +45 -20
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +42 -18
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +23 -14
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +39 -11
- package/modules/photo/Photo.js +53 -36
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +57 -52
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +88 -176
- package/modules/sky/cascades.js +86 -25
- package/modules/sky/cascades.tsl.js +82 -0
- package/modules/sky/clouds.js +34 -19
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +83 -13
- package/modules/sky/fog.js +140 -95
- package/modules/sky/frame.js +112 -44
- package/modules/sky/look.js +22 -19
- package/modules/sky/lookFog.js +48 -52
- package/modules/sky/lookShadow.js +53 -41
- package/modules/sky/lookSky.js +82 -21
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +41 -19
- package/modules/sky/shadow.js +44 -20
- package/modules/sky/skyModule.js +45 -33
- package/modules/sky/tint.js +61 -0
- package/modules/terrain/ChunkManager.js +175 -108
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/index.js +105 -50
- package/modules/terrain/look.js +83 -0
- package/modules/terrain/lookGround.js +21 -16
- package/modules/terrain/terrainDefaults.js +1 -1
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +5 -3
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +107 -76
- package/modules/vegetation/Vegetation.js +186 -110
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +32 -11
- package/modules/vegetation/look.js +119 -0
- package/modules/vegetation/lookWind.js +71 -10
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +8 -2
- package/modules/water/Water.js +65 -27
- package/modules/water/look.js +29 -18
- package/modules/water/surface.js +64 -25
- package/modules/water/surfaceDefaults.js +3 -0
- package/modules/weather/Weather.js +62 -104
- package/modules/weather/look.js +1 -2
- package/modules/weather/particles.js +24 -9
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherLook.js +135 -0
- package/modules/world/World.js +24 -7
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +7 -5
- package/package.json +7 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +120 -39
- package/render/effects.js +130 -38
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +26 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +158 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +260 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/lighting.js +66 -14
- package/render/lights.js +223 -4
- package/render/lookGlow.js +139 -0
- package/render/lookSurface.js +99 -36
- package/render/materials.js +71 -52
- package/render/modeling.js +73 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +311 -34
- package/render/postLook.js +124 -46
- package/render/postWebGL.js +197 -0
- package/render/probes.js +231 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/surface.js +53 -17
- package/render/terms.js +211 -0
- package/render/uniformDecl.js +3 -2
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +614 -240
- package/types/gameplay.d.ts +482 -312
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +44 -3
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +102 -31
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +5 -5
- package/types/generated/modules/grid/index.d.ts +29 -17
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +12 -104
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/weather/Weather.d.ts +17 -18
- package/types/generated/modules/weather/weatherLook.d.ts +12 -0
- package/types/generated/modules/world/World.d.ts +18 -3
- package/types/generated/render/PostFX.d.ts +67 -30
- package/types/generated/render/materials.d.ts +26 -20
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +137 -44
- package/types/style.d.ts +109 -81
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +158 -110
- package/ui/Focus.js +25 -14
- package/ui/LoadingScreen.js +1 -1
- package/ui/Parts.js +27 -11
- package/ui/UI.js +20 -10
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +9 -6
- package/ui/touchPart.js +1 -1
- package/core/claims.js +0 -51
- package/core/look/layers.js +0 -136
- package/core/renamed.js +0 -22
- package/docs/api/entities.md +0 -61
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/layers.js +0 -69
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/world/cells.js +0 -42
package/modules/sky/fog.js
CHANGED
|
@@ -1,27 +1,45 @@
|
|
|
1
1
|
// Sky fog (helper of Sky.js): style.sky.fog / sky({ fog }) picks the fog model and color; the sky drives it every frame.
|
|
2
2
|
// kind 'linear' (default, three.js Fog: near = 0.3 x far) | 'exp' | 'exp2' (three.js FogExp2) | 'height' (thick low, thin high)
|
|
3
|
-
// color 'horizon' (default: the dome's horizon color, so distant ground melts into the sky) | a color | (sky) => color
|
|
4
|
-
//
|
|
3
|
+
// color 'horizon' (default: the dome's horizon color, so distant ground melts into the sky) | a color | ({ time, weather, season, state, sky }) => color
|
|
4
|
+
// color / near / far / density each also take such a function, evaluated every frame (core/look/state.js)
|
|
5
|
+
// density per meter for exp / exp2 / height (default: derived from look.fog far, so the fog reaches the same distance as linear)
|
|
5
6
|
// height / falloff 'height' only: the fog's floor (world y) and how fast it thins above it (per meter)
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
7
|
+
// Your own fog math is the look hook, never a style key: engine.look.fog.patch('fog', glsl) with
|
|
8
|
+
// `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)` returning (fog rgb, amount 0..1). In scope: fogColor, cameraPosition, fogNear / fogFar
|
|
9
|
+
// (linear) or fogDensity (the other kinds), THREEDOG_FOG_HEIGHT / THREEDOG_FOG_FALLOFF. No custom uniforms: write constants in the GLSL.
|
|
10
|
+
// WebGPURenderer draws the hook's tsl form instead ({ glsl, tsl }; render/fx/sky.tsl.js): tsl: (ctx) => vec4 node (fog rgb, amount), ctx = { color,
|
|
11
|
+
// depth, worldPos (the same arguments as nodes), cameraPosition, density, near, far, height, falloff, fog (what the kind alone draws, the value
|
|
12
|
+
// so far), fx, tsl }. Each renderer needs its own form; a missing one throws by name.
|
|
13
|
+
// How: 'linear' / 'exp2' without a hook are three's own fog, untouched (the default draws exactly what it always drew). 'exp', 'height' and the
|
|
14
|
+
// hook are one named shader patch, 'fog', on the semantic slots fogPars / fog (render/slots.js), put on each material in this engine's scene
|
|
15
|
+
// (fogMaterials below). Why per material and not THREE.ShaderChunk.fog_*: the chunks are one object per page, so a rewrite reached every
|
|
16
|
+
// engine and every package, and two engines with different fog could not share a page (it used to throw). A patch lives on the material, its
|
|
17
|
+
// cacheKey follows the code, so two engines with different fog both draw right; changing the fog later recompiles the patched materials.
|
|
18
|
+
// Like the cascades' csm patch (cascades.js), this reaches the game's own built-in materials too: three's fog under a FogExp2 object would draw
|
|
19
|
+
// exp2 instead of the asked kind, a wrong picture, not a neutral one. describe().owned row 'fog.patch' lists the game materials it went on.
|
|
20
|
+
// A ShaderMaterial (fog: true) is the game's own code and keeps three's fog; so do Sprite materials (no world position varying there).
|
|
21
|
+
// Who writes scene.fog: sky({ fog: true | false }) (look.js) and look.fog.manual() / replace() (lookFog.js), one owned record (frame.js).
|
|
17
22
|
import * as THREE from 'three';
|
|
18
|
-
import {
|
|
23
|
+
import { closest } from '../../core/validate.js';
|
|
24
|
+
import { readParams, keysSchema } from '../../core/params.js';
|
|
25
|
+
import { live } from '../../core/look/state.js';
|
|
26
|
+
import { patchMaterial, unpatchMaterial, isEngineMade } from '../../render/patches.js';
|
|
27
|
+
import { hashText } from '../../render/effects.js';
|
|
28
|
+
import { sceneVisitor } from '../../core/sceneDelta.js';
|
|
29
|
+
import { codedError } from '../../core/errorHints.js';
|
|
30
|
+
import { fogFarOf } from '../../core/sceneMethods.js';
|
|
31
|
+
import { skyNodes } from './shader.js';
|
|
32
|
+
|
|
33
|
+
/** A start distance for the fog object: a function far is evaluated per frame (updateFog), so the object starts at the distance in effect */
|
|
34
|
+
export const startFar = (f, e) => (typeof f.far === 'number' ? f.far : fogFarOf(e));
|
|
19
35
|
|
|
20
36
|
const KINDS = ['linear', 'exp', 'exp2', 'height'];
|
|
21
37
|
export const FOG_KINDS = KINDS;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
38
|
+
// Linear fog starts at this fraction of far when look.fog near is not set. One constant, shown in look.fog's catalog (lookFog.js why / off),
|
|
39
|
+
// so the start distance is a visible engine choice instead of a number buried in two places (review 2026-11-03)
|
|
40
|
+
export const FOG_NEAR = 0.3;
|
|
41
|
+
// no 'glsl': custom fog math is look.fog.patch('fog', glsl) only (one injection entry), so style.sky.fog.glsl throws as an unknown key
|
|
42
|
+
const KEYS = ['kind', 'color', 'density', 'height', 'falloff', 'near', 'far', 'enabled']; // near / far / enabled: look.fog (lookFog.js)
|
|
25
43
|
// fog amount reached at the far distance with the derived density: exp(-3.9) = 2% (exp, height), exp(-1.98^2) = 2% (exp2)
|
|
26
44
|
const REACH = { exp: 3.9, exp2: 1.98, height: 3.9 };
|
|
27
45
|
const flt = v => Number.isInteger(v) ? v.toFixed(1) : String(v);
|
|
@@ -37,103 +55,130 @@ const FN = {
|
|
|
37
55
|
return vec4(color, 1.0 - exp(-fogDensity * dist * k));
|
|
38
56
|
}`,
|
|
39
57
|
};
|
|
58
|
+
export const FOG_SIGNATURE = /vec4\s+threedogFog\s*\(/;
|
|
40
59
|
|
|
41
|
-
/**
|
|
42
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Check style.sky.fog (+ sky({ fog }) on top) and return the resolved settings; throws with the fix on a bad kind.
|
|
62
|
+
* @param {object} spec the settings @param {string | { glsl?: string, tsl?: Function }} [hook] look.fog's 'hook:fog' value (lookFog.js validated it)
|
|
63
|
+
*/
|
|
64
|
+
export function resolveFog(spec, hook) {
|
|
43
65
|
const s = spec || {};
|
|
44
|
-
|
|
66
|
+
if (s.glsl != null) throw codedError('sky-option', "style.sky.fog.glsl is not an option; your own fog math goes through the look hook: engine.look.fog.patch('fog', glsl) with `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)`");
|
|
67
|
+
readParams('style.sky.fog', keysSchema(KEYS), s);
|
|
45
68
|
const kind = s.kind ?? 'linear';
|
|
46
|
-
if (!KINDS.includes(kind)) throw
|
|
47
|
-
if (s.glsl != null && (typeof s.glsl !== 'string' || !/vec4\s+threedogFog\s*\(/.test(s.glsl)))
|
|
48
|
-
throw new Error('style.sky.fog.glsl must be GLSL that defines `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)` returning (fog rgb, amount 0..1); see modules/sky/fog.js');
|
|
69
|
+
if (!KINDS.includes(kind)) throw codedError('sky-option', `style.sky.fog.kind '${kind}' is not a fog kind; use ${KINDS.map(k => `'${k}'`).join(' | ')}` + (closest(kind, KINDS) ? ` (did you mean '${closest(kind, KINDS)}'?)` : ''));
|
|
49
70
|
const color = s.color ?? 'horizon';
|
|
71
|
+
// the hook: GLSL text, or { glsl?, tsl? } (lookFog.js checked the shape); kept whole so each renderer picks its own form
|
|
72
|
+
const h = hook == null ? null : typeof hook === 'string' ? { glsl: hook } : hook;
|
|
50
73
|
return { kind, color: color === 'horizon' || typeof color === 'function' ? color : new THREE.Color(color), density: s.density ?? null,
|
|
51
|
-
height: s.height ?? 0, falloff: s.falloff ?? 0.05, glsl:
|
|
74
|
+
height: s.height ?? 0, falloff: s.falloff ?? 0.05, glsl: h ? h.glsl ?? null : FN[kind] ?? null, hook: h, near: s.near ?? null, far: s.far ?? null, enabled: s.enabled !== false };
|
|
52
75
|
}
|
|
53
76
|
|
|
54
77
|
/** The fog object for the kind: density-based kinds use FogExp2 (its fogDensity uniform is live), linear uses Fog */
|
|
55
78
|
export function makeFog(f, far) {
|
|
56
|
-
return f.kind === 'linear' ? new THREE.Fog(0xcccccc, far *
|
|
79
|
+
return f.kind === 'linear' ? new THREE.Fog(0xcccccc, far * FOG_NEAR, far) : new THREE.FogExp2(0xcccccc, REACH[f.kind] / far);
|
|
57
80
|
}
|
|
58
81
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
export function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// the material compiles under FOG_EXP2 when the fog object is FogExp2, so that branch holds the replacement for density kinds;
|
|
75
|
-
// a custom glsl for 'linear' takes the other branch
|
|
76
|
-
const dense = f.kind !== 'linear', own = `vec4 threedogFogOut = threedogFog(fogColor, vFogDepth, vFogWorld);
|
|
77
|
-
gl_FragColor.rgb = mix(gl_FragColor.rgb, threedogFogOut.rgb, clamp(threedogFogOut.a, 0.0, 1.0));`;
|
|
78
|
-
const orig = ORIGINAL.fog_fragment.replace('#ifdef USE_FOG', '').replace(/#endif\s*$/, '');
|
|
79
|
-
C.fog_pars_vertex = '#ifdef USE_FOG\n\tvarying float vFogDepth;\n\tvarying vec3 vFogWorld;\n#endif\n';
|
|
80
|
-
// world position from the view-space one: the view matrix is a pure rotation + translation, so its transpose undoes the rotation
|
|
81
|
-
// (cheaper than another matrix and right for instanced and skinned meshes too, which mvPosition already includes)
|
|
82
|
-
C.fog_vertex = '#ifdef USE_FOG\n\tvFogDepth = - mvPosition.z;\n\tvFogWorld = ( vec4( mvPosition.xyz, 0.0 ) * viewMatrix ).xyz + cameraPosition;\n#endif\n';
|
|
83
|
-
C.fog_pars_fragment = `#ifdef USE_FOG
|
|
84
|
-
uniform vec3 fogColor;
|
|
85
|
-
varying float vFogDepth;
|
|
86
|
-
varying vec3 vFogWorld;
|
|
87
|
-
const float THREEDOG_FOG_HEIGHT = ${flt(f.height)};
|
|
88
|
-
const float THREEDOG_FOG_FALLOFF = ${flt(f.falloff)};
|
|
89
|
-
#ifdef FOG_EXP2
|
|
90
|
-
uniform float fogDensity;
|
|
91
|
-
${dense ? f.glsl : ''}
|
|
92
|
-
#else
|
|
93
|
-
uniform float fogNear;
|
|
94
|
-
uniform float fogFar;
|
|
95
|
-
${dense ? '' : f.glsl}
|
|
96
|
-
#endif
|
|
82
|
+
/**
|
|
83
|
+
* The 'fog' patch for resolved settings, or null when three's own fog draws it (plain linear / exp2).
|
|
84
|
+
* The material compiles under FOG_EXP2 when the fog object is FogExp2, so that branch holds the replacement for the density kinds; a hook on
|
|
85
|
+
* 'linear' takes the other branch. The other branch keeps three's own code, so a game that swaps in the other fog object still gets fog.
|
|
86
|
+
*/
|
|
87
|
+
export function fogPatch(f) {
|
|
88
|
+
if (!f?.glsl) return null;
|
|
89
|
+
const dense = f.kind !== 'linear', mine = dense ? '#ifdef FOG_EXP2' : '#ifndef FOG_EXP2';
|
|
90
|
+
// three's fog_fragment body without its #ifdef USE_FOG wrapper (read now: nothing in the engine rewrites the chunk any more)
|
|
91
|
+
const orig = THREE.ShaderChunk.fog_fragment.replace('#ifdef USE_FOG', '').replace(/#endif\s*$/, '');
|
|
92
|
+
const pars = `#ifdef USE_FOG
|
|
93
|
+
const float THREEDOG_FOG_HEIGHT = ${flt(f.height)};
|
|
94
|
+
const float THREEDOG_FOG_FALLOFF = ${flt(f.falloff)};
|
|
95
|
+
${mine}
|
|
96
|
+
${f.glsl}
|
|
97
97
|
#endif
|
|
98
|
-
`;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
#endif`;
|
|
99
|
+
// vFogDepth is three's own varying (fog_vertex); the world position comes from the engine's 'world' patch (vThreedogWorld)
|
|
100
|
+
const body = `#ifdef USE_FOG
|
|
101
|
+
${mine}
|
|
102
|
+
vec4 threedogFogOut = threedogFog(fogColor, vFogDepth, vThreedogWorld);
|
|
103
|
+
gl_FragColor.rgb = mix(gl_FragColor.rgb, threedogFogOut.rgb, clamp(threedogFogOut.a, 0.0, 1.0));
|
|
104
|
+
#else
|
|
105
|
+
${orig}
|
|
105
106
|
#endif
|
|
106
|
-
`;
|
|
107
|
-
return
|
|
107
|
+
#endif`;
|
|
108
|
+
return { name: 'fog', cacheKey: hashText(pars + body), needs: { patches: ['world'] }, glsl: { fogPars: pars, fog: body } };
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
111
|
+
// Built-in material types whose shaders have the world varying's anchor and three's fog chunks (Sprite does not: it builds mvPosition by hand)
|
|
112
|
+
const FOGGED = new Set(['MeshBasicMaterial', 'MeshLambertMaterial', 'MeshPhongMaterial', 'MeshStandardMaterial', 'MeshPhysicalMaterial',
|
|
113
|
+
'MeshToonMaterial', 'MeshMatcapMaterial', 'LineBasicMaterial', 'LineDashedMaterial', 'PointsMaterial']);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Point the fog patch at new settings: unchanged code does nothing, new code re-patches every material it went on (they recompile once),
|
|
117
|
+
* null takes it off them. The next fogMaterials walk reaches materials it has not seen.
|
|
118
|
+
* @param {any} sky @param {any} f resolved settings, or null (no fog: sky({ fog: false }), module disposed)
|
|
119
|
+
*/
|
|
120
|
+
export function setFogPatch(sky, f) {
|
|
121
|
+
sky._fogSet = f; // the settings in force: a renderer swap (fallback 'webgl') applies them again on the other route
|
|
122
|
+
// WebGPURenderer: one scene fog node instead of the per-material patch (render/fx/sky.tsl.js fogSide: kinds, the FogExp2 rule, the hook error)
|
|
123
|
+
const n = skyNodes(sky.engine);
|
|
124
|
+
if (n) { (sky._fogNode ??= n.fogSide(sky.engine.scene)).set(f); return; }
|
|
125
|
+
if (f?.hook && f.glsl == null) throw codedError('sky-option', "look.fog.patch('fog') has only a tsl form, which WebGLRenderer cannot draw: give glsl too ({ glsl, tsl })");
|
|
126
|
+
const w = sky._fogWalk ??= { patch: null, mats: new Map(), view: null };
|
|
127
|
+
const p = f ? fogPatch(f) : null;
|
|
128
|
+
if ((p?.cacheKey ?? null) === (w.patch?.cacheKey ?? null)) return;
|
|
129
|
+
w.patch = p;
|
|
130
|
+
for (const m of w.mats.keys()) unpatchMaterial(m, 'fog');
|
|
131
|
+
w.mats.clear();
|
|
132
|
+
// new code: every material in the scene again (rescan); no patch: stop watching the scene
|
|
133
|
+
if (!p) { w.view?.remove(); w.view = null; return; }
|
|
134
|
+
const fit = m => {
|
|
135
|
+
if (!m || w.mats.get(m) === w.patch || !FOGGED.has(m.type) || m.fog === false) return;
|
|
136
|
+
patchMaterial(m, [w.patch], { strict: false }); w.mats.set(m, w.patch);
|
|
118
137
|
};
|
|
138
|
+
if (w.view) w.view.rescan();
|
|
139
|
+
else w.view = sceneVisitor(sky.engine.scene, { enter(o) { const ms = o.material; if (Array.isArray(ms)) for (const m of ms) fit(m); else fit(ms); } });
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Per frame (updateSky): put the fog patch on fogged materials of objects that entered the scene since the last frame (core/sceneDelta.js) */
|
|
143
|
+
export function fogMaterials(sky) {
|
|
144
|
+
sky._fogWalk?.view?.sync();
|
|
145
|
+
sky._fogNode?.sync(); // WebGPU: the scene fog node follows scene.fog's type (render/fx/sky.tsl.js)
|
|
119
146
|
}
|
|
147
|
+
|
|
148
|
+
/** describe().owned row 'fog.patch': the game's own materials the fog patch went on (undefined while none) */
|
|
149
|
+
export function fogGameMaterials(sky) {
|
|
150
|
+
const g = [...(sky._fogWalk?.mats.keys() ?? [])].filter(m => !isEngineMade(m)).map(m => m.name || m.type);
|
|
151
|
+
return g.length ? { part: 'fog', key: 'patch', writer: 'engine', materials: g, why: "kind 'exp' / 'height' / look.fog hook: three's fog would draw another curve" } : undefined;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** The far distance a disabled fog is pushed to (out of reach, no recompile); fogBand reads it back to know the fog is off */
|
|
155
|
+
const FOG_OFF_FAR = 1e9;
|
|
156
|
+
|
|
120
157
|
/** Per frame: fog color and distance / density from the sky's horizon and the modifier layers (fog multiplies the distance) */
|
|
121
|
-
export function updateFog(sky, horizon,
|
|
158
|
+
export function updateFog(sky, horizon, ctx) {
|
|
122
159
|
// only when the sky drives fog (sky({ fog: true })) and scene.fog is still a fog object: the game may have nulled or replaced it
|
|
123
160
|
const fog = sky.engine.scene.fog, f = sky._fog;
|
|
124
|
-
if (sky.
|
|
125
|
-
// look.fog
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
161
|
+
if (!sky._oFog?.on || !fog?.color) return; // off after scene.fog = yours (the owned entry yielded) or look.fog.manual()
|
|
162
|
+
// look.fog far is a shared point: its value already holds the weather's multiplier (engine.mod('look.fog.far', { mul })); near / density set
|
|
163
|
+
// explicitly are kept as given; enabled false pushes the fog out of reach without a recompile
|
|
164
|
+
const far = f.enabled ? fogFarOf(sky.engine) : FOG_OFF_FAR, near = live(f.near, ctx), density = live(f.density, ctx);
|
|
165
|
+
// a function color may answer 'horizon' too (({ state }) => state.boss ? '#400' : 'horizon'), so the default stays one word away
|
|
166
|
+
const color = live(f.color, ctx);
|
|
167
|
+
if (color === 'horizon') fog.color.copy(horizon);
|
|
168
|
+
else fog.color.set(color);
|
|
169
|
+
// near / far are written for every kind: the dev guard reads them
|
|
170
|
+
fog.far = far; fog.near = f.enabled && near != null ? near : far * FOG_NEAR;
|
|
171
|
+
if (f.kind !== 'linear') fog.density = !f.enabled ? 0 : density != null ? density : REACH[f.kind] / far;
|
|
133
172
|
}
|
|
134
173
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
174
|
+
// The dome's fog band: its lower band fades to the fog color so the line where fogged ground meets the sky does not show.
|
|
175
|
+
// Always compiled in and switched by the uFogBand uniform (0 = off, mix(col, x, 0.0) is col exactly), so any fog color change at
|
|
176
|
+
// runtime -- 'horizon' <-> a fixed color <-> a function, look.fog.set, a game writing scene.fog.color under manual() -- needs no recompile.
|
|
177
|
+
export const DOME_FOG = { decl: 'uniform vec3 uFogColor; uniform float uFogBand;', body: '\n col = mix(col, uFogColor, uFogBand * (1.0 - smoothstep(-0.02, 0.15, d.y)));' };
|
|
178
|
+
/** Per frame, after updateFog: the band is on exactly when the fog's color is not the horizon the dome draws. One rule for every mode
|
|
179
|
+
* (sky-driven, manual, replaced fog), because it reads the fog object itself rather than the sky's settings; 'horizon' copies the color
|
|
180
|
+
* exactly, so the default stays bit-for-bit the plain dome. No fog object (fog: false) = nothing to hide = off; a fog that is there but draws
|
|
181
|
+
* nothing (look.fog enabled: false pushes far out of reach, or an exp2 density of 0) = also off, or the dome would show a band no ground has. */
|
|
182
|
+
// !(far >= off): a game's own FogExp2 has no far at all and still shows
|
|
183
|
+
const fogShows = fog => !(fog.far >= FOG_OFF_FAR) && !(fog.isFogExp2 && fog.density <= 0);
|
|
184
|
+
export const fogBand = (fog, horizon) => (fog?.color && fogShows(fog) && !fog.color.equals(horizon) ? 1 : 0);
|
package/modules/sky/frame.js
CHANGED
|
@@ -1,76 +1,144 @@
|
|
|
1
1
|
// Sky per-frame work (helper of Sky.js): dome colors, sun / moon light, ambient, fog and the shadow center from the time of day and
|
|
2
2
|
// the modifier layers; plus the dev guard that warns when a game edits what this overwrites every frame.
|
|
3
|
-
import {
|
|
4
|
-
import { applySeason } from './
|
|
5
|
-
import { applyCover } from './
|
|
6
|
-
import { updateFog } from './fog.js';
|
|
3
|
+
import { defineOwned } from '../../core/owned.js';
|
|
4
|
+
import { applySeason } from './season.js';
|
|
5
|
+
import { applyCover, skyTint } from './tint.js';
|
|
6
|
+
import { updateFog, fogBand, fogMaterials } from './fog.js';
|
|
7
7
|
import { cascadeFrame } from './cascades.js';
|
|
8
|
+
import { fillContext, live } from '../../core/look/state.js';
|
|
9
|
+
import { roomShare, ROOM_RADIANCE } from '../../render/lights.js';
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Brightness of the sky's ambient light for one sky color pair: ambient intensity x the luminance of the hemi color (top / horizon halfway,
|
|
13
|
+
* linear colors, so the mean of their luminances). One measure for the keyframe peak (Sky.js) and the frame (updateSky).
|
|
14
|
+
* @param {import('three').Color} top @param {import('three').Color} horizon @param {number} ambient
|
|
15
|
+
*/
|
|
16
|
+
export const skyLight = (top, horizon, ambient) => ambient * (lum(top) + lum(horizon)) / 2;
|
|
17
|
+
const lum = c => 0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b;
|
|
18
|
+
|
|
19
|
+
// The copyable takeover calls each owned property's warning quotes (core/owned.js): the engine yields to a direct write, these say it explicitly
|
|
20
|
+
const L = {
|
|
21
|
+
sun: { manual: "engine.look.lights.manual('sun')", set: "engine.look.lights.set({ sun: { intensity: 2 } })" },
|
|
22
|
+
sunColor: { manual: "engine.look.lights.manual('sun.color')", set: "engine.look.lights.set({ sun: { color: '#ffd9a0' } })" },
|
|
23
|
+
sunDir: { manual: "engine.look.lights.manual('sun.direction')" },
|
|
24
|
+
hemi: { manual: "engine.look.lights.manual('hemi')", set: "engine.look.lights.set({ hemi: { intensity: 0.8 } })" },
|
|
25
|
+
fog: { manual: 'engine.look.fog.manual()', set: "engine.look.fog.set({ color: '#cfd8e0', far: 300 })" },
|
|
26
|
+
exposure: { manual: "engine.look.tone.manual('exposure')", set: 'engine.look.tone.set({ exposure: 1.2 })' },
|
|
27
|
+
background: { manual: "engine.look.sky.manual('background')", replace: 'engine.look.sky.replace(null)' },
|
|
28
|
+
follow: { manual: "engine.look.shadow.manual('follow')", set: 'engine.look.shadow.set({ follow: false })' },
|
|
17
29
|
};
|
|
18
30
|
|
|
19
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Register what the sky writes every frame (core/owned.js). Everything starts engine-written; the one way to take a value over is
|
|
33
|
+
* look.<part>.manual(key) (or a direct write, which the sky yields to). Lights in false mode are hidden and not registered.
|
|
34
|
+
*/
|
|
20
35
|
export function watchOwned(sky) {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
const e = sky.engine, scene = e.scene, fog = () => scene.fog, D = sky._drive, sun = sky._sun, hemi = sky._hemi;
|
|
37
|
+
const own = (id, part, key, read, levels, objects) => defineOwned(e, { id, part, key, read, levels, objects });
|
|
38
|
+
const list = [];
|
|
39
|
+
if (D.sun !== false) {
|
|
40
|
+
sky._oSunI = own('sun.intensity', 'lights', 'sun.intensity', () => sun.intensity, L.sun, [sun]);
|
|
41
|
+
sky._oSunC = own('sun.color', 'lights', 'sun.color', () => sun.color.toArray(), L.sunColor, [sun, sun.color]);
|
|
42
|
+
// the direction is where the sun sits relative to its target; the shadow box still follows the focus when the game owns the direction (shadow.js)
|
|
43
|
+
sky._oSunDir = own('sun.direction', 'lights', 'sun.direction', () => { const p = sun.position, t = sun.target.position; return [p.x - t.x, p.y - t.y, p.z - t.z]; }, L.sunDir, [sun, sun.position]);
|
|
44
|
+
sky._oFollow = own('shadow.follow', 'shadow', 'follow', () => sun.target.position.toArray(), L.follow, [sun.target, sun.target.position]);
|
|
45
|
+
list.push(sky._oSunI, sky._oSunC, sky._oSunDir, sky._oFollow);
|
|
46
|
+
}
|
|
47
|
+
if (D.hemi !== false) list.push(sky._oHemi = own('hemi', 'lights', 'hemi', () => [hemi.intensity, ...hemi.color.toArray(), ...hemi.groundColor.toArray()], L.hemi, [hemi, hemi.color, hemi.groundColor]));
|
|
48
|
+
// fog: the object itself, color, near and far (the values, not their ratio: a game writing far 50 / near 15 is an outside write too; the engine
|
|
49
|
+
// only writes near / far inside updateFog, between check and mark, so its own writes never look like the game's).
|
|
50
|
+
// scene.fog = a fog of yours is a change of the object this entry reads, so it yields: "who writes scene.fog" has one record, not a second flag
|
|
51
|
+
if (D.fog !== false) list.push(sky._oFog = own('fog', 'fog', 'fog', () => [fog(), ...(fog()?.color?.toArray() ?? []), fog()?.near, fog()?.far, fog()?.density], L.fog,
|
|
52
|
+
[scene, ...(fog() ? [fog(), fog().color] : [])]));
|
|
53
|
+
list.push(sky._oExposure = own('exposure', 'tone', 'exposure', () => e.renderer.toneMappingExposure, L.exposure, [e.renderer]));
|
|
54
|
+
// background: the sky writes it with a backdrop / skybox; with the dome it draws over whatever scene.background holds, so a game that sets one
|
|
55
|
+
// takes it, and the dome hides (onChange) so the game's background shows; handing it back shows the dome again
|
|
56
|
+
list.push(sky._oBg = own('background', 'sky', 'background', () => [scene.background, scene.backgroundIntensity], L.background, [scene]));
|
|
57
|
+
sky._oBg._onChange = o => { if (!sky._backdrop && !sky.skybox && !sky._ownSky) sky.dome.visible = o.on; }; // a replaced sky keeps the dome hidden
|
|
58
|
+
return list;
|
|
33
59
|
}
|
|
34
60
|
|
|
35
61
|
/** Recompute dome, lights, fog and shadow placement for this frame */
|
|
36
62
|
export function updateSky(sky, focus) {
|
|
37
63
|
applySeason(sky, sky.engine.uniforms);
|
|
38
|
-
|
|
64
|
+
// the contract's inputs, once per frame: every function-valued look key below reads this one object (core/look/state.js)
|
|
65
|
+
const ctx = fillContext(sky.engine, sky, sky.engine.weather?.name, sky.engine.calendar), P = sky.engine.look.sky;
|
|
66
|
+
for (const p of Object.values(sky.engine.look)) p.author.tick(ctx); // function values on number keys (look.fog far, look.lights sun.intensity ...)
|
|
67
|
+
const t = sky.drawnTime, kf = sky.kf;
|
|
39
68
|
let i = 0; while (i < kf.length - 2 && t > kf[i + 1][0]) i++;
|
|
40
69
|
const a = kf[i], b = kf[i + 1], f = (t - a[0]) / (b[0] - a[0]);
|
|
41
70
|
const u = sky.uniforms, scene = sky.engine.scene;
|
|
42
71
|
u.uTop.value.copy(a[1]).lerp(b[1], f);
|
|
43
72
|
u.uHorizon.value.copy(a[2]).lerp(b[2], f);
|
|
44
|
-
|
|
45
|
-
|
|
73
|
+
// look.sky top / horizon: a color or a function over the keyframes (null = keyframes); fog 'horizon', hemi color and the dome all follow
|
|
74
|
+
const top = P.value('top'), hor = P.value('horizon');
|
|
75
|
+
if (top != null) u.uTop.value.set(live(top, ctx));
|
|
76
|
+
if (hor != null) u.uHorizon.value.set(live(hor, ctx));
|
|
77
|
+
for (const o of sky._owned) if (o !== sky._oExposure || sky.engine.exposureDriver) o.check(); // exposure is engine-written only with a driver
|
|
46
78
|
applyCover(sky, sky.engine.uniforms); // after the season: snow / ash cover lies over the season tint
|
|
47
|
-
const M = sky.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
79
|
+
const M = skyTint(sky, sky._tintNow), flash = sky._points.flash.value(), hemiI = a[5] + (b[5] - a[5]) * f;
|
|
80
|
+
// the sky's light now, 0-1 of its brightest keyframe row, read before any tint. Why: a sky.tint color (weather grey, a cave tint) is the color
|
|
81
|
+
// under that brightest sky; lerping toward it as a fixed color turned a rainy night into a lit grey (#0d1628 -> #6b6b6d, R3). Dimmed by the
|
|
82
|
+
// sky's own light it stays dark at night and is unchanged at the brightest row
|
|
83
|
+
// sky. style.sky.dim.tint false keeps the tint at its full color at any hour (a style decision, not the engine's)
|
|
84
|
+
const light = !sky.dim.tint ? 1 : sky._lightPeak > 0 ? Math.min(1, skyLight(u.uTop.value, u.uHorizon.value, hemiI) / sky._lightPeak) : 1;
|
|
85
|
+
if (M.amount || M.horizon) {
|
|
86
|
+
const tint = sky._tintLit.copy(M.color).multiplyScalar(light);
|
|
87
|
+
if (M.amount) u.uTop.value.lerp(tint, M.amount);
|
|
88
|
+
if (M.horizon) u.uHorizon.value.lerp(tint, M.horizon);
|
|
89
|
+
}
|
|
90
|
+
if (flash) { u.uTop.value.addScalar(flash * 0.4); u.uHorizon.value.addScalar(flash * 0.3); }
|
|
51
91
|
const bd = sky._backdrop; // style.sky.backdrop (look.js): a flat background in place of the dome, fog follows it
|
|
52
|
-
if (bd) { if (bd.fn) bd.color.set(bd.fn(
|
|
53
|
-
updateFog(sky, bd ? bd.color : u.uHorizon.value,
|
|
92
|
+
if (bd && sky._oBg.on) { if (bd.fn) bd.color.set(bd.fn(ctx)); sky.dome.visible = false; scene.background = bd.color; }
|
|
93
|
+
updateFog(sky, bd ? bd.color : u.uHorizon.value, ctx);
|
|
94
|
+
// the drawn sky colors for game shaders (render/effects.js uSkyTop / uSkyHorizon): the same horizon the fog's 'horizon' color copies
|
|
95
|
+
sky.engine.uniforms.uSkyTop.value.copy(u.uTop.value); sky.engine.uniforms.uSkyHorizon.value.copy(bd ? bd.color : u.uHorizon.value);
|
|
96
|
+
fogMaterials(sky); // the 'fog' patch onto materials added since the last scene change (nothing while three's own fog draws it)
|
|
97
|
+
u.uFogBand.value = fogBand(scene.fog, u.uHorizon.value); // compared to the dome's horizon (not the backdrop): the band is drawn on the dome
|
|
54
98
|
u.uSunColor.value.copy(a[3]).lerp(b[3], f); // the dome's sun disk follows the keyframes whatever drives the light
|
|
55
|
-
|
|
56
|
-
const sunI = a[4] + (b[4] - a[4]) * f, hemiI = a[5] + (b[5] - a[5]) * f;
|
|
99
|
+
const sunI = a[4] + (b[4] - a[4]) * f;
|
|
57
100
|
|
|
58
101
|
const ang = (t - 0.25) * Math.PI * 2, elev = Math.sin(ang);
|
|
59
102
|
sky.sunDir.set(Math.cos(ang) * sky.orbit.sway, elev, sky.orbit.tilt).normalize();
|
|
60
103
|
u.uSunDir.value.copy(sky.sunDir);
|
|
104
|
+
// the contract's shared outputs: engine.uniforms is what a game's own sky / water / shader reads (a replaced dome keeps getting
|
|
105
|
+
// these); uSunDir is the dome's own object (shader.js), so the copy above already wrote it
|
|
106
|
+
const EU = sky.engine.uniforms;
|
|
107
|
+
EU.uDaylight.value = Math.max(0, elev); EU.uTimeOfDay.value = t;
|
|
61
108
|
u.uNight.value = Math.min(1, Math.max(0, -elev * 4));
|
|
62
109
|
const lightDir = elev >= 0 ? sky.sunDir : sky._lightDir.copy(sky.sunDir).negate().setZ(sky.orbit.tilt).normalize();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
110
|
+
// the keyframes are the style layer of the light keys (look.lights.drive in Sky.js); the sunset fade is an effect on top, like the weather's
|
|
111
|
+
// multiplier. So a game's look.lights.set({ sun: { intensity: 3 } }) replaces the keyframes and still dims at dusk and in rain (core/look/points.js)
|
|
112
|
+
const Lk = sky.engine.look.lights, La = Lk.author, D = sky._drive;
|
|
113
|
+
La.batch(() => {
|
|
114
|
+
if (D.sun === true) {
|
|
115
|
+
La.feed('sun.intensity', sunI); La.feed('sun.color', u.uSunColor.value.getHex());
|
|
116
|
+
// fade out near the horizon so day/night switching does not pop
|
|
117
|
+
sky._horizon = La.point('sun.intensity').take({ owner: 'sky:horizon', layer: 'effect', mul: Math.min(1, Math.abs(elev) * 7) });
|
|
118
|
+
}
|
|
119
|
+
if (D.hemi === true) {
|
|
120
|
+
La.feed('hemi.intensity', hemiI);
|
|
121
|
+
La.feed('hemi.color', sky._tmpC.copy(u.uTop.value).lerp(u.uHorizon.value, 0.5).getHex());
|
|
122
|
+
La.feed('hemi.ground', sky._tmpC.copy(sky.groundTint).multiplyScalar(0.4 + 0.6 * Math.min(1, hemiI)).getHex());
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
if (sky._oSunI?.on) sky._sun.intensity = Lk.value('sun.intensity');
|
|
126
|
+
if (sky._oSunC?.on) sky._sun.color.set(live(Lk.value('sun.color'), ctx));
|
|
127
|
+
// one ambient budget (look.lights hemi.intensity: the style's ambient column x the weather's multiplier): the room map takes its share, the hemisphere light the rest
|
|
128
|
+
const amb = Lk.value('hemi.intensity'), share = roomShare(sky.engine);
|
|
129
|
+
if (sky._oHemi?.on) {
|
|
130
|
+
sky._hemi.intensity = amb * (1 - share) + flash * 3;
|
|
131
|
+
sky._hemi.color.set(live(Lk.value('hemi.color'), ctx));
|
|
132
|
+
sky._hemi.groundColor.set(live(Lk.value('hemi.ground'), ctx));
|
|
68
133
|
}
|
|
69
|
-
|
|
134
|
+
// the room environment is its share of the same budget, in the same units: ambient x the luminance of the sky color the hemi light takes
|
|
135
|
+
// (a neutral white map must not light a dark-blue night white: desert demo R4), turned into an environment intensity by what the map gives
|
|
136
|
+
// at 1 (ROOM_RADIANCE; three's hemisphere light divides by PI, the environment does not). look.lights env.share is the share
|
|
137
|
+
sky._envFollow(amb * skyLight(u.uTop.value, u.uHorizon.value, 1) / (Math.PI * ROOM_RADIANCE));
|
|
70
138
|
const ex = sky.engine.exposureDriver;
|
|
71
|
-
if (ex) sky.engine.renderer.toneMappingExposure = ex(
|
|
139
|
+
if (ex && sky._oExposure.on) sky.engine.renderer.toneMappingExposure = ex(ctx); // style.exposure keyframes / function (engine.look.tone.set)
|
|
72
140
|
|
|
73
|
-
if (sky.skybox) sky.engine.scene.backgroundIntensity = Math.max(0.05,
|
|
141
|
+
if (sky.skybox && sky._oBg.on) sky.engine.scene.backgroundIntensity = Math.max(0.05, amb / 1.2);
|
|
74
142
|
if (sky.csm) cascadeFrame(sky, lightDir); // cascades place their own lights from the camera (cascades.js)
|
|
75
143
|
else if (sky._drive.sun !== false) sky._placeShadow(focus, lightDir);
|
|
76
144
|
for (const o of sky._owned) o.mark();
|
package/modules/sky/look.js
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
// Sky look setup (helper of Sky.js): which engine lights the sky drives, the fog model, extra dome layers.
|
|
2
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
3
|
// sky({ sun: true }) default: the sky drives engine.lights.sun (color, intensity, direction, shadow box) from the keyframes
|
|
4
|
-
// sky({ sun: 'manual' }) the sky still aims it along the time of day and moves the shadow box; color and intensity are the game's
|
|
5
4
|
// sky({ sun: false }) hidden (visible = false, no shadows) and never touched: light the world with your own three.js lights
|
|
6
|
-
// sky({ hemisphere: true |
|
|
7
|
-
// sky({ fog: true |
|
|
8
|
-
//
|
|
9
|
-
//
|
|
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.
|
|
10
11
|
// Hidden lights are left in the scene (visible = false): three skips them, and toggling visible later recompiles like adding a light would.
|
|
11
12
|
import * as THREE from 'three';
|
|
12
|
-
import { resolveFog,
|
|
13
|
+
import { resolveFog, DOME_FOG } from './fog.js';
|
|
13
14
|
import { resolveDomeLayers } from './domeLayers.js';
|
|
15
|
+
import { codedError } from '../../core/errorHints.js';
|
|
16
|
+
import { isWebGPU } from '../../render/backend.js';
|
|
14
17
|
|
|
15
|
-
const
|
|
18
|
+
const TAKE = { sun: "engine.look.lights.manual(['sun.intensity', 'sun.color'])", hemisphere: "engine.look.lights.manual('hemi')", fog: 'engine.look.fog.manual()' };
|
|
16
19
|
const modeOf = (name, v = true) => {
|
|
17
|
-
if (
|
|
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)}`);
|
|
18
22
|
return v;
|
|
19
23
|
};
|
|
20
24
|
|
|
21
|
-
/** Resolve light modes, fog and dome layers for a new Sky; returns the extra dome uniforms and GLSL ({ uniforms, decl, body }) */
|
|
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 */
|
|
22
26
|
export function prepareLook(sky, st, over) {
|
|
23
|
-
/** @internal which engine lights the sky writes each frame: true /
|
|
24
|
-
// fog is also the look override (an object of style.sky.fog settings, which means true); a boolean
|
|
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
|
|
25
29
|
const fogObj = over.fog != null && typeof over.fog === 'object';
|
|
26
30
|
sky._drive = { sun: modeOf('sun', over.sun), hemi: modeOf('hemisphere', over.hemisphere), fog: fogObj ? true : modeOf('fog', over.fog) };
|
|
27
31
|
const { sun, hemi } = sky.engine.lights;
|
|
@@ -31,21 +35,20 @@ export function prepareLook(sky, st, over) {
|
|
|
31
35
|
sky._fogSpec = fogObj || over.fog == null ? st.fog : sky.engine.style.sky?.fog; // look.fog's style layer (lookFog.js)
|
|
32
36
|
sky._fog = resolveFog(sky._fogSpec);
|
|
33
37
|
sky._backdrop = resolveBackdrop(st);
|
|
34
|
-
const f =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return { uniforms, decl: [f.decl, l.decl].filter(Boolean).join('\n'), body: f.body + l.body };
|
|
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 };
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
// style.sky.backdrop: one flat color (or (sky) => color each frame) instead of the dome -- no gradient, horizon, sun / moon disk,
|
|
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,
|
|
42
45
|
// stars or clouds. The color goes straight to scene.background (no tone mapping), so what is written is what shows; the keyframes
|
|
43
46
|
// still light the world, and fog in its default 'horizon' color follows the backdrop so far things fade into it.
|
|
44
47
|
export function resolveBackdrop(st) {
|
|
45
48
|
const v = st.backdrop;
|
|
46
49
|
if (v == null) return null;
|
|
47
50
|
const color = typeof v === 'number' || typeof v === 'string' || v.isColor;
|
|
48
|
-
if (!color && typeof v !== 'function') throw
|
|
49
|
-
if (st.skybox) throw
|
|
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)');
|
|
50
53
|
return { fn: color ? null : v, color: new THREE.Color(color ? v : 0x000000) };
|
|
51
54
|
}
|