threedog 0.7.0 → 1.0.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.
Files changed (593) hide show
  1. package/CHANGELOG.md +411 -1
  2. package/README.md +8 -11
  3. package/core/{Animator.js → assets/Animator.js} +30 -18
  4. package/core/{Assets.js → assets/Assets.js} +131 -56
  5. package/core/{Baked.js → assets/Baked.js} +4 -4
  6. package/core/assets/assetEntry.js +302 -0
  7. package/core/{assetHot.js → assets/assetHot.js} +9 -7
  8. package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
  9. package/core/assets/assetLod.js +113 -0
  10. package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
  11. package/core/{assetReport.js → assets/assetReport.js} +7 -14
  12. package/core/{namedModel.js → assets/namedModel.js} +17 -13
  13. package/core/{Audio.js → audio/Audio.js} +47 -25
  14. package/core/{audioRules.js → audio/audioRules.js} +8 -5
  15. package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
  16. package/core/{Events.js → base/Events.js} +3 -3
  17. package/core/{I18n.js → base/I18n.js} +15 -12
  18. package/core/{Random.js → base/Random.js} +7 -4
  19. package/core/{Vars.js → base/Vars.js} +14 -4
  20. package/core/{easing.js → base/easing.js} +1 -1
  21. package/core/{errorCodes.js → base/errorCodes.js} +151 -125
  22. package/core/{errorHints.js → base/errorHints.js} +17 -10
  23. package/core/{errors.js → base/errors.js} +12 -10
  24. package/core/{events.generated.js → base/events.generated.js} +11 -0
  25. package/core/base/follows.js +26 -0
  26. package/core/base/math.js +66 -0
  27. package/core/{params.js → base/params.js} +5 -6
  28. package/core/base/saveValues.js +81 -0
  29. package/core/base/sections.js +97 -0
  30. package/core/base/spelling.js +32 -0
  31. package/core/base/util.js +32 -0
  32. package/core/{validate.js → base/validate.js} +34 -34
  33. package/core/{Engine.js → engine/Engine.js} +137 -91
  34. package/core/{Loading.js → engine/Loading.js} +34 -5
  35. package/core/{copies.js → engine/copies.js} +4 -4
  36. package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
  37. package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
  38. package/core/{loop.js → engine/loop.js} +88 -49
  39. package/core/engine/moduleSlots.js +176 -0
  40. package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
  41. package/core/engine/modules.js +503 -0
  42. package/core/{page.js → engine/page.js} +59 -29
  43. package/core/{plugins.js → engine/plugins.js} +21 -12
  44. package/core/{services.js → engine/services.js} +50 -40
  45. package/core/{startup.js → engine/startup.js} +66 -54
  46. package/core/{Input.js → input/Input.js} +67 -39
  47. package/core/{inputContext.js → input/inputContext.js} +14 -5
  48. package/core/input/inputKeyboard.js +39 -0
  49. package/core/{inputPad.js → input/inputPad.js} +24 -3
  50. package/core/{inputPointer.js → input/inputPointer.js} +11 -3
  51. package/core/input/inputSeat.js +66 -0
  52. package/core/{inputTouch.js → input/inputTouch.js} +24 -7
  53. package/core/{Budget.js → inspect/Budget.js} +21 -20
  54. package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
  55. package/core/{Describe.js → inspect/Describe.js} +34 -26
  56. package/core/{Inspect.js → inspect/Inspect.js} +39 -10
  57. package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
  58. package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
  59. package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
  60. package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
  61. package/core/{UrlState.js → inspect/UrlState.js} +60 -24
  62. package/core/{catalog.js → inspect/catalog.js} +15 -8
  63. package/core/{checks.js → inspect/checks.js} +7 -5
  64. package/core/{debugView.js → inspect/debugView.js} +4 -4
  65. package/core/{describeRender.js → inspect/describeRender.js} +24 -22
  66. package/core/{describeText.js → inspect/describeText.js} +17 -8
  67. package/core/inspect/geometryWatch.js +38 -0
  68. package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
  69. package/core/inspect/metadata.generated.js +4140 -0
  70. package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
  71. package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
  72. package/core/inspect/toolDoor.js +21 -0
  73. package/core/inspect/valueHistory.js +35 -0
  74. package/core/{Ops.js → ops/Ops.js} +44 -14
  75. package/core/{control.js → ops/control.js} +57 -31
  76. package/core/ops/holds.js +140 -0
  77. package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
  78. package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
  79. package/core/{opsFail.js → ops/opsFail.js} +5 -7
  80. package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
  81. package/core/{opsRun.js → ops/opsRun.js} +9 -6
  82. package/core/{owned.js → ops/owned.js} +33 -19
  83. package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
  84. package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
  85. package/core/{stacks.js → ops/stacks.js} +34 -15
  86. package/core/{wrap.js → ops/wrap.js} +8 -6
  87. package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
  88. package/core/{Saves.js → saves/Saves.js} +171 -54
  89. package/core/saves/saveApply.js +312 -0
  90. package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
  91. package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
  92. package/core/saves/session.js +231 -0
  93. package/core/saves/stateReplace.js +184 -0
  94. package/core/{Rays.js → scene/Rays.js} +44 -30
  95. package/core/{Views.js → scene/Views.js} +16 -8
  96. package/core/{adaptive.js → scene/adaptive.js} +19 -9
  97. package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
  98. package/core/scene/compositeGround.js +72 -0
  99. package/core/scene/floor.js +17 -0
  100. package/core/{gameLights.js → scene/gameLights.js} +17 -7
  101. package/core/{grayMap.js → scene/grayMap.js} +8 -2
  102. package/core/{grid.js → scene/grid.js} +6 -4
  103. package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
  104. package/core/scene/ground.contract.js +14 -0
  105. package/core/scene/ground.js +139 -0
  106. package/core/{movement.js → scene/movement.js} +3 -3
  107. package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
  108. package/core/scene/pixel.js +154 -0
  109. package/core/scene/pixelRatio.js +167 -0
  110. package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
  111. package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
  112. package/core/scene/stepPoses.js +60 -0
  113. package/core/{targeting.js → scene/targeting.js} +4 -5
  114. package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
  115. package/core/{thingOps.js → scene/thingOps.js} +25 -16
  116. package/core/{things.js → scene/things.js} +18 -5
  117. package/core/{threePatches.js → scene/threePatches.js} +1 -1
  118. package/core/{tier.js → scene/tier.js} +10 -0
  119. package/core/scene/view.js +161 -0
  120. package/core/{Batching.js → stream/Batching.js} +85 -28
  121. package/core/{Stream.js → stream/Stream.js} +80 -38
  122. package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
  123. package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
  124. package/core/{scatter.js → stream/scatter.js} +7 -4
  125. package/core/{streamSources.js → stream/streamSources.js} +14 -8
  126. package/core/{Commits.js → threads/Commits.js} +17 -11
  127. package/core/{Jobs.js → threads/Jobs.js} +25 -13
  128. package/core/{Threads.js → threads/Threads.js} +21 -18
  129. package/core/{threadPure.js → threads/threadPure.js} +7 -5
  130. package/core/{threadServe.js → threads/threadServe.js} +3 -3
  131. package/core/{Clock.js → time/Clock.js} +20 -11
  132. package/core/{dayTime.js → time/dayTime.js} +5 -1
  133. package/core/{skip.js → time/skip.js} +28 -21
  134. package/core/{time.js → time/time.js} +32 -20
  135. package/core/{uiClock.js → time/uiClock.js} +4 -4
  136. package/docs/AI.md +92 -72
  137. package/docs/API.md +33 -28
  138. package/docs/CODEMAP.md +121 -200
  139. package/docs/COMMANDS.md +77 -70
  140. package/docs/CONVENTIONS.md +167 -24
  141. package/docs/MIGRATING-0.8.md +171 -0
  142. package/docs/MIGRATING-1.0.md +101 -0
  143. package/docs/THREE.md +140 -38
  144. package/docs/api/assets.md +12 -13
  145. package/docs/api/audio.md +6 -5
  146. package/docs/api/budget.md +4 -4
  147. package/docs/api/calendar.md +10 -11
  148. package/docs/api/cameraRig.md +32 -29
  149. package/docs/api/characters.md +35 -24
  150. package/docs/api/clock.md +1 -1
  151. package/docs/api/collider3d.md +9 -0
  152. package/docs/api/collision.md +12 -9
  153. package/docs/api/content.md +18 -17
  154. package/docs/api/dialogue.md +5 -4
  155. package/docs/api/engine.md +58 -54
  156. package/docs/api/events.md +17 -6
  157. package/docs/api/flow.md +1 -1
  158. package/docs/api/grids.md +1 -1
  159. package/docs/api/ground.md +6 -7
  160. package/docs/api/hud.md +2 -2
  161. package/docs/api/i18n.md +6 -6
  162. package/docs/api/input.md +9 -8
  163. package/docs/api/interactions.md +5 -5
  164. package/docs/api/inventory.md +10 -10
  165. package/docs/api/jobs.md +5 -5
  166. package/docs/api/level.md +10 -9
  167. package/docs/api/lightPool.md +1 -6
  168. package/docs/api/music.md +3 -3
  169. package/docs/api/nav.md +14 -12
  170. package/docs/api/openWorld.md +1 -1
  171. package/docs/api/particles.md +10 -7
  172. package/docs/api/photo.md +4 -2
  173. package/docs/api/pickups.md +3 -3
  174. package/docs/api/post.md +21 -5
  175. package/docs/api/quests.md +7 -5
  176. package/docs/api/rays.md +7 -7
  177. package/docs/api/rigid.md +29 -19
  178. package/docs/api/saves.md +13 -11
  179. package/docs/api/settings.md +9 -8
  180. package/docs/api/sky.md +8 -7
  181. package/docs/api/stream.md +8 -9
  182. package/docs/api/swarm.md +34 -0
  183. package/docs/api/terrain.md +6 -8
  184. package/docs/api/terrainDraw.md +2 -2
  185. package/docs/api/timeline.md +4 -4
  186. package/docs/api/tools.md +27 -22
  187. package/docs/api/triggers.md +2 -0
  188. package/docs/api/vars.md +1 -1
  189. package/docs/api/vegetation.md +4 -3
  190. package/docs/api/vegetationDraw.md +2 -2
  191. package/docs/api/water.md +7 -3
  192. package/docs/api/weather.md +27 -12
  193. package/docs/api/weatherDraw.md +4 -4
  194. package/docs/api/world.md +6 -6
  195. package/docs/recipes/01-new-game.md +28 -43
  196. package/docs/recipes/02-npc.md +21 -23
  197. package/docs/recipes/03-items-pickups.md +37 -53
  198. package/docs/recipes/04-quests.md +5 -4
  199. package/docs/recipes/05-props-bake.md +34 -44
  200. package/docs/recipes/06-clock-events.md +31 -22
  201. package/docs/recipes/07-flow-scenes-pause.md +30 -32
  202. package/docs/recipes/08-weather-sky.md +91 -37
  203. package/docs/recipes/09-materials-lights-models.md +25 -39
  204. package/docs/recipes/10-blender-level.md +22 -11
  205. package/docs/recipes/11-vehicles.md +44 -24
  206. package/docs/recipes/12-navmesh.md +60 -15
  207. package/docs/recipes/13-animation.md +70 -22
  208. package/docs/recipes/14-custom-module.md +33 -20
  209. package/docs/recipes/15-perf.md +51 -28
  210. package/docs/recipes/16-dev-bridge.md +39 -58
  211. package/docs/recipes/18-world.md +49 -28
  212. package/docs/recipes/19-shooting-picking.md +7 -4
  213. package/docs/recipes/20-content-actions-save.md +55 -40
  214. package/docs/recipes/21-camera.md +47 -25
  215. package/docs/recipes/22-shop-gold.md +21 -16
  216. package/docs/recipes/23-ops.md +28 -24
  217. package/docs/recipes/26-ui-parts.md +25 -14
  218. package/docs/recipes/27-net.md +3 -5
  219. package/docs/recipes/28-terrain.md +119 -23
  220. package/docs/recipes/29-grid.md +3 -3
  221. package/docs/recipes/30-templates.md +63 -30
  222. package/docs/recipes/31-audio.md +7 -7
  223. package/docs/recipes/32-action-game.md +21 -11
  224. package/docs/recipes/33-stream-sources.md +6 -3
  225. package/docs/recipes/34-environment-lighting.md +72 -25
  226. package/docs/recipes/35-picture-from-reference.md +20 -23
  227. package/docs/recipes/36-ground-plants.md +106 -0
  228. package/docs/recipes/40-scene.md +18 -21
  229. package/docs/recipes/43-shader-patches-surfaces.md +27 -48
  230. package/docs/recipes/44-water-weather-hooks.md +56 -50
  231. package/docs/recipes/45-cascaded-shadows.md +41 -20
  232. package/docs/recipes/46-blender-art-route.md +9 -10
  233. package/docs/recipes/49-game-module-contract.md +7 -6
  234. package/docs/recipes/50-own-renderer.md +3 -2
  235. package/docs/recipes/51-capability-catalog.md +14 -8
  236. package/docs/recipes/52-around-the-picture.md +56 -100
  237. package/docs/recipes/53-ground-up-close.md +61 -24
  238. package/docs/recipes/55-mods-time-wrap.md +17 -20
  239. package/docs/recipes/56-webgpu-tsl.md +28 -15
  240. package/docs/recipes/57-control.md +39 -12
  241. package/docs/recipes/58-input.md +15 -2
  242. package/docs/recipes/59-depth-post-effects.md +1 -1
  243. package/docs/recipes/60-judge-the-picture.md +30 -25
  244. package/docs/recipes/62-picture-code.md +129 -39
  245. package/docs/recipes/63-third-person-start.md +19 -5
  246. package/docs/recipes/64-particles.md +54 -5
  247. package/docs/recipes/65-swarm.md +140 -0
  248. package/docs/recipes/66-common-tasks.md +313 -0
  249. package/examples/action/.threedog/content-index.json +1 -1
  250. package/examples/action/GAMEMAP.md +5 -5
  251. package/examples/perf-island/.threedog/content-index.json +1 -0
  252. package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
  253. package/examples/{sheepisland → perf-island}/assets.js +1 -1
  254. package/examples/{sheepisland → perf-island}/main.js +8 -8
  255. package/examples/{sheepisland → perf-island}/models.js +1 -1
  256. package/examples/{sheepisland → perf-island}/params.js +1 -1
  257. package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
  258. package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
  259. package/examples/{sheepisland → perf-island}/views.js +1 -1
  260. package/examples/plain-picture/GAMEMAP.md +4 -1
  261. package/examples/rc2d/GAMEMAP.md +4 -3
  262. package/examples/rc2d/main.js +1 -3
  263. package/examples/rc2d/rc2d.js +1 -1
  264. package/examples/styletest/.threedog/content-index.json +1 -1
  265. package/examples/styletest/GAMEMAP.md +6 -5
  266. package/examples/techniques/contact-shadows/contactShadows.js +1 -1
  267. package/examples/techniques/contact-shadows/main.js +1 -1
  268. package/examples/techniques/interior-light/main.js +1 -1
  269. package/examples/techniques/modular-building/README.md +7 -6
  270. package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
  271. package/examples/techniques/procedural-animation/README.md +1 -1
  272. package/examples/webgpu-tsl/GAMEMAP.md +2 -1
  273. package/examples/world/.threedog/content-index.json +1 -1
  274. package/examples/world/GAMEMAP.md +9 -7
  275. package/examples/world/main.js +3 -3
  276. package/examples/world/picture/sky.js +1 -1
  277. package/index.d.ts +16 -12
  278. package/index.js +53 -32
  279. package/llms.txt +11 -14
  280. package/modules/ambience/Ambience.js +16 -11
  281. package/modules/calendar/Calendar.js +19 -19
  282. package/modules/calendar/index.js +18 -16
  283. package/modules/calendar/schedule.js +11 -6
  284. package/modules/calendar/seasons.js +7 -7
  285. package/modules/camera/FirstPersonCamera.js +5 -5
  286. package/modules/camera/FixedCamera.js +43 -30
  287. package/modules/camera/FollowCamera.js +24 -15
  288. package/modules/camera/RtsCamera.js +12 -11
  289. package/modules/camera/common.js +72 -37
  290. package/modules/camera/contract.js +1 -0
  291. package/modules/camera/pixelSnap.js +62 -0
  292. package/modules/characters/Character.js +166 -70
  293. package/modules/characters/NPC.js +84 -44
  294. package/modules/characters/assetModel.js +16 -12
  295. package/modules/characters/astar.js +48 -27
  296. package/modules/characters/behaviors.js +4 -5
  297. package/modules/characters/character.contract.js +21 -0
  298. package/modules/characters/contract.js +17 -3
  299. package/modules/characters/index.js +240 -226
  300. package/modules/characters/moveHelpers.js +88 -12
  301. package/modules/characters/mover.contract.js +14 -0
  302. package/modules/characters/movers/common.js +22 -18
  303. package/modules/characters/movers/manual.js +1 -1
  304. package/modules/characters/movers/rapier.js +18 -10
  305. package/modules/characters/movers/simple.js +26 -13
  306. package/modules/characters/movers/support.js +24 -13
  307. package/modules/characters/npcAvoid.js +19 -16
  308. package/modules/characters/npcSim.js +88 -32
  309. package/modules/characters/npcView.js +19 -11
  310. package/modules/characters/pathAsync.js +81 -29
  311. package/modules/characters/pathJob.js +38 -21
  312. package/modules/characters/pathWorker.js +1 -1
  313. package/modules/characters/player.js +120 -0
  314. package/modules/characters/playerStrings.js +2 -2
  315. package/modules/characters/proceduralRig.js +2 -2
  316. package/modules/characters/seat.js +56 -0
  317. package/modules/characters/useModel.js +3 -3
  318. package/modules/characters/vehicle.contract.js +8 -5
  319. package/modules/characters/walkTo.js +40 -33
  320. package/modules/collision/Collision.js +69 -45
  321. package/modules/collision/contract.js +15 -0
  322. package/modules/collision/grid.js +6 -1
  323. package/modules/content/explain.js +2 -3
  324. package/modules/content/fields.js +24 -3
  325. package/modules/content/ids.js +5 -3
  326. package/modules/content/index.js +132 -114
  327. package/modules/content/loader.js +117 -140
  328. package/modules/content/markers.js +25 -0
  329. package/modules/content/models.js +54 -17
  330. package/modules/content/packs.js +5 -4
  331. package/modules/content/parts.js +2 -2
  332. package/modules/content/places.js +36 -0
  333. package/modules/content/props.js +22 -17
  334. package/modules/content/rules.js +47 -61
  335. package/modules/content/stages.js +7 -7
  336. package/modules/content/templates.js +80 -49
  337. package/modules/content/words.js +47 -0
  338. package/modules/debug/DebugPanel.js +14 -45
  339. package/modules/flow/contract.js +2 -1
  340. package/modules/flow/index.js +30 -16
  341. package/modules/gameplay/Container.js +17 -13
  342. package/modules/gameplay/Containers.js +23 -6
  343. package/modules/gameplay/Dialogue.js +93 -34
  344. package/modules/gameplay/Interactions.js +93 -51
  345. package/modules/gameplay/Inventory.js +64 -22
  346. package/modules/gameplay/Quests.js +146 -30
  347. package/modules/gameplay/boxOps.js +8 -1
  348. package/modules/gameplay/dialogueBubbles.js +16 -12
  349. package/modules/gameplay/inventoryOps.js +11 -8
  350. package/modules/gameplay/pickups.js +63 -37
  351. package/modules/gameplay/questLog.js +4 -2
  352. package/modules/gameplay/questSave.js +9 -4
  353. package/modules/gameplay/quests.contract.js +1 -1
  354. package/modules/grid/Grid.js +2 -2
  355. package/modules/grid/Layer.js +12 -8
  356. package/modules/grid/index.js +28 -23
  357. package/modules/grid/ops.js +43 -46
  358. package/modules/grid/preview.js +7 -7
  359. package/modules/grid/tiles.js +6 -6
  360. package/modules/hlod/index.js +42 -57
  361. package/modules/hud/index.js +22 -14
  362. package/modules/hud/parts.js +8 -8
  363. package/modules/level/contract.js +16 -0
  364. package/modules/level/heightfield.js +29 -31
  365. package/modules/level/index.js +113 -161
  366. package/modules/level/load.js +196 -0
  367. package/modules/level/meshes.js +65 -0
  368. package/modules/level/nodes.js +40 -23
  369. package/modules/lights/index.js +33 -183
  370. package/modules/lights/slots.js +93 -0
  371. package/modules/lights/sources.js +90 -0
  372. package/modules/music/Music.js +34 -28
  373. package/modules/music/rules.js +1 -1
  374. package/modules/nav/contract.js +16 -0
  375. package/modules/nav/index.js +180 -49
  376. package/modules/nav/navPath.js +45 -10
  377. package/modules/net/Client.js +7 -7
  378. package/modules/net/Host.js +7 -7
  379. package/modules/net/Net.js +1 -1
  380. package/modules/net/index.js +6 -5
  381. package/modules/net/sync.js +2 -2
  382. package/modules/net/transports.js +2 -2
  383. package/modules/particles/Particles.js +95 -29
  384. package/modules/particles/effect.js +86 -32
  385. package/modules/particles/shaders.js +19 -1
  386. package/modules/photo/Photo.js +23 -23
  387. package/modules/rigid/RigidBodies.js +255 -89
  388. package/modules/rigid/Vehicles.js +17 -8
  389. package/modules/rigid/collider3d.contract.js +26 -0
  390. package/modules/rigid/ragdoll.js +298 -0
  391. package/modules/rigid/ragdollBones.js +209 -0
  392. package/modules/rigid/refresh.js +10 -0
  393. package/modules/rigid/sync.js +51 -20
  394. package/modules/settings/Settings.js +177 -61
  395. package/modules/settings/apply.js +20 -13
  396. package/modules/settings/sections.js +19 -14
  397. package/modules/settings/strings.js +2 -2
  398. package/modules/settings/view.js +3 -3
  399. package/modules/sky/Sky.js +29 -22
  400. package/modules/sky/clouds.js +7 -7
  401. package/modules/sky/dome.js +33 -20
  402. package/modules/sky/domeLayers.js +9 -9
  403. package/modules/sky/environment.js +6 -6
  404. package/modules/sky/frame.js +19 -10
  405. package/modules/sky/season.js +7 -1
  406. package/modules/sky/shader.js +24 -25
  407. package/modules/sky/skyModule.js +17 -28
  408. package/modules/sky/tint.js +1 -1
  409. package/modules/swarm/Swarm.js +356 -0
  410. package/modules/swarm/draw.js +68 -0
  411. package/modules/swarm/grid.js +63 -0
  412. package/modules/terrain/ChunkManager.js +71 -59
  413. package/modules/terrain/chunkQueries.js +7 -24
  414. package/modules/terrain/chunkWorker.js +1 -1
  415. package/modules/terrain/draw.js +14 -11
  416. package/modules/terrain/index.js +42 -42
  417. package/modules/terrain/terrainColorMap.js +6 -3
  418. package/modules/terrain/terrainDefaults.js +2 -1
  419. package/modules/terrain/terrainEdit.js +45 -29
  420. package/modules/terrain/terrainGen.js +19 -12
  421. package/modules/terrain/terrainIsland.js +2 -2
  422. package/modules/terrain/terrainMesh.js +7 -6
  423. package/modules/terrain/terrainShape.js +8 -10
  424. package/modules/terrain/terrainShapeMain.js +3 -3
  425. package/modules/timeline/Timeline.js +83 -43
  426. package/modules/timeline/Tween.js +25 -19
  427. package/modules/timeline/shots.js +24 -17
  428. package/modules/triggers/index.js +95 -28
  429. package/modules/vegetation/Vegetation.js +34 -26
  430. package/modules/vegetation/densityMap.js +4 -7
  431. package/modules/vegetation/draw.js +39 -18
  432. package/modules/vegetation/groundChunks.js +21 -38
  433. package/modules/vegetation/index.js +37 -12
  434. package/modules/vegetation/modelGeometry.js +3 -6
  435. package/modules/vegetation/nearFade.js +1 -1
  436. package/modules/water/Water.js +20 -16
  437. package/modules/water/surface.js +3 -3
  438. package/modules/weather/Weather.js +52 -40
  439. package/modules/weather/particles.js +8 -8
  440. package/modules/weather/weatherDraw.js +28 -23
  441. package/modules/world/World.js +28 -15
  442. package/modules/world/explain.js +1 -1
  443. package/modules/world/index.js +30 -17
  444. package/modules/world/persist.js +90 -27
  445. package/modules/world/pos.js +5 -5
  446. package/modules/world/records.js +37 -11
  447. package/modules/world/sim.js +78 -27
  448. package/modules/world/simFar.js +2 -2
  449. package/modules/world/state.js +43 -11
  450. package/modules/world/thingSource.js +20 -5
  451. package/modules/world/views.js +27 -14
  452. package/package.json +48 -7
  453. package/presets.js +1 -3
  454. package/render/PostFX.js +83 -53
  455. package/render/backend.js +31 -33
  456. package/render/cascades.js +17 -12
  457. package/render/cascades.tsl.js +5 -8
  458. package/render/daylight.js +20 -3
  459. package/render/detail.js +8 -7
  460. package/render/effects.js +28 -25
  461. package/render/fuse.js +3 -3
  462. package/render/fx/cloudShadow.tsl.js +3 -3
  463. package/render/fx/detail.tsl.js +1 -1
  464. package/render/fx/index.js +5 -10
  465. package/render/fx/library.tsl.js +11 -0
  466. package/render/fx/lighting.tsl.js +2 -1
  467. package/render/fx/nodeErrors.tsl.js +2 -2
  468. package/render/fx/objectOrigin.tsl.js +1 -2
  469. package/render/fx/particles.tsl.js +8 -6
  470. package/render/fx/patchNodes.tsl.js +5 -15
  471. package/render/fx/postWebGPU.tsl.js +30 -26
  472. package/render/fx/sky.tsl.js +15 -17
  473. package/render/fx/uniforms.tsl.js +4 -4
  474. package/render/fx/wind.tsl.js +1 -1
  475. package/render/fxNumbers.js +3 -0
  476. package/render/layers.js +2 -2
  477. package/render/lighting.js +5 -3
  478. package/render/lightmap.js +41 -21
  479. package/render/lights.js +6 -6
  480. package/render/lit.js +24 -0
  481. package/render/materials.js +8 -7
  482. package/render/mergeCommon.js +22 -0
  483. package/render/modeling.js +2 -2
  484. package/render/occlusion.js +62 -15
  485. package/render/ownFrame.js +4 -4
  486. package/render/patches.js +15 -15
  487. package/render/postWebGL.js +15 -12
  488. package/render/probes.js +41 -19
  489. package/render/recordSweep.js +117 -0
  490. package/render/shaderErrors.js +10 -9
  491. package/render/shadowCache.tsl.js +107 -0
  492. package/render/shadowTypes.js +9 -0
  493. package/{core → render}/shadows.js +59 -13
  494. package/render/slots.js +7 -7
  495. package/render/terms.js +22 -24
  496. package/render/uniformDecl.js +1 -1
  497. package/types/core.d.ts +336 -202
  498. package/types/gameplay.d.ts +254 -130
  499. package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
  500. package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
  501. package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
  502. package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
  503. package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
  504. package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
  505. package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
  506. package/types/generated/core/input/inputSeat.d.ts +26 -0
  507. package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
  508. package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
  509. package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
  510. package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
  511. package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
  512. package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
  513. package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
  514. package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
  515. package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
  516. package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
  517. package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
  518. package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
  519. package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
  520. package/types/generated/modules/calendar/Calendar.d.ts +10 -11
  521. package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
  522. package/types/generated/modules/grid/Grid.d.ts +1 -0
  523. package/types/generated/modules/grid/Layer.d.ts +1 -1
  524. package/types/generated/modules/grid/index.d.ts +3 -3
  525. package/types/generated/modules/music/Music.d.ts +7 -5
  526. package/types/generated/modules/particles/Particles.d.ts +5 -4
  527. package/types/generated/modules/sky/Sky.d.ts +21 -10
  528. package/types/generated/modules/swarm/Swarm.d.ts +80 -0
  529. package/types/generated/modules/timeline/Timeline.d.ts +7 -5
  530. package/types/generated/modules/water/Water.d.ts +1 -0
  531. package/types/generated/modules/weather/Weather.d.ts +14 -16
  532. package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
  533. package/types/generated/modules/world/World.d.ts +11 -7
  534. package/types/generated/render/PostFX.d.ts +21 -23
  535. package/types/generated/render/materials.d.ts +1 -0
  536. package/types/generated/render/occlusion.d.ts +9 -0
  537. package/types/generated/render/patches.d.ts +1 -0
  538. package/types/generated/ui/Focus.d.ts +1 -0
  539. package/types/generated/ui/UI.d.ts +1 -0
  540. package/types/nav.d.ts +47 -15
  541. package/types/physics.d.ts +150 -73
  542. package/types/pixel.d.ts +75 -0
  543. package/types/tsl.d.ts +37 -4
  544. package/types/world.d.ts +48 -75
  545. package/ui/Focus.js +10 -9
  546. package/ui/Parts.js +13 -5
  547. package/ui/UI.js +7 -7
  548. package/ui/defaults.js +3 -2
  549. package/ui/theme.js +7 -5
  550. package/core/assetEntry.js +0 -109
  551. package/core/engineCamera.js +0 -32
  552. package/core/ground.js +0 -104
  553. package/core/holds.js +0 -134
  554. package/core/math.js +0 -48
  555. package/core/moduleSlots.js +0 -100
  556. package/core/modules.js +0 -314
  557. package/core/saveApply.js +0 -210
  558. package/core/saveValues.js +0 -46
  559. package/core/session.js +0 -174
  560. package/core/shadowTypes.js +0 -16
  561. package/core/util.js +0 -17
  562. package/core/view.js +0 -43
  563. package/docs/MIGRATING-0.3.md +0 -248
  564. package/docs/MIGRATING-0.4.md +0 -320
  565. package/docs/MIGRATING-0.5.md +0 -68
  566. package/docs/MIGRATING-0.6.md +0 -126
  567. package/docs/PERF.md +0 -245
  568. package/docs/recipes/36-sky-ground-plants.md +0 -158
  569. package/docs/recipes/37-terrain-hooks.md +0 -115
  570. package/docs/recipes/38-environment-hooks.md +0 -67
  571. package/docs/recipes/42-terrain-shape.md +0 -64
  572. package/docs/recipes/47-island-snow-backdrop.md +0 -43
  573. package/docs/recipes/54-three-idioms.md +0 -88
  574. package/examples/plain-picture/FINDINGS.md +0 -53
  575. package/examples/sheepisland/.threedog/content-index.json +0 -1
  576. package/modules/camera/projection.js +0 -21
  577. /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
  578. /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
  579. /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
  580. /package/core/{actor.js → ops/actor.js} +0 -0
  581. /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
  582. /package/core/{saveIds.js → saves/saveIds.js} +0 -0
  583. /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
  584. /package/core/{cells.js → stream/cells.js} +0 -0
  585. /package/core/{streamCells.js → stream/streamCells.js} +0 -0
  586. /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
  587. /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
  588. /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
  589. /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
  590. /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
  591. /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
  592. /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
  593. /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
