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
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Making a new picture from a reference picture
|
|
2
|
+
|
|
3
|
+
**In this recipe**: Example · The loop · What picture code can change, and what it cannot · Steps · Picture check after every shot · Picture questions ·
|
|
4
|
+
Guard rails · A fixed scene to judge by
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
threedog picture palette art/reference/ref.png --n 8 --average # the colors: they go in picture/palette.js
|
|
8
|
+
threedog shot --size 480x270 --out now.png # your picture, with its picture numbers
|
|
9
|
+
threedog picture compare art/reference/ref.png .threedog/shots/now.png --out side.png # what differs, as numbers and one image
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
No reference picture? Skip the measuring (step 2, `picture palette`, `picture compare` against a reference); judge each shot against DESIGN.md and
|
|
13
|
+
its "Loved / Not for this game" list, and use the rest: the loop, the picture check after every shot and the picture questions.
|
|
14
|
+
|
|
15
|
+
For an AI that is given one picture ("make it look like this") and has to turn it into the game's picture. The tools keep the work measurable: `threedog picture palette`
|
|
16
|
+
and `picture compare` measure pictures, your game's `picture/` folder holds the result in plain three.js (recipe 62). They never say which colors are right; the taste is
|
|
17
|
+
yours. How the `picture/` folder is laid out and which signals it reads are in `62-picture-code.md`; this page is the order of work.
|
|
18
|
+
|
|
19
|
+
## The loop (every round, in this order)
|
|
20
|
+
Looping "edit, screenshot, read the image" costs the most tokens and fixes the least. Numbers come first, pictures last.
|
|
21
|
+
1. **Measure the reference once** (step 2 below): `picture palette <ref> --average`, then `picture compare <ref> <your shot>`. Break the picture into
|
|
22
|
+
techniques (shading, one texture language, palette, edges) before choosing values.
|
|
23
|
+
2. **Change one family of values** (colors, then materials, then post). After writing or changing a model, look at it alone
|
|
24
|
+
first: `threedog gallery --shots` (every model under three lights, `.threedog/gallery/index.html`) shows wrong scale, wrong facing, holes and missing
|
|
25
|
+
faces before the level hides them.
|
|
26
|
+
3. **Shoot small and compare to the previous shot**: `threedog shot --size 480x270 --keep --compare <previous.png>`. It prints the
|
|
27
|
+
pixel diff and the picture differences. Through MCP the `snap` tool is 480 px wide by default; `picture_compare` gives the numbers.
|
|
28
|
+
4. **Read the numbers first, then at most one image per round.** Name the biggest remaining difference and fix only that. `picture compare <ref> <shot>
|
|
29
|
+
--out side.png` puts both in one image. With no reference, read the shot's hints (below). Then look at the image as a player would and judge it
|
|
30
|
+
against the picture DESIGN.md wants and its "Loved / Not for this game" list (never against a technique example): what would a player read as a
|
|
31
|
+
mistake? Typical ones are objects floating or cutting into each other, odd flat discs or blobs (a hard-edged opaque "puddle" reads as a gray ball),
|
|
32
|
+
glare, areas too dark or busy to read, placeholder-looking shapes; these are prompts, not a list to tick. Fix what you find, or note it in
|
|
33
|
+
STATUS.md with why it stays. Before calling a picture done, go through the "Picture questions" below that matter for this game.
|
|
34
|
+
5. **Wrong in a way the numbers do not explain?** Diagnose before guessing: `engine.debug.view('albedo' | 'lighting' | 'shadow' | 'normals')` shows which
|
|
35
|
+
layer is off, and every value has one writer, a line in your `picture/` code. Nothing drawn: `threedog scene --hidden` (reasons per mesh).
|
|
36
|
+
Washed-out or too-dark textures, odd normals: `threedog inspect materials` (wrong color spaces first, sizes, who made each material).
|
|
37
|
+
6. **If the biggest difference stops shrinking over a few rounds, change approach** (in this order) and tell the user which and why:
|
|
38
|
+
painted textures (`map`, `normalMap`) -> `onBeforeCompile` on your own material -> your own `ShaderMaterial`.
|
|
39
|
+
Never call it "close" to stop tuning.
|
|
40
|
+
7. **Every few rounds show the user the shot and the numbers.**
|
|
41
|
+
|
|
42
|
+
The loop is the same for every art direction; only what you measure and which value you move differ: flat (palette share, hard edges, no shading), painterly
|
|
43
|
+
(soft edges, texture, low contrast), low-poly (few flat colors, faceted light), realistic (exposure, tone mapping, lighting, material roughness). None is the default.
|
|
44
|
+
|
|
45
|
+
## What picture code can change, and what it cannot
|
|
46
|
+
Can change (all in `picture/`, plain three.js): colors (`picture/palette.js`, `scene.background`), every material (matte `MeshLambertMaterial`, banded `MeshToonMaterial`,
|
|
47
|
+
PBR `MeshStandardMaterial`, your own shader), the engine's big parts through their own `.material` and `.uniforms` (ground, plants, water, sky dome), lights, fog,
|
|
48
|
+
`renderer.toneMapping` and `toneMappingExposure`, post passes (the effects in `@threedog/post-effects`), UI colors and fonts, and the colors
|
|
49
|
+
of the procedural models.
|
|
50
|
+
|
|
51
|
+
Cannot change by picture code: the **silhouette of models**. A tree stays the shape its model has; a new shape means a new asset (code-built models
|
|
52
|
+
or `.glb` files, recipes `05-props-bake.md` and `10-blender-level.md`). And the **world rules**: water level, terrain shape, what
|
|
53
|
+
exists where, timing and gameplay belong to the modules' options and the game's content. If the reference shows a different
|
|
54
|
+
world (a canyon instead of hills), say so instead of faking it with colors.
|
|
55
|
+
|
|
56
|
+
## Steps
|
|
57
|
+
1. **Keep the picture.** Put it in the game's `art/reference/` (one file per style, with a few lines of notes beside it on what to copy:
|
|
58
|
+
palette, mood, line work, light direction). Use the highest-resolution picture you have: a small or compressed one gives wrong detail and brightness numbers.
|
|
59
|
+
2. **Measure it.** `threedog picture palette art/reference/ref.png --n 8 --average` (MCP: `picture_palette`) prints the colors (`--json`: JSON only) with share, hue, saturation,
|
|
60
|
+
brightness, and role hints: largest block = ground / environment candidate, brightest = highlight / sky candidate, most saturated = accent candidate,
|
|
61
|
+
darkest = shadow or outline candidate, and one summary line such as `warm colors, mostly sand, low saturation, medium brightness, weak light/dark contrast`.
|
|
62
|
+
It reads pixels in a headless browser (png, jpg, webp, gif, svg). The overall mean (`--average`) sets exposure and tint; the clusters pick the named
|
|
63
|
+
palette entries. A phone screenshot with a dark UI frame needs `--ignore-ui` or `--region x,y,w,h`; `--crop cut.png` saves exactly what was measured.
|
|
64
|
+
3. **Write them down.** The colors you measured go in `picture/palette.js`, snapped to a few named ones (a reference usually has 5 to 8 that matter). Procedural
|
|
65
|
+
models the picture needs go in the game's `art/` folder, registered with `engine.assets.manifest({ name: 'mygame', models })`.
|
|
66
|
+
4. **Fill it in, in this order** (each step changes the picture most for the least work): sky colors and `scene.background` (light and mood), `renderer.toneMapping` and
|
|
67
|
+
exposure, the lights in `picture/lights.js`, the ground's colors, the materials in `picture/materials.js` (matte, banded, shiny, PBR, unlit), post, then UI.
|
|
68
|
+
The first frame should already be close: if it is far from the reference, fix sky, exposure, palette and material type before adding anything.
|
|
69
|
+
5. **Check.** `npm run check` type-checks `picture/`, and a misspelled option or a bad call fails on the page with a line in `.threedog/errors.log`.
|
|
70
|
+
6. **Picture: the loop above.** Take pictures with the same arguments every round so only the picture differs, from named places (`shot --at <place>`), not free `--pos` shots.
|
|
71
|
+
`threedog picture compare art/reference/ref.png .threedog/shots/now.png [--region x,y,w,h]` prints brightness,
|
|
72
|
+
saturation, contrast, fine detail, average and main color of both and one sentence such as "the screenshot is 18% darker and 2.3x more broken up". There is
|
|
73
|
+
deliberately no "similarity %": the numbers turn "looks dirty / fragmented / too dark" into something you can change and re-measure. Dirty = lower
|
|
74
|
+
saturation or an off hue, fragmented = fine detail ratio well above 1, dark or flat = brightness and contrast. Keep a change if its number moved toward
|
|
75
|
+
the reference and the picture looks better. A phone UI frame in the screenshot skews the numbers: compare a `--region`.
|
|
76
|
+
Add `--out side.png` (MCP `picture_compare` always writes `<shot>.compare.png`) and open that one image: reference left, screenshot right; look at both.
|
|
77
|
+
7. **Stop** when the biggest remaining difference is a silhouette or a world rule: that is the assets or the game, not the picture code.
|
|
78
|
+
|
|
79
|
+
## Picture check after every shot
|
|
80
|
+
Every `threedog shot` prints picture numbers and hints (`--no-picture` skips them). The numbers are luminance, contrast (std and p5-p95 range of
|
|
81
|
+
luminance), saturation, clipped and near-black shares, and the shadow area. Hints come in two kinds:
|
|
82
|
+
- **Contradictions**, whatever the art direction: the settings say one thing and the pixels another. Shadows on but none measurable (with the cause it found:
|
|
83
|
+
the light's `shadow.bias` as meters of shadow depth, the view outside the shadow box, texel size, or fill light washing them out), a light that changes
|
|
84
|
+
no pixel.
|
|
85
|
+
- **Facts**: measured, maybe wanted, with what sets them: glare, large clipped or near-black areas, a night that is not dark from lighting (and
|
|
86
|
+
whether the brightness at 00:00 is lighting at all), the key / fill balance. Each becomes a contradiction only where DESIGN.md declares the
|
|
87
|
+
opposite.
|
|
88
|
+
- **Intent**, only against what the game declared: DESIGN.md's optional `Picture intent:` line (listed words such as `no-glare`, `dark-nights`,
|
|
89
|
+
`strong-light`, `muted`; the template lists them all; the table's free text is not read), or the reference given with `--ref`. A muted,
|
|
90
|
+
low-contrast game is told when its shot measures saturated and contrasty, never the other way round unless it said so. No declaration and
|
|
91
|
+
no reference: numbers only, no judgement.
|
|
92
|
+
|
|
93
|
+
A hint is a fact plus the parameter and its current value, not a target. It never says what value is right for an art direction; decide that from
|
|
94
|
+
the reference, DESIGN.md or the user. A deliberate choice (a night meant to be pitch black) makes a hint something to note, not to fix.
|
|
95
|
+
|
|
96
|
+
## Picture questions
|
|
97
|
+
Pick the ones that matter for this game, before calling a picture done and when a round stalls. They name what to look at, not which answer is
|
|
98
|
+
right for a given art direction.
|
|
99
|
+
- **Light roles**: is there one clear key light (direction, color), a fill that keeps shadows readable, and does the sky / ambient color agree with it?
|
|
100
|
+
`debug.view('lighting')`.
|
|
101
|
+
- **Shadows and contact**: do objects sit on the ground (contact shadow, AO, or a dark base), are shadow edges as hard or soft as the reference, no
|
|
102
|
+
acne or peter-panning? `debug.view('shadow')`. A shadow that starts a hand's width away from a foot or a crate is peter-panning: check
|
|
103
|
+
the light's `shadow.bias` (it is in 0-1 shadow depth, so a large value over a long light range is decimeters). Faint shadows: the shadowed ground gets
|
|
104
|
+
only the fill and the environment, so their sum against the key light sets the contrast; small casters blur when the shadow box is much bigger than the
|
|
105
|
+
scene (texel size): fit `light.shadow.camera` to the scene.
|
|
106
|
+
- **Day / night**: shoot noon and night (`shot --time 12:00`, `--time 22:00`); is night as dark as the design wants on every material, PBR ones
|
|
107
|
+
too? A PBR material that stays bright at night is usually lit by an environment map that does not follow the time: `scene.environmentIntensity` is yours to drive from `uDaylight`.
|
|
108
|
+
- **Material response**: do surfaces that should differ (wood, stone, metal, cloth, skin, water) differ in roughness, specular and color, not only hue?
|
|
109
|
+
A plastic-looking surface is a shading problem, not a color problem.
|
|
110
|
+
Metals have something to reflect (environment). A glossy flat decal (puddle, spill, polished floor) reflects only the environment map, never the
|
|
111
|
+
street around it: a hard-edged dark or bright ellipse then reads as a hole or a blob. Give it soft alpha edges and a color close to the surface
|
|
112
|
+
under it, or darken / smooth the ground's own material (roughness map) instead of laying a disc on it; check it at noon and at night.
|
|
113
|
+
- **Texture scale and detail**: is texel density similar across neighbors, no obvious tiling at the usual camera distance, detail matching how close the
|
|
114
|
+
camera gets? Color spaces right (`inspect materials`).
|
|
115
|
+
- **Color and grading**: value range (darkest / brightest), saturation and the overall hue shift match the reference (`picture compare`); exposure and
|
|
116
|
+
tone mapping chosen, not left at whatever was there.
|
|
117
|
+
- **Atmosphere and depth**: fog, haze or color shift with distance as the reference shows; the background separates from the play space.
|
|
118
|
+
- **Readability of gameplay elements**: the player, interactables, hazards and pickups stand out by value or color from the ground at play distance and
|
|
119
|
+
under every time of day / weather the game uses (shoot them at dusk and in rain too).
|
|
120
|
+
- **Consistency**: does any asset step out of the overall art direction (outline weight, shading model, texture language) where DESIGN.md did not
|
|
121
|
+
intend it? A deliberate mix is a choice, not a mistake.
|
|
122
|
+
|
|
123
|
+
## Guard rails
|
|
124
|
+
- Restraint: for each post effect, say which difference in the shot it fixes. Start with none, add one for a visible difference you named, and
|
|
125
|
+
measure again after each one.
|
|
126
|
+
- Never put gameplay or world values in `picture/` to match a picture.
|
|
127
|
+
- Fonts and textures are assets: register the file in an asset pack and name it, the picture code does not carry files.
|
|
128
|
+
- Keep `npm run check` at 0 errors; a new picture adds no warnings.
|
|
129
|
+
|
|
130
|
+
## A fixed scene to judge by
|
|
131
|
+
Same arguments, same picture, so only the picture differs. A game with many pictures to judge gives itself a small page with one of everything; `/styletest.html`
|
|
132
|
+
(`examples/styletest`) is the engine's own, a pattern to copy: a character, trees, rock, grass, flowers, water, terrain, glass, a shadow receiver,
|
|
133
|
+
wood / stone / metal surfaces, a lit room (outside and inside) and the UI parts, under named cameras.
|
|
134
|
+
- `threedog shot styletest --view <name> [--time day|dusk|night] [--weather clear|rain|snow]`; the same words work as URL parameters
|
|
135
|
+
(`?view=room&time=dusk&weather=rain`).
|
|
136
|
+
- Views: `overview` (everything: overall brightness, ground color, shadow darkness), `character` (close-up: character colors, outline, shadow on
|
|
137
|
+
the ground), `water` (water color, shore, fog at distance), `room` (the lamp and window light against the dark corners: ambient level, `ao`, bloom),
|
|
138
|
+
`path` (the camera moves along a fixed line at 2.5 m/s: with `--wait 4` the shot is the same frame every time; in a browser look for grass blades
|
|
139
|
+
and shadow edges that flicker or crawl), `ui` (HUD, dialogue line, bag window: the UI colors).
|
|
140
|
+
- Per round: shoot `overview`, `room` at `--time dusk`, and `character`.
|
|
141
|
+
- The dev panel, in any game: `if (location.search.includes('panel=1')) import('@threedog/tools/panel').then(m => m.openPanel(engine));`
|
|
142
|
+
It needs the optional dev package `tweakpane` (`npm install -D tweakpane`; the repository's `npm install` has it); without it the page says so.
|
|
143
|
+
A production build of the vite preset gets a stub instead (no panel, no tweakpane in the bundle); dev and test builds get the real one.
|
|
144
|
+
It reads the three.js objects and writes them directly: exposure, `scene.fog`, each light, `engine.water` / `terrain` / `vegetation` materials and uniforms
|
|
145
|
+
(when installed), a material picked by name, `engine.uniforms`, post effects, UI colors. "write back" saves the changes to
|
|
146
|
+
`.threedog/tune.json` on the dev server; then `threedog tune write <file>` prints the code change as a diff (one `// threedog:tune begin ... end` block
|
|
147
|
+
of plain three.js writes) and `--apply` writes it. Review it, then keep the block or move each value where it belongs (`picture/palette.js`, the material's definition).
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Sky, ground and plants
|
|
2
|
+
|
|
3
|
+
```js
|
|
4
|
+
engine.use(terrain({ ...terrainPreset(), colors: { grass: 0x6a8a3a, rock: 0x777066 }, biomeColors: { meadow: ['grass'], cliff: ['rock'] } }));
|
|
5
|
+
engine.terrain.material.flatShading = true; // the ground's picture is a plain three.js material
|
|
6
|
+
engine.terrain.recolor({ colors: { grass: 0xa8a050, rock: 0x777066 } }); // what the workers baked in, changed at run time
|
|
7
|
+
engine.terrain.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.terrain.patches }); // your own, effects kept
|
|
8
|
+
engine.vegetation.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.vegetation.patches });
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For an AI that wants the sky, the ground or the plants to look a way the defaults do not. Each section lists the engine default; code that sets nothing
|
|
12
|
+
gets it. None of these settings moves a hill, a river or a species list. The order of work from a reference picture is in `35-picture-from-reference.md`.
|
|
13
|
+
|
|
14
|
+
## Sky clouds: `sky({ clouds })` (at run time `engine.uniforms.uCloudCover.value`, `uCloudColor`, `uCloudShade`, `uSkyCloudScale`, `uSkyCloudSpeed`, `uCloudOpacity`, `uCloudSoft`)
|
|
15
|
+
| Key | Meaning | Default |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| `color`, `shade`, `coverage`, `scale`, `speed` | lit color, shaded color, cover (multiplies the weather's cloud amount), size, drift speed | |
|
|
18
|
+
| `kind` | `'plane'` cheap, 3 noise samples. `'cumulus'` billowy, 8 noise samples per cloudy sky pixel, flatter projection (clouds fill the whole sky instead of crowding at the horizon), the sun side of each cloud is lit and the underside shaded | `'plane'` |
|
|
19
|
+
| `horizon` | added to `dir.y` before projecting; smaller = clouds shrink and crowd more towards the horizon | plane 0.08, cumulus 0.5 |
|
|
20
|
+
| `fade` | `[from, to]` in `dir.y`: invisible below `from`, full above `to` | plane `[0, 0.18]`, cumulus `[0, 0.12]` |
|
|
21
|
+
| `opacity`, `softness` | cloud alpha; width of the cloud edge | 0.9 / 0.3 (cumulus 0.95 / 0.35) |
|
|
22
|
+
| `noise` | plane only: `{ scales: [2.7, 6.1], weights: [0.6, 0.3, 0.1] }`, the two finer layers' frequency and the mix of the three | as shown |
|
|
23
|
+
| `relief` | cumulus only: contrast of the sun-side light | 5 |
|
|
24
|
+
|
|
25
|
+
Why a thin band at the horizon with `plane`: the plane projection divides by height, so near the horizon one screen pixel covers a lot of cloud plane
|
|
26
|
+
and the noise is dense and small; overhead one pixel covers little and the same coverage looks sparse. For a sky full of big clouds use
|
|
27
|
+
`kind: 'cumulus'`, or raise `horizon` (0.3-0.6) and lower `scale`. Cost: both are one 2D pass over the dome (no ray marching); cumulus is about
|
|
28
|
+
2.7x the noise work of plane on the cloudy pixels (pixels below the horizon or with no cloud cover skip it). Cloud shadows on the ground
|
|
29
|
+
(the signal `engine.uniforms.uCloudShadow`, a separate setting) follow the same weather cover, so more clouds still means more shadow.
|
|
30
|
+
|
|
31
|
+
```js fragment
|
|
32
|
+
sky: { clouds: { kind: 'cumulus', coverage: 1, scale: 0.45, color: 0xfff4e4, shade: 0x8a9cb8, speed: [0.003, 0.001] } }
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Your own cloud function
|
|
36
|
+
`engine.sky.clouds(glsl | { glsl, tsl, uniforms })` is the one way in (a `glsl` key in `sky({ clouds })` throws and names it). The GLSL must define this function; the dome calls it for every upper-hemisphere pixel with cover above 0.01, then does `mix(sky, rgb, a)`:
|
|
37
|
+
```glsl
|
|
38
|
+
vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover)
|
|
39
|
+
// dir: unit view direction, dir.y > 0. sunDir: towards the sun (the moon is opposite). night: 0 day .. 1 night.
|
|
40
|
+
// lit / shade: clouds.color / clouds.shade. cover: weather cloud amount * clouds.coverage.
|
|
41
|
+
// return: rgb = final cloud color (dim it at night yourself), a = opacity (apply your own horizon fade).
|
|
42
|
+
```
|
|
43
|
+
In scope: the GLSL noise helpers `float threedogHash(vec2 p)` and `float threedogNoise(vec2 p)`, the built-in cloud uniforms (`uCloudScale`, `uCloudSpeed`, `uCloudHorizon`, `uCloudFade`...) and
|
|
44
|
+
the patch's `uniforms` (declared for you; number, `THREE.Color`, `THREE.Vector2/3/4`, array of 2-4 numbers, or `THREE.Texture`). Change one later
|
|
45
|
+
with `engine.sky.dome.material.uniforms.uEdge.value = 0.1`. A bad `kind`, GLSL without the function, or an unsupported uniform value throws with the fix.
|
|
46
|
+
Flat painted cloud blobs with a hard edge, multiplied by a texture:
|
|
47
|
+
```js
|
|
48
|
+
// sky({ clouds: { color: 0xfff1dc, shade: 0x9aa8c4 } }) gives lit and shade; the function goes through the hook
|
|
49
|
+
engine.sky.clouds({ uniforms: { uPaper: paperTexture, uEdge: 0.06 }, // paperTexture: any THREE.Texture, repeat wrapping
|
|
50
|
+
glsl: `vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover){
|
|
51
|
+
vec2 p = d.xz / (d.y + 0.5) * 0.4 + vec2(0.004, 0.002) * time;
|
|
52
|
+
float n = threedogNoise(p) * 0.65 + threedogNoise(p * 2.3 + 5.0) * 0.35;
|
|
53
|
+
float a = smoothstep(1.0 - cover, 1.0 - cover + uEdge, n); // hard edge
|
|
54
|
+
float up = clamp(0.5 + (n - threedogNoise(p + sunDir.xz * 0.1)) * 6.0, 0.0, 1.0); // sun side
|
|
55
|
+
vec3 c = mix(shade, lit, up) * texture2D(uPaper, p * 3.0).rgb * (0.35 + 0.65 * (1.0 - night));
|
|
56
|
+
return vec4(c, a * smoothstep(0.0, 0.1, d.y));
|
|
57
|
+
}` });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Ground color: `terrain({ colors, biomeColors, steep, variation })`
|
|
61
|
+
Terrain colors are baked by the (worker) generator: two colors blended by a noise, a small brightness grain, and an optional layer of large patches.
|
|
62
|
+
`colors` names the colors, `biomeColors` gives each ground type one or two of those names, `steep` overrides them on slopes. A ground type with no
|
|
63
|
+
color is neutral gray. The `variation` defaults are shown (plain data, so it travels to the workers; unknown keys throw):
|
|
64
|
+
```js fragment
|
|
65
|
+
terrain({ colors: { ... }, biomeColors: { ... },
|
|
66
|
+
variation: {
|
|
67
|
+
blend: { size: 33, strength: 1 }, // wavelength in m of the two-color noise; strength > 1 = harder contrast, < 1 = flatter
|
|
68
|
+
jitter: { size: 0.33, min: 0.92, range: 0.12 }, // grain cell in m; darkest multiplier; how much brighter it can get (0 range = no grain)
|
|
69
|
+
patches: { size: 90, strength: 0.15, levels: 0, tint: 0xb59a5a }, // optional (example values): a second, large layer of color blocks
|
|
70
|
+
} })
|
|
71
|
+
```
|
|
72
|
+
`patches` is off unless given. It is a noise much larger than `blend`; `levels: 4` snaps it to 4 flat steps (hard-edged color blocks instead of a
|
|
73
|
+
soft blend); without `tint` it lightens and darkens the ground, with `tint` it pulls the color towards the tint where the noise is high. Vertex colors
|
|
74
|
+
interpolate across a chunk cell (4 m at the default resolution), so blocks smaller than that blur; for crisp blocks use `shading: 'texture'`
|
|
75
|
+
(recipe 37) or a texture (next). Which combination fits which picture, and ground that looks wrong up close: recipe 53.
|
|
76
|
+
|
|
77
|
+
### Changing it at run time: `engine.terrain.recolor`
|
|
78
|
+
```js fragment
|
|
79
|
+
engine.terrain.recolor({ colors, biomeColors, steep, variation, shading, normals }); // every chunk is rebuilt; edits stay, collision does not change
|
|
80
|
+
engine.terrain.recolor({ detail: { noise: 'paper', strength: 0.2 } }); // only the material: no chunk is rebuilt
|
|
81
|
+
```
|
|
82
|
+
Each value is given whole, not merged, and `null` takes it out (`shading: null` goes back to what `terrain({...})` was given). Keys left out stay.
|
|
83
|
+
`recolor` throws under a picture that replaced `'terrain-draw'`, which draws the ground its own way.
|
|
84
|
+
|
|
85
|
+
### Your own ground material
|
|
86
|
+
`engine.terrain.material` is what every chunk draws with: a plain three.js material, neutral gray with vertex colors until you change it. Write to it, or
|
|
87
|
+
set your own at any time; `terrain({ material })` (a Material or `(engine) => Material`) does the same from the start. Setting it swaps the material on
|
|
88
|
+
every loaded chunk, regenerates nothing and adds nothing: a material of yours is drawn as given. To keep the cloud shadow, the season tint and the
|
|
89
|
+
detail layer, hand it `engine.terrain.patches`. `terrain({ material })` adds them for you unless `effects: false`. After a later `recolor({ detail })`
|
|
90
|
+
patch your material again; the engine only rebuilds its own.
|
|
91
|
+
|
|
92
|
+
Chunk geometry has `position`, `normal`, `color` and `uv = world xz / chunk size`, continuous across chunk borders (checked by
|
|
93
|
+
`tests/specs/appearance.mjs`), so a repeating texture is seamless whatever chunk it lands in. `texture.repeat.set(8, 8)` = 8 tiles per chunk. Without
|
|
94
|
+
UVs (steep sides stretch a top-down map), project from the world position in a patch instead (`needs.patches: ['world']` gives `vThreedogWorld`):
|
|
95
|
+
```js
|
|
96
|
+
engine.terrain.material = applyEffects(new THREE.MeshLambertMaterial({ vertexColors: true }), { clouds: false, patches: [{
|
|
97
|
+
name: 'triplanar', needs: { patches: ['world'] }, uniforms: { uTex: { value: groundTexture }, uTexScale: { value: 0.1 } }, // groundTexture: repeat wrapping
|
|
98
|
+
glsl: { fragment: { pars: 'uniform sampler2D uTex; uniform float uTexScale;',
|
|
99
|
+
color_fragment: `vec3 n = abs(normalize(cross(dFdx(vThreedogWorld), dFdy(vThreedogWorld)))); n /= n.x + n.y + n.z;
|
|
100
|
+
diffuseColor.rgb *= texture2D(uTex, vThreedogWorld.zy * uTexScale).rgb * n.x + texture2D(uTex, vThreedogWorld.xz * uTexScale).rgb * n.y
|
|
101
|
+
+ texture2D(uTex, vThreedogWorld.xy * uTexScale).rgb * n.z;` } } }] });
|
|
102
|
+
```
|
|
103
|
+
A procedural noise texture is a `THREE.DataTexture` filled in a loop (`wrapS = wrapT = THREE.RepeatWrapping`, `colorSpace = THREE.SRGBColorSpace`,
|
|
104
|
+
`needsUpdate = true`).
|
|
105
|
+
|
|
106
|
+
### Detail layer
|
|
107
|
+
The lighter alternative, with no material of your own: `terrain({ detail })`, or `engine.terrain.recolor({ detail })` at run time. It takes
|
|
108
|
+
`noise: 'grain' | 'paper' | 'stroke' | 'dabs'`, or `texture: 'name'`, or your own `glsl`, and `scale`, `strength`, `fade` ... (keys in recipe 43; here
|
|
109
|
+
`scale` defaults to 0.25 and `strength` to 0.35). `engine.terrain.uniforms` are its `{ value }` objects, written directly and live:
|
|
110
|
+
`engine.terrain.uniforms.uDetailStrength.value = 0.2`. Which to pick: recipe 53.
|
|
111
|
+
|
|
112
|
+
## Plants and wind
|
|
113
|
+
```js
|
|
114
|
+
engine.vegetation.define('oak', { model: await engine.assets.model('oak'), wind: 0.02 }); // per species: its own material, wind, fade
|
|
115
|
+
engine.vegetation.define('fern', { geometry, material: new THREE.MeshToonMaterial({ vertexColors: true }), wind: 0.08 });
|
|
116
|
+
engine.vegetation.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.vegetation.patches }); // the shared default
|
|
117
|
+
engine.uniforms.uWindAmp.value = 0.5; engine.uniforms.uWindFreq.value = 2; // how hard and how fast: plain signals, live
|
|
118
|
+
```
|
|
119
|
+
`engine.vegetation.material` is what every species with no material or model of its own draws. Set it and it is drawn as given, on plants already
|
|
120
|
+
planted too: nothing is added behind it, so hand it `engine.vegetation.patches` (season tint, sway at one amplitude, the `color()` code) to keep those.
|
|
121
|
+
`null` gives the neutral default back. A species' own amplitude and near fade need a material of its own: `define(name, { material })` adds wind, cloud
|
|
122
|
+
shadows, season tint and the fade to it unless `effects: false`. Each species' live material is `engine.vegetationDraw.kind(name).material`.
|
|
123
|
+
|
|
124
|
+
What the vegetation code fixes, split into mechanism (stays) and picture:
|
|
125
|
+
|
|
126
|
+
| Where | What | Kind |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| `Vegetation.define` | per species: `wind` amplitude, `rule`, `positions`, `densityMap`, `lodRing`, `maxRing`, `nearOnly`, `castShadow`, `shadowRing`, `material`, `effects` | already options (game content) |
|
|
129
|
+
| `GroundChunks`, `VegetationDraw` (`modules/vegetation/draw.js`) | one InstancedMesh per species per chunk; rings decide LOD swap, draw distance, shadow distance; 3 ms placement budget; collision lag | mechanism, stays (the whole picture is replaceable: recipe 28 section 6) |
|
|
130
|
+
| wind sway shape | two sines (speed `1.2 + 0.6*uWind` and `2.9`, spatial phase from the instance origin), height-weighted, lean with wind strength | picture: **`engine.vegetation.sway(glsl)`** replaces it for every species whose `wind` is a number, planted ones too |
|
|
131
|
+
| wind speed, strength | `uWindFreq`, `uWindAmp` | signals: `engine.uniforms.uWindFreq.value`, `uWindAmp.value` (0 = plants stand still) |
|
|
132
|
+
| color | vertex and instance colors, season tint | picture: **`engine.vegetation.color(glsl \| { glsl, tsl })`** puts code in the `color` slot of every species, live |
|
|
133
|
+
| season tint | `diffuseColor.rgb *= tint` (default) or a blend towards the tint; colors from `engine.sky.seasonTints` | `engine.sky.seasonTints = { mode: 'multiply' \| 'mix', strength, autumn: { foliage: 0xffb070 } }`; see recipe 43 |
|
|
134
|
+
| defaults | `castShadow` = not `nearOnly`, `shadowRing` 1, `lodRing` 1 | per-species options, set them in the species |
|
|
135
|
+
|
|
136
|
+
```js
|
|
137
|
+
engine.vegetation.sway({ uniforms: { uSteps: 3 }, // stepped sway: plants snap between 3 poses instead of a smooth sine
|
|
138
|
+
glsl: `void threedogWind(inout vec3 transformed, vec3 ip, vec3 position){
|
|
139
|
+
float s = floor(sin(uTime * uWindFreq + ip.x * 0.3 + ip.z * 0.2) * uSteps) / uSteps;
|
|
140
|
+
transformed.x += s * max(position.y, 0.0) * THREEDOG_WIND_AMP * uWind;
|
|
141
|
+
}` });
|
|
142
|
+
```
|
|
143
|
+
`threedogWind` receives the vertex (`transformed`, object space), `ip` (world position of this plant's origin, so each plant has its own phase) and
|
|
144
|
+
`position`; `uTime`, `uWind` (weather), `uWindFreq` and `THREEDOG_WIND_AMP` (the species' amplitude) are in scope. It applies to every material made by
|
|
145
|
+
`vegetation.define` whose `wind` is a number, and the shadow sways with it. A missing function throws with the signature. WebGPU needs the `tsl` form: `{ glsl, tsl }`.
|
|
146
|
+
`sway(null)` gives the built-in sway back. A shared material the game set keeps what it was built with: apply the new `engine.vegetation.patches` to it. The same object works in code:
|
|
147
|
+
`applyEffects(mat, { wind: { amplitude: 0.03, glsl, uniforms } })`.
|
|
148
|
+
|
|
149
|
+
Two entries, two scopes: `sway()` is the default shape for all plants, and `vegetation.define(name, { wind: { amplitude, glsl, tsl, uniforms } })` is one species' own
|
|
150
|
+
sway. When both are set the species' own wins, and `sway()` and `sway(null)` leave it as it is. Use one `sway()` for the world and a `wind` object for the plant that moves differently.
|
|
151
|
+
|
|
152
|
+
Cost, measured with software rendering (relative numbers only): 10,000 grass blades of 6 triangles in one InstancedMesh draw in 1 call; per frame
|
|
153
|
+
about 120 ms with no wind, default wind and a custom sway alike, so the sway function is not where grass time goes (vertex count and fill are).
|
|
154
|
+
Reduce grass cost with `rule.perChunk`, `maxRing` and `nearOnly`, not the wind.
|
|
155
|
+
|
|
156
|
+
## What is still fixed
|
|
157
|
+
Cloud *shadows* on the ground (`threedog_clouds_pars_fragment`) keep their two-noise shape; strength, scale and speed are the signals
|
|
158
|
+
`engine.uniforms.uCloudShadow`, `uCloudScale`, `uCloudSpeed`. Grass has no billboard or blade-shape setting: give `vegetation.define` your own `geometry` or `model`.
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
For an AI that wants the ground to look a way the defaults do not: crisp color borders (a river bank, a path edge), a coarse low-poly mesh with
|
|
4
4
|
fine color, a different triangle cut, custom lighting normals, height read from a grid or image. Terrain basics are in `28-terrain.md`, ground
|
|
5
|
-
color noise in `36-sky-ground-
|
|
6
|
-
default (`tests/specs/terrain-
|
|
5
|
+
color noise in `36-sky-ground-plants.md`, the ground up close (detail, variation, symptoms) in `53-ground-up-close.md`. Each knob names its
|
|
6
|
+
default (`tests/specs/terrain-draw.mjs` pins them). Each knob has three exits: a parameter, a small pure function, or replacing the whole ground material.
|
|
7
7
|
|
|
8
8
|
## Why the bank is jagged: color lived on the mesh
|
|
9
9
|
With `shading: 'smooth'` or `'flat'` a color is computed at a grid point (or triangle center) and blended across the triangle. At the default
|
|
@@ -14,10 +14,9 @@ computed per pixel into a per-chunk image, the mesh stays as coarse as you like.
|
|
|
14
14
|
## 1. `shading: 'texture'` (and `colorResolution`)
|
|
15
15
|
```js
|
|
16
16
|
engine.use(terrain({ ...terrainPreset(), shading: 'texture', colorResolution: 128 }));
|
|
17
|
-
// or as a look of a style: terrain: { config: { shading: 'texture', colorResolution: 128 }, colors, biomeColors, ... }
|
|
18
17
|
```
|
|
19
18
|
- A worker computes a `(colorResolution + 2)^2` RGBA image per chunk with the same rules as the vertex colors (`faceColor`: ground type from your
|
|
20
|
-
`groundType`, `biomeColors` two-color noise blend, `steep` slope colors, `
|
|
19
|
+
`groundType`, `biomeColors` two-color noise blend, `steep` slope colors, `variation` blend / jitter / patches, painted cells).
|
|
21
20
|
The main thread uploads it as a `DataTexture` (sRGB, mipmaps, anisotropy 4). The `+ 2` is a 1 pixel border computed from world coordinates, so
|
|
22
21
|
neighboring chunks hold identical values at the seam and no seam shows (checked byte for byte).
|
|
23
22
|
- Vertex colors are plain white in this mode (they carry no color). The material samples the image by world xz (the `world` patch), so `uv`
|
|
@@ -55,8 +54,7 @@ Cost (software-rendered machine, relative values only):
|
|
|
55
54
|
```js
|
|
56
55
|
terrain({ normalFn: (i, j, h, cell) => [(h(i - 1, j) - h(i + 1, j)) / cell, 4, (h(i, j - 1) - h(i, j + 1)) / cell] }) // gentler lighting on slopes
|
|
57
56
|
```
|
|
58
|
-
`normals` and `normalFn`
|
|
59
|
-
(`engine.look.ground.set({ normals: 'flat' })`, rebuilds the chunks), not a `terrain()` option.
|
|
57
|
+
`normals` and `normalFn` change light only, never height or collision. `engine.terrain.recolor({ normals: 'flat' })` changes it at run time (rebuilds the chunks).
|
|
60
58
|
|
|
61
59
|
## 3. `diagonal`: how a cell is cut into triangles
|
|
62
60
|
```js
|
|
@@ -64,15 +62,13 @@ terrain({ diagonal: 'adaptive' }) // 'fixed' (default) | 'adaptive' | 'alterna
|
|
|
64
62
|
```
|
|
65
63
|
`fixed` cuts every cell the same way. `adaptive` cuts along the diagonal with the smaller height difference, which removes
|
|
66
64
|
the zigzag ridges a fixed cut leaves on a slope; `alternate` flips every other cell (no directional bias on flat low-poly facets). `engine.surface`,
|
|
67
|
-
collision and vegetation heights follow the chosen cut, so nothing floats.
|
|
68
|
-
`terrain({...})`, not to a style (rule R34 and `style check` accept `shading`, `colorResolution`, `normals`, `normalFn` in `style.terrain.config`
|
|
69
|
-
and flag `diagonal`).
|
|
65
|
+
collision and vegetation heights follow the chosen cut, so nothing floats. It changes the walkable shape, so `recolor` does not take it.
|
|
70
66
|
|
|
71
67
|
## 4. `boundsPad`: the chunk bounding sphere margin
|
|
72
68
|
`boundsPad: { up: 3, radius: 8 }` (meters, the defaults) is the margin of the culling sphere: the center is raised by `up`, the radius grows
|
|
73
69
|
by `radius`. Raise it if a shader moves vertices far (wind on tall ground cover, a vertex-displacement patch) and chunks pop out at the screen edge.
|
|
74
70
|
|
|
75
|
-
## 5. Relation to `
|
|
71
|
+
## 5. Relation to `variation`
|
|
76
72
|
`variation` shapes *what* color a point gets; `shading` decides *where* it is evaluated. In vertex modes every variation is limited to cell size; in
|
|
77
73
|
texture mode it is sampled per pixel, so `patches: { size: 20, levels: 4 }` gives hard-edged color blocks, and a `jitter.size` below the pixel size
|
|
78
74
|
(0.5 m at `colorResolution: 128`) comes out as one grain per pixel, coarser than asked. Choosing a combination, and ground that looks wrong up close: recipe 53.
|
|
@@ -96,7 +92,7 @@ Using a preset (`riverAt` of `@threedog/terrain-noise`) the same switch gives cr
|
|
|
96
92
|
`width` samples span `width - 1` cells; outside the grid the edge value is used, or `outside: v`. The grid is just a field: height, moisture, a
|
|
97
93
|
ground-type weight, spawn density, a walkable mask, danger, travel cost.
|
|
98
94
|
|
|
99
|
-
`interp` is the
|
|
95
|
+
`interp` is the picture between nodes; none of them is the right one:
|
|
100
96
|
- `'nearest'`: flat steps, one value per cell. Terraces, blocky or voxel-like ground, tile masks, numbers that are ids.
|
|
101
97
|
- `'linear'` (default): plain bilinear blend; smooth enough for most fields, never leaves the range of its four corners.
|
|
102
98
|
- `'cubic'`: smooth slopes without cell creases (rolling hills, soft gradients). It can overshoot beside a sharp step; `clamp: true` keeps the
|
|
@@ -112,8 +108,8 @@ const walk = sampleGrid(mask, { width: 64, height: 64, cellSize: 1, interp: 'nea
|
|
|
112
108
|
A terrain `height` function is recompiled in a worker and cannot capture `heightAt`, so the terrain reads the same image through its own
|
|
113
109
|
`heightmap` (bilinear, centered on `center`): `terrain({ heightmap: { ...g, size: [512, 512], min: -5, max: 60 } })` with `g` from `gridFromImage`
|
|
114
110
|
using the default `range` (it expects 0-1 values; `min`/`max` scale them). Use `sampleGrid` for everything outside the terrain module; when you need
|
|
115
|
-
a
|
|
111
|
+
a picture the terrain's bilinear read does not give (terraces: `nearest`), bake it into the data first or write the step in a `height` function.
|
|
116
112
|
|
|
117
113
|
## Whole replacement
|
|
118
|
-
Anything beyond this: `terrain({ material })` (or `
|
|
114
|
+
Anything beyond this: `terrain({ material })` (or `engine.terrain.material = m`) swaps the ground material and `engine.terrain.T.buildChunk(cx, cz)` returns the
|
|
119
115
|
raw arrays (`pos`, `nor`, `col`, `uv`, and `tex: { data, size }` in texture mode) if you build chunk meshes yourself.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Lights, fog and exposure
|
|
2
|
+
|
|
3
|
+
Lights, fog and exposure are your own three.js code ([recipe 62](62-picture-code.md)): the sky computes signals and draws its dome, it writes none of them. This page covers what is left around
|
|
4
|
+
that: the placeholder lights, fog, the tone curve, extra sky layers. Sky basics are in `08-weather-sky.md`, clouds and ground color in
|
|
5
|
+
`36-sky-ground-plants.md`, environment lighting in `34-environment-lighting.md`.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Lights: the placeholders, and your own
|
|
9
|
+
The engine has one directional light (`engine.lights.sun`) and one hemisphere (`engine.lights.hemi`): still white placeholders (sun 2 at (40, 80, 30) with soft shadows, hemi 1.2), so a scene
|
|
10
|
+
with no picture code is neutral gray and not black. Nothing moves them, with or without a sky.
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
const engine = createEngine({ canvas, lights: false }); // the placeholders stay out of the scene
|
|
14
|
+
const sun = new THREE.DirectionalLight(0xffd0a0, 2); engine.scene.add(sun, sun.target); // add your own lights before engine.start()
|
|
15
|
+
engine.onRender(() => { sun.position.copy(engine.uniforms.uSunDir.value).multiplyScalar(100); sun.intensity = 2 * engine.uniforms.uDaylight.value * engine.uniforms.uWeatherLight.value; });
|
|
16
|
+
const torch = new THREE.PointLight(0xffa040, 6, 12); engine.add(torch);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- `createEngine({ lights: false })`: the default sun and hemisphere are never put in the scene, `engine.lights.sun` / `hemi`
|
|
20
|
+
stay as detached objects so nothing reads `undefined`. Use it for a scene lit entirely by your own lights.
|
|
21
|
+
- Shadows: only the engine sun's box is managed. Your own `castShadow` lights work as in three.js, each costing its
|
|
22
|
+
own shadow pass; `engine.shadows` (recipe 45) takes them when you hand them in, and `engine.shadows.enabled = false` turns every shadow off.
|
|
23
|
+
- Add or remove lights before `engine.start()`; what a change costs mid-play, and many lamps with `lightPool`: recipe 09 "Lights and stalls".
|
|
24
|
+
|
|
25
|
+
## Fog: plain three.js, signals, your own math
|
|
26
|
+
```js
|
|
27
|
+
const fog = engine.scene.fog = new THREE.Fog(0x99bbbb, 60, 220); // or new THREE.FogExp2(color, density)
|
|
28
|
+
engine.onRender(() => { // a fog that follows the day and the weather: your picture/ code
|
|
29
|
+
fog.color.copy(engine.uniforms.uSkyHorizon.value);
|
|
30
|
+
fog.far = 220 / engine.uniforms.uWeatherFog.value;
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
There is no fog until your code makes one, and nothing writes it after that.
|
|
34
|
+
|
|
35
|
+
- Signals to read: `uSkyHorizon` is the color at the horizon, so fog in that color hides the line where the dome meets the ground; `uWeatherFog` is what the weather asks for, a
|
|
36
|
+
multiplier your code applies; `uViewDistance` says how far the world is meant to be seen (`terrain({ viewFog: true })` writes it).
|
|
37
|
+
- Color, near, far and density are live. Adding or removing `scene.fog`, or changing its type, recompiles materials once: do it at a scene change, not every frame.
|
|
38
|
+
- Materials with `fog: false` (the dome) are not fogged.
|
|
39
|
+
- Your own fog math (height fog, a warm far haze): the `fogPars` and `fog` slots on a material, WebGL only (recipe 43), or your own `ShaderMaterial`:
|
|
40
|
+
`applyEffects(material, { patches: [{ name: 'haze', slot: 'fog', glsl: 'float f = 1.0 - exp(-fogDensity * vFogDepth); gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(1.0, 0.85, 0.7), f * 0.3);' }] })`.
|
|
41
|
+
- Check the result with `engine.describe('picture').picture.fog`; `threedog shot` says how much of the picture the fog makes up.
|
|
42
|
+
|
|
43
|
+
## Exposure and the tone curve
|
|
44
|
+
```js
|
|
45
|
+
engine.renderer.toneMappingExposure = 1.3;
|
|
46
|
+
engine.onRender(() => { engine.renderer.toneMappingExposure = 1 + 0.5 * (1 - engine.uniforms.uDaylight.value); }); // over the day: your picture/ code
|
|
47
|
+
engine.renderer.toneMapping = THREE.NeutralToneMapping; // the curve; materials recompile on their next draw
|
|
48
|
+
```
|
|
49
|
+
The engine picks no curve: `renderer.toneMapping` stays three.js's default (`NoToneMapping`) until your code writes it. A curve of your own is a post effect in the `'tone'` slot (recipe 52).
|
|
50
|
+
|
|
51
|
+
## Extra sky layers: rainbow, aurora, color bands
|
|
52
|
+
`engine.sky.layer(name, spec)`, drawn on the dome after clouds and stars; none by default:
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
engine.sky.layer('aurora', { blend: 'add', uniforms: { uAurora: [0.2, 1, 0.6] }, glsl: `vec4 threedogSkyLayer(vec3 d, float time, vec3 sunDir, float night){
|
|
56
|
+
float band = smoothstep(0.25, 0.45, d.y) * (1.0 - smoothstep(0.55, 0.8, d.y));
|
|
57
|
+
float n = threedogNoise(vec2(d.x * 4.0 + time * 0.05, d.z * 2.0));
|
|
58
|
+
return vec4(uAurora, band * n * night); }` });
|
|
59
|
+
```
|
|
60
|
+
Signature `vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)` returns (rgb, amount). `blend: 'mix'` (default) or `'add'`;
|
|
61
|
+
`order` sorts layers (smaller first); `uniforms` like `clouds.uniforms`, live in `engine.sky.dome.material.uniforms.uAurora.value`. Each layer's function is
|
|
62
|
+
renamed (`threedogSkyLayer0`, `1`, ...), so layers from different parts of the game never clash. Whole replacement: `engine.sky.replace(panorama)` or
|
|
63
|
+
hide `engine.sky.dome` and add your own background.
|
|
64
|
+
|
|
65
|
+
## Water and weather particles
|
|
66
|
+
Water depth color, crest foam, wave / surface GLSL, reflections; rain and snow shape, size, density and shaders, the lightning picture, and
|
|
67
|
+
particles for the game's own weather (`engine.weather.define`): `44-water-weather-hooks.md`.
|