threedog 0.2.0 → 0.5.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 +290 -0
- package/README.md +9 -8
- package/core/Animator.js +15 -12
- package/core/Assets.js +83 -16
- package/core/Audio.js +45 -38
- package/core/Baked.js +32 -8
- package/core/Batching.js +102 -15
- package/core/Budget.js +39 -18
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +45 -10
- package/core/Describe.js +104 -43
- package/core/Engine.js +190 -57
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +168 -79
- package/core/Inspect.js +2 -2
- package/core/InspectMaterials.js +85 -0
- package/core/InspectPerf.js +61 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +5 -5
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +14 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +25 -9
- package/core/Views.js +9 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +22 -5
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +38 -11
- package/core/assetManifest.js +48 -9
- package/core/assetReport.js +1 -1
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +5 -2
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +82 -15
- package/core/describeRender.js +43 -17
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +438 -19
- package/core/errorHints.js +37 -141
- package/core/errors.js +31 -8
- package/core/events.generated.js +12 -7
- package/core/gameLights.js +62 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +128 -0
- package/core/gridLoad.js +20 -0
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +48 -12
- package/core/lightWatch.js +6 -4
- package/core/look/coreParts.js +137 -30
- package/core/look/part.js +175 -95
- package/core/look/points.js +255 -0
- package/core/look/report.js +34 -17
- package/core/look/shadowPart.js +63 -0
- package/core/look/state.js +45 -0
- package/core/look/write.js +12 -28
- package/core/loop.js +101 -37
- package/core/math.js +11 -3
- package/core/moduleSlots.js +75 -0
- package/core/moduleTypes.js +73 -0
- package/core/modules.js +145 -27
- package/core/movement.js +2 -2
- package/core/namedModel.js +70 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +168 -0
- package/core/page.js +2 -1
- package/core/params.js +30 -8
- package/core/plugins.js +277 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +203 -0
- package/core/sceneMethods.js +35 -30
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +2 -1
- package/core/sharedPoint.js +317 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +34 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -11
- package/core/streamSources.js +0 -11
- package/core/styleParts.js +65 -47
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +2 -2
- package/core/thingOps.js +29 -6
- package/core/things.js +21 -11
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +7 -1
- package/core/validate.js +65 -86
- package/core/wrap.js +106 -0
- package/docs/AI.md +89 -97
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +224 -149
- package/docs/COMMANDS.md +57 -34
- package/docs/CONVENTIONS.md +92 -30
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +228 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +79 -27
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +12 -9
- package/docs/api/audio.md +10 -14
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -25
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +9 -6
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +65 -62
- package/docs/api/events.md +19 -14
- package/docs/api/grids.md +3 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +11 -6
- package/docs/api/interactions.md +7 -5
- package/docs/api/inventory.md +17 -16
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +15 -0
- package/docs/api/post.md +5 -4
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +11 -44
- package/docs/api/stream.md +1 -1
- package/docs/api/style.md +31 -29
- package/docs/api/terrain.md +9 -6
- package/docs/api/terrainLook.md +10 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +30 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +12 -8
- package/docs/api/vegetationLook.md +10 -0
- package/docs/api/water.md +4 -20
- package/docs/api/weather.md +5 -15
- package/docs/api/weatherLook.md +10 -0
- package/docs/api/world.md +2 -1
- package/docs/recipes/01-new-game.md +71 -59
- package/docs/recipes/02-npc.md +46 -29
- package/docs/recipes/03-items-pickups.md +38 -24
- package/docs/recipes/04-quests.md +34 -27
- package/docs/recipes/05-props-bake.md +154 -18
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +41 -10
- package/docs/recipes/08-weather-sky.md +146 -37
- package/docs/recipes/09-style.md +218 -0
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +34 -10
- package/docs/recipes/14-custom-module.md +65 -34
- package/docs/recipes/15-perf.md +35 -6
- package/docs/recipes/16-dev-bridge.md +65 -41
- package/docs/recipes/18-world.md +21 -8
- package/docs/recipes/19-shooting-picking.md +12 -11
- package/docs/recipes/20-content-actions-save.md +63 -25
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +18 -18
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +12 -6
- package/docs/recipes/28-terrain.md +35 -2
- package/docs/recipes/29-grid.md +71 -33
- package/docs/recipes/30-templates.md +64 -12
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +35 -2
- package/docs/recipes/34-environment-lighting.md +27 -4
- package/docs/recipes/35-style-from-reference.md +115 -51
- package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
- package/docs/recipes/37-terrain-look-hooks.md +37 -15
- package/docs/recipes/38-environment-look-hooks.md +64 -48
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +3 -3
- package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
- package/docs/recipes/44-water-weather-look-hooks.md +30 -21
- package/docs/recipes/45-cascaded-shadows.md +17 -8
- package/docs/recipes/46-blender-art-route.md +4 -4
- package/docs/recipes/47-island-snow-backdrop.md +11 -10
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +46 -33
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +4 -4
- package/docs/recipes/52-look.md +228 -54
- package/docs/recipes/53-ground-up-close.md +58 -0
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +112 -0
- package/docs/recipes/56-webgpu-tsl.md +260 -0
- package/docs/recipes/57-control.md +65 -0
- package/docs/recipes/58-input.md +57 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +55 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +17 -13
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/look.js +1 -1
- package/examples/action/main.js +10 -13
- package/examples/action/models.js +24 -23
- package/examples/pullable.json +111 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +83 -0
- package/examples/rc2d/README.md +52 -0
- package/examples/rc2d/main.js +63 -0
- package/examples/rc2d/rc2d.js +197 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +13 -11
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/main.js +17 -12
- package/examples/sheepisland/style/index.js +6 -6
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +15 -16
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/npcs.js +1 -1
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +18 -17
- package/examples/styletest/models.js +1 -1
- package/examples/styletest/params.js +3 -3
- package/examples/techniques/contact-shadows/README.md +92 -0
- package/examples/techniques/contact-shadows/contactShadows.js +51 -0
- package/examples/techniques/contact-shadows/main.js +53 -0
- package/examples/techniques/day-night-grade/README.md +86 -0
- package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
- package/examples/techniques/day-night-grade/main.js +51 -0
- package/examples/techniques/interior-light/README.md +103 -0
- package/examples/techniques/interior-light/interiorLight.js +45 -0
- package/examples/techniques/interior-light/main.js +124 -0
- package/examples/techniques/modular-building/README.md +125 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +47 -0
- package/examples/techniques/night-lights/README.md +94 -0
- package/examples/techniques/night-lights/main.js +70 -0
- package/examples/techniques/night-lights/nightLights.js +91 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +84 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/procedural-animation/README.md +77 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +45 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +67 -0
- package/examples/techniques/procedural-surface/main.js +103 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +75 -0
- package/examples/techniques/stylized-shading/main.js +93 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +135 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
- package/examples/techniques/sun-and-key-light/main.js +95 -0
- package/examples/techniques/wet-road/README.md +99 -0
- package/examples/techniques/wet-road/main.js +68 -0
- package/examples/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +84 -0
- package/examples/webgpu-tsl/README.md +42 -0
- package/examples/webgpu-tsl/main.js +21 -0
- package/examples/webgpu-tsl/tslScene.js +75 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +22 -15
- package/examples/world/art/humanoid.js +42 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +58 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/npcs.js +2 -2
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +17 -13
- package/examples/world/style/index.js +61 -0
- package/examples/world/style/plugins/10-bloom.js +5 -0
- package/index.d.ts +50 -45
- package/index.js +27 -22
- package/llms.txt +20 -12
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +81 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +70 -19
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +196 -59
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +27 -8
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +87 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +97 -19
- package/modules/characters/movers/manual.js +20 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +172 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +12 -8
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +46 -10
- package/modules/characters/useModel.js +1 -1
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +65 -25
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +97 -28
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +11 -40
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +16 -9
- package/modules/content/rules.js +58 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +121 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +193 -67
- package/modules/gameplay/Inventory.js +69 -73
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +18 -16
- package/modules/gameplay/pickups.js +268 -85
- package/modules/gameplay/questLog.js +4 -4
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +14 -13
- package/modules/grid/index.js +60 -36
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +15 -16
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +6 -5
- package/modules/hlod/index.js +51 -19
- package/modules/hud/index.js +35 -20
- package/modules/hud/parts.js +20 -7
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +45 -20
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +42 -18
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +23 -14
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +39 -11
- package/modules/photo/Photo.js +53 -36
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +57 -52
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +88 -176
- package/modules/sky/cascades.js +86 -25
- package/modules/sky/cascades.tsl.js +82 -0
- package/modules/sky/clouds.js +34 -19
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +83 -13
- package/modules/sky/fog.js +140 -95
- package/modules/sky/frame.js +112 -44
- package/modules/sky/look.js +22 -19
- package/modules/sky/lookFog.js +48 -52
- package/modules/sky/lookShadow.js +53 -41
- package/modules/sky/lookSky.js +82 -21
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +41 -19
- package/modules/sky/shadow.js +44 -20
- package/modules/sky/skyModule.js +45 -33
- package/modules/sky/tint.js +61 -0
- package/modules/terrain/ChunkManager.js +175 -108
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/index.js +105 -50
- package/modules/terrain/look.js +83 -0
- package/modules/terrain/lookGround.js +21 -16
- package/modules/terrain/terrainDefaults.js +1 -1
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +5 -3
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +107 -76
- package/modules/vegetation/Vegetation.js +190 -102
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +31 -10
- package/modules/vegetation/look.js +119 -0
- package/modules/vegetation/lookWind.js +71 -10
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +45 -0
- package/modules/water/Water.js +65 -27
- package/modules/water/look.js +29 -18
- package/modules/water/surface.js +64 -25
- package/modules/water/surfaceDefaults.js +3 -0
- package/modules/weather/Weather.js +62 -104
- package/modules/weather/look.js +1 -2
- package/modules/weather/particles.js +24 -9
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherLook.js +135 -0
- package/modules/world/World.js +24 -7
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +7 -5
- package/package.json +8 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +150 -45
- package/render/effects.js +130 -38
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +26 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +158 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +260 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/lighting.js +66 -14
- package/render/lights.js +223 -4
- package/render/lookGlow.js +139 -0
- package/render/lookSurface.js +99 -36
- package/render/materials.js +71 -52
- package/render/modeling.js +73 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +311 -34
- package/render/postLook.js +124 -46
- package/render/postWebGL.js +197 -0
- package/render/probes.js +231 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/surface.js +53 -17
- package/render/terms.js +211 -0
- package/render/uniformDecl.js +3 -2
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +620 -244
- package/types/gameplay.d.ts +494 -318
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +44 -3
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +102 -31
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +5 -5
- package/types/generated/modules/grid/index.d.ts +29 -17
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +12 -104
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/weather/Weather.d.ts +17 -18
- package/types/generated/modules/weather/weatherLook.d.ts +12 -0
- package/types/generated/modules/world/World.d.ts +18 -3
- package/types/generated/render/PostFX.d.ts +67 -30
- package/types/generated/render/materials.d.ts +26 -20
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +137 -44
- package/types/style.d.ts +125 -92
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +164 -110
- package/ui/Focus.js +25 -14
- package/ui/LoadingScreen.js +1 -1
- package/ui/Parts.js +27 -11
- package/ui/UI.js +20 -10
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +9 -6
- package/ui/touchPart.js +1 -1
- package/core/claims.js +0 -51
- package/core/look/layers.js +0 -136
- package/core/renamed.js +0 -21
- package/docs/api/entities.md +0 -61
- package/docs/recipes/09-style-pack.md +0 -234
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/layers.js +0 -69
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/world/cells.js +0 -42
|
@@ -1,18 +1,38 @@
|
|
|
1
1
|
# Writing shader patches and surface looks
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
material**
|
|
3
|
+
**In this recipe**: Your own material · Material roles are open · Patch a slot · Shortcut: spec keys that wire the functions
|
|
4
|
+
|
|
5
|
+
Lead with three.js: **write your own material or `ShaderMaterial`**, or **patch a slot** of any material with your own GLSL. The look is the
|
|
6
|
+
game's own; this page gives building blocks, not looks.
|
|
7
|
+
|
|
8
|
+
```js
|
|
9
|
+
const fragmentShader = '#include <threedog_lighting>\n' + myFragmentBody; // 3. engine GLSL, called inside 1 or 2
|
|
10
|
+
const mat = new THREE.ShaderMaterial({ uniforms: { ...engine.uniforms }, vertexShader, fragmentShader }); // 1. your own shader
|
|
11
|
+
applyEffects(mat2, { patches: [{ name: 'tint', slot: 'color', glsl: 'diffuseColor.rgb *= 0.9;' }] }); // 2. patch a slot
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
**1. Your own material or shader** works exactly as in three.js (`new THREE.MeshStandardMaterial`, `ShaderMaterial`, `onBeforeCompile`), as a
|
|
15
|
+
material role too (below). **2. Patch a slot**: a named piece of GLSL at a named place (`color`, `normal`, `lighting`, `output`...) on any material,
|
|
16
|
+
built-in or yours. **3. Engine GLSL functions** (`#include <threedog_wind>`, `<threedog_detail>`, `<threedog_lighting>`...) are tools you call inside 1 and 2:
|
|
17
|
+
a noise, a wrapped diffuse term, a fresnel edge. None of them is a look. A look is what your game's own shader or style combines: its colors,
|
|
18
|
+
textures, light model and post. The default surface is flat (`lambert` plus vertex colors) until you write one. A few spec keys wire one function
|
|
19
|
+
into a built-in material as a shortcut (last section); reach for them only when they already say what you want.
|
|
20
|
+
|
|
21
|
+
## Your own material
|
|
22
|
+
A `materials` entry that is a Material instance (cloned per use, its patches kept) or a function returning one; `style.lighting` still shapes plain three.js
|
|
23
|
+
lit materials returned by it. Nothing else is applied: textures, `detail` and `lighting` keys are only read on specs, so call `applyEffects(material,
|
|
24
|
+
{ detail, patches })` yourself when you want those tools. Outside a role, `new THREE.*Material` anywhere is fine (THREE.md).
|
|
6
25
|
|
|
7
26
|
## Material roles are open
|
|
8
27
|
`style.materials` maps a role name to a material. The engine asks for `default terrain vegetation character water pickup prop`; **any other
|
|
9
|
-
name is fine** (`
|
|
28
|
+
name is fine** (`cloth`, `metal`, `glass`): code asks for it with `engine.makeMaterial('cloth', { color })`, an unlisted role uses `materials.default`.
|
|
10
29
|
Only a name very close to an existing one (`props`, `charcter`) warns, as a probable typo.
|
|
11
30
|
|
|
12
|
-
```js
|
|
31
|
+
```js fragment
|
|
13
32
|
materials: {
|
|
14
33
|
default: { type: 'lambert' },
|
|
15
|
-
|
|
34
|
+
cloth: { type: 'standard', roughness: 1, color: 0x8a6f5a },
|
|
35
|
+
glass: { type: 'physical', transmission: 1, roughness: 0.05, thickness: 0.2 },
|
|
16
36
|
rock: { type: 'standard', map: 'rock.png', normalMap: 'rock_n.png', roughnessMap: 'rock_r.png', repeat: 4 },
|
|
17
37
|
prop: (params, purpose, engine) => new THREE.MeshMatcapMaterial({ matcap: texture, color: params.color }), // any Material
|
|
18
38
|
}
|
|
@@ -21,29 +41,162 @@ A **function** gets `(params, purpose, engine)`: the call's `params` (color, ver
|
|
|
21
41
|
three.js Material. A **spec** is plain data (`type: lambert | phong | standard | physical | toon | basic` plus material properties), layered over
|
|
22
42
|
`materials.default` when that is a spec too; keys the material has are set, spec keys below are handled by the engine.
|
|
23
43
|
|
|
24
|
-
##
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
`
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
## Patch a slot: your own GLSL
|
|
45
|
+
`detail.glsl` (the `detail` spec key, last section) replaces the noise: `vec4 threedogDetailSample(vec2 p)` returns `vec4(color, height 0-1)`; `p` is already scaled, turned, stretched;
|
|
46
|
+
`uniforms: { uCells: 6 }` (numbers, colors, arrays, textures) are in scope; `threedogDetailFootprint` is one pixel in pattern units (`fade` uses it; read it to fade your own sample). `lighting.glsl` replaces the three light effects:
|
|
47
|
+
`void threedogLighting(inout ReflectedLight light, vec3 normal, vec3 viewDir, vec3 sunDir, float sunShadow, vec3 albedo)` (view space; `sunShadow` 1 lit,
|
|
48
|
+
0 shadowed; change `light.directDiffuse` / `indirectDiffuse`, the lights are already summed).
|
|
49
|
+
|
|
50
|
+
For anything else write a **named patch** that names a **slot** (where the code goes) and add it with `applyEffects(material, { patches: [...] })`
|
|
51
|
+
(or in a `materials` function, or `look.materials.add(name, patch, { roles })`):
|
|
52
|
+
```js fragment
|
|
53
|
+
{ name: 'tint', slot: 'color', glsl: 'diffuseColor.rgb *= 0.9;' } // one slot
|
|
54
|
+
{ name: 'sway', slot: 'position', shadow: true, glsl: 'transformed.x += sin(position.y) * 0.1;' } // moves vertices: the shadow follows
|
|
55
|
+
{ name: 'glow', pars: 'uniform float uGlow;', uniforms: { uGlow: { value: 0.5 } },
|
|
56
|
+
glsl: { color: 'diffuseColor.rgb *= 0.95;', output: 'outgoingLight += uGlow * 0.1;' } } // several slots; pars = declarations
|
|
57
|
+
```
|
|
58
|
+
The full form, with every field:
|
|
59
|
+
```js fragment
|
|
60
|
+
{ name: 'fuzz', // one name per effect; the same name again replaces it
|
|
61
|
+
slot: 'color', // where the code goes (table below)
|
|
62
|
+
glsl: 'diffuseColor.rgb *= 1.0 - uFuzz * 0.5;',
|
|
63
|
+
pars: 'uniform float uFuzz;', // declarations at the top of every stage the patch touches (or { vertex, fragment })
|
|
64
|
+
cacheKey: 'v1', // changes whenever the GLSL text changes, never for uniform values
|
|
65
|
+
uniforms: { uFuzz: { value: 0.3 } }, // numbers live here, so materials with different values share a program
|
|
66
|
+
needs: { patches: ['world'], data: ['vertexColors'] }, // 'world' gives `varying vec3 vThreedogWorld`; data = program inputs you read
|
|
67
|
+
conflicts: ['wind'], // patches it cannot share a material with (checked when added)
|
|
68
|
+
shadow: false } // true = the patch MOVES vertices, so its vertex code also runs in the shadow passes (wind does)
|
|
69
|
+
```
|
|
70
|
+
Slots (the one table is `render/slots.js`; the engine's own wind, clouds, season, detail, lighting and cascades use the same names, and on WebGPU
|
|
71
|
+
the same names map to node properties through a patch's `tsl` field, recipe 56). An unknown slot throws with this list.
|
|
72
|
+
|
|
73
|
+
<!-- slots:begin (generated from render/slots.js slotTable(); threedog check R42 compares) -->
|
|
74
|
+
| slot | GLSL (WebGL) | WebGPU (NodeMaterial) | in scope | meaning |
|
|
75
|
+
|---|---|---|---|---|
|
|
76
|
+
| `position` | after `begin_vertex` | `positionNode` | transformed (vec3, object space, write), position, normal, uv | move vertices in object space, before skinning / instancing / the model matrix; WebGPU: the same place (the engine runs the chain before three's instancing; a game's own positionNode still applies after it) |
|
|
77
|
+
| `shadowPosition` | after `begin_vertex` (shadow passes) | `castShadowPositionNode` | transformed (vec3, object space, write), position | vertex code for the shadow passes only (depth / point-light distance), replacing this patch's position code there |
|
|
78
|
+
| `clipPosition` | after `project_vertex` | `vertexNode` | transformed, mvPosition (view space), gl_Position (clip space, write) | after projection: snap or offset on screen, or write world-space varyings |
|
|
79
|
+
| `map` | after `map_fragment` | `colorNode` | diffuseColor (vec4, write; the map applied, vertex colors not yet) | the base color / texture, before vertex colors and every color patch |
|
|
80
|
+
| `color` | after `color_fragment` | inside `setupDiffuseColor` | diffuseColor (vec4, write; map and vertex colors already applied), vUv when the material has a map | the surface (diffuse) color before lighting |
|
|
81
|
+
| `normal` | after `normal_fragment_maps` | inside `setupNormal` | normal (vec3, view space, write), faceDirection, vViewPosition | the shading normal (bump, detail) after normal / bump maps |
|
|
82
|
+
| `roughness` | after `roughnessmap_fragment` | `roughnessNode` | roughnessFactor (float, write); MeshStandard / MeshPhysical only | roughness after the roughness map |
|
|
83
|
+
| `emissive` | after `emissivemap_fragment` | `emissiveNode` | totalEmissiveRadiance (vec3, write), diffuseColor | emitted light after the emissive map |
|
|
84
|
+
| `lightsPars` | after `shadowmap_pars_fragment` | WebGL only | declarations; three's light structs, getShadow() and directionalLights[] are already declared | functions that call three's light / shadow helpers (pars goes before them); WebGPU: TSL has no declaration area: the light's direction and shadow come to the lighting slot's direct(light, ctx) hook |
|
|
85
|
+
| `lightingModel` | replace `lights_fragment_begin` | WebGL only | geometryPosition, geometryNormal, material, reflectedLight; your code replaces three's light loop | replace how lights are summed (one patch per material may take it); WebGPU: use the lighting slot's hooks { start, light, direct, after }, or a NodeMaterial with your own setupLightingModel |
|
|
86
|
+
| `lighting` | after `lights_fragment_end` | inside `setupLightingModel` | reflectedLight.directDiffuse / directSpecular / indirectDiffuse (write), normal, diffuseColor, vViewPosition | after lights are summed: cloud shadows, wrap, shadow tint, rim; WebGPU: hooks { start, light, direct, after }: light(light, ctx) returns a new color for one light before three lights the surface with it (what GLSL does by wrapping three's light info in lightsPars), direct(light, ctx) sees each light in three's loop and adds to its own sums, which join the summed light at the patch's place in the list, then its after() runs: the same order as WebGL |
|
|
87
|
+
| `output` | before `opaque_fragment` | inside `setupOutput` | outgoingLight (vec3, write), diffuseColor.a | the final lit color, before fog and tone mapping |
|
|
88
|
+
| `fogPars` | after `fog_pars_fragment` | WebGL only | declarations; fogColor and fogNear / fogFar or fogDensity are already declared (inside #ifdef USE_FOG) | fog functions that read three's fog uniforms (wrap them in #ifdef USE_FOG); WebGPU: fog on WebGPU is scene.fogNode (the sky fog kinds and look.fog hooks have a tsl form) |
|
|
89
|
+
| `fog` | replace `fog_fragment` | WebGL only | gl_FragColor (write, tone mapped already), fogColor, vFogDepth, fogNear / fogFar or fogDensity (inside #ifdef USE_FOG) | replace how fog mixes into the final color (one patch per material may take it); WebGPU: fog on WebGPU is scene.fogNode (the sky fog kinds and look.fog hooks have a tsl form) |
|
|
90
|
+
<!-- slots:end -->
|
|
91
|
+
|
|
92
|
+
Several patches in one slot run in the order added. A compile error names the patch and slot:
|
|
93
|
+
`[threedog] shader error in patch 'fuzz' (slot color), fragment shader: ERROR: 0:812: 'uFuz' : undeclared identifier | ...`.
|
|
94
|
+
|
|
95
|
+
**Shader hot reload (dev).** Keep GLSL in its own file and import it as text: `import fuzz from './fuzz.glsl?raw'` (also `.vert`, `.frag`, `.vs`,
|
|
96
|
+
`.fs`), then use it as a patch's `glsl` or a `ShaderMaterial`'s `fragmentShader` / `vertexShader`. Under `npm run dev` the vite preset serves the file
|
|
97
|
+
inside `// threedog:begin file=<path>` markers; saving it recompiles every material holding its text (`engine.debug.reloadGlsl`; a patch gets a new
|
|
98
|
+
cacheKey so the old program is not reused) without reloading the page, and a compile error names the file line:
|
|
99
|
+
`shader error in file shaders/fuzz.glsl:4, patch 'fuzz' (slot color)`. Text copied into your own `onBeforeCompile` closure cannot be found: the page
|
|
100
|
+
reloads instead. Builds get the plain text. Plain Vite equivalent: `import.meta.hot.accept('./fuzz.glsl?raw', m => { mat.fragmentShader = m.default; mat.needsUpdate = true; })`.
|
|
101
|
+
`MeshBasicMaterial` has no lights, so no `normal` / `lighting` slots; `lambert` has no `roughness`. A slot the material lacks throws when the patch is added.
|
|
102
|
+
`vThreedogWorld` is the world position (instancing and batching included); it comes from the engine's `world` patch. A patch whose GLSL reads
|
|
103
|
+
`vThreedogWorld` gets `world` added in front of it even without `needs` (a one-time dev note asks for the `needs: { patches: ['world'] }` line, which
|
|
104
|
+
says the same thing in the patch itself). Meshes with several patches stack them in one program per distinct combination.
|
|
105
|
+
|
|
106
|
+
The `normal` slot also fixes a three.js rule that surprises card and grass art: with `side: THREE.DoubleSide` three flips the normal of every back
|
|
107
|
+
face (`faceDirection`), so a blade or card whose normals all point up shades dark from the side you see its back. Keep the authored normal by
|
|
108
|
+
writing it back in the `normal` slot, e.g. `normal = normalize((viewMatrix * vec4(0.0, 1.0, 0.0, 0.0)).xyz);` (up in view space) or
|
|
109
|
+
`normal *= faceDirection;` (undo the flip).
|
|
110
|
+
|
|
111
|
+
Patches on one material must agree. Each patch declares what it relies on, and a bad combination throws when it is added (or logs once at compile):
|
|
112
|
+
|
|
113
|
+
| Field | Meaning | Checked |
|
|
114
|
+
|---|---|---|
|
|
115
|
+
| `needs.data` | Program inputs the code reads: `'instancing'`, `'instancingColor'`, `'vertexColors'`, `'skinning'`, `'batching'` | when the program compiles (console.error once per material) |
|
|
116
|
+
| `needs.patches` | Patches it builds on, e.g. `['world']` for the `vThreedogWorld` varying (world position; the engine adds `world` itself when a patch needs it or its code reads `vThreedogWorld`) | when added |
|
|
117
|
+
| `conflicts` | Patch names it cannot share a material with | when added, both ways |
|
|
118
|
+
| `uniforms` | A uniform name belongs to one patch; share `engine.uniforms` (`uTime`, `uWind`, `uCloud`...) instead of making your own `uTime` | when added |
|
|
119
|
+
| `shadow` | Render steps: without it the color pass only; `true` also runs its vertex code in the depth (sun / spot shadows) and distance (point-light shadows) passes | - |
|
|
120
|
+
| `cacheKey` | Changes whenever the GLSL text changes (defines, branches), never for uniform values; the program key joins every patch's `name=cacheKey` in order | same name + cacheKey with different code throws |
|
|
121
|
+
```js
|
|
122
|
+
applyEffects(mat, { wind: 0.03, season: 'foliage', patches: [{ name: 'ripple', needs: { patches: ['world'] }, conflicts: ['wind'],
|
|
123
|
+
slot: 'color', glsl: 'diffuseColor.rgb *= 0.9 + 0.1 * sin(vThreedogWorld.x);' }] }); // throws: 'wind' and 'ripple' cannot be combined
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Exit: raw three.js anchors** (WebGL only, plain three.js knowledge). Where no slot fits, `glsl: { vertex|fragment: { <chunk>: code } }` puts
|
|
127
|
+
code after `#include <chunk>` (a value may be `{ before, after, replace }`; the key `pars` is declarations at the top of that stage). A missing chunk
|
|
128
|
+
throws when the patch is added, not as a silent no-op. Chunk names in three **0.187** (read from `three/src/renderers/shaders`), in main-body order:
|
|
129
|
+
|
|
130
|
+
| stage | chunk | what is in scope after it |
|
|
131
|
+
|---|---|---|
|
|
132
|
+
| vertex | `begin_vertex` | `transformed` (object space; wind moves it here) |
|
|
133
|
+
| vertex | `project_vertex` | `mvPosition`, `gl_Position` |
|
|
134
|
+
| vertex | `worldpos_vertex` | `worldPosition` (only when shadows, env maps or transmission need it) |
|
|
135
|
+
| fragment | `map_fragment` `color_fragment` | `diffuseColor` (rgb after the map, then the vertex colors) |
|
|
136
|
+
| fragment | `roughnessmap_fragment` `metalnessmap_fragment` | `roughnessFactor`, `metalnessFactor` (standard / physical) |
|
|
137
|
+
| fragment | `normal_fragment_begin` `normal_fragment_maps` | `normal` (view space), `faceDirection`; `vViewPosition` = minus the view-space position |
|
|
138
|
+
| fragment | `emissivemap_fragment` | `totalEmissiveRadiance` |
|
|
139
|
+
| fragment | `lights_fragment_begin` ... `lights_fragment_end` | `reflectedLight.directDiffuse / indirectDiffuse / directSpecular / indirectSpecular`; after `_end` they are final |
|
|
140
|
+
| fragment | `opaque_fragment` | `outgoingLight` and `gl_FragColor`; (called `output_fragment` before r154) |
|
|
141
|
+
|
|
142
|
+
### Engine effects in your own ShaderMaterial
|
|
143
|
+
```js
|
|
144
|
+
const mat = new THREE.ShaderMaterial({ uniforms: { ...engine.uniforms, uMine: { value: 1 } }, vertexShader, fragmentShader });
|
|
145
|
+
```
|
|
146
|
+
The engine never patches a ShaderMaterial of yours; call its effects as functions instead (the automatic patches call the same ones):
|
|
147
|
+
`fragmentShader: '#include <threedog_detail>\nvoid main(){ gl_FragColor = vec4(threedogDetailNoise(vW.xz, 1, 2.0).rgb, 1.0); }'`
|
|
148
|
+
|
|
149
|
+
| include | function |
|
|
150
|
+
|---|---|
|
|
151
|
+
| `#include <threedog_uniforms>` | declares every engine uniform: `uTime`, `uWind`, `uWindFreq`, `uWindAmp`, `uCloud`, `uCloudShadow`, `uCloudScale`, `uCloudSpeed`, `uFoliageTint`, `uGroundTint`, `uFoliageMix`, `uGroundMix`, `uCover` (snow / ash cover amount alone: x foliage, y ground), `uSunDir`, `uDaylight`, `uTimeOfDay` (include once, in each stage that uses them) |
|
|
152
|
+
| `#include <threedog_wind>` | `vec3 threedogWind(vec3 position, vec3 origin, float amplitude)`: object-space sway offset, higher vertices sway more; `origin` is the object's world origin (its phase) |
|
|
153
|
+
| `#include <threedog_cloudShadow>` | `float threedogCloudShadow(vec3 worldPos)`: light factor 0-1 under the drifting clouds |
|
|
154
|
+
| `#include <threedog_season>` | `vec3 threedogSeason(vec3 color, int kind)`: season tint, kind 0 foliage, 1 ground |
|
|
155
|
+
|
|
156
|
+
To change the cloud shadow or the season tint on the engine's own materials (not only in your shader), replace the term: `engine.look.cloudShadow.replace({ glsl, tsl })` / `engine.look.season.replace(kind => ({ glsl, tsl }))`, or `replace(false)` to drop it (recipe 52).
|
|
157
|
+
| `#include <threedog_detail>` | `vec4 threedogDetailNoise(vec2 p, int kind, float octaves)`: the detail noises, kind 0 grain, 1 paper, 2 stroke, 3 dabs, returns (gray rgb, height 0-1); `vec3 threedogDetailBump(vec3 surfPos, vec3 surfNorm, float h, float k, float faceDir)`: screen-space bump. No uniforms. `p` is yours: world xz for a pattern fixed to the ground (it shrinks with distance), `gl_FragCoord.xy / 3.0` for one the same size all over the screen (3-pixel cells; device pixels, so it follows the pixel ratio) |
|
|
158
|
+
| `#include <threedog_lighting>` | `vec3 threedogWrapDiffuse(float nl, float wrap, vec3 lightColor, float shadow, vec3 albedo)` (light to add), `vec3 threedogShadowTint(vec3 ambient, vec3 tint, float strength, float soft, float nl, float shadow)` (the new ambient), `vec3 threedogRim(vec3 normal, vec3 viewDir, vec3 color, float strength, float power, float shadowSide, float nl)` (light to add); nl = dot(normal, sunDir), shadow 1 lit / 0 shadowed. No uniforms |
|
|
159
|
+
|
|
160
|
+
```glsl
|
|
161
|
+
#include <threedog_uniforms>
|
|
162
|
+
#include <threedog_wind>
|
|
163
|
+
void main() { vec3 p = position + threedogWind(position, (modelMatrix * vec4(0, 0, 0, 1)).xyz, 0.05); gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0); }
|
|
164
|
+
```
|
|
165
|
+
The `detail` and `lighting` patches on built-in materials call these same functions, so a value tuned in `look.surface` reads the same in your shader.
|
|
166
|
+
|
|
167
|
+
Combining tools into a look is per game: write it in the game's style or its own material code.
|
|
168
|
+
Check a pack with `threedog style check`; the pixel and program-count guarantees are in `tests/specs/surface.mjs`.
|
|
30
169
|
|
|
31
|
-
|
|
32
|
-
|
|
170
|
+
## Shortcut: spec keys that wire the functions (`detail`, `lighting`, `ramp`)
|
|
171
|
+
Each key below puts one of the functions above into a built-in material, with its numbers as uniforms. They are building blocks with
|
|
172
|
+
fixed shapes (four noise kinds, one tint model, a band ramp), not finished looks: combine them with your own colors, textures and patches,
|
|
173
|
+
and when a key does not give what you want, write the shader yourself (sections above) and call the same function there.
|
|
174
|
+
|
|
175
|
+
The accepted spec keys, texture slots, `repeat` / `wrap` and who wins between pack and call: recipe 48. How texture names load: the engine
|
|
176
|
+
fetches the asset with `engine.assets.texture` (`map`, `emissiveMap` sRGB, the other slots linear), sets anisotropy, wrap and repeat, and a neutral
|
|
177
|
+
stand-in (flat normal, white) sits in the slot until the image arrives. `style check` verifies the names against the asset pack. This page
|
|
178
|
+
covers the keys that add shader code: `detail`, `lighting`, toon `ramp`, seasons.
|
|
179
|
+
|
|
180
|
+
**`detail`**: a noise pattern, a texture or your own GLSL laid over the surface in world space (needs no UVs). Off unless written; every number is a uniform, so
|
|
181
|
+
100 materials with different `scale` / `strength` / `direction` compile **one** program on WebGL (tested: 8 variants, +0 programs).
|
|
182
|
+
WebGPURenderer keys its program by the patch's uniform objects instead: materials with the same `detail` / `lighting` options share one
|
|
183
|
+
patch object, so they share one program there too (tested: 8 materials of one role, 1 build); different numbers build one each. Sharing
|
|
184
|
+
means one set of values: a uniform changed on one of them changes all of that spec.
|
|
33
185
|
|
|
34
186
|
| key | meaning |
|
|
35
187
|
|---|---|
|
|
36
|
-
| `noise` | `'grain'` (default) `'paper'` `'stroke'
|
|
37
|
-
| `projection` | `'world'` top-down (default, fine for ground)
|
|
38
|
-
| `scale` `strength` | repeats per meter (0.25), color effect 0-1 (0.35) |
|
|
188
|
+
| `noise` | `'grain'` (default) `'paper'` `'stroke'` `'dabs'` (soft oval dabs, no direction); or `texture: 'name'` (asset name or a Texture), or `glsl` (below) |
|
|
189
|
+
| `projection` | `'world'` top-down (default, fine for ground), `'triplanar'` (walls, rocks, characters) or `'screen'`: on the screen pixels, so the grain is the same size near and far (illustration, print, painted looks); world and triplanar grain shrinks with distance and `fade` takes it out |
|
|
190
|
+
| `scale` `strength` | repeats per meter (0.25; with `'screen'` pixels per pattern cell, 2), color effect 0-1 (0.35) |
|
|
39
191
|
| `mode` `tint` | `'multiply'` (default) `'add'` `'mix'`; tint colors the sample |
|
|
40
192
|
| `direction` `stretch` | degrees; stretch along it (strokes default 6): a brush stroke is `{ noise: 'stroke', direction: 20 }` |
|
|
41
193
|
| `octaves` | 1-4 noise layers (2) |
|
|
42
194
|
| `normal` | relief height in meters (bumps the normal; 0 = off) |
|
|
43
195
|
| `roughness` | amount the sample moves roughness (`standard` / `physical`) |
|
|
196
|
+
| `fade` | default `true`: the effect fades out where its pattern is smaller than a pixel (far, grazing), so it does not shimmer; `false` keeps it |
|
|
44
197
|
|
|
45
198
|
Which channels (color, normal, roughness) are on is fixed when the material is made (it is part of the program); the numbers can change any time.
|
|
46
|
-
`style.terrain.detail` (
|
|
199
|
+
The ground takes the same object as `style.terrain.detail` / `look.ground.set({ detail })`; which detail suits which ground: recipe 53.
|
|
47
200
|
|
|
48
201
|
**`lighting`** shapes the light after it is summed. three has no "shadow color": a shadow only removes the sun's light. The patch reads the first
|
|
49
202
|
directional light (the sun; three sorts shadow casters first) and its shadow value for the pixel:
|
|
@@ -61,60 +214,4 @@ ramp. Put it on every lit material of the pack with `style.lighting` (same keys;
|
|
|
61
214
|
**Seasons**: `style.seasons: { mode: 'mix', strength: 0.5, autumn: { foliage: 0xd98a3a } }`. `multiply` (default) multiplies the color on, which turns
|
|
62
215
|
orange-on-green muddy; `mix` moves the surface `strength` of the way to the color.
|
|
63
216
|
|
|
64
|
-
## Exit 2: your own GLSL
|
|
65
|
-
`detail.glsl` replaces the noise: `vec4 threedogDetailSample(vec2 p)` returns `vec4(color, height 0-1)`; `p` is already scaled, turned, stretched;
|
|
66
|
-
`uniforms: { uCells: 6 }` (numbers, colors, arrays, textures) are in scope. `lighting.glsl` replaces the three light effects:
|
|
67
|
-
`void threedogLighting(inout ReflectedLight light, vec3 normal, vec3 viewDir, vec3 sunDir, float sunShadow, vec3 albedo)` (view space; `sunShadow` 1 lit,
|
|
68
|
-
0 shadowed; change `light.directDiffuse` / `indirectDiffuse`, the lights are already summed).
|
|
69
|
-
|
|
70
|
-
For anything else write a **named patch** and add it with `applyEffects(material, { patches: [...] })` (or in a `materials` function):
|
|
71
|
-
```js
|
|
72
|
-
{ name: 'fuzz', // one name per effect; the same name again replaces it
|
|
73
|
-
cacheKey: 'v1', // changes whenever the GLSL text changes, never for uniform values
|
|
74
|
-
uniforms: { uFuzz: { value: 0.3 } }, // numbers live here, so materials with different values share a program
|
|
75
|
-
needs: { patches: ['world'], data: ['vertexColors'] }, // 'world' gives `varying vec3 vThreedogWorld`; data = program inputs you read
|
|
76
|
-
conflicts: ['wind'], // patches it cannot share a material with (checked when added)
|
|
77
|
-
shadow: false, // true = the patch MOVES vertices, so its vertex code also runs in the shadow passes (wind does)
|
|
78
|
-
glsl: { fragment: { pars: 'uniform float uFuzz;', // pars = declarations at the top
|
|
79
|
-
color_fragment: 'diffuseColor.rgb *= 1.0 - uFuzz * 0.5;' } } } // chunk name -> code placed after `#include <chunk>`
|
|
80
|
-
```
|
|
81
|
-
A chunk value may be `{ before, after }`. A missing chunk throws when the patch is added (`strict`), not as a silent no-op. Chunk names in three **0.187**
|
|
82
|
-
(read from `three/src/renderers/shaders`), in main-body order:
|
|
83
|
-
|
|
84
|
-
| stage | chunk | what is in scope after it |
|
|
85
|
-
|---|---|---|
|
|
86
|
-
| vertex | `begin_vertex` | `transformed` (object space; wind moves it here) |
|
|
87
|
-
| vertex | `project_vertex` | `mvPosition`, `gl_Position` |
|
|
88
|
-
| vertex | `worldpos_vertex` | `worldPosition` (only when shadows, env maps or transmission need it) |
|
|
89
|
-
| fragment | `map_fragment` `color_fragment` | `diffuseColor` (rgb after the map, then the vertex colors) |
|
|
90
|
-
| fragment | `roughnessmap_fragment` `metalnessmap_fragment` | `roughnessFactor`, `metalnessFactor` (standard / physical) |
|
|
91
|
-
| fragment | `normal_fragment_begin` `normal_fragment_maps` | `normal` (view space), `faceDirection`; `vViewPosition` = minus the view-space position |
|
|
92
|
-
| fragment | `emissivemap_fragment` | `totalEmissiveRadiance` |
|
|
93
|
-
| fragment | `lights_fragment_begin` ... `lights_fragment_end` | `reflectedLight.directDiffuse / indirectDiffuse / directSpecular / indirectSpecular`; after `_end` they are final |
|
|
94
|
-
| fragment | `opaque_fragment` | `outgoingLight` and `gl_FragColor`; (called `output_fragment` before r154) |
|
|
95
|
-
|
|
96
|
-
`MeshBasicMaterial` has no lights, so no `lights_*` chunks; `lambert` has no roughness chunks. `vThreedogWorld` is the world position (instancing and
|
|
97
|
-
batching included). Meshes with several patches stack them in the order added, in one program per distinct combination.
|
|
98
|
-
|
|
99
|
-
## Exit 3: your own material
|
|
100
|
-
A `materials` entry that is a Material instance (cloned per use, its patches kept) or a function returning one; `style.lighting` still shapes plain three.js
|
|
101
|
-
lit materials returned by it. Nothing else is applied: textures, `detail` and `lighting` keys are only read on specs, so call `applyEffects(material,
|
|
102
|
-
{ detail, patches })` yourself.
|
|
103
|
-
|
|
104
|
-
## Three complete looks
|
|
105
|
-
```js
|
|
106
|
-
const looks = {
|
|
107
|
-
// wool: rough, fuzzy, soft light, a warm rim; one fine grain seen from every side
|
|
108
|
-
wool: { type: 'standard', roughness: 1, detail: { noise: 'grain', projection: 'triplanar', scale: 4, octaves: 3, strength: 0.25, normal: 0.01 },
|
|
109
|
-
lighting: { wrap: 0.5, rim: { color: 0xffd9a8, strength: 0.35, power: 2.5 } } },
|
|
110
|
-
// leaves: toon bands, brush strokes along the wind, cool shade, a bit of transmitted light on the side away from the sun
|
|
111
|
-
leaf: { type: 'toon', ramp: [0.45, 0.8, 1], soften: 0.25, detail: { noise: 'stroke', direction: 35, scale: 1.2, strength: 0.3, mode: 'add' },
|
|
112
|
-
lighting: { shadowTint: { color: 0x5a6fb0, strength: 0.7 }, rim: { color: 0xb8e08a, strength: 0.3, shadowSide: 1 } } },
|
|
113
|
-
// rock: a real texture set, plus a world-space grain that also roughens it
|
|
114
|
-
rock: { type: 'standard', map: 'rock.png', normalMap: 'rock_n.png', roughnessMap: 'rock_r.png', repeat: 3,
|
|
115
|
-
detail: { noise: 'paper', projection: 'triplanar', scale: 0.8, strength: 0.2, normal: 0.02, roughness: 0.3 } },
|
|
116
|
-
};
|
|
117
|
-
```
|
|
118
|
-
Fetch them with `engine.makeMaterial('wool')`. Check a pack with `threedog style check`; the pixel and program-count guarantees are in `tests/specs/surface.mjs`.
|
|
119
|
-
|
|
120
217
|
To change these from code at run time (`materials`, `surface`, `ground`, `wind` look parts), see recipe 52.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
# Water and
|
|
1
|
+
# Water and rain/snow looks: depth color, foam, reflections, particles, lightning
|
|
2
2
|
|
|
3
|
-
For an AI that wants water or weather particles to look a way the defaults do not. Water basics are the `water()` module
|
|
4
|
-
|
|
5
|
-
(
|
|
6
|
-
|
|
3
|
+
For an AI that wants water or weather particles to look a way the defaults do not. Water basics are the `water()` module (structure only: `sea`, `level`,
|
|
4
|
+
`flat`, `size`, `segments`, `uniforms` for the hooks) and its look `style.water` / `engine.look.water.set` (color, opacity, waves, fresnel, normal map,
|
|
5
|
+
shininess, specular; `water({ color })` throws naming `look.water.set`); lights, fog and the sky are in `38-environment-look-hooks.md`. A style that writes none of the keys below keeps the built-in
|
|
6
|
+
shaders and pays nothing for them (`tests/specs/appearance-water.mjs`). Three exits: a parameter, a GLSL function you replace, or your own material.
|
|
7
|
+
At run time the same keys go through `engine.look.water` / `engine.look.weather` (recipe 52).
|
|
7
8
|
|
|
8
9
|
## Water: depth color and crest foam (parameters)
|
|
9
|
-
```js
|
|
10
|
+
```js fragment
|
|
10
11
|
water: {
|
|
11
12
|
depthColor: { shallow: 0x55ddcc, deep: 0x082040 }, // by 'view' (default): shallow looking down, deep toward the horizon
|
|
12
13
|
depthColor: { shallow: 0x7fe0d0, deep: 0x0a3050, by: 'wave', curve: 1.5 }, // shallow on the crests, deep in the troughs
|
|
@@ -14,8 +15,9 @@ water: {
|
|
|
14
15
|
}
|
|
15
16
|
```
|
|
16
17
|
- `depthColor` replaces `color` (opacity stays). `'view'` is a fresnel-style blend by the view angle, `'wave'` blends by the wave height; neither
|
|
17
|
-
needs a depth texture. `curve` bends the blend (above 1 keeps more of the shallow color).
|
|
18
|
-
|
|
18
|
+
needs a depth texture. `curve` bends the blend (above 1 keeps more of the shallow color). A color left out is a neutral gray (light for
|
|
19
|
+
`shallow`, dark for `deep`): the engine picks no water color, so set both.
|
|
20
|
+
- `foam` uses the same wave height as the vertices: `start` / `end` are fractions of the peak height (the `wave` hook's `waveMax`, default 0.29) where
|
|
19
21
|
foam begins and is full. Foam is opaque even on transparent water. All numbers are uniforms (`engine.water.material.uniforms.uFoamStart.value`).
|
|
20
22
|
- **Shore foam is not built in.** An accurate foam line where water meets land needs the distance to the ground under each pixel: a depth
|
|
21
23
|
pre-pass (a `DepthTexture` render target of the scene without water) or a terrain height lookup, both cost a full extra pass or a texture
|
|
@@ -27,17 +29,16 @@ water: {
|
|
|
27
29
|
|
|
28
30
|
## Water: replace the wave or the surface function (GLSL)
|
|
29
31
|
```js
|
|
30
|
-
water: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// style.water: { uniforms: { uBands: 4, uDeep: [0.05, 0.2, 0.4] } } numbers, colors, [x, y(, z, w)] arrays, textures; in both stages
|
|
33
|
+
// the GLSL goes through the look hooks only (style.water.glsl / water({ glsl }) throw and name them):
|
|
34
|
+
engine.look.water.patch('wave', {
|
|
35
|
+
glsl: `float threedogWaterWave(vec3 p, float t) { // p = world position * waveScale, t = time * waveSpeed
|
|
34
36
|
return sin(p.x * 0.5 + t) * 0.2 + sin(p.z * 0.8 - t * 1.3) * 0.1; }`, // height before waveHeight
|
|
35
37
|
waveMax: 0.3, // its peak: foam and depthColor 'wave' divide by it
|
|
36
|
-
|
|
38
|
+
});
|
|
39
|
+
engine.look.water.patch('surface', `vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time) {
|
|
37
40
|
float b = floor(facing * uBands) / uBands; // toon bands by view angle
|
|
38
|
-
return vec4(mix(uDeep, vec3(0.4, 0.8, 0.9), b), base.a); }
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
+
return vec4(mix(uDeep, vec3(0.4, 0.8, 0.9), b), base.a); }`);
|
|
41
42
|
```
|
|
42
43
|
- `wave` replaces only the vertex motion; the rest of the built-in water stays. Copying the default
|
|
43
44
|
(`modules/water/surface.js`, `WAVE`) draws pixel for pixel the same.
|
|
@@ -47,7 +48,9 @@ water: {
|
|
|
47
48
|
- A wrong signature throws with the right one; misspelled keys warn with the near name; `threedog style check` knows these keys.
|
|
48
49
|
|
|
49
50
|
## Water: your own material (reflections, refraction)
|
|
50
|
-
`style.water.material: (engine, { uniforms, waves, surface, normalMap }) => Material` replaces the whole water material;
|
|
51
|
+
`style.water.material: (engine, { uniforms, waves, surface, normalMap }) => Material` replaces the whole water material; at run time the same
|
|
52
|
+
slot is `engine.look.water.replace(fn)` (one entry: `water({ material })` throws naming it). `uniforms` already holds `style.water.uniforms`
|
|
53
|
+
/ `water({ uniforms })`, so your material reads them like the hooks do. The engine still builds
|
|
51
54
|
the meshes, snaps the sea to the focus and scrolls the normal map. Reflections and refraction are not built in (each one renders the scene a
|
|
52
55
|
second time). three's `Reflector` addon works through this exit; the engine water is pre-rotated geometry, so the mirror gets the mesh's
|
|
53
56
|
matrix turned into the XY plane it expects:
|
|
@@ -77,10 +80,16 @@ water: { material: () => {
|
|
|
77
80
|
- three's `Refractor` addon (next to `Reflector`) reads `matrixWorld` as an XY plane too, so the same adapter applies (not covered by a test).
|
|
78
81
|
- Tested: `tests/specs/appearance-water.mjs` renders this exact example and finds the reflected box in the mirror texture.
|
|
79
82
|
|
|
83
|
+
## Water: your own meshes (three's `Water` addon, your own geometry)
|
|
84
|
+
The water module's material is replaceable, its meshes are not. For water drawn entirely your way, leave `water()` out and draw it in plain
|
|
85
|
+
three.js: the water data stays in the engine without the module. `engine.waterAt(x, z)` gives the surface height (water bodies first, then
|
|
86
|
+
`engine.waterLevel`), `engine.waterBodies` lists the lakes and ponds (`{ x, z, radius | hw, hd, level }`), and `water:add` / `water:remove` tell
|
|
87
|
+
you when one comes or goes, so swimming, buoyancy and anything else reading the water keep working.
|
|
88
|
+
|
|
80
89
|
## Weather particles: rain and snow parameters
|
|
81
|
-
`style.weather.rain` / `snow` (left-out keys keep the built-in look
|
|
90
|
+
`style.weather.rain` / `snow` (left-out keys keep the built-in look):
|
|
82
91
|
|
|
83
|
-
```js
|
|
92
|
+
```js fragment
|
|
84
93
|
weather: {
|
|
85
94
|
rain: { color: 0xa8b8d0, opacity: 0.6, length: 1.2, speed: 26, slant: 1.5, density: a => a * a }, // streaks; sparse in a drizzle
|
|
86
95
|
// rain: { shape: 'soft', size: 10, maxSize: 6, sway: 0.3 }, // drops as soft sprites instead of streaks
|
|
@@ -92,10 +101,10 @@ weather: {
|
|
|
92
101
|
(`size` pixels at 3 m, capped at `maxSize`; drifts `sway` meters). `speed` is the fall in m/s.
|
|
93
102
|
- `density: amount => share`: how many particles show at a weather amount 0..1 (rain `a => min(1, a * 1.2)`, snow `() => 1`); opacity still
|
|
94
103
|
follows the amount. `count` per system (default `weather({ particles })`, halved on low-tier devices). Coverage is `style.weather.area`.
|
|
95
|
-
- The numbers are uniforms: `engine.
|
|
104
|
+
- The numbers are uniforms: `engine.weatherLook.systems.get('rain').uniforms.uColor.value.set(0xff0000)` works at run time.
|
|
96
105
|
|
|
97
106
|
## Weather particles: replace the shaders (GLSL)
|
|
98
|
-
```js
|
|
107
|
+
```js fragment
|
|
99
108
|
snow: { uniforms: { uTint: [1, 0.85, 0.9] }, glsl: { fragment: `uniform float uOpacity;
|
|
100
109
|
void main(){
|
|
101
110
|
vec2 d = gl_PointCoord - 0.5;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# Cascaded shadows
|
|
2
2
|
|
|
3
|
-
Off by default: the sun casts one shadow map around the focus (`extent`, default 70 m)
|
|
3
|
+
Off by default: the sun casts one shadow map around the focus (`extent`, default 70 m). Cascades split the sun's shadow
|
|
4
4
|
along the view into 2-4 maps (three's CSM addon): sharp near the camera, coarse far away. Use them when near shadows look blocky and the
|
|
5
5
|
world is bigger than one map covers well.
|
|
6
6
|
|
|
7
7
|
```js
|
|
8
|
-
engine.use(sky({ shadow: { cascades: 3 } })); // or the style
|
|
8
|
+
engine.use(sky({ shadow: { cascades: 3 } })); // or the style: style.sky.shadow.cascades
|
|
9
9
|
engine.look.shadow.set({ cascades: 3, maxFar: 150 }); // at run time; { cascades: 1 } switches back
|
|
10
10
|
```
|
|
11
11
|
|
|
@@ -21,21 +21,30 @@ engine.look.shadow.set({ cascades: 3, maxFar: 150 }); // at run time; { ca
|
|
|
21
21
|
follow the camera frustum and snap to whole shadow pixels themselves, so edges do not shimmer while the camera moves.
|
|
22
22
|
|
|
23
23
|
## How it works (what you can rely on)
|
|
24
|
-
- `engine.
|
|
24
|
+
- `engine.lights.sun` stays the light the sky drives (color, intensity, direction; `look.lights.manual('sun.intensity')` takes it) and is cascade 0; the other
|
|
25
25
|
cascades are extra DirectionalLights that copy its color and intensity every frame. `engine.sky.csm` is three's CSM object (lights,
|
|
26
26
|
breaks, updateFrustums()), null when off.
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
- Built-in lit materials (Lambert, Phong, Standard, Physical, Toon), **your own `new` ones too**, get a named patch `csm`, added after the
|
|
28
|
+
material's other patches; wind, cloud shadows, season, detail and lighting patches stay, and wind shadows still sway. This is the one place
|
|
29
|
+
the engine changes a material it did not make: unpatched, a lit material is lit once by every cascade light (N times as bright, doubled
|
|
30
|
+
shadows). `engine.describe().owned['shadow.csm'].materials` lists your materials that got it. Materials added later are picked up the next
|
|
31
|
+
frame (the scene is walked once per frame while cascades are on).
|
|
32
|
+
- Your own `ShaderMaterial` with `lights: true` is never patched unasked: one warning names it, and `engine.look.shadow.include(mat)` opts it
|
|
33
|
+
in (it needs `#include <lights_fragment_begin>`, i.e. a shader built from `THREE.ShaderLib`).
|
|
30
34
|
Never call `CSM.setupMaterial` yourself: it overwrites `onBeforeCompile` and drops every patch. A game patch must not replace
|
|
31
35
|
`lights_fragment_begin` (it would clash with `csm`, reported when added).
|
|
32
36
|
- three's `ShaderChunk` is never changed (the addon's constructor does that globally; the engine swaps the chunk per material instead).
|
|
33
37
|
- With `shadow.updateEvery > 1` cascades move only on frames whose maps re-render (or when the camera jumps), so lights and maps agree.
|
|
34
|
-
- Photo mode
|
|
38
|
+
- Photo mode's `setShadowMapSize` (and `look.shadow.set({ mapSize })`) resizes every cascade's map, on both renderers.
|
|
39
|
+
|
|
40
|
+
On WebGPURenderer (recipe 56) the same `look.shadow.set({ cascades })` is three's
|
|
41
|
+
`CSMShadowNode` on `engine.lights.sun.shadow.shadowNode`: one light, so no material is patched, nothing is listed in `describe().owned`,
|
|
42
|
+
and `look.shadow.include(mat)` does nothing (it says so once). `engine.sky.csm` is that node (its `lights` are placeholder objects, not
|
|
43
|
+
lights). The cascade shadow cameras reach `lightMargin + 2 * maxFar` meters, as on WebGL.
|
|
35
44
|
|
|
36
45
|
## Costs and stalls
|
|
37
46
|
- Each cascade draws the shadow casters once more (each culls to its own box; near ones see little). `engine.budget.byTag()` counts a
|
|
38
|
-
caster once per shadow
|
|
47
|
+
caster once per shadow map (each cascade, on both renderers), an upper bound. In the styletest acceptance test (software renderer, relative only) 3 cascades
|
|
39
48
|
went from 1 to 3 shadow passes and roughly doubled frame time; do not expect frame rate to improve.
|
|
40
49
|
- Switching cascades on, off or changing any cascade field recompiles every lit material once (a stall), and each material keeps the
|
|
41
50
|
old program until it is disposed (three would otherwise reuse a stale program whose uniforms no longer update). Do it on a settings
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Blender to game (GLB) route
|
|
2
2
|
|
|
3
3
|
Code-built geometry (`models.js`, recipe 05) is good for blockout, props and variations, but it cannot reach the finish of hand-made art: painted
|
|
4
4
|
textures, baked shadows, sculpted edges. That finish comes from Blender. This page is the whole path, in order. The level naming rules live in
|
|
@@ -79,11 +79,11 @@ A whole level is `level({ url: '/models/town.glb' })` (recipe 10). Animation cli
|
|
|
79
79
|
|
|
80
80
|
## 5. The GLB's own materials and the style
|
|
81
81
|
**The GLB keeps its own materials.** The engine loads them as they are (textures, colors, roughness) and does not swap them for style roles;
|
|
82
|
-
that is what lets a
|
|
83
|
-
(terrain, vegetation, procedural models, pickups). One scene can mix
|
|
82
|
+
that is what lets a painted or baked texture show. `style.materials` (recipe 43) applies only to what code builds through `engine.makeMaterial(role, ...)`
|
|
83
|
+
(terrain, vegetation, procedural models, pickups). One scene can mix GLB props and styled code-built things.
|
|
84
84
|
|
|
85
85
|
There is no automatic mapping from a GLB material name to a style role and no flag for it. To make a GLB follow the style anyway, do it in your
|
|
86
|
-
game code, per model: name the material in Blender after the role (`
|
|
86
|
+
game code, per model: name the material in Blender after the role (`cloth`, `metal`, `glass`) and look it up:
|
|
87
87
|
```js
|
|
88
88
|
const m = await engine.assets.model('hat');
|
|
89
89
|
m.traverse(o => { if (o.isMesh) o.material = engine.makeMaterial(o.material.name, { color: o.material.color.getHex() }); });
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Snow cover, flat backdrop, rounded terrain rim
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Three independent settings, each for its own situation: a **rounded rim** for terrain with a visible edge (an island, a diorama board, a floating
|
|
4
|
+
level; recipe 42 for the outline), **snow cover** for any outdoor scene where it snows, and a **flat backdrop** for a scene that should have no
|
|
5
|
+
horizon (a menu stage, a board game, a diorama). All are style or scenario settings; none needs a shader of your own.
|
|
5
6
|
|
|
6
7
|
## Round rim
|
|
7
8
|
`terrain({ shape: { edge: { round: 1.2 } } })` bends the top down by up to 1.2 m toward the rim. The side wall follows every bend of the
|
|
@@ -12,7 +13,7 @@ With `shading: 'texture'` the color map is applied before the vertex colors, so
|
|
|
12
13
|
`style.seasons: { mode: 'mix', winter: { ground: 0xeef0f2 } }` therefore whitens the textured top like the side walls (recipe 43).
|
|
13
14
|
|
|
14
15
|
## Snow that settles: `style.weather.snow.cover`
|
|
15
|
-
```js
|
|
16
|
+
```js fragment
|
|
16
17
|
weather: {
|
|
17
18
|
snow: { size: 18, cover: { foliage: 0xf2f4f6, ground: 0xeef0f2, strength: 0.8 } },
|
|
18
19
|
},
|
|
@@ -22,23 +23,23 @@ weather: {
|
|
|
22
23
|
and any material with `applyEffects(m, { season: 'ground' })` follow; no extra shader pass.
|
|
23
24
|
- Over a `mode: 'mix'` season the two blend into one mix; a `'multiply'` season gives way while snow lies (use `'mix'` for smooth fades).
|
|
24
25
|
- Leave a part out to keep its season color (`cover: { foliage: 0xffffff }` whitens trees only). Leave `cover` out and snow is particles only.
|
|
25
|
-
- Ash, frost or anything else: `engine.
|
|
26
|
+
- Ash, frost or anything else: `engine.mod('look.ground.cover', { owner: 'ash', value: { ground: 0x555555, amount: 0.6 } })` (one entry per owner, the handle's `remove()` ends it).
|
|
26
27
|
|
|
27
28
|
## Weather changes and seasons in scenarios
|
|
28
29
|
- `engine.events.on('weather:change', ({ from, to }) => ...)`: once per change of name, when the blend starts (`weather.set` with the same name
|
|
29
30
|
again does not fire).
|
|
30
|
-
- `engine.applyState({ season: 'winter' })` (or `?season=winter`): jumps `
|
|
31
|
-
`
|
|
31
|
+
- `engine.applyState({ season: 'winter' })` (or `?season=winter`): jumps `calendar.day` to that season's first day, time of day kept. Needs
|
|
32
|
+
`calendar({ seasons })`; a wrong name throws with the calendar's list.
|
|
32
33
|
|
|
33
34
|
## Flat backdrop: `style.sky.backdrop`
|
|
34
|
-
```js
|
|
35
|
+
```js fragment
|
|
35
36
|
sky: { backdrop: 0xefebe4 }, // one color
|
|
36
|
-
sky: { backdrop: sky => (sky.isDay ? 0xefebe4 : 0x2c3346) }, // per frame (time of day, weather, your own state)
|
|
37
|
+
sky: { backdrop: ({ sky }) => (sky.isDay ? 0xefebe4 : 0x2c3346) }, // per frame (time of day, weather, your own state)
|
|
37
38
|
```
|
|
38
39
|
- Hides the dome (no gradient, horizon line, sun / moon disk, stars or clouds) and sets `scene.background` to the color. A plain background
|
|
39
40
|
color is not tone mapped, so what you write is what shows. `style.background` stays the color when there is no sky module.
|
|
40
41
|
- The keyframes still light the world (sun, ambient, their colors).
|
|
41
42
|
- Fog: in its default `'horizon'` color the fog follows the backdrop, so far things fade into it; `style.sky.fog.color` of your own wins.
|
|
42
43
|
- Not together with `skybox` (both replace the dome).
|
|
43
|
-
- To fade the backdrop toward gray in snow, read the weather in the function: `
|
|
44
|
+
- To fade the backdrop toward gray in snow, read the weather in the function: `() => new THREE.Color(0xefebe4).lerp(gray, engine.weather.current.snow * 0.3)`
|
|
44
45
|
(reuse the Color objects; it runs every frame).
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# 48. `engine.makeMaterial(role, spec)`: which keys work, who wins
|
|
2
2
|
|
|
3
|
-
`engine.makeMaterial('furniture', { color: 0x8a5a36 })` returns a normal three.js material. The **role** picks the look from
|
|
4
|
-
|
|
3
|
+
`engine.makeMaterial('furniture', { color: 0x8a5a36 })` returns a normal three.js material. The **role** picks the look from `engine.look.materials`,
|
|
4
|
+
the one entry for "what material a purpose gets": its style layer is the style's `materials` table (and a style plugin's Material), its game layer
|
|
5
|
+
`look.materials.set / replace` (unlisted roles use `default`); the **spec** is this call's own settings. A plain `new THREE.MeshStandardMaterial()`
|
|
6
|
+
needs none of this: it gets fog, cascaded shadows and cloud shadow by itself.
|
|
5
7
|
|
|
6
8
|
## Which spec keys are accepted
|
|
7
9
|
|
|
@@ -11,8 +13,11 @@
|
|
|
11
13
|
- `type`: `'lambert' | 'phong' | 'standard' | 'physical' | 'toon' | 'basic'` (default `lambert`, or whatever the pack says).
|
|
12
14
|
- Texture slots by asset name (or a `THREE.Texture`): `map`, `emissiveMap` (sRGB), `normalMap`, `roughnessMap`, `metalnessMap`, `aoMap`, `bumpMap`,
|
|
13
15
|
`alphaMap`... The slot must exist on the type (`roughnessMap` needs `standard`). Plus `repeat` (number or `[x, y]`) and `wrap` (`repeat | clamp | mirror`).
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
Per slot: `aoMap: { texture: 'ao', channel: 1 }` (second uv set, uv1), also `repeat`, `wrap`, `colorSpace` ('srgb' | 'linear' | 'none') for that slot only.
|
|
17
|
+
Your own `THREE.Texture` (or one registered in code: `assets.manifest({ textures: { brick: () => makeBrick() } })`) keeps its own repeat / wrap /
|
|
18
|
+
colorSpace; only what the spec writes changes, and then on a copy, never your texture.
|
|
19
|
+
- `detail`: a shortcut that lays an engine noise, a texture or your own GLSL over the surface in world space (no UVs); its keys: recipe 43.
|
|
20
|
+
- `lighting`: a shortcut that adds engine light-shaping functions (or your own GLSL) after the light is summed, merged over `style.lighting`; `false` opts out (recipe 43).
|
|
16
21
|
- toon only: `steps` (number of bands), or `ramp` (+ `soften`). `ramp` on a non-toon type throws.
|
|
17
22
|
- A key the chosen material does not have (`roughness` on lambert) is skipped on purpose, so one spec works for any type.
|
|
18
23
|
A key that looks like a typo of a real one (`roughnes`) warns once in dev with `did you mean 'roughness'?`. Nothing is ever blocked.
|
|
@@ -39,7 +44,7 @@ The result is an ordinary `THREE.Material`; edit it freely. The engine does not
|
|
|
39
44
|
```js
|
|
40
45
|
const glass = engine.makeMaterial('window', { color: 0x9fd4ff, transparent: true, opacity: 0.35, side: THREE.DoubleSide });
|
|
41
46
|
glass.depthWrite = false; // plain property edit, fine
|
|
42
|
-
glass.onBeforeCompile =
|
|
47
|
+
glass.onBeforeCompile = shader => { /* ... */ }; // allowed, but it replaces the engine's shader patches (wind, clouds, detail, lighting) on this material
|
|
43
48
|
```
|
|
44
49
|
|
|
45
50
|
Keep `makeMaterial` as the way to *create* materials (a style swap then restyles the game, `npm run check` flags a bare `new THREE.Mesh*Material`);
|
|
@@ -67,4 +72,4 @@ engine.makeMaterial('wall', { color: 0xc9b99a, detail: { noise: 'paper' }, light
|
|
|
67
72
|
engine.makeMaterial('character', { type: 'toon', color: 0xe8a0a0, ramp: [0.25, 0.6, 1] });
|
|
68
73
|
```
|
|
69
74
|
|
|
70
|
-
See also: `09-style
|
|
75
|
+
See also: `09-style.md` (writing the pack side), `43-shader-patches-surface-looks.md` (detail / lighting / patches).
|