@@ -1,24 +1,69 @@
1
- # The ground up close: options and diagnosis
1
+ # The ground up close: options, crisp color borders, normals, diagnosis
2
2
 
3
3
  Not a standard recipe. Several pictures are right for different games, and none is the default. **Decide from the reference images first**: is the
4
4
  ground flat color shapes, a painted surface, a photographic texture, or a few lit polygons? Then pick a row. If the ground already looks wrong,
5
5
  jump to the symptoms.
6
6
 
7
7
  ## Approaches (pick by the picture you want)
8
- | Picture | How | Typical values |
9
- |---|---|---|
10
- | Flat color blocks, no detail (minimal, flat illustration; on purpose) | `shading: 'flat'` or `'smooth'`, `colors` / `biomeColors`, no `detail`; a few `variation.patches` with `levels` | `resolution: 16`; `patches: { size: 90, levels: 3, strength: 0.15 }` |
11
- | Color map + detail layer + near grass (soft variation, crisp borders) | `terrain({ shading: 'texture', colorResolution, detail })`, grass with `vegetation.define(name, { nearOnly: true })` | `colorResolution: 128`; `detail: { noise: 'dabs', scale: 0.5, strength: 0.25, normal: 0.03 }` |
12
- | Tiling or triplanar textures (your own painted, photographed or generated images) | your own material with `map` and `texture.repeat` through `terrain({ material })`, or `detail: { texture: 'name' }` (`projection: 'triplanar'` on slopes and rocks) | `repeat: 8`; `detail: { texture, scale: 0.5, strength: 0.6 }` |
13
- | Vertex color + toon lighting | vertex colors from `colors` and `variation.jitter`, `terrain({ material })` with a `MeshToonMaterial`, `gradientMap: rampTexture(...)`; detail optional | `jitter: { size: 2, min: 0.9, range: 0.15 }`; `rampTexture([0.4, 0.75, 1])` |
14
- | Your own shader or plain three.js | `terrain({ material })`, or recipe 40 section 8 (what you give up) | any |
8
+ | Picture | How |
9
+ |---|---|
10
+ | Flat color blocks, no detail (minimal, flat illustration; on purpose) | `shading: 'flat'` or `'smooth'`, `colors` / `biomeColors`, no `detail`; a few `variation.patches` with `levels` |
11
+ | Color map + detail layer + near grass (soft variation, crisp borders) | `terrain({ shading: 'texture', colorResolution, detail })`, grass with `vegetation.define(name, { nearOnly: true })` |
12
+ | Tiling or triplanar textures (your own painted, photographed or generated images) | your own material with `map` and `texture.repeat` through `terrain({ material })`, or `detail: { texture: 'name' }` (`projection: 'triplanar'` on slopes and rocks) |
13
+ | Vertex color + toon lighting | vertex colors from `colors` and `variation.jitter`, `terrain({ material })` with a `MeshToonMaterial`, `gradientMap: rampTexture(...)`; detail optional |
14
+ | Your own shader or plain three.js | `terrain({ material })`, or recipe 40 section 8 (what you give up) |
15
15
 
