threedog 0.7.0 → 1.0.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 +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
package/docs/recipes/40-scene.md
CHANGED
|
@@ -8,9 +8,9 @@ The engine's three outward concepts are **Scene** (what stands in the world, whe
|
|
|
8
8
|
sounds, fonts: `05-props-bake.md` §3b) and **Picture** (how it looks: `09-materials-lights-models.md`). Content packs belong to Scene: they are the data form of it.
|
|
9
9
|
Patches, ops and world records are the scene's inner machinery; read them when you need them (`23-ops.md`, `18-world.md`).
|
|
10
10
|
|
|
11
|
-
Every root
|
|
11
|
+
Every root added with `engine.add` or `engine.scene.add` is registered: an id, where it was added (`main.js:50`, dev builds only), who manages it and how much a save
|
|
12
12
|
keeps. World records (template instances, props, pickups, NPCs, level nodes) share the same id space and the same query, so one question works for a
|
|
13
|
-
plain three.js mesh and for a template instance alike. `engine.
|
|
13
|
+
plain three.js mesh and for a template instance alike. Only `engine.add(obj, { id })` gives it a stable id.
|
|
14
14
|
|
|
15
15
|
## 1. Two doors into one scene
|
|
16
16
|
A scene object comes in either of two ways, and both end up in the same scene:
|
|
@@ -23,7 +23,7 @@ A scene object comes in either of two ways, and both end up in the same scene:
|
|
|
23
23
|
|
|
24
24
|
The same windmill, both ways:
|
|
25
25
|
|
|
26
|
-
```js
|
|
26
|
+
```js fragment
|
|
27
27
|
// A. plain three.js: your code builds it on every start
|
|
28
28
|
const mill = buildWindmill(); // THREE.Group
|
|
29
29
|
mill.position.set(20, 0, -10);
|
|
@@ -41,11 +41,11 @@ export default { windmill: { model: 'windmill', collide: 'circle' } };
|
|
|
41
41
|
// content/props.js
|
|
42
42
|
export default [{ id: 'windmill-hill', template: 'windmill', x: 20, z: -10 }];
|
|
43
43
|
```
|
|
44
|
-
```js
|
|
44
|
+
```js fragment
|
|
45
45
|
// main.js: a code-built model registered by name
|
|
46
46
|
engine.assets.manifest({ models: { windmill: buildWindmill } });
|
|
47
47
|
```
|
|
48
|
-
Route B gives the object an id, a source line (`engine.world.origin('windmill-hill')`), a save record and a place
|
|
48
|
+
Route B gives the object an id, a source line (`engine.world.origin('windmill-hill')`), a save record and a place the editor (F2, recipe 30 section 7) writes back to.
|
|
49
49
|
Route A gives you less ceremony and full three.js control.
|
|
50
50
|
|
|
51
51
|
## 2. What goes in content, what stays three.js
|
|
@@ -56,8 +56,7 @@ Route A gives you less ceremony and full three.js control.
|
|
|
56
56
|
| Many copies of one definition | A one-off with custom geometry or material logic |
|
|
57
57
|
| Has a state worth reading with `world.get(id)` | Pure presentation |
|
|
58
58
|
|
|
59
|
-
The rule check
|
|
60
|
-
`engine.content.spawn`, `pickups.spawn` and `npcs.add` at startup. `engine.add`, `collision.*`, `rigid.*`, `interactions.add` and the
|
|
59
|
+
The rule check R33 flags only calls that would run again after a load and so duplicate saved data (recipe 30 section 6). `engine.add`, `collision.*`, `rigid.*`, `interactions.add` and the
|
|
61
60
|
like are fine at startup.
|
|
62
61
|
|
|
63
62
|
## 3. Which state a save keeps
|
|
@@ -76,15 +75,15 @@ inside an op with `engine.content.spawn(name, at)`: a record is saved whole.
|
|
|
76
75
|
|
|
77
76
|
## 4. Give it an id
|
|
78
77
|
```js
|
|
79
|
-
const windmill =
|
|
78
|
+
const windmill = new THREE.Group(); // any Object3D
|
|
80
79
|
engine.add(windmill, { id: 'windmill' }); // at setup: thing.set / thing.remove changes to it are saved
|
|
81
|
-
engine.add(
|
|
80
|
+
engine.add(new THREE.Group()); // effects need no id: obj#7, this session only
|
|
82
81
|
engine.thing('windmill');
|
|
83
82
|
// { id: 'windmill', kind: 'Group', owner: 'game', at: 'main.js:50', phase: 'setup', saved: 'code',
|
|
84
83
|
// keeps: ['position, rotation, scale, visibility and removal made with thing.set / thing.remove (scene save part)'],
|
|
85
84
|
// loses: ['geometry and material changes', 'children added later', 'userData', ...], edit: 'added by code at main.js:50 (id ...)' }
|
|
86
85
|
engine.thing('windmill').object; // the live Object3D (not enumerable, so the result stays JSON-able)
|
|
87
|
-
engine.
|
|
86
|
+
engine.pick(0, 0)?.thing; // any child resolves to its registered root
|
|
88
87
|
```
|
|
89
88
|
- The id is `{ id }`, else a session id `obj#n` (session tier: never saved). `obj.name` is not an id (GLB roots are all called `Scene`): it only helps `engine.thing(name)` find the object. An id is a non-empty string without `#`,
|
|
90
89
|
unique across `engine.add` objects and world records: a clash throws (`thing-id`) from either side (`engine.add` or `world.add`) and says which one holds it.
|
|
@@ -99,7 +98,8 @@ engine.thing(engine.pick(0, 0).object).id; // any child resolves to its
|
|
|
99
98
|
const args = { id: 'windmill', position: [5, 0, 2], rotation: 1.2 }; // rotation: a number is yaw, or [x, y, z]; scale: a number or [x, y, z]
|
|
100
99
|
const r = engine.ops.run('thing.set', args);
|
|
101
100
|
engine.ops.undo('thing.set', args, r.value); // back where it was
|
|
102
|
-
engine.ops.run('thing.remove', { id: 'windmill' });
|
|
101
|
+
const gone = engine.ops.run('thing.remove', { id: 'windmill' }); // detached and kept: undo puts it back
|
|
102
|
+
engine.ops.undo('thing.remove', { id: 'windmill' }, gone.value);
|
|
103
103
|
```
|
|
104
104
|
- A world record id turns into `world.set` / `world.move` (`rot` / `scale` are template instance fields) and `world.remove`; the model follows the
|
|
105
105
|
record. `visible` is refused for a record (`recordVisible`): hide its model with `present({ show })` and a field.
|
|
@@ -123,16 +123,14 @@ write a template, add a placement with an id. Delete the `engine.add` line. Noth
|
|
|
123
123
|
op are listed by `saves.save()` and in `describe().scene.unsaved`.
|
|
124
124
|
- `engine.add` of a world model throws (`thing-owned`): world adds, places and tears down its models.
|
|
125
125
|
- Code that moves a `positionFrom: 'record'` world model outside its present `update` is warned once and listed in `describe().scene.conflicts`.
|
|
126
|
-
-
|
|
127
|
-
- Cost: a release build pays two table writes per `engine.add` (about 2 µs per add in `tests/specs/things.mjs`); dev builds also take a short stack
|
|
128
|
-
for `at`, at most 2000 per session (`describe().scene.atCapped` after that).
|
|
126
|
+
- Dev builds take a short stack for `at`, at most 2000 per session (`describe().scene.atCapped` after that).
|
|
129
127
|
|
|
130
128
|
## 7. Why is this mesh this colour? (material provenance)
|
|
131
129
|
|
|
132
130
|
`engine.inspect.scene()` / `threedog scene` list, for each mesh, one `material:` line and the renderer line (tone mapping, exposure; the same text as `describe().render`). Diagnostics only: nothing about the picture changes.
|
|
133
131
|
|
|
134
132
|
```
|
|
135
|
-
renderer:
|
|
133
|
+
renderer: aces (game) exposure 1.1 shadows pcf
|
|
136
134
|
✓ roof [Mesh] (4, 3, 0) r=2 · MeshLambertMaterial/roof
|
|
137
135
|
material: roof from game · MeshLambertMaterial #3b5168 · map x color #3b5168 (vertexColors off) · map (base colour)
|
|
138
136
|
note: map already carries colour and color #3b5168 is not white: the result is map x color (fine when it is a tint)
|
|
@@ -152,18 +150,18 @@ Plain three.js is always allowed (`engine.scene`, `engine.renderer`, `engine.cam
|
|
|
152
150
|
| your own `EffectComposer` / render call to the canvas | the engine yields the frame (`[own-frame]`), so `engine.post` effects, adaptive resolution, photo mode, `describe().render.post`; keep them with `engine.post.add(pass)` instead |
|
|
153
151
|
| `renderer.toneMappingExposure = x`, `scene.fog = ...` | the debug layer's restore (`engine.debug.override` gives the old value back) |
|
|
154
152
|
|
|
155
|
-
The engine adds nothing to your materials. The cloud shadow is a signal (`engine.uniforms.uCloudShadow`, `
|
|
153
|
+
The engine adds nothing to your materials. The cloud shadow is a signal (`engine.uniforms.uCloudShadow`, `uCloudShadowScale`, `uCloudShadowSpeed`) and a function: `applyEffects(mat)` gives a lit three.js material the engine's term, so it darkens under the drifting clouds like the engine's ground, on WebGL and WebGPU; your own shader calls `threedogCloudShadow(worldPos)` (recipe 43). Clouds dim the sun only (directional lights, every cascade included): a `PointLight` street lamp or a torch is never shaded by them. At 0 a uniform branch skips the cloud noise, and one program per material type stays. Snow and season cover work the same way: `applyEffects(mat, { season: 'ground' })` (`'foliage'` for leaves).
|
|
156
154
|
Keep the integrations by going through the engine: `applyEffects(mat, { wind, season, detail, lighting, patches })` on your material, `engine.post.add(pass | { name, fuse: { glsl }, slot })` for a screen effect.
|
|
157
155
|
|
|
158
|
-
## 9. One id, everything: explain
|
|
156
|
+
## 9. One id, everything: explain and the three kinds of change
|
|
159
157
|
```js
|
|
160
|
-
engine.thing
|
|
158
|
+
engine.explain({ thing: 'chest-home' }).detail; // CLI: threedog explain thing chest-home --full (MCP: explain); the same JSON
|
|
161
159
|
// { id, kind, owner, definition: { at: 'content/props.js:14', template, templateAt, level?, node?, spawned? }, model, materials: [{ role, name, from, keys }],
|
|
162
160
|
// state, rules: { blocksMovement, pickable, interact, height }, ops: [{ op, desc, args }], saved: { tier, keeps, loses }, change: {…}, overrides? }
|
|
163
161
|
```
|
|
164
162
|
`ops` lists the ops whose definition names this id, kind or template in the optional `targets` field (`engine.ops.define('chest.toggle', { targets: 'chest', … })`;
|
|
165
163
|
`'*'` = any thing, which `thing.set` / `thing.remove` use). `definition.at` is null in release builds and for code run without a file (page `eval`).
|
|
166
|
-
`
|
|
164
|
+
`text` says in one line where the id comes from and how to change it for good; `detail` has type `ThingExplanation`. The same `engine.explain` answers an op, a quest, a value, a module and a capability (recipe 23).
|
|
167
165
|
|
|
168
166
|
| Kind | How | Lasts |
|
|
169
167
|
|---|---|---|
|
|
@@ -173,7 +171,7 @@ engine.thing('chest-home').explain(); // CLI: threedog thing chest-home (MCP:
|
|
|
173
171
|
|
|
174
172
|
```js
|
|
175
173
|
const h = engine.debug.override('ai-session', 'windmill', { material: 'flat' }); // unlit base colour: is the colour wrong, or the light?
|
|
176
|
-
engine.debug.override('ai-session',
|
|
174
|
+
engine.debug.override('ai-session', engine.player.root, { visible: false });
|
|
177
175
|
engine.debug.override('ai-session', engine.renderer, 'toneMappingExposure', 3); // any three.js value: (object, key, value); held above picture code until remove()
|
|
178
176
|
engine.describe().scene.overrides; // [{ owner, target, material: 'flat' }, …]: the screen differs from the real state while this is non-empty
|
|
179
177
|
h.remove(); engine.debug.clear('ai-session'); // clear removes every override of that owner (and its debug.view) and nothing else
|
|
@@ -187,4 +185,3 @@ file no longer has the value you saw (someone else changed it). `content add pro
|
|
|
187
185
|
`--file content/props/town.js` picks the part of a folder kind) and `content remove <id>` deletes one. Fields are the content file's names
|
|
188
186
|
(`x`, `z`, `y`, `rot`, `scale`, `template`, `place`, `model`), not the record's `position`. It refuses, and says why with the line, for an entry built
|
|
189
187
|
by code (loop, spread, computed value), an id matching several entries (`--in props`), or an add / remove that would shift entries whose id is their position. A placed entry wins over a template or npc of the same name.
|
|
190
|
-
It finds the file through `.threedog/content-index.json` (written by the content check; rebuilt when an id is not where it says), so a write reads only that one file however many there are.
|
|
@@ -5,17 +5,14 @@
|
|
|
5
5
|
A new game draws on WebGPU, where shaders are TSL: start with [recipe 56](56-webgpu-tsl.md), whose node materials and `tsl:` patch fields do these same jobs. This page is the GLSL route, for a game made with `threedog new-game --webgl`: **write your own material or `ShaderMaterial`**, or **patch a slot** of any material with your own GLSL. The picture is the
|
|
6
6
|
game's own; this page gives building blocks, not finished pictures. There is one entry for shader code: `applyEffects`.
|
|
7
7
|
|
|
8
|
-
```js
|
|
8
|
+
```js fragment
|
|
9
9
|
const fragmentShader = '#include <threedog_lighting>\n' + myFragmentBody; // 3. engine GLSL, called inside 1 or 2
|
|
10
10
|
const mat = new THREE.ShaderMaterial({ uniforms: { ...engine.uniforms }, vertexShader, fragmentShader }); // 1. your own shader
|
|
11
11
|
applyEffects(mat2, { patches: [{ name: 'tint', slot: 'color', glsl: 'diffuseColor.rgb *= 0.9;' }] }); // 2. patch a slot
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
built-in or yours. **3. Engine GLSL functions** (`#include <threedog_wind>`, `<threedog_detail>`, `<threedog_lighting>`...) are tools you call inside 1 and 2:
|
|
17
|
-
a noise, a wrapped diffuse term, a fresnel edge. None of them is a picture. A picture is what your game's `picture/` code combines: its colors,
|
|
18
|
-
textures, light model and post. The default surface is flat (`lambert` plus vertex colors) until you write one.
|
|
14
|
+
A patch is a named piece of GLSL at a named place on any material, built-in or yours. The engine GLSL functions are tools you call inside your shader or a patch; none of them is a picture. A picture is what your
|
|
15
|
+
game's `picture/` code combines.
|
|
19
16
|
|
|
20
17
|
## Your own material
|
|
21
18
|
Any `new THREE.*Material` is fine (THREE.md), and the engine patches nothing of yours: call `applyEffects(material, { wind, clouds, season, detail, patches })` for the
|
|
@@ -27,22 +24,22 @@ engine.water.material = applyEffects(new THREE.MeshPhongMaterial({ color: 0x3070
|
|
|
27
24
|
## Patch a slot: your own GLSL
|
|
28
25
|
Write a **named patch** that names a **slot** (where the code goes) and add it with `applyEffects(material, { patches: [...] })`:
|
|
29
26
|
```js fragment
|
|
30
|
-
{ name: 'tint', slot: 'color', glsl: 'diffuseColor.rgb *= 0.9;' }
|
|
31
|
-
{ name: 'sway', slot: 'position', shadow: true, glsl: 'transformed.x += sin(position.y) * 0.1;' }
|
|
27
|
+
{ name: 'tint', slot: 'color', glsl: 'diffuseColor.rgb *= 0.9;' }, // one slot
|
|
28
|
+
{ name: 'sway', slot: 'position', shadow: true, glsl: 'transformed.x += sin(position.y) * 0.1;' }, // moves vertices: the shadow follows
|
|
32
29
|
{ name: 'glow', pars: 'uniform float uGlow;', uniforms: { uGlow: { value: 0.5 } },
|
|
33
30
|
glsl: { color: 'diffuseColor.rgb *= 0.95;', output: 'outgoingLight += uGlow * 0.1;' } } // several slots; pars = declarations
|
|
34
31
|
```
|
|
35
32
|
The full form, with every field:
|
|
36
33
|
```js fragment
|
|
37
34
|
{ name: 'fuzz', // one name per effect; the same name again replaces it
|
|
38
|
-
slot: 'color',
|
|
35
|
+
slot: 'color',
|
|
39
36
|
glsl: 'diffuseColor.rgb *= 1.0 - uFuzz * 0.5;',
|
|
40
37
|
pars: 'uniform float uFuzz;', // declarations at the top of every stage the patch touches (or { vertex, fragment })
|
|
41
|
-
cacheKey: 'v1',
|
|
38
|
+
cacheKey: 'v1',
|
|
42
39
|
uniforms: { uFuzz: { value: 0.3 } }, // numbers live here, so materials with different values share a program
|
|
43
|
-
needs: { patches: ['world'], data: ['vertexColors'] },
|
|
44
|
-
conflicts: ['wind'],
|
|
45
|
-
shadow: false }
|
|
40
|
+
needs: { patches: ['world'], data: ['vertexColors'] },
|
|
41
|
+
conflicts: ['wind'],
|
|
42
|
+
shadow: false }
|
|
46
43
|
```
|
|
47
44
|
Slots (the one table is `render/slots.js`; the engine's own wind, clouds, season, detail, lighting and cascades use the same names, and on WebGPU
|
|
48
45
|
the same names map to node properties through a patch's `tsl` field, recipe 56). An unknown slot throws with this list.
|
|
@@ -60,7 +57,7 @@ the same names map to node properties through a patch's `tsl` field, recipe 56).
|
|
|
60
57
|
| `emissive` | after `emissivemap_fragment` | `emissiveNode` | totalEmissiveRadiance (vec3, write), diffuseColor | emitted light after the emissive map |
|
|
61
58
|
| `lightsPars` | after `shadowmap_pars_fragment` | WebGL only | declarations; three's light structs, getShadow() and directionalLights[] are already declared | functions that call three's light / shadow helpers (pars goes before them); WebGPU: TSL has no declaration area: the light's direction and shadow come to the lighting slot's direct(light, ctx) hook |
|
|
62
59
|
| `lightingModel` | replace `lights_fragment_begin` | WebGL only | geometryPosition, geometryNormal, material, reflectedLight; your code replaces three's light loop | replace how lights are summed (one patch per material may take it); WebGPU: use the lighting slot's hooks { start, light, direct, after }, or a NodeMaterial with your own setupLightingModel |
|
|
63
|
-
| `lighting` | after `lights_fragment_end` | inside `setupLightingModel` | reflectedLight.directDiffuse / directSpecular / indirectDiffuse (write), normal, diffuseColor, vViewPosition | after lights are summed:
|
|
60
|
+
| `lighting` | after `lights_fragment_end` | inside `setupLightingModel` | reflectedLight.directDiffuse / directSpecular / indirectDiffuse (write), normal, diffuseColor, vViewPosition | after lights are summed: wrap, shadow tint, rim; WebGPU: hooks { start, light, direct, after }: light(light, ctx) returns a new color for one light before three lights the surface with it (what GLSL does by wrapping three's light info in lightsPars), direct(light, ctx) sees each light in three's loop and adds to its own sums, which join the summed light at the patch's place in the list, then its after() runs: the same order as WebGL |
|
|
64
61
|
| `output` | before `opaque_fragment` | inside `setupOutput` | outgoingLight (vec3, write), diffuseColor.a | the final lit color, before fog and tone mapping |
|
|
65
62
|
| `fogPars` | after `fog_pars_fragment` | WebGL only | declarations; fogColor and fogNear / fogFar or fogDensity are already declared (inside #ifdef USE_FOG) | fog functions that read three's fog uniforms (wrap them in #ifdef USE_FOG); WebGPU: fog on WebGPU is scene.fogNode, set by the game |
|
|
66
63
|
| `fog` | replace `fog_fragment` | WebGL only | gl_FragColor (write, tone mapped already), fogColor, vFogDepth, fogNear / fogFar or fogDensity (inside #ifdef USE_FOG) | replace how fog mixes into the final color (one patch per material may take it); WebGPU: fog on WebGPU is scene.fogNode, set by the game |
|
|
@@ -76,9 +73,7 @@ cacheKey so the old program is not reused) without reloading the page, and a com
|
|
|
76
73
|
`shader error in file shaders/fuzz.glsl:4, patch 'fuzz' (slot color)`. Text copied into your own `onBeforeCompile` closure cannot be found: the page
|
|
77
74
|
reloads instead. Builds get the plain text. Plain Vite equivalent: `import.meta.hot.accept('./fuzz.glsl?raw', m => { mat.fragmentShader = m.default; mat.needsUpdate = true; })`.
|
|
78
75
|
`MeshBasicMaterial` has no lights, so no `normal` / `lighting` slots; `lambert` has no `roughness`. A slot the material lacks throws when the patch is added.
|
|
79
|
-
`vThreedogWorld` is the world position (instancing and batching included); it comes from the engine's `world` patch
|
|
80
|
-
`vThreedogWorld` gets `world` added in front of it even without `needs` (a one-time dev note asks for the `needs: { patches: ['world'] }` line, which
|
|
81
|
-
says the same thing in the patch itself). Meshes with several patches stack them in one program per distinct combination.
|
|
76
|
+
`vThreedogWorld` is the world position (instancing and batching included); it comes from the engine's `world` patch, added in front of a patch whose GLSL reads it even without `needs` (a one-time dev note asks for the line). Meshes with several patches stack them in one program per distinct combination.
|
|
82
77
|
|
|
83
78
|
The `normal` slot also fixes a three.js rule that surprises card and grass art: with `side: THREE.DoubleSide` three flips the normal of every back
|
|
84
79
|
face (`faceDirection`), so a blade or card whose normals all point up shades dark from the side you see its back. Keep the authored normal by
|
|
@@ -90,34 +85,22 @@ Patches on one material must agree. Each patch declares what it relies on, and a
|
|
|
90
85
|
| Field | Meaning | Checked |
|
|
91
86
|
|---|---|---|
|
|
92
87
|
| `needs.data` | Program inputs the code reads: `'instancing'`, `'instancingColor'`, `'vertexColors'`, `'skinning'`, `'batching'` | when the program compiles (console.error once per material) |
|
|
93
|
-
| `needs.patches` | Patches it builds on, e.g. `['world']` for the `vThreedogWorld` varying
|
|
88
|
+
| `needs.patches` | Patches it builds on, e.g. `['world']` for the `vThreedogWorld` varying | when added |
|
|
94
89
|
| `conflicts` | Patch names it cannot share a material with | when added, both ways |
|
|
95
|
-
| `uniforms` | A uniform name belongs to one patch; share `engine.uniforms` (`uTime`, `uWind`, `
|
|
90
|
+
| `uniforms` | A uniform name belongs to one patch; share `engine.uniforms` (`uTime`, `uWind`, `uWeatherCloud`...) instead of making your own `uTime` | when added |
|
|
96
91
|
| `shadow` | Render steps: without it the color pass only; `true` also runs its vertex code in the depth (sun / spot shadows) and distance (point-light shadows) passes | - |
|
|
97
92
|
| `cacheKey` | Changes whenever the GLSL text changes (defines, branches), never for uniform values; the program key joins every patch's `name=cacheKey` in order | same name + cacheKey with different code throws. On WebGPU the program also follows the identity of each `tsl` function, so make it once and reuse it: one written fresh per material costs a program per material |
|
|
98
|
-
```js
|
|
93
|
+
```js fragment
|
|
99
94
|
applyEffects(mat, { wind: 0.03, season: 'foliage', patches: [{ name: 'ripple', needs: { patches: ['world'] }, conflicts: ['wind'],
|
|
100
95
|
slot: 'color', glsl: 'diffuseColor.rgb *= 0.9 + 0.1 * sin(vThreedogWorld.x);' }] }); // throws: 'wind' and 'ripple' cannot be combined
|
|
101
96
|
```
|
|
102
97
|
|
|
103
|
-
**Exit: raw three.js anchors** (WebGL only
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
| stage | chunk | what is in scope after it |
|
|
108
|
-
|---|---|---|
|
|
109
|
-
| vertex | `begin_vertex` | `transformed` (object space; wind moves it here) |
|
|
110
|
-
| vertex | `project_vertex` | `mvPosition`, `gl_Position` |
|
|
111
|
-
| vertex | `worldpos_vertex` | `worldPosition` (only when shadows, env maps or transmission need it) |
|
|
112
|
-
| fragment | `map_fragment` `color_fragment` | `diffuseColor` (rgb after the map, then the vertex colors) |
|
|
113
|
-
| fragment | `roughnessmap_fragment` `metalnessmap_fragment` | `roughnessFactor`, `metalnessFactor` (standard / physical) |
|
|
114
|
-
| fragment | `normal_fragment_begin` `normal_fragment_maps` | `normal` (view space), `faceDirection`; `vViewPosition` = minus the view-space position |
|
|
115
|
-
| fragment | `emissivemap_fragment` | `totalEmissiveRadiance` |
|
|
116
|
-
| fragment | `lights_fragment_begin` ... `lights_fragment_end` | `reflectedLight.directDiffuse / indirectDiffuse / directSpecular / indirectSpecular`; after `_end` they are final |
|
|
117
|
-
| fragment | `opaque_fragment` | `outgoingLight` and `gl_FragColor`; (called `output_fragment` before r154) |
|
|
98
|
+
**Exit: raw three.js anchors** (WebGL only). Where no slot fits, `glsl: { vertex|fragment: { <chunk>: code } }` puts code after `#include <chunk>` (a value may be `{ before, after, replace }`; the key `pars` is
|
|
99
|
+
declarations at the top of that stage). A missing chunk throws when the patch is added, not as a silent no-op. Chunk names are three's, in `three/src/renderers/shaders`; the slot table above gives the common ones and
|
|
100
|
+
what is in scope. `worldPosition` exists after `worldpos_vertex` only when shadows, env maps or transmission need it.
|
|
118
101
|
|
|
119
102
|
### Engine effects in your own ShaderMaterial
|
|
120
|
-
```js
|
|
103
|
+
```js fragment
|
|
121
104
|
const mat = new THREE.ShaderMaterial({ uniforms: { ...engine.uniforms, uMine: { value: 1 } }, vertexShader, fragmentShader });
|
|
122
105
|
```
|
|
123
106
|
The engine never patches a ShaderMaterial of yours; call its effects as functions instead (the automatic patches call the same ones):
|
|
@@ -125,12 +108,10 @@ The engine never patches a ShaderMaterial of yours; call its effects as function
|
|
|
125
108
|
|
|
126
109
|
| include | function |
|
|
127
110
|
|---|---|
|
|
128
|
-
| `#include <threedog_uniforms>` | declares every
|
|
111
|
+
| `#include <threedog_uniforms>` | declares every name on `engine.uniforms`, for example `uTime`, `uWind`, `uWeatherCloud`, `uRain`, `uFoliageTint`, `uGroundCover` (snow / ash cover amount alone: x foliage, y ground), `uSunDir`, `uDaylight`, `uNight`, `uSkyHorizon` (include once, in each stage that uses them; do not declare one of these yourself as well) |
|
|
129
112
|
| `#include <threedog_wind>` | `vec3 threedogWind(vec3 position, vec3 origin, float amplitude)`: object-space sway offset, higher vertices sway more; `origin` is the object's world origin (its phase) |
|
|
130
113
|
| `#include <threedog_cloudShadow>` | `float threedogCloudShadow(vec3 worldPos)`: light factor 0-1 under the drifting clouds |
|
|
131
114
|
| `#include <threedog_season>` | `vec3 threedogSeason(vec3 color, int kind)`: season tint, kind 0 foliage, 1 ground |
|
|
132
|
-
|
|
133
|
-
To change the cloud shadow or the season tint on the engine's own materials (not only in your shader), replace the term: `engine.terms.cloudShadow({ glsl, tsl })` / `engine.terms.season(kind => ({ glsl, tsl }))`, or `false` to drop it (recipe 52).
|
|
134
115
|
| `#include <threedog_detail>` | `vec4 threedogDetailNoise(vec2 p, int kind, float octaves)`: the detail noises, kind 0 grain, 1 paper, 2 stroke, 3 dabs, returns (gray rgb, height 0-1); `vec3 threedogDetailBump(vec3 surfPos, vec3 surfNorm, float h, float k, float faceDir)`: screen-space bump. No uniforms. `p` is yours: world xz for a pattern fixed to the ground (it shrinks with distance), `gl_FragCoord.xy / 3.0` for one the same size all over the screen (3-pixel cells; device pixels, so it follows the pixel ratio) |
|
|
135
116
|
| `#include <threedog_lighting>` | `vec3 threedogWrapDiffuse(float nl, float wrap, vec3 lightColor, float shadow, vec3 albedo)` (light to add), `vec3 threedogShadowTint(vec3 ambient, vec3 tint, float strength, float soft, float nl, float shadow)` (the new ambient), `vec3 threedogRim(vec3 normal, vec3 viewDir, vec3 color, float strength, float power, float shadowSide, float nl)` (light to add); nl = dot(normal, sunDir), shadow 1 lit / 0 shadowed. No uniforms |
|
|
136
117
|
|
|
@@ -139,18 +120,16 @@ To change the cloud shadow or the season tint on the engine's own materials (not
|
|
|
139
120
|
#include <threedog_wind>
|
|
140
121
|
void main() { vec3 p = position + threedogWind(position, (modelMatrix * vec4(0, 0, 0, 1)).xyz, 0.05); gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0); }
|
|
141
122
|
```
|
|
142
|
-
The `detail` effect below calls these same functions, so a value tuned on a material reads the same in your shader. To give
|
|
143
|
-
season tint, leave the engine's out (`clouds: false`, no `season`) and write your own patch with these functions
|
|
144
|
-
The pixel and program-count guarantees are in `tests/specs/surface.mjs`.
|
|
123
|
+
The `detail` effect below calls these same functions, so a value tuned on a material reads the same in your shader. To give one material another cloud shadow or
|
|
124
|
+
season tint, leave the engine's out (`clouds: false`, no `season`) and write your own patch with these functions; on every engine material at once: `engine.shaderTerms` (recipe 52).
|
|
145
125
|
|
|
146
126
|
## Ready-made effects: `detail`, light shaping, seasons
|
|
147
|
-
Each one puts a function above on a built-in material, with its numbers as uniforms. They are building blocks with fixed shapes
|
|
148
|
-
not finished pictures: combine them with your own colors, textures and patches, and when one does not give what you want, write the shader yourself and call the same function there.
|
|
127
|
+
Each one puts a function above on a built-in material, with its numbers as uniforms. They are building blocks with fixed shapes, not finished pictures: when one does not give what you want, write the shader yourself and call the same function there.
|
|
149
128
|
|
|
150
129
|
**`detail`**: `applyEffects(material, { detail: { noise: 'paper', strength: 0.4 } })`. A noise pattern, a texture or your own GLSL laid over the surface in world space (needs no UVs). Every number is a uniform, so
|
|
151
|
-
|
|
130
|
+
materials with different `scale` / `strength` / `direction` compile **one** program on WebGL.
|
|
152
131
|
WebGPURenderer keys its program by the patch's uniform objects instead: materials with the same `detail` options share one
|
|
153
|
-
patch object, so they share one program there too
|
|
132
|
+
patch object, so they share one program there too; different numbers build one each. Sharing
|
|
154
133
|
means one set of values: a uniform changed on one of them changes all that share those options.
|
|
155
134
|
|
|
156
135
|
| key | meaning |
|
|
@@ -169,13 +148,13 @@ Which channels (color, normal, roughness) are on is fixed when the material is m
|
|
|
169
148
|
The ground takes the same object as `terrain({ detail })`, its live numbers are `engine.terrain.uniforms`; which detail suits which ground: recipe 53.
|
|
170
149
|
|
|
171
150
|
**Light shaping** is a patch in the `lighting` slot, after the lights are summed. three has no "shadow color": a shadow only removes the sun's light. The ready-made form:
|
|
172
|
-
```js
|
|
151
|
+
```js fragment
|
|
173
152
|
applyEffects(mat, { lighting: { wrap: 0.4, shadowTint: { color: 0x4060a0, strength: 0.6, soft: 0.3 }, rim: { color: 0xffe0b0, strength: 0.4, power: 3, shadowSide: 0 } } });
|
|
174
153
|
applyEffects(mat, { lighting: { glsl: 'void threedogLighting(inout ReflectedLight light, vec3 normal, vec3 viewDir, vec3 sunDir, float sunShadow, vec3 albedo){ ... }' } }); // your own function
|
|
175
154
|
```
|
|
176
155
|
All numbers are uniforms, and materials with the same options share one program. Written by hand, the first directional
|
|
177
156
|
light is the sun (three sorts shadow casters first), so a patch reads it there and calls `threedogRim`, `threedogWrapDiffuse` or `threedogShadowTint`:
|
|
178
|
-
```js
|
|
157
|
+
```js fragment
|
|
179
158
|
const rim = { name: 'rim', slot: 'lighting', pars: '#include <threedog_lighting>', glsl: `
|
|
180
159
|
#if NUM_DIR_LIGHTS > 0
|
|
181
160
|
float nl = dot(normal, directionalLights[0].direction);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
# Water and rain/snow: depth color, foam, reflections, particles, lightning
|
|
1
|
+
# Water and rain/snow: depth color, foam, reflections, particles, snow cover, lightning
|
|
2
|
+
|
|
3
|
+
**In this recipe**: water look and material, foam and depth, a reflecting mirror (WebGL addon and WebGPU node), weather particles, snow that settles, lightning.
|
|
2
4
|
|
|
3
5
|
```js
|
|
4
6
|
engine.use(water({ level: 2 }));
|
|
@@ -10,20 +12,14 @@ engine.water.normalMap('water-n', { scale: 0.4, repeat: 0.05, speed: [0.01, 0.00
|
|
|
10
12
|
```
|
|
11
13
|
|
|
12
14
|
For an AI that wants water or weather particles to look a way the defaults do not. `water()` takes the structure only (`sea`, `level`, `flat`, `size`,
|
|
13
|
-
`segments`); the water is neutral gray until your `picture/` code writes it. Lights
|
|
14
|
-
none of `depthColor`, `foam`, `surface` keeps the plain shader and pays nothing
|
|
15
|
+
`segments`); the water is neutral gray until your `picture/` code writes it. Lights and fog are in `34-environment-lighting.md`, the sky in `08-weather-sky.md`. Water that uses
|
|
16
|
+
none of `depthColor`, `foam`, `surface` keeps the plain shader and pays nothing. Four exits: a material write, a
|
|
15
17
|
uniform, a GLSL function you replace, or your own material.
|
|
16
18
|
|
|
17
19
|
## Water: material and uniforms
|
|
18
20
|
`engine.water.material` is shared by every water mesh and is a `MeshLambertMaterial` by default: color, opacity and anything else three.js has on it are
|
|
19
21
|
plain writes. Lambert has no highlight; for `shininess` / `specular` set your own Phong material (below). `engine.water.uniforms` are `{ value }` objects:
|
|
20
|
-
|
|
21
|
-
| Uniform | Default | What it does |
|
|
22
|
-
|---|---|---|
|
|
23
|
-
| `uWave` | 1 | multiplies the wave function (0 = flat) |
|
|
24
|
-
| `uWaveScale` | 1 | world position scale fed to the wave function |
|
|
25
|
-
| `uWaveSpeed` | 1 | time scale fed to the wave function |
|
|
26
|
-
| `uFresnel` | 0.5 | grazing angles blend toward the fog color, or the sky's horizon with no fog (0 = off) |
|
|
22
|
+
`uWave` multiplies the wave function (0 = flat), `uWaveScale` scales the world position fed to it, `uWaveSpeed` the time; all three default to 1. `uFresnel` (default 0.5, 0 = off) blends grazing angles toward the fog color, or the sky's horizon with no fog.
|
|
27
23
|
|
|
28
24
|
## Water: depth color and crest foam
|
|
29
25
|
```js fragment
|
|
@@ -31,22 +27,17 @@ engine.water.shader({ depthColor: { shallow: 0x55ddcc, deep: 0x082040 } });
|
|
|
31
27
|
engine.water.shader({ depthColor: { shallow: 0x7fe0d0, deep: 0x0a3050, by: 'wave', curve: 1.5 } }); // shallow on the crests, deep in the troughs
|
|
32
28
|
engine.water.shader({ foam: { color: 0xffffff, start: 0.55, end: 0.85, opacity: 1 } }); // white on the wave tops; foam: true = these defaults
|
|
33
29
|
```
|
|
34
|
-
- `shader()` decides which GLSL exists, so
|
|
35
|
-
earlier call gave, `null` takes one back out. It refreshes `engine.water.patches` and `engine.water.uniforms`; `uWave`, `uWaveScale`, `uWaveSpeed`,
|
|
36
|
-
`uFresnel` stay the same objects.
|
|
30
|
+
- `shader()` decides which GLSL exists, so each call is one recompile: a scene change, not a frame. What it keeps and refreshes: `../api/water.md`.
|
|
37
31
|
- `depthColor` replaces the material color (opacity stays). `'view'` is a fresnel-style blend by the view angle, `'wave'` blends by the wave height; neither
|
|
38
32
|
needs a depth texture. `curve` bends the blend (above 1 keeps more of the shallow color). A color left out is a neutral gray (light for
|
|
39
33
|
`shallow`, dark for `deep`): the engine picks no water color, so set both.
|
|
40
34
|
- `foam` uses the same wave height as the vertices: `start` / `end` are fractions of the peak height (`waveMax` of the `wave` function, default 0.29) where
|
|
41
|
-
foam begins and is full. Foam is opaque even on transparent water. All numbers are uniforms (`engine.water.uniforms.uFoamStart.value
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
read per pixel. Do it yourself with your own material: render the scene's depth to a target before the water draws
|
|
46
|
-
(`material.onBeforeRender`), pass it as a uniform, and in your fragment compare the scene depth with this fragment's depth, both turned into meters with three's
|
|
47
|
-
`perspectiveDepthToViewZ` (`#include <packing>`); foam
|
|
48
|
-
where the difference is under about a meter. A cheap fake: `engine.addWaterBody` lakes have known radii, so a surface function can foam the
|
|
35
|
+
foam begins and is full. Foam is opaque even on transparent water. All numbers are uniforms (`engine.water.uniforms.uFoamStart.value`).
|
|
36
|
+
- **Shore foam is not built in.** A foam line where water meets land needs the distance to the ground under each pixel, so an extra depth pass or a height lookup per pixel.
|
|
37
|
+
Do it with your own material: render the scene's depth to a target before the water draws (`material.onBeforeRender`), pass it as a uniform, and compare it with this fragment's depth, both in meters through three's
|
|
38
|
+
`perspectiveDepthToViewZ` (`#include <packing>`). A cheap fake: `engine.addWaterBody` lakes have known radii, so a surface function can foam the
|
|
49
39
|
ring `length(worldPos.xz - center) > radius - 1.0` (pass the center and radius as `uniforms`).
|
|
40
|
+
- A look that changes with real depth (tint, opacity) reads depth as the water level minus `engine.ground.height(x, z)`: once per vertex of a subdivided plane, or baked into an attribute a material reads.
|
|
50
41
|
|
|
51
42
|
## Water: replace the wave or the surface function (GLSL)
|
|
52
43
|
```js
|
|
@@ -71,13 +62,11 @@ engine.water.shader({
|
|
|
71
62
|
- Your GLSL has no WebGPU form (the GLSL route is for `--webgl` games): on `renderer: 'webgpu'` start() names the patch. The built-in wave, depth color and foam run on both renderers.
|
|
72
63
|
|
|
73
64
|
## Water: normal map
|
|
74
|
-
`engine.water.normalMap(name, { scale, repeat, speed })`
|
|
75
|
-
per meter (rewrites the meshes' UVs once), `speed` the scroll `[x, z]` per second. Keys left out keep their value; the same name again only changes those;
|
|
76
|
-
`null` takes it off. It returns the texture, also readable as `engine.water.normalTexture`. A material of your own takes that texture itself
|
|
65
|
+
`engine.water.normalMap(name, { scale, repeat, speed })` goes on the engine's material only (keys in `../api/water.md`). A material of your own takes the texture itself
|
|
77
66
|
(`myMaterial.normalMap = engine.water.normalTexture`); the tiling and the scroll run whatever material draws.
|
|
78
67
|
|
|
79
68
|
## Water: your own material (reflections, refraction)
|
|
80
|
-
```js
|
|
69
|
+
```js fragment
|
|
81
70
|
engine.water.material = applyEffects(new THREE.MeshPhongMaterial({ color: 0x3070a0, shininess: 90, specular: 0xaaaaaa, transparent: true, opacity: 0.85 }),
|
|
82
71
|
{ patches: engine.water.patches }); // keep the waves, the surface and the fresnel
|
|
83
72
|
engine.water.material = new THREE.ShaderMaterial({ uniforms: engine.water.uniforms, vertexShader, fragmentShader }); // or all your own
|
|
@@ -86,7 +75,8 @@ Setting `engine.water.material` swaps it on every water mesh, now and later, and
|
|
|
86
75
|
stay (pick from the list by `name` for only some: `waves`, `waterSurface`, `fresnel`; `waterSurface` needs `waves` before it). After a later `shader()` call
|
|
87
76
|
patch your material again; the engine only rebuilds its own. Your material reads `engine.water.uniforms` like the built-in one, and the engine still
|
|
88
77
|
builds the meshes, snaps the sea to the focus and scrolls the normal map. Reflections and refraction are not built in (each one renders the scene a
|
|
89
|
-
second time).
|
|
78
|
+
second time). **The `Reflector` addon below is WebGL only**: on the default WebGPU renderer its `ShaderMaterial` stops the page, so use the WebGPU route
|
|
79
|
+
further down. On WebGL, three's `Reflector` addon works through this exit; the engine water is pre-rotated geometry, so the mirror gets the mesh's
|
|
90
80
|
matrix turned into the XY plane it expects:
|
|
91
81
|
|
|
92
82
|
```js
|
|
@@ -105,12 +95,26 @@ m.onBeforeRender = (renderer, scene, camera, geometry, mesh) => {
|
|
|
105
95
|
};
|
|
106
96
|
engine.water.material = m;
|
|
107
97
|
```
|
|
98
|
+
**WebGPU route** (default renderer): three's `reflector` node (`three/tsl`) draws the scene into a texture the material samples by screen position, so the mesh
|
|
99
|
+
geometry does not matter. The mirror is the XY plane of `target` (normal +Z): turn it flat, put it at the water level. Plain three.js, not run in this repo's tests.
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
import * as THREE from 'three/webgpu';
|
|
103
|
+
import { reflector, mix, color } from 'three/tsl';
|
|
104
|
+
|
|
105
|
+
const mirror = reflector({ resolutionScale: 0.5 }); // half-size render target
|
|
106
|
+
mirror.target.rotateX(-Math.PI / 2); // XY plane -> flat, normal up
|
|
107
|
+
mirror.target.position.y = 0; // the water level
|
|
108
|
+
engine.scene.add(mirror.target); // must be in the scene
|
|
109
|
+
const m = new THREE.MeshBasicNodeMaterial();
|
|
110
|
+
m.colorNode = mix(color(0x2a5a7a), mirror, 0.6); // 0 = water color, 1 = pure reflection
|
|
111
|
+
engine.water.material = m;
|
|
112
|
+
```
|
|
108
113
|
- Cost: the whole scene drawn once more per frame per water mesh at `textureWidth` x `textureHeight` (shadows are not re-rendered). Use 256-512
|
|
109
114
|
on phones; on `engine.tier === 'low'` keep the default material instead.
|
|
110
115
|
- One mirror plane: the material is shared, so water bodies at other levels need `water({ sea: false })` or their own mirror. The Reflector's
|
|
111
116
|
shader has no waves or fog; for both, copy its `fragmentShader` into a `MeshPhongMaterial` patch that samples `tDiffuse` with `textureMatrix`.
|
|
112
117
|
- three's `Refractor` addon (next to `Reflector`) reads `matrixWorld` as an XY plane too, so the same adapter applies (not covered by a test).
|
|
113
|
-
- Tested: `tests/specs/appearance-water.mjs` renders this exact example and finds the reflected box in the mirror texture.
|
|
114
118
|
|
|
115
119
|
## Water: your own meshes (three's `Water` addon, your own geometry)
|
|
116
120
|
The water module's material is yours to swap, its meshes are not. For water drawn entirely your way, leave `water()` out and draw it in plain
|
|
@@ -121,7 +125,7 @@ you when one comes or goes, so swimming, buoyancy and anything else reading the
|
|
|
121
125
|
## Weather particles: rain and snow parameters
|
|
122
126
|
`weather({ rain, snow })` (left-out keys keep the built-in picture):
|
|
123
127
|
|
|
124
|
-
```js
|
|
128
|
+
```js fragment
|
|
125
129
|
weather({ types,
|
|
126
130
|
rain: { color: 0xa8b8d0, opacity: 0.6, length: 1.2, speed: 26, slant: 1.5, density: a => a * a }, // streaks; sparse in a drizzle
|
|
127
131
|
// rain: { shape: 'soft', size: 10, maxSize: 6, sway: 0.3 }, // drops as soft sprites instead of streaks
|
|
@@ -129,14 +133,11 @@ weather({ types,
|
|
|
129
133
|
// snow: { texture: 'flake' }, // a sprite image replaces the shape
|
|
130
134
|
});
|
|
131
135
|
```
|
|
132
|
-
|
|
133
|
-
(`size` pixels at 3 m, capped at `maxSize`; drifts `sway` meters). `speed` is the fall in m/s.
|
|
134
|
-
- `density: amount => share`: how many particles show at a weather amount 0..1 (rain `a => min(1, a * 1.2)`, snow `() => 1`); opacity still
|
|
135
|
-
follows the amount. `count` per system (default `weather({ particles })`, halved on low-tier devices). Coverage is `weather({ area })`.
|
|
136
|
+
The keys and defaults are `WeatherParticles` in `types/world.d.ts`. `density` decides how many particles show at a weather amount; opacity follows the amount as well. Coverage is `weather({ area })`.
|
|
136
137
|
|
|
137
|
-
At run time each system is in `engine.weather.particles`, and every number is a plain write, live on both renderers
|
|
138
|
+
At run time each system is in `engine.weather.particles`, and every number is a plain write, live on both renderers. `particles.rain` exists only when the weather table has a `rain` field (`particles.snow` likewise for `snow`); with a table of your own, read it as `particles.rain?.`:
|
|
138
139
|
```js
|
|
139
|
-
const rain = engine.weather.particles.rain;
|
|
140
|
+
const rain = engine.weather.particles.rain, myFragment = 'void main() { gl_FragColor = vec4(0.7, 0.8, 1.0, 0.4); }';
|
|
140
141
|
rain.spec.speed = 30; rain.spec.opacity = 0.3; rain.spec.slant = 2; // read each frame; density too
|
|
141
142
|
rain.uniforms.uColor.value.set(0xa8b8d0); rain.uniforms.uLen.value = 1.2; // sprites: uPx (size), uMaxPx (maxSize), uSwayAmp (sway)
|
|
142
143
|
rain.material = new THREE.ShaderMaterial({ uniforms: rain.uniforms, vertexShader: rain.material.vertexShader,
|
|
@@ -146,7 +147,7 @@ engine.weather.overcastColor.set(0x667788); engine.weather.lightningBrightness =
|
|
|
146
147
|
The fall and the follow-the-camera wrap live in the vertex shader, so a material of your own shares `uniforms` and keeps a vertex shader like it.
|
|
147
148
|
|
|
148
149
|
## Weather particles: replace the shaders (GLSL)
|
|
149
|
-
```js
|
|
150
|
+
```js fragment
|
|
150
151
|
weather({ types, snow: { uniforms: { uTint: [1, 0.85, 0.9] }, glsl: { fragment: `uniform float uOpacity;
|
|
151
152
|
void main(){
|
|
152
153
|
vec2 d = gl_PointCoord - 0.5;
|
|
@@ -157,35 +158,40 @@ void main(){
|
|
|
157
158
|
}` } } });
|
|
158
159
|
```
|
|
159
160
|
`glsl.vertex` / `glsl.fragment` are the whole shader text; copy `modules/weather/shaders.js` (`lineVert lineFrag pointVert pointFrag`) as the
|
|
160
|
-
start
|
|
161
|
-
`
|
|
162
|
-
|
|
161
|
+
start (what is in scope: `glsl` in `WeatherParticles`; the attribute `aEnd` is 0 at the head, 1 at the tail). Your `uniforms` are declared for you; declare the built-in ones you use, as the copies do. Keep
|
|
162
|
+
the two `#include` lines so the color matches three's materials with and without post-processing. WebGPURenderer does not compile GLSL text: `engine.weather.defineField(field, { create })` with a node material there.
|
|
163
|
+
|
|
164
|
+
## Snow that settles: `weather({ snow: { cover } })`
|
|
165
|
+
```js fragment
|
|
166
|
+
weather({ types, snow: { size: 18, cover: { foliage: 0xf2f4f6, ground: 0xeef0f2, strength: 0.8 } } });
|
|
167
|
+
```
|
|
168
|
+
- While the weather's `snow` amount rises (any type with `snow > 0`), the foliage / ground season tint moves `strength` of the way toward
|
|
169
|
+
these colors, and melts back as it falls. It reuses the season patch uniforms (`uFoliageTint/Mix`, `uGroundTint/Mix`): vegetation, terrain
|
|
170
|
+
and any material with `applyEffects(m, { season: 'ground' })` follow; no extra shader pass. It needs `sky()`, which holds the point the cover goes through.
|
|
171
|
+
- Over a `mode: 'mix'` season the two blend into one mix; a `'multiply'` season gives way while snow lies (use `'mix'` for smooth fades).
|
|
172
|
+
- Leave a part out to keep its season color (`cover: { foliage: 0xffffff }` whitens trees only). Leave `cover` out and snow is particles only.
|
|
173
|
+
- Ash, frost or anything else: `engine.mod('ground.cover', { owner: 'ash', value: { ground: 0x555555, amount: 0.6 } })` (one entry per owner, the handle's `remove()` ends it).
|
|
163
174
|
|
|
164
175
|
## Lightning picture
|
|
165
|
-
```js
|
|
176
|
+
```js fragment
|
|
166
177
|
weather({ types, lightning: f => f * f * 0.8 }); // flash 1 at the strike -> sky flash amount (default flickers)
|
|
167
178
|
weather({ types, lightning: () => 0 }); // no sky flash: draw your own bolt instead
|
|
168
179
|
engine.events.on('weather:lightning', () => spawnBolt()); // when it strikes stays the weather table's (lightning > 0.5)
|
|
169
180
|
```
|
|
170
181
|
|
|
171
182
|
## Particles of the game's own weather
|
|
172
|
-
A field of the game's own weather table (`ash`, `petals`, `sparks`) gets particles with `engine.weather.
|
|
183
|
+
A field of the game's own weather table (`ash`, `petals`, `sparks`) gets particles with `engine.weather.defineField(field, spec)`; the amount is
|
|
173
184
|
`engine.weather.current[field]`, so they fade in and out with the weather. The spec takes the rain / snow keys above (default: drifting
|
|
174
185
|
round sprites), or `create` for a system of your own:
|
|
175
186
|
|
|
176
187
|
```js
|
|
177
|
-
engine
|
|
178
|
-
engine.
|
|
179
|
-
engine.weather.
|
|
188
|
+
const engine = createEngine({ canvas });
|
|
189
|
+
engine.use(sky(), weather({ types: { clear: {}, shower: { rain: 1 }, ashfall: { ash: 1, grey: 0.5, sun: 0.6 } } }));
|
|
190
|
+
engine.weather.defineField('ash', { shape: 'soft', color: 0x555555, size: 14, speed: 0.8, sway: 3 });
|
|
191
|
+
engine.weather.defineField('rain', { create: (engine, { area, count }) => { // the same call replaces rain or snow
|
|
180
192
|
const drops = new THREE.InstancedMesh(new THREE.SphereGeometry(0.03), new THREE.MeshBasicMaterial({ color: 0x99bbff }), count);
|
|
181
193
|
return { object: drops, update(amount, { camera, time, wind }) { /* move the instances; shown while amount > 0.02 */ } };
|
|
182
194
|
} });
|
|
183
195
|
```
|
|
184
|
-
A field no type has throws with the table's fields. `
|
|
196
|
+
A field no type has throws with the table's fields. `defineField(field, null)` gives rain and snow back and removes any other field. Rain and snow are built
|
|
185
197
|
only when a type rains or snows, so a desert pays nothing.
|
|
186
|
-
|
|
187
|
-
The weather's effect on the picture stays on signals: `engine.uniforms.uWeatherLight`, `uWeatherFog`, `uRain`, `uSnow`, `uWind`, `uCloud`. The game's own light,
|
|
188
|
-
fog and wet-road code reads them; the weather writes no light and no fog.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
A look that changes with depth (tint, opacity, foam) reads depth as the water level minus `engine.ground.height(x, z)`: once per vertex of a subdivided plane, or baked into an attribute a material reads.
|