threedog 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +81 -1
- package/README.md +21 -13
- package/core/Assets.js +23 -12
- package/core/Audio.js +1 -1
- package/core/Baked.js +14 -23
- package/core/Budget.js +2 -2
- package/core/DebugOverrides.js +33 -18
- package/core/Describe.js +10 -11
- package/core/Engine.js +50 -46
- package/core/I18n.js +2 -2
- package/core/Input.js +11 -5
- package/core/Inspect.js +6 -3
- package/core/InspectMaterials.js +2 -3
- package/core/InspectPerf.js +11 -4
- package/core/MaterialInfo.js +7 -5
- package/core/Rays.js +7 -2
- package/core/Stream.js +2 -3
- package/core/UrlState.js +49 -9
- package/core/Views.js +1 -0
- package/core/adaptive.js +2 -2
- package/core/assetEntry.js +5 -2
- package/core/assetLoad.js +13 -15
- package/core/assetManifest.js +6 -3
- package/core/assetReport.js +4 -4
- package/core/batchGroups.js +9 -1
- package/core/catalog.js +16 -3
- package/core/chunkStream.js +1 -1
- package/core/copies.js +1 -1
- package/core/debugView.js +4 -4
- package/core/describeRender.js +104 -28
- package/core/describeText.js +6 -6
- package/core/errorCodes.js +72 -45
- package/core/errorHints.js +4 -1
- package/core/errors.js +4 -4
- package/core/events.generated.js +1 -0
- package/core/gameLights.js +9 -2
- package/core/lifecycle.js +2 -4
- package/core/lightWatch.js +5 -3
- package/core/loop.js +18 -11
- package/core/math.js +7 -0
- package/core/moduleSlots.js +32 -7
- package/core/moduleTypes.js +20 -7
- package/core/modules.js +7 -7
- package/core/namedModel.js +8 -4
- package/core/owned.js +33 -30
- package/core/page.js +43 -10
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +64 -96
- package/core/sceneDelta.js +12 -4
- package/core/sceneMethods.js +2 -9
- package/core/services.js +1 -1
- package/core/shadowTypes.js +1 -1
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +5 -19
- package/core/stackFrames.js +16 -5
- package/core/stacks.js +6 -6
- package/core/startup.js +9 -11
- package/core/thingExplain.js +1 -1
- package/core/things.js +1 -1
- package/core/tier.js +1 -1
- package/core/util.js +1 -1
- package/core/validate.js +1 -1
- package/core/view.js +43 -0
- package/docs/AI.md +62 -58
- package/docs/API.md +15 -15
- package/docs/CODEMAP.md +36 -54
- package/docs/COMMANDS.md +28 -25
- package/docs/CONVENTIONS.md +36 -30
- package/docs/MIGRATING-0.4.md +93 -1
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/THREE.md +24 -22
- package/docs/api/assets.md +5 -3
- package/docs/api/audio.md +2 -2
- package/docs/api/budget.md +4 -0
- package/docs/api/characters.md +3 -1
- package/docs/api/collision.md +2 -2
- package/docs/api/engine.md +47 -20
- package/docs/api/events.md +2 -1
- package/docs/api/grids.md +8 -1
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +3 -0
- package/docs/api/input.md +3 -2
- package/docs/api/interactions.md +3 -1
- package/docs/api/inventory.md +1 -2
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +1 -1
- package/docs/api/occlusion.md +5 -0
- package/docs/api/particles.md +6 -3
- package/docs/api/pickups.md +6 -0
- package/docs/api/post.md +5 -3
- package/docs/api/sky.md +12 -10
- package/docs/api/terrain.md +12 -6
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/tools.md +8 -7
- package/docs/api/triggers.md +2 -0
- package/docs/api/vegetation.md +7 -2
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +6 -2
- package/docs/api/weather.md +5 -0
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +19 -23
- package/docs/recipes/03-items-pickups.md +25 -4
- package/docs/recipes/05-props-bake.md +53 -37
- package/docs/recipes/06-clock-events.md +3 -3
- package/docs/recipes/07-flow-scenes-pause.md +12 -3
- package/docs/recipes/08-weather-sky.md +45 -57
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +2 -2
- package/docs/recipes/11-vehicles.md +3 -3
- package/docs/recipes/13-animation.md +13 -7
- package/docs/recipes/14-custom-module.md +7 -5
- package/docs/recipes/15-perf.md +3 -3
- package/docs/recipes/16-dev-bridge.md +22 -12
- package/docs/recipes/18-world.md +10 -8
- package/docs/recipes/19-shooting-picking.md +7 -5
- package/docs/recipes/20-content-actions-save.md +6 -2
- package/docs/recipes/21-camera.md +8 -3
- package/docs/recipes/23-ops.md +1 -1
- package/docs/recipes/26-ui-parts.md +35 -11
- package/docs/recipes/28-terrain.md +12 -12
- package/docs/recipes/29-grid.md +14 -5
- package/docs/recipes/30-templates.md +8 -3
- package/docs/recipes/31-audio.md +4 -4
- package/docs/recipes/32-action-game.md +18 -4
- package/docs/recipes/34-environment-lighting.md +102 -38
- package/docs/recipes/35-picture-from-reference.md +147 -0
- package/docs/recipes/36-sky-ground-plants.md +158 -0
- package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -13
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +106 -27
- package/docs/recipes/42-terrain-shape.md +1 -1
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +121 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +10 -12
- package/docs/recipes/49-game-module-contract.md +1 -1
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +181 -0
- package/docs/recipes/53-ground-up-close.md +12 -12
- package/docs/recipes/54-three-idioms.md +18 -18
- package/docs/recipes/55-mods-time-wrap.md +17 -5
- package/docs/recipes/56-webgpu-tsl.md +66 -23
- package/docs/recipes/57-control.md +39 -0
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +39 -24
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +244 -0
- package/docs/recipes/63-third-person-start.md +77 -0
- package/docs/recipes/64-particles.md +35 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +7 -5
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/FINDINGS.md +53 -0
- package/examples/plain-picture/GAMEMAP.md +90 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +8 -3
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +25 -33
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/sheepisland/.threedog/content-index.json +1 -1
- package/examples/sheepisland/GAMEMAP.md +13 -10
- package/examples/sheepisland/assets.js +2 -2
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +15 -9
- package/examples/sheepisland/{style/models.js → models.js} +13 -24
- package/examples/sheepisland/picture/index.js +20 -0
- package/examples/sheepisland/picture/lights.js +34 -0
- package/examples/sheepisland/picture/materials.js +61 -0
- package/examples/sheepisland/picture/palette.js +60 -0
- package/examples/sheepisland/picture/sky.js +20 -0
- package/examples/sheepisland/views.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -11
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +30 -67
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +4 -3
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +5 -3
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +9 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +15 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +7 -16
- package/index.js +7 -7
- package/llms.txt +15 -13
- package/modules/ambience/Ambience.js +1 -1
- package/modules/calendar/Calendar.js +1 -1
- package/modules/calendar/index.js +1 -0
- package/modules/camera/FirstPersonCamera.js +1 -1
- package/modules/camera/FixedCamera.js +2 -2
- package/modules/camera/RtsCamera.js +1 -1
- package/modules/camera/common.js +7 -5
- package/modules/characters/Character.js +15 -10
- package/modules/characters/NPC.js +5 -5
- package/modules/characters/assetModel.js +5 -4
- package/modules/characters/index.js +28 -3
- package/modules/characters/movers/common.js +6 -1
- package/modules/characters/movers/manual.js +3 -0
- package/modules/characters/movers/support.js +25 -11
- package/modules/characters/npcSim.js +5 -1
- package/modules/characters/proceduralRig.js +18 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/collision/Collision.js +4 -2
- package/modules/content/index.js +8 -0
- package/modules/content/models.js +56 -11
- package/modules/content/props.js +5 -3
- package/modules/content/rules.js +12 -4
- package/modules/content/templates.js +5 -3
- package/modules/gameplay/Interactions.js +91 -16
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +1 -1
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -2
- package/modules/gameplay/pickups.js +62 -24
- package/modules/gameplay/questLog.js +2 -2
- package/modules/grid/Layer.js +13 -0
- package/modules/grid/index.js +40 -11
- package/modules/grid/preview.js +24 -15
- package/modules/grid/tiles.js +15 -19
- package/modules/hlod/index.js +3 -2
- package/modules/hud/index.js +13 -0
- package/modules/hud/parts.js +9 -7
- package/modules/level/index.js +5 -4
- package/modules/lights/index.js +12 -8
- package/modules/music/Music.js +1 -1
- package/modules/particles/Particles.js +41 -20
- package/modules/particles/effect.js +21 -6
- package/modules/photo/Photo.js +11 -10
- package/modules/settings/Settings.js +7 -7
- package/modules/settings/apply.js +5 -5
- package/modules/settings/sections.js +2 -2
- package/modules/settings/strings.js +1 -1
- package/modules/sky/Sky.js +104 -89
- package/modules/sky/clouds.js +16 -17
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +5 -5
- package/modules/sky/environment.js +45 -169
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +26 -90
- package/modules/sky/season.js +3 -3
- package/modules/sky/shader.js +35 -29
- package/modules/sky/skyModule.js +25 -22
- package/modules/sky/tint.js +9 -11
- package/modules/terrain/ChunkManager.js +29 -12
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +44 -66
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +1 -1
- package/modules/terrain/terrainGen.js +2 -2
- package/modules/triggers/index.js +10 -6
- package/modules/vegetation/Vegetation.js +58 -17
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +1 -1
- package/modules/vegetation/index.js +10 -10
- package/modules/water/Water.js +135 -88
- package/modules/water/surface.js +53 -53
- package/modules/weather/Weather.js +52 -17
- package/modules/weather/particles.js +13 -5
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +2 -2
- package/modules/world/views.js +1 -1
- package/package.json +3 -2
- package/presets.js +2 -2
- package/render/PostFX.js +199 -41
- package/render/backend.js +52 -6
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +5 -5
- package/render/effects.js +41 -26
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/index.js +7 -5
- package/render/fx/patchNodes.tsl.js +1 -1
- package/render/fx/postWebGPU.tsl.js +30 -7
- package/render/fx/sky.tsl.js +19 -92
- package/render/fx/water.tsl.js +1 -1
- package/render/layers.js +14 -0
- package/render/lighting.js +6 -5
- package/render/lightmap.js +142 -0
- package/render/lights.js +23 -201
- package/render/materials.js +44 -160
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +1 -1
- package/render/patches.js +34 -29
- package/render/postWebGL.js +11 -3
- package/render/probes.js +179 -122
- package/render/slots.js +4 -4
- package/render/terms.js +53 -101
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +333 -296
- package/types/gameplay.d.ts +65 -26
- package/types/generated/core/Audio.d.ts +1 -1
- package/types/generated/core/DebugOverrides.d.ts +14 -6
- package/types/generated/core/Input.d.ts +9 -2
- package/types/generated/core/page.d.ts +9 -2
- package/types/generated/modules/grid/Layer.d.ts +8 -0
- package/types/generated/modules/grid/index.d.ts +29 -5
- package/types/generated/modules/particles/Particles.d.ts +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -18
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +33 -3
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +2 -2
- package/types/generated/render/PostFX.d.ts +53 -10
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +19 -44
- package/types/generated/render/occlusion.d.ts +13 -0
- package/types/physics.d.ts +5 -3
- package/types/tsl.d.ts +8 -0
- package/types/world.d.ts +376 -57
- package/ui/Focus.js +12 -2
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +8 -4
- package/ui/UI.js +10 -10
- package/ui/cursor.js +1 -1
- package/ui/theme.js +33 -27
- package/ui/touchPart.js +1 -1
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/styleParts.js +0 -114
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// Cascaded shadows of one DirectionalLight: 2-4 maps along the view (three's CSM addon), sharp near the camera, wide far away. The one copy of this
|
|
2
|
+
// engineering: engine.shadows.cascades(light) (core/shadows.js) builds them here, one set per engine (one 'csm' patch per material, and the cascade order
|
|
3
|
+
// is the order of the shadow-casting lights).
|
|
4
|
+
// Design choices, each one because the addon used as-is would break something:
|
|
5
|
+
// - The light handed in stays in charge and is the nearest cascade, so whoever writes it keeps its color / intensity / direction.
|
|
6
|
+
// The other cascades are extra DirectionalLights that copy its color and intensity every frame.
|
|
7
|
+
// - Materials get the cascade lighting through one named patch, 'csm' (render/patches.js), never CSM.setupMaterial: that assigns
|
|
8
|
+
// material.onBeforeCompile and would drop every other patch (wind, clouds, season, detail, lighting), and CSM.dispose deletes it.
|
|
9
|
+
// - The chunk swap is per material (the patch replaces <lights_fragment_begin>): CSM's constructor overwrites ShaderChunk globally and
|
|
10
|
+
// never restores it, which would reach every material and every engine on the page; here _injectInclude does nothing.
|
|
11
|
+
// - Every lit material in the scene must carry the patch: without it the cascade lights would add up (N times the sunlight). So while
|
|
12
|
+
// cascades are on, each frame visits only what entered the scene since the last one (core/sceneDelta.js: an add at any depth, or
|
|
13
|
+
// mesh.material = x) and patches lit materials it has not seen (one Map lookup per mesh); the whole scene is walked once, when they turn on.
|
|
14
|
+
// - Which materials (user decision 4, option A, 2026-11-02): every BUILT-IN lit type, the game's own `new` materials too. This is the one named
|
|
15
|
+
// exception to "the engine does not change what it did not create": unpatched, a lit material is lit by every cascade light (N times as
|
|
16
|
+
// bright, doubled shadows), so leaving it alone is not neutral, it is a wrong picture. describe().owned lists the game materials it patched.
|
|
17
|
+
// A ShaderMaterial with lights: true is the game's own shader code, so it is never patched silently: one warning names
|
|
18
|
+
// engine.shadows.include(mat), which opts it in.
|
|
19
|
+
// - csm.update() runs only on frames whose shadow maps re-render (engine.shadows.budget), else lights move while the maps stay old.
|
|
20
|
+
// On WebGPURenderer all of the above is replaced by three's CSMShadowNode on the light (cascades.tsl.js, registered by threedog/tsl): one light,
|
|
21
|
+
// so no patch, no scene walk, and engine.shadows.include() does nothing. This file only hands over to it, so WebGL bundles never load three/webgpu.
|
|
22
|
+
import * as THREE from 'three';
|
|
23
|
+
import { CSM } from 'three/addons/csm/CSM.js';
|
|
24
|
+
import { CSMShader } from 'three/addons/csm/CSMShader.js';
|
|
25
|
+
import { patchMaterial, unpatchMaterial, isEngineMade } from './patches.js';
|
|
26
|
+
|
|
27
|
+
import { warnOnce } from '../core/validate.js';
|
|
28
|
+
import { sceneVisitor } from '../core/sceneDelta.js';
|
|
29
|
+
import { codedError } from '../core/errorHints.js';
|
|
30
|
+
import { setShadowUpdate, shadowUpdatePending, shadowsOn, isWebGPU, webgpuPart } from './backend.js';
|
|
31
|
+
|
|
32
|
+
export const CASCADE_SPLITS = ['practical', 'uniform', 'logarithmic'];
|
|
33
|
+
/** Fields of a cascade set besides its count; both entries start from these */
|
|
34
|
+
export const CASCADE_DEFAULTS = { maxFar: 120, fade: true, lightMargin: 100, split: 'practical' };
|
|
35
|
+
|
|
36
|
+
const LIT = new Set(['MeshLambertMaterial', 'MeshPhongMaterial', 'MeshStandardMaterial', 'MeshPhysicalMaterial', 'MeshToonMaterial']);
|
|
37
|
+
const litShader = m => m.isShaderMaterial && m.lights && m.fragmentShader.includes('#include <lights_fragment_begin>');
|
|
38
|
+
/** ShaderMaterials the game opted in with engine.shadows.include(mat), per engine */
|
|
39
|
+
const optedIn = e => e._csmInclude ??= new WeakSet();
|
|
40
|
+
/**
|
|
41
|
+
* engine.shadows.include(material): let the cascades patch a ShaderMaterial (lights: true) of yours. Built-in lit materials need nothing.
|
|
42
|
+
* @example engine.shadows.include(myLitShaderMaterial);
|
|
43
|
+
*/
|
|
44
|
+
export function includeInCascades(e, m) {
|
|
45
|
+
if (!m?.isMaterial) throw codedError('shadow-cascades', `engine.shadows.include(material): needs a three.js Material; got ${m}. Example: engine.shadows.include(myShaderMaterial)`);
|
|
46
|
+
if (m.isShaderMaterial && !litShader(m)) throw codedError('shadow-cascades', "engine.shadows.include(material): this ShaderMaterial has no lights: true + '#include <lights_fragment_begin>', so the cascades cannot reach it; build it on THREE.ShaderLib's lit shaders, or leave it out");
|
|
47
|
+
if (isWebGPU(e.renderer)) { // the cascades are the light's shadow node there: every material is lit once without opting in
|
|
48
|
+
warnOnce('engine.shadows.include(mat) does nothing on WebGPURenderer: cascaded shadows there are one light (three CSMShadowNode) and patch no material');
|
|
49
|
+
return m;
|
|
50
|
+
}
|
|
51
|
+
optedIn(e).add(m);
|
|
52
|
+
if (e._cascades?.mats.has(m)) e._cascades.fit(m); // already looked at and left alone: patch it now (fit is per material, so no scene walk)
|
|
53
|
+
return m;
|
|
54
|
+
}
|
|
55
|
+
const lit = (c, m) => {
|
|
56
|
+
if (LIT.has(m.type)) return true;
|
|
57
|
+
if (!litShader(m)) return false;
|
|
58
|
+
if (optedIn(c.engine).has(m)) return true;
|
|
59
|
+
warnOnce(`cascaded shadows: engine.shadows.include(mat) opts ShaderMaterial '${m.name || m.uuid.slice(0, 8)}' in. Until then it has lights: true and is lit by all ` +
|
|
60
|
+
`${c.lights.length} cascade lights (too bright, doubled shadows): the engine does not patch your own shader code unasked`);
|
|
61
|
+
return false;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// The addon's split / frustum / texel-snapped placement, with the given light as cascade 0 and the chunk swap left to the 'csm' patch
|
|
65
|
+
class LightCSM extends CSM {
|
|
66
|
+
/** @param {any} e @param {any} light @param {{ cascades: number, maxFar: number, fade: boolean, lightMargin: number, split: any }} S */
|
|
67
|
+
constructor(e, light, S) {
|
|
68
|
+
const custom = typeof S.split === 'function';
|
|
69
|
+
super({ camera: e.camera, parent: e.scene, cascades: S.cascades, maxFar: S.maxFar, mode: custom ? 'custom' : S.split, customSplitsCallback: custom ? S.split : undefined,
|
|
70
|
+
shadowMapSize: light.shadow.mapSize.x, shadowBias: light.shadow.bias, lightMargin: S.lightMargin, lightNear: 1, lightFar: S.lightMargin + 2 * S.maxFar });
|
|
71
|
+
const first = this.lights[0];
|
|
72
|
+
this.parent.remove(first, first.target); first.dispose();
|
|
73
|
+
this.lights[0] = light;
|
|
74
|
+
// uniforms shared by every patched material: one write here reaches all of them
|
|
75
|
+
this.uniforms = { CSM_cascades: { value: [] }, cameraNear: { value: 0 }, shadowFar: { value: 0 } };
|
|
76
|
+
this.fade = S.fade;
|
|
77
|
+
this.updateFrustums();
|
|
78
|
+
// cacheKey is new for every build: three keeps a material's old programs and, when a key comes back (cascades off, then on again),
|
|
79
|
+
// reuses that program with the uniforms map of the material's latest compile, which lacks these uniforms, so the GPU would keep the
|
|
80
|
+
// old build's split and far values (shadows vanish where the old cascade 0 ended). One recompile per switch, which the light count
|
|
81
|
+
// change costs anyway; each material keeps one program per switch until it is disposed, so switch on a settings screen, not per frame
|
|
82
|
+
e._csmBuild = (e._csmBuild ?? 0) + 1;
|
|
83
|
+
this.patch = { name: 'csm', cacheKey: `${S.cascades}${S.fade ? 'f' : ''}.${e._csmBuild}`, uniforms: this.uniforms, slot: 'lightingModel',
|
|
84
|
+
pars: `#define USE_CSM 1\n#define CSM_CASCADES ${S.cascades}\n${S.fade ? '#define CSM_FADE\n' : ''}` +
|
|
85
|
+
'uniform vec2 CSM_cascades[CSM_CASCADES];\nuniform float cameraNear;\nuniform float shadowFar;',
|
|
86
|
+
glsl: CSMShader.lights_fragment_begin };
|
|
87
|
+
/**
|
|
88
|
+
* material -> the patch object it carries (null: looked at, left alone), and weak refs to walk them: switching off finds every material still alive.
|
|
89
|
+
* Weak because streamed terrain makes a material per chunk with its own color map, and a strong table would keep them all for as long as cascades run. Not
|
|
90
|
+
* a dispose listener: dispose() is also how a game forces a rebuild of a material it keeps on the mesh, and that one must still lose the patch at drop()
|
|
91
|
+
*/
|
|
92
|
+
this.mats = new WeakMap();
|
|
93
|
+
this.refs = [];
|
|
94
|
+
this.sweepAt = 1024;
|
|
95
|
+
this.engine = e;
|
|
96
|
+
this.light = light;
|
|
97
|
+
this.at = new THREE.Vector3(Infinity, 0, 0); // camera position at the last placement
|
|
98
|
+
this.proj = '';
|
|
99
|
+
/** what entered the scene since the last frame (view.walks: how many full walks ran; tests read it) */
|
|
100
|
+
this.view = sceneVisitor(e.scene, { enter: o => { if (!o.isMesh) return; const ms = o.material; if (Array.isArray(ms)) for (const m of ms) this.fit(m); else if (ms) this.fit(ms); } });
|
|
101
|
+
const sc = light.shadow.camera;
|
|
102
|
+
Object.assign(sc, { near: 1, far: this.lightFar }); sc.updateProjectionMatrix();
|
|
103
|
+
}
|
|
104
|
+
fit(m) {
|
|
105
|
+
const was = this.mats.get(m);
|
|
106
|
+
if (was === this.patch || (was === null && !optedIn(this.engine).has(m))) return;
|
|
107
|
+
if (was === undefined) this.remember(m);
|
|
108
|
+
if (!lit(this, m)) { this.mats.set(m, null); return; } // null: looked at, left alone (no per-frame recheck / rewarn)
|
|
109
|
+
patchMaterial(m, [this.patch], { strict: false }); this.mats.set(m, this.patch);
|
|
110
|
+
}
|
|
111
|
+
/** One weak ref per material; the dead ones go when the list has doubled, so a long walk through a streamed world keeps it at the size of what is alive */
|
|
112
|
+
remember(m) {
|
|
113
|
+
this.refs.push(new WeakRef(m));
|
|
114
|
+
if (this.refs.length < this.sweepAt) return;
|
|
115
|
+
this.refs = this.refs.filter(r => r.deref());
|
|
116
|
+
this.sweepAt = Math.max(1024, this.refs.length * 2);
|
|
117
|
+
}
|
|
118
|
+
/** The materials looked at and still alive, with the patch each carries @returns {[any, any][]} */
|
|
119
|
+
alive() { return this.refs.flatMap(r => { const m = r.deref(); return m ? [[m, this.mats.get(m)]] : []; }); }
|
|
120
|
+
/** describe().owned row: the game's own materials the csm patch went on (the named exception, see the header) */
|
|
121
|
+
gameMaterials() { return this.alive().filter(([m, p]) => p && !isEngineMade(m)).map(([m]) => m.name || m.type); }
|
|
122
|
+
_injectInclude() {}
|
|
123
|
+
_updateUniforms() {
|
|
124
|
+
const U = this.uniforms;
|
|
125
|
+
if (!U) return; // the base constructor calls this before the uniforms exist
|
|
126
|
+
this._getExtendedBreaks(U.CSM_cascades.value);
|
|
127
|
+
U.cameraNear.value = this.camera.near; U.shadowFar.value = Math.min(this.camera.far, this.maxFar);
|
|
128
|
+
}
|
|
129
|
+
/** The light's shadow values reach the extra lights: what is written on the light is the one source */
|
|
130
|
+
shadowParams() {
|
|
131
|
+
const s = this.light.shadow;
|
|
132
|
+
this.shadowMapSize = s.mapSize.x; // the placement snaps to this texel size
|
|
133
|
+
for (const l of this.lights) if (l !== this.light) {
|
|
134
|
+
Object.assign(l.shadow, { bias: s.bias, normalBias: s.normalBias, radius: s.radius, blurSamples: s.blurSamples, intensity: s.intensity, autoUpdate: s.autoUpdate });
|
|
135
|
+
if (s.needsUpdate) l.shadow.needsUpdate = true; // a budget asks on the light handed in; every cascade redraws with it
|
|
136
|
+
if (l.shadow.mapSize.x !== s.mapSize.x) { l.shadow.mapSize.copy(s.mapSize); l.shadow.map?.dispose(); l.shadow.map = null; }
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Per frame: patch materials that entered the scene, follow the camera and the light, place on shadow frames
|
|
141
|
+
* @param {any} lightDir unit vector toward the light @param {number} updateEvery 1 = the shadow maps redraw every frame
|
|
142
|
+
*/
|
|
143
|
+
frame(lightDir, updateEvery) {
|
|
144
|
+
const e = this.engine, cam = e.camera, light = this.light;
|
|
145
|
+
this.view.sync();
|
|
146
|
+
this.shadowParams();
|
|
147
|
+
const proj = cam.isPerspectiveCamera ? `${cam.fov},${cam.aspect},${cam.near},${cam.far},${cam.zoom}` : `${cam.left},${cam.right},${cam.near},${cam.far},${cam.zoom}`;
|
|
148
|
+
let force = false;
|
|
149
|
+
if (this.camera !== cam || proj !== this.proj) { this.camera = cam; this.proj = proj; this.updateFrustums(); force = true; }
|
|
150
|
+
this.lightDirection.copy(lightDir).negate(); // CSM points from the light into the scene
|
|
151
|
+
// with no shadow on the light the extra lights would only add light (the patch's bands need the shadow lights): hide them
|
|
152
|
+
const show = light.visible && light.castShadow && !!light.parent && shadowsOn(e);
|
|
153
|
+
for (const l of this.lights) if (l !== light) { l.color.copy(light.color); l.intensity = light.intensity; l.visible = show; }
|
|
154
|
+
cam.updateMatrixWorld();
|
|
155
|
+
// not updating every frame: also place early when the camera left a quarter of the nearest cascade (teleport, fast travel)
|
|
156
|
+
const near = this.breaks[0] * Math.min(cam.far, this.maxFar);
|
|
157
|
+
if (updateEvery <= 1 || shadowUpdatePending(e.renderer, e.scene) || force || this.at.distanceToSquared(cam.position) > (near / 4) ** 2) {
|
|
158
|
+
this.update(); this.at.copy(cam.position);
|
|
159
|
+
if (updateEvery > 1) setShadowUpdate(e.renderer, e.scene, { now: true });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** Switch off: extra lights out, the 'csm' patch off every material it went on */
|
|
163
|
+
drop() {
|
|
164
|
+
for (const l of this.lights) if (l !== this.light) { this.parent.remove(l, l.target); l.dispose(); }
|
|
165
|
+
this.view.remove();
|
|
166
|
+
for (const [m, p] of this.alive()) if (p) unpatchMaterial(m, 'csm');
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Build the cascades of a light. One set per engine, named at the second build: a material holds one 'csm' patch, and on WebGL the cascade
|
|
172
|
+
* order is the order of the shadow-casting lights.
|
|
173
|
+
* @param {any} e @param {any} light @param {{ cascades: number, maxFar: number, fade: boolean, lightMargin: number, split: any }} S
|
|
174
|
+
* @param {string} who the entry, for the errors
|
|
175
|
+
* @returns {any} LightCSM, or the shadow node on WebGPURenderer
|
|
176
|
+
*/
|
|
177
|
+
export function createCascades(e, light, S, who) {
|
|
178
|
+
if (e._cascades) throw codedError('shadow-cascades', `${who}: cascaded shadows are already on for light '${e._cascades.light.name || e._cascades.light.type}', and an engine draws one set. Switch those off first (handle.remove())`);
|
|
179
|
+
const sc = light.shadow.camera, box = { left: sc.left, right: sc.right, top: sc.top, bottom: sc.bottom, near: sc.near, far: sc.far };
|
|
180
|
+
const c = isWebGPU(e.renderer) ? webgpuPart('cascades', `[shadows] cascaded shadows (${who})`).create(e, light, S) : new LightCSM(e, light, S);
|
|
181
|
+
c._box = box;
|
|
182
|
+
c.shadowParams();
|
|
183
|
+
return (e._cascades = c);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Remove the engine's cascades, if any: the light's shadow box comes back and the plain map redraws @param {any} e */
|
|
187
|
+
export function dropCascades(e) {
|
|
188
|
+
const c = e._cascades;
|
|
189
|
+
if (!c) return;
|
|
190
|
+
c.drop();
|
|
191
|
+
const sc = c.light.shadow.camera;
|
|
192
|
+
Object.assign(sc, c._box); sc.updateProjectionMatrix();
|
|
193
|
+
e._cascades = null;
|
|
194
|
+
setShadowUpdate(e.renderer, e.scene, { now: true });
|
|
195
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Cascaded shadows on WebGPURenderer (the WebGPU half of cascades.js; loaded only through threedog/tsl, render/fx/index.js).
|
|
2
|
+
// Why three's CSMShadowNode and not the WebGL design: the cascades become the shadow node of the one light (light.shadow.shadowNode),
|
|
3
|
+
// so a material is lit by that light once and shadowed by whichever cascade covers it. Nothing is patched and the scene is never walked:
|
|
4
|
+
// the 'csm' patch, the per-frame scene visitor and engine.shadows.include() exist on WebGL only because there every cascade is a full
|
|
5
|
+
// DirectionalLight that would light an unpatched material N times (user decision 4, docs/plans/2026-11-03-webgpu-phase2.md).
|
|
6
|
+
// How it differs from the node used as-is, each one because the plain node would break something here:
|
|
7
|
+
// - The light's shadow camera gets near 1 / far lightMargin + 2 * maxFar before the node clones it into the cascades. The node only sizes
|
|
8
|
+
// each cascade sideways and puts its light lightMargin behind the slice; with the old far kept, the far cascades' ground lies past far
|
|
9
|
+
// and draws no shadow at all (what E2 saw). Three's WebGL CSM sets the same lightFar itself.
|
|
10
|
+
// - The cascades are built with engine.camera, never with whatever camera compiles first (a probe or photo render would own them).
|
|
11
|
+
// - Placement waits for frames whose cascade maps redraw (engine.shadows.budget): moving the cascade lights while the maps stay old
|
|
12
|
+
// shifts every shadow, the same reason cascades.js only calls csm.update() on shadow frames.
|
|
13
|
+
// - Switching it on or off tells three's light node to rebuild its shadow (the light's 'dispose' event): the node caches the shadow it
|
|
14
|
+
// built first and would keep drawing the old one.
|
|
15
|
+
import { Object3D } from 'three/webgpu';
|
|
16
|
+
import { CSMShadowNode } from 'three/addons/csm/CSMShadowNode.js';
|
|
17
|
+
import { setShadowUpdate, shadowUpdatePending, registerWebGPUPart } from './backend.js';
|
|
18
|
+
|
|
19
|
+
class CascadeNode extends CSMShadowNode {
|
|
20
|
+
/** @param {any} e @param {any} light @param {any} S the cascade fields */
|
|
21
|
+
constructor(e, light, S) {
|
|
22
|
+
const custom = typeof S.split === 'function';
|
|
23
|
+
super(light, { cascades: S.cascades, maxFar: S.maxFar, mode: custom ? 'custom' : S.split, customSplitsCallback: custom ? S.split : undefined, lightMargin: S.lightMargin });
|
|
24
|
+
this.isCascadeNode = true;
|
|
25
|
+
this.fade = S.fade;
|
|
26
|
+
this._engine = e; // underscore names: three walks a node's public fields looking for child nodes
|
|
27
|
+
this._at = { x: Infinity, y: 0, z: 0 }; // camera position at the last early update
|
|
28
|
+
this._aim = new Object3D(); // the light's target in world space, for three's node (updateBefore)
|
|
29
|
+
this._proj = '';
|
|
30
|
+
const sc = light.shadow.camera;
|
|
31
|
+
Object.assign(sc, { near: 1, far: S.lightMargin + 2 * S.maxFar }); sc.updateProjectionMatrix();
|
|
32
|
+
light.shadow.shadowNode = this;
|
|
33
|
+
rebuildShadow(light);
|
|
34
|
+
}
|
|
35
|
+
setup(builder) {
|
|
36
|
+
// _init is the node's own first-build step (cascade stand-in lights, frustums); run it with the engine camera instead of builder.camera
|
|
37
|
+
// (private to three, so not in @types/three)
|
|
38
|
+
if (this.camera === null) /** @type {any} */ (this)._init({ camera: this._engine.camera, renderer: builder.renderer });
|
|
39
|
+
return super.setup(builder);
|
|
40
|
+
}
|
|
41
|
+
/** @param {any} frame @returns {boolean} false would make three call it again this frame (NodeFrame) */
|
|
42
|
+
updateBefore(frame) {
|
|
43
|
+
if (this.lights.length && !this.lights.some(l => l.shadow.autoUpdate || l.shadow.needsUpdate)) return true; // no cascade map redraws this frame
|
|
44
|
+
// three's node aims with light.target.position, a local value: a target under a parent gave shadows another direction than the light's own shading
|
|
45
|
+
// (and than WebGL). The light is a child of the scene (checked at the call), so its position needs no such step
|
|
46
|
+
const light = /** @type {any} */ (this.light), target = light.target;
|
|
47
|
+
target.updateWorldMatrix(true, false);
|
|
48
|
+
this._aim.position.setFromMatrixPosition(target.matrixWorld);
|
|
49
|
+
light.target = this._aim;
|
|
50
|
+
try { return super.updateBefore(frame); } finally { light.target = target; }
|
|
51
|
+
}
|
|
52
|
+
fit() {}
|
|
53
|
+
gameMaterials() { return []; }
|
|
54
|
+
/** The light's shadow values reach the cascades (the node itself scales bias by cascade: bias x (i + 1), kept) */
|
|
55
|
+
shadowParams() {
|
|
56
|
+
const s = /** @type {any} */ (this.light).shadow;
|
|
57
|
+
this.lights.forEach((l, i) => {
|
|
58
|
+
Object.assign(l.shadow, { bias: s.bias * (i + 1), normalBias: s.normalBias, radius: s.radius, blurSamples: s.blurSamples, intensity: s.intensity, autoUpdate: s.autoUpdate });
|
|
59
|
+
l.shadow.mapSize.copy(s.mapSize);
|
|
60
|
+
if (s.needsUpdate) l.shadow.needsUpdate = true; // a budget asks on the light handed in; every cascade redraws with it
|
|
61
|
+
});
|
|
62
|
+
if (this.lights.length) s.needsUpdate = false; // with cascades the light's own map is never drawn, so nothing else clears it
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Per frame: follow a new camera / projection, update early after a jump. The node reads the light's direction itself, so the first argument (the WebGL
|
|
66
|
+
* cascades' direction) is unused @param {any} _ @param {number} updateEvery 1 = the shadow maps redraw every frame
|
|
67
|
+
*/
|
|
68
|
+
frame(_, updateEvery) {
|
|
69
|
+
const e = this._engine, cam = e.camera;
|
|
70
|
+
this.shadowParams();
|
|
71
|
+
if (this.camera === null) return; // not built yet: setup() takes engine.camera
|
|
72
|
+
const proj = cam.isPerspectiveCamera ? `${cam.fov},${cam.aspect},${cam.near},${cam.far},${cam.zoom}` : `${cam.left},${cam.right},${cam.near},${cam.far},${cam.zoom}`;
|
|
73
|
+
let force = false;
|
|
74
|
+
if (this.camera !== cam || proj !== this._proj) { this.camera = cam; this._proj = proj; this.updateFrustums(); force = true; }
|
|
75
|
+
cam.updateMatrixWorld();
|
|
76
|
+
if (updateEvery <= 1) return;
|
|
77
|
+
// not updating every frame: also update early when the camera left a quarter of the nearest cascade (teleport, fast travel)
|
|
78
|
+
const near = this.breaks[0] * Math.min(cam.far, this.maxFar), p = cam.position, d = (p.x - this._at.x) ** 2 + (p.y - this._at.y) ** 2 + (p.z - this._at.z) ** 2;
|
|
79
|
+
if (force || d > (near / 4) ** 2) { setShadowUpdate(e.renderer, e.scene, { now: true }); this._at = { x: p.x, y: p.y, z: p.z }; }
|
|
80
|
+
else if (shadowUpdatePending(e.renderer, e.scene)) this._at = { x: p.x, y: p.y, z: p.z };
|
|
81
|
+
}
|
|
82
|
+
/** Switch off: the cascade lights and maps go, the light gets its plain shadow back */
|
|
83
|
+
drop() {
|
|
84
|
+
const light = /** @type {any} */ (this.light);
|
|
85
|
+
delete light.shadow.shadowNode; // three tests `!== undefined`: null would count as a node
|
|
86
|
+
for (const n of /** @type {any} */ (this)._shadowNodes) n.dispose(); // the node's own dispose() leaves the cascade maps on the GPU (private field)
|
|
87
|
+
this.dispose();
|
|
88
|
+
rebuildShadow(light);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Make three's light node drop the shadow it cached (AnalyticLightNode listens for the light's 'dispose'; its version bump recompiles) */
|
|
93
|
+
function rebuildShadow(light) { light.dispatchEvent({ type: 'dispose' }); }
|
|
94
|
+
|
|
95
|
+
// cascades.js looks this up when the renderer is a WebGPURenderer (the WebGL bundle never imports three/webgpu); nothing to call
|
|
96
|
+
registerWebGPUPart('cascades', Object.freeze({ create: (e, light, S) => new CascadeNode(e, light, S) }));
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Day and night as a signal. engine.uniforms.uNight is 0 by day and 1 at night; lightPool sources with `dusk` fade on this same curve, so a game's
|
|
2
|
+
// emissive windows that read uNight switch on together with the lamps instead of two curves drifting apart.
|
|
3
|
+
|
|
4
|
+
// default dusk: lights fade in as daylight drops below 0.3 (calendar daylight: about 16:50 -> fully lit at 18:00). It is only a starting value:
|
|
5
|
+
// each lightPool source may pass its own `dusk`, and a game's own fade reads uDaylight with its own edge
|
|
6
|
+
export const DUSK = 0.3;
|
|
7
|
+
|
|
8
|
+
/** Daylight 0..1 from the 'daylight' measure (engine.audio.measure): the calendar registers it (gameplay day / night), the sky only when no
|
|
9
|
+
* calendar did (the drawn sun). Read through the measure, not e.calendar / e.sky, so render/ names no module and a game's own clock module counts
|
|
10
|
+
* the same by registering the measure. null when nothing tells day from night */
|
|
11
|
+
export const daylightOf = e => { const d = e.audio?.measures.get('daylight')?.(e); return typeof d === 'number' ? d : null; };
|
|
12
|
+
/**
|
|
13
|
+
* 0 by day, 1 at night for one dusk (daylight below which it fades in); null daylight -> 0 (the day value is kept). dusk 0 has no fade:
|
|
14
|
+
* on only while daylight is 0 (a cave mushroom that glows only in full dark); the d / dusk curve would divide by zero there
|
|
15
|
+
*/
|
|
16
|
+
export function nightOf(d, dusk) {
|
|
17
|
+
if (d === null) return 0;
|
|
18
|
+
if (dusk === 0) return d > 0 ? 0 : 1;
|
|
19
|
+
const t = Math.min(1, Math.max(0, d / dusk));
|
|
20
|
+
return 1 - t * t * (3 - 2 * t); // smoothstep: no visible kink when the fade starts or ends
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Time of day 0..1 from the 'timeOfDay' measure: the calendar registers it (the game clock), the sky only when no calendar did (its fixed time).
|
|
24
|
+
* null when nothing owns a time of day (the uniform keeps its default) */
|
|
25
|
+
export const timeOfDayOf = e => { const t = e.audio?.measures.get('timeOfDay')?.(e); return typeof t === 'number' ? t : null; };
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Twice per frame, before the modules' frame hooks (an onFrame reads this frame's signal) and again just before drawing (a time jump in a hook reaches the picture
|
|
29
|
+
* in the same frame as uSunDir): the one writer of uDaylight and uTimeOfDay. They come from the measures, so whoever owns game
|
|
30
|
+
* time (the calendar, else the sky's fixed time) decides them, and a game with no sky() still has them moving. The sky writes neither.
|
|
31
|
+
* @internal core/loop.js
|
|
32
|
+
* @param {any} e
|
|
33
|
+
*/
|
|
34
|
+
export function writeDaylight(e) {
|
|
35
|
+
const d = daylightOf(e), t = timeOfDayOf(e);
|
|
36
|
+
e.uniforms.uNight.value = nightOf(d, DUSK);
|
|
37
|
+
if (d !== null) e.uniforms.uDaylight.value = d;
|
|
38
|
+
if (t !== null) e.uniforms.uTimeOfDay.value = t;
|
|
39
|
+
}
|
package/render/detail.js
CHANGED
|
@@ -20,7 +20,7 @@ const MODES = ['multiply', 'add', 'mix'];
|
|
|
20
20
|
// Callable (#include <threedog_detail> in your own ShaderMaterial; the patch's built-in noises call the same functions). No uniforms:
|
|
21
21
|
// vec4 threedogDetailNoise(vec2 p, int kind, float octaves) kind 0 grain, 1 paper, 2 stroke, 3 dabs; returns (gray rgb, height 0-1)
|
|
22
22
|
// vec3 threedogDetailBump(vec3 surfPos, vec3 surfNorm, float h, float k, float faceDir) screen-space bump (three's bump-map math)
|
|
23
|
-
// Why: a game's own shader gets the
|
|
23
|
+
// Why: a game's own shader gets the same grain / paper / brush texture by calling it instead of the engine patching its material.
|
|
24
24
|
// The hash / value noise are the shared threedogHash / threedogNoise (#include <threedog_noise>, render/effects.js), not a copy: the detail grain,
|
|
25
25
|
// cloud shadows and sky clouds are one noise, and the TSL side (render/fx/detail.tsl.js) calls the same hash() / noise().
|
|
26
26
|
const CALLABLE = `#ifndef THREEDOG_DETAIL
|
|
@@ -98,8 +98,8 @@ const COLOR = `{ vec3 tdc = threedogDS.rgb * uDetailTint;
|
|
|
98
98
|
else diffuseColor.rgb = mix(diffuseColor.rgb, tdc, uDetailStrength * threedogDFade); }`;
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
|
-
* The `detail` patch from a detail option object (
|
|
102
|
-
* @internal use
|
|
101
|
+
* The `detail` patch from a detail option object (DetailOptions above). `engine` loads a texture given by asset name.
|
|
102
|
+
* @internal use applyEffects(mat, { detail }) or terrain({ detail })
|
|
103
103
|
* @param {any} o
|
|
104
104
|
* @param {{ assets?: any } | null} engine
|
|
105
105
|
* @param {string} [label] where the options came from, for errors
|
|
@@ -128,7 +128,7 @@ export function detailPatch(o, engine, label = 'detail') {
|
|
|
128
128
|
else {
|
|
129
129
|
tex = placeholderTexture('detail');
|
|
130
130
|
if (typeof o.texture === 'string') {
|
|
131
|
-
if (!engine?.assets) throw codedError('material-option', `${label}.texture '${o.texture}' is an asset name but no engine is known; pass the engine (
|
|
131
|
+
if (!engine?.assets) throw codedError('material-option', `${label}.texture '${o.texture}' is an asset name but no engine is known; pass the engine (applyEffects(mat, { detail, engine })) or give a THREE.Texture`);
|
|
132
132
|
engine.assets.useTexture(o.texture, t => {
|
|
133
133
|
const own = t.clone(); // shares the image (no second upload); own wrapping
|
|
134
134
|
// read as data, like the gray stand-in: 128 is the neutral the blend doubles to 1. Decoded as sRGB it reads 0.22, and the ground
|
|
@@ -153,7 +153,7 @@ ${PROJECT[proj]}`;
|
|
|
153
153
|
if (bump) glsl.normal = 'normal = threedogDetailBump(-vViewPosition, normal, threedogDS.a, uDetailBump * threedogDFade, faceDirection);';
|
|
154
154
|
if (rough) glsl.roughness = 'roughnessFactor = clamp(roughnessFactor + (threedogDS.a - 0.5) * uDetailRough * threedogDFade, 0.04, 1.0);';
|
|
155
155
|
return { name: 'detail', cacheKey: `${src}|${proj}|${colorOn ? 'c' : ''}${bump ? 'n' : ''}${rough ? 'r' : ''}`, needs: { patches: ['world'] }, uniforms: u, pars, glsl,
|
|
156
|
-
// a game's own GLSL sample has no TSL twin: no tsl field, so a NodeMaterial names the patch instead of drawing it without its
|
|
156
|
+
// a game's own GLSL sample has no TSL twin: no tsl field, so a NodeMaterial names the patch instead of drawing it without its picture
|
|
157
157
|
...(!o.glsl && { tsl: detailTsl(u, proj, o.texture ? -1 : NOISES.indexOf(o.noise ?? 'grain'), colorOn, bump, rough) }) };
|
|
158
158
|
}
|
|
159
159
|
|
package/render/effects.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Built-in shader effects. Used by render/materials.js: the engine uniforms they read, the GLSL chunks (also registered as
|
|
1
|
+
// Built-in shader effects. Used by render/materials.js (applyEffects): the engine uniforms they read, the GLSL chunks (also registered as
|
|
2
2
|
// THREE.ShaderChunk.threedog_*), the named patches world / clouds / wind / season, and placeholder textures.
|
|
3
3
|
import * as THREE from 'three';
|
|
4
4
|
import { engineUniform } from './engineUniforms.js';
|
|
@@ -6,47 +6,58 @@ import { notePatch } from '../core/threePatches.js';
|
|
|
6
6
|
import { WIND, HASH, CLOUD, glslFloat as f } from './fxNumbers.js';
|
|
7
7
|
|
|
8
8
|
// ---------- engine uniforms ----------
|
|
9
|
-
// Each engine has its own uniforms (engine.uniforms)
|
|
9
|
+
// Each engine has its own uniforms (engine.uniforms). Built-in effects name engine uniforms, which patches.js swaps
|
|
10
10
|
// for the compiling renderer's engine (bindUniforms), so two engines on one page never share time, wind or cloud cover.
|
|
11
11
|
const UNIFORM_DEFAULTS = {
|
|
12
12
|
uTime: 0, // ambient seconds (engine.time.now('ambient')), written only by core/time.js
|
|
13
13
|
uWind: 1, // wind multiplier (driven by weather)
|
|
14
14
|
uCloud: 0.25, // cloud cover 0-1 (driven by weather)
|
|
15
|
-
|
|
15
|
+
uWeatherLight: 1, uWeatherFog: 1, // weather's multipliers: the game's picture/ code applies them to its own light and fog distance
|
|
16
|
+
uViewDistance: 600, // how far the world is meant to be seen, meters: stream radius, a game's fog far (terrain viewFog writes it)
|
|
17
|
+
uRain: 0, uSnow: 0, // rain / snow amount 0-1 (weather state): signals for a game's wet road or snowy roof shader
|
|
18
|
+
uCloudShadow: 0, // darkest cloud shadow (0 = no cloud shadows; the game writes it)
|
|
16
19
|
uCloudScale: 0.006, // cloud size (smaller = bigger clouds)
|
|
17
20
|
uCloudSpeed: () => new THREE.Vector2(0.012, 0.006), // cloud drift direction and speed
|
|
18
21
|
uWindFreq: 1, // sway frequency multiplier
|
|
19
|
-
uWindAmp: 1, // sway amplitude multiplier
|
|
22
|
+
uWindAmp: 1, // sway amplitude multiplier; every wind patch's amplitude is scaled by it
|
|
20
23
|
uFoliageTint: () => new THREE.Color(1, 1, 1), // season: foliage tint (driven by the sky module's calendar)
|
|
21
24
|
uGroundTint: () => new THREE.Color(1, 1, 1), // season: ground tint
|
|
22
25
|
uFoliageMix: 0, uGroundMix: 0, // season mode 'mix': how far the surface moves to the tint (0 = multiply, the default)
|
|
23
26
|
// snow / ash cover amount alone (x foliage, y ground, 0-1; modules/sky/tint.js): the tints above already hold it blended in, but a game's
|
|
24
|
-
// own tint (
|
|
27
|
+
// own tint (engine.terms.season) needs the amount by itself to draw its own snow
|
|
25
28
|
uCover: () => new THREE.Vector2(0, 0),
|
|
26
29
|
// the sky contract's shared outputs (modules/sky/frame.js writes them every frame): a game's own sky dome, water or shader reads these, so a
|
|
27
30
|
// replaced sky still follows the time of day. Share the object itself: mySky.material.uniforms.sunPosition = engine.uniforms.uSunDir
|
|
28
31
|
uSunDir: () => new THREE.Vector3(0, 1, 0), // unit vector toward the sun
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
//
|
|
32
|
+
uSunColor: () => new THREE.Color(1, 1, 1), // the keyframes' sun color now: what a game's own sun takes, so no second table of the day's light
|
|
33
|
+
uDaylight: 1, // 0 at night .. 1 at noon (the 'daylight' measure: calendar, else the drawn sun; render/daylight.js)
|
|
34
|
+
uNight: 0, // 0 by day .. 1 at night: the curve lightPool `dusk` sources fade on (render/daylight.js)
|
|
35
|
+
uTimeOfDay: 0.5, // 0-1 time of day (0 midnight, 0.5 noon): the 'timeOfDay' measure, calendar else sky's fixed time; render/daylight.js
|
|
36
|
+
// the sky colors as drawn this frame (keyframes, engine.sky.top / horizon, weather tint, lightning; a backdrop's color for the horizon): the one
|
|
32
37
|
// read for a game shader that should meet the sky (sea, distant cards). Fog in its default 'horizon' color is this same color (fog.js)
|
|
33
38
|
uSkyTop: () => new THREE.Color(0, 0, 0),
|
|
34
39
|
uSkyHorizon: () => new THREE.Color(0.8, 0.8, 0.8),
|
|
40
|
+
// the sky dome's picture numbers (modules/sky/shader.js shares these objects with the dome; sky({ ... }) sets their start values): write .value, on both renderers
|
|
41
|
+
uSunSize: 900, // sharpness exponent of the sun disk (larger = smaller)
|
|
42
|
+
uSunGlow: 0.18, uSunPower: 6, // sun glow, sun disk brightness
|
|
43
|
+
uMoonSize: 1400, uMoonPower: 3, // sharpness exponent of the moon disk, moon disk brightness
|
|
44
|
+
uMoonColor: () => new THREE.Color(0xdcdcdc),
|
|
45
|
+
uStars: 0.0025, uStarScale: 260, // share of sky grid cells holding a star at night (0 = none), star grid resolution (larger = smaller stars)
|
|
46
|
+
uCurve: 0.55, // horizon-to-zenith gradient exponent
|
|
47
|
+
uCloudCover: 0, // dome cloud amount 0..1+, multiplied by the weather's uCloud
|
|
48
|
+
uSkyCloudScale: 0.35, // dome cloud size (smaller = bigger clouds); uCloudScale is the cloud shadows'
|
|
49
|
+
uSkyCloudSpeed: () => new THREE.Vector2(0.004, 0.002), // dome cloud drift [x, z] per second; uCloudSpeed is the cloud shadows'
|
|
50
|
+
uCloudOpacity: 0.9, uCloudSoft: 0.3, // dome cloud opacity and edge softness
|
|
51
|
+
uCloudColor: () => new THREE.Color(0xf4f4f4), uCloudShade: () => new THREE.Color(0xaaaaaa), // dome cloud lit and shaded side
|
|
35
52
|
};
|
|
36
53
|
/**
|
|
37
|
-
* A fresh set of engine uniforms
|
|
54
|
+
* A fresh set of engine uniforms at their neutral defaults (each engine owns one: engine.uniforms; the game writes them directly)
|
|
38
55
|
* @internal
|
|
39
|
-
* @param {any} [style]
|
|
40
56
|
* @returns {import('../types/core').EngineUniforms}
|
|
41
57
|
*/
|
|
42
|
-
export function createUniforms(
|
|
58
|
+
export function createUniforms() {
|
|
43
59
|
const u = /** @type {any} */ ({});
|
|
44
60
|
for (const [k, v] of Object.entries(UNIFORM_DEFAULTS)) u[k] = engineUniform(k, typeof v === 'function' ? v() : v);
|
|
45
|
-
const c = style.clouds || {}, w = style.wind || {};
|
|
46
|
-
if (c.shadow != null) u.uCloudShadow.value = c.shadow;
|
|
47
|
-
if (c.scale != null) u.uCloudScale.value = c.scale;
|
|
48
|
-
if (c.speed) u.uCloudSpeed.value.set(c.speed[0], c.speed[1]);
|
|
49
|
-
if (w.frequency != null) u.uWindFreq.value = w.frequency;
|
|
50
61
|
return u;
|
|
51
62
|
}
|
|
52
63
|
const TEMPLATE = createUniforms(); // what built-in patches name; resolved to the compiling engine's uniforms
|
|
@@ -72,9 +83,9 @@ export const NOISE_GLSL = `float threedogHash(vec2 p){ return fract(sin(dot(p, v
|
|
|
72
83
|
// patching the game's material (plan §4b). The older pars / vertex chunks below stay for the patches (they declare only what each patch needs).
|
|
73
84
|
const CALLABLE = {
|
|
74
85
|
threedog_uniforms: `uniform float uTime; uniform float uWind; uniform float uWindFreq; uniform float uWindAmp;
|
|
75
|
-
uniform float uCloud; uniform float uCloudShadow; uniform float uCloudScale; uniform vec2 uCloudSpeed;
|
|
86
|
+
uniform float uCloud; uniform float uRain; uniform float uSnow; uniform float uCloudShadow; uniform float uCloudScale; uniform vec2 uCloudSpeed;
|
|
76
87
|
uniform vec3 uFoliageTint; uniform vec3 uGroundTint; uniform float uFoliageMix; uniform float uGroundMix; uniform vec2 uCover;
|
|
77
|
-
uniform vec3 uSunDir; uniform float uDaylight; uniform float uTimeOfDay; uniform vec3 uSkyTop; uniform vec3 uSkyHorizon;`,
|
|
88
|
+
uniform vec3 uSunDir; uniform vec3 uSunColor; uniform float uDaylight; uniform float uTimeOfDay; uniform vec3 uSkyTop; uniform vec3 uSkyHorizon;`,
|
|
78
89
|
// Higher vertices sway more; each tree / grass clump / batched object has its own phase from its own origin
|
|
79
90
|
threedog_wind: `
|
|
80
91
|
vec3 threedogWind(vec3 position, vec3 origin, float amplitude){
|
|
@@ -172,6 +183,10 @@ const pick = (...keys) => Object.fromEntries(keys.map(k => [k, TEMPLATE[k]]));
|
|
|
172
183
|
* @internal
|
|
173
184
|
*/
|
|
174
185
|
export const PROVIDED_BY = { vThreedogWorld: 'world' };
|
|
186
|
+
// One tsl function per built-in spec: the WebGPU program key holds each function's identity (render/patches.js nodeKey), so a fresh closure per
|
|
187
|
+
// call would give every material with the same effects its own program
|
|
188
|
+
const TSL_ONCE = new Map();
|
|
189
|
+
const tslOnce = (key, make) => { let t = TSL_ONCE.get(key); if (!t) TSL_ONCE.set(key, t = make()); return t; };
|
|
175
190
|
// The engine's built-in effects as named patches (also readable as GLSL examples for your own patches)
|
|
176
191
|
/** @internal @type {Record<string, (...args: any[]) => import('./patches.js').ShaderPatch>} */
|
|
177
192
|
export const EFFECTS = {
|
|
@@ -186,7 +201,7 @@ export const EFFECTS = {
|
|
|
186
201
|
// sun light only, skipped while uCloudShadow is 0 (threedog_clouds_light above); WebGPU: the lighting slot's light() hook changes the
|
|
187
202
|
// sun's color before three lights the surface with it, behind the same uniform branch
|
|
188
203
|
pars: '#include <threedog_clouds_pars_fragment>', glsl: { lightsPars: '#include <threedog_clouds_light>' },
|
|
189
|
-
tsl: { lighting: { light: (L, c) => {
|
|
204
|
+
tsl: tslOnce('clouds', () => ({ lighting: { light: (L, c) => {
|
|
190
205
|
if (!L.light?.isDirectionalLight && !L.light?.isSunLight) return undefined;
|
|
191
206
|
const T = c.tsl;
|
|
192
207
|
if (!c.state.cloud) {
|
|
@@ -194,8 +209,8 @@ export const EFFECTS = {
|
|
|
194
209
|
T.If(c.fx.uniform('uCloudShadow').greaterThan(0), () => { k.assign(c.fx.cloudShadow(T.positionWorld)); });
|
|
195
210
|
}
|
|
196
211
|
return L.color.mul(c.state.cloud);
|
|
197
|
-
} } } }),
|
|
198
|
-
// wind(amplitude) or wind(amplitude, { glsl, uniforms, decl }): a
|
|
212
|
+
} } })) }),
|
|
213
|
+
// wind(amplitude) or wind(amplitude, { glsl, uniforms, decl }): a game's own sway function replaces the default one
|
|
199
214
|
wind: (amplitude, custom) => ({ name: 'wind', cacheKey: custom ? `${amplitude}|${hashText(custom.glsl ?? '')}` : amplitude, shadow: true,
|
|
200
215
|
uniforms: { ...pick('uTime', 'uWind', 'uWindFreq', 'uWindAmp'), ...custom?.uniforms }, slot: 'position', glsl: '#include <threedog_wind_vertex>',
|
|
201
216
|
pars: `uniform float uWindAmp;
|
|
@@ -205,18 +220,18 @@ export const EFFECTS = {
|
|
|
205
220
|
#define THREEDOG_WIND_CUSTOM
|
|
206
221
|
${custom.decl}
|
|
207
222
|
${custom.glsl}` : ''),
|
|
208
|
-
// a game's own sway brings its own tsl (
|
|
223
|
+
// a game's own sway brings its own tsl (engine.vegetation.sway({ glsl, tsl })); one with GLSL only has no tsl (a NodeMaterial names it).
|
|
209
224
|
// ctx.position is object space before instancing on both renderers (render/slots.js), so this is the GLSL line as it is
|
|
210
225
|
...(custom?.tsl && { tsl: custom.tsl }),
|
|
211
|
-
...(!custom && { tsl: c => c.position.add(c.fx.wind(c.tsl.positionGeometry, c.fx.objectOrigin(),
|
|
212
|
-
c.tsl.float(+(+amplitude).toFixed(4)).mul(c.fx.uniform('uWindAmp')))) }) }),
|
|
226
|
+
...(!custom && { tsl: tslOnce(`wind ${(+amplitude).toFixed(4)}`, () => c => c.position.add(c.fx.wind(c.tsl.positionGeometry, c.fx.objectOrigin(),
|
|
227
|
+
c.tsl.float(+(+amplitude).toFixed(4)).mul(c.fx.uniform('uWindAmp'))))) }) }),
|
|
213
228
|
season: kind => {
|
|
214
|
-
// the shared threedogSeason / TSL season() on both sides (mix is 0 in the default 'multiply' mode;
|
|
229
|
+
// the shared threedogSeason / TSL season() on both sides (mix is 0 in the default 'multiply' mode; a season's mode 'mix' sets it)
|
|
215
230
|
const id = kind === 'ground' ? 1 : 0;
|
|
216
231
|
return { name: 'season', cacheKey: kind, uniforms: pick('uFoliageTint', 'uGroundTint', 'uFoliageMix', 'uGroundMix'), slot: 'color',
|
|
217
232
|
pars: 'uniform vec3 uFoliageTint; uniform vec3 uGroundTint; uniform float uFoliageMix; uniform float uGroundMix;\n#include <threedog_season>',
|
|
218
233
|
glsl: `diffuseColor.rgb = threedogSeason(diffuseColor.rgb, ${id});`,
|
|
219
|
-
tsl: c => c.tsl.vec4(c.fx.season(c.color.rgb, id), c.color.a) };
|
|
234
|
+
tsl: tslOnce(`season ${id}`, () => c => c.tsl.vec4(c.fx.season(c.color.rgb, id), c.color.a)) };
|
|
220
235
|
},
|
|
221
236
|
};
|
|
222
237
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// TSL celLighting(): the lighting model behind colored cel bands, on a MeshToonNodeMaterial (mat.setupLightingModel = celLighting).
|
|
2
|
+
// Why not three's ToonLightingModel alone: it reads only the red channel of gradientMap, and it multiplies the band by a light color that already
|
|
3
|
+
// holds the shadow, so everything the shadow map covers falls to zero direct light: the ramp's dark entries never show there and a cast shadow
|
|
4
|
+
// keeps the shadow map's soft edge. Here the shadow moves the ramp lookup instead (a shadowed pixel reads the ramp's dark end), so a cast shadow
|
|
5
|
+
// takes the same flat band and color as the turned-away side.
|
|
6
|
+
// Why colorNode cannot do this: it runs before lighting and sees no light. This runs inside three's light loop, for every light type.
|
|
7
|
+
import { LightingModel } from 'three/webgpu';
|
|
8
|
+
import { BRDF_Lambert, diffuseColor, normalView, materialReference, step, vec2, vec3 } from 'three/tsl';
|
|
9
|
+
|
|
10
|
+
class CelLightingModel extends LightingModel {
|
|
11
|
+
/** Lights keep their color without the shadow while this model builds: three's getShadow hook returns what light.colorNode becomes @param {any} builder */
|
|
12
|
+
start(builder) {
|
|
13
|
+
const ctx = builder.context, had = ctx.getShadow;
|
|
14
|
+
ctx.getShadow = lightNode => lightNode.baseColorNode;
|
|
15
|
+
super.start(builder);
|
|
16
|
+
if (had) ctx.getShadow = had; else delete ctx.getShadow;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @param {any} data @param {any} builder */
|
|
20
|
+
direct({ lightDirection, lightColor, lightNode, reflectedLight }, builder) {
|
|
21
|
+
// a light keeps its shadowNode after building a receiver, so an object that does not receive must not read it
|
|
22
|
+
const shadow = builder.object.receiveShadow && builder.renderer.shadowMap.enabled && lightNode?.light?.castShadow ? lightNode.shadowNode : null;
|
|
23
|
+
const lookup = normalView.dot(lightDirection).mul(0.5).add(0.5); // three's toon lookup: the left half of the ramp is the side turned away
|
|
24
|
+
const t = /** @type {any} */ (shadow ? lookup.mul(shadow.x) : lookup);
|
|
25
|
+
const ramp = /** @type {any} */ (materialReference('gradientMap', 'texture'));
|
|
26
|
+
const band = builder.material.gradientMap ? ramp.context({ getUV: () => vec2(t, 0) }).rgb : vec3(step(0.7, t).mul(0.3).add(0.7));
|
|
27
|
+
reflectedLight.directDiffuse.addAssign(band.mul(lightColor).mul(BRDF_Lambert({ diffuseColor: diffuseColor.rgb })));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @param {any} builder */
|
|
31
|
+
indirect(builder) {
|
|
32
|
+
const { ambientOcclusion, irradiance, reflectedLight } = builder.context;
|
|
33
|
+
reflectedLight.indirectDiffuse.addAssign(irradiance.mul(BRDF_Lambert({ diffuseColor })));
|
|
34
|
+
reflectedLight.indirectDiffuse.mulAssign(ambientOcclusion);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The lighting model for colored cel bands: assign it to a MeshToonNodeMaterial whose gradientMap holds the ramp (rampTexture; colors work). Without a gradientMap: three's two default levels.
|
|
40
|
+
* @example const mat = new MeshToonNodeMaterial({ color: 0xe08050, gradientMap: rampTexture([0x4a5a9a, 0xc0c8e0, 0xffffff]) }); mat.setupLightingModel = celLighting;
|
|
41
|
+
*/
|
|
42
|
+
export function celLighting() { return new CelLightingModel(); }
|
package/render/fx/index.js
CHANGED
|
@@ -8,19 +8,21 @@ export { season } from './season.tsl.js';
|
|
|
8
8
|
export { objectOrigin } from './objectOrigin.tsl.js';
|
|
9
9
|
export { detailNoise, detailBump } from './detail.tsl.js';
|
|
10
10
|
export { wrapDiffuse, shadowTint, rim } from './lighting.tsl.js';
|
|
11
|
+
export { celLighting } from './cel.tsl.js';
|
|
11
12
|
export { waterWave, waterSurface, waterFresnel } from './water.tsl.js';
|
|
12
13
|
export { uniforms } from './uniforms.tsl.js';
|
|
13
14
|
// Registers what a patch's `tsl` field does on a NodeMaterial (render/patches.js looks it up; nothing to call)
|
|
14
15
|
import './patchNodes.tsl.js';
|
|
15
|
-
// Registers the node versions of the particle / weather shaders (modules/particles and modules/weather
|
|
16
|
+
// Registers the node versions of the particle / weather shaders (modules/particles and modules/weather drawing them up on WebGPURenderer)
|
|
16
17
|
import './particles.tsl.js';
|
|
17
18
|
// Registers the WebGPU post chain (render/PostFX.js looks it up when the renderer is a WebGPURenderer; nothing to call)
|
|
18
19
|
import './postWebGPU.tsl.js';
|
|
19
|
-
// Registers the node version of the sky dome
|
|
20
|
+
// Registers the node version of the sky dome (modules/sky looks it up on WebGPURenderer)
|
|
20
21
|
import './sky.tsl.js';
|
|
21
|
-
// Registers cascaded shadows as three's CSMShadowNode on the
|
|
22
|
-
import '
|
|
22
|
+
// Registers cascaded shadows as three's CSMShadowNode on the light (render/cascades.js looks it up on WebGPURenderer; nothing to call)
|
|
23
|
+
import '../cascades.tsl.js';
|
|
23
24
|
import { WebGPURenderer, PMREMGenerator, CubeRenderTarget, MeshBasicNodeMaterial } from 'three/webgpu';
|
|
25
|
+
import { LightProbeGrid } from 'three/addons/lighting/LightProbeGrid.js';
|
|
24
26
|
import { registerWebGPUPart } from '../backend.js';
|
|
25
27
|
// createEngine({ renderer: 'webgpu' }) builds from these, so the engine core never imports three/webgpu itself (WebGL bundles stay as they are)
|
|
26
|
-
registerWebGPUPart('classes', Object.freeze({ WebGPURenderer, PMREMGenerator, CubeRenderTarget, MeshBasicNodeMaterial }));
|
|
28
|
+
registerWebGPUPart('classes', Object.freeze({ WebGPURenderer, PMREMGenerator, CubeRenderTarget, MeshBasicNodeMaterial, LightProbeGrid }));
|
|
@@ -165,7 +165,7 @@ function gaps(m, p) {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
// The nodes a patch list turns into, kept per SOURCE material: a NodeMaterial patched directly, or a classic material (MeshLambertMaterial ...)
|
|
168
|
-
// patched for both renderers. Why classic materials too: the engine's own materials (
|
|
168
|
+
// patched for both renderers. Why classic materials too: the engine's own materials (terrain, vegetation, water) stay classic so
|
|
169
169
|
// one material object draws on WebGLRenderer (GLSL side) and on WebGPURenderer, including fallback: 'webgl', which is decided only in start().
|
|
170
170
|
// three's WebGPURenderer turns a classic material into a fresh node twin per build (NodeLibrary.fromMaterial); render/patches.js wraps that
|
|
171
171
|
// one call so the twin gets these nodes (dress). The source keeps them too, as non-enumerable accessors: three's shadow pass reads
|