16
16
  Detail noises (recipe 43): `grain` fine speckle, `paper` fibres, `stroke` directional streaks (stretched on purpose), `dabs` soft oval dabs with
17
- no direction. `fade` (on by default) removes the detail where its pattern is smaller than a pixel. At run time: `engine.terrain.recolor({ detail })`. On any
17
+ no direction. `fade` (on by default) removes the detail where its pattern is smaller than a pixel. On any
18
18
  other material: `applyEffects(mat, { detail })`, with your own function as `detail: { glsl }` (recipe 43).
19
19
 
20
- Where each key is defined: `variation` (blend, jitter, patches) recipe 36; `shading`, `colorResolution`, `normals`, `normalFn`, heights from a
21
- grid recipe 37; `detail` keys recipe 43; run-time changes `engine.terrain.recolor` recipe 36; terrain basics recipe 28.
20
+ `variation`, `recolor` and your own material are in recipe 36; terrain basics, the triangle cut and heights from a grid in recipe 28.
21
+
22
+ ## Crisp borders: `shading: 'texture'`
23
+ With `shading: 'smooth'` or `'flat'` a color is computed at a grid point (or triangle center) and blended across the triangle. At the default
24
+ `resolution: 16` on a 64 m chunk that is one color sample per 4 m, so any border between two ground types can only run along triangle edges.
25
+ Raising `resolution` fixes it at the price of triangles (and collision, and edit granularity). `shading: 'texture'` cuts the link: color is
26
+ computed per pixel into a per-chunk image, the mesh stays as coarse as you like.
27
+
28
+ ```js
29
+ engine.use(terrain({
30
+ shading: 'texture', colorResolution: 192, resolution: 16,
31
+ height: (x, z) => 0,
32
+ // the border is a curve; the ground type is evaluated per pixel
33
+ groundType: (x, z) => z > 32 + 14 * Math.sin(x * 0.09) ? 'grass' : 'sand',
34
+ colors: { grass: 0x5a8a3a, sand: 0xd8c690 }, biomeColors: { grass: ['grass'], sand: ['sand'] },
35
+ }));
36
+ ```
37
+ With a preset the same switch gives crisp banks without more triangles: `terrain({ ...terrainPreset(), shading: 'texture' })`.
38
+
39
+ - A worker computes a `(colorResolution + 2)^2` RGBA image per chunk with the same rules as the vertex colors (`groundType`, `biomeColors`, `steep`, `variation`, painted cells).
40
+ The `+ 2` is a 1 pixel border computed from world coordinates, so neighboring chunks hold identical values at the seam and no seam shows.
41
+ - Vertex colors are plain white in this mode. The material samples the image by world xz, so `uv`
42
+ stays free for your own textures. The map goes on before the vertex colors, so every patch after it sees the mapped color: a `mode: 'mix'` season tint (recipe 36) tints the textured top like the side walls.
43
+ - Each chunk gets its own clone of the terrain material (same patches, one compiled
44
+ program), so a property you write on the material object after chunks exist does not reach loaded chunks. Assign a material instead (`engine.terrain.material = m`, which remounts every chunk), or pass it through `terrain({ material })`.
45
+ - Painted cells (`terrain.edit(..., { paint })`) keep their whole-cell color; the image of every chunk touched by an edit is re-uploaded in place.
46
+ - Independent of `resolution`: `resolution` still sets mesh, collision and edit granularity, `colorResolution` only the color detail
47
+ (64 m chunk: 128 = 0.5 m per pixel, 256 = 0.25 m). `recolor` cannot change `colorResolution`.
48
+
49
+ Cost: the worker time per chunk is mostly your `groundType` called once per pixel, several times that of smooth at 128; 64 costs a quarter, 256 four times that.
50
+ Memory is `(colorResolution + 2)^2 x 4` bytes per chunk plus mipmaps (about 90 KB at 128, 23 KB at 64). The first frames pay one shader compile and the uploads, not a cost per frame.
51
+ On a low tier (`engine.tier === 'low'`) the default drops to 64 unless you set `colorResolution`. To skip the
52
+ color map there, choose the shading yourself: `shading: engine.tier === 'low' ? 'smooth' : 'texture'`.
53
+
54
+ `variation` shapes *what* color a point gets; `shading` decides *where* it is evaluated. In vertex modes every variation is limited to cell size; in
55
+ texture mode it is sampled per pixel, so `patches: { size: 20, levels: 4 }` gives hard-edged color blocks, and a `jitter.size` below the pixel size
56
+ (0.5 m at `colorResolution: 128`) comes out as one grain per pixel, coarser than asked.
57
+
58
+ ## Lighting normals: `normals` and `normalFn`
59
+ - `shading: 'smooth'` lights with one normal per grid point, `'flat'` one per triangle. In texture mode choose: `normals: 'smooth'` (default) or
60
+ `'flat'` (faceted light, fine color: a low-poly shape with crisp borders).
61
+ - `normalFn(i, j, h, cell) => [nx, ny, nz]` replaces the smooth normal at grid point `(i, j)`; `h(i, j)` reads a grid-point height, `cell` is the
62
+ spacing in meters. Pure like `height` / `groundType`. The engine normalizes the result. Default: central difference of the four neighbors.
63
+ ```js
64
+ terrain({ normalFn: (i, j, h, cell) => [(h(i - 1, j) - h(i + 1, j)) / cell, 4, (h(i, j - 1) - h(i, j + 1)) / cell] }) // gentler lighting on slopes
65
+ ```
66
+ `normals` and `normalFn` change light only, never height or collision. `engine.terrain.recolor({ normals: 'flat' })` changes it at run time (rebuilds the chunks).
22
67
 
