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/09-style.md
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
# The game's style folder: changing the art
|
|
2
|
-
|
|
3
|
-
**In this recipe**: 0. Using a style · 0b. Composing a style from parts · 0c. What a style may not hold · 0d. Look plugins in a style folder · 1. Creating a new style ·
|
|
4
|
-
1b. Lights and stalls · 2. Using your own models instead of procedural ones · 2b. Wind, cloud shadows and season tint on your own… ·
|
|
5
|
-
3. When the engine gets a new "look parameter" · 4. Verify · 5. Sounds and music
|
|
6
|
-
|
|
7
|
-
**The engine ships no art.** No default style, character model, terrain look or terrain generator: with no style and no model everything is a
|
|
8
|
-
plain neutral placeholder (a gray capsule for characters, a gray box for props and pickups, flat gray ground at y = 0, one white hemisphere light plus
|
|
9
|
-
one neutral directional light without shadows or tone mapping), and the console says once in dev what is missing and how to fix it.
|
|
10
|
-
|
|
11
|
-
A game's style is a plain object its `style/` folder exports, passed in as `createEngine({ style })`. It holds **looks only**: colors,
|
|
12
|
-
materials and shaders, sky and lighting, post effects, UI look. Not part of it: model / texture / sound files and procedural models content names (an
|
|
13
|
-
**asset pack**, `engine.assets.manifest`, recipe 05 "Asset packs"), sounds (section 5), gameplay data and timing (a **content pack**, recipe 20;
|
|
14
|
-
`calendar({ hoursPerDay })`). Which key is read by whom is in the "style keys" table of `../CODEMAP.md`; the field list is in `../api/style.md`. Every
|
|
15
|
-
entry can be omitted; omitted entries are the neutral placeholders above (the city example passes no style at all). Write it as a plain object literal, no `@type` or `as const`: fields with a fixed set of words (`shading`, `mode`, `type` …) accept any string in the types, and a wrong word is reported by `threedog style check` with the fix.
|
|
16
|
-
|
|
17
|
-
## 0. Using a style
|
|
18
|
-
A game keeps its style in its `style/` folder (`style/index.js`; a new game starts with an empty one). Any art
|
|
19
|
-
direction fits: realistic, toon, pixel, painterly, flat, noir. The engine ships none (section 1).
|
|
20
|
-
```js
|
|
21
|
-
import { createEngine, presets, openWorld } from 'threedog';
|
|
22
|
-
import style from './style/index.js'; // the game's own look
|
|
23
|
-
import { terrainPreset, terrainStrings } from '@threedog/terrain-noise'; // the world shape is not a look: its own package
|
|
24
|
-
const engine = createEngine({ canvas, style, strings: terrainStrings }); // terrainStrings: names of the preset's ground types
|
|
25
|
-
engine.use(openWorld({ camera: 'follow', seed: 7, terrain: terrainPreset() })); // noise terrain (hills, rivers, biomes) that your pack colors, see recipes/28
|
|
26
|
-
```
|
|
27
|
-
Procedural models are an asset pack, not part of the style (`engine.assets.manifest(assets)`; the world example keeps its in `examples/world/art/`). Post effects such as `bloom` / `ao` / `outline` come from
|
|
28
|
-
`@threedog/post-effects`. The terrain generator `terrainPreset` / `riverAt` / `BIOMES` /
|
|
29
|
-
`terrainStrings` is a separate package, `@threedog/terrain-noise`: the shape of the world is gameplay, so a style keeps only the colors of its
|
|
30
|
-
ground types (`terrain.colors`, `biomeColors`).
|
|
31
|
-
|
|
32
|
-
## 0b. Composing a style from parts
|
|
33
|
-
`style` may be a list of parts, deep-merged left to right into `engine.style`, so one pack's materials, another pack's sky and the game's own colors
|
|
34
|
-
mix without copying whole packs:
|
|
35
|
-
```js
|
|
36
|
-
import base from './style/index.js';
|
|
37
|
-
const dusk = { sky: { sunSize: 600, keyframes: myDuskKeyframes } }; // only these two sky fields change
|
|
38
|
-
const engine = createEngine({ canvas, style: [base, dusk, { ui: { accent: '#7fd3ff' }, post: null }] });
|
|
39
|
-
```
|
|
40
|
-
Rules (`core/styleParts.js`): plain `{ }` objects merge key by key at every depth; everything else replaces whole (arrays such as `sky.keyframes` and
|
|
41
|
-
`post`, functions, three.js objects); a key set to `null` removes it; `undefined` is ignored; nested lists flatten, so a pack can itself be a list of
|
|
42
|
-
parts; parts are never mutated. One object (not a list) is used as it is.
|
|
43
|
-
The merged style is the **style layer** of every look value (recipe 52 "How look values stack"): later parts win there and two parts never
|
|
44
|
-
conflict; a game's `look.<part>.set(...)` sits on top of it, and the weather and the sunset multiply whichever decides. A style starts the fog
|
|
45
|
-
distance (`sky.fog.far`) and the shadow filter (`sky.shadow.type`); there are no `createEngine` options for them.
|
|
46
|
-
|
|
47
|
-
**Post effects are plugins.** A style brings each post effect as a file in its `style/plugins/` folder (`10-bloom.js: export default bloom()`,
|
|
48
|
-
listed with `plugins: import.meta.glob('./plugins/*.js', { eager: true })`), the same file a game's `plugins/` folder takes: both go through
|
|
49
|
-
`engine.look.post.add`, the one way into the chain (recipe 52). Each part's plugins stay grouped under the part's name, so one pack's effect is
|
|
50
|
-
switched off with `engine.plugins.off('<pack>/<file>')` or `look.post.set({ bloom: false })`, and `plugins: null` drops the earlier parts' plugins.
|
|
51
|
-
There is no `style.post` list (it was a second way in, with its own on / off rules).
|
|
52
|
-
|
|
53
|
-
**Retinting the procedural models.** `style.palette` holds the colors the trees, rocks, grass and flowers are built from (the keys are the pack's own, e.g. `bark`, `leaf`, `rock`,
|
|
54
|
-
`grassTip`...; see `base.palette`). One part changes them all:
|
|
55
|
-
`style: [base, { palette: { leaf: 0xd98a3a } }]` (autumn); keys left out keep the base colors. A generator of your own written
|
|
56
|
-
with `function` (not an arrow) reads `this.palette`; the palette is part of the model cache key, so a changed palette rebuilds. `.glb` files and
|
|
57
|
-
models baked earlier keep their colors.
|
|
58
|
-
|
|
59
|
-
## 0c. What a style may not hold
|
|
60
|
-
Swapping the style must never change the map or the rules, only how they look. So these are **not** style fields, and a dev run throws an error
|
|
61
|
-
naming where each goes:
|
|
62
|
-
- water level, whether there is a sea, the water mesh size: `style.water.level / sea / size` -> `engine.use(water({ level, sea, size }))`.
|
|
63
|
-
The other way round, a look value is never a module option: water color, waves, normal map (`style.water.*`), sky keyframes, sun, moon, stars
|
|
64
|
-
(`style.sky.*`) and terrain `normals` (`style.terrain.config.normals`) are set in the style, and at run time with `engine.look.water` /
|
|
65
|
-
`look.sky` / `look.ground` `.set(...)`; `water({ color })`, `sky({ moonSize })`, `terrain({ normals })` throw naming that call
|
|
66
|
-
- terrain shape and size (seed, chunk size, resolution, water level, height functions): `style.terrain.config.*` -> `terrain({ ... })`. The looks
|
|
67
|
-
in `terrain.config` are `shading` (`'smooth'` | `'texture'` | `'flat'`), `colorResolution`, `normals` and `normalFn` (recipe 37); at run time
|
|
68
|
-
`engine.look.ground.set({ shading, colors, variation, detail })` (recipe 52)
|
|
69
|
-
Quality settings are not world state and may stay in a style (shadow `mapSize` and `low` overrides, water `segments`); players can override them in
|
|
70
|
-
settings. A game's `style/` folder is also checked by `threedog check` (R34).
|
|
71
|
-
|
|
72
|
-
## 0d. Look plugins in a style folder
|
|
73
|
-
One folder = one style: starting values, the material per role, and optional look plugins. A plugin is a file exporting the same shapes as the
|
|
74
|
-
game's `plugins/` folder (recipe 40 §1): a three.js `Pass`, a `Material` (its `name` is the role), a material patch `{ slot, glsl, roles }` (plugged with `look.materials.add`),
|
|
75
|
-
an `Object3D`, or a look module (a sky or vegetation look with `replaces`). The style lists them in `plugins`, and the engine plugs them through
|
|
76
|
-
`engine.plugins`, the same loader as the game's folder, so a plugin file works alone in `plugins/` or inside any number of style folders unchanged:
|
|
77
|
-
```js
|
|
78
|
-
// style/index.js style/plugins/10-paper.js: export default new ShaderPass(PaperShader)
|
|
79
|
-
export default { // style/plugins/20-stone.js: export default Object.assign(new THREE.MeshToonMaterial({ color: 0x777777 }), { name: 'stone' })
|
|
80
|
-
name: 'ink', exposure: 1.1, materials: { wood: { type: 'lambert', color: 0x8a5a36 } },
|
|
81
|
-
plugins: import.meta.glob('./plugins/*.js', { eager: true }), // without Vite: { paper: { default: paperPass } }
|
|
82
|
-
};
|
|
83
|
-
```
|
|
84
|
-
They sit **under** the game: a style plugin's material and patch are on the style layer of `engine.look.materials`, so the game's
|
|
85
|
-
`look.materials.set / replace` and the game's own plugins win. Names are `<style>/<file>` (`ink/10-paper`); `engine.plugins.off('ink')` takes
|
|
86
|
-
all of the style's plugins out, `off('ink/10-paper')` one; `describe().slots` lists them with `style ink: plugins/...`. `off('ink')` turns off
|
|
87
|
-
the pack's **plugins only**: its starting values (`exposure`, `fog`, the `materials` table and the other fields of `style/index.js`) are the
|
|
88
|
-
style itself and stay; the `off()` result and the off rows of `describe().slots` say so. To drop those too, start with another style.
|
|
89
|
-
Each plugin is its own owner (`style:ink/10-paper`), the pack only groups them: switching one off takes out only what that file wrote, and
|
|
90
|
-
the others keep theirs. Two plugins that write the same key on the same layer (two Materials named `stone`) are a `shared-conflict` naming
|
|
91
|
-
both files in development; to let one win on purpose, say so in that file: `export const replaces = '10-stone';` (the other is unplugged
|
|
92
|
-
while this one is on, and comes back when it goes off; `plugins.list()` shows `replacedBy`). In a list of parts each
|
|
93
|
-
part's plugins stay under that part's name, and `{ plugins: null }` drops the earlier parts'. The personal library (`threedog lib`) stores a
|
|
94
|
-
plugin once; `lib pull` puts its code in `plugins/<name>/` with the wiring file `plugins/<name>.js`, and copying both into a style folder's `plugins/` is all it takes to bundle it.
|
|
95
|
-
|
|
96
|
-
## 1. Creating a new style
|
|
97
|
-
Edit your game's `style/index.js` (`threedog new-game` makes it empty, every key commented out; fill one section at a time). To try a second look,
|
|
98
|
-
copy the folder (`style-toon/`) and point `createEngine` at it; `threedog style check style-toon` (a folder path; with no argument it checks the game's `style/`) finds mistakes before you look at pixels:
|
|
99
|
-
```js
|
|
100
|
-
import toon from './style-toon/index.js';
|
|
101
|
-
const engine = createEngine({ canvas, style: toon });
|
|
102
|
-
```
|
|
103
|
-
**A material role is a free label inside the style, not a fixed list.** `makeMaterial('anything', { color })` is always legal: a role the style does not
|
|
104
|
-
name falls back to `materials.default`, and a new role (`'lantern'`, `'roof'`) becomes real the moment the style adds `materials.lantern`. The engine
|
|
105
|
-
warns only when a name looks like a typo of a known role (`'buidling'`).
|
|
106
|
-
|
|
107
|
-
Keys you will change most often:
|
|
108
|
-
| Key | What it controls |
|
|
109
|
-
|---|---|
|
|
110
|
-
| `materials` | The material per role. Three forms: a spec `{ default: { type: 'toon', steps: 3 }, water: { type: 'phong', shininess: 90 } }` (lambert / phong / standard / physical / toon / basic; a wrong type throws), any three.js material instance `water: new THREE.MeshMatcapMaterial({ matcap })` (cloned per use), or a function `prop: (params, role) => new THREE.ShaderMaterial({...})`. The table is the style layer of `engine.look.materials`, the one entry `makeMaterial(role)` reads: the game changes a role with `look.materials.set / replace` (recipe 52), never by editing `engine.style.materials` |
|
|
111
|
-
| `antialias` | `false` for sharp pixel edges; omitted = on for desktop, off for phones (players can switch it in settings) |
|
|
112
|
-
| `post` | List of post effects (e.g. `[outline(), ao(), bloom()]`; `outline({ enabled: true })` draws edge lines); slots, the effects package, `fuse`, outline modes: [recipe 52](52-look.md#post-effect-chain) |
|
|
113
|
-
| `sky` `weather` `water` `terrain` `seasons` `clouds` | Sky keyframes (sun color and intensity over the day, fog color, shadows), rain and snow, water, terrain colors (`terrain.colors` palette, `terrain.biomeColors` ground type -> palette names, `terrain.steep` slope colors; a type with no color is gray; `terrain.config`: `shading` `'smooth'` (engine default) | `'texture'` (per-chunk color map) | `'flat'` (facets), `colorResolution`, `normals`, `normalFn`, recipe 37; `terrain.detail` a detail layer, recipe 53; `terrain.material` swaps the whole ground material, chunks have `uv` = world xz / chunk size; `water.material: (engine, { uniforms, waves, normalMap }) => Material` swaps the whole water surface, e.g. `applyEffects(new THREE.MeshToonMaterial({ color }), { clouds: false, patches: [waves] })` keeps the built-in waves), seasonal tints |
|
|
114
|
-
| `character` | `animation.fade`: skeletal animation transition seconds. Bodies are assets, not style: `createPlayer({ model })` with a registered model, a GLB asset name or `{ rig }`; part colors are material roles or `{ colors }` per character (recipe 13). Without a model a gray capsule |
|
|
115
|
-
| `pickup` `particles` | Items on the ground: look values only (`color`, `size`, `lift`; the shape is an asset model name, recipe 03), particle presets (dust smoke leaves splash sparks...) |
|
|
116
|
-
| `triggers` `grid` | Tool colors, not art: trigger zone wireframe (`debugColor`), grid placement preview (`ok` / `bad`). The engine has neutral defaults (gray; light = can place, dark = cannot); a pack may recolor them |
|
|
117
|
-
| `ui` | UI colors, `font` (a CSS font-family list), `fonts` (font asset names to load at start, the files in an asset pack: recipes/05 §3b), extra `css`, `templates` that replace a whole UI piece |
|
|
118
|
-
|
|
119
|
-
## 1b. Lights and stalls
|
|
120
|
-
Every engine has `engine.lights = { sun, hemi }`, plain three.js lights. Without a style they are a neutral placeholder (white
|
|
121
|
-
hemisphere + neutral directional light, no shadows); the look (sun color and intensity curves, sky colors, fog, shadow softness, exposure, tone
|
|
122
|
-
mapping) comes from the style's `sky`, `exposure` and `toneMapping`, and the sky module drives the same two lights. At run time:
|
|
123
|
-
`engine.look.lights.set(...)` (recipe 52); to light the world yourself: recipe 38. `toneMapping` is read once, when the engine creates its
|
|
124
|
-
renderer; later the curve is plain three.js (`engine.renderer.toneMapping = ...`).
|
|
125
|
-
|
|
126
|
-
three.js builds one shader program per material for each light setup. `engine.start()` compiles everything visible behind the
|
|
127
|
-
loading screen (`engine.startup.compileMs`), but adding or removing a light later, or toggling `visible` on one, changes the setup and compiles again:
|
|
128
|
-
a frame can freeze for hundreds of milliseconds. Keep the number of lights fixed: create them up front and fade with `intensity` (0 = off, no
|
|
129
|
-
recompile). In dev the console warns (code `light-recompile`) when programs were compiled in a frame where the lights changed.
|
|
130
|
-
|
|
131
|
-
For many torches, street lamps, campfires, muzzle flashes or neon signs use the light pool: a fixed number of real lights, created once at install,
|
|
132
|
-
moves to the sources that matter most (near the camera, bright, high `priority`) and fades with intensity, so the light setup never changes. Install
|
|
133
|
-
it before `engine.start()` so the startup compile covers its lights:
|
|
134
|
-
```js
|
|
135
|
-
import { lightPool } from 'threedog';
|
|
136
|
-
engine.use(lightPool({ point: 8 })); // 8 PointLights; lightPool({ spot: 2, shadows: 1 }) adds spots / lets one point light cast
|
|
137
|
-
for (const t of torches) engine.lightPool.add(t, { // an Object3D is followed; a position stays put
|
|
138
|
-
color: 0xffa040, intensity: 4, distance: 8,
|
|
139
|
-
flicker: (time, i) => 0.85 + 0.15 * Math.sin(time * 13 + i),
|
|
140
|
-
glow: t.getObjectByName('halo'), // stand-in while it has no real light: its material's opacity / emissiveIntensity fades to 0 as the light fades in
|
|
141
|
-
});
|
|
142
|
-
const flash = engine.lightPool.add(gun.muzzle, { intensity: 0, priority: 5, distance: 6 });
|
|
143
|
-
flash.set({ intensity: 8 }); /* next frame */ flash.set({ intensity: 0 }); // muzzle flash: no light is created
|
|
144
|
-
```
|
|
145
|
-
`engine.lightPool.usage()` (and `describe().lightPool`) lists which source each real light holds; `focus` measures from the player instead of the
|
|
146
|
-
camera. Options and handle: `../api/lightPool.md`. Windows and signs that light up at night (many materials, no real light each):
|
|
147
|
-
`engine.look.materials.glow('window', { night: 2 })` (recipe 52 "Night glow").
|
|
148
|
-
|
|
149
|
-
Top-down or side-view games whose light should spread over the floor and stop at walls (soft shadows, any number or shape of emissive
|
|
150
|
-
lights) can copy the optional 2D radiance cascades example instead: `examples/rc2d/` (README there: when it fits, cost, limits). It is not a module.
|
|
151
|
-
|
|
152
|
-
## 2. Using your own models instead of procedural ones
|
|
153
|
-
Models are assets, not style keys: content names them, an asset pack maps the names to files or generators. Register a later manifest with the same
|
|
154
|
-
name to swap one:
|
|
155
|
-
```js
|
|
156
|
-
engine.assets.manifest(yourAssets); // assets from an asset pack you have: trees, rocks, flowers... built in code
|
|
157
|
-
engine.assets.manifest({ name: 'mine', models: { pine: () => myPineGeometry(), well: '/models/well.glb' } }); // replaces pine, adds well
|
|
158
|
-
```
|
|
159
|
-
Vegetation takes a geometry (`geometry: await engine.assets.geometry('pine')`, the first mesh in the model) or a whole model with one material per
|
|
160
|
-
mesh, e.g. bark trunk + alpha-cut leaf cards:
|
|
161
|
-
`engine.vegetation.define('oak', { model: await engine.assets.model('oak'), wind: 0.02 })` (still one draw call per part; felling hides every part). For
|
|
162
|
-
the import workflow see `10-blender-level.md`.
|
|
163
|
-
`mergeColored(parts, { flat: false })` keeps smooth normals; UVs survive when every part has them.
|
|
164
|
-
A generator in `models` may also return an Object3D with its own materials; those are used as they are.
|
|
165
|
-
|
|
166
|
-
### 2a. Reusing art from somewhere else: copy it in, do not depend on it
|
|
167
|
-
Art code you already have (generator modules such as `art/my-crate.js` from an earlier game, a folder of your own, files someone gave you, a package
|
|
168
|
-
you installed) is reused by **copying** it into this game. The copy is the game's own: edit it freely; nothing links back and nothing updates it.
|
|
169
|
-
```sh
|
|
170
|
-
threedog art list ../earlier-game # modules, exported functions with their first JSDoc line, asset files (uses its art/ folder)
|
|
171
|
-
threedog art copy ../earlier-game crate lamp # by file or function name; none = every module
|
|
172
|
-
threedog art copy ../earlier-game crate --dry # what would be written, nothing written
|
|
173
|
-
```
|
|
174
|
-
It copies the named modules, every local file they import and every texture / model file they name ('./wood.png', `new URL(...)`, '/models/x.glb'
|
|
175
|
-
from the source's `public/`), rewrites relative import paths to the new layout (outside-the-art-folder helpers land in `art/shared/`), keeps package
|
|
176
|
-
imports and lists them, and prints the `engine.assets.manifest` lines to register the generators. An existing file with different content stops the
|
|
177
|
-
whole copy (nothing written) unless `--force`. The engine ships no art library and names no source: which art to reuse is yours to choose.
|
|
178
|
-
GLB files from Blender are copied the same way and checked with recipe 46 section 3.
|
|
179
|
-
|
|
180
|
-
## 2b. Wind, cloud shadows and season tint on your own materials
|
|
181
|
-
The engine's shader effects are named patches that work on any material that has the usual three.js chunks (WebGL only):
|
|
182
|
-
```js
|
|
183
|
-
import { applyEffects } from 'threedog';
|
|
184
|
-
const leaves = applyEffects(new THREE.MeshToonMaterial({ color: 0x5a8a3a }), { wind: 0.03, season: 'foliage' }); // clouds default on
|
|
185
|
-
engine.vegetation.define('bush', { geometry, material: leaves }); // vegetation adds them itself; effects: false keeps the material untouched
|
|
186
|
-
```
|
|
187
|
-
The shadow sways with the wind automatically. Your own effect (pixel snapping, dissolve...) is a patch too, and stacks with the built-in ones and with
|
|
188
|
-
the material's own `onBeforeCompile`:
|
|
189
|
-
`applyEffects(mat, { patches:
|
|
190
|
-
[{ name: 'snap', cacheKey: 64, uniforms, glsl: { vertex: { pars: '...', project_vertex: '...code after #include <project_vertex>' } } }] })`.
|
|
191
|
-
A missing `#include` anchor throws. A hand-written `ShaderMaterial` can `#include <threedog_wind_vertex>`, `<threedog_clouds_pars_fragment>` etc. (see
|
|
192
|
-
`render/effects.js`) with `engine.uniforms` as its uniforms.
|
|
193
|
-
`material.clone()` does not carry patches (three's `Material.copy` skips `onBeforeCompile`): a pack's Material instance in `materials` is fine
|
|
194
|
-
(`makeMaterial` keeps its patches); when you clone one yourself, apply the effects to the clone again.
|
|
195
|
-
What a patch declares (`needs`, `conflicts`, `shadow`, `cacheKey`) and the chunk names: recipe 43, "Patch a slot". Textures by asset name are
|
|
196
|
-
material spec keys (recipe 48); the engine GLSL functions you can call in your own shader, and the spec keys that wire some of them in as a shortcut: recipe 43.
|
|
197
|
-
|
|
198
|
-
## 3. When the engine gets a new "look parameter"
|
|
199
|
-
Hard rule 1: a module only writes a neutral gray fallback and reads `engine.style.xxx ?? fallback`, **and the real value is added to a style
|
|
200
|
-
(its `index.js`) at the same time** (with a one-line comment saying what it means),
|
|
201
|
-
and the new field gets a doc comment in `types/style.d.ts` (`docs/api/` is generated from there). Materials always go through
|
|
202
|
-
`makeMaterial('role', { color })`, leaving the surface feel to the role in `engine.look.materials` (the style's `materials` table is its style layer). Whose style: `engine.makeMaterial('role', { color })` uses that
|
|
203
|
-
engine's pack; the free `makeMaterial()` uses the first engine created (fine for one engine, a dev warning when two packs run). Engine code and styles always
|
|
204
|
-
go through the engine (`water.material(engine, ...)`, a generator's `this.engine`), so two engines never share materials.
|
|
205
|
-
Look parameters only: a field that changes the world (a level, a size, a seed) goes to the module's options, not the style (section 0c).
|
|
206
|
-
|
|
207
|
-
## 4. Verify
|
|
208
|
-
- `npm run check`: R14 reports "creates a material directly" in engine code (games, examples and styles are plain three.js and not checked) and R39
|
|
209
|
-
"non-gray fallback color"; the type check catches misspelled keys in the style.
|
|
210
|
-
- `npm run map`: the "style keys" table in CODEMAP is updated.
|
|
211
|
-
- Take screenshots only when the look changed, and compare two times of day: `npm run shot -- / --time 12:00`, `npm run shot -- / --time 18:30`
|
|
212
|
-
(images go to .threedog/shots/).
|
|
213
|
-
- It must still run without a style: start once with `createEngine({ canvas })` and no `style` (gray placeholders, one console note per missing piece).
|
|
214
|
-
|
|
215
|
-
## 5. Sounds and music (the game's, not the style's)
|
|
216
|
-
Sounds are game config, passed to `createEngine({ audio: { sounds, ambience, music, footsteps, levels } })` and read back as `engine.audio.config`; a
|
|
217
|
-
style carries none. The engine plays nothing the game did not name. Buses, sounds by name, the ambience rule table, music rules, footsteps and
|
|
218
|
-
ducking: `recipes/31-audio.md`.
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
# Making a new look from a reference picture
|
|
2
|
-
|
|
3
|
-
**In this recipe**: The loop · What a style can change, and what it cannot · Steps · Look check after every shot · Look questions · Guard rails ·
|
|
4
|
-
The style test page
|
|
5
|
-
|
|
6
|
-
No reference picture? Skip the measuring (step 2, `style palette`, `style compare` against a reference); judge each shot against DESIGN.md and
|
|
7
|
-
its "Loved / Not for this game" list, and use the rest: the loop, `style check`, the look check after every shot and the look questions.
|
|
8
|
-
|
|
9
|
-
For an AI that is given one picture ("make it look like this") and has to turn it into a style. The tools keep the work measurable: `threedog style palette`
|
|
10
|
-
and `style compare` measure pictures, your game's `style/index.js` holds the result, `threedog style check` finds mistakes before you look at pixels. They never say which
|
|
11
|
-
colors are right; the taste is yours. What a style is and the composing rules are in `09-style.md`; this page is the order of work.
|
|
12
|
-
|
|
13
|
-
## The loop (every round, in this order)
|
|
14
|
-
Looping "edit, screenshot, read the image" costs the most tokens and fixes the least. Numbers come first, pictures last.
|
|
15
|
-
1. **Measure the reference once** (step 2 below): `style palette <ref> --average`, then `style compare <ref> <your shot>`. Break the picture into
|
|
16
|
-
techniques (shading, one texture language, palette, edges) before choosing values.
|
|
17
|
-
2. **Change one family of values** (colors, then materials, then post). Art code hot-swaps on save. After writing or changing a model, look at it alone
|
|
18
|
-
first: `threedog gallery --shots` (every model under three lights, `.threedog/gallery/index.html`) shows wrong scale, wrong facing, holes and missing
|
|
19
|
-
faces before the level hides them.
|
|
20
|
-
3. **Shoot small and compare to the previous shot**: `threedog shot styletest --view overview --size 480x270 --keep --compare <previous.png>`. It prints the
|
|
21
|
-
pixel diff and the look differences. Through MCP the `snap` tool is 480 px wide by default; `style_compare` gives the numbers.
|
|
22
|
-
4. **Read the numbers first, then at most one image per round.** Name the biggest remaining difference and fix only that. `style compare <ref> <shot>
|
|
23
|
-
--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
|
|
24
|
-
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
|
|
25
|
-
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),
|
|
26
|
-
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
|
|
27
|
-
STATUS.md with why it stays. Before calling a look done, go through the "Look questions" below that matter for this game.
|
|
28
|
-
5. **Wrong in a way the numbers do not explain?** Diagnose before guessing: `engine.debug.view('albedo' | 'lighting' | 'shadow' | 'normals')` shows which
|
|
29
|
-
layer is off, `engine.describe().look` shows who set each value and where (recipe 52). Nothing drawn: `threedog scene --hidden` (reasons per mesh).
|
|
30
|
-
Washed-out or too-dark textures, odd normals: `threedog inspect materials` (wrong color spaces first, sizes, who made each material).
|
|
31
|
-
6. **If the biggest difference stops shrinking over a few rounds, change approach** (in this order) and tell the user which and why:
|
|
32
|
-
`look.surface.patch('detail' | 'lighting', glsl)` -> painted textures (`map`, `normalMap`) -> `look.materials.replace` -> plain three.js
|
|
33
|
-
(recipe 40 section 8). Never call it "close" to stop tuning.
|
|
34
|
-
7. **Every few rounds show the user the shot and the numbers.**
|
|
35
|
-
|
|
36
|
-
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
|
|
37
|
-
(soft edges, texture, low contrast), low-poly (few flat colors, faceted light), realistic (exposure, tone mapping, lighting, material roughness). None is the default.
|
|
38
|
-
|
|
39
|
-
## What a style can change, and what it cannot
|
|
40
|
-
Can change (all in the style): colors (`palette`, `terrain.colors`, `background`, `water.color`, season tints), material types per role
|
|
41
|
-
(`materials`: matte `lambert`, `toon` bands, `standard`...), lights and sky (`sky.keyframes`, sun, clouds, shadows, `exposure`, `toneMapping`), post
|
|
42
|
-
effects (`post`: outline, bloom, grain, vignette, color grading from `@threedog/post-effects`), UI colors and fonts, particle looks, and the colors
|
|
43
|
-
of the procedural models (`palette` read by `models.js`).
|
|
44
|
-
|
|
45
|
-
Cannot change by a style: the **silhouette of models**. A tree stays the shape its model has; a new shape means a new asset pack (code-built models
|
|
46
|
-
in `models.js`, or `.glb` files, recipes `05-props-bake.md` and `10-blender-level.md`). And the **world rules**: water level, terrain shape, what
|
|
47
|
-
exists where, timing and gameplay are not in a style (a dev run throws, `style check` and R34 report it). If the reference shows a different
|
|
48
|
-
world (a canyon instead of hills), say so instead of faking it with colors.
|
|
49
|
-
|
|
50
|
-
## Steps
|
|
51
|
-
1. **Keep the picture.** Put it in the game's `art/reference/` (one file per look, with a few lines of notes beside it on what to copy:
|
|
52
|
-
palette, mood, line work, light direction). Use the highest-resolution picture you have: a small or compressed one gives wrong detail and brightness numbers.
|
|
53
|
-
2. **Measure it.** `threedog style palette art/reference/ref.png --n 8 --average` (MCP: `style_palette`) prints the colors (`--json`: JSON only) with share, hue, saturation,
|
|
54
|
-
brightness, and role hints: largest block = ground / environment candidate, brightest = highlight / sky candidate, most saturated = accent candidate,
|
|
55
|
-
darkest = shadow or outline candidate, and one summary line such as `warm colors, mostly sand, low saturation, medium brightness, weak light/dark contrast`.
|
|
56
|
-
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
|
|
57
|
-
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.
|
|
58
|
-
3. **Open the style.** Edit your game's `style/index.js` (a new game has one with every key commented out, so the engine shows gray placeholders).
|
|
59
|
-
It is already passed in: `import style from './style/index.js'`, `createEngine({ canvas, style })`. Procedural models the look needs go in the same
|
|
60
|
-
folder (`style/models.js`, registered with `engine.assets.manifest({ name: 'mygame', models })`).
|
|
61
|
-
To start from another pack's strengths instead, compose: `style: [basePack, style]` (later parts win key by key).
|
|
62
|
-
4. **Fill it in, in this order** (each step changes the picture most for the least work): `sky` and `background` (light and mood), `exposure` and
|
|
63
|
-
`toneMapping`, `palette` and `terrain.colors` / `biomeColors` (the measured colors, snapped to a few named ones; a reference usually has 5 to 8 that
|
|
64
|
-
matter), `materials` (`lambert` matte, `toon` banded, `phong` shiny, `standard` PBR, `basic` unlit), `post`, then `ui`. The first frame should already be close:
|
|
65
|
-
if it is far from the reference, fix sky, exposure, palette and material type before adding anything.
|
|
66
|
-
5. **Check.** `threedog style check` (the game's `style/` folder; or give a folder, a file or a game name). It checks the final merged style, not each part:
|
|
67
|
-
unknown fields (with "did you mean"), world-state fields, palette keys a model reads but the style does not define, color formats (`'ff8800'`
|
|
68
|
-
without `#`, a float, a string `'0xff8800'`), post-effect conflicts (same name twice, two `scene` effects, a depth reader after a buffer-swapping
|
|
69
|
-
effect, `dof` ordered after `outline`), misspelled material roles and types, and asset names the pack does not register. `--json` gives the same list for
|
|
70
|
-
tools, `--assets file.js` adds another pack's names. Exit code 1 on errors. It is static: it cannot prove a pack holds no gameplay logic, only
|
|
71
|
-
the patterns R34 can see (`npm run check` runs R34).
|
|
72
|
-
6. **Look: the loop above.** Take pictures with the same arguments every round so only the style differs, and use the style test page's named camera
|
|
73
|
-
views (below), not free `--pos` shots. `threedog style compare art/reference/ref.png .threedog/shots/styletest.png [--region x,y,w,h]` prints brightness,
|
|
74
|
-
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
|
|
75
|
-
deliberately no "similarity %": the numbers turn "looks dirty / fragmented / too dark" into something you can change and re-measure. Dirty = lower
|
|
76
|
-
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
|
|
77
|
-
the reference and the picture looks better. A phone UI frame in the screenshot skews the numbers: compare a `--region`.
|
|
78
|
-
Add `--out side.png` (MCP `style_compare` always writes `<shot>.compare.png`) and open that one image: reference left, screenshot right; look at both.
|
|
79
|
-
7. **Stop** when the biggest remaining difference is a silhouette or a world rule: that is the asset pack or the game, not the style.
|
|
80
|
-
|
|
81
|
-
## Look check after every shot
|
|
82
|
-
Every `threedog shot` prints look numbers and hints (`--no-look` skips them). The numbers are luminance, contrast (std and p5-p95 range of
|
|
83
|
-
luminance), saturation, clipped and near-black shares, and the shadow area. Hints come in two kinds:
|
|
84
|
-
- **Contradictions**, whatever the style: the settings say one thing and the pixels another. Shadows on but none measurable (with the cause it found:
|
|
85
|
-
`look.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
|
|
86
|
-
no pixel.
|
|
87
|
-
- **Facts**: measured, maybe wanted, with what sets them: glare, large clipped or near-black areas, a night that is not dark from lighting (and
|
|
88
|
-
whether the brightness at 00:00 is lighting at all), the key / fill balance. Each becomes a contradiction only where DESIGN.md declares the
|
|
89
|
-
opposite.
|
|
90
|
-
- **Intent**, only against what the game declared: DESIGN.md's optional `Look intent:` line (listed words such as `no-glare`, `dark-nights`,
|
|
91
|
-
`strong-light`, `muted`; the template lists them all; the table's free text is not read), or the reference given with `--ref`. A muted,
|
|
92
|
-
low-contrast game is told when its shot measures saturated and contrasty, never the other way round unless it said so. No declaration and
|
|
93
|
-
no reference: numbers only, no judgement.
|
|
94
|
-
|
|
95
|
-
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
|
|
96
|
-
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.
|
|
97
|
-
|
|
98
|
-
## Look questions
|
|
99
|
-
Pick the ones that matter for this game, before calling a look done and when a round stalls. They name what to look at, not which answer is
|
|
100
|
-
right for a given art direction.
|
|
101
|
-
- **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?
|
|
102
|
-
`debug.view('lighting')`.
|
|
103
|
-
- **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
|
|
104
|
-
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
|
|
105
|
-
`look.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
|
|
106
|
-
only hemi + environment, so their sum against the sun sets the contrast; small casters blur when the shadow box is much bigger than the
|
|
107
|
-
scene (texel size: recipe 52, "Atmosphere parts"); a compact scene fits it, for example `look.shadow.set({ extent: 30 })`.
|
|
108
|
-
- **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
|
|
109
|
-
too? A PBR material that stays bright at night is usually lit by an environment map that does not follow the time (`describe().look.env.source`
|
|
110
|
-
says which map lights it and whether it follows).
|
|
111
|
-
- **Material response**: do surfaces that should differ (wood, stone, metal, cloth, skin, water) differ in roughness, specular and color, not only hue?
|
|
112
|
-
A plastic-looking surface is a shading problem, not a color problem.
|
|
113
|
-
Metals have something to reflect (environment). A glossy flat decal (puddle, spill, polished floor) reflects only the environment map, never the
|
|
114
|
-
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
|
|
115
|
-
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.
|
|
116
|
-
- **Texture scale and detail**: is texel density similar across neighbors, no obvious tiling at the usual camera distance, detail matching how close the
|
|
117
|
-
camera gets? Color spaces right (`inspect materials`).
|
|
118
|
-
- **Color and grading**: value range (darkest / brightest), saturation and the overall hue shift match the reference (`style compare`); exposure and
|
|
119
|
-
tone mapping chosen, not left at whatever was there.
|
|
120
|
-
- **Atmosphere and depth**: fog, haze or color shift with distance as the reference shows; the background separates from the play space.
|
|
121
|
-
- **Readability of gameplay elements**: the player, interactables, hazards and pickups stand out by value or color from the ground at play distance and
|
|
122
|
-
under every time of day / weather the game uses (shoot them at dusk and in rain too).
|
|
123
|
-
- **Consistency**: does any asset step out of the overall style (outline weight, shading model, texture language) where DESIGN.md did not
|
|
124
|
-
intend it? A deliberate mix of styles is a choice, not a mistake.
|
|
125
|
-
|
|
126
|
-
## Guard rails
|
|
127
|
-
- 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
|
|
128
|
-
measure again after each one; `style check` lists which are on and how to see what each costs.
|
|
129
|
-
- Never put gameplay or world values in the pack to match a picture; `style check` reports them as errors.
|
|
130
|
-
- Fonts and textures are asset-pack entries; the style names them (`ui.fonts: ['pixel']`, `terrain.detail.texture`), it does not carry files.
|
|
131
|
-
- Keep `npm run check` at 0 errors; a new pack adds no warnings.
|
|
132
|
-
|
|
133
|
-
## The style test page
|
|
134
|
-
`/styletest.html` (`examples/styletest`) is the one fixed scene a style is judged by: a character, trees, rock, grass, flowers, water, terrain, glass,
|
|
135
|
-
a shadow receiver, wood / stone / metal surfaces, a lit room (outside and inside) and the UI parts. Same arguments, same picture, so only the style differs.
|
|
136
|
-
- `threedog shot styletest --view <name> [--time day|dusk|night] [--weather clear|rain|snow]`; the same words work as URL parameters
|
|
137
|
-
(`?view=room&time=dusk&weather=rain`; also `style=none` for the engine's gray placeholders, `env=1` for environment lighting from the sky).
|
|
138
|
-
- Views: `overview` (everything: overall brightness, ground color, shadow darkness), `character` (close-up: character colors, outline, shadow on
|
|
139
|
-
the ground), `water` (water color, shore, fog at distance), `room` (the lamp and window light against the dark corners: ambient level, `ao`, bloom),
|
|
140
|
-
`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
|
|
141
|
-
and shadow edges that flicker or crawl), `ui` (HUD, dialogue line, bag window: the `ui` colors).
|
|
142
|
-
- Per round: shoot `overview`, `room` at `--time dusk`, and `character`.
|
|
143
|
-
- The dev panel (workbench + tune), in any game: `if (location.search.includes('panel=1')) import('@threedog/tools/panel').then(m => m.openPanel(engine));`
|
|
144
|
-
It needs the optional dev package `tweakpane` (`npm install -D tweakpane`; the repository's `npm install` has it); without it the page says so.
|
|
145
|
-
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.
|
|
146
|
-
`/styletest.html?panel=1` opens it on the style test, which also passes `{ overrides }` (its `?ov=` style part) for "apply and rebuild".
|
|
147
|
-
Live sliders change exposure, sky time, environment lighting, water color, post effects and UI colors at once; palette, terrain and wave values
|
|
148
|
-
are marked "needs rebuild" and only apply after "apply and rebuild". "export overrides" prints an object literal to paste into
|
|
149
|
-
`style: [yourPack, { ... }]`; the original pack is never written, so the paste is the one place the change becomes real.
|
|
150
|
-
The "tune" folder drags any look part value (`engine.look.<part>.set`), a material picked by name (color, roughness, metalness, emissive...) and
|
|
151
|
-
numeric `engine.uniforms`. "write back" saves them (with the style changes) to `.threedog/tune.json` on the dev server; then
|
|
152
|
-
`threedog tune write <file>` prints the code change as a diff (one `// threedog:tune begin ... end` block of plain calls) and `--apply` writes it.
|
|
153
|
-
Review it, then keep the block or move each value where it belongs (the pack, the material's definition).
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# Sky, ground and plant looks: what a style can change
|
|
2
|
-
|
|
3
|
-
For an AI turning a reference picture into a style and hitting "the engine draws it this way". Colors and materials are in `09-style.md`, the
|
|
4
|
-
order of work in `35-style-from-reference.md`. This page lists the places where the *shape* of a look was fixed in engine code and is now a style
|
|
5
|
-
setting. Each table lists the engine default; a style that sets nothing here gets those defaults. Styles hold looks only
|
|
6
|
-
(rule R34): none of these settings move a hill, a river or a species list.
|
|
7
|
-
|
|
8
|
-
## Sky clouds: `style.sky.clouds` (at run time `engine.look.sky.set({ clouds: { coverage, color } })`; not a `sky()` option)
|
|
9
|
-
| Key | Meaning | Default |
|
|
10
|
-
|---|---|---|
|
|
11
|
-
| `color`, `shade`, `coverage`, `scale`, `speed` | lit color, shaded color, cover (multiplies the weather's cloud amount), size, drift speed | |
|
|
12
|
-
| `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'` |
|
|
13
|
-
| `horizon` | added to `dir.y` before projecting; smaller = clouds shrink and crowd more towards the horizon | plane 0.08, cumulus 0.5 |
|
|
14
|
-
| `fade` | `[from, to]` in `dir.y`: invisible below `from`, full above `to` | plane `[0, 0.18]`, cumulus `[0, 0.12]` |
|
|
15
|
-
| `opacity`, `softness` | cloud alpha; width of the cloud edge | 0.9 / 0.3 (cumulus 0.95 / 0.35) |
|
|
16
|
-
| `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 |
|
|
17
|
-
| `relief` | cumulus only: contrast of the sun-side light | 5 |
|
|
18
|
-
|
|
19
|
-
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
|
|
20
|
-
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
|
|
21
|
-
`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
|
|
22
|
-
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
|
|
23
|
-
(`style.clouds.shadow`, a separate setting) follow the same weather cover, so more clouds still means more shadow.
|
|
24
|
-
|
|
25
|
-
```js fragment
|
|
26
|
-
sky: { clouds: { kind: 'cumulus', coverage: 1, scale: 0.45, color: 0xfff4e4, shade: 0x8a9cb8, speed: [0.003, 0.001] } }
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Your own cloud function
|
|
30
|
-
`engine.look.sky.patch('clouds', glsl | { glsl, uniforms })` is the one way in (a `glsl` key in `style.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)`:
|
|
31
|
-
```glsl
|
|
32
|
-
vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover)
|
|
33
|
-
// dir: unit view direction, dir.y > 0. sunDir: towards the sun (the moon is opposite). night: 0 day .. 1 night.
|
|
34
|
-
// lit / shade: clouds.color / clouds.shade. cover: weather cloud amount * clouds.coverage.
|
|
35
|
-
// return: rgb = final cloud color (dim it at night yourself), a = opacity (apply your own horizon fade).
|
|
36
|
-
```
|
|
37
|
-
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
|
|
38
|
-
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
|
|
39
|
-
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.
|
|
40
|
-
Flat painted cloud blobs with a hard edge, multiplied by a texture:
|
|
41
|
-
```js
|
|
42
|
-
// style: clouds: { color: 0xfff1dc, shade: 0x9aa8c4 }; the function goes through the hook
|
|
43
|
-
engine.look.sky.patch('clouds', { uniforms: { uPaper: paperTexture, uEdge: 0.06 }, // paperTexture: any THREE.Texture, repeat wrapping
|
|
44
|
-
glsl: `vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover){
|
|
45
|
-
vec2 p = d.xz / (d.y + 0.5) * 0.4 + vec2(0.004, 0.002) * time;
|
|
46
|
-
float n = threedogNoise(p) * 0.65 + threedogNoise(p * 2.3 + 5.0) * 0.35;
|
|
47
|
-
float a = smoothstep(1.0 - cover, 1.0 - cover + uEdge, n); // hard edge
|
|
48
|
-
float up = clamp(0.5 + (n - threedogNoise(p + sunDir.xz * 0.1)) * 6.0, 0.0, 1.0); // sun side
|
|
49
|
-
vec3 c = mix(shade, lit, up) * texture2D(uPaper, p * 3.0).rgb * (0.35 + 0.65 * (1.0 - night));
|
|
50
|
-
return vec4(c, a * smoothstep(0.0, 0.1, d.y));
|
|
51
|
-
}` });
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Ground color: `style.terrain.variation`
|
|
55
|
-
Terrain colors are baked by the (worker) generator from the palette: two palette colors blended by a noise, a small brightness grain, and an
|
|
56
|
-
optional layer of large patches. The defaults are shown (plain data, so it travels to the workers; unknown keys throw):
|
|
57
|
-
```js fragment
|
|
58
|
-
terrain: { colors: { ... }, biomeColors: { ... },
|
|
59
|
-
variation: {
|
|
60
|
-
blend: { size: 33, strength: 1 }, // wavelength in m of the two-color noise; strength > 1 = harder contrast, < 1 = flatter
|
|
61
|
-
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)
|
|
62
|
-
patches: { size: 90, strength: 0.15, levels: 0, tint: 0xb59a5a }, // optional (example values): a second, large layer of color blocks
|
|
63
|
-
} }
|
|
64
|
-
```
|
|
65
|
-
`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
|
|
66
|
-
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
|
|
67
|
-
interpolate across a chunk cell (4 m at the default resolution), so blocks smaller than that blur; for crisp blocks use `shading: 'texture'`
|
|
68
|
-
(recipe 37) or a texture (next). Which combination fits which look, and ground that looks wrong up close: recipe 53.
|
|
69
|
-
|
|
70
|
-
### Your own ground material
|
|
71
|
-
`style.terrain.material` (a Material or `(engine) => Material`) replaces the ground material. Chunk geometry has `uv = world xz / chunk size`, continuous
|
|
72
|
-
across chunk borders (checked by `tests/specs/appearance.mjs`), so a repeating texture is seamless whatever chunk it lands in; cloud shadows and
|
|
73
|
-
season tint are added to your material. `texture.repeat.set(8, 8)` = 8 tiles per chunk. Without UVs (steep sides stretch a top-down map), project
|
|
74
|
-
from the world position in a patch instead (`needs.patches: ['world']` gives `vThreedogWorld`):
|
|
75
|
-
```js
|
|
76
|
-
material: engine => applyEffects(new THREE.MeshLambertMaterial({ vertexColors: true }), { clouds: false, patches: [{
|
|
77
|
-
name: 'triplanar', needs: { patches: ['world'] }, uniforms: { uTex: { value: groundTexture }, uTexScale: { value: 0.1 } }, // groundTexture: repeat wrapping
|
|
78
|
-
glsl: { fragment: { pars: 'uniform sampler2D uTex; uniform float uTexScale;',
|
|
79
|
-
color_fragment: `vec3 n = abs(normalize(cross(dFdx(vThreedogWorld), dFdy(vThreedogWorld)))); n /= n.x + n.y + n.z;
|
|
80
|
-
diffuseColor.rgb *= texture2D(uTex, vThreedogWorld.zy * uTexScale).rgb * n.x + texture2D(uTex, vThreedogWorld.xz * uTexScale).rgb * n.y
|
|
81
|
-
+ texture2D(uTex, vThreedogWorld.xy * uTexScale).rgb * n.z;` } } }] })
|
|
82
|
-
```
|
|
83
|
-
A procedural noise texture is a `THREE.DataTexture` filled in a loop (`wrapS = wrapT = THREE.RepeatWrapping`, `colorSpace = THREE.SRGBColorSpace`,
|
|
84
|
-
`needsUpdate = true`). The lighter alternative is a detail layer, `style.terrain.detail` / `look.ground.set({ detail })`: the same object as a
|
|
85
|
-
material spec's `detail` (`noise: 'grain' | 'paper' | 'stroke' | 'dabs'`, or `texture: 'name'`, or your own `glsl`; `scale`, `strength`, `fade`
|
|
86
|
-
...; keys in recipe 43), with no material of your own. Which to pick: recipe 53.
|
|
87
|
-
|
|
88
|
-
## Plants and wind
|
|
89
|
-
Audit of what the vegetation code fixes, split into mechanism (stays) and look (made a setting):
|
|
90
|
-
|
|
91
|
-
| Where | What | Kind |
|
|
92
|
-
|---|---|---|
|
|
93
|
-
| `Vegetation.define` | per species: `wind` amplitude, `rule`, `positions`, `densityMap`, `lodRing`, `maxRing`, `nearOnly`, `castShadow`, `shadowRing`, `material`, `effects` | already options (game content) |
|
|
94
|
-
| `GroundChunks`, `VegetationLook` (`modules/vegetation/look.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 look is replaceable: recipe 28 section 6) |
|
|
95
|
-
| 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 | look: **`engine.look.wind.patch('sway', glsl)`** replaces it |
|
|
96
|
-
| wind speed | `uWindFreq` | already `style.wind.frequency` |
|
|
97
|
-
| season tint | `diffuseColor.rgb *= tint` (default) or a blend towards the tint; colors from `style.seasons` | look, both settings: `style.seasons.mode: 'multiply' \| 'mix'` (+ `strength`); see recipe 43 |
|
|
98
|
-
| defaults | `castShadow` = not `nearOnly`, `shadowRing` 1, `lodRing` 1 | per-species options, set them in the species |
|
|
99
|
-
|
|
100
|
-
```js
|
|
101
|
-
engine.look.wind.patch('sway', { uniforms: { uSteps: 3 }, // stepped sway: plants snap between 3 poses instead of a smooth sine; before vegetation.define
|
|
102
|
-
glsl: `void threedogWind(inout vec3 transformed, vec3 ip, vec3 position){
|
|
103
|
-
float s = floor(sin(uTime * uWindFreq + ip.x * 0.3 + ip.z * 0.2) * uSteps) / uSteps;
|
|
104
|
-
transformed.x += s * max(position.y, 0.0) * THREEDOG_WIND_AMP * uWind;
|
|
105
|
-
}` });
|
|
106
|
-
```
|
|
107
|
-
`threedogWind` receives the vertex (`transformed`, object space), `ip` (world position of this plant's origin, so each plant has its own phase) and
|
|
108
|
-
`position`; `uTime`, `uWind` (weather), `uWindFreq` and `THREEDOG_WIND_AMP` (the species' amplitude) are in scope. It applies to every material made by
|
|
109
|
-
`vegetation.define` that has `wind` set, and the shadow sways with it. A missing function throws with the signature. The same object works in code:
|
|
110
|
-
`applyEffects(mat, { wind: { amplitude: 0.03, glsl, uniforms } })`.
|
|
111
|
-
|
|
112
|
-
Cost, measured with software rendering (relative numbers only): 10,000 grass blades of 6 triangles in one InstancedMesh draw in 1 call; per frame
|
|
113
|
-
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).
|
|
114
|
-
Reduce grass cost with `rule.perChunk`, `maxRing` and `nearOnly`, not the wind.
|
|
115
|
-
|
|
116
|
-
## What is still fixed
|
|
117
|
-
Season tint is multiplicative. Cloud *shadows* on the ground (`threedog_clouds_pars_fragment`) keep their two-noise shape; only strength, scale and
|
|
118
|
-
speed are style settings. Grass has no billboard or blade-shape setting: give `vegetation.define` your own `geometry` or `model`.
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# Owning lights, fog and exposure yourself
|
|
2
|
-
|
|
3
|
-
The normal way to change lights, fog, exposure and the sky is `engine.look.<part>.set` / `patch` ([recipe 52](52-look.md)): the sky keeps
|
|
4
|
-
driving them over the day, and your values sit on top. This page is the next step, for when that is not enough: your own fog math, exposure over
|
|
5
|
-
the day, extra sky layers, and taking a light or the fog away from the sky entirely. Sky basics are in `08-weather-sky.md`, clouds and ground color in
|
|
6
|
-
`36-sky-ground-plant-looks.md`, environment lighting in `34-environment-lighting.md`. Each section starts with the `look` call and ends with the exit.
|
|
7
|
-
|
|
8
|
-
```js
|
|
9
|
-
// 1. keyframes (default): style.sky.keyframes / style.exposure lists drive the day; nothing to write
|
|
10
|
-
// 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)
|
|
11
|
-
engine.look.fog.set({ color: ({ state }) => state.boss ? '#400' : 'horizon' }); engine.look.state({ boss: true });
|
|
12
|
-
// 3. your own three.js sky (three/addons Sky, a ShaderMaterial dome, a skybox): never written; time / weather keep flowing through engine.uniforms
|
|
13
|
-
engine.look.sky.replace(mySky); mySky.material.uniforms.sunPosition = engine.uniforms.uSunDir; // the same Vector3, refreshed every frame
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Lights: override, take over, or switch off
|
|
17
|
-
The engine has one directional light (`engine.lights.sun`; moonlight at night, the shadows live on it) and one hemisphere
|
|
18
|
-
ambient (`engine.lights.hemi`). The sky module rewrites their color and intensity every frame from `style.sky.keyframes`,
|
|
19
|
-
so editing the three.js objects directly is overwritten (a dev warning says so). **Without the sky module** both lights are a bright placeholder
|
|
20
|
-
(hemi 1.2, white sun 2 at (40, 80, 30), no shadows).
|
|
21
|
-
|
|
22
|
-
```js
|
|
23
|
-
engine.look.lights.set({ sun: { color: '#ffd0a0', intensity: 1.4 }, hemi: { intensity: 0.5 } }, { owner: 'dusk' }); // 1. override, any hour
|
|
24
|
-
engine.mod('look.lights.sun.intensity', { owner: 'cave', mul: 0.3 }); // or a multiplier on top of the day cycle (recipe 52)
|
|
25
|
-
|
|
26
|
-
engine.look.lights.manual(['sun.intensity', 'sun.color']); // 2. take over: the sky still aims the sun along the time of day and moves the shadow box
|
|
27
|
-
engine.lights.sun.color.set(0xffd0a0); engine.lights.sun.intensity = 1.4; // yours now, never overwritten
|
|
28
|
-
|
|
29
|
-
engine.use(sky({ sun: false, hemisphere: false })); // 3. switch off (a dungeon): both hidden, never touched; the dome still shows sun and moon
|
|
30
|
-
const torch = new THREE.PointLight(0xffa040, 6, 12); engine.add(torch); // add your own lights before engine.start()
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
- `sky({ sun, hemisphere })`: `true` (default) the sky drives everything; `false` `visible = false`, no shadows, never touched (lightning no
|
|
34
|
-
longer flashes the ambient either). Taking a value over is one call for every look value, `engine.look.<part>.manual(key)` (here
|
|
35
|
-
`look.lights.manual('sun' | 'hemi' | 'sun.intensity' ...)`), not a sky() option; `manual(key, false)` hands it back.
|
|
36
|
-
- `createEngine({ lights: false })` goes one step further: the default sun and hemisphere are never put in the scene, `engine.lights.sun` / `hemi`
|
|
37
|
-
stay as detached objects so nothing reads `undefined`. Use it for a scene lit entirely by your own lights.
|
|
38
|
-
- Shadows: only the engine sun's shadow is managed (`engine.look.shadow.set`). Your own `castShadow` lights work as in three.js, each costing its
|
|
39
|
-
own shadow pass; `look.shadow.set({ enabled: false })` turns theirs off too and restores them after.
|
|
40
|
-
- Add or remove lights before `engine.start()`: a light count that changes mid-play recompiles every material (one long frame). Many lamps or
|
|
41
|
-
torches: `lightPool({ point: 6 })` keeps a fixed number of real lights and moves them to the nearest sources (recipe 09, "Lights and stalls").
|
|
42
|
-
|
|
43
|
-
## Fog: kind, color, density, your own math, or your own fog
|
|
44
|
-
```js
|
|
45
|
-
engine.look.fog.set({ far: 220, color: '#9bb' }); // live: color, density, near, far, enabled, linear <-> exp2
|
|
46
|
-
engine.look.fog.set({ kind: 'height', height: 2, falloff: 0.08, density: 0.03 }); // valley mist; materials recompile once (below)
|
|
47
|
-
engine.look.fog.patch('fog', `vec4 threedogFog(vec3 c, float depth, vec3 p){
|
|
48
|
-
float f = 1.0 - exp(-fogDensity * depth);
|
|
49
|
-
return vec4(mix(c, vec3(1.0, 0.85, 0.7), f * 0.3), f); }`); // warm far haze
|
|
50
|
-
engine.look.fog.manual(); // the exit: the sky stops writing scene.fog (or assign your own: scene.fog = new THREE.Fog(...))
|
|
51
|
-
```
|
|
52
|
-
The same keys are the style layer `style.sky.fog` (or `sky({ fog })`), e.g. `fog: { kind: 'exp', color: 0xb8c4d0 }` or
|
|
53
|
-
`fog: { color: ({ sky }) => sky.isDay ? 0xc8d0d8 : 0x10141c }` (a function, evaluated each frame).
|
|
54
|
-
|
|
55
|
-
- `kind`: `'linear'` (default, near = 0.3 x far) | `'exp'` | `'exp2'` | `'height'`. `color`: `'horizon'` (default; the dome's lower band fades to
|
|
56
|
-
the fog color, so the horizon line never shows) | color | `({ time, weather, season, state, sky }) => color` (near / far / density take a function too). `density` per meter (default derived from the fog distance);
|
|
57
|
-
an explicit density is kept as given (weather multiplies `far`, which moves only the derived one).
|
|
58
|
-
- The `fog` hook replaces the fog math in every material, built-in or yours: `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)` returns
|
|
59
|
-
(fog rgb, amount 0..1). In scope: `fogColor`, `cameraPosition`, `fogNear` / `fogFar` (linear) or `fogDensity` (other kinds),
|
|
60
|
-
`THREEDOG_FOG_HEIGHT`, `THREEDOG_FOG_FALLOFF`.
|
|
61
|
-
- How: `'exp'`, `'height'` and the hook are one named shader patch, `fog`, on the semantic slots `fogPars` / `fog` (recipe 43), put on
|
|
62
|
-
every built-in material in this engine's scene (yours too: three's own fog would draw another curve; `describe().owned['fog.patch']` lists
|
|
63
|
-
them). Changing them later works and recompiles those materials once, so do it at a scene change, not every frame. Color and density stay live
|
|
64
|
-
uniforms. No custom uniforms (three copies fog uniforms into each material when it compiles); write constants. Materials with `fog: false`
|
|
65
|
-
(the dome) are not fogged. Your own ShaderMaterial and sprites keep three's plain fog.
|
|
66
|
-
- Your own fog is plain three.js: `scene.fog = new THREE.Fog(...)` (or `FogExp2`), and the engine stops writing it (there is no
|
|
67
|
-
`look.fog.replace`); `look.fog.manual()` keeps the engine's `scene.fog` and the sky never writes it again (set its color / near / far); `sky({ fog: false })` sets `scene.fog = null` (leave fog out of your materials with `fog: false` and fog in a
|
|
68
|
-
post pass).
|
|
69
|
-
- Two engines on one page each patch their own scene's materials, so they may use different fog kinds and hooks. Nothing rewrites
|
|
70
|
-
`THREE.ShaderChunk`; plain `linear` / `exp2` add no patch at all.
|
|
71
|
-
|
|
72
|
-
## Exposure over time, and the tone curve
|
|
73
|
-
```js
|
|
74
|
-
exposure: [[0, 1.6], [0.3, 1], [0.75, 1.1]] // style: per time of day (0-1), wraps across midnight
|
|
75
|
-
exposure: ({ sky }) => sky.isDay ? 1 : 1.5 // or a function, evaluated by the sky module every frame
|
|
76
|
-
engine.look.tone.set({ exposure: 1.3 }); // at run time: number, keyframes or function (replaces the style's)
|
|
77
|
-
engine.renderer.toneMapping = THREE.NeutralToneMapping; // the curve: plain three.js; materials recompile on their next draw
|
|
78
|
-
```
|
|
79
|
-
A plain number is set once (no per-frame work). Keyframes and functions need the sky module (it knows the time of day). The curve is written
|
|
80
|
-
once when the engine creates its renderer (`style.toneMapping`, else AgX) and never again, so a direct write stays.
|
|
81
|
-
|
|
82
|
-
## Extra sky layers: rainbow, aurora, color bands
|
|
83
|
-
`style.sky.layers` (at run time `engine.look.sky.patch('layer:aurora', { glsl, blend })`, recipe 52), drawn on the dome
|
|
84
|
-
after clouds and stars; none by default:
|
|
85
|
-
|
|
86
|
-
```js
|
|
87
|
-
layers: [{ blend: 'add', uniforms: { uAurora: [0.2, 1, 0.6] }, glsl: `vec4 threedogSkyLayer(vec3 d, float time, vec3 sunDir, float night){
|
|
88
|
-
float band = smoothstep(0.25, 0.45, d.y) * (1.0 - smoothstep(0.55, 0.8, d.y));
|
|
89
|
-
float n = threedogNoise(vec2(d.x * 4.0 + time * 0.05, d.z * 2.0));
|
|
90
|
-
return vec4(uAurora, band * n * night); }` }]
|
|
91
|
-
```
|
|
92
|
-
Signature `vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)` returns (rgb, amount). `blend: 'mix'` (default) or `'add'`;
|
|
93
|
-
`order` sorts layers (smaller first); `uniforms` like `clouds.uniforms`, live in `engine.sky.dome.material.uniforms.uAurora.value`. Each layer's function is
|
|
94
|
-
renamed (`threedogSkyLayer0`, `1`, ...), so layers from different style parts never clash. Whole replacement: `style.sky.skybox` (a panorama) or
|
|
95
|
-
hide `engine.sky.dome` and add your own background.
|
|
96
|
-
|
|
97
|
-
## Water and weather particles
|
|
98
|
-
Water depth color, crest foam, wave / surface GLSL, reflections; rain and snow shape, size, density and shaders, the lightning look, and
|
|
99
|
-
particles for the game's own weather (`engine.look.weather.replace`): `44-water-weather-look-hooks.md`.
|