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
|
@@ -53,8 +53,9 @@ vanish at that distance? Does anything flicker at seams when the camera moves?
|
|
|
53
53
|
- **Merged hero block**: a fixed set piece merged once for the fewest draws, when it never changes.
|
|
54
54
|
|
|
55
55
|
## The engine helper (optional convenience)
|
|
56
|
-
`kit.js` is the kit: modules, assembler, manifest entries; it imports only `three` and `three/addons`. `main.js` is the demo page
|
|
57
|
-
|
|
56
|
+
`kit.js` is the kit: modules, assembler, manifest entries; it imports only `three` and `three/addons`. `main.js` is the demo page and `picture/` its
|
|
57
|
+
picture in plain three.js (lights, tone curve, one Lambert material per slot, every value in `picture/palette.js`). The page builds the same seed
|
|
58
|
+
three ways (gray block-out, warm with soft cove trims, cool with hard stepped trims and faintly emissive frames; the two coloured
|
|
58
59
|
sets are demo values, not advice). In the kit, the block-out stage is `facade` strings of `.` (blank walls) and `roof`. A style is the slot
|
|
59
60
|
materials (`wall`, `trim`, `roof`, `frame`, `glass`, `accent`, `awning`, `sign`) plus `profiles` plus `windows`. The only textures are gray
|
|
60
61
|
masks (awning stripes, sign text) tinted by the slot material's colour, so a material swap recolours them too. `street` mirrors upper floors
|
|
@@ -111,7 +112,7 @@ Rules (correctness):
|
|
|
111
112
|
notice". Where pieces meet, either one covers the seam (corner pilasters cover the wall ends; front / back trims run past the corners,
|
|
112
113
|
side trims stop at the walls) or they are offset by a few millimetres (the sill top sits above the reveal floor).
|
|
113
114
|
- **Generators get every input from `params`.** The slot materials are live objects, so the kit's manifest entries are `cache: false`
|
|
114
|
-
(the dev cache would otherwise keep a model built with old materials). To bake a street,
|
|
115
|
+
(the dev cache would otherwise keep a model built with old materials). To bake a street, build the slot materials inside the
|
|
115
116
|
generator instead (recipe 05, section 2a) and drop `cache: false`.
|
|
116
117
|
|
|
117
118
|
Limits:
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Modular building kit (optional technique example, see README.md). Shapes only: every module is built from parameters and drawn with the
|
|
3
3
|
// game's own materials, one per slot (wall, trim, roof, frame, glass, accent, awning, sign). Imports only three and three/addons, so a game can
|
|
4
4
|
// copy the folder and change anything.
|
|
5
|
-
// The pieces are deliberately plain: they teach the method (grid, modules, variation, shared geometry), not a
|
|
5
|
+
// The pieces are deliberately plain: they teach the method (grid, modules, variation, shared geometry), not a picture.
|
|
6
6
|
import * as THREE from 'three';
|
|
7
7
|
import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js';
|
|
8
8
|
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
|
|
@@ -18,7 +18,7 @@ export const PROFILES = {
|
|
|
18
18
|
cove: [[0, 0], [0.35, 0], [0.5, 0.25], [0.75, 0.45], [1, 0.75], [1, 1], [0, 1]],
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
/** Window variants a street picks from: a few shared variants (not a random size per window) keep the
|
|
21
|
+
/** Window variants a street picks from: a few shared variants (not a random size per window) keep the picture designed and the geometry shared */
|
|
22
22
|
export const WINDOWS = [
|
|
23
23
|
{ width: 0.9, height: 1.4, sill: 0.9, mullions: 1, planter: false },
|
|
24
24
|
{ width: 1.1, height: 1.5, sill: 0.8, mullions: 2, planter: true },
|
|
@@ -2,32 +2,24 @@
|
|
|
2
2
|
// Modular building demo (page /modular-building.html): one seeded street from kit.js, drawn with one of three material sets.
|
|
3
3
|
// URL: ?set=gray|warm|cool (gray = the block-out, the default) &seed=1 &count=10 &view=street|close &batch=0 (draw every piece on its own) | merge (kit.merge: one mesh per material).
|
|
4
4
|
// The two coloured sets exist to show the kit is style-free: same seed, same shapes, other slots and trim profiles. They are demo values,
|
|
5
|
-
// not a recommended
|
|
6
|
-
|
|
5
|
+
// not a recommended picture. Test page for tests/specs/modular-building.mjs: window.mbTest = { kit, street, createModularKit, bakeVertexAO, THREE }.
|
|
6
|
+
// Shapes only here; the whole picture is picture/.
|
|
7
|
+
import { createEngine, fixedCamera, bakeVertexAO, THREE } from 'threedog';
|
|
7
8
|
import { createModularKit, PROFILES } from './kit.js';
|
|
9
|
+
import { createPicture } from './picture/index.js';
|
|
8
10
|
|
|
9
11
|
const url = new URLSearchParams(location.search);
|
|
10
12
|
const set = url.get('set') ?? 'gray', seed = Number(url.get('seed') ?? 1), count = Number(url.get('count') ?? 10);
|
|
11
|
-
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), ui: { loading: false }, saveKey: 'threedog-modular-building',
|
|
13
|
+
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, ui: { loading: false }, saveKey: 'threedog-modular-building',
|
|
12
14
|
batching: url.get('batch') === '0' || url.get('batch') === 'merge' ? false : undefined });
|
|
15
|
+
const { mat: { ground: groundMat, ...slots } } = createPicture(engine, { set });
|
|
13
16
|
|
|
14
|
-
/** Slot materials for one set. A game makes these from its own style (makeMaterial roles, or plain three.js materials) */
|
|
15
|
-
function makeSlots(name = 'gray') {
|
|
16
|
-
const m = (/** @type {number} */ color, extra = {}) => makeMaterial('prop', { color, ...extra });
|
|
17
|
-
if (name === 'gray') return { wall: m(0x9c9c9c), trim: m(0xbdbdbd), roof: m(0x6c6c6c), frame: m(0x5c5c5c), glass: m(0x3c4046, { roughness: 0.3 }),
|
|
18
|
-
accent: m(0x7c7c7c), awning: m(0xc4c4c4), sign: m(0xd2d2d2) };
|
|
19
|
-
if (name === 'warm') return { wall: m(0xd9c7a3), trim: m(0xf0e9da), roof: m(0xa4553a), frame: m(0x3f5b45), glass: m(0x2e3d4f, { roughness: 0.2 }),
|
|
20
|
-
accent: m(0x7a4e33), awning: m(0xb8433a), sign: m(0xe0b54a) };
|
|
21
|
-
if (name === 'cool') return { wall: m(0x4a5260), trim: m(0x9aa3ad), roof: m(0x2c3038), frame: m(0x30c0d0, { emissive: 0x1a6a74, emissiveIntensity: 0.6 }),
|
|
22
|
-
glass: m(0x1b2a33, { roughness: 0.15, emissive: 0x0e2a33, emissiveIntensity: 0.5 }), accent: m(0xd07a30), awning: m(0x2f8f9a), sign: m(0xe6edf2) };
|
|
23
|
-
throw new Error(`modular-building: unknown set "${name}" (gray, warm, cool)`);
|
|
24
|
-
}
|
|
25
17
|
// a style swaps trim profiles too: same names (so a seed picks the same trim slot), other cross-sections. Hard-edged for the cool set
|
|
26
18
|
const cutProfiles = { flat: PROFILES.flat, step: [[0, 0], [1, 0], [1, 0.35], [0.4, 0.35], [0.4, 1], [0, 1]], cove: [[0, 0], [0.6, 0], [1, 0.4], [1, 1], [0, 1]] };
|
|
27
|
-
const kit = createModularKit({ slots
|
|
19
|
+
const kit = createModularKit({ slots, profiles: set === 'cool' ? cutProfiles : PROFILES });
|
|
28
20
|
engine.assets.manifest(kit.pack); // every module, a building and the street, by name: threedog gallery, hot swap, ?panel=1 tuning
|
|
29
21
|
|
|
30
|
-
const ground = new THREE.Mesh(new THREE.PlaneGeometry(400, 400),
|
|
22
|
+
const ground = new THREE.Mesh(new THREE.PlaneGeometry(400, 400), groundMat);
|
|
31
23
|
ground.rotation.x = -Math.PI / 2; ground.receiveShadow = true;
|
|
32
24
|
engine.scene.add(ground);
|
|
33
25
|
|
|
@@ -43,5 +35,5 @@ built.userData.batch = true; // opt in to engine.batching before adding: ident
|
|
|
43
35
|
const street = url.get('batch') === 'merge' ? kit.merge(built) : built;
|
|
44
36
|
engine.scene.add(street);
|
|
45
37
|
|
|
46
|
-
Object.assign(window, { engine, mbTest: { kit, street, createModularKit,
|
|
38
|
+
Object.assign(window, { engine, mbTest: { kit, street, createModularKit, bakeVertexAO, THREE } });
|
|
47
39
|
engine.start();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The picture of the modular-building demo: wiring only.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
import { BACKGROUND, EXPOSURE, TONE_MAPPING } from './palette.js';
|
|
5
|
+
import { createLights } from './lights.js';
|
|
6
|
+
import { createMaterials } from './materials.js';
|
|
7
|
+
|
|
8
|
+
/** Returns { mat, sun, hemi }. @param {any} engine @param {{ set: string }} o */
|
|
9
|
+
export function createPicture(engine, o) {
|
|
10
|
+
engine.renderer.toneMapping = TONE_MAPPING;
|
|
11
|
+
engine.renderer.toneMappingExposure = EXPOSURE;
|
|
12
|
+
engine.scene.background = new THREE.Color(BACKGROUND);
|
|
13
|
+
const lights = createLights(engine), { mat } = createMaterials(o.set);
|
|
14
|
+
// onRender, not onFrame: engine.focus is this frame's only after the camera module ran
|
|
15
|
+
engine.onRender(() => lights.update());
|
|
16
|
+
return { mat, sun: lights.sun, hemi: lights.hemi };
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// One fixed sun and a hemisphere fill: the street has no time of day, the page judges shapes.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
import { LIGHT, SHADOW } from './palette.js';
|
|
5
|
+
|
|
6
|
+
/** @param {any} engine */
|
|
7
|
+
export function createLights(engine) {
|
|
8
|
+
const { sun: key, ambient } = LIGHT, { extent, far, mapSize, lowMapSize, bias, normalBias, radius } = SHADOW;
|
|
9
|
+
const hemi = new THREE.HemisphereLight(ambient.sky, ambient.ground, ambient.intensity);
|
|
10
|
+
const sun = new THREE.DirectionalLight(key.color, key.intensity);
|
|
11
|
+
sun.castShadow = true;
|
|
12
|
+
sun.shadow.mapSize.setScalar(engine.tier === 'low' ? lowMapSize : mapSize);
|
|
13
|
+
Object.assign(sun.shadow.camera, { left: -extent, right: extent, top: extent, bottom: -extent, near: 1, far });
|
|
14
|
+
Object.assign(sun.shadow, { bias, normalBias, radius });
|
|
15
|
+
engine.scene.add(hemi, sun, sun.target);
|
|
16
|
+
|
|
17
|
+
const [ox, oy, oz] = key.offset;
|
|
18
|
+
return {
|
|
19
|
+
sun, hemi,
|
|
20
|
+
update() {
|
|
21
|
+
// the shadow box sits on what the camera looks at, so ?view=close keeps the same shadows as the street shot
|
|
22
|
+
sun.target.position.set(engine.focus.x, 0, engine.focus.z);
|
|
23
|
+
sun.position.set(engine.focus.x + ox, oy, engine.focus.z + oz);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Materials by name, plain Lambert: the ground plus one material per kit slot, from one set of the palette.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
import { GROUND, SETS } from './palette.js';
|
|
5
|
+
|
|
6
|
+
/** @param {string} set a name in SETS */
|
|
7
|
+
export function createMaterials(set) {
|
|
8
|
+
const slots = SETS[/** @type {keyof typeof SETS} */ (set)];
|
|
9
|
+
if (!slots) throw new Error(`modular-building: unknown set "${set}" (${Object.keys(SETS).join(', ')})`);
|
|
10
|
+
const mat = /** @type {Record<string, THREE.MeshLambertMaterial>} */ ({ ground: new THREE.MeshLambertMaterial({ color: GROUND }) });
|
|
11
|
+
for (const [name, v] of Object.entries(slots)) mat[name] = new THREE.MeshLambertMaterial(typeof v === 'number' ? { color: v } : v);
|
|
12
|
+
return { mat };
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Palette of the modular street: every value of the picture. The sets are demo values that prove the kit is style-free, not a recommended picture.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
|
|
5
|
+
/** Slot colors per set. A plain number is the color; an object is the material's own properties */
|
|
6
|
+
export const SETS = {
|
|
7
|
+
// the block-out: gray, so only silhouette and rhythm are left to judge
|
|
8
|
+
gray: { wall: 0x9c9c9c, trim: 0xbdbdbd, roof: 0x6c6c6c, frame: 0x5c5c5c, glass: 0x3c4046, accent: 0x7c7c7c, awning: 0xc4c4c4, sign: 0xd2d2d2 },
|
|
9
|
+
warm: { wall: 0xd9c7a3, trim: 0xf0e9da, roof: 0xa4553a, frame: 0x3f5b45, glass: 0x2e3d4f, accent: 0x7a4e33, awning: 0xb8433a, sign: 0xe0b54a },
|
|
10
|
+
cool: { wall: 0x4a5260, trim: 0x9aa3ad, roof: 0x2c3038, frame: { color: 0x30c0d0, emissive: 0x1a6a74, emissiveIntensity: 0.6 },
|
|
11
|
+
glass: { color: 0x1b2a33, emissive: 0x0e2a33, emissiveIntensity: 0.5 }, accent: 0xd07a30, awning: 0x2f8f9a, sign: 0xe6edf2 },
|
|
12
|
+
};
|
|
13
|
+
export const GROUND = 0x8c8c86;
|
|
14
|
+
export const BACKGROUND = 0x8c8c8c;
|
|
15
|
+
/** A strong, nearly even fill over a modest sun, on purpose: a block-out has to show every facade, so the sides facing away stay as readable as the lit ones */
|
|
16
|
+
export const LIGHT = {
|
|
17
|
+
sun: { color: 0xffffff, intensity: 2, offset: [40, 80, 30] },
|
|
18
|
+
ambient: { sky: 0xffffff, ground: 0x909090, intensity: 3.1 },
|
|
19
|
+
};
|
|
20
|
+
/** A 60 m box around what the camera looks at: most of a ten-building street, at about 3 cm a texel */
|
|
21
|
+
export const SHADOW = { extent: 30, far: 250, mapSize: 2048, lowMapSize: 1024, bias: -0.0001, normalBias: 0.03, radius: 3 };
|
|
22
|
+
export const TONE_MAPPING = THREE.AgXToneMapping;
|
|
23
|
+
export const EXPOSURE = 1;
|
|
@@ -14,12 +14,12 @@ colored windows, and a night that is darker than all of them.
|
|
|
14
14
|
the facades above dark, like a real cut-off fixture. `distance` only cuts the tail; keep it a few times the lamp height so the edge comes
|
|
15
15
|
from decay.
|
|
16
16
|
|
|
17
|
-
**Which pixels bloom is the threshold's choice.** The tone curve (AgX
|
|
17
|
+
**Which pixels bloom is the threshold's choice.** The tone curve (AgX on this page) compresses everything above ~1 toward white. Bloom adds light
|
|
18
18
|
around pixels above its `threshold` (linear, before the curve). Usually it sits between the windows and the lamp heads, so only the small heads
|
|
19
19
|
glow and windows and signs read as colored light; if your game wants a hazy, everything-glows night, set it lower on purpose.
|
|
20
20
|
|
|
21
21
|
**Emissive is a color, not a brightness knob.** Saturated emissive colors survive the tone curve; near-white ones have no headroom and clip
|
|
22
|
-
to flat white rectangles
|
|
22
|
+
to flat white rectangles. Get the warmth from the color and let bloom carry the halo; the
|
|
23
23
|
intensities in this example are its values, not targets.
|
|
24
24
|
|
|
25
25
|
**Lights read when the night is darker than they are.** If the ambient at night is close to the pool brightness, the lamps look painted on.
|
|
@@ -31,7 +31,7 @@ bright, readable night, keep the ambient up and let the lamps be accents instead
|
|
|
31
31
|
**Lights fade in.** A hard switch at 18:00 pops; fade by daylight.
|
|
32
32
|
|
|
33
33
|
How to judge it in a shot at the game's camera: the ground under a lamp is clearly brighter than half way to the next one, and the pool fades
|
|
34
|
-
without a ring; around a lamp only its core is white (the
|
|
34
|
+
without a ring; around a lamp only its core is white (the picture check of `threedog shot` / `threedog snap` names each light or glowing material that blows pixels out, and the detail lost under it); the "near black" share stays low enough
|
|
35
35
|
that shapes hold.
|
|
36
36
|
|
|
37
37
|
| Symptom | Cause | Fix |
|
|
@@ -39,7 +39,7 @@ that shapes hold.
|
|
|
39
39
|
| Lamp heads and windows are flat white blocks | emissive far above the tone curve's shoulder: everything clips to the same white | lower emissiveIntensity, use a saturated color; usually only the small lamp core clips (more if your game wants blinding light) |
|
|
40
40
|
| A wall next to a lamp is a bright blown-out sheet | `decay: 0` (or 1) and the light close to the wall: no falloff, the whole wall gets the full intensity | `decay: 2`, aim a spot down, move the light off the wall |
|
|
41
41
|
| The whole night scene glows and looks foggy | bloom threshold below 1: every lit surface blooms | threshold between window and lamp-head brightness |
|
|
42
|
-
| Everything is too bright or too gray at night | exposure or ambient set for the day | lower the night ambient (
|
|
42
|
+
| Everything is too bright or too gray at night | exposure or ambient set for the day | lower the night ambient (`NIGHT.hemi` in `picture/palette.js`) rather than the lights |
|
|
43
43
|
| Halo plus bloom look like a smear | both at full strength | pick one as the main glow, keep the other faint |
|
|
44
44
|
| Lights pop on at nightfall | a hard switch at 18:00 | fade by daylight (`dusk`) |
|
|
45
45
|
|
|
@@ -63,32 +63,33 @@ that shapes hold.
|
|
|
63
63
|
- **Pixel art**: hard-edged pools in two or three palette steps, no bloom. A texture lookup.
|
|
64
64
|
|
|
65
65
|
## The engine helper (optional convenience)
|
|
66
|
-
`threedog examples pull night-lights` copies it. Only `nightLights.js` is the technique (defaults in `NIGHT_LIGHTS_DEFAULTS`); `main.js` is the
|
|
67
|
-
demo scene,
|
|
66
|
+
`threedog examples pull night-lights` copies it. Only `nightLights.js` is the technique (defaults in `NIGHT_LIGHTS_DEFAULTS`) and it stands alone; `main.js` is the
|
|
67
|
+
demo scene and `picture/` its picture (sun, ambient, sky, fog, bloom, tone curve). In a game:
|
|
68
68
|
```js
|
|
69
69
|
engine.use(lightPool({ point: 4, spot: 8 })); // real lights for the nearest lamps; the rest wait their turn
|
|
70
70
|
const lights = createNightLights(engine);
|
|
71
71
|
lights.addLamp(headPosition, { head: headMaterial }); // pooled spot aimed down + emissive head + halo
|
|
72
|
-
lights.addGlow(windowMaterial); //
|
|
72
|
+
lights.addGlow(windowMaterial); // emissive fades in at dusk
|
|
73
73
|
```
|
|
74
74
|
This example's current values: 80 cd at 5.5 m, so the pool center is a little under the brightness a sunlit mid-gray gets (recipe 52 "How
|
|
75
75
|
bright a lit color comes out"); raise it for brighter streets, lower it for moody ones. Lamp heads at 2.5, windows at 0.6, bloom threshold 1.4.
|
|
76
|
-
The demo
|
|
76
|
+
The demo keeps its night ambient far under the pools (`NIGHT.hemi` in `picture/palette.js`). With bloom on, keep the halo's
|
|
77
77
|
opacity low; they stack.
|
|
78
78
|
|
|
79
79
|
Cost (the demo street): 8 pooled spot lights (no shadows) for any number of lamps; one emissive material per kind of glow; one sprite per lamp
|
|
80
|
-
sharing one material and a 64 px texture; bloom is one `UnrealBloomPass` (several half-resolution blur passes; costly on integrated GPUs,
|
|
81
|
-
|
|
80
|
+
sharing one material and a 64 px texture; bloom is one `UnrealBloomPass` (several half-resolution blur passes; costly on integrated GPUs, so
|
|
81
|
+
`picture/post.js` starts it off on low-tier devices). Spot shadows add one shadow map each (another pass over the casters): this example gives none; a game that wants lamp shadows picks its hero lamps and measures the frame time as it adds them.
|
|
82
82
|
|
|
83
83
|
Rules (correctness):
|
|
84
84
|
- Lamps take their real lights from `engine.lightPool` (`lightPool({ spot })`): a fixed number of three.js lights, so many lamps never
|
|
85
85
|
recompile shaders or add per-light cost. Without the pool it throws.
|
|
86
86
|
- The night factor comes from the time of day (`engine.calendar.daylight`, the sky's when there is no calendar). Nothing here is saved: it
|
|
87
87
|
is recomputed from the time each frame, so loads and time skips are right by construction.
|
|
88
|
-
-
|
|
89
|
-
-
|
|
90
|
-
the
|
|
91
|
-
from `daylight` (`dusk` is set to the glow's range) and sets the pooled lights; `lights.force(v)` holds it.
|
|
88
|
+
- `addGlow` drives every mesh using that material: give dark windows their own material (the demo uses two lit ones and plain wall gray).
|
|
89
|
+
- The lamps' real lights fade through the pool (`lightPool.add(at, { dusk })`). Windows, signs, lamp heads and halos are not pool sources, so
|
|
90
|
+
the technique applies the same curve at the same `dusk` to their `emissiveIntensity` and the halo opacity, in one `engine.onRender`.
|
|
92
91
|
|
|
93
92
|
Sources: written for this example; no code copied. Light units and falloff as documented for three.js physically based lights; the bloom pass
|
|
94
93
|
is three's `UnrealBloomPass` through `@threedog/post-effects`.
|
|
94
|
+
|
|
95
|
+
This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`). A game on the default WebGPU route writes the same ideas in TSL (recipe 56).
|
|
@@ -1,70 +1,47 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
// hint-off-file(material): the demo street is deliberately plain gray three.js materials, not a style
|
|
3
2
|
// Night-lights demo (page /night-lights.html): a neutral gray street with lamps, lit windows and two signs, the technique of nightLights.js.
|
|
4
3
|
// URL: ?time=HH:MM (the engine reads it) &halo=0 &bloom=0 &glare=1 (the classic mistakes all at once: decay 0, hot windows, low bloom threshold)
|
|
5
|
-
// Test page for tests/specs/night-lights.mjs: window.nightLightsTest = { lights, THREE, lampAt, between }.
|
|
6
|
-
import { createEngine, calendar, sky, fixedCamera, lightPool, presets, THREE } from '
|
|
7
|
-
import {
|
|
8
|
-
import { createNightLights } from './nightLights.js';
|
|
4
|
+
// Test page for tests/specs/night-lights.mjs: window.nightLightsTest = { lights, picture, THREE, lampAt, between }. Shapes only here; the whole picture is picture/.
|
|
5
|
+
import { createEngine, calendar, sky, fixedCamera, lightPool, presets, THREE } from 'threedog';
|
|
6
|
+
import { createPicture } from './picture/index.js';
|
|
9
7
|
|
|
10
|
-
const url = new URLSearchParams(location.search)
|
|
11
|
-
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), ui: { loading: false }, saveKey: 'threedog-night-lights' });
|
|
8
|
+
const url = new URLSearchParams(location.search);
|
|
9
|
+
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, ui: { loading: false }, saveKey: 'threedog-night-lights' });
|
|
12
10
|
engine.use(calendar({ ...presets.calendar.fixedTime, time: '22:00' }), sky(), lightPool({ point: 2, spot: 8 }),
|
|
13
11
|
fixedCamera({ shots: { street: { position: [3.2, 1.7, 12], lookAt: [-1, 1.2, -20] } }, start: 'street' }));
|
|
14
|
-
|
|
15
|
-
// every lit wall and window glow (the glare=1 case).
|
|
16
|
-
if (url.get('bloom') !== '0') engine.look.post.add(bloom(glare ? { threshold: 0.2, strength: 1.2, radius: 0.8 } : { threshold: 1.4, strength: 0.45, radius: 0.35 }));
|
|
12
|
+
const picture = createPicture(engine, { halo: url.get('halo') !== '0', bloom: url.get('bloom') !== '0', glare: url.get('glare') === '1' }), { mat } = picture;
|
|
17
13
|
|
|
18
|
-
// ---- the street
|
|
19
|
-
const gray = (/** @type {number} */ c, r = 0.9) => new THREE.MeshStandardMaterial({ color: c, roughness: r });
|
|
14
|
+
// ---- the street ----
|
|
20
15
|
const add = (/** @type {THREE.BufferGeometry} */ g, /** @type {THREE.Material} */ m, /** @type {number[]} */ [x, y, z]) => {
|
|
21
16
|
const mesh = new THREE.Mesh(g, m); mesh.position.set(x, y, z); mesh.receiveShadow = true; mesh.castShadow = true; engine.scene.add(mesh); return mesh;
|
|
22
17
|
};
|
|
23
|
-
add(new THREE.PlaneGeometry(10, 160).rotateX(-Math.PI / 2),
|
|
24
|
-
const
|
|
25
|
-
for (const x of [-6.5, 6.5]) add(new THREE.BoxGeometry(3, 0.15, 160), curb, [x, 0.075, -50]);
|
|
26
|
-
const winMat = (/** @type {number} */ c) => new THREE.MeshStandardMaterial({ color: 0x18181a, emissive: c, emissiveIntensity: 0, roughness: 0.3 });
|
|
27
|
-
const warm = winMat(0xffb36b), cool = winMat(0xc8d8ff);
|
|
18
|
+
add(new THREE.PlaneGeometry(10, 160).rotateX(-Math.PI / 2), mat.road, [0, 0, -50]);
|
|
19
|
+
for (const x of [-6.5, 6.5]) add(new THREE.BoxGeometry(3, 0.15, 160), mat.curb, [x, 0.075, -50]);
|
|
28
20
|
for (const side of [-1, 1]) for (let z = 10, i = 0; z > -110; z -= 14, i++) {
|
|
29
21
|
const h = 8 + ((i * 7 + (side > 0 ? 3 : 0)) % 5) * 2;
|
|
30
|
-
add(new THREE.BoxGeometry(6, h, 12), wall, [side * 11, h / 2, z]);
|
|
22
|
+
add(new THREE.BoxGeometry(6, h, 12), mat.wall, [side * 11, h / 2, z]);
|
|
31
23
|
for (let fy = 2; fy < h - 1; fy += 3) for (const dz of [-3.5, 0, 3.5]) {
|
|
32
24
|
const k = (i * 5 + fy * 3 + dz * 2 + side) % 7;
|
|
33
25
|
if (k > 3) continue; // about half the windows are dark: all lit reads as an office tower, not a street at night
|
|
34
|
-
add(new THREE.PlaneGeometry(1.4, 1.6).rotateY(-side * Math.PI / 2), k === 0 ?
|
|
26
|
+
add(new THREE.PlaneGeometry(1.4, 1.6).rotateY(-side * Math.PI / 2), k === 0 ? mat.windowCool : mat.windowWarm, [side * 7.99, fy, z + dz]).castShadow = false;
|
|
35
27
|
}
|
|
36
28
|
}
|
|
37
29
|
// two signs on the facades: saturated colours so their brightness reads as colour instead of white
|
|
38
|
-
|
|
39
|
-
add(new THREE.BoxGeometry(0.15,
|
|
40
|
-
add(new THREE.BoxGeometry(0.15, 2.6, 0.6), signB, [7.9, 4.5, -22]).castShadow = false;
|
|
30
|
+
add(new THREE.BoxGeometry(0.15, 0.7, 3.2), mat.signCyan, [-7.9, 4.2, -6]).castShadow = false;
|
|
31
|
+
add(new THREE.BoxGeometry(0.15, 2.6, 0.6), mat.signPink, [7.9, 4.5, -22]).castShadow = false;
|
|
41
32
|
|
|
42
|
-
// ---- the
|
|
43
|
-
const
|
|
44
|
-
lights.addGlow(warm); lights.addGlow(cool, 0.45); lights.addGlow(signA, 1.4); lights.addGlow(signB, 1.4);
|
|
45
|
-
const pole = gray(0x505054), lampAt = [];
|
|
33
|
+
// ---- the lamps ----
|
|
34
|
+
const lampAt = [];
|
|
46
35
|
for (let z = 8, i = 0; z > -110; z -= 13, i++) {
|
|
47
36
|
const x = i % 2 ? 5.2 : -5.2;
|
|
48
|
-
add(new THREE.CylinderGeometry(0.08, 0.1, 5.6, 8), pole, [x, 2.8, z]);
|
|
49
|
-
add(new THREE.BoxGeometry(0.7, 0.12, 0.35), pole, [x * 0.9, 5.62, z]);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
lights.addLamp({ x: x * 0.86, y: 5.45, z }, { head });
|
|
37
|
+
add(new THREE.CylinderGeometry(0.08, 0.1, 5.6, 8), mat.pole, [x, 2.8, z]);
|
|
38
|
+
add(new THREE.BoxGeometry(0.7, 0.12, 0.35), mat.pole, [x * 0.9, 5.62, z]);
|
|
39
|
+
add(new THREE.BoxGeometry(0.5, 0.06, 0.28), mat.head, [x * 0.86, 5.53, z]).castShadow = false; // the glowing underside only: a thin lens, not a lit box
|
|
40
|
+
picture.addLamp({ x: x * 0.86, y: 5.45, z });
|
|
53
41
|
lampAt.push([x * 0.86, z]);
|
|
54
42
|
}
|
|
55
43
|
|
|
56
|
-
// The neutral sky keeps a fair amount of ambient at night; a night scene where lamps should matter needs the ambient well under the pools.
|
|
57
|
-
// A game's own sky keyframes do this; here: lower the sky ambient by the same night factor the lights use (the room-map light already follows it).
|
|
58
|
-
let ambientMod = /** @type {{ remove(): void } | null} */ (null), lastNight = -1;
|
|
59
|
-
engine.onFrame(() => {
|
|
60
|
-
const n = Math.round(lights.night * 20) / 20; // a few steps: changing the multiplier is not free
|
|
61
|
-
if (n === lastNight) return;
|
|
62
|
-
lastNight = n;
|
|
63
|
-
ambientMod?.remove();
|
|
64
|
-
ambientMod = n > 0 ? engine.mod('look.lights.hemi.intensity', { owner: 'night-demo', mul: 1 - 0.5 * n }) : null;
|
|
65
|
-
});
|
|
66
|
-
|
|
67
44
|
// points the spec reads: the ground under the second lamp, and the ground half way to the next lamp on the same side
|
|
68
45
|
const between = [lampAt[1][0], (lampAt[1][1] + lampAt[3][1]) / 2];
|
|
69
|
-
Object.assign(window, { engine, nightLightsTest: { lights, THREE, lampAt, between } });
|
|
46
|
+
Object.assign(window, { engine, nightLightsTest: { lights: picture.nightLights, picture, THREE, lampAt, between } });
|
|
70
47
|
engine.start();
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
// Technique: street lamps, lit windows and signs that read as light at night without glaring (README.md next to this file). Copy this file
|
|
3
3
|
// into a game; in a game the import below becomes `from 'threedog'`. Needs engine.use(lightPool({ spot: n })) for the lamps' real lights.
|
|
4
4
|
// What it does: lamps = a pooled SpotLight aimed down (a light pool on the ground, walls above stay dark) + an emissive head + an optional
|
|
5
|
-
// soft halo sprite. One daylight curve for all of it
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// chosen against the tone curve: the head is the only thing bright enough to bloom; windows stay below clipping.
|
|
5
|
+
// soft halo sprite. One daylight curve for all of it: the lamps' real lights fade with lightPool.add({ dusk }), and night() below is that same
|
|
6
|
+
// curve for what the pool does not drive (windows, signs, lamp heads, halos). The numbers are chosen against the tone curve: the head is the only
|
|
7
|
+
// thing bright enough to bloom; windows stay below clipping.
|
|
9
8
|
import { THREE } from 'threedog';
|
|
10
9
|
|
|
11
10
|
/** Every knob of the technique; createNightLights(engine, { ...overrides }) */
|
|
@@ -22,7 +21,7 @@ export const NIGHT_LIGHTS_DEFAULTS = {
|
|
|
22
21
|
halo: true, // a soft sprite around each head: glow without post (or on top of a gentle bloom)
|
|
23
22
|
haloSize: 1.6, // meters
|
|
24
23
|
haloOpacity: 0.18, // additive: keep it low, it stacks on the bloom
|
|
25
|
-
dusk: 0.3, // daylight (engine.calendar.daylight, 0-1) below which lamps, heads, windows and halos fade in
|
|
24
|
+
dusk: 0.3, // daylight (engine.calendar.daylight, 0-1) below which lamps, heads, windows and halos fade in
|
|
26
25
|
};
|
|
27
26
|
|
|
28
27
|
/** One soft radial gradient shared by every halo (64 px is plenty: it is blurred by nature) */
|
|
@@ -51,22 +50,27 @@ export function createNightLights(engine, over = {}) {
|
|
|
51
50
|
|
|
52
51
|
/** @type {{ light: any, head: any, halo: THREE.Sprite | null, intensity: number }[]} */
|
|
53
52
|
const lamps = [];
|
|
54
|
-
/**
|
|
55
|
-
const glows =
|
|
53
|
+
/** material -> its emissiveIntensity at full night; a Map, because many lamps may share one head material */
|
|
54
|
+
const glows = /** @type {Map<any, number>} */ (new Map());
|
|
56
55
|
const haloMat = new THREE.SpriteMaterial({ map: haloMap(), color: o.lampColor, transparent: true, opacity: 0, depthWrite: false, blending: THREE.AdditiveBlending });
|
|
57
56
|
const group = new THREE.Group(); group.name = 'nightLights';
|
|
58
57
|
engine.scene.add(group);
|
|
59
58
|
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
// 0 by day, 1 at night: the curve lightPool applies to a source with dusk, on the daylight the pool reads (the calendar's, the sky's without one)
|
|
60
|
+
const night = () => {
|
|
61
|
+
const x = Math.min(1, Math.max(0, (engine.calendar?.daylight ?? engine.sky?.daylight ?? 1) / o.dusk));
|
|
62
|
+
return 1 - x * x * (3 - 2 * x);
|
|
63
|
+
};
|
|
64
|
+
// its own hook, so this file works alone in any game; onRender, not onFrame, so a time change shows in the same frame
|
|
65
|
+
const hook = engine.onRender(() => {
|
|
66
|
+
const n = night();
|
|
67
|
+
haloMat.opacity = o.haloOpacity * n;
|
|
68
|
+
for (const [m, full] of glows) m.emissiveIntensity = full * n;
|
|
69
|
+
});
|
|
66
70
|
|
|
67
71
|
return {
|
|
68
|
-
/** 0 = day (all off) ... 1 = full night
|
|
69
|
-
get night() { return
|
|
72
|
+
/** 0 = day (all off) ... 1 = full night */
|
|
73
|
+
get night() { return night(); },
|
|
70
74
|
/**
|
|
71
75
|
* A street lamp. at = the light's position (just under the head). head = the lamp head's material (its emissive is driven).
|
|
72
76
|
* @param {THREE.Vector3 | { x: number, y: number, z: number }} at
|
|
@@ -75,17 +79,17 @@ export function createNightLights(engine, over = {}) {
|
|
|
75
79
|
addLamp(at, { head, color = o.lampColor, intensity = o.lampIntensity, spot = true } = {}) {
|
|
76
80
|
const p = new THREE.Vector3(at.x, at.y, at.z);
|
|
77
81
|
const light = engine.lightPool.add(p, { type: spot ? 'spot' : 'point', color, intensity, distance: o.lampDistance, decay: o.lampDecay,
|
|
78
|
-
angle: o.lampAngle, penumbra: o.lampPenumbra, name: 'street lamp', dusk: o.dusk }); // dusk: off by day
|
|
82
|
+
angle: o.lampAngle, penumbra: o.lampPenumbra, name: 'street lamp', dusk: o.dusk }); // dusk: off by day
|
|
79
83
|
let halo = null;
|
|
80
84
|
if (o.halo) { halo = new THREE.Sprite(haloMat); halo.position.copy(p).y += 0.1; halo.scale.setScalar(o.haloSize); halo.renderOrder = 3; group.add(halo); }
|
|
81
85
|
const lamp = { light, head: head ?? null, halo, intensity };
|
|
82
86
|
lamps.push(lamp);
|
|
83
|
-
if (head) { /** @type {any} */ (head).emissive?.set?.(color); glows.
|
|
87
|
+
if (head) { /** @type {any} */ (head).emissive?.set?.(color); glows.set(head, o.headEmissive); }
|
|
84
88
|
return lamp;
|
|
85
89
|
},
|
|
86
|
-
/** A lit window or sign
|
|
87
|
-
addGlow(/** @type {
|
|
88
|
-
describe() { return { night:
|
|
89
|
-
dispose() {
|
|
90
|
+
/** A lit window or sign: the material's emissiveIntensity fades to `base` at night (pass o.signEmissive for signs) */
|
|
91
|
+
addGlow(/** @type {THREE.Material} */ material, base = o.windowEmissive) { glows.set(material, base); },
|
|
92
|
+
describe() { return { night: night(), lamps: lamps.length, glows: glows.size, daylight: engine.calendar?.daylight ?? engine.sky?.daylight ?? null }; },
|
|
93
|
+
dispose() { hook.remove(); for (const l of lamps) l.light.remove(); group.removeFromParent(); haloMat.dispose(); },
|
|
90
94
|
};
|
|
91
95
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The picture of the night street: wiring only. Each part writes plain three.js from the signals; one onRender drives them.
|
|
3
|
+
import { EXPOSURE, TONE_MAPPING } from './palette.js';
|
|
4
|
+
import { createLights } from './lights.js';
|
|
5
|
+
import { createMaterials } from './materials.js';
|
|
6
|
+
import { createSky } from './sky.js';
|
|
7
|
+
import { createPost } from './post.js';
|
|
8
|
+
|
|
9
|
+
/** Needs engine.use(lightPool(...)) first. Returns { mat, addLamp, nightLights, sun, hemi }. @param {any} engine @param {{ halo: boolean, bloom: boolean, glare: boolean }} o */
|
|
10
|
+
export function createPicture(engine, o) {
|
|
11
|
+
engine.renderer.toneMapping = TONE_MAPPING;
|
|
12
|
+
engine.renderer.toneMappingExposure = EXPOSURE;
|
|
13
|
+
const mat = createMaterials(), lights = createLights(engine, mat, o), sky = createSky(engine);
|
|
14
|
+
if (o.bloom) createPost(engine, o);
|
|
15
|
+
// onRender, not onFrame: onFrame runs before the sky module, so it would read last frame's signals
|
|
16
|
+
engine.onRender(() => { sky.update(engine.uniforms); lights.update(engine.uniforms); });
|
|
17
|
+
return { mat, addLamp: lights.addLamp, nightLights: lights.nightLights, sun: lights.sun, hemi: lights.hemi };
|
|
18
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Sun or moon, ambient, and the night lights technique on this street's materials. addLamp is the one name the street needs from here.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
import { DAY, GLARE, GLOW, NIGHT, SHADOW, dayLevel } from './palette.js';
|
|
5
|
+
import { createNightLights } from '../nightLights.js';
|
|
6
|
+
|
|
7
|
+
/** @param {any} engine @param {ReturnType<typeof import('./materials.js').createMaterials>} mat @param {{ halo: boolean, glare: boolean }} o */
|
|
8
|
+
export function createLights(engine, mat, o) {
|
|
9
|
+
const hemi = new THREE.HemisphereLight(DAY.hemi.sky, DAY.hemi.ground, DAY.hemi.intensity);
|
|
10
|
+
const sun = new THREE.DirectionalLight(DAY.sun.color, DAY.sun.intensity);
|
|
11
|
+
const { center, extent, near, far, distance, normalBias, mapSize } = SHADOW;
|
|
12
|
+
sun.castShadow = true;
|
|
13
|
+
sun.shadow.mapSize.setScalar(engine.tier === 'low' ? mapSize.low : mapSize.high);
|
|
14
|
+
Object.assign(sun.shadow.camera, { left: -extent, right: extent, top: extent, bottom: -extent, near, far });
|
|
15
|
+
sun.shadow.normalBias = normalBias;
|
|
16
|
+
sun.target.position.fromArray(center);
|
|
17
|
+
engine.scene.add(hemi, sun, sun.target);
|
|
18
|
+
|
|
19
|
+
const nightLights = createNightLights(engine, { halo: o.halo, ...(o.glare ? GLARE.lights : {}) });
|
|
20
|
+
nightLights.addGlow(mat.windowWarm);
|
|
21
|
+
nightLights.addGlow(mat.windowCool, GLOW.windowCool);
|
|
22
|
+
nightLights.addGlow(mat.signCyan, GLOW.sign);
|
|
23
|
+
nightLights.addGlow(mat.signPink, GLOW.sign);
|
|
24
|
+
|
|
25
|
+
const dir = new THREE.Vector3(), a = new THREE.Color(), b = new THREE.Color();
|
|
26
|
+
const blend = (/** @type {THREE.Color} */ out, /** @type {number} */ night, /** @type {number} */ day, /** @type {number} */ k) => out.copy(a.set(night)).lerp(b.set(day), k);
|
|
27
|
+
return {
|
|
28
|
+
sun, hemi, nightLights,
|
|
29
|
+
/** @param {{ x: number, y: number, z: number }} at */
|
|
30
|
+
addLamp: at => nightLights.addLamp(at, { head: mat.head }),
|
|
31
|
+
/** @param {any} s engine.uniforms */
|
|
32
|
+
update(s) {
|
|
33
|
+
const d = s.uSunDir.value, k = dayLevel(s.uDaylight.value);
|
|
34
|
+
// below the horizon the same light is the moon, across the sky from where the sun went; it fades through 0 at the swap so shadows never jump
|
|
35
|
+
dir.set(d.y < 0 ? -d.x : d.x, Math.abs(d.y), d.z).normalize();
|
|
36
|
+
sun.position.copy(dir).multiplyScalar(distance).add(sun.target.position);
|
|
37
|
+
sun.intensity = (NIGHT.sun.intensity + (DAY.sun.intensity - NIGHT.sun.intensity) * k) * Math.min(1, Math.abs(d.y) / 0.08);
|
|
38
|
+
blend(sun.color, NIGHT.sun.color, DAY.sun.color, k);
|
|
39
|
+
hemi.intensity = NIGHT.hemi.intensity + (DAY.hemi.intensity - NIGHT.hemi.intensity) * k;
|
|
40
|
+
blend(hemi.color, NIGHT.hemi.sky, DAY.hemi.sky, k);
|
|
41
|
+
blend(hemi.groundColor, NIGHT.hemi.ground, DAY.hemi.ground, k);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Materials by name. Windows, signs and lamp heads start dark: nightLights.js raises their emissive at night.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
import { COLORS, ROUGHNESS } from './palette.js';
|
|
5
|
+
|
|
6
|
+
export function createMaterials() {
|
|
7
|
+
const gray = (/** @type {number} */ color, roughness = ROUGHNESS.plain) => new THREE.MeshStandardMaterial({ color, roughness });
|
|
8
|
+
const glowing = (/** @type {number} */ emissive) => new THREE.MeshStandardMaterial({ color: COLORS.glass, emissive, emissiveIntensity: 0, roughness: ROUGHNESS.glass });
|
|
9
|
+
return {
|
|
10
|
+
road: gray(COLORS.road, ROUGHNESS.road), curb: gray(COLORS.curb), wall: gray(COLORS.wall), pole: gray(COLORS.pole),
|
|
11
|
+
windowWarm: glowing(COLORS.windowWarm), windowCool: glowing(COLORS.windowCool), signCyan: glowing(COLORS.signCyan), signPink: glowing(COLORS.signPink),
|
|
12
|
+
// emissive stays black here: addLamp gives the head the lamp's own color
|
|
13
|
+
head: new THREE.MeshStandardMaterial({ color: COLORS.head, roughness: ROUGHNESS.head, emissiveIntensity: 0 }),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Every value of the night street's picture. A neutral gray start: the street is gray so the lamps, windows and signs are the only color.
|
|
3
|
+
// The lamp, window and halo values live in nightLights.js, the technique this page shows; only what differs from them is here.
|
|
4
|
+
import { THREE } from 'threedog';
|
|
5
|
+
|
|
6
|
+
/** Surfaces of the demo street */
|
|
7
|
+
export const COLORS = { road: 0x5c5c60, curb: 0x8a8a8c, wall: 0x7c7c80, pole: 0x505054, glass: 0x18181a, head: 0x202020,
|
|
8
|
+
windowWarm: 0xffb36b, windowCool: 0xc8d8ff, signCyan: 0x30e0ff, signPink: 0xff3a8a };
|
|
9
|
+
export const ROUGHNESS = { road: 0.8, plain: 0.9, glass: 0.3, head: 1 };
|
|
10
|
+
|
|
11
|
+
// The ambient at night sits well under the lamp pools: lights read only when the night is darker than they are
|
|
12
|
+
export const DAY = { top: 0xb4b4b4, horizon: 0xd4d4d4, sun: { color: 0xffffff, intensity: 3 }, hemi: { sky: 0xb9b9b9, ground: 0x909090, intensity: 1.2 } }; // ground: the sunlit road's bounce, what lifts the shaded facades
|
|
13
|
+
export const NIGHT = { top: 0x1a1a1a, horizon: 0x2a2a2a, sun: { color: 0xa8a8a8, intensity: 0.4 }, hemi: { sky: 0x212121, ground: 0x3a3a3a, intensity: 0.087 } };
|
|
14
|
+
export const FOG = { near: 180, far: 600 };
|
|
15
|
+
/** Sun height (uDaylight) from which it counts as full day: the sun of a real latitude never reaches 1 */
|
|
16
|
+
export const FULL_DAY_AT = 0.5;
|
|
17
|
+
/** 0 night .. 1 day from the sun's height, smooth at both ends so dusk has no kink @param {number} daylight */
|
|
18
|
+
export function dayLevel(daylight) {
|
|
19
|
+
const t = Math.min(1, daylight / FULL_DAY_AT);
|
|
20
|
+
return t * t * (3 - 2 * t);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The sun's shadow box covers the whole street, from the camera to the far end; the camera never moves, so it never has to follow */
|
|
24
|
+
export const SHADOW = { center: [0, 0, -50], extent: 90, near: 1, far: 260, distance: 120, normalBias: 0.04, mapSize: { low: 1024, high: 2048 } };
|
|
25
|
+
|
|
26
|
+
export const TONE_MAPPING = THREE.AgXToneMapping;
|
|
27
|
+
export const EXPOSURE = 1;
|
|
28
|
+
|
|
29
|
+
/** Bloom only for what is hotter than the threshold (linear): lamp heads at 2.5 bloom, windows at 0.6 never do */
|
|
30
|
+
export const BLOOM = { threshold: 1.4, strength: 0.45, radius: 0.35 };
|
|
31
|
+
/** Window and sign brightness where it differs from the technique's windowEmissive: cool windows are dimmer, signs hotter */
|
|
32
|
+
export const GLOW = { windowCool: 0.45, sign: 1.4 };
|
|
33
|
+
/** ?glare=1: the classic mistakes all at once. A threshold under 1 makes every lit wall and window glow, decay 0 floods the walls */
|
|
34
|
+
export const GLARE = { bloom: { threshold: 0.2, strength: 1.2, radius: 0.8 }, lights: { lampDecay: 0, windowEmissive: 3, headEmissive: 8 } };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The bloom on the lamp heads. Added but off on low-tier devices: it blurs the whole frame several times.
|
|
3
|
+
import { bloom } from '@threedog/post-effects';
|
|
4
|
+
import { BLOOM, GLARE } from './palette.js';
|
|
5
|
+
|
|
6
|
+
/** @param {any} engine @param {{ glare: boolean }} o */
|
|
7
|
+
export function createPost(engine, o) {
|
|
8
|
+
engine.post.add(bloom({ ...(o.glare ? GLARE.bloom : BLOOM), enabled: engine.tier !== 'low' }), { name: 'bloom', slot: 'hdr' });
|
|
9
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The sky is this page's: a gradient sphere in place of the engine's dome, with fog in the horizon color.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
import { DAY, FOG, NIGHT, dayLevel } from './palette.js';
|
|
5
|
+
|
|
6
|
+
/** @param {any} engine */
|
|
7
|
+
export function createSky(engine) {
|
|
8
|
+
const { scene } = engine, fog = new THREE.Fog(0x000000, FOG.near, FOG.far);
|
|
9
|
+
scene.fog = fog;
|
|
10
|
+
const skyMat = new THREE.ShaderMaterial({
|
|
11
|
+
side: THREE.BackSide, depthWrite: false, fog: false,
|
|
12
|
+
uniforms: { uTop: { value: new THREE.Color() }, uHorizon: { value: new THREE.Color() } },
|
|
13
|
+
vertexShader: 'varying vec3 vDir; void main(){ vDir = normalize(position); gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }',
|
|
14
|
+
// tonemapping_fragment: the sky takes the same curve as the street, with or without the post chain (?bloom=0 draws straight to the canvas)
|
|
15
|
+
fragmentShader: `uniform vec3 uTop; uniform vec3 uHorizon; varying vec3 vDir;
|
|
16
|
+
void main(){ gl_FragColor = vec4(mix(uHorizon, uTop, smoothstep(-0.05, 0.45, vDir.y)), 1.0);
|
|
17
|
+
#include <tonemapping_fragment>
|
|
18
|
+
#include <colorspace_fragment>
|
|
19
|
+
}`,
|
|
20
|
+
});
|
|
21
|
+
const dome = new THREE.Mesh(new THREE.SphereGeometry(400, 32, 16), skyMat);
|
|
22
|
+
dome.renderOrder = -1;
|
|
23
|
+
scene.add(dome);
|
|
24
|
+
if (engine.sky) engine.sky.dome.visible = false;
|
|
25
|
+
|
|
26
|
+
const day = new THREE.Color();
|
|
27
|
+
return {
|
|
28
|
+
/** @param {any} s engine.uniforms */
|
|
29
|
+
update(s) {
|
|
30
|
+
const k = dayLevel(s.uDaylight.value), { uTop, uHorizon } = skyMat.uniforms;
|
|
31
|
+
uTop.value.set(NIGHT.top).lerp(day.set(DAY.top), k);
|
|
32
|
+
uHorizon.value.set(NIGHT.horizon).lerp(day.set(DAY.horizon), k);
|
|
33
|
+
fog.color.copy(uHorizon.value);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|