23
68
  ## Symptom, causes, options
24
69
  **Brushed metal at grazing angles.** Cause: `stroke` stretches one axis (`stretch` 6) and `world` projection looks straight down, so a flat
@@ -29,30 +74,22 @@ ground seen at a low angle shows the stretch as long streaks. Options: `noise: '
29
74
  its cell lines (`terrain({ heightmap })` always reads its image bilinearly; `sampleGrid` defaults to `interp: 'linear'`); a coarse mesh
30
75
  `resolution` (16 per 64 m chunk = one height every 4 m); `shading: 'flat'`, which lights each triangle on its own so every facet shows.
31
76
  Options, any of them: more height samples (a larger image or table), or the data smoothed before the terrain reads it; `sampleGrid(...,
32
- { interp: 'cubic' })` for smooth heights everywhere outside the terrain module (placement, gameplay; recipe 37 section 7; a terrain `height`
33
- function runs in a worker and cannot capture a sampler); a finer `resolution` (more triangles, collision and edit cells); `shading: 'smooth'`,
77
+ { interp: 'cubic' })` for smooth heights everywhere outside the terrain module (placement, gameplay; recipe 28 section 9); a finer `resolution` (more triangles, collision and edit cells); `shading: 'smooth'`,
34
78
  or `normals: 'smooth'` with `shading: 'texture'`; `diagonal: 'adaptive'` against zigzag ridges; or noise in the `height` function (`n.fbm`; ridges from
35
79
  folding it) instead of a sparse table. Terraces can also be the picture you want: `interp: 'nearest'`, or a stepped `height`.
36
80
 
37
81
  **Blurry up close.** Cause: the color map is `colorResolution + 2` pixels per 64 m chunk side; 128 is 0.5 m per pixel, which is soft when the
