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
|
@@ -9,7 +9,7 @@ never imports this folder.
|
|
|
9
9
|
## The principle
|
|
10
10
|
A shaded surface is read through three things: where light turns into shade (the terminator), how hard that turn is, and what color the
|
|
11
11
|
shade has. Stylizing is choosing those three on purpose instead of leaving them to a physical default. The columns are routes, not a ranking;
|
|
12
|
-
choose from what the game's
|
|
12
|
+
choose from what the game's picture should feel like.
|
|
13
13
|
- **Bands** (toon): the light share is cut into a few levels. Few bands read from far away; more bands drift back towards smooth shading.
|
|
14
14
|
- **Soft wrap** (painterly): light wraps past the terminator, so forms read soft and light; a warm band at the terminator and colored shadows
|
|
15
15
|
are what a painter adds and a renderer does not.
|
|
@@ -21,8 +21,8 @@ choose from what the game's look should feel like.
|
|
|
21
21
|
brightest, sharpest thing in the shot? Then roughness is doing the styling instead of the art.
|
|
22
22
|
|
|
23
23
|
How to judge it: shoot at the game's real camera (`threedog shot /your-page --gpu`). The bands, terminator or shade color should still be
|
|
24
|
-
visible at that distance; if a technique only shows in a close-up, it is not part of the game's
|
|
25
|
-
areas in the shot's
|
|
24
|
+
visible at that distance; if a technique only shows in a close-up, it is not part of the game's picture. A very low contrast with no clipped
|
|
25
|
+
areas in the shot's picture numbers usually means the fill light (hemisphere, environment) is as strong as the sun.
|
|
26
26
|
|
|
27
27
|
## Plain three.js
|
|
28
28
|
- Toon: [MeshToonMaterial](https://threejs.org/docs/#api/en/materials/MeshToonMaterial) with a `gradientMap` (a small `DataTexture`,
|
|
@@ -45,31 +45,30 @@ areas in the shot's look numbers usually means the fill light (hemisphere, envir
|
|
|
45
45
|
- **Pixel art**: two or three hard bands from a palette, nearest-filtered ramp. Same cost as toon.
|
|
46
46
|
|
|
47
47
|
## The engine helper (optional convenience)
|
|
48
|
-
Copy `shading.js` into a game; `main.js`
|
|
48
|
+
Copy `shading.js` into a game; `main.js` (shapes) and `picture/` (this page's whole picture, plain three.js; knobs in `picture/palette.js`) are only the demo. Every route is a patch in three's own lit material
|
|
49
49
|
(`applyEffects(material, { patches })`, slots `lightsPars` and `lighting`, recipe 43). The patch runs after three has summed the lights,
|
|
50
50
|
re-reads the sun's direction and its shadow-map value, and changes only the sun's share (or the ambient's color). Because the light loop is
|
|
51
|
-
untouched, the materials keep
|
|
51
|
+
untouched, the materials keep your sun and shadows, hemisphere and point lights, fog, cloud shadows and seasons. Nothing edits
|
|
52
52
|
`THREE.ShaderChunk`, and every number is a uniform, so materials that differ only in values share one shader program.
|
|
53
53
|
Functions: `rampTexture(stops)`, `toonMaterial({ color, ramp, bands, soft, shade })`, `toonPatch(...)` for your own material,
|
|
54
54
|
`painterlyMaterial({ color, wrap, terminator, shadow })`, `stylizedPbrMaterial({ color, roughness, lift })`.
|
|
55
55
|
|
|
56
|
-
| route | what the patch does | knobs (`
|
|
56
|
+
| route | what the patch does | knobs (`picture/palette.js`) |
|
|
57
57
|
|---|---|---|
|
|
58
|
-
| toon, ramp texture | sun share (n.l times shadow, 0-1) looks up a 1-D texture; the texture can carry color per band | `
|
|
59
|
-
| toon, smoothstep | the same share cut into `bands` levels by smoothstep, `soft` = border width | `
|
|
60
|
-
| both toons | the dark band's ambient leans to `shade` at the same brightness | `
|
|
61
|
-
| painterly | wrapped diffuse (`threedogWrapDiffuse`), a warm band at the terminator, shade and cast shadow lean to a cool hue (`threedogShadowTint`) | `
|
|
62
|
-
| stylized PBR | MeshStandardMaterial with roughness and albedo chosen per surface, and here a floor under the ambient so shade keeps some color | `
|
|
58
|
+
| toon, ramp texture | sun share (n.l times shadow, 0-1) looks up a 1-D texture; the texture can carry color per band | `TOON_RAMP` stops |
|
|
59
|
+
| toon, smoothstep | the same share cut into `bands` levels by smoothstep, `soft` = border width | `TOON_BANDS` |
|
|
60
|
+
| both toons | the dark band's ambient leans to `shade` at the same brightness | `TOON_SHADE` |
|
|
61
|
+
| painterly | wrapped diffuse (`threedogWrapDiffuse`), a warm band at the terminator, shade and cast shadow lean to a cool hue (`threedogShadowTint`) | `PAINTERLY` |
|
|
62
|
+
| stylized PBR | MeshStandardMaterial with roughness and albedo chosen per surface, and here a floor under the ambient so shade keeps some color | `PBR_ROUGHNESS`, `PBR_LIFT` |
|
|
63
63
|
|
|
64
64
|
Cost: a few ALU operations per pixel and one texture read for the ramp route; no extra draw, render target or pass. The shadow value is read
|
|
65
65
|
once more per pixel (three has already read it once), which is the most expensive part on large shadow kernels.
|
|
66
66
|
|
|
67
67
|
Rules (correctness):
|
|
68
|
-
- Patch, do not replace: keep three's light loop (`lighting` slot, not `lightingModel`) so
|
|
68
|
+
- Patch, do not replace: keep three's light loop (`lighting` slot, not `lightingModel`) so shadows, fog and lights keep working.
|
|
69
69
|
- Index 0 of `directionalLights` is the sun only when it is the shadow-casting light (three sorts casters first). A game with several
|
|
70
70
|
shadow-casting directional lights must pick its own.
|
|
71
|
-
- The demo
|
|
72
|
-
them with `engine.look.lights.manual(...)` first (recipe 52).
|
|
71
|
+
- The demo's lights are its own (`picture/lights.js`, `createEngine({ lights: false })`): the sun has to be a shadow-casting light for the patches to read its shadow map. Its `RoomEnvironment` is plain three.js too; the plastic column's hot spots are that room.
|
|
73
72
|
|
|
74
73
|
Sources: written for this engine from common practice: half-Lambert / wrapped diffuse (Valve, "Shading in Valve's Source Engine", 2006),
|
|
75
74
|
toon ramps (three.js `MeshToonMaterial` and its examples), colored shadows and terminator color as taught in traditional painting. No code copied.
|
|
@@ -1,46 +1,15 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
// Stylized shading demo (page /technique-shading.html): the same neutral models (a house block, a character-sized capsule, a ball, a ground
|
|
3
3
|
// tile) five times, one column per route: toon by ramp texture, toon by smoothstep, painterly soft light, stylized PBR, and the "plastic"
|
|
4
|
-
// mistake for comparison.
|
|
5
|
-
// Test page for tests/specs/technique-
|
|
4
|
+
// mistake for comparison. Shapes only here; the whole picture, sun with its shadow map included, is picture/.
|
|
5
|
+
// Test page for tests/specs/technique-pictures.mjs: window.techTest = { THREE, columns, sun, hemi }.
|
|
6
6
|
import { createEngine, fixedCamera, THREE } from 'threedog';
|
|
7
|
-
import {
|
|
7
|
+
import { createPicture } from './picture/index.js';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
sun: [36, 44, -8], sunIntensity: 3.2, hemi: 0.35, env: 0.35, // sun offset from its target (direction only); key / fill strengths: the fill sets how dark shade gets
|
|
12
|
-
// neutral bases, the same in every column so only the shading differs (sRGB hex)
|
|
13
|
-
colors: { wall: 0xc2bcb2, roof: 0x7d756e, body: 0xb0b2b8, ball: 0xaaa59d, tile: 0x96948f },
|
|
14
|
-
toonRamp: [[0, 0.0], [0.12, 0.45], [0.55, 0xfff2df]], // [sun share where a band starts, light]: shade, mid band, a warm lit band
|
|
15
|
-
toonBands: { bands: 3, soft: 0.02 },
|
|
16
|
-
toonShade: { shade: 0x6a78b8, shadeStrength: 0.35 }, // the dark band leans blue-violet
|
|
17
|
-
painterly: { wrap: 0.5, terminator: 0xff7a45, terminatorStrength: 0.35, shadow: 0x5a6fb0, shadowStrength: 0.45 },
|
|
18
|
-
pbrRoughness: { wall: 0.9, roof: 0.75, body: 0.6, ball: 0.45, tile: 0.95 }, // designed per surface, never one value for all
|
|
19
|
-
pbrLift: 0.12,
|
|
20
|
-
plasticRoughness: 0.2, // the mistake: one low roughness everywhere
|
|
21
|
-
spacing: 3.5,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), ui: { loading: false }, saveKey: 'threedog-technique-shading' });
|
|
25
|
-
const sky = new THREE.Color(0xa3acb6);
|
|
26
|
-
engine.scene.background = sky;
|
|
27
|
-
engine.scene.fog = new THREE.Fog(sky, 30, 90);
|
|
28
|
-
// no sky drives the sun here, so its position is a plain write (with a sky: look.lights.manual('sun.direction') first). From the right, lower than the default, so every model shows a lit side, a turn and a shaded side
|
|
29
|
-
engine.lights.sun.position.copy(engine.lights.sun.target.position).add(new THREE.Vector3(...PARAMS.sun));
|
|
30
|
-
engine.lights.sun.intensity = PARAMS.sunIntensity; // plain three.js writes: with no sky nothing else drives these
|
|
31
|
-
engine.lights.hemi.intensity = PARAMS.hemi;
|
|
32
|
-
engine.look.lights.set({ env: { intensity: PARAMS.env } }); // the neutral room reflection Standard materials get; strong, it flattens PBR shade // plain three.js fog: every route's material keeps three's fog chunk
|
|
9
|
+
const SPACING = 3.5;
|
|
10
|
+
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, ui: { loading: false }, saveKey: 'threedog-technique-shading' });
|
|
33
11
|
engine.use(fixedCamera({ shots: { main: { position: [0, 5.2, 13.5], lookAt: [0, 0.9, 0], fov: 45 } }, start: 'main' }));
|
|
34
|
-
|
|
35
|
-
const ramp = rampTexture(/** @type {[number, number][]} */ (PARAMS.toonRamp));
|
|
36
|
-
/** @type {Record<string, (part: keyof typeof PARAMS.colors) => THREE.Material>} */
|
|
37
|
-
const routes = {
|
|
38
|
-
'toon (ramp texture)': part => toonMaterial({ color: PARAMS.colors[part], ramp, ...PARAMS.toonShade }),
|
|
39
|
-
'toon (smoothstep)': part => toonMaterial({ color: PARAMS.colors[part], ...PARAMS.toonBands, ...PARAMS.toonShade }),
|
|
40
|
-
painterly: part => painterlyMaterial({ color: PARAMS.colors[part], ...PARAMS.painterly }),
|
|
41
|
-
'stylized PBR': part => stylizedPbrMaterial({ color: PARAMS.colors[part], roughness: PARAMS.pbrRoughness[part], lift: PARAMS.pbrLift }),
|
|
42
|
-
'plastic (mistake)': part => new THREE.MeshStandardMaterial({ color: PARAMS.colors[part], roughness: PARAMS.plasticRoughness, metalness: 0 }),
|
|
43
|
-
};
|
|
12
|
+
const picture = createPicture(engine);
|
|
44
13
|
|
|
45
14
|
/** A gable roof as an extruded triangle, w wide, d deep, h high */
|
|
46
15
|
function roofGeometry(w, d, h) {
|
|
@@ -62,10 +31,10 @@ function place(g, m, at) {
|
|
|
62
31
|
engine.scene.add(mesh);
|
|
63
32
|
return mesh;
|
|
64
33
|
}
|
|
65
|
-
const names = Object.keys(routes), columns = [];
|
|
34
|
+
const names = Object.keys(picture.routes), columns = [];
|
|
66
35
|
names.forEach((name, i) => {
|
|
67
|
-
const x = (i - (names.length - 1) / 2) *
|
|
68
|
-
const mats = Object.fromEntries(
|
|
36
|
+
const x = (i - (names.length - 1) / 2) * SPACING, make = picture.routes[name];
|
|
37
|
+
const mats = Object.fromEntries(picture.parts.map(p => [p, make(/** @type {any} */ (p))]));
|
|
69
38
|
place(geo.tile, mats.tile, [x, 0.03, 0]);
|
|
70
39
|
const house = place(geo.wall, mats.wall, [x, 0.86, -1.2]);
|
|
71
40
|
place(geo.roof, mats.roof, [x, 1.66, -1.2]);
|
|
@@ -75,7 +44,7 @@ names.forEach((name, i) => {
|
|
|
75
44
|
columns.push({ name, x, house, body, ball, shadowSpot: [x - 1.35, 0.06, -0.6], openSpot: [x + 1.2, 0.06, 1.9] });
|
|
76
45
|
});
|
|
77
46
|
// a darker ground around the tiles so their edges read
|
|
78
|
-
const ground = new THREE.Mesh(new THREE.PlaneGeometry(200, 200),
|
|
47
|
+
const ground = new THREE.Mesh(new THREE.PlaneGeometry(200, 200), picture.ground);
|
|
79
48
|
ground.rotation.x = -Math.PI / 2; ground.receiveShadow = true;
|
|
80
49
|
engine.scene.add(ground);
|
|
81
50
|
|
|
@@ -89,5 +58,5 @@ if (labels) {
|
|
|
89
58
|
}));
|
|
90
59
|
}
|
|
91
60
|
|
|
92
|
-
Object.assign(window, { engine, techTest: { THREE, columns, sun:
|
|
61
|
+
Object.assign(window, { engine, techTest: { THREE, columns, sun: picture.sun, hemi: picture.hemi } });
|
|
93
62
|
engine.start();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The picture of the shading demo: wiring only. Nothing here moves, so there is no onRender; a picture with signals would call each part from one.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
import { COLORS, FOG, PARTS, TONE_MAPPING } from './palette.js';
|
|
5
|
+
import { createLights } from './lights.js';
|
|
6
|
+
import { createMaterials } from './materials.js';
|
|
7
|
+
|
|
8
|
+
/** Returns { routes, ground, parts, sun, hemi } @param {any} engine */
|
|
9
|
+
export function createPicture(engine) {
|
|
10
|
+
engine.renderer.toneMapping = TONE_MAPPING;
|
|
11
|
+
engine.scene.background = new THREE.Color(COLORS.sky);
|
|
12
|
+
engine.scene.fog = new THREE.Fog(COLORS.sky, FOG.near, FOG.far); // every route keeps three's fog chunk
|
|
13
|
+
return { ...createLights(engine), ...createMaterials(), parts: Object.keys(PARTS) };
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// One sun, one ambient and a room to reflect, all fixed: the scene never changes, so the page has no signals to read.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
|
|
5
|
+
import { COLORS, LIGHT } from './palette.js';
|
|
6
|
+
|
|
7
|
+
/** @param {any} engine */
|
|
8
|
+
export function createLights(engine) {
|
|
9
|
+
const { scene, renderer } = engine;
|
|
10
|
+
const hemi = new THREE.HemisphereLight(0xffffff, COLORS.shade, LIGHT.ambient);
|
|
11
|
+
const sun = new THREE.DirectionalLight(0xffffff, LIGHT.sunIntensity);
|
|
12
|
+
sun.position.set(LIGHT.sun[0], LIGHT.sun[1], LIGHT.sun[2]);
|
|
13
|
+
sun.castShadow = true; // index 0 of three's lit directional lights, which is the one shading.js bands
|
|
14
|
+
sun.shadow.mapSize.setScalar(engine.tier === 'low' ? 1024 : 2048);
|
|
15
|
+
Object.assign(sun.shadow.camera, { left: -30, right: 30, top: 30, bottom: -30, near: 1, far: 250 });
|
|
16
|
+
sun.shadow.bias = -0.0001; sun.shadow.normalBias = 0.03; sun.shadow.radius = 3;
|
|
17
|
+
scene.add(hemi, sun, sun.target);
|
|
18
|
+
const pmrem = new THREE.PMREMGenerator(renderer);
|
|
19
|
+
scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
|
|
20
|
+
scene.environmentIntensity = LIGHT.room;
|
|
21
|
+
pmrem.dispose();
|
|
22
|
+
return { sun, hemi };
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Materials by name: one maker per route, called with a part's name, so a column differs from the next only here.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
import { rampTexture, toonMaterial, painterlyMaterial, stylizedPbrMaterial } from '../shading.js';
|
|
5
|
+
import { COLORS, PARTS, PBR_LIFT, PBR_ROUGHNESS, PAINTERLY, PLASTIC_ROUGHNESS, TOON_BANDS, TOON_RAMP, TOON_SHADE } from './palette.js';
|
|
6
|
+
|
|
7
|
+
export function createMaterials() {
|
|
8
|
+
const ramp = rampTexture(TOON_RAMP);
|
|
9
|
+
/** @type {Record<string, (part: keyof typeof PARTS) => THREE.Material>} */
|
|
10
|
+
const routes = {
|
|
11
|
+
'toon (ramp texture)': part => toonMaterial({ color: PARTS[part], ramp, ...TOON_SHADE }),
|
|
12
|
+
'toon (smoothstep)': part => toonMaterial({ color: PARTS[part], ...TOON_BANDS, ...TOON_SHADE }),
|
|
13
|
+
painterly: part => painterlyMaterial({ color: PARTS[part], ...PAINTERLY }),
|
|
14
|
+
'stylized PBR': part => stylizedPbrMaterial({ color: PARTS[part], roughness: PBR_ROUGHNESS[part], lift: PBR_LIFT }),
|
|
15
|
+
'plastic (mistake)': part => new THREE.MeshStandardMaterial({ color: PARTS[part], roughness: PLASTIC_ROUGHNESS, metalness: 0 }),
|
|
16
|
+
};
|
|
17
|
+
return { routes, ground: new THREE.MeshLambertMaterial({ color: COLORS.ground }) };
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Shading demo palette: neutral bases, the same in every column so only the shading differs, and the values each route takes.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
|
|
5
|
+
/** sRGB hex per model part; ground and sky around the columns */
|
|
6
|
+
export const PARTS = { wall: 0xc2bcb2, roof: 0x7d756e, body: 0xb0b2b8, ball: 0xaaa59d, tile: 0x96948f };
|
|
7
|
+
export const COLORS = { ground: 0x6c6a66, sky: 0xa3acb6, shade: 0xb0b0b0 };
|
|
8
|
+
export const TOON_RAMP = /** @type {[number, number][]} */ ([[0, 0.0], [0.12, 0.45], [0.55, 0xfff2df]]); // [sun share where a band starts, light]: shade, mid band, a warm lit band
|
|
9
|
+
export const TOON_BANDS = { bands: 3, soft: 0.02 };
|
|
10
|
+
export const TOON_SHADE = { shade: 0x6a78b8, shadeStrength: 0.35 }; // the dark band leans blue-violet
|
|
11
|
+
export const PAINTERLY = { wrap: 0.5, terminator: 0xff7a45, terminatorStrength: 0.35, shadow: 0x5a6fb0, shadowStrength: 0.45 };
|
|
12
|
+
export const PBR_ROUGHNESS = { wall: 0.9, roof: 0.75, body: 0.6, ball: 0.45, tile: 0.95 }; // designed per surface, never one value for all
|
|
13
|
+
export const PBR_LIFT = 0.12;
|
|
14
|
+
export const PLASTIC_ROUGHNESS = 0.2; // the mistake: one low roughness everywhere
|
|
15
|
+
/** sun: offset from its target (direction only), from the right and behind, so every model shows a lit side, a turn and a shaded side. ambient sets how dark shade
|
|
16
|
+
* gets; room: the reflection Standard materials get, which is what the plastic column's hot spots are made of (strong, it flattens PBR shade) */
|
|
17
|
+
export const LIGHT = { sun: [36, 44, -8], sunIntensity: 3.2, ambient: 0.35, room: 0.35 };
|
|
18
|
+
export const FOG = { near: 30, far: 90 };
|
|
19
|
+
export const TONE_MAPPING = THREE.AgXToneMapping;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
// Stylized shading: three routes that reshape how light lands on a surface, all as patches on three's own lit materials, so every route still
|
|
3
|
-
// takes the
|
|
4
|
-
// Copy this file into a game (for example src/
|
|
3
|
+
// takes the game's sun, its shadow map, hemisphere / point lights and fog (nothing here replaces the light loop or edits ShaderChunk).
|
|
4
|
+
// Copy this file into a game (for example src/picture/shading.js); it imports only three and threedog. Numbers live in uniforms, so materials
|
|
5
5
|
// that differ only in values share one shader program.
|
|
6
6
|
import * as THREE from 'three';
|
|
7
7
|
import { applyEffects } from 'threedog';
|
|
@@ -60,7 +60,7 @@ off once) and how much darker the shadowed areas are, with the light parameters
|
|
|
60
60
|
- Shadow: `renderer.shadowMap.type` (`BasicShadowMap`, `PCFShadowMap`, `VSMShadowMap`), `light.shadow.radius`, `shadow.blurSamples` (VSM),
|
|
61
61
|
`shadow.mapSize`, `shadow.camera` bounds, `shadow.bias`, `shadow.normalBias`
|
|
62
62
|
([LightShadow](https://threejs.org/docs/#api/en/lights/shadows/LightShadow), [webgl_shadowmap_vsm](https://threejs.org/examples/#webgl_shadowmap_vsm)).
|
|
63
|
-
- Large views: `
|
|
63
|
+
- Large views: `engine.shadows.cascades(light, { count: 3 })` (recipe 45).
|
|
64
64
|
- Debugging the box: `CameraHelper(light.shadow.camera)` ([CameraHelper](https://threejs.org/docs/#api/en/helpers/CameraHelper)).
|
|
65
65
|
|
|
66
66
|
## Style routes
|
|
@@ -73,10 +73,11 @@ off once) and how much darker the shadowed areas are, with the light parameters
|
|
|
73
73
|
- **Noir / horror**: low or back key, very low fill, little color in the fill; the silhouette carries the scene.
|
|
74
74
|
- **Pixel art**: `basic` shadows, hard and aliased on purpose, with a map sized so a texel matches the art's pixel.
|
|
75
75
|
|
|
76
|
-
## The
|
|
77
|
-
`threedog examples pull sun-and-key-light` copies `keyLight.js` and this README into the game
|
|
78
|
-
key and fill colors and strengths
|
|
79
|
-
`fitSunShadow(
|
|
76
|
+
## The helper (optional convenience)
|
|
77
|
+
`threedog examples pull sun-and-key-light` copies `keyLight.js` and this README into the game. It writes plain three.js on your own lights:
|
|
78
|
+
`applyKeyFill({ sun, hemi, scene }, route, { tint })` sets key and fill colors and strengths, `aimSun(sun, { elevation, azimuth, camera })` places
|
|
79
|
+
the sun relative to the camera, `fitSunShadow(sun, { extent, biasCm, normalBias })` fits the box and converts the bias from centimeters.
|
|
80
|
+
`applyKeyFill` and `fitSunShadow` return `{ remove() }`, which writes back the values they found. The demo's own picture is in `picture/`.
|
|
80
81
|
|
|
81
82
|
The three routes, side by side:
|
|
82
83
|
|
|
@@ -87,10 +88,10 @@ The three routes, side by side:
|
|
|
87
88
|
| fill (hemi + env) | 0.35 + 0.1, blue | 1.5 + 0.3, pale gray-blue | 0.55 + 0.1, blue |
|
|
88
89
|
| shadow | pcf, radius 1 | vsm, radius 14 | pcf, radius 2 |
|
|
89
90
|
| measured ground lit : shadow (linear light) | about 4.3 : 1 | about 1.25 : 1 | about 1.9 : 1 |
|
|
90
|
-
|
|
|
91
|
+
| picture numbers (`threedog shot`) | luminance 0.60, contrast 0.07 | 0.63, 0.06 | 0.51, 0.12 |
|
|
91
92
|
|
|
92
93
|
The measured ratios are what this scene gives, not targets. The golden route has a lower ratio *on the ground* than noon (the key arrives at
|
|
93
|
-
13°) and a much higher one on walls facing the sun. The light-number estimate in `
|
|
94
|
+
13°) and a much higher one on walls facing the sun. The light-number estimate in `picture/lights.js` (`ratio`) overstates every ratio because the room
|
|
94
95
|
environment adds more fill than its intensity number suggests. `tint=0` is a neutral studio, `tint=1` a natural afternoon, `tint=1.5` a
|
|
95
96
|
painterly or stylized look.
|
|
96
97
|
|
|
@@ -100,32 +101,29 @@ Shadow softness and cost (GPU path):
|
|
|
100
101
|
or a smaller map. Cost grows little with radius.
|
|
101
102
|
- `vsm` + `radius` + `blurSamples`: the softest, wide penumbras for overcast or stylized looks; a blur pass and float targets (the engine's
|
|
102
103
|
rough estimate: 1.6x the pcf shadow pass). Can show light bleeding where two casters overlap.
|
|
103
|
-
- This yard fits +-12 m, 1.2 cm per texel (
|
|
104
|
+
- This yard fits +-12 m, 1.2 cm per texel (one texel is `2 x extent / mapSize`).
|
|
104
105
|
- Cost scales with the casters drawn into the map (each shadow-casting light draws them once more) and the map's pixel count.
|
|
105
106
|
`engine.budget.byTag()` and `threedog stress` show it for your scene; this example does not measure milliseconds.
|
|
106
107
|
|
|
107
|
-
Cascades vs one fitted shadow: one fitted box (this example, `
|
|
108
|
+
Cascades vs one fitted shadow: one fitted box (this example, `extent` around the play area) is the sharpest and cheapest when
|
|
108
109
|
the camera sees a bounded area: a room, an arena, a top-down board. A large open world with a free camera wants cascades (`?cascades=3`,
|
|
109
|
-
`
|
|
110
|
+
`engine.shadows.cascades(sun, { count: 3, maxFar })`, recipe 45): sharp near the camera, coarse far away, at the cost of drawing the casters once per
|
|
110
111
|
cascade and a recompile when switched. Before adding cascades, try a smaller `extent` or `maxFar`.
|
|
111
112
|
|
|
112
113
|
Lessons from real demos:
|
|
113
|
-
- **Bias too large
|
|
114
|
-
|
|
115
|
-
most of the work against acne. Try `?bias=25` and look at the small cube and ball: their shadows detach or vanish.
|
|
114
|
+
- **Bias too large removes contact shadows.** A bias of about 25 cm in world depth takes the shadow off the base of anything resting on the
|
|
115
|
+
ground. About 2 cm is plenty here, with `normalBias` (meters) doing most of the work against acne. Try `?bias=25` and look at the small cube and ball: their shadows detach or vanish.
|
|
116
116
|
- **Strong hemisphere + environment washes shadows out.** The shot check reports "shadows on but none measurable". Lower the fill
|
|
117
|
-
(`
|
|
117
|
+
(`hemi.intensity`, `scene.environmentIntensity`) before blaming the shadow settings.
|
|
118
118
|
- **A +-70 m shadow box blurs small objects in a compact scene.** Try `?extent=70`: the 10 cm cube's shadow turns into a smudge. Fit the box.
|
|
119
119
|
|
|
120
120
|
Rules (correctness):
|
|
121
|
-
- The
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
-
|
|
126
|
-
|
|
127
|
-
- `PCFSoftShadowMap` is gone in three 0.187 (three warns and uses PCF). Soft PCF edges come from `radius`; the engine's types are
|
|
128
|
-
`basic`, `pcf`, `vsm` (`look.shadow.set({ type })`). Switching the type recompiles every lit material: do it on a settings screen.
|
|
121
|
+
- The lights are yours: `createEngine({ lights: false })`, your own `DirectionalLight` and `HemisphereLight`, nothing else writes them. A sun's
|
|
122
|
+
direction is `sun.position` relative to `sun.target`; keep the target in the scene (`scene.add(sun.target)`) so a moved target takes effect.
|
|
123
|
+
- The shadow box centers on `sun.target`: a fixed sun over a compact scene keeps it there (here the yard); a moving player needs the target to follow.
|
|
124
|
+
- After writing the box call `sun.shadow.camera.updateProjectionMatrix()`: three.js does not do it for a directional light.
|
|
125
|
+
- `PCFSoftShadowMap` is gone in three 0.187 (three warns and uses PCF). Soft PCF edges come from `radius`; the types are
|
|
126
|
+
`BasicShadowMap`, `PCFShadowMap`, `VSMShadowMap` (`renderer.shadowMap.type`). Switching the type recompiles every lit material: do it on a settings screen.
|
|
129
127
|
- `bias` is in the shadow camera's 0-1 depth, so its size in meters is `bias x (far - near)`. The page converts from centimeters:
|
|
130
128
|
`bias = -cm / 100 / (shadow.camera.far - shadow.camera.near)`. `normalBias` is already in meters.
|
|
131
129
|
- Do not name your page's URL parameters `time`, `view`, `weather`, `pos`, `season`, `state`, `save`, `wait` or `cutscene`: those are the
|
|
@@ -1,36 +1,43 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
// Sun and key light helpers (technique example, README.md next to this file). Imports only three
|
|
3
|
-
// Why helpers at all: aiming
|
|
4
|
-
//
|
|
2
|
+
// Sun and key light helpers (technique example, README.md next to this file). Imports only three and writes only the lights you pass in.
|
|
3
|
+
// Why helpers at all: aiming a sun relative to the camera and fitting its shadow are a few writes in a set order; written once here so a game's
|
|
4
|
+
// lighting code holds only its own numbers.
|
|
5
5
|
import * as THREE from 'three';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Key and fill from one route: the sun is the key, the hemisphere light +
|
|
9
|
-
* colors, more = pushed further apart (warm key / cool shadows).
|
|
10
|
-
*
|
|
11
|
-
* @param {any} engine
|
|
8
|
+
* Key and fill from one route: the sun is the key, the hemisphere light + the scene's environment the fill. tint 0 = white light, 1 = the route's
|
|
9
|
+
* colors, more = pushed further apart (warm key / cool shadows). Returns { remove() }: it writes back the values it found.
|
|
10
|
+
* @param {{ sun: THREE.DirectionalLight, hemi: THREE.HemisphereLight, scene?: THREE.Scene }} lights scene: for environmentIntensity; leave it out without an environment
|
|
12
11
|
* @param {{ key: { intensity: number, color: string }, fill: { intensity: number, color: string, ground: string }, env: number }} route
|
|
13
|
-
* @param {{ tint?: number
|
|
12
|
+
* @param {{ tint?: number }} [o]
|
|
14
13
|
*/
|
|
15
|
-
export function applyKeyFill(
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
export function applyKeyFill({ sun, hemi, scene }, route, { tint = 1 } = {}) {
|
|
15
|
+
const saved = { key: sun.intensity, keyColor: sun.color.clone(), fill: hemi.intensity, fillColor: hemi.color.clone(), ground: hemi.groundColor.clone(), env: scene?.environmentIntensity };
|
|
16
|
+
const white = new THREE.Color('#ffffff');
|
|
17
|
+
sun.intensity = route.key.intensity;
|
|
18
|
+
sun.color.copy(white).lerp(new THREE.Color(route.key.color), tint);
|
|
19
|
+
hemi.intensity = route.fill.intensity;
|
|
20
|
+
hemi.color.copy(white).lerp(new THREE.Color(route.fill.color), tint);
|
|
21
|
+
hemi.groundColor.set(route.fill.ground);
|
|
22
|
+
if (scene) scene.environmentIntensity = route.env;
|
|
23
|
+
return {
|
|
24
|
+
remove() {
|
|
25
|
+
sun.intensity = saved.key; sun.color.copy(saved.keyColor);
|
|
26
|
+
hemi.intensity = saved.fill; hemi.color.copy(saved.fillColor); hemi.groundColor.copy(saved.ground);
|
|
27
|
+
if (scene) scene.environmentIntensity = /** @type {number} */ (saved.env);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
/**
|
|
25
33
|
* Aim the sun for the composition. azimuth is measured around `target` from the camera: 0 = behind the camera (front light), 90 = from the
|
|
26
|
-
* side, 180 = facing the camera (back light).
|
|
27
|
-
*
|
|
28
|
-
* @param {
|
|
34
|
+
* side, 180 = facing the camera (back light). Writes only the direction; color and intensity stay where they were. Returns the unit direction
|
|
35
|
+
* toward the sun.
|
|
36
|
+
* @param {THREE.DirectionalLight} sun
|
|
29
37
|
* @param {{ elevation: number, azimuth: number, camera: number[], target?: number[] }} o degrees; camera / target positions
|
|
30
38
|
*/
|
|
31
|
-
export function aimSun(
|
|
32
|
-
|
|
33
|
-
const sun = engine.lights.sun, t = new THREE.Vector3(target[0], target[1], target[2]);
|
|
39
|
+
export function aimSun(sun, { elevation, azimuth, camera, target = [0, 0, 0] }) {
|
|
40
|
+
const t = new THREE.Vector3(target[0], target[1], target[2]);
|
|
34
41
|
const toCam = new THREE.Vector3(camera[0] - t.x, 0, camera[2] - t.z).normalize();
|
|
35
42
|
const el = THREE.MathUtils.degToRad(elevation);
|
|
36
43
|
const h = toCam.applyAxisAngle(new THREE.Vector3(0, 1, 0), THREE.MathUtils.degToRad(azimuth));
|
|
@@ -41,13 +48,24 @@ export function aimSun(engine, { elevation, azimuth, camera, target = [0, 0, 0]
|
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
/**
|
|
44
|
-
* One shadow box fitted to a compact scene
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* @param {
|
|
48
|
-
* @param {{ extent: number, biasCm?: number, normalBias?: number, owner?: string } & Record<string, any>} o
|
|
51
|
+
* One shadow box fitted to a compact scene, centered on the sun's target. biasCm is the depth bias in centimeters: three adds bias in the shadow
|
|
52
|
+
* camera's 0-1 depth, i.e. a world offset of bias x (far - near). Returns { remove() }: it writes back the values it found.
|
|
53
|
+
* @param {THREE.DirectionalLight} sun
|
|
54
|
+
* @param {{ extent: number, biasCm?: number, normalBias?: number, mapSize?: number, radius?: number, blurSamples?: number }} o
|
|
49
55
|
*/
|
|
50
|
-
export function fitSunShadow(
|
|
51
|
-
const
|
|
52
|
-
|
|
56
|
+
export function fitSunShadow(sun, { extent, biasCm = 2, normalBias = 0.02, mapSize = sun.shadow.mapSize.x, radius = sun.shadow.radius, blurSamples = sun.shadow.blurSamples }) {
|
|
57
|
+
const s = sun.shadow, c = s.camera;
|
|
58
|
+
const write = (/** @type {number} */ half, /** @type {number} */ size, /** @type {Partial<THREE.DirectionalLightShadow>} */ values) => {
|
|
59
|
+
Object.assign(c, { left: -half, right: half, top: half, bottom: -half });
|
|
60
|
+
c.updateProjectionMatrix(); // three.js does not do this for a DirectionalLight's shadow camera
|
|
61
|
+
Object.assign(s, values);
|
|
62
|
+
if (s.mapSize.x !== size) { // a map keeps the size it was made with: drop it and three.js makes the new one
|
|
63
|
+
s.mapSize.setScalar(size);
|
|
64
|
+
s.map?.dispose();
|
|
65
|
+
s.map = null;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const before = c.right, beforeSize = s.mapSize.x, saved = { bias: s.bias, normalBias: s.normalBias, radius: s.radius, blurSamples: s.blurSamples };
|
|
69
|
+
write(extent, mapSize, { bias: -biasCm / 100 / (c.far - c.near), normalBias, radius, blurSamples });
|
|
70
|
+
return { remove() { write(before, beforeSize, saved); } };
|
|
53
71
|
}
|
|
@@ -6,66 +6,27 @@
|
|
|
6
6
|
// &sun=front|side|back|low|top override the route's sun direction (relative to the camera)
|
|
7
7
|
// &tint=0..1.5 how far key and fill are pushed apart in color (warm key / cool shadows); default per route
|
|
8
8
|
// &shadow=basic|pcf|vsm &radius=N &extent=M &bias=cm &cascades=1..4 shadow filter, softness, box half size, depth bias in cm, cascades
|
|
9
|
-
// Test page for tests/specs/techniques-light.mjs: window.sunTest = { THREE, route,
|
|
10
|
-
import { createEngine,
|
|
11
|
-
import {
|
|
9
|
+
// Test page for tests/specs/techniques-light.mjs: window.sunTest = { THREE, route, picture, points }. Shapes only here; the whole picture is picture/.
|
|
10
|
+
import { createEngine, fixedCamera, THREE } from 'threedog';
|
|
11
|
+
import { createPicture } from './picture/index.js';
|
|
12
|
+
import { DIRECTIONS, ROUTES, SHADOW_FIT } from './picture/palette.js';
|
|
12
13
|
|
|
13
|
-
// ---- parameters: change these ----------------------------------------------------------------------------------------------------------
|
|
14
|
-
// elevation / azimuth in degrees. azimuth is measured around the subject from the camera: 0 = sun behind the camera (front light),
|
|
15
|
-
// 90 = from the side, 180 = facing the camera (back light). key = the sun (DirectionalLight), fill = the hemisphere light + the room environment.
|
|
16
|
-
/** @type {Record<string, { elevation: number, azimuth: number, key: { intensity: number, color: string }, fill: { intensity: number, color: string, ground: string }, env: number, tint: number, backdrop: string, shadow: { type: 'basic' | 'pcf' | 'vsm', radius: number, blurSamples?: number } }>} */
|
|
17
|
-
const ROUTES = {
|
|
18
|
-
// hard noon: a strong high key, a weak blue fill -> short dark shadows, key:fill about 5:1 on the ground. Clear, graphic, a bit harsh.
|
|
19
|
-
noon: { elevation: 72, azimuth: 35, key: { intensity: 2.7, color: '#fff3e2' }, fill: { intensity: 0.35, color: '#9fbfe8', ground: '#6d675e' }, env: 0.1,
|
|
20
|
-
tint: 1, backdrop: '#a8c4e4', shadow: { type: 'pcf', radius: 1 } },
|
|
21
|
-
// soft overcast: the sky is the light. A weak key, a strong near-white fill, a very soft shadow -> key:fill about 1.4:1, forms read by
|
|
22
|
-
// gentle gradients and contact darkening only. Calm, can turn gray-flat if the fill is also dim or colorless.
|
|
23
|
-
overcast: { elevation: 58, azimuth: 40, key: { intensity: 0.9, color: '#f1f0ec' }, fill: { intensity: 1.5, color: '#d9dee6', ground: '#8b8a86' }, env: 0.3,
|
|
24
|
-
tint: 1, backdrop: '#c8cdd4', shadow: { type: 'vsm', radius: 14, blurSamples: 16 } },
|
|
25
|
-
// golden hour: a low warm key from the side, a cool fill -> long shadows, lit faces glow orange, shadows read blue, rims on round tops.
|
|
26
|
-
golden: { elevation: 13, azimuth: 50, key: { intensity: 5, color: '#ffb877' }, fill: { intensity: 0.55, color: '#7f9fdc', ground: '#5c4d40' }, env: 0.1,
|
|
27
|
-
tint: 1, backdrop: '#e6b98f', shadow: { type: 'pcf', radius: 2 } },
|
|
28
|
-
};
|
|
29
|
-
// sun direction overrides (?sun=...), same units as above
|
|
30
|
-
const DIRECTIONS = { front: [35, 0], side: [35, 90], back: [22, 165], low: [9, 60], top: [88, 0] };
|
|
31
|
-
// one shadow box fitted to this compact yard: 2048 px over +-12 m = 1.2 cm texels (the engine's open-world default +-70 m is 6.8 cm)
|
|
32
|
-
const SHADOW_FIT = { extent: 12, mapSize: 2048, bias: 2, normalBias: 0.02 }; // bias in centimeters here (converted below)
|
|
33
14
|
const CAMERA = { position: [5.5, 3.6, 7.2], lookAt: [0, 0.8, 0] };
|
|
34
|
-
// ------------------------------------------------------------------------------------------------------------------------------------------
|
|
35
|
-
|
|
36
15
|
const url = new URLSearchParams(location.search);
|
|
37
16
|
const routeName = url.get('route') ?? 'golden';
|
|
38
17
|
const route = ROUTES[routeName];
|
|
39
18
|
if (!route) throw new Error(`?route=${routeName}: use one of ${Object.keys(ROUTES).join(', ')}`);
|
|
40
19
|
const num = (/** @type {string} */ k, /** @type {number} */ d) => (url.has(k) ? Number(url.get(k)) : d);
|
|
41
20
|
const [elevation, azimuth] = url.has('sun') ? DIRECTIONS[/** @type {keyof typeof DIRECTIONS} */ (url.get('sun'))] ?? [route.elevation, route.azimuth] : [route.elevation, route.azimuth];
|
|
42
|
-
const tint = num('tint', route.tint);
|
|
43
21
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
engine.use(sky({ time: '12:00' }));
|
|
22
|
+
// no sky module: a route fixes the sun, so nothing here needs the time of day
|
|
23
|
+
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, ui: { loading: false }, saveKey: 'threedog-sun-key' });
|
|
47
24
|
engine.use(fixedCamera({ position: CAMERA.position, lookAt: CAMERA.lookAt }));
|
|
25
|
+
const picture = createPicture(engine, { route, tint: num('tint', route.tint), elevation, azimuth, camera: CAMERA.position, shadow: {
|
|
26
|
+
type: url.get('shadow') ?? route.shadow.type, radius: num('radius', route.shadow.radius), extent: num('extent', SHADOW_FIT.extent), biasCm: num('bias', SHADOW_FIT.bias),
|
|
27
|
+
normalBias: SHADOW_FIT.normalBias, mapSize: SHADOW_FIT.mapSize, cascades: num('cascades', 1), ...(route.shadow.blurSamples ? { blurSamples: route.shadow.blurSamples } : {}),
|
|
28
|
+
} }), { mat } = picture;
|
|
48
29
|
|
|
49
|
-
// ---- key and fill: the override layer of look.lights (the sun is exactly this, whatever the keyframes say); keyLight.js ----
|
|
50
|
-
applyKeyFill(engine, route, { tint, owner: 'technique' });
|
|
51
|
-
// a flat backdrop in the fill color and fog that fades the ground into it: no dome gradient or sun disc at the wrong place
|
|
52
|
-
engine.look.sky.set({ backdrop: route.backdrop }, { owner: 'technique' });
|
|
53
|
-
engine.look.fog.set({ color: route.backdrop, far: 70 }, { owner: 'technique' });
|
|
54
|
-
|
|
55
|
-
// ---- sun direction: taken from the sky (it would follow the time of day) and aimed for the composition ----
|
|
56
|
-
const sunDir = aimSun(engine, { elevation, azimuth, camera: CAMERA.position });
|
|
57
|
-
const el = THREE.MathUtils.degToRad(elevation);
|
|
58
|
-
|
|
59
|
-
// ---- the shadow: one box fitted to the yard, centered on it (follow: false), filter from the route or the URL ----
|
|
60
|
-
const biasCm = num('bias', SHADOW_FIT.bias);
|
|
61
|
-
fitSunShadow(engine, {
|
|
62
|
-
extent: num('extent', SHADOW_FIT.extent), biasCm, normalBias: SHADOW_FIT.normalBias, mapSize: SHADOW_FIT.mapSize, cascades: num('cascades', 1),
|
|
63
|
-
type: url.get('shadow') ?? route.shadow.type, radius: num('radius', route.shadow.radius),
|
|
64
|
-
...(route.shadow.blurSamples ? { blurSamples: route.shadow.blurSamples } : {}), owner: 'technique',
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// ---- the neutral gray scene (plain three.js) ----
|
|
68
|
-
const mat = (/** @type {number} */ c, roughness = 0.85) => new THREE.MeshStandardMaterial({ color: c, roughness });
|
|
69
30
|
const add = (/** @type {THREE.BufferGeometry} */ g, /** @type {THREE.Material} */ m, /** @type {number[]} */ [x, y, z]) => {
|
|
70
31
|
const mesh = new THREE.Mesh(g, m);
|
|
71
32
|
mesh.position.set(x, y, z);
|
|
@@ -73,23 +34,18 @@ const add = (/** @type {THREE.BufferGeometry} */ g, /** @type {THREE.Material} *
|
|
|
73
34
|
engine.scene.add(mesh);
|
|
74
35
|
return mesh;
|
|
75
36
|
};
|
|
76
|
-
const ground = add(new THREE.PlaneGeometry(160, 160), mat
|
|
37
|
+
const ground = add(new THREE.PlaneGeometry(160, 160), mat.ground, [0, 0, 0]);
|
|
77
38
|
ground.rotation.x = -Math.PI / 2;
|
|
78
39
|
ground.castShadow = false;
|
|
79
|
-
add(new THREE.BoxGeometry(2, 2, 2), mat
|
|
80
|
-
add(new THREE.SphereGeometry(1, 48, 32), mat
|
|
81
|
-
add(new THREE.CylinderGeometry(0.7, 0.7, 1.4, 40), mat
|
|
82
|
-
add(new THREE.CylinderGeometry(0.08, 0.08, 3, 12), mat
|
|
83
|
-
add(new THREE.CapsuleGeometry(0.28, 1.2, 8, 20), mat
|
|
84
|
-
add(new THREE.BoxGeometry(0.1, 0.1, 0.1), mat
|
|
85
|
-
add(new THREE.SphereGeometry(0.12, 24, 16), mat
|
|
40
|
+
add(new THREE.BoxGeometry(2, 2, 2), mat.cube, [-2.6, 1, -1.2]); // three faces: top / sun side / shade side read the form
|
|
41
|
+
add(new THREE.SphereGeometry(1, 48, 32), mat.ball, [0.6, 1, -2.4]); // a terminator: hard or soft depends on the route
|
|
42
|
+
add(new THREE.CylinderGeometry(0.7, 0.7, 1.4, 40), mat.drum, [2.8, 0.7, -0.6]);
|
|
43
|
+
add(new THREE.CylinderGeometry(0.08, 0.08, 3, 12), mat.pole, [0, 1.5, 1.6]); // the pole: its shadow length is the sun elevation
|
|
44
|
+
add(new THREE.CapsuleGeometry(0.28, 1.2, 8, 20), mat.figure, [-0.4, 0.88, 3.2]); // figure height (1.76 m)
|
|
45
|
+
add(new THREE.BoxGeometry(0.1, 0.1, 0.1), mat.small, [1.6, 0.05, 2.6]); // small objects: lose their contact shadow when the bias is too large
|
|
46
|
+
add(new THREE.SphereGeometry(0.12, 24, 16), mat.small, [2.1, 0.12, 2.2]);
|
|
86
47
|
|
|
87
|
-
// key:fill from the light numbers: a surface facing the sun gets key + fill, one in shadow only fill. The ground gets the key at sin(elevation),
|
|
88
|
-
// which is why a low sun darkens the ground and brightens the walls facing it. A rough guide only: the room environment adds more fill than its
|
|
89
|
-
// intensity number says, so the measured ratio is lower (README "Measured"); read the real one in a shot
|
|
90
|
-
const fillUp = route.fill.intensity + route.env;
|
|
91
|
-
const ratio = { ground: +((route.key.intensity * Math.sin(el) + fillUp) / fillUp).toFixed(2), facing: +((route.key.intensity + fillUp) / fillUp).toFixed(2) };
|
|
92
48
|
// the pole base: the spec walks from it away from the sun to measure the shadow length
|
|
93
49
|
const points = { poleBase: [0, 0, 1.6] };
|
|
94
|
-
Object.assign(window, { engine, sunTest: { THREE, route: routeName, elevation, azimuth,
|
|
50
|
+
Object.assign(window, { engine, sunTest: { THREE, route: routeName, elevation, azimuth, picture, points } });
|
|
95
51
|
engine.start();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The picture of the sun-and-key-light demo: wiring only. A route is fixed, so nothing here runs per frame.
|
|
3
|
+
import { TONE_MAPPING } from './palette.js';
|
|
4
|
+
import { createLights } from './lights.js';
|
|
5
|
+
import { createMaterials } from './materials.js';
|
|
6
|
+
import { createSky } from './sky.js';
|
|
7
|
+
|
|
8
|
+
/** Returns { mat, sun, hemi, sunDir, ratio }. @param {any} engine @param {Parameters<typeof createLights>[1]} o */
|
|
9
|
+
export function createPicture(engine, o) {
|
|
10
|
+
engine.renderer.toneMapping = TONE_MAPPING;
|
|
11
|
+
createSky(engine, o.route.backdrop);
|
|
12
|
+
return { ...createMaterials(), ...createLights(engine, o) };
|
|
13
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Key, fill and the sun's shadow for one route. No signals: a route is a fixed composition, so everything is written once.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
import { applyKeyFill, aimSun, fitSunShadow } from '../keyLight.js';
|
|
5
|
+
import { SHADOW_TYPES } from './palette.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {any} engine
|
|
9
|
+
* @param {{ route: any, tint: number, elevation: number, azimuth: number, camera: number[], shadow: { type: string, extent: number, biasCm: number, normalBias: number, mapSize: number, radius: number, blurSamples?: number, cascades: number } }} o
|
|
10
|
+
*/
|
|
11
|
+
export function createLights(engine, { route, tint, elevation, azimuth, camera, shadow }) {
|
|
12
|
+
const { scene, renderer } = engine, { type, cascades, ...fit } = shadow;
|
|
13
|
+
const filter = SHADOW_TYPES[/** @type {keyof typeof SHADOW_TYPES} */ (type)];
|
|
14
|
+
if (filter === undefined) throw new Error(`?shadow=${type}: use one of ${Object.keys(SHADOW_TYPES).join(', ')}`);
|
|
15
|
+
renderer.shadowMap.type = filter;
|
|
16
|
+
|
|
17
|
+
const hemi = new THREE.HemisphereLight(), sun = new THREE.DirectionalLight();
|
|
18
|
+
sun.castShadow = true;
|
|
19
|
+
Object.assign(sun.shadow.camera, { near: 1, far: 320 }); // the sun stands 160 m from its target: the box reaches past it on both sides
|
|
20
|
+
scene.add(hemi, sun, sun.target);
|
|
21
|
+
|
|
22
|
+
applyKeyFill({ sun, hemi, scene }, route, { tint });
|
|
23
|
+
const sunDir = aimSun(sun, { elevation, azimuth, camera });
|
|
24
|
+
fitSunShadow(sun, fit);
|
|
25
|
+
if (cascades > 1) engine.shadows.cascades(sun, { count: cascades });
|
|
26
|
+
|
|
27
|
+
// key:fill from the light numbers: a surface facing the sun gets key + fill, one in shadow only fill. The ground gets the key at sin(elevation),
|
|
28
|
+
// which is why a low sun darkens the ground and brightens the walls facing it. A rough guide only: the room environment adds more fill than its
|
|
29
|
+
// intensity number says, so the measured ratio is lower (README "Measured"); read the real one in a shot
|
|
30
|
+
const fillUp = route.fill.intensity + route.env, up = Math.sin(THREE.MathUtils.degToRad(elevation));
|
|
31
|
+
const ratio = { ground: +((route.key.intensity * up + fillUp) / fillUp).toFixed(2), facing: +((route.key.intensity + fillUp) / fillUp).toFixed(2) };
|
|
32
|
+
return { sun, hemi, sunDir, ratio };
|
|
33
|
+
}
|