threedog 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +81 -1
- package/README.md +21 -13
- package/core/Assets.js +23 -12
- package/core/Audio.js +1 -1
- package/core/Baked.js +14 -23
- package/core/Budget.js +2 -2
- package/core/DebugOverrides.js +33 -18
- package/core/Describe.js +10 -11
- package/core/Engine.js +50 -46
- package/core/I18n.js +2 -2
- package/core/Input.js +11 -5
- package/core/Inspect.js +6 -3
- package/core/InspectMaterials.js +2 -3
- package/core/InspectPerf.js +11 -4
- package/core/MaterialInfo.js +7 -5
- package/core/Rays.js +7 -2
- package/core/Stream.js +2 -3
- package/core/UrlState.js +49 -9
- package/core/Views.js +1 -0
- package/core/adaptive.js +2 -2
- package/core/assetEntry.js +5 -2
- package/core/assetLoad.js +13 -15
- package/core/assetManifest.js +6 -3
- package/core/assetReport.js +4 -4
- package/core/batchGroups.js +9 -1
- package/core/catalog.js +16 -3
- package/core/chunkStream.js +1 -1
- package/core/copies.js +1 -1
- package/core/debugView.js +4 -4
- package/core/describeRender.js +104 -28
- package/core/describeText.js +6 -6
- package/core/errorCodes.js +72 -45
- package/core/errorHints.js +4 -1
- package/core/errors.js +4 -4
- package/core/events.generated.js +1 -0
- package/core/gameLights.js +9 -2
- package/core/lifecycle.js +2 -4
- package/core/lightWatch.js +5 -3
- package/core/loop.js +18 -11
- package/core/math.js +7 -0
- package/core/moduleSlots.js +32 -7
- package/core/moduleTypes.js +20 -7
- package/core/modules.js +7 -7
- package/core/namedModel.js +8 -4
- package/core/owned.js +33 -30
- package/core/page.js +43 -10
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +64 -96
- package/core/sceneDelta.js +12 -4
- package/core/sceneMethods.js +2 -9
- package/core/services.js +1 -1
- package/core/shadowTypes.js +1 -1
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +5 -19
- package/core/stackFrames.js +16 -5
- package/core/stacks.js +6 -6
- package/core/startup.js +9 -11
- package/core/thingExplain.js +1 -1
- package/core/things.js +1 -1
- package/core/tier.js +1 -1
- package/core/util.js +1 -1
- package/core/validate.js +1 -1
- package/core/view.js +43 -0
- package/docs/AI.md +62 -58
- package/docs/API.md +15 -15
- package/docs/CODEMAP.md +36 -54
- package/docs/COMMANDS.md +28 -25
- package/docs/CONVENTIONS.md +36 -30
- package/docs/MIGRATING-0.4.md +93 -1
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/THREE.md +24 -22
- package/docs/api/assets.md +5 -3
- package/docs/api/audio.md +2 -2
- package/docs/api/budget.md +4 -0
- package/docs/api/characters.md +3 -1
- package/docs/api/collision.md +2 -2
- package/docs/api/engine.md +47 -20
- package/docs/api/events.md +2 -1
- package/docs/api/grids.md +8 -1
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +3 -0
- package/docs/api/input.md +3 -2
- package/docs/api/interactions.md +3 -1
- package/docs/api/inventory.md +1 -2
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +1 -1
- package/docs/api/occlusion.md +5 -0
- package/docs/api/particles.md +6 -3
- package/docs/api/pickups.md +6 -0
- package/docs/api/post.md +5 -3
- package/docs/api/sky.md +12 -10
- package/docs/api/terrain.md +12 -6
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/tools.md +8 -7
- package/docs/api/triggers.md +2 -0
- package/docs/api/vegetation.md +7 -2
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +6 -2
- package/docs/api/weather.md +5 -0
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +19 -23
- package/docs/recipes/03-items-pickups.md +25 -4
- package/docs/recipes/05-props-bake.md +53 -37
- package/docs/recipes/06-clock-events.md +3 -3
- package/docs/recipes/07-flow-scenes-pause.md +12 -3
- package/docs/recipes/08-weather-sky.md +45 -57
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +2 -2
- package/docs/recipes/11-vehicles.md +3 -3
- package/docs/recipes/13-animation.md +13 -7
- package/docs/recipes/14-custom-module.md +7 -5
- package/docs/recipes/15-perf.md +3 -3
- package/docs/recipes/16-dev-bridge.md +22 -12
- package/docs/recipes/18-world.md +10 -8
- package/docs/recipes/19-shooting-picking.md +7 -5
- package/docs/recipes/20-content-actions-save.md +6 -2
- package/docs/recipes/21-camera.md +8 -3
- package/docs/recipes/23-ops.md +1 -1
- package/docs/recipes/26-ui-parts.md +35 -11
- package/docs/recipes/28-terrain.md +12 -12
- package/docs/recipes/29-grid.md +14 -5
- package/docs/recipes/30-templates.md +8 -3
- package/docs/recipes/31-audio.md +4 -4
- package/docs/recipes/32-action-game.md +18 -4
- package/docs/recipes/34-environment-lighting.md +102 -38
- package/docs/recipes/35-picture-from-reference.md +147 -0
- package/docs/recipes/36-sky-ground-plants.md +158 -0
- package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -13
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +106 -27
- package/docs/recipes/42-terrain-shape.md +1 -1
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +121 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +10 -12
- package/docs/recipes/49-game-module-contract.md +1 -1
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +181 -0
- package/docs/recipes/53-ground-up-close.md +12 -12
- package/docs/recipes/54-three-idioms.md +18 -18
- package/docs/recipes/55-mods-time-wrap.md +17 -5
- package/docs/recipes/56-webgpu-tsl.md +66 -23
- package/docs/recipes/57-control.md +39 -0
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +39 -24
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +244 -0
- package/docs/recipes/63-third-person-start.md +77 -0
- package/docs/recipes/64-particles.md +35 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +7 -5
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/FINDINGS.md +53 -0
- package/examples/plain-picture/GAMEMAP.md +90 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +8 -3
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +25 -33
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/sheepisland/.threedog/content-index.json +1 -1
- package/examples/sheepisland/GAMEMAP.md +13 -10
- package/examples/sheepisland/assets.js +2 -2
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +15 -9
- package/examples/sheepisland/{style/models.js → models.js} +13 -24
- package/examples/sheepisland/picture/index.js +20 -0
- package/examples/sheepisland/picture/lights.js +34 -0
- package/examples/sheepisland/picture/materials.js +61 -0
- package/examples/sheepisland/picture/palette.js +60 -0
- package/examples/sheepisland/picture/sky.js +20 -0
- package/examples/sheepisland/views.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -11
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +30 -67
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +4 -3
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +5 -3
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +9 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +15 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +7 -16
- package/index.js +7 -7
- package/llms.txt +15 -13
- package/modules/ambience/Ambience.js +1 -1
- package/modules/calendar/Calendar.js +1 -1
- package/modules/calendar/index.js +1 -0
- package/modules/camera/FirstPersonCamera.js +1 -1
- package/modules/camera/FixedCamera.js +2 -2
- package/modules/camera/RtsCamera.js +1 -1
- package/modules/camera/common.js +7 -5
- package/modules/characters/Character.js +15 -10
- package/modules/characters/NPC.js +5 -5
- package/modules/characters/assetModel.js +5 -4
- package/modules/characters/index.js +28 -3
- package/modules/characters/movers/common.js +6 -1
- package/modules/characters/movers/manual.js +3 -0
- package/modules/characters/movers/support.js +25 -11
- package/modules/characters/npcSim.js +5 -1
- package/modules/characters/proceduralRig.js +18 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/collision/Collision.js +4 -2
- package/modules/content/index.js +8 -0
- package/modules/content/models.js +56 -11
- package/modules/content/props.js +5 -3
- package/modules/content/rules.js +12 -4
- package/modules/content/templates.js +5 -3
- package/modules/gameplay/Interactions.js +91 -16
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +1 -1
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -2
- package/modules/gameplay/pickups.js +62 -24
- package/modules/gameplay/questLog.js +2 -2
- package/modules/grid/Layer.js +13 -0
- package/modules/grid/index.js +40 -11
- package/modules/grid/preview.js +24 -15
- package/modules/grid/tiles.js +15 -19
- package/modules/hlod/index.js +3 -2
- package/modules/hud/index.js +13 -0
- package/modules/hud/parts.js +9 -7
- package/modules/level/index.js +5 -4
- package/modules/lights/index.js +12 -8
- package/modules/music/Music.js +1 -1
- package/modules/particles/Particles.js +41 -20
- package/modules/particles/effect.js +21 -6
- package/modules/photo/Photo.js +11 -10
- package/modules/settings/Settings.js +7 -7
- package/modules/settings/apply.js +5 -5
- package/modules/settings/sections.js +2 -2
- package/modules/settings/strings.js +1 -1
- package/modules/sky/Sky.js +104 -89
- package/modules/sky/clouds.js +16 -17
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +5 -5
- package/modules/sky/environment.js +45 -169
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +26 -90
- package/modules/sky/season.js +3 -3
- package/modules/sky/shader.js +35 -29
- package/modules/sky/skyModule.js +25 -22
- package/modules/sky/tint.js +9 -11
- package/modules/terrain/ChunkManager.js +29 -12
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +44 -66
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +1 -1
- package/modules/terrain/terrainGen.js +2 -2
- package/modules/triggers/index.js +10 -6
- package/modules/vegetation/Vegetation.js +58 -17
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +1 -1
- package/modules/vegetation/index.js +10 -10
- package/modules/water/Water.js +135 -88
- package/modules/water/surface.js +53 -53
- package/modules/weather/Weather.js +52 -17
- package/modules/weather/particles.js +13 -5
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +2 -2
- package/modules/world/views.js +1 -1
- package/package.json +3 -2
- package/presets.js +2 -2
- package/render/PostFX.js +199 -41
- package/render/backend.js +52 -6
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +5 -5
- package/render/effects.js +41 -26
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/index.js +7 -5
- package/render/fx/patchNodes.tsl.js +1 -1
- package/render/fx/postWebGPU.tsl.js +30 -7
- package/render/fx/sky.tsl.js +19 -92
- package/render/fx/water.tsl.js +1 -1
- package/render/layers.js +14 -0
- package/render/lighting.js +6 -5
- package/render/lightmap.js +142 -0
- package/render/lights.js +23 -201
- package/render/materials.js +44 -160
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +1 -1
- package/render/patches.js +34 -29
- package/render/postWebGL.js +11 -3
- package/render/probes.js +179 -122
- package/render/slots.js +4 -4
- package/render/terms.js +53 -101
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +333 -296
- package/types/gameplay.d.ts +65 -26
- package/types/generated/core/Audio.d.ts +1 -1
- package/types/generated/core/DebugOverrides.d.ts +14 -6
- package/types/generated/core/Input.d.ts +9 -2
- package/types/generated/core/page.d.ts +9 -2
- package/types/generated/modules/grid/Layer.d.ts +8 -0
- package/types/generated/modules/grid/index.d.ts +29 -5
- package/types/generated/modules/particles/Particles.d.ts +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -18
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +33 -3
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +2 -2
- package/types/generated/render/PostFX.d.ts +53 -10
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +19 -44
- package/types/generated/render/occlusion.d.ts +13 -0
- package/types/physics.d.ts +5 -3
- package/types/tsl.d.ts +8 -0
- package/types/world.d.ts +376 -57
- package/ui/Focus.js +12 -2
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +8 -4
- package/ui/UI.js +10 -10
- package/ui/cursor.js +1 -1
- package/ui/theme.js +33 -27
- package/ui/touchPart.js +1 -1
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/styleParts.js +0 -114
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
package/docs/recipes/52-look.md
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
# 52 Change any look: `engine.look`
|
|
2
|
-
|
|
3
|
-
**In this recipe**: Atmosphere parts · Surface parts · Water, weather, post · Post effect chain · Who writes it · How look values stack ·
|
|
4
|
-
Lower-level forms that stay
|
|
5
|
-
|
|
6
|
-
Every look part lives at `engine.look.<part>` and is changed with the same verbs. The style gives the starting values; the game changes them on top.
|
|
7
|
-
|
|
8
|
-
```js
|
|
9
|
-
const cave = engine.look.tone.set({ exposure: 0.6 }, { owner: 'cave' }); // adjust: only the keys you give; null drops a key
|
|
10
|
-
cave.remove(); // the style value shows again (every handle ends with remove())
|
|
11
|
-
engine.look.lights.manual('sun'); engine.lights.sun.intensity = 3; // take a value the engine drives; manual('sun', false) gives it back
|
|
12
|
-
engine.look.env.replace('sky'); // swap the one three.js thing a part draws (here the environment map); replace(null) gives it back
|
|
13
|
-
engine.describe().look.tone.exposure; // { value: 0.6, writer: 'game:cave', at: 'main.js:12', under: ['style'] }
|
|
14
|
-
engine.catalog('look.tone'); // params with default, why, off; hooks; what replace accepts and loses
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Sky and atmosphere, three ways (recipe 08 has the contract):
|
|
18
|
-
```js
|
|
19
|
-
// 1. keyframes (default): style.sky.keyframes / style.exposure lists drive the day; nothing to write
|
|
20
|
-
// 2. a function of the frame context, fed by one call: any key marked fn (fog color / near / far / density, sky top / horizon / backdrop, lights, exposure)
|
|
21
|
-
engine.look.fog.set({ color: ({ state }) => state.boss ? '#400' : 'horizon' }); engine.look.state({ boss: true });
|
|
22
|
-
// 3. your own three.js sky (three/addons Sky, a ShaderMaterial dome, a skybox): never written; time / weather keep flowing through engine.uniforms
|
|
23
|
-
engine.look.sky.replace(mySky); mySky.material.uniforms.sunPosition = engine.uniforms.uSunDir; // the same Vector3, refreshed every frame
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Two routes, side by side (not a ladder): the **look** itself is plain three.js, any time: your own material, `ShaderMaterial`, `onBeforeCompile`,
|
|
27
|
-
textures, lights, passes, written directly (a direct write takes the value over: auto-yield). `engine.look` is the **coordination** route: owners,
|
|
28
|
-
layers, keyframes that follow time / weather / season, and `describe` saying who set what. Use either per value; the verbs here
|
|
29
|
-
are optional shortcuts, not steps to climb before three.js is allowed. When tuning params does not reach the reference, write the three.js.
|
|
30
|
-
Where looks sit among the other ways to customize: `../CONVENTIONS.md` "Customization ladder".
|
|
31
|
-
Which knob changes what on screen, and how to judge it for your style: [recipe 60](60-judge-the-picture.md).
|
|
32
|
-
|
|
33
|
-
- Layers, upper wins: engine default < style < game (each owner; the last one written wins) < `engine.debug.override(owner, 'look.<part>', values)`.
|
|
34
|
-
- <a id="verbs"></a>**The verbs, the same on every part**: `set(values)` changes values; `patch(hook, code)` swaps one named hook the part declares (that is all patch means); `add(thing)` puts one more named thing in next to the engine's (`look.post.add`, `look.materials.add`; the handle's `remove()` takes it out); `replace(thing)` swaps the one three.js thing the part draws (a texture, a sky object, a Material, an effect list; `replace(null)` gives it back); `manual(key)` stops the engine writing a value it writes on its own (the table below); `value(key)` is the one read (who set it: `describe().look`). To swap a whole module with its behaviour and saves (the sky, the ground or plant look, the weather look) use `engine.use(mine(), { replaces: '<slot>' })` instead: `replace` is for one thing, `replaces` for a module. A part offers only the verbs that make sense for it; the others throw with the call to use and the verbs it has. A part whose verb takes other arguments (`materials.replace(role, impl)`) lists the call shape in `engine.catalog('look.<part>').signatures`, and a wrong call quotes it.
|
|
35
|
-
- `writer` in describe is who set the value: the layer, `'engine'`, `'style'`, `'game'` (owner `'game'`) or `'<layer>:<owner>'` (for example game:cave or debug:probe), unless something else writes the property now: then `'three'` (a direct write) or `'manual:game'`, the same name as `describe().owned`. `describe().render` keeps only renderer facts; each value carries `look` (the path of the record to read here, `'look.tone.exposure'`) and that record's `writer`. The tone curve has no look record (the engine writes `renderer.toneMapping` once at creation; change it with plain three.js): its owned row `toneMapping` yields quietly to a direct write, and `render.toneMapping.writer` is `'engine'`, `'style'` or `'game'` directly.
|
|
36
|
-
- Look changes are not saved: after a load, set them again from your own state.
|
|
37
|
-
- Changing the three.js object directly (`engine.renderer.toneMappingExposure = 2`) still works; describe tags it `three` and you lose the owner and the debug layer.
|
|
38
|
-
- How bright a lit color comes out (three.js light units, AgX, exposure 1): a diffuse surface facing up receives
|
|
39
|
-
`sun.intensity × sin(sun elevation) + hemi.intensity` (the hemisphere's sky color, since it faces up), and three divides by π, so a total of
|
|
40
|
-
**about 3 (≈ π) shows mid-tone albedos (sRGB 0.35-0.65) at roughly their own value**: sun 2 high overhead + hemisphere 1, or a low sun 4 at 20° +
|
|
41
|
-
hemisphere 1.6. Measured on three's AgX curve: total 2.5 for sRGB 0.35, 2.6 for 0.5, 3.4 for 0.65, 5.5 for 0.8 (AgX darkens light colors and
|
|
42
|
-
pales saturated ones, so a pale or vivid palette needs more, or exposure). Walls and faces away from the sun get only their `N·L` share, and
|
|
43
|
-
the environment (`look.lights` `env`, `look.env`) adds on top for Standard / Physical materials; under a sky the room map follows the keyframes'
|
|
44
|
-
ambient column (recipe 08 "Day and night brightness").
|
|
45
|
-
- Your own module's part: `defineLookPart(engine, { id, params, style, apply })`. Every param declares `default`; a default that changes the picture declares `why` and `off`, or `neutral: true` (checked by `npm run check`; R36 checks that the part's `Look<Part>` type lists the same keys). Module code changes records only through `part.author` (`write`, `ownerValue`, `extend`, `retract`, `has`, `resolved`, `values`, `restyle`, `drive` / `feed`); it is kept off the part so a game's autocomplete shows only the verbs above (rule R25 flags `part._...`); `validate(key, value)` in the spec rejects a value before anything is written, and an `apply` that throws leaves no layer behind.
|
|
46
|
-
|
|
47
|
-
## Atmosphere parts (sky module): fog, sky, shadow
|
|
48
|
-
|
|
49
|
-
```js
|
|
50
|
-
engine.look.fog.set({ far: 220, color: '#9bb' }, { owner: 'cave' }); // kind, color, density, near, far, height, falloff, enabled
|
|
51
|
-
engine.look.fog.manual(); // the sky stops writing scene.fog (manual(false) gives it back)
|
|
52
|
-
engine.scene.fog = new THREE.Fog(0x445566, 10, 120); // a fog of your own: plain three.js, the engine yields (there is no look.fog.replace)
|
|
53
|
-
engine.look.sky.set({ clouds: { coverage: 0.7, speed: [0.01, 0] }, backdrop: 0x335577 });
|
|
54
|
-
engine.look.sky.patch('layer:aurora', { glsl: '...threedogSkyLayer...', blend: 'add' }); // a named dome layer; patch('layer:aurora', null) removes it
|
|
55
|
-
engine.look.sky.patch('clouds', glsl); // the cloud function; replace(skyboxName | Texture | Object3D) swaps the dome
|
|
56
|
-
engine.look.shadow.set({ type: 'vsm', radius: 3, cascades: 3, maxFar: 150 }); // set only
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
- `fog` shows `enabled` and `far` (fog reaches full strength at `far`, 600 m unless a style, the terrain view or the game says otherwise, starting at 0.3 x that) as the visible defaults; turn off with `set({ enabled: false })`. Color, density, near, far, enabled and linear <-> exp2 are live; color switches freely between `'horizon'` (the default: fog matches the sky where they meet), a fixed color and a function, and the dome's lower band fades to any non-horizon fog color so no seam shows. Kind `'exp'` / `'height'`, `height`, `falloff` and the `'fog'` hook replace three's shared fog shader chunks, so they only work before the first frame (style, `sky({ fog })`, or right after `createEngine`); later they throw and say so.
|
|
60
|
-
- `sky`: `clouds.*` are live uniforms of the dome (they only draw when `clouds.coverage` > 0). A hook change recompiles the dome material once. Style `layers` arrays are named by their `name` key, else `layer0`, `layer1`.
|
|
61
|
-
- <a id="tsl-forms"></a>**tsl forms** (`renderer: 'webgpu'`): the GLSL hooks `clouds`, `layer:<name>` (and style `layers` entries) and `fog` take `{ glsl, tsl }`; each renderer draws its own form and a missing one throws by name (`[webgpu-needs-tsl]` on WebGPU). `tsl: (ctx) => vec4 node`, ctx = the GLSL function's arguments as nodes plus the value so far (`ctx.clouds` the built-in kind, `ctx.color` the sky under a layer, `ctx.fog` what the fog kind alone draws), `ctx.uniforms` (the dome's, yours included), `ctx.fx.noise` / `hash` and `ctx.tsl` (three/tsl):
|
|
62
|
-
`engine.look.sky.patch('layer:glow', { glsl, tsl: ({ dir, tsl }) => tsl.vec4(1, 0.6, 0.3, tsl.smoothstep(0.3, 0.8, dir.y).mul(0.4)), blend: 'add' })`;
|
|
63
|
-
`engine.look.fog.patch('fog', { glsl, tsl: ({ depth, tsl }) => tsl.vec4(0.3, 0.3, 0.8, tsl.exp(depth.mul(-0.02)).oneMinus()) })`.
|
|
64
|
-
- `shadow`: no `patch` (the cascade patch is internal) and no `replace` (to own the shadows, light with your own lights: `sky({ sun: false })`).
|
|
65
|
-
`engine.look.shadow.include(myLitShaderMaterial)` opts a ShaderMaterial of yours into cascaded shadows (built-in lit materials need nothing).
|
|
66
|
-
- Whether a picture reads as lit is mostly key against fill. The key (the sun or one main light) is the light that casts the shadow; the fill is
|
|
67
|
-
everything else (sky and ground light, the environment). Shadowed surfaces see only the fill while lit ones see both, so the balance sets how
|
|
68
|
-
deep the shadows look: less fill is harder and more dramatic, more fill softer and more readable, and there is no right ratio, only the one
|
|
69
|
-
the game wants. A warm key over a cool fill (or the reverse) separates lit from shaded sides without more contrast. The shot's `light:`
|
|
70
|
-
fact measures the ratio; judge the result on a shot with a known-colored object in shadow. To compare afterwards, the `sun-and-key-light`
|
|
71
|
-
technique (`threedog examples pull sun-and-key-light`) shows three routes side by side.
|
|
72
|
-
- Shadow detail is texels per meter: one shadow-map texel covers `2 x extent / mapSize` meters (for example the default `extent` 70 on a
|
|
73
|
-
2048 map is about 6.8 cm, twice that on the 1024 map of low tier and headless shots). A box much bigger than what the camera sees blurs
|
|
74
|
-
the shadows of small things; a box smaller than it cuts shadows off. `look.shadow.set({ extent })` sizes it; a depth bias scales with the
|
|
75
|
-
texel, so re-check `bias` / `normalBias` after changing either.
|
|
76
|
-
- Fog kinds and the fog hook in detail, and taking lights or fog away from the sky entirely (`look.lights.manual('sun')`, `sky({ sun: false })`, `look.fog.manual()`): [recipe 38](38-environment-look-hooks.md).
|
|
77
|
-
|
|
78
|
-
## Surface parts: `materials`, `surface`, `ground`, `wind`
|
|
79
|
-
|
|
80
|
-
A change to these parts reaches the materials made **after** it, with one exception: `look.materials.set` of the plain properties `color`, `emissive`, `emissiveIntensity`, `roughness`, `metalness`, `opacity`, `envMapIntensity`, `shininess` and `specular` also changes the materials already made for that role (no recompile; clearing the layer goes back to the style's value). Shader-changing keys (`type`, `steps`, `ramp`, `soften`, `repeat`, `wrap`, `detail`, `lighting`, `add`, `replace`) and all of `look.surface` are for new materials only (a Material already handed out, or cloned by your game, is not touched; catalog and describe say so as `appliesTo`, and a debug override warns). To bring the materials already out in line, call `engine.look.materials.rebuild()`: every material `makeMaterial` made that a mesh in the scene holds is made again from the current layers and put in its place (the call's own params, colors set by hand and wind / cloud shadow added after `makeMaterial` are kept; the old one is disposed; it returns `{ rebuilt, kept, ms }`). `engine.plugins.off / on` of a material or patch plugin calls it for you (`{ rebuild: false }` skips it, and the result then names this call), so a streamed world never mixes the old and new look; `plugins.list()` and `describe().slots` show the reach: `live` or `new materials only`. `engine.look.<part>.object` is the three.js object behind a part; for `materials` it is a function: `engine.look.materials.object('cloth')` is the last Material made for that role, `object()` all of them.
|
|
81
|
-
|
|
82
|
-
```js
|
|
83
|
-
const L = engine.look;
|
|
84
|
-
L.materials.set({ cloth: { roughness: 0.4, color: 0xf2ece0 } }, { owner: 'shop' }); // on top of the style's materials.cloth (look.materials' style layer); any role name
|
|
85
|
-
L.materials.add('dim', { glsl: { fragment: { color_fragment: 'diffuseColor.rgb *= 0.8;' } } }, { roles: ['metal'] }); // one more ShaderPatch on those roles (h.remove() takes it out)
|
|
86
|
-
L.materials.replace('glass', new THREE.MeshPhysicalMaterial({ transmission: 1 })); // the role is this Material (or (params, purpose, engine) => Material)
|
|
87
|
-
L.surface.patch('lighting', glsl); // your own threedogLighting(...) on every lit material, recipe 43
|
|
88
|
-
L.surface.set({ lighting: { wrap: 0.3 }, detail: { strength: 0.15 } }); // or the spec-key shortcuts (recipe 43, last section)
|
|
89
|
-
L.ground.set({ shading: 'flat', colors: { grass: '#7cc06b' } }); // colors / biomeColors / steep / variation / shading rebuild the chunks
|
|
90
|
-
L.ground.set({ detail: { noise: 'paper', scale: 0.4, strength: 0.25 } }); // detail layer on the ground (style.terrain.detail)
|
|
91
|
-
L.ground.replace((e) => myGroundMaterial(e)); // Material or (engine) => Material; replace(null) gives it back
|
|
92
|
-
L.ground.replace(myGroundMaterial, { effects: false }); // drawn as given: no cloud shadow / season / detail patch (same word as vegetation.define)
|
|
93
|
-
L.wind.set({ frequency: 1.5, amplitude: 0.5 }); // live on every plant, planted ones too
|
|
94
|
-
L.wind.patch('sway', { glsl, tsl }); // threedogWind(...) / tsl: (ctx) => moved position; read when vegetation.define runs, so patch first
|
|
95
|
-
L.vegetation.patch('color', { glsl: 'diffuseColor.rgb *= 0.8;', tsl: c => c.color.mul(0.8) }); // part of the plant look, live on planted species
|
|
96
|
-
L.cloudShadow.replace({ glsl: 'reflectedLight.directDiffuse *= myShade(vThreedogWorld);', tsl: c => ({ directDiffuse: c.directDiffuse.mul(myShadeNode) }) });
|
|
97
|
-
L.cloudShadow.replace(false); // no engine cloud shadow anywhere: draw your own
|
|
98
|
-
L.season.replace(kind => ({ glsl: 'diffuseColor.rgb = mix(diffuseColor.rgb, vec3(1.0), uCover.y);', tsl: c => myTint(c, kind) })); // your own season / snow tint
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
- `materials`: `set` / `add` / `replace` all name roles (`add(name, shaderPatch, { roles })`; materials have no named hook, so no `patch`). `set` merges into spec entries; a role whose style entry is a Material or a function is changed with `replace`. Role names are free: invent new ones (`makeMaterial('lantern-glass')`); the engine only warns on a likely typo of a known role.
|
|
102
|
-
- `materials.glow(match, { night, day = 0, dusk = 0.3, owner })`: see "Night glow" below.
|
|
103
|
-
- `surface`: `set` / `patch('lighting' | 'detail', glsl)`; no `replace` (swap a whole material with `materials.replace`). `style.lighting` is the style layer.
|
|
104
|
-
- `ground` (terrain module): `set` / `patch('detail', glsl)` / `replace`. What `terrain({ colors, shading, material })` was given shows as owner `terrain()`.
|
|
105
|
-
- `wind` (vegetation module): `set` / `patch('sway', glsl | { glsl, tsl })`; no `replace`. `style.wind` is the style layer.
|
|
106
|
-
- `vegetation` (vegetation module): `patch('color', glsl | { glsl, tsl, uniforms })`, code in the `color` slot of every species' material, changed live. The whole plant look is replaced as a module: `engine.use(myPlants, { replaces: 'vegetation-look' })`.
|
|
107
|
-
- `cloudShadow` and `season` (core): `replace(spec)` puts your own patch (`{ glsl, tsl, uniforms?, pars?, slot? }`, slot `lighting` / `color` by default) in place of the engine's on every engine material, including ones built before the call; `replace(false)` removes the term; removing the layer gives the engine's back. The signals stay bound: `uCloud*` and `threedogCloudShadow(worldPos)`; `uFoliageTint` / `uGroundTint` / `uFoliageMix` / `uGroundMix`, `uCover` (cover amount alone, x foliage, y ground) and `threedogSeason(color, kind)`. `season` also takes `kind => spec` (kind `'foliage'` | `'ground'`). Each renderer draws its own form, and a missing one throws by name.
|
|
108
|
-
- `set({ role: { key } })` accepts a key `makeMaterial` reads (type, steps, ramp, soften, repeat, wrap, detail, lighting, or a three.js material property); a typo throws.
|
|
109
|
-
- `look.cloudShadow` (cloud shadows, core) stays its own part: its `shadow` is read by every material and by the weather, not only by surfaces.
|
|
110
|
-
|
|
111
|
-
### Night glow: emissive that follows daylight
|
|
112
|
-
|
|
113
|
-
Lit windows, neon signs, lamp bulbs, glowing mushrooms, screens: name the materials once and give the emissiveIntensity for night and day. The
|
|
114
|
-
color is yours (the material's `emissive`); the engine writes only `emissiveIntensity`, fading from `day` to `night` as daylight drops below `dusk`
|
|
115
|
-
(the calendar's daylight, else the sky's sun). `dusk` defaults to 0.3, roughly 17:00 to 18:00 and back in the morning: a starting value, not a
|
|
116
|
-
rule. Judge it in shots at dusk: a shop sign may want to come on while the sky is still bright (a higher `dusk`), a cave mushroom only in full
|
|
117
|
-
dark (a lower one).
|
|
118
|
-
```js
|
|
119
|
-
engine.look.materials.glow('window', { night: 2 }); // a material role (makeMaterial('window', { emissive: '#ffcc66' })) or material.name (a GLB's)
|
|
120
|
-
engine.look.materials.glow('neon', { night: 3, day: 0.4, dusk: 0.6 }); // signs stay faintly lit by day, full on early
|
|
121
|
-
const h = engine.look.materials.glow(m => m.name.startsWith('bulb'), { night: 1.5 }); // or a Material, or a filter
|
|
122
|
-
h.remove(); // each material gets its own emissiveIntensity back
|
|
123
|
-
```
|
|
124
|
-
**Headroom: why a glow turns into glare.** What reaches the tone curve is the emissive color times `emissiveIntensity`. A near-white color
|
|
125
|
-
(`#ffe6c0`) has no headroom: all three channels already sit near 1, so multiplied past 1 they clip to the same white under tone mapping, and
|
|
126
|
-
bloom spreads that white over what is around it (a lit sign becomes a white block with a smear). A saturated color at a lower intensity still
|
|
127
|
-
reads as light: its strongest channel carries the brightness, the others keep the hue, and bloom carries the halo. The numbers above are the
|
|
128
|
-
examples' current values, not targets. Judge the result with the look check of `threedog shot` or `threedog snap` at night: it names each
|
|
129
|
-
glowing material and light that blows pixels out, with its current emissive and intensity and how much detail is lost under it, as a fact to
|
|
130
|
-
weigh against what the game wants (some games want a blinding sign).
|
|
131
|
-
It finds models built later (templates near the player, streamed cells, a level loaded afterwards): the scene is searched again after it changed,
|
|
132
|
-
not every frame. `describe().look.materials` lists each rule (`glow:window`) and how many materials it found; a match without an emissive color or
|
|
133
|
-
with a black one warns once. For the light those windows throw on the street, add a few `lightPool` sources (recipe 09 §1b); a pool source's
|
|
134
|
-
`glow` stand-in is for one object near one light and does not follow the time of day.
|
|
135
|
-
|
|
136
|
-
## Water, weather, post
|
|
137
|
-
|
|
138
|
-
```js
|
|
139
|
-
engine.look.water.set({ opacity: 0.5, waveHeight: 2 }, { owner: 'storm' }); // live, no recompile
|
|
140
|
-
engine.look.water.set({ foam: { color: 0xffffff }, depthColor: { shallow: 0x88ccdd, deep: 0x003355 } }); // rebuilds the water material once
|
|
141
|
-
engine.look.water.patch('wave', 'float threedogWaterWave(vec3 p, float t) { return sin(p.x + t) * 0.2; }'); // hooks: wave, surface
|
|
142
|
-
engine.look.water.replace((engine, { uniforms, waves, surface }) => myMaterial); // the whole surface (style.water.material)
|
|
143
|
-
|
|
144
|
-
engine.look.weather.set({ 'rain.speed': 10, 'snow.size': 8, 'lightning.brightness': 0.5, overcastColor: '#667' }); // rebuilds that field's particles once
|
|
145
|
-
engine.look.weather.patch('rain.fragment', wholeFragmentShaderText); // rain|snow . vertex|fragment: the WHOLE shader text, not a function
|
|
146
|
-
engine.look.weather.replace({ ash: { shape: 'soft', color: 0x555555 }, rain: { create } }); // null gives the fields back
|
|
147
|
-
|
|
148
|
-
engine.look.post.set({ bloom: { strength: 0.6 }, vignette: false }); // keys: '<effect>.<param>', '<effect>.enabled'
|
|
149
|
-
engine.look.post.add(new UnrealBloomPass(size, 0.6, 0.4, 0.85), { name: 'glow' }); // THE one way in: a Pass, a node function or an effect; returns { name, remove() }
|
|
150
|
-
engine.look.post.add({ name: 'tint', fuse: { glsl: 'color.rgb *= vec3(1.0, 0.9, 0.8);' }, slot: 'ldr', order: 5 }, { owner: 'cave' }); // a pixel snippet is an effect too
|
|
151
|
-
engine.look.post.replace([bloom(), grain()]); // swaps the whole chain; replace(null) gives back what add() put in
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
- Water: structural keys (`depthColor`, `foam`, the hooks, `replace`) rebuild the shared material once and hand it to every water mesh; the live keys only write a uniform. `water()` takes no look values (`water({ opacity })` throws naming `look.water.set`); `normalMap` also rebuilds once, `normalRepeat` retiles the meshes' UVs.
|
|
155
|
-
- Weather: a field the weather table lacks (`snow` in a desert) has no particles; setting it warns once. `replace({ [field]: spec })` holds one object per owner, so list every field you replace in each call; while a field is replaced, `set` on it is ignored.
|
|
156
|
-
- Post: `look.post.set` writes the `game` layer (keys `<effect>.<param>` and `<effect>.enabled`); effects a style's plugins add (bloom, ao ...) sit on the style layer (owner `style:<pack>/<file>`, one per plugin); `engine.post.get(name)` only reads an effect. MSAA is `engine.post.setAntialias(on)`. Costly effects start off on low-tier devices: that is the engine layer (`describe().look.post['<effect>.enabled']` reads `writer: 'engine'` with a `why`), and `look.post` lists `<effect>.enabled` with `why` and `off`; a game's `set` turns it back on and reads `game`.
|
|
157
|
-
- `describe().render.post` reads the same records (`writer`: style, game, debug).
|
|
158
|
-
|
|
159
|
-
## Post effect chain
|
|
160
|
-
|
|
161
|
-
Post-processing is an ordered list of named effects, and **`engine.look.post.add(x, { name, slot, order, owner })` is the one way an effect gets
|
|
162
|
-
in**: game code, the game's `plugins/` folder (a file that exports the Pass or effect) and a style's `style/plugins/` all go through it, so every
|
|
163
|
-
effect has a name, an owner, on / off with `look.post.set({ <name>: false })` and a row in `describe().slots`. `x` is a plain three.js Pass (WebGL),
|
|
164
|
-
a TSL node function `(input, ctx) => node` (WebGPU), or an effect `{ name, create, node, fuse, slot, order, params }` (both renderers: give
|
|
165
|
-
`create` and `node`, or a `fuse`). Each runs in a slot, then by `order` (low first):
|
|
166
|
-
`scene` (replaces the scene render, one at a time, e.g. pixelation) -> `hdr` (linear color: outline, AO, bloom) -> tone mapping -> `ldr` (sRGB: LUT,
|
|
167
|
-
palette, grain, vignette) -> `final` (FXAA / SMAA). An effect is `{ name, slot, order, params, create(ctx) => pass, update?(pass, params) }`; under
|
|
168
|
-
WebGL the pass is any three.js postprocessing Pass, built the first time it is on (on WebGPU an effect gives `node` instead: recipe 56). To read the chain: `engine.post.object()` (the
|
|
169
|
-
EffectComposer, null until post first runs) and `engine.post.targets()` (its render targets); both stay the engine's (it rebuilds passes,
|
|
170
|
-
resizes, disposes), so change the chain through `look.post`. A plain Pass is placed by its kind: one that renders `engine.scene` itself
|
|
171
|
-
(`RenderPixelatedPass`, `SSAARenderPass`, `TAARenderPass`) goes in `scene` and replaces the engine's scene render (the scene is drawn once; a
|
|
172
|
-
second one throws), FXAA / SMAA / TAA in `final`, any other in `hdr` after the style's effects; a RenderPass of `engine.scene` and an OutputPass are
|
|
173
|
-
skipped (the engine has them). Without `{ name }` it is listed by class or shader name (`CopyShader#1`); its `remove()` does not dispose it.
|
|
174
|
-
A game that renders the canvas itself (its own composer) takes the frame: the engine stops drawing and warns once `[own-frame]`.
|
|
175
|
-
```js
|
|
176
|
-
import { bloom, outline, vignette, lut } from '@threedog/post-effects'; // shared effects come from the add-on, not from another game's style
|
|
177
|
-
import { LUTPass } from 'three/addons/postprocessing/LUTPass.js';
|
|
178
|
-
engine.look.post.add(outline({ thickness: 1.5 })); engine.look.post.add(vignette());
|
|
179
|
-
engine.look.post.add({ name: 'myLut', slot: 'ldr', params: { lut: myLut }, create: ({ params }) => new LUTPass({ lut: params.lut }) });
|
|
180
|
-
// a style brings its effects as plugin files, the same files a game's plugins/ takes: style/plugins/10-bloom.js
|
|
181
|
-
export default bloom({ strength: 0.2 }); // and in style/index.js: plugins: import.meta.glob('./plugins/*.js', { eager: true })
|
|
182
|
-
```
|
|
183
|
-
- The engine ships no effects. `@threedog/post-effects` (import only what you use) has `bloom`, `ao`, `outline`, `dof` (all `hdr`; outline and dof
|
|
184
|
-
read depth) and `lut` (contrast / saturation / warm-cool / optional 3D LUT), `grain`, `vignette`, `chromatic` (`ldr`). An added effect is on
|
|
185
|
-
(`enabled: false` adds it off, for `look.post.set({ '<name>.enabled': true })` later). The costly ones (`bloom`, `ao`, `dof`, outline
|
|
186
|
-
`normal`/`both`) a style's plugins bring start off on low-tier devices (`look.post.set({ ao: true })` turns one on; `threedog shot` renders the
|
|
187
|
-
desktop tier and names what a tier leaves out, `--tier low` checks the low one). To take one of a pack's effects out: `engine.plugins.off('<pack>/<file>')`
|
|
188
|
-
or `look.post.set({ ao: false })`; to add one on top: a game plugin file or `look.post.add`.
|
|
189
|
-
- Depth: an effect that reads scene depth (`needsDepth: true`, e.g. `outline`) must run before any pass that swaps buffers (a `ShaderPass`, a
|
|
190
|
-
scene-slot pixelation pass, the tone-mapping output). A chain that breaks this throws when the effect is added or enabled, naming both effects;
|
|
191
|
-
give the depth reader a lower `order`. `dof` keeps the scene depth (`pass.keepsDepth = true`), so `dof` and `outline` can both be on while `dof`
|
|
192
|
-
has the lower `order` (default: dof 5, outline 10). `threedog style check` reports the other order as an error.
|
|
193
|
-
- Pause or unload: `look.post.set({ bloom: false })` pauses an effect where it is (its place, params and owner stay); `engine.plugins.off('<file>')`
|
|
194
|
-
unloads the plugin (the effect leaves the chain; `on` plugs it again). Either way the effect comes back in the same place: inside a slot,
|
|
195
|
-
`order` decides, and equal orders keep the order the names were first added in (a plugin's effects are placed in plugin-list order, even
|
|
196
|
-
one that starts off), so off / on never reorders the chain.
|
|
197
|
-
- On / off is `look.post.set({ bloom: false })` for every effect, whoever added it (there is no `createEngine({ post })`: the engine ships no
|
|
198
|
-
effect to switch on, add one with `look.post.add(bloom())`). MSAA (`antialias`) works with every effect on. The settings menu shows `bloom` / `ao` toggles only when the style registers effects with those names; a toggle the player changes is written under owner `settings` (`writer: 'game:settings'`), and the menu writes nothing for a value it only re-applies unchanged.
|
|
199
|
-
- `fuse`: a light color effect can skip its own fullscreen pass by carrying a GLSL snippet instead of `create()`:
|
|
200
|
-
`fuse: { uniforms: { uMyAmount: 'float' }, values: p => ({ uMyAmount: p.amount }), glsl: 'color.rgb *= 1.0 - uMyAmount * length(vUv - 0.5);' }`.
|
|
201
|
-
Fused effects that are on and next to each other in one slot (never `scene`) compile into one shader and draw in one pass, in `order`. The
|
|
202
|
-
snippet edits `vec4 color` and may use `vUv`, `tDiffuse`, `uTime`, `uResolution`, `fxHash(vec2)`; uniform names are shared by the group, so prefix
|
|
203
|
-
them with the effect name. A snippet that samples `tDiffuse` elsewhere (blur, color fringe) sets `reads: true` and starts a new group.
|
|
204
|
-
`look.post.add({ name, fuse: { glsl }, slot: 'ldr' })` adds just a snippet.
|
|
205
|
-
- Outline: `outline({ mode: 'depth' | 'normal' | 'both' })`: `depth` (default, silhouettes), `normal` (creases; draws the scene once more with
|
|
206
|
-
normals, so it is `costly`), `both`. `fadeWithDistance: false` keeps lines at any distance; `wobble: 1.5` jitters lines by up to 1.5 px at 8 steps a
|
|
207
|
-
second. To exempt objects: `outline({ offLayer: OUTLINE_OFF_LAYER })` and `mesh.layers.enable(OUTLINE_OFF_LAYER)` (one extra render of just
|
|
208
|
-
those objects; nothing when `offLayer` is `null`).
|
|
209
|
-
- Ambient occlusion (darker creases and contact corners): `ao({ radius, intensity })` wraps three's `GTAOPass`; `radius` is in world units
|
|
210
|
-
(default 0.25), `intensity` 0..1 (default 1), both change in place: `look.post.set({ 'ao.enabled': true, 'ao.radius': 0.6 })` (with `ao()` added
|
|
211
|
-
by a style plugin or the game), or `look.post.add(ao({ enabled: true }))` at run time. Order 20 runs it before bloom and the tone mapping. It follows resize,
|
|
212
|
-
render scale and MSAA like every effect. It draws the scene once more with normals: points and lines are skipped, and a vertex-moving shader
|
|
213
|
-
patch (wind) is not applied there, so swaying leaves get the AO of their rest pose. Cost on a laptop GPU (AMD 780M, 1280x720, MSAA, a street
|
|
214
|
-
scene): about +6 ms a frame (4.4 -> 10.7 ms). Other GTAOPass settings (`samples`, `thickness`, `output`):
|
|
215
|
-
`engine.post.object().passes.find(p => p.gtaoMaterial)`.
|
|
216
|
-
|
|
217
|
-
## Who writes it: the ownership table
|
|
218
|
-
|
|
219
|
-
Some three.js values the engine writes **on its own**, every frame or on a timer: the sky drives the sun, the camera module places the camera.
|
|
220
|
-
Each of them is registered once (`core/owned.js`), and every one behaves the same way:
|
|
221
|
-
|
|
222
|
-
- **Engine** (default): the engine writes it. Adjust it while the engine keeps driving: the `set` call in the table.
|
|
223
|
-
- **Taken** (`manual`): `engine.look.<part>.manual(key)` stops the engine writing it; the three.js object is yours (`engine.lights.sun.intensity = 3` sticks).
|
|
224
|
-
`manual(key, false)` (or the handle's `remove()`) gives it back. Keys match by dotted prefix: `manual('sun')` takes `sun.intensity` and `sun.color`;
|
|
225
|
-
`manual()` takes every key of the part. This is the one takeover entry: no module option starts a value taken over (`sky({ sun: 'manual' })`
|
|
226
|
-
throws and names the call). A fog of your own is the direct write below: `scene.fog = new THREE.Fog(...)`.
|
|
227
|
-
- **Written directly** without `manual`: the engine notices, **stops writing it and keeps your value**, and warns once with the `manual` call and the
|
|
228
|
-
hand-back call. This happens in release builds too (only the warning is dev-only), so a game behaves the same with and without checks.
|
|
229
|
-
- A `timeline.tween` on an object is a temporary takeover of that object only: no warning, no hand-over (other objects stay checked).
|
|
230
|
-
|
|
231
|
-
`engine.describe().owned` lists every registered value and who writes it now, as `writer` (`engine`, `manual:game`,
|
|
232
|
-
`three (engine yielded)`); the same `writer` shows next to a look value, `describe().look.<part>.<key>.writer`. (Without a takeover it is the layer that set the value, `game` or `game:<owner>`; `owner` is only ever the name you pass.) A test (`tests/specs/owned.mjs`) runs the three
|
|
233
|
-
behaviors for every registered value and fails when one is registered without a row here.
|
|
234
|
-
|
|
235
|
-
| id | part | written when | take it | adjust while the engine drives |
|
|
236
|
-
|---|---|---|---|---|
|
|
237
|
-
| `sun.intensity` | lights | sky, every frame (keyframes, weather) | `engine.look.lights.manual('sun')` | `engine.look.lights.set({ sun: { intensity: 2 } })` |
|
|
238
|
-
| `sun.color` | lights | sky, every frame | `engine.look.lights.manual('sun.color')` | `engine.look.lights.set({ sun: { color: '#ffd9a0' } })` |
|
|
239
|
-
| `sun.direction` | lights | sky, every frame (time of day) | `engine.look.lights.manual('sun.direction')`: aim it by `sun.position` relative to `sun.target`; the shadow box still follows | - |
|
|
240
|
-
| `shadow.follow` | shadow | sky, every frame (shadow box center = `sun.target`); without a sky the baseline sun follows `engine.focus` | `engine.look.shadow.manual('follow')`; no sky: `engine.look.lights.manual('shadow.follow')` | `engine.look.shadow.set({ follow: 'focus' \| 'camera' \| object3D \| () => Vector3 \| false })`, size: `set({ extent })` |
|
|
241
|
-
| `hemi` | lights | sky, every frame | `engine.look.lights.manual('hemi')` | `engine.look.lights.set({ hemi: { intensity: 0.8 } })` |
|
|
242
|
-
| `fog` | fog | sky, every frame (color, distance) | `engine.look.fog.manual()` | `engine.look.fog.set({ color: '#cfd8e0', far: 300 })` |
|
|
243
|
-
| `toneMapping` | tone | once, at `createEngine` (`style.toneMapping`, else AgX); a direct write yields with no warning (it is the documented way) | `engine.renderer.toneMapping = THREE.ACESFilmicToneMapping`; an own curve as a post stage: `engine.look.post.add({ name, slot: 'tone', create })` (or `node` on WebGPU; replaces OutputPass / renderOutput; outputs display color), or `engine.look.tone.manual('toneMapping')`; `manual('toneMapping', false)` writes the creation curve back | - |
|
|
244
|
-
| `exposure` | tone | sky, every frame, only with exposure keyframes | `engine.look.tone.manual('exposure')` | `engine.look.tone.set({ exposure: 1.2 })` |
|
|
245
|
-
| `background` | sky | sky: a backdrop color or skybox every frame; with the dome the dome hides when you take it | `engine.look.sky.manual('background')`; whole sky: `look.sky.replace(texture \| object3D)` | `engine.look.sky.set({ backdrop: '#335577' })` |
|
|
246
|
-
| `env` | env | sky, every frame: the room map's intensity (ambient column); a `'sky'` environment is rebuilt on its interval | `engine.look.env.manual()` | `engine.look.env.set({ intensity: 0.8 })`, `look.env.replace('sky' \| 'asset' \| myTexture \| myPmremTarget)` |
|
|
247
|
-
| `camera.far` | view | fog distance / terrain view range (`terrain({ viewFog })`, `setViewChunks`) | `engine.look.view.manual('far')` | - |
|
|
248
|
-
| `camera.fov` | view | the settings menu fov slider, camera modules (first person / rts fov, fixed shots, back to the install fov on a switch) | `engine.look.view.manual('fov')` | - |
|
|
249
|
-
| `pixelRatio` | view | adaptive resolution, about once a second while slow | `engine.look.view.manual('pixelRatio')` | `engine.setPixelRatio(1.5)` |
|
|
250
|
-
| `camera` (position, rotation) | view | the camera module, every frame | `const cam = engine.takeCamera('me')` (`cam.remove()` gives it back) | - |
|
|
251
|
-
| `post.chain` | post | whenever the effect list changes (set / add / replace, MSAA): the engine rebuilds the composer passes (WebGL) or `pipeline.outputNode` (WebGPU) | `engine.look.post.manual()`: the built chain stays as you left it in `engine.post.object()`; `manual(false)` rebuilds it from the list. A write to `object()` without `manual` does not yield: the next chain change replaces it | `engine.look.post.set({ bloom: { strength: 0.6 } })` |
|
|
252
|
-
| `shadow.csm` (not a property: a list) | shadow | while `cascades > 1`: the `csm` patch goes on every built-in lit material, yours too (else N times as bright) | - (lower `cascades` to 1); your ShaderMaterial is left alone until `engine.look.shadow.include(mat)` | - |
|
|
253
|
-
|
|
254
|
-
Material live keys (`look.materials.set({ wood: { color } })` on materials already made) are per material, not one row: a key the
|
|
255
|
-
`makeMaterial('wood', { color })` call passed itself is never overwritten, and a value you set by hand afterwards (`m.color.set(...)`) is
|
|
256
|
-
skipped with one warning. Order: by hand > the call's params > `look.materials.set` > the style.
|
|
257
|
-
|
|
258
|
-
Not in this table, because the engine writes them once rather than keeps writing them: automatic batching (it moves engine-placed meshes to layer 31
|
|
259
|
-
and says so once in the dev console and in `describe().perf.batching`; turn it off per object with `userData.batch = false`, see
|
|
260
|
-
[05-props-bake.md](05-props-bake.md) §2b) and `castShadow` on generator props (set when the model is made: a generator's own flags are kept, the
|
|
261
|
-
manifest entry can set them; change it on the object afterwards).
|
|
262
|
-
|
|
263
|
-
## How look values stack
|
|
264
|
-
|
|
265
|
-
Every `look.<part>.<key>` is a shared point (recipe 55), so one rule holds for all of them: **the game sets a base value, effects multiply on top,
|
|
266
|
-
the player's settings cap it.**
|
|
267
|
-
```js
|
|
268
|
-
engine.look.lights.set({ sun: { intensity: 3 } }, { owner: 'arena' }); // the base (replaces the style / keyframes); rain still dims it: 3 × 0.6
|
|
269
|
-
engine.mod('look.lights.sun.intensity', { owner: 'cave', mul: 0.3 }); // cooperate: entries multiply; the handle's remove() ends yours
|
|
270
|
-
engine.mod('look.fog.far', { owner: 'storm', mul: 0.6, layer: 'effect' }); // an effect module writes the effect layer
|
|
271
|
-
engine.describe().shared['look.lights.sun.intensity'].how; // 'arena 3 × sky:horizon 1 × weather 0.6 × cave 0.3'
|
|
272
|
-
```
|
|
273
|
-
- `set` decides, `mul` / `add` cooperate. Two owners `set` one value on one layer is the dev error `shared-conflict`; copy one of its fixes.
|
|
274
|
-
- The exact number whatever the weather: `engine.look.lights.manual('sun')` and write the three.js light, or set on `{ layer: 'system' }`.
|
|
275
|
-
- The settings menu only restricts (`shadows` off is `look.shadow.enabled` set false on the settings layer); a game's `enabled: true` does not
|
|
276
|
-
switch them back on, and a cutscene's `false` is not undone by the menu. `describe().shared` names who decided and who is hidden.
|
|
277
|
-
- A direct three.js write (`engine.lights.hemi.intensity = 0.2`) still works: the engine yields, describe says `three (engine yielded)`.
|
|
278
|
-
- `look.sky.tint`, `look.ground.cover` (blend by amount) and `look.sky.flash` (adds) are points of the same kind, written with `engine.mod`.
|
|
279
|
-
|
|
280
|
-
## Lower-level forms that stay
|
|
281
|
-
|
|
282
|
-
Per-call `makeMaterial(role, params)` keys win for that one material; `applyEffects(mat, { patches })` is the low-level form of `look.materials.add(name, spec, { roles })`; `style.materials`, `style.terrain.*`, `style.wind.*` and `style.lighting` are the style layer of `look.materials` / `look.ground` / `look.wind` / `look.surface`.
|
package/examples/action/look.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// This example's look, its whole style (createEngine({ style: look })): the colors models.js reads. Logic never reads colors; models.js does.
|
|
2
|
-
export default {
|
|
3
|
-
name: 'action', // a part needs at least one Style field (TypeScript rejects an object that shares none), so it names itself
|
|
4
|
-
action: { floor: 0x5b6168, wall: 0x8a8f96, pillar: 0x9a8c78, enemy: 0x6fbf5a, eye: 0x1d2024 },
|
|
5
|
-
};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// sheepisland: this game's style, LOOKS ONLY (recipes/09-style.md, 35-style-from-reference.md), filled in from the empty style/index.js
|
|
2
|
-
// a new game starts with. A soft painted diorama: few flat colors, round shapes, soft shadows, a pale warm background with no horizon.
|
|
3
|
-
// The world (island outline, river, wheat field) is the game's terrain() in ../main.js, never here.
|
|
4
|
-
import { makeMaterial, applyEffects } from '../../../index.js';
|
|
5
|
-
import { models, PALETTE } from './models.js';
|
|
6
|
-
|
|
7
|
-
export { models };
|
|
8
|
-
/** Asset pack of the procedural models: engine.assets.manifest(assets) registers roundTree, sheep and wheatTuft */
|
|
9
|
-
export const assets = { name: 'sheepisland', models };
|
|
10
|
-
|
|
11
|
-
// Background: zenith = horizon = fog color at every time, so the dome is one flat tone and no horizon line shows.
|
|
12
|
-
// [time 0-1, zenith, horizon (= fog), sun color, sun intensity, ambient intensity]
|
|
13
|
-
// Ground material with snow that survives shading: 'texture'. The engine's season tint runs at color_fragment, before the per-chunk color map is
|
|
14
|
-
// multiplied in, so in 'mix' mode the map paints the green back over the white. This patch repeats the season mix later (slot emissive, emissivemap_fragment,
|
|
15
|
-
// after every color patch, before lighting), reading the engine's own season uniforms under new names (the season patch declares the old ones).
|
|
16
|
-
/** @param {any} engine */
|
|
17
|
-
function snowyGround(engine) {
|
|
18
|
-
const u = engine.uniforms;
|
|
19
|
-
return applyEffects(makeMaterial('terrain', { vertexColors: true }, engine), { clouds: false, patches: [{
|
|
20
|
-
name: 'snowCover', cacheKey: 1, uniforms: { uSnowTint: u.uGroundTint, uSnowMix: u.uGroundMix },
|
|
21
|
-
pars: 'uniform vec3 uSnowTint; uniform float uSnowMix;',
|
|
22
|
-
slot: 'emissive', glsl: 'diffuseColor.rgb = mix(diffuseColor.rgb, uSnowTint, uSnowMix);' }] });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const DAY = 0xefebe4, DUSK = 0xf0d9c4, NIGHT = 0x2c3346;
|
|
26
|
-
export default {
|
|
27
|
-
name: 'sheepisland',
|
|
28
|
-
exposure: 1,
|
|
29
|
-
toneMapping: 'neutral', // neutral keeps the painted colors close to what is written here (aces darkens and shifts them)
|
|
30
|
-
|
|
31
|
-
// no post plugins: restraint, the reference shows no outline, bloom or grain
|
|
32
|
-
|
|
33
|
-
materials: {
|
|
34
|
-
default: { type: 'lambert' },
|
|
35
|
-
leaf: { type: 'lambert' },
|
|
36
|
-
bark: { type: 'lambert' },
|
|
37
|
-
wool: { type: 'lambert' },
|
|
38
|
-
face: { type: 'lambert' },
|
|
39
|
-
cliff: { type: 'lambert' },
|
|
40
|
-
vegetation: { type: 'lambert', side: 2 }, // the wheat stalks are thin: both sides (THREE.DoubleSide = 2)
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
// Soft light: half-lambert wrap so the shade side of a round blob is not black, and a cool blue shade instead of a gray one
|
|
44
|
-
lighting: { wrap: 0.45, shadowTint: { color: 0x7d88b8, strength: 0.45, soft: 0.3 } },
|
|
45
|
-
|
|
46
|
-
palette: PALETTE,
|
|
47
|
-
|
|
48
|
-
sky: {
|
|
49
|
-
keyframes: [
|
|
50
|
-
[0.00, NIGHT, NIGHT, 0x9aaad8, 0.7, 0.85],
|
|
51
|
-
[0.22, NIGHT, NIGHT, 0x9aaad8, 0.7, 0.85],
|
|
52
|
-
[0.30, DAY, DAY, 0xfff0dc, 1.8, 1.0],
|
|
53
|
-
[0.50, DAY, DAY, 0xfffaf0, 2.3, 1.15],
|
|
54
|
-
[0.70, DAY, DAY, 0xffe6c8, 1.9, 1.0],
|
|
55
|
-
[0.77, DUSK, DUSK, 0xffb07a, 1.5, 0.85],
|
|
56
|
-
[0.84, NIGHT, NIGHT, 0x9aaad8, 0.7, 0.85],
|
|
57
|
-
[1.00, NIGHT, NIGHT, 0x9aaad8, 0.7, 0.85],
|
|
58
|
-
],
|
|
59
|
-
groundTint: 0xb8c49a, // ambient bounce from below: the green of the meadow, not gray
|
|
60
|
-
sunBrightness: 0, sunGlow: 0, moonBrightness: 0, starDensity: 0, // a flat painted backdrop: no disc, glow or stars
|
|
61
|
-
clouds: { coverage: 0 },
|
|
62
|
-
shadow: { type: 'pcf', radius: 4, extent: 45, mapSize: 2048 }, // soft edges; the island is small, so a tight box keeps them sharp enough
|
|
63
|
-
fog: { kind: 'exp', density: 0.0015 }, // barely there: the far rim fades a touch into the backdrop
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
terrain: {
|
|
67
|
-
config: { shading: 'texture', colorResolution: 256 }, // crisp river bank and field edge without more triangles (recipe 37); 128 (0.5 m pixels) shows stairs up close
|
|
68
|
-
colors: { grassA: 0x92c062, grassB: 0x86b658, river: 0x6aa6d6, riverDeep: 0x5b97ca, wheatA: 0xdcae48, wheatB: 0xd2a442,
|
|
69
|
-
earth: 0xb98d64, rock: 0x94705a },
|
|
70
|
-
biomeColors: { grass: ['grassA', 'grassB'], river: ['river', 'riverDeep'], wheat: ['wheatA', 'wheatB'], cliff: ['earth'], rock: ['rock'] },
|
|
71
|
-
variation: { blend: { size: 14, strength: 0.6 }, jitter: { size: 0.5, min: 0.97, range: 0.04 } }, // low texture: almost no grain
|
|
72
|
-
material: snowyGround,
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
// Snow: winter in the calendar turns foliage and ground most of the way to white ('mix', so green does not go muddy)
|
|
76
|
-
seasons: { mode: /** @type {const} */ ('mix'), strength: 0.82, winter: { foliage: 0xf6f6f8, ground: 0xf4f5f8 } },
|
|
77
|
-
// snow greys the sky towards overcastColor and dims the sun: keep the backdrop pale and the island readable
|
|
78
|
-
weather: { snow: { color: 0xffffff }, overcastColor: 0xe6e3de, types: { snow: { sun: 0.8, grey: 0.25 } } },
|
|
79
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// This example's look, a style part merged over the style under test (createEngine({ style: [worldStyle, look] }), worldStyle = ../world/style): how the test surfaces feel.
|
|
2
|
-
// The exhibits ask for roles wood / stone / metal / glass; a style that does not define them falls back to materials.default.
|
|
3
|
-
export default {
|
|
4
|
-
name: 'styletest',
|
|
5
|
-
materials: {
|
|
6
|
-
wood: { type: 'lambert' },
|
|
7
|
-
stone: { type: 'lambert', flatShading: true },
|
|
8
|
-
metal: { type: 'standard', metalness: 0.9, roughness: 0.3 }, // only looks like metal with environment light: ?env=1
|
|
9
|
-
glass: { type: 'phong', shininess: 100 },
|
|
10
|
-
},
|
|
11
|
-
};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
// Day-night lighting and color grade: one set of keyframes over the day for the sky (sun / moon, hemisphere, fog), exposure, a post color grade,
|
|
3
|
-
// and the game's own lamps. Technique example (README.md next to this file); copy and adapt: the numbers are a neutral starting point, the
|
|
4
|
-
// colors of your game come from its DESIGN.md look, not from here.
|
|
5
|
-
import { lut } from '@threedog/post-effects';
|
|
6
|
-
|
|
7
|
-
/** Sky keyframes: [time 0-1, zenith, horizon (= fog color), sun color (the moon at night), sun intensity, ambient intensity] */
|
|
8
|
-
export const SKY = [
|
|
9
|
-
[0.00, 0x0d1626, 0x1f2c44, 0x8fa4d4, 0.35, 0.26], // night: the "sun" row is moonlight, blue and weak; ambient keeps a floor
|
|
10
|
-
[0.21, 0x172036, 0x3a4058, 0x9aa8d4, 0.35, 0.26],
|
|
11
|
-
[0.26, 0x55688c, 0xd09c7c, 0xffb27c, 1.2, 0.6], // sunrise: warm sun, horizon warm, zenith still cool (the contrast IS the look)
|
|
12
|
-
[0.33, 0x6d92c2, 0xc6d2dc, 0xfff0dc, 2.4, 0.9],
|
|
13
|
-
[0.50, 0x6e98ce, 0xcfdae4, 0xfffaf2, 3.0, 1.1], // noon: sun 3 + hemi 1.1 ~ pi: mid-tone albedos show at their own value
|
|
14
|
-
[0.68, 0x6a8ebe, 0xd4d0c6, 0xfff0d8, 2.6, 1.0],
|
|
15
|
-
[0.73, 0x4c5c86, 0xdc9c6c, 0xffa264, 1.6, 0.7], // dusk: warmth in the LIGHT color, ambient drops so shadows turn cool by contrast
|
|
16
|
-
[0.78, 0x222e4c, 0x5c5068, 0x9aa6d4, 0.35, 0.32], // blue hour: the moon row again, a little more ambient than deep night
|
|
17
|
-
[1.00, 0x0d1626, 0x1f2c44, 0x8fa4d4, 0.35, 0.26],
|
|
18
|
-
];
|
|
19
|
-
/** Exposure over the day [time, exposure]: lifted at night so the moonlit scene reads, but never back to day brightness */
|
|
20
|
-
export const EXPOSURE = [[0, 1.15], [0.22, 1.15], [0.3, 1.0], [0.7, 1.0], [0.77, 1.1], [1, 1.15]];
|
|
21
|
-
/** Color grade over the day [time, temperature (-1 cool..1 warm), saturation, contrast] (the lut() post effect's params) */
|
|
22
|
-
export const GRADE = [
|
|
23
|
-
[0.00, -0.45, 0.72, 1.06], // night: cooler and less saturated (eyes lose color in the dark), a touch of contrast keeps edges
|
|
24
|
-
[0.22, -0.3, 0.8, 1.04],
|
|
25
|
-
[0.28, 0.35, 0.95, 1.0],
|
|
26
|
-
[0.40, 0, 1, 1],
|
|
27
|
-
[0.65, 0, 1, 1],
|
|
28
|
-
[0.73, 0.5, 0.9, 1.04], // dusk: warm, and saturation DOWN as warmth goes up, or oranges clip into neon
|
|
29
|
-
[0.79, -0.25, 0.78, 1.05],
|
|
30
|
-
[1.00, -0.45, 0.72, 1.06],
|
|
31
|
-
];
|
|
32
|
-
/** Lamps: fully on below this daylight (0 night .. 1 noon), fading in above it */
|
|
33
|
-
export const LAMPS = { onBelow: 0.02, offAbove: 0.35 }; // daylight 0.35 is about 16:40: windows and lamps come on before dark, as people switch them on
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The style fragment that carries the keyframes: createEngine({ style: [yourStyle, dayNightStyle()] }) or merge the keys into your own.
|
|
37
|
-
* The grade is a look plugin of this fragment (the shape a plugins/ file exports), so it reaches the chain through look.post.add like any effect
|
|
38
|
-
*/
|
|
39
|
-
export function dayNightStyle() {
|
|
40
|
-
return { name: 'dayNight', sky: { keyframes: SKY, moonColor: 0xc8d4f0 }, exposure: EXPOSURE, plugins: { 'lut.js': { default: lut({ enabled: true }) } } };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Linear interpolation over [[t, ...values]] rows sorted by t, wrapping at 1 */
|
|
44
|
-
export function sample(rows, t) {
|
|
45
|
-
let i = rows.findIndex(r => r[0] > t);
|
|
46
|
-
if (i <= 0) i = i === 0 ? 0 : rows.length - 1;
|
|
47
|
-
const a = rows[Math.max(0, i - 1)], b = rows[i], k = b[0] === a[0] ? 0 : (t - a[0]) / (b[0] - a[0]);
|
|
48
|
-
return a.slice(1).map((v, j) => v + (b[j + 1] - v) * Math.min(1, Math.max(0, k)));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Drive the grade and the game's lamps from engine.calendar every frame. Lamps: [{ light?: THREE.Light, material?: { emissiveIntensity },
|
|
53
|
-
* intensity, emissive }]: full values at night. The grade is written through look.post (owner 'day-night'), only when it moved, so
|
|
54
|
-
* describe() shows who set it and the fused post shader is not refreshed every frame (the same owner overwrites its keys). Returns { remove(), level() }.
|
|
55
|
-
* @param {import('threedog').Engine} engine
|
|
56
|
-
* @param {{ lamps?: { light?: any, material?: any, intensity?: number, emissive?: number }[] }} [o]
|
|
57
|
-
*/
|
|
58
|
-
export function followDayNight(engine, { lamps = [] } = {}) {
|
|
59
|
-
let last = null, level = 0, post = null;
|
|
60
|
-
const smooth = (/** @type {number} */ x) => x * x * (3 - 2 * x);
|
|
61
|
-
const frame = engine.onFrame(() => {
|
|
62
|
-
const cal = /** @type {any} */ (engine).calendar, t = cal.timeOfDay;
|
|
63
|
-
const [temperature, saturation, contrast] = sample(GRADE, t);
|
|
64
|
-
if (!last || Math.abs(last[0] - temperature) + Math.abs(last[1] - saturation) + Math.abs(last[2] - contrast) > 0.004) {
|
|
65
|
-
last = [temperature, saturation, contrast];
|
|
66
|
-
post = engine.look.post.set({ 'lut.temperature': temperature, 'lut.saturation': saturation, 'lut.contrast': contrast }, { owner: 'day-night' });
|
|
67
|
-
}
|
|
68
|
-
level = 1 - smooth(Math.min(1, Math.max(0, (cal.daylight - LAMPS.onBelow) / (LAMPS.offAbove - LAMPS.onBelow))));
|
|
69
|
-
for (const l of lamps) {
|
|
70
|
-
// intensity only, never visible = false: a light count change recompiles every lit material (a stall at dusk)
|
|
71
|
-
if (l.light) l.light.intensity = (l.intensity ?? 1) * level;
|
|
72
|
-
if (l.material) l.material.emissiveIntensity = (l.emissive ?? 1) * level;
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
return { remove() { frame.remove(); post?.remove(); }, level: () => level };
|
|
76
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
// A whole small scene on the WebGPU route, every material a three.js NodeMaterial written in TSL: ground, wind-blown grass, one material of
|
|
3
|
-
// the game's own (a lantern that lights up as the day ends) and one post effect (soft scanlines). README.md next to this file; copy and adapt.
|
|
4
|
-
// What it shows: the engine's shader functions (threedog/tsl) are plain TSL functions called inside your own nodes, and the engine's values
|
|
5
|
-
// (time, wind, daylight, season) reach your nodes through uniforms(engine). Nothing here is a style: colors are neutral starting points.
|
|
6
|
-
// Needs: import 'threedog/tsl' at the top of the game's main.js and createEngine({ renderer: 'webgpu' }) (or your own WebGPURenderer).
|
|
7
|
-
import * as THREE from 'three';
|
|
8
|
-
import { MeshLambertNodeMaterial, MeshStandardNodeMaterial } from 'three/webgpu';
|
|
9
|
-
import { color, float, mix, positionGeometry, positionLocal, positionWorld, sin, smoothstep, uv } from 'three/tsl';
|
|
10
|
-
import { wind, objectOrigin, cloudShadow, season, detailNoise, uniforms } from 'threedog/tsl';
|
|
11
|
-
|
|
12
|
-
export const PARAMS = {
|
|
13
|
-
size: 40, // m, side of the square ground
|
|
14
|
-
grass: 1500, // blades (one InstancedMesh: one draw call however many)
|
|
15
|
-
sway: 0.25, // wind amplitude, meters per meter of blade height (times engine.uniforms.uWind, which weather changes)
|
|
16
|
-
scanlines: 0.08, // post effect strength 0..1; 0 = the effect stays in the chain but does nothing
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Build the scene into engine.scene. Call before engine.start().
|
|
21
|
-
* @param {import('threedog').Engine} engine
|
|
22
|
-
* @param {Partial<typeof PARAMS>} [o]
|
|
23
|
-
* @returns {{ ground: THREE.Mesh, grass: THREE.InstancedMesh, lantern: THREE.Mesh, post: { remove(): void } }}
|
|
24
|
-
*/
|
|
25
|
-
export function createTslScene(engine, o = {}) {
|
|
26
|
-
const P = { ...PARAMS, ...o }, u = uniforms(engine);
|
|
27
|
-
|
|
28
|
-
// Ground: two earth tones mixed by the engine's detail noise (a world-space pattern, so tiles never repeat), tinted by the season and
|
|
29
|
-
// darkened under the drifting cloud shadows. All three are functions of the position; none of them needs a texture.
|
|
30
|
-
const patches = detailNoise(positionWorld.xz.mul(0.15), 0, 3).a;
|
|
31
|
-
const groundMat = new MeshStandardNodeMaterial({ roughness: 1 });
|
|
32
|
-
groundMat.colorNode = season(mix(color(0x5f7a3c), color(0x857452), smoothstep(0.35, 0.65, patches)), 1).mul(cloudShadow(positionWorld));
|
|
33
|
-
const ground = new THREE.Mesh(new THREE.PlaneGeometry(P.size, P.size).rotateX(-Math.PI / 2), groundMat);
|
|
34
|
-
ground.receiveShadow = true;
|
|
35
|
-
ground.name = 'ground';
|
|
36
|
-
|
|
37
|
-
// Grass: one blade shape drawn many times. wind() returns an object-space offset; positionGeometry is the blade before the instance
|
|
38
|
-
// transform, objectOrigin() each instance's own world origin (so neighbours sway out of phase). positionNode is also what three's shadow
|
|
39
|
-
// pass reads, so the shadows sway with the blades without a second material.
|
|
40
|
-
// Instances are only moved, never rotated or scaled: then the object-space offset is already right after the instance transform. Rotated
|
|
41
|
-
// instances: use the patch form applyEffects(mat, { wind }) (recipe 56, section 5), which turns the offset with each instance.
|
|
42
|
-
const blade = new THREE.PlaneGeometry(0.07, 0.5, 1, 3).translate(0, 0.25, 0);
|
|
43
|
-
const grassMat = new MeshLambertNodeMaterial({ side: THREE.DoubleSide });
|
|
44
|
-
grassMat.colorNode = season(mix(color(0x2f4a1c), color(0x8fb052), uv().y), 0);
|
|
45
|
-
grassMat.positionNode = positionLocal.add(wind(positionGeometry, objectOrigin(), float(P.sway)));
|
|
46
|
-
const grass = new THREE.InstancedMesh(blade, grassMat, P.grass);
|
|
47
|
-
const m = new THREE.Matrix4(), r = engine.random, half = P.size * 0.45;
|
|
48
|
-
for (let i = 0; i < P.grass; i++) grass.setMatrixAt(i, m.makeTranslation(r.range(-half, half), 0, r.range(-half, half)));
|
|
49
|
-
grass.castShadow = true;
|
|
50
|
-
grass.name = 'grass';
|
|
51
|
-
|
|
52
|
-
// The game's own material: a lantern whose glow follows the engine's daylight (1 at noon, 0 at night) and flickers with engine time.
|
|
53
|
-
// uniforms(engine) are nodes over engine.uniforms: when the sky moves uDaylight, this node moves with it; nothing to update per frame.
|
|
54
|
-
const night = float(1).sub(u.uDaylight);
|
|
55
|
-
const flicker = sin(u.uTime.mul(7)).mul(0.08).add(0.92);
|
|
56
|
-
const lanternMat = new MeshStandardNodeMaterial({ color: 0x3a2a18, roughness: 0.6 });
|
|
57
|
-
lanternMat.emissiveNode = color(0xffa040).mul(smoothstep(0.3, 0.9, night).mul(3).mul(flicker));
|
|
58
|
-
const lantern = new THREE.Mesh(new THREE.OctahedronGeometry(0.35, 1), lanternMat);
|
|
59
|
-
lantern.position.set(0, 1.2, 0);
|
|
60
|
-
lantern.castShadow = true;
|
|
61
|
-
lantern.name = 'lantern';
|
|
62
|
-
|
|
63
|
-
engine.scene.add(ground, grass, lantern);
|
|
64
|
-
|
|
65
|
-
// Post on the WebGPU route: an effect gives node(input, ctx) => color node. input is the picture so far; slot 'ldr' runs after tone
|
|
66
|
-
// mapping, so the values are display colors 0..1. ctx.p holds a live uniform per number param: look.post.set({ 'scanlines.amount': 0.2 })
|
|
67
|
-
// changes it without rebuilding the chain. A three.js Pass (create) does not run on WebGPURenderer.
|
|
68
|
-
const post = engine.look.post.add({ name: 'scanlines', slot: 'ldr', params: { amount: P.scanlines },
|
|
69
|
-
node: (input, { tsl: T, p }) => {
|
|
70
|
-
const line = T.sin(T.screenCoordinate.y.mul(Math.PI)).mul(0.5).add(0.5); // 0..1 every other device pixel row
|
|
71
|
-
return T.vec4(input.rgb.mul(T.float(1).sub(p.amount.mul(line))), input.a);
|
|
72
|
-
} });
|
|
73
|
-
|
|
74
|
-
return { ground, grass, lantern, post };
|
|
75
|
-
}
|