38
- camera is within a few meters. It does not depend on the mesh `resolution`. On a `low` tier the default is 64 (twice as coarse) unless you set
39
- it. Options: `colorResolution: 256` (0.25 m; four times the image memory and worker time); a detail layer on top (it is computed per screen
82
+ camera is within a few meters. It does not depend on the mesh `resolution`. Options: `colorResolution: 256` (four times the image memory and worker time); a detail layer on top (it is computed per screen
40
83
  pixel, so it stays sharp); near grass over the ground; or accept soft color and let a texture carry the fine part.
41
84
 
42
85
  **One flat green.** Cause: not resolution. Color comes from `colors` / `biomeColors` per ground type (`groundType`), `variation.blend`
43
86
  (wavelength and `strength` of the two-color noise) and `steep`. One color with no `biomeColors` and a flat blend is one green. Options: two
44
- colors in `biomeColors` for the type; `blend.strength` 1.5; `variation.patches` with a `tint`; more ground types.
87
+ colors in `biomeColors` for the type; a higher `blend.strength`; `variation.patches` with a `tint`; more ground types.
45
88
 
46
- **Dark blotches.** Cause: usually cloud shadows (`engine.uniforms.uCloudShadow.value` above 0), not texture; they drift with `uCloudSpeed`, and bigger clouds mean
47
- bigger blotches. Test by setting `uCloudShadow` to 0; if they vanish, lower it or change `uCloudScale`. Blotches that
89
+ **Dark blotches.** Cause: usually cloud shadows (`engine.uniforms.uCloudShadow.value` above 0), not texture; they drift with `uCloudShadowSpeed`, and bigger clouds mean
90
+ bigger blotches. Test by setting `uCloudShadow` to 0; if they vanish, lower it or change `uCloudShadowScale`. Blotches that
48
91
  never move are `variation.patches` or a strong `detail`.
49
92
 
50
93
  **Shimmer far away.** Cause: a pattern smaller than a pixel aliases. `detail.fade` (default) fades it out; `fade: false` keeps it. In your own
51
94
  `glsl`, read `threedogDetailFootprint` (one pixel in pattern units; 1 = one cell per pixel) and fade yourself. A `variation.jitter.size` below a
52
95
  pixel shimmers the same way; use a few meters, or `shading: 'texture'` (mipmapped).
53
-
54
- **Near-only vegetation fades out by distance.** Any `nearOnly` species (grass, flowers, pebbles, twigs, snow tufts, debris ...) is placed per chunk ring
55
- (`maxRing`), whose edge would be a visible line. By default instances shrink toward their base over a band that ends at `maxRing x chunk size` from the
56
- player (start at 65% of it), so nothing pops per chunk. Tune with `fade: { start: 20, end: 45 }` (metres), or `fade: false` for a hard edge
57
- (e.g. a species hidden in fog anyway). It is part of the species' own material (no extra draw call or program), keeps wind sway and shadows in step, and is skipped
58
- when `effects: false`. A larger `maxRing`, fog, or a ground color near the species' base color still help for stylized looks with strong silhouettes.
@@ -3,6 +3,7 @@
3
3
  A shared value is something several owners change: the game, a module, an effect. Name it, say who you are, say how you change it:
4
4
 
5
5
  ```js
6
+ engine.time.channel('enemies'); // a channel of your own exists once you name it (world, player and calendar are built in)
6
7
  const slow = engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35, for: 2 }); // bullet time; slow.remove() ends it early
7
8
  engine.mod('time.world', { owner: 'hitstop', set: 0, layer: 'system', for: 0.06 }); // decide on a higher layer: hides everything below
8
9
 
@@ -21,8 +22,8 @@ What to remember:
21
22
  - **Layers combine by themselves.** The game sets a base value, effects (weather, sunset, bullet time) multiply on top, the player's settings cap
22
23
  it. You never pick a layer by hand unless you want to: game code and game modules write `'game'` (the default); effects pass `layer: 'effect'`.
23
24
  - **`mul` / `add` to cooperate, `set` to decide.** Any number of owners can multiply and add. Two owners `set` the same value on the same layer is
24
- an error in development that names both lines and gives three copyable fixes; copy one. Release builds let the later write win and warn once.
25
- - **`replaces` to swap an engine part** that `provides` a slot; a second provider without it is the error `shared-taken`.
25
+ an error (in development and release alike) that names both lines and gives three copyable fixes; copy one. The earlier value stays.
26
+ - **`replaces` to swap an engine part** that `provides` a slot; a second provider without it is the error `shared-taken`. What the old part issued goes with it: read `engine.<slot>` where you use it, and keep the issuer beside any handle so you can compare (`if (from !== engine.rigid) { from = engine.rigid; crate = from.addBox(mesh); }`). Version numbers count per module, so they cannot tell two modules apart. The engine's own props, NPCs, pickups, cars and movers do this; a rider leaves a rigid car when rigid goes. `world` is the exception: it owns every record, so install your world before the modules that need it. Once they are installed, or after `start()`, `replaces: 'world'` and `unuse('world')` are refused (`module-replaces`, `module-unuse`) and nothing changes. A factory that gives two modules goes in whole: `engine.use(terrain(o), { replaces: 'terrain' })` swaps its drawing part too. A module of your own wraps `world.present`, `world.simulate`, `rays.addProvider`, `input.touchButton` and `assets.onSwap` in `ctx.track(...)`, so they leave with it.
26
27
  - Every handle ends with `h.remove()` (`engine.mod`, `ctx.mod`, `input.gate`, `wrap`, `freeze`, `takeCamera`); it drops only your own entry.
27
28
 
28
29
  Only things several parties commonly write are shared values: time speeds and the calendar rate, pause / freeze / camera holders, move stats,
@@ -34,7 +35,7 @@ engine.mod('time.player', { owner: 'haste', mul: 1.2, for: 5 });
34
35
  const menu = engine.freeze('pause-menu'); /* ... */ menu.remove(); // pause menu: the picture, UI and ambient uTime (wind, water, clouds) keep running; { ambient: true } stops those too
35
36
  engine.input.gate('jump', { owner: 'stun', for: 1.5 }); // no jumping while stunned
36
37
  engine.wrap(engine.inventory, 'add', (next, id, n = 1, o) => // a weight rule on top of the engine's inventory
37
- carried() + weightOf(id) * n > 30 ? false : next(id, n, o), { owner: 'weight' });
38
+ carried() + weightOf(id) * n > 30 ? { ok: false, code: 'tooHeavy' } : next(id, n, o), { owner: 'weight' });
38
39
  ```
39
40
 
40
41
  ## The rules in full: `engine.mod(point, { owner, set | add | mul | clamp, layer?, for?, id? })`
@@ -44,8 +45,8 @@ engine.wrap(engine.inventory, 'add', (next, id, n = 1, o) =>
44
45
  | `engine` | the engine's own defaults and drivers |
45
46
  | `game` (default) | game code, game modules |
46
47
  | `effect` | temporary effects: weather, sunset fade, bullet time, haste |
47
- | `settings` | the player's settings menu: only `clamp` / `mul` (a value point: `set: false`), so it can turn things down or off, never on |
48
48
  | `system` | cutscenes, menus, photo tools (also "lock this number": a `set` here hides every layer below) |
49
+ | `settings` | the player's settings menu: only `clamp` / `mul` (a value point: `set: false`), so it can turn things down or off, never on. Above `system`, so the restriction holds in a cutscene too |
49
50
  | `debug` | debug overrides and panels |
50
51
 
51
52
  - Inside a layer: `set`, then every `add`, then every `mul`, then every `clamp` (`{ min, max }`); the result is clamped to the point's own min / max.
@@ -64,16 +65,16 @@ engine.wrap(engine.inventory, 'add', (next, id, n = 1, o) =>
64
65
  - Saved: `engine` to `effect` entries. Not saved: `settings` (the settings module re-applies the player's choices), `system`, `debug`.
65
66
 
66
67
  ## Picture points follow the same rule
67
- `shadows.enabled`, `post.<name>.enabled`, `sky.tint`, `sky.flash` and `ground.cover` are shared points like the rest: the game sets a base value, effects multiply on top, the player's settings cap it.
68
+ `shadows.enabled`, `post.<name>.enabled`, `sky.tint`, `sky.flash` and `ground.cover` are shared points like the rest.
68
69
  `sky.tint`, `ground.cover` (blend by amount) and `sky.flash` (adds) are written with `engine.mod`.
69
70
  ```js
70
- const hold = engine.mod('shadows.enabled', { owner: 'cutscene', layer: 'system', set: false }); // decides over the game and the menu
71
+ const hold = engine.mod('shadows.enabled', { owner: 'cutscene', layer: 'system', set: false }); // decides over the game
71
72
  engine.describe().shared['shadows.enabled']; // who decided and who is hidden
72
73
  hold.remove(); // the handle ends yours
73
74
  ```
74
- - The exact number whatever else is stacked: set on `{ layer: 'system' }`, or write the three.js value.
75
- - The settings menu only restricts (`shadows` off is `shadows.enabled` set false on the settings layer); a game's `enabled: true` does not
76
- switch them back on, and a cutscene's `false` is not undone by the menu.
75
+ - The exact number whatever else is stacked: set on `{ layer: 'system' }` (the player's settings can still lower it), or write the three.js value.
76
+ - The settings menu only restricts (`shadows` off is `shadows.enabled` set false on the settings layer), so neither a game's nor a cutscene's `enabled: true`
77
+ switches them back on, and a cutscene's `false` is not undone by the menu.
77
78
  - A direct three.js write (`engine.lights.hemi.intensity = 0.2`) still works, and describe tags it `three`.
78
79
 
79
80
  ## Time channels
@@ -86,10 +87,8 @@ hold.remove();
86
87
  - One time source: `engine.time.tick` is the only counter; `engine.time.now('real' | 'ambient' | 'calendar' | channel)` are read-only views of it
87
88
  (recipe 06 "The time table"). Passing time is `engine.skip({ seconds })`: every view moves as if stepped, timers fire in order, far NPCs and
88
89
  the calendar catch up. Writing `engine.clock.now` throws (it is a view).
89
- - Timers: `engine.clock.after(s, fnOrEvent, data, { channel })` / `clock.every(s, fn, { channel })` on any view (default `'calendar'`; `'real'`
90
+ - Timers: `engine.clock.after(s, fnOrEvent, { data, channel })` / `clock.every(s, fn, { channel })` on any view (default `'calendar'`; `'real'`
90
91
  ignores bullet time; `'enemies'` slows with it). One queue: `remove()` takes effect at once, even later in the same step.
91
- - `character.velocity` / `character.vy` are not stacks: a write is an impulse the mover integrates from (no owner, nothing to hand back). Lasting
92
- knockback is `character.push(vx, vz, seconds)`; full takeover is `character.mover = 'manual'`.
93
92
 
94
93
  ## Fixed-step order: `onFixed(fn, { phase })`
95
94
 
@@ -102,23 +101,21 @@ checks that need this step's player position). The order never depends on which
102
101
  - Several wrappers compose: the last one wrapped runs first. `handle.remove()` takes one out; the method is restored when the last goes.
103
102
  - Every caller of that method goes through it (the game, the module's own ops, other modules). It wraps one method: a rule for every way items
104
103
  enter the bag wraps `add` and `transfer`.
105
- - Only public methods (the module's `contract.js` `api` list); `_private` names throw. `describe().wraps` lists `{ 'inventory.add': [owners] }`.
104
+ - Meant for public methods (the module's `contract.js` `api` list); a `_private` name warns once in dev and still works. `describe().wraps` lists `{ 'inventory.add': [owners] }`.
106
105
 
107
106
  ## Replacing a module
108
107
 
109
108
  Two modules that each want to be "the" one (a sky, a tone-mapping stage, an inventory) declare an exclusive slot: `provides: ['inventory']`.
110
109
  Other modules `requires: ['inventory']` and work with whichever holds it. `engine.use(myInventory(), { replaces: 'inventory' })` unloads the
111
- holder (its tracked handles, its `ctx.mod` entries, its `dispose`) before the new install, and puts it back if that fails.
110
+ holder (its tracked handles, its `ctx.mod` entries, its `dispose`) before the new install, and puts it back if that fails, with its save data and content sections. Either way the holder is a fresh install, so `module:restored` fires with the fresh modules once their `init` is done: content sections load again, as a `content.load` on a running game would (a newcomer with its own format may refuse a pack written for the old holder: that part stays out, with a warning naming the pack), and what game code defined on the old holder by hand it defines again on that event. Level walls and solid props need no event: they go into whichever `collision` or `collider3d` is installed, also one that came late or came back.
112
111
 
113
- Each replaceable module has a contract (`modules/gameplay/inventory.contract.js`, `interactions.contract.js`, `dialogue.contract.js`, `quests.contract.js`, `modules/flow/contract.js`,
114
- `modules/characters/contract.js`, `modules/calendar/contract.js`, `modules/camera/contract.js`; object contract `modules/characters/vehicle.contract.js`): the api, fields, ops, events
112
+ Most replaceable modules have a contract (`modules/gameplay/*.contract.js`, `modules/*/contract.js`; object contract `modules/characters/vehicle.contract.js`; the rest and what cannot be replaced: CONVENTIONS.md "What can be replaced"): the api, fields, ops, events
115
113
  and save keys other code relies on, and nothing more (the engine's callers use only that surface). `runContract(contract, () => myInventory(), { check })`
116
- from `@threedog/tools/contract` checks a replacement (in a game installed from npm too); `tests/contract/fakeInventory.js` in the engine's
117
- repository (not shipped) is a whole replacement in ~40 lines; `fakeDialogue.js`, `fakeQuests.js`, `fakeCamera.js` and `fakeVehicle.js`
118
- are the same for their contracts, and the engine's NPCs, timeline, content loader, hud and characters run on them (test `tests/specs/ui-nav.mjs`).
114
+ from `@threedog/tools/contract` checks a replacement (in a game installed from npm too); `tests/contract/` in the engine's repository (not shipped) holds small
115
+ whole replacements such as `fakeInventory.js`.
119
116
  A camera module's `prepare` hook: `runContract(contract, () => myCamera(), { check, prepare: e => { e.camera = ... } })` adds what it needs to the
120
117
  small engine. A vehicle is checked as an object: `runContract(vehicleContract, () => myBoat, { check })`.
121
118
 
122
119
  ## Who holds what
123
120
 
124
- `describe().holds`: pause / freeze / camera / debugView, `input` (pushed contexts with owners), `gates`. Every other shared value and slot: `describe().shared`.
121
+ Holders: `describe().holds` (recipe 16, Notes). Every other shared value and slot: `describe().shared`.
@@ -1,7 +1,7 @@
1
1
  # WebGPU and your own TSL materials
2
2
 
3
3
  **In this recipe**: WebGPU or WebGL · Turning it on, fallbacks · A minimal TSL material · The engine's values as nodes · The engine's shader
4
- functions · Patches with a `tsl` field (lighting hooks) · Sky and fog hooks · Post effects as nodes · A consistent style · Mistakes, each with the fix · GLSL to TSL
4
+ functions · Patches with a `tsl` field (lighting hooks) · Sky and fog hooks · Post effects as nodes · A consistent style · Mistakes, each with the fix · Drawn wrong without a thrown error · GLSL to TSL
5
5
 
6
6
  On the WebGPU route a game draws with three.js node materials (`MeshStandardNodeMaterial` ...) and writes shaders in TSL, three's shading
7
7
  language in JavaScript. Learn TSL from three itself: the [TSL guide](https://github.com/mrdoob/three.js/wiki/Three.js-Shading-Language) and
@@ -16,7 +16,7 @@ Rules (correctness, not taste): `import 'threedog/tsl'` comes first in `main.js`
16
16
  `threedog new-game` and `threedog init` start a game on WebGPU with TSL (`main.js` imports `threedog/tsl` first and calls `createEngine({ renderer: 'webgpu' })`). `--webgl` starts it on GLSL instead. `createEngine` called without `renderer` still builds a WebGL renderer. When the browser has no WebGPU the game keeps running on three's WebGL2 backend, and `engine.describe().renderer` says why. How to decide:
17
17
  - WebGPU + TSL (the default for a new game): the picture is built from TSL, you write shaders in JavaScript and compose them as functions, or start from a three.js WebGPU example, and effects that exist only as node materials are open to you.
18
18
  - `--webgl` + GLSL: the game already has GLSL (ShaderMaterials, `onBeforeCompile`, a three.js `Pass`), or must run best on modest hardware where plain WebGL draws a frame fastest, or start-up time matters more than the shading style. Recipe 43 is the GLSL route for the same tasks.
19
- - Check on the hardware you care about: `threedog inspect perf` on both routes, same scene. Measured in 2026-11 on one scene (terrain, 3000 trees, shadows, bloom): on an integrated GPU WebGPU took about 1.5 times as long as WebGL and WebGPURenderer's WebGL2 backend about 1.7 times; the first WebGPU frame came 0.6 to 1.3 s later (shader compilation).
19
+ - Check on the hardware you care about: `threedog inspect perf` on both routes, same scene. On an integrated GPU expect WebGPU to take longer per frame than plain WebGL, the WebGL2 backend longer still, and the first WebGPU frame to come later (shader compilation).
20
20
 
21
21
  ## Turning it on
22
22
  ```js
@@ -50,16 +50,10 @@ engine.add(new THREE.Mesh(new THREE.TorusKnotGeometry(0.6, 0.2, 128, 16), mat));
50
50
  A node material is lit, shadowed and fogged by three like its plain twin; you replace only the inputs you set (`colorNode`, `positionNode`,
51
51
  `normalNode`, `emissiveNode`, `roughnessNode`, `opacityNode` ...).
52
52
 
53
- ## Node names games use
54
- Everything is imported from `three/tsl`; a name you do not find here is almost always there too (`Object.keys(await import('three/tsl'))` lists them, `node_modules/three/src/nodes/` has the source).
55
- - Values: `float`, `vec2`, `vec3`, `vec4`, `color`, `uniform`, `texture`, `attribute`, `varying`.
56
- - Where am I: `positionLocal`, `positionWorld`, `positionGeometry`, `normalLocal`, `normalWorld`, `normalView`, `uv`, `screenUV`, `cameraPosition`, `instanceIndex`, `vertexColor`, `time`.
57
- - Math: `sin`, `cos`, `abs`, `fract`, `floor`, `pow`, `length`, `dot`, `normalize`, `min`, `max`, `clamp`, `mix`, `step`, `smoothstep`, `oneMinus`, `select`; chain the operators as methods (`.add`, `.mul`, `.sub`, `.div`).
58
- - Noise: `mx_noise_float`, `mx_fractal_noise_float` (MaterialX, also `_vec3`).
59
- - Your own function and branches: `Fn`, `If`, `Loop`.
53
+ Node names come from `three/tsl` (`Object.keys(await import('three/tsl'))` lists them, `node_modules/three/src/nodes/` has the source). Noise: `mx_noise_float`, `mx_fractal_noise_float` (MaterialX, also `_vec3`), or `noise` / `hash` below.
60
54
 
61
55
  ## The engine's values as nodes: `uniforms(engine)`
62
- `uniforms(engine)` returns `engine.uniforms` as TSL nodes with the same names: `uTime`, `uWind`, `uCloud`, `uSunDir`, `uSunColor`, `uDaylight`
56
+ `uniforms(engine)` returns `engine.uniforms` as TSL nodes with the same names: `uTime`, `uWind`, `uWeatherCloud`, `uSunDir`, `uSunColor`, `uDaylight`
63
57
  (0 at night, 1 at noon), `uTimeOfDay`, `uFoliageTint`, `uGroundTint` ... (the list: `uniforms` in [the engine API](../api/engine.md)). The node reads the
64
58
  engine's value each render, so weather, the calendar and the sky move your material with no per-frame code.
65
59
  ```js
@@ -84,6 +78,8 @@ in the package's `types/tsl.d.ts`. Call them on nodes, put the result where it b
84
78
  |---|---|---|
85
79
  | `wind(positionGeometry, objectOrigin(), amplitude)` | object-space offset (vec3) | `positionNode = positionLocal.add(...)`: grass, leaves, flags, hanging cloth |
86
80
  | `objectOrigin()` | world origin of the object or instance (vec3) | a per-object phase or random seed |
81
+ | `instanceOffset(offset)` | the offset turned and scaled by the drawn instance (vec3) | `wind` on an `InstancedMesh` with rotated instances |
82
+ | `noise(p)`, `hash(p)` | smooth value noise / a random number, 0-1 | your own patterns; the same ones the engine's clouds use |
87
83
  | `cloudShadow(positionWorld)` | 0-1 light factor under drifting clouds | multiply into the color or the direct light |
88
84
  | `season(color, 0 \| 1)` | the color moved by the calendar's tint (0 foliage, 1 ground) | `colorNode` |
89
85
  | `detailNoise(p, kind, octaves)` / `detailBump(...)` | gray noise + height / a bumped normal | breaking up flat color; `normalNode` |
@@ -204,6 +200,15 @@ emissive lines; a storybook is soft ramp edges (`rampTexture(ramp, soften)`) wit
204
200
  many stray colors has something running after the `lut`; grain and vignette belong before it there.
205
201
  - Put an effect in the stage that matches what it reads. A grade written for finished colors looks wrong before the tone curve, and a glow after it stops glowing.
206
202
 
203
+ ## Dropping a mesh whose material lives on
204
+ A game has nothing to do here. WebGPURenderer keeps a record of every mesh it drew, and neither `scene.remove` nor `geometry.dispose()` frees it while the material stays in use. So every few seconds the engine looks for meshes that have left every Scene and frees theirs, after 4 to 8 seconds out. Adding such a mesh back is fine: its record is rebuilt.
205
+
206
+ Two things stay yours:
207
+ - Call `geometry.dispose()` (or use `engine.remove`) when a mesh is gone for good. Only you know it will not come back. A steady climb of unused geometries warns in dev, with the code `geometry-undisposed`.
208
+ - A pool that sits out for more than a few seconds pays a rebuild on return. Keep such a pool in the scene with `visible = false` and it pays nothing.
209
+
210
+ A record of a mesh in a Scene you no longer draw stays, because a Scene may be drawn again. Send `mesh.dispatchEvent({ type: 'dispose' })` if you throw such a Scene away.
211
+
207
212
  ## Mistakes, each with the fix
208
213
  Each block shows the mistake as a comment and the working line under it.
209
214
  ```js
@@ -281,23 +286,31 @@ Many materials, many programs: WebGPURenderer builds one program per distinct se
281
286
  `detail` / `lighting` options through `applyEffects` share theirs, so a hundred stones build one; a patch you write once and pass
282
287
  to every material shares too, a fresh patch object per material builds one program each.
283
288
 
289
+ ## Drawn wrong without a thrown error
290
+ These come from WebGPURenderer in three.js r187. Nothing throws and the engine's start check does not name them, so the picture is what shows them.
291
+ - `new THREE.Points(geo, new THREE.PointsMaterial({ size: 8 }))` → `const s = new THREE.Sprite(new PointsNodeMaterial({ positionNode: instancedBufferAttribute(attr), size: 8 })); s.count = n; s.frustumCulled = false`: a `Points` object is always 1 px here, and `size` and `sizeNode` work only on the instanced sprite. `engine.particles` already draws this way.
292
+ - `new THREE.LineLoop(geo, mat)` → `new THREE.Line(geo, mat)` with the first point repeated at the end: the renderer skips a `LineLoop` and logs a console error each frame.
293
+ - `new THREE.LineBasicMaterial({ linewidth: 4 })` → `Line2` from `three/addons/lines/webgpu/Line2.js` with `LineGeometry` and `new Line2NodeMaterial({ linewidth: 4 })`: line primitives have no width on WebGPU. The addon's plain `LineMaterial` is a `ShaderMaterial`, so it fails by name.
294
+ - `mesh.customDepthMaterial = m` (or `customDistanceMaterial`) → `material.castShadowPositionNode`, `material.maskShadowNode`, `material.castShadowNode`: only WebGLRenderer reads the old two. The shadow pass already follows a material's `positionNode`.
295
+ - `new THREE.MeshDepthMaterial()` (or `MeshDistanceMaterial`) → a `MeshBasicNodeMaterial` whose `colorNode` reads `depth` from `three/tsl`: neither has a node version, so the mesh draws with an empty `NodeMaterial` after a console error.
296
+ - `map.repeat.set(4, 4)` with `texture(map, myUv)` → `texture(map, myUv).setUpdateMatrix(true)`: a texture node given its own UVs ignores `repeat`, `offset` and `rotation`. `texture(map)` alone follows them.
297
+ - `new THREE.MeshBasicMaterial({ toneMapped: false })` → draw it outside the frame (`engine.ui`): the flag is never read here, so every material gets the frame's tone mapping.
298
+ - `new THREE.MeshStandardMaterial({ dithering: true })` → your own noise in `colorNode`, or a post effect: the flag is never read here, so banding stays.
299
+
284
300
  ## GLSL to TSL
301
+ The language itself is in three's TSL guide. The lines that catch a port:
302
+
285
303
  | GLSL | TSL (`three/tsl`) |
286
304
  |---|---|
287
- | `float x = 1.0;` / `vec3(1.0, 0.5, 0.0)` | `float(1)` / `vec3(1, 0.5, 0)`, `color(0xff8000)` for a hex color |
288
305
  | `a + b`, `a * b`, `-a`, `1.0 - a` | `a.add(b)`, `a.mul(b)`, `a.negate()`, `a.oneMinus()` |
289
306
  | `x += y;` | `x.addAssign(y)` (x made with `.toVar()`) |
290
- | `mix(a, b, t)`, `smoothstep(e0, e1, x)`, `clamp(x, 0.0, 1.0)` | `mix(a, b, t)`, `smoothstep(e0, e1, x)`, `x.clamp(0, 1)` |
291
307
  | `uniform float uAmount;` | `const uAmount = uniform(0.5)`, changed by `uAmount.value = 1` |
292
308
  | the engine's `uTime`, `uWind`, `uDaylight` | `uniforms(engine).uTime` ... (the clock every engine effect reads, not three's own `time`) |
293
309
  | `varying vec3 vPos;` | built in: `positionWorld`, `normalView`...; your own: `node.toVarying()` |
294
- | `vec4 c = texture2D(map, vUv);` | `const c = texture(map, uv())` |
295
310
  | `gl_FragCoord.xy` | `screenCoordinate.xy` (pixels), `screenUV` (0-1) |
296
311
  | `position`, `normal`, `uv` attributes | `positionGeometry`, `normalGeometry`, `const st = uv()` |
297
312
  | moving vertices (`transformed`, `gl_Position`) | `material.positionNode` (object space), `vertexNode` (clip space) |
298
313
  | `gl_FragColor = ...` | `colorNode` (lit surface color), `emissiveNode`, `outputNode` (final color) |
299
314
  | `if (c) {...} else {...}` | `const v = select(c, a, b)`; inside `Fn`, `If` / `Else` blocks |
300
- | `for (int i = 0; i < 4; i++)` | `Loop` with a count and a callback, inside `Fn` |
301
- | `float f(vec3 p) {...}` | `const f = Fn(([p]) => ...)` |
302
315
  | `discard;` | `Discard` inside `Fn`, or `alphaTest` with `opacityNode` |
303
316
  | `#include <threedog_wind>`, `threedogWind(...)` | `import { wind } from 'threedog/tsl'`, `wind(...)` |
@@ -3,14 +3,14 @@
3
3
  Every character (the player, an NPC, a hand-built `Character`) has one control slot. One owner is in charge of it at a time, and only that
4
4
  owner moves the character. Take it, steer, give it back:
5
5
 
6
- ```js
6
+ ```js fragment
7
7
  // a quest walks the guard to the gate; its schedule waits and carries on afterwards
8
8
  const escort = engine.control.take(guard, { owner: 'escort', layer: 'script', step: (dt, ch) => ({ x: 0, z: 1 }) });
9
9
  escort.remove();
10
10
 
11
- // a roll: the keys pause for 0.4 s, then come back by themselves
11
+ // a roll: the keys pause for 0.4 play seconds, then come back
12
12
  const roll = engine.control.take(engine.player, { owner: 'roll', layer: 'script', step: () => ({ x: 0, z: 1, run: true }) });
13
- engine.clock.after(0.4, () => roll.remove());
13
+ engine.clock.after(0.4, () => roll.remove(), { channel: 'real' });
14
14
 
15
15
  // no step: move it from your own code; move() does nothing while someone above holds it
16
16
  const h = engine.control.take(drone, { owner: 'ai', layer: 'script' });
@@ -22,10 +22,10 @@ engine.describe().control; // the same for every held character, by id
22
22
 
23
23
  What to remember:
24
24
  - **Layers, lowest first**: `base` (the character's own driver: the player's keys, an NPC's behaviour) < `script` (walkTo, quest scripts, AI
25
- orders; the default) < `cutscene` (timeline) < `net` (another machine drives it). The highest holder is in charge.
25
+ orders; the default) < `cutscene` (timeline) < `physics` (a ragdoll: nothing can steer a limp body) < `net` (another machine drives it). The highest holder is in charge.
26
26
  - **A higher holder pauses the lower one, it does not cancel it.** When the cutscene ends, the walk it interrupted goes on; when the walk
27
27
  arrives, the keys work again. Nobody has to remember what to restore.
28
- - **One owner per layer.** Two different owners on the same layer is `[control-conflict]` in development, naming both: end the old one first
28
+ - **One owner per layer.** Two different owners on the same layer is `[control-conflict]` in every build, naming both: end the old one first
29
29
  (`h.remove()`), or take another layer. The same owner taking again just replaces its own hold.
30
30
  - **A held character moves only through its holder.** `character.move()` from anywhere else is `[control-bypass]` in development: the bug where
31
31
  keys, a walk and a cutscene all pushed one body in the same step and the last one won.
@@ -41,7 +41,7 @@ What to remember:
41
41
  | `createPlayer({ control })` | base | `'player-input'` | `control` is `'camera'` or `(player, input, dt) => ({ x, z, run })`; jump and driving live here too |
42
42
  | NPC behaviour (schedule, wander, your own) | base | `'npcs'` | paused near and far while anything above holds the NPC; kept by NPC id, so it survives the model being rebuilt |
43
43
  | `character.walkTo(target)` | script | `'walkTo'` | paused under a cutscene (no progress, no stuck clock), resumes after |
44
- | `timeline.play(steps, { actors })` | cutscene | `'timeline'` | `actors` defaults to `[engine.player]`; `[]` drives nobody; a `path` step adds its character. While the player is an actor, the `'cutscene'` input context is up |
44
+ | `timeline.play(steps, { actors })` | cutscene | `'timeline'` | `actors` defaults to `[engine.player]`; `[]` drives nobody; a `path` step adds its character. Resolves `{ ending, error? }`: `'finished'`, `'skipped'`, `'dropped'` (a load, new game or dispose took its state) or `'failed'`; `timeline:end` carries the same. While the player is an actor, the `'cutscene'` input context is up |
45
45
  | `net()` | net | `'net'` | a client holds every character the host drives; the host holds each peer's avatar. Taking one is `[control-net]`: change it with an op the host runs |
46
46
 
47
47
  Two cutscenes running at once are one owner (`'timeline'`), counted per character, so they never conflict; the slot goes back when the last
@@ -64,7 +64,7 @@ Move the player by script in one of three ways. Pick by what the player may stil
64
64
  | A ride on a route: boat, cable car, being carried up stairs | `engine.control.take` with `step: () => false` | steers nothing, gravity is off, your code places it |
65
65
  | Climbing: ladder, rope, wall | `mover: 'manual'` plus the `states` option | moves on the axis you write, the climb clip plays |
66
66
 
67
- ```js
67
+ ```js fragment
68
68
  // a ride: keys and gravity stop while the hold lasts; the seat is a point in the boat's own space
69
69
  const seat = new THREE.Vector3(0, 0.6, 0);
70
70
  const ride = engine.control.take(engine.player, { owner: 'boat', layer: 'script', step: (dt, ch) => {
@@ -74,17 +74,17 @@ const ride = engine.control.take(engine.player, { owner: 'boat', layer: 'script'
74
74
  return false; // placed by hand this step
75
75
  } });
76
76
  ```
77
- To lock the player's input during a scripted ride, one line: `const lock = engine.input.push('ride');` and `lock.remove()` at the end. `engine.characters.support(deckMesh)` works for a boat on water: pass the deck mesh, and the player stands on it and rides it wherever it moves, with no ground needed under it.
77
+ To lock the player's input during a scripted ride, one line: `const lock = engine.input.push('ride');` and `lock.remove()` at the end.
78
78
  Gravity comes back the moment the hold ends, so end a ride where the character can stand: `player.placeAt(pier)` then `ride.remove()`, both in a
79
79
  fixed step or an op. The camera and saves follow the position as usual.
80
80
 
81
- ```js
81
+ ```js fragment
82
82
  // a ladder (the landing point must be ground or a registered platform, engine.characters.support; anywhere else it drops to what is below): createPlayer({ clips: { climb: 'Climb' }, states: () => climbing ? 'climb' : null }), then call this when the player uses the ladder
83
83
  let climbing = false;
84
84
  function climb(player, top) { // top: { x, y, z }, where it steps off, on ground or a registered platform
85
85
  climbing = true; player.mover = 'manual'; // no gravity, the position is yours
86
86
  const h = engine.control.take(player, { owner: 'ladder', layer: 'script', step: (dt, ch) => {
87
- const up = (engine.input.down('moveForward') ? 1 : 0) - (engine.input.down('moveBackward') ? 1 : 0);
87
+ const up = (engine.input.down('moveForward') ? 1 : 0) - (engine.input.down('moveBack') ? 1 : 0);
88
88
  ch.root.position.y += up * 2 * dt;
89
89
  if (ch.root.position.y < top.y) return null; // null: the mover runs, so states picks climb
90
90
  climbing = false; ch.mover = 'simple'; h.remove(); ch.placeAt(top);
@@ -98,7 +98,34 @@ function climb(player, top) { // top: { x, y, z }, where it ste
98
98
  Getting into a vehicle does not change who controls the character: the player's input (`'player-input'`) drives the car while seated. A
99
99
  cutscene that takes the player while driving stops the steering; the rider stays on its seat.
100
100
 
101
+ Holding a car on the grid (a countdown, after the finish) is the same take, plus the brake, since a released pedal only rolls:
102
+ ```js
103
+ const hold = engine.control.take(engine.player, { owner: 'race', layer: 'script', step: () => null }); // the keys stop driving
104
+ engine.onFixed(() => { if (hold.active) car.drive(0, 0, 1); }); // throttle, steer, brake
105
+ hold.remove(); // go
106
+ ```
107
+
101
108
  ## Saves
102
109
 
103
- Holds are not saved: they are running code (a walk, a cutscene, a quest step), and that code takes control again after a load. A walk is
104
- cancelled by a load (`walkTo` resolves `'cancelled'`).
110
+ Holds are not saved: they are running code (a walk, a cutscene, a quest step), and that code takes control again after a load. `walkTo` resolves
111
+ `'cancelled'` on whatever ends the walk: a load or new game, a level change, `placeAt`, a seat, physics taking the body, the character going. To go on, call it again.
112
+
113
+ ## Advanced: your own mover (flight, swimming, wall running)
114
+
115
+ Only for a body the built-in movers cannot move. Most games stop at the sections above.
116
+
117
+ Control decides where to go, the mover decides how to move. A mover is `(character, engine) => ({ name, move(x, z, run, dt, y), dispose? })`; `y` is the up part of the direction (a control step returns `{ x, y, z }`, default 0, and `walkTo` and NPCs pass it towards the path's next point). It writes `character.root.position`.
118
+
119
+ ```js fragment
120
+ const fly = (c, e) => ({ name: 'fly', move(x, z, run, dt, y) {
121
+ const p = c.root.position, v = c.stat('speed') * dt;
122
+ p.x += x * v; p.y += y * v; p.z += z * v;
123
+ c.grounded = false; e.characters.kit.ownState(c, 'fly', v / dt);
124
+ } });
125
+ const held = engine.mod('character.mover', { owner: 'wings', id: 'player', set: fly }); // for a while: held.remove() puts back what was there
126
+ engine.player.mover = fly; // or for good
127
+ ```
128
+
129
+ A mover that keeps something in the physics world gives it a `leave()`: the engine calls it when another mover takes over, and `move` runs again when it is back. `mover: 'rapier'` does this, so an NPC taking off leaves no capsule behind.
130
+
131
+ Contact is opt-in: `engine.characters.kit` has `kit.beginMove`, `kit.groundAt`, `kit.endMove`, `kit.ownState`. Call `kit.beginMove` first and `kit.endMove` last to be carried by platforms and keep `safeGround` and the fall check. A mover that calls neither owns contact. The rule takes the built-in names too, and `false` means `'manual'`; it is not saved, take it again after a load. What a mover must have: `modules/characters/mover.contract.js`.
@@ -47,8 +47,8 @@ Everything a module declares or binds through `ctx.input` leaves with it (rollba
47
47
  ## 4. What the engine tells you
48
48
  - **`input-unbound`** (dev, once per action): a module needs an action nobody bound. The message names the action, its context and the bind line.
49
49
  `engine.input.isUnbound('interact')` asks the same thing: true for no key at all, false for any key, an optional action or `[]` (no key on purpose).
50
- - **`interaction-no-key`** (dev throws, gameplay freezes): interactions were added to an action with no key. Rule R51 finds it in `check`, the smoke test fails on it,
51
- `describe` calls the thing `no key bound` and `interaction.use` is refused with `noKey`.
50
+ - **`interaction-no-key`** (dev warning, once per action): interactions were added to an action with no key. Rule R51 warns in `check`, `describe` calls the thing `no key bound`,
51
+ and `ops` does not offer it, but `interaction.use` still runs when code asks: a click-only or touch-only game is right. `engine.input.bind('interact', [])` says so and ends the warning.
52
52
  - **`input-bound-twice`** (dev throws; release: the later wins): two owners bind one action, e.g. the game's `createEngine({ bindings })` and a
53
53
  module's `ctx.input.bind` for the same action. Keep one. The same owner binding again only replaces its keys.
54
54
  - **`input-action-context`**: two owners declare one action in different contexts. Rename one, or use the same context to share it.
@@ -58,3 +58,16 @@ Everything a module declares or binds through `ctx.input` leaves with it (rollba
58
58
  `engine.input.rebind('attack', ['KeyK'])` is the player's choice, on top of the game's keys; `rebind('attack', null)` gives the game's back.
59
59
  `engine.input.rebound()` lists them (the settings menu saves exactly that and restores it at start, even before the module declaring an action is
60
60
  installed). The settings menu's key page, its reset button and its save all go through these two calls.
61
+
62
+ ## Local players on one screen
63
+
64
+ A seat is one player's own keys and gamepad. It reads like `engine.input` (`axis`, `down`, `pressed`, `released`), so a control function works on either.
65
+
66
+ ```js
67
+ const two = engine.input.seat({ pad: 1, keys: { moveForward: 'KeyI', moveBack: 'KeyK', moveLeft: 'KeyJ', moveRight: 'KeyL', jump: 'KeyU' } });
68
+ const p2 = engine.characters.createPlayer({ id: 'two', input: two, control: 'camera', spawn: [4, 0, 0] });
69
+ ```
70
+
71
+ The seat's pad leaves `engine.input` and answers the game's pad bindings on this seat alone, so `bind('jump', ['PadA'])` works for it as written. A seat's keys are its own list: keep them out of the first player's bindings. Two seats on one pad or key, or one seat on two players, throw `input-seat`.
72
+
73
+ `engine.player` stays the first player; `p2` has its own world record, saved with the world, and `removePlayer('two')` takes it away. There is one screen and one camera. Footstep sounds and NPCs giving way cover every player. A seat with its own `interact` key uses what its player stands by, as that player (`seat.actor`, set by `createPlayer`; `ctx.actor` in the op). The prompt shows `engine.actor`'s choice alone, and one hold runs at a time. A trigger zone hears every player when its `who` names them.
@@ -4,7 +4,7 @@ Fog you march through, light shafts, haze that thickens with distance, edge or f
4
4
  and turn it into a distance or a world position. This recipe writes one such effect with both forms, a three.js `Pass` (GLSL) for
5
5
  WebGLRenderer and a TSL node for WebGPURenderer, in one effect object. How effects are ordered, switched and tuned is recipe 52's
6
6
  [Post effect chain](52-around-the-picture.md#post-effect-chain); the TSL side in general is [recipe 56](56-webgpu-tsl.md#post-effects-as-nodes).
7
- For plain distance or height fog on materials, `engine.scene.fog` is enough (recipe 38); a post effect is for what fog on materials cannot do.
7
+ For plain distance or height fog on materials, `engine.scene.fog` is enough (recipe 34).
8
8
 
9
9
  ## One effect, both renderers
10
10
  `needsDepth: true` gives the WebGL pass the scene depth as `readBuffer.depthTexture`; on WebGPU the same depth is `ctx.scenePass.getTextureNode('depth')`.
@@ -7,7 +7,7 @@ time of day, so every row says what to look for instead.
7
7
 
8
8
  Where the rest lives (one home each, this page only points there):
9
9
  - the calls, their parameters and who writes what: [recipe 52](52-around-the-picture.md) (reading the picture, the post chain, the ownership table);
10
- - the plain three.js way and how the engine yields to it: [THREE.md](../THREE.md) (a direct write takes the value over; the engine stops writing it);
10
+ - the plain three.js way and how the engine yields to it: [THREE.md](../THREE.md);
11
11
  - questions about the whole picture (light roles, readability, consistency) and the numbers each shot prints: [recipe 35](35-picture-from-reference.md) "Picture questions" and "Picture check after every shot";
12
12
  - a whole picture: the game's `picture/` code ([recipe 62](62-picture-code.md), materials and lights in [recipe 09](09-materials-lights-models.md)).
13
13
 
@@ -16,31 +16,36 @@ Change one knob, take a shot (`threedog shot`, or `threedog snap` on a running p
16
16
  times and weathers the game really shows (`threedog shot --time`), not only noon. A knob is right when the difference you wanted is visible
17
17
  and nothing else got worse; when you cannot say what difference a knob should make, leave it at the style's value.
18
18
 
19
+ Whether a picture reads as lit is mostly key against fill. The key (the sun or one main light) casts the shadow; the fill is everything else (sky and ground light, the environment). Shadowed
20
+ surfaces see only the fill while lit ones see both, so the balance sets how deep the shadows look: less fill is harder, more fill softer and more readable, and there is no right ratio, only the one the
21
+ game wants. A warm key over a cool fill (or the reverse) separates lit from shaded sides without more contrast. The shot's `light:` fact measures the ratio; judge it on a shot with a known-colored object in
22
+ shadow. `threedog examples pull sun-and-key-light` shows three routes side by side.
23
+
19
24
  ## The knobs
20
25
 
21
- | Knob | What it changes on screen | It is right when | Engine line (details) | Plain three.js |
22
- |---|---|---|---|---|
23
- | Sky gradient, horizon | the color from the top of the sky down to where it meets the ground | the horizon band and the fog agree where they meet; the top-to-horizon change matches the hour and mood; no visible seam | `engine.sky.top`, `engine.sky.horizon` ([08 §3](08-weather-sky.md#3-changing-sky-colors-sun-stars)); own shader: share `engine.uniforms.uSkyHorizon` / `uSkyTop` ([08](08-weather-sky.md#sky-color-for-my-shader-horizon-color-zenith-color)) | `engine.sky.replace(mySky)` with three/addons `Sky` or a `ShaderMaterial` dome |
24
- | Fog near / far | how fast distant things fade | the play space stays clear, the far edge of the world dissolves instead of ending in a line, landmarks you want seen still read | your `picture/` code ([38 Fog](38-environment-hooks.md#fog-plain-threejs-signals-your-own-math)) | `engine.scene.fog = new THREE.Fog(color, near, far)` |
25
- | Fog color vs sky | whether the distance melts into the sky or into its own haze | distant hills fade toward the sky behind them; a fog color of its own is a choice you can name (smoke, mist, a dream) | your `picture/` code reads `uSkyHorizon` ([38 Fog](38-environment-hooks.md#fog-plain-threejs-signals-your-own-math)) | `engine.scene.fog.color.set(c)` |
26
- | Exposure | overall brightness after lighting | the brightest things you care about keep detail and the darkest still read; a night is dark because the lights are, not because exposure hides it | `engine.renderer.toneMappingExposure = 1.2` ([38 Exposure](38-environment-hooks.md#exposure-and-the-tone-curve)) | `engine.renderer.toneMappingExposure = v` |
27
- | Tone mapping curve | how highlights roll off and how saturated bright colors stay | bright colors keep their hue where the style wants color, highlights soften where it wants film; flat-color styles may want almost no curve | (plain three.js is the route; [52 Who writes it](52-around-the-picture.md#who-writes-it-the-ownership-table)) | `engine.renderer.toneMapping = THREE.AgXToneMapping` (or ACESFilmic, Neutral, No) |
28
- | Sun direction | where shadows fall and which faces are lit | shapes read from the camera (lit side and shaded side both visible), shadows point somewhere useful, the hour looks like the hour | time of day (`engine.calendar`, [06](06-clock-events.md)); sun path: `engine.sky.orbit.tilt`; the lights do not move on their own: aim yours from `engine.uniforms.uSunDir` ([62](62-picture-code.md)) | `engine.lights.sun.position.set(x, y, z)`, or your own `DirectionalLight` |
29
- | Sun color, intensity | the key light: color and strength of lit faces | lit and shaded sides separate; whites under the sun are the white the style wants (warm, neutral, cool) | your `picture/` code writes the light ([62](62-picture-code.md)) | `engine.lights.sun.color.set(c)` |
30
- | Ambient / hemisphere, environment | the fill: how bright and what color the shaded side is | shadows are as deep as the style wants and still show shape; up-facing and down-facing faces differ; metals have something to reflect | your `picture/` code writes the hemisphere light and `scene.environment` ([34](34-environment-lighting.md), [08 brightness](08-weather-sky.md#3-changing-sky-colors-sun-stars)) | `engine.lights.hemi.groundColor.set(c)`, `engine.scene.environmentIntensity = v` |
31
- | Shadow softness | hard or blurred shadow edges | edges match the light (crisp under a clear sun, soft under cloud or for a gentle style); no stair-steps or speckle | `renderer.shadowMap.type`, `light.shadow.radius` ([52 Atmosphere](52-around-the-picture.md#atmosphere-fog-sky), [45](45-cascaded-shadows.md)) | `engine.lights.sun.shadow.radius = r` |
32
- | Shadow distance, detail | how far shadows reach and how sharp small ones are | the area the player looks at has shadows; small props keep theirs; objects touch the ground (no gap under a foot) | `engine.shadows.box(sun, { extent })`, `engine.shadows.cascades(sun, { count, maxFar })`, `sun.shadow.bias` ([45](45-cascaded-shadows.md)) | `engine.lights.sun.shadow.camera` sides, `engine.lights.sun.shadow.mapSize` |
33
- | Bloom | light bleeding around bright pixels | the bright things you meant (sun, lamps, magic) glow and nothing else does; the picture does not turn milky | `engine.post.add(bloom())` from `@threedog/post-effects`, then `engine.post.get('bloom').set({ strength })` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) | `engine.post.add(new UnrealBloomPass(size, strength, radius, threshold))` |
34
- | Light glow / halo | lamps, windows, signs that read as lit | a glowing object keeps its hue at the center (it is not a white block), has a halo where bloom is on, and lights its surroundings if it should | `engine.uniforms.uNight` ([09 §1b](09-materials-lights-models.md#night-glow-emissive-that-follows-daylight)); many lamps: `lightPool` ([09 §1b](09-materials-lights-models.md#1b-lights-and-stalls)) | `material.emissive` / `material.emissiveIntensity`, an additive `THREE.Sprite` for a halo |
35
- | Water, sea | color with depth, waves, foam, what it reflects | shallow and deep read differently, the far sea meets the sky without a seam, foam sits where waves break | `engine.water.shader({ depthColor, foam })`, `engine.water.uniforms.uWave` ([44](44-water-weather-hooks.md)) | three/addons `Water`, or a `ShaderMaterial` that reads `engine.uniforms.uSkyHorizon` ([44 own material](44-water-weather-hooks.md#water-your-own-material-reflections-refraction)) |
36
- | Wet ground | streets and stone after rain | wet is darker and glossier together, gloss shows reflections of something bright, puddles have soft edges | no engine picture: read `engine.uniforms.uRain`, then write `material.color`, `material.roughness` ([08 §7](08-weather-sky.md#7-wet-roads-and-puddles-after-rain)) | `material.roughness`, `material.color` on your ground material |
37
- | Color grading | contrast, saturation and warm / cool shift of the whole frame | the frame has the mood you named; skin, foliage and the player's colors still read | `engine.post.add(lut())` from `@threedog/post-effects` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) | `engine.post.add(new LUTPass({ lut }))` |
38
- | Cloud shadow | moving dark patches on the ground | the patches drift slowly enough to read as clouds, are as dark as the sky is cloudy, and do not hide gameplay | `engine.uniforms.uCloudShadow`, `uCloudScale`, `uCloudSpeed`; clouds in the sky: `engine.uniforms.uCloudCover`, `uSkyCloudScale`, `uSkyCloudSpeed` ([08](08-weather-sky.md)) | your own patch: `engine.terms.cloudShadow(spec)` ([52](52-around-the-picture.md)) |
39
- | Grain, vignette | film noise; darker frame corners | you notice the mood, not the effect; text and the HUD stay clean | `engine.post.add(grain())`, `engine.post.add(vignette())` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) | a pixel snippet: `engine.post.add({ name, fuse: { glsl }, slot: 'ldr' })` |
40
- | Ambient occlusion | darker creases and contact corners | objects sit on the ground and corners have weight; no dark halo around thin things | `engine.post.add(ao())` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) | three/addons `GTAOPass` through `engine.post.add(pass)` |
41
- | Outline | lines around shapes | lines help read shapes at play distance and match the style's line weight | `engine.post.add(outline())` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) | three/addons `OutlinePass` through `engine.post.add(pass)` |
42
- | Surface shading | how light falls across a surface (smooth, banded, flat) | materials that should differ (wood, stone, metal, cloth) differ in response, not only in color | `applyEffects(mat, { lighting })`, `rampTexture` ([43](43-shader-patches-surfaces.md), [09](09-materials-lights-models.md)) | `new THREE.MeshToonMaterial({ gradientMap })` or any material of yours |
43
- | God rays, volumetric fog | light shafts, fog thick in the air | shafts come from where the light is and fade when it leaves the screen | your own depth effect ([59](59-depth-post-effects.md)) | a Pass of yours through `engine.post.add(pass)` |
26
+ | Knob | What it changes on screen | It is right when | How (details) |
27
+ |---|---|---|---|
28
+ | Sky gradient, horizon | the color from the top of the sky down to where it meets the ground | the horizon band and the fog agree where they meet; the top-to-horizon change matches the hour and mood; no visible seam | `engine.sky.top`, `engine.sky.horizon` ([08 §3](08-weather-sky.md#3-changing-sky-colors-sun-stars)); own shader: share `engine.uniforms.uSkyHorizon` / `uSkyTop` ([08](08-weather-sky.md#sky-color-for-my-shader-horizon-color-zenith-color)); own sky: `engine.sky.replace(mySky)` |
29
+ | Fog near / far | how fast distant things fade | the play space stays clear, the far edge of the world dissolves instead of ending in a line, landmarks you want seen still read | `engine.scene.fog = new THREE.Fog(color, near, far)` ([34 Fog](34-environment-lighting.md#fog-plain-threejs-signals-your-own-math)) |
30
+ | Fog color vs sky | whether the distance melts into the sky or into its own haze | distant hills fade toward the sky behind them; a fog color of its own is a choice you can name (smoke, mist, a dream) | `scene.fog.color`, your `picture/` code reads `uSkyHorizon` ([34 Fog](34-environment-lighting.md#fog-plain-threejs-signals-your-own-math)) |
31
+ | Exposure | overall brightness after lighting | the brightest things you care about keep detail and the darkest still read; a night is dark because the lights are, not because exposure hides it | `engine.renderer.toneMappingExposure` ([34 Exposure](34-environment-lighting.md#exposure-and-the-tone-curve)) |
32
+ | Tone mapping curve | how highlights roll off and how saturated bright colors stay | bright colors keep their hue where the style wants color, highlights soften where it wants film; flat-color styles may want almost no curve | `engine.renderer.toneMapping = THREE.AgXToneMapping` (or ACESFilmic, Neutral, No) ([52 Who writes it](52-around-the-picture.md#who-writes-it-the-ownership-table)) |
33
+ | Sun direction | where shadows fall and which faces are lit | shapes read from the camera (lit side and shaded side both visible), shadows point somewhere useful, the hour looks like the hour | time of day (`engine.calendar`, [06](06-clock-events.md)); sun path: `engine.sky.orbit.tilt`; the lights do not move on their own: aim yours from `engine.uniforms.uSunDir` ([62](62-picture-code.md)) |
34
+ | Sun color, intensity | the key light: color and strength of lit faces | lit and shaded sides separate; whites under the sun are the white the style wants (warm, neutral, cool) | your `picture/` code writes the light ([62](62-picture-code.md)) |
35
+ | Ambient / hemisphere, environment | the fill: how bright and what color the shaded side is | shadows are as deep as the style wants and still show shape; up-facing and down-facing faces differ; metals have something to reflect | your `picture/` code writes the hemisphere light and `scene.environment`, `scene.environmentIntensity` ([34](34-environment-lighting.md), [08 brightness](08-weather-sky.md#3-changing-sky-colors-sun-stars)) |
36
+ | Shadow softness | hard or blurred shadow edges | edges match the light (crisp under a clear sun, soft under cloud or for a gentle style); no stair-steps or speckle | `renderer.shadowMap.type`, `light.shadow.radius` ([45](45-cascaded-shadows.md)) |
37
+ | Shadow distance, detail | how far shadows reach and how sharp small ones are | the area the player looks at has shadows; small props keep theirs; objects touch the ground (no gap under a foot) | `engine.shadows.box(sun, { extent })`, `engine.shadows.cascades(sun, { count, maxFar })`, `light.shadow.bias`, `mapSize` ([45](45-cascaded-shadows.md)) |
38
+ | Bloom | light bleeding around bright pixels | the bright things you meant (sun, lamps, magic) glow and nothing else does; the picture does not turn milky | `engine.post.add(bloom())` from `@threedog/post-effects`, or three's `UnrealBloomPass` through `engine.post.add(pass)` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
39
+ | Light glow / halo | lamps, windows, signs that read as lit | a glowing object keeps its hue at the center (it is not a white block), has a halo where bloom is on, and lights its surroundings if it should | `material.emissive`, `engine.uniforms.uNight` ([09 §1b](09-materials-lights-models.md#night-glow-emissive-that-follows-daylight)); many lamps: `lightPool` ([09 §1b](09-materials-lights-models.md#1b-lights-and-stalls)) |
40
+ | Water, sea | color with depth, waves, foam, what it reflects | shallow and deep read differently, the far sea meets the sky without a seam, foam sits where waves break | `engine.water.shader({ depthColor, foam })`, `engine.water.uniforms.uWave` ([44](44-water-weather-hooks.md)); own: three/addons `Water`, a `ShaderMaterial` ([44 own material](44-water-weather-hooks.md#water-your-own-material-reflections-refraction)) |
41
+ | Wet ground | streets and stone after rain | wet is darker and glossier together, gloss shows reflections of something bright, puddles have soft edges | no engine picture: read `engine.uniforms.uRain`, then write `material.color`, `material.roughness` ([08 §7](08-weather-sky.md#7-wet-roads-and-puddles-after-rain)) |
42
+ | Color grading | contrast, saturation and warm / cool shift of the whole frame | the frame has the mood you named; skin, foliage and the player's colors still read | `engine.post.add(lut())` from `@threedog/post-effects`, or `new LUTPass({ lut })` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
43
+ | Cloud shadow | moving dark patches on the ground | the patches drift slowly enough to read as clouds, are as dark as the sky is cloudy, and do not hide gameplay | `engine.uniforms.uCloudShadow`, `uCloudShadowScale`, `uCloudShadowSpeed`; clouds in the sky: `uCloudCover`, `uSkyCloudScale`, `uSkyCloudSpeed` on the dome ([08](08-weather-sky.md)); your own: `engine.shaderTerms.cloudShadow(spec)` ([52](52-around-the-picture.md)) |
44
+ | Grain, vignette | film noise; darker frame corners | you notice the mood, not the effect; text and the HUD stay clean | `engine.post.add(grain())`, `engine.post.add(vignette())`; a pixel snippet: `engine.post.add({ name, fuse: { glsl }, slot: 'ldr' })` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
45
+ | Ambient occlusion | darker creases and contact corners | objects sit on the ground and corners have weight; no dark halo around thin things | `engine.post.add(ao())` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
46
+ | Outline | lines around shapes | lines help read shapes at play distance and match the style's line weight | `engine.post.add(outline())` ([52 Post chain](52-around-the-picture.md#post-effect-chain)), or three/addons `OutlinePass` |
47
+ | Surface shading | how light falls across a surface (smooth, banded, flat) | materials that should differ (wood, stone, metal, cloth) differ in response, not only in color | `new THREE.MeshToonMaterial({ gradientMap })` or any material of yours; `applyEffects(mat, { lighting })`, `rampTexture` ([43](43-shader-patches-surfaces.md), [09](09-materials-lights-models.md)) |
48
+ | God rays, volumetric fog | light shafts, fog thick in the air | shafts come from where the light is and fade when it leaves the screen | your own depth effect ([59](59-depth-post-effects.md)) |
44
49
 
45
50
  ## When the picture check names a feature
46
51
  The check printed after every shot states a fact and, where the engine has a feature for it, one line of usage. Each is a way out, not a request: a
@@ -51,7 +56,7 @@ hard-edged or pitch-dark look may want exactly what was measured. All of them re
51
56
  | one shadow texel covers X m | the size on the ground of one shadow map pixel, when shadows do not show | cascades: `engine.shadows.cascades(engine.lights.sun, { count })` for the engine sun, `engine.shadows.cascades(light, { count: 3 })` on your own light ([recipe 45](45-cascaded-shadows.md)) |
52
57
  | over budget | lit point and spot lights, shadow maps, the largest map size, against `engine.budget` | many lights: `engine.lightPool` ([recipe 09](09-materials-lights-models.md)); shadows: `castShadow`, `light.shadow.mapSize` picked from `engine.tier` |
53
58
  | shadows nearly black | how much the fill adds on the shadowed pixels themselves | `engine.bakeProbes` ([recipe 34](34-environment-lighting.md)) or a fill light |
54
- | shadow stripes, stepped edges | the shadow alone, at canvas pixels: thin bands, or stairs along an edge | the bias, map size and shadow range it lists; stairs also the cascades above |
59
+ | shadow stripes, stepped edges | the shadow alone, at canvas pixels: several thin bands side by side, or edges that move when only the shadow map's pixel grid moves | the bias, map size and shadow range it lists; stairs also the cascades above |
55
60
  | fog covers X% | how much of the picture is fog color; printed before a line about the night, since the fog comes first | `scene.fog` |
56
61
 
57
62
  Limits a game sets per device go through the same check: `engine.budget.enable(engine.tier === 'low' ? { lights: 4 } : { lights: 12 })`. A limit you wrote is