threedog 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (511) hide show
  1. package/CHANGELOG.md +81 -1
  2. package/README.md +21 -13
  3. package/core/Assets.js +23 -12
  4. package/core/Audio.js +1 -1
  5. package/core/Baked.js +14 -23
  6. package/core/Budget.js +2 -2
  7. package/core/DebugOverrides.js +33 -18
  8. package/core/Describe.js +10 -11
  9. package/core/Engine.js +50 -46
  10. package/core/I18n.js +2 -2
  11. package/core/Input.js +11 -5
  12. package/core/Inspect.js +6 -3
  13. package/core/InspectMaterials.js +2 -3
  14. package/core/InspectPerf.js +11 -4
  15. package/core/MaterialInfo.js +7 -5
  16. package/core/Rays.js +7 -2
  17. package/core/Stream.js +2 -3
  18. package/core/UrlState.js +49 -9
  19. package/core/Views.js +1 -0
  20. package/core/adaptive.js +2 -2
  21. package/core/assetEntry.js +5 -2
  22. package/core/assetLoad.js +13 -15
  23. package/core/assetManifest.js +6 -3
  24. package/core/assetReport.js +4 -4
  25. package/core/batchGroups.js +9 -1
  26. package/core/catalog.js +16 -3
  27. package/core/chunkStream.js +1 -1
  28. package/core/copies.js +1 -1
  29. package/core/debugView.js +4 -4
  30. package/core/describeRender.js +104 -28
  31. package/core/describeText.js +6 -6
  32. package/core/errorCodes.js +72 -45
  33. package/core/errorHints.js +4 -1
  34. package/core/errors.js +4 -4
  35. package/core/events.generated.js +1 -0
  36. package/core/gameLights.js +9 -2
  37. package/core/lifecycle.js +2 -4
  38. package/core/lightWatch.js +5 -3
  39. package/core/loop.js +18 -11
  40. package/core/math.js +7 -0
  41. package/core/moduleSlots.js +32 -7
  42. package/core/moduleTypes.js +20 -7
  43. package/core/modules.js +7 -7
  44. package/core/namedModel.js +8 -4
  45. package/core/owned.js +33 -30
  46. package/core/page.js +43 -10
  47. package/core/pictureSlots.js +33 -0
  48. package/core/pictureWriters.js +343 -0
  49. package/core/plugins.js +64 -96
  50. package/core/sceneDelta.js +12 -4
  51. package/core/sceneMethods.js +2 -9
  52. package/core/services.js +1 -1
  53. package/core/shadowTypes.js +1 -1
  54. package/core/shadows.js +405 -0
  55. package/core/sharedPoint.js +5 -19
  56. package/core/stackFrames.js +16 -5
  57. package/core/stacks.js +6 -6
  58. package/core/startup.js +9 -11
  59. package/core/thingExplain.js +1 -1
  60. package/core/things.js +1 -1
  61. package/core/tier.js +1 -1
  62. package/core/util.js +1 -1
  63. package/core/validate.js +1 -1
  64. package/core/view.js +43 -0
  65. package/docs/AI.md +62 -58
  66. package/docs/API.md +15 -15
  67. package/docs/CODEMAP.md +36 -54
  68. package/docs/COMMANDS.md +28 -25
  69. package/docs/CONVENTIONS.md +36 -30
  70. package/docs/MIGRATING-0.4.md +93 -1
  71. package/docs/MIGRATING-0.6.md +126 -0
  72. package/docs/MIGRATING-0.7.md +39 -0
  73. package/docs/THREE.md +24 -22
  74. package/docs/api/assets.md +5 -3
  75. package/docs/api/audio.md +2 -2
  76. package/docs/api/budget.md +4 -0
  77. package/docs/api/characters.md +3 -1
  78. package/docs/api/collision.md +2 -2
  79. package/docs/api/engine.md +47 -20
  80. package/docs/api/events.md +2 -1
  81. package/docs/api/grids.md +8 -1
  82. package/docs/api/ground.md +1 -1
  83. package/docs/api/hud.md +3 -0
  84. package/docs/api/input.md +3 -2
  85. package/docs/api/interactions.md +3 -1
  86. package/docs/api/inventory.md +1 -2
  87. package/docs/api/level.md +0 -1
  88. package/docs/api/lightPool.md +1 -1
  89. package/docs/api/occlusion.md +5 -0
  90. package/docs/api/particles.md +6 -3
  91. package/docs/api/pickups.md +6 -0
  92. package/docs/api/post.md +5 -3
  93. package/docs/api/sky.md +12 -10
  94. package/docs/api/terrain.md +12 -6
  95. package/docs/api/terrainDraw.md +12 -0
  96. package/docs/api/tools.md +8 -7
  97. package/docs/api/triggers.md +2 -0
  98. package/docs/api/vegetation.md +7 -2
  99. package/docs/api/vegetationDraw.md +10 -0
  100. package/docs/api/water.md +6 -2
  101. package/docs/api/weather.md +5 -0
  102. package/docs/api/weatherDraw.md +10 -0
  103. package/docs/api/world.md +1 -1
  104. package/docs/recipes/01-new-game.md +19 -23
  105. package/docs/recipes/03-items-pickups.md +25 -4
  106. package/docs/recipes/05-props-bake.md +53 -37
  107. package/docs/recipes/06-clock-events.md +3 -3
  108. package/docs/recipes/07-flow-scenes-pause.md +12 -3
  109. package/docs/recipes/08-weather-sky.md +45 -57
  110. package/docs/recipes/09-materials-lights-models.md +185 -0
  111. package/docs/recipes/10-blender-level.md +2 -2
  112. package/docs/recipes/11-vehicles.md +3 -3
  113. package/docs/recipes/13-animation.md +13 -7
  114. package/docs/recipes/14-custom-module.md +7 -5
  115. package/docs/recipes/15-perf.md +3 -3
  116. package/docs/recipes/16-dev-bridge.md +22 -12
  117. package/docs/recipes/18-world.md +10 -8
  118. package/docs/recipes/19-shooting-picking.md +7 -5
  119. package/docs/recipes/20-content-actions-save.md +6 -2
  120. package/docs/recipes/21-camera.md +8 -3
  121. package/docs/recipes/23-ops.md +1 -1
  122. package/docs/recipes/26-ui-parts.md +35 -11
  123. package/docs/recipes/28-terrain.md +12 -12
  124. package/docs/recipes/29-grid.md +14 -5
  125. package/docs/recipes/30-templates.md +8 -3
  126. package/docs/recipes/31-audio.md +4 -4
  127. package/docs/recipes/32-action-game.md +18 -4
  128. package/docs/recipes/34-environment-lighting.md +102 -38
  129. package/docs/recipes/35-picture-from-reference.md +147 -0
  130. package/docs/recipes/36-sky-ground-plants.md +158 -0
  131. package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -13
  132. package/docs/recipes/38-environment-hooks.md +67 -0
  133. package/docs/recipes/40-scene.md +106 -27
  134. package/docs/recipes/42-terrain-shape.md +1 -1
  135. package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
  136. package/docs/recipes/44-water-weather-hooks.md +191 -0
  137. package/docs/recipes/45-cascaded-shadows.md +121 -23
  138. package/docs/recipes/46-blender-art-route.md +17 -20
  139. package/docs/recipes/47-island-snow-backdrop.md +10 -12
  140. package/docs/recipes/49-game-module-contract.md +1 -1
  141. package/docs/recipes/50-own-renderer.md +3 -3
  142. package/docs/recipes/52-around-the-picture.md +181 -0
  143. package/docs/recipes/53-ground-up-close.md +12 -12
  144. package/docs/recipes/54-three-idioms.md +18 -18
  145. package/docs/recipes/55-mods-time-wrap.md +17 -5
  146. package/docs/recipes/56-webgpu-tsl.md +66 -23
  147. package/docs/recipes/57-control.md +39 -0
  148. package/docs/recipes/58-input.md +3 -0
  149. package/docs/recipes/59-depth-post-effects.md +5 -5
  150. package/docs/recipes/60-judge-the-picture.md +39 -24
  151. package/docs/recipes/61-deploy.md +27 -0
  152. package/docs/recipes/62-picture-code.md +244 -0
  153. package/docs/recipes/63-third-person-start.md +77 -0
  154. package/docs/recipes/64-particles.md +35 -0
  155. package/examples/action/.threedog/content-index.json +1 -1
  156. package/examples/action/GAMEMAP.md +7 -5
  157. package/examples/action/main.js +5 -4
  158. package/examples/action/models.js +12 -14
  159. package/examples/action/picture/index.js +13 -0
  160. package/examples/action/picture/lights.js +35 -0
  161. package/examples/action/picture/materials.js +8 -0
  162. package/examples/action/picture/palette.js +33 -0
  163. package/examples/plain-picture/.threedog/content-index.json +1 -0
  164. package/examples/plain-picture/FINDINGS.md +53 -0
  165. package/examples/plain-picture/GAMEMAP.md +90 -0
  166. package/examples/plain-picture/main.js +48 -0
  167. package/examples/plain-picture/picture/index.js +21 -0
  168. package/examples/plain-picture/picture/lights.js +54 -0
  169. package/examples/plain-picture/picture/materials.js +24 -0
  170. package/examples/plain-picture/picture/palette.js +16 -0
  171. package/examples/plain-picture/picture/sky.js +37 -0
  172. package/examples/pullable.json +31 -9
  173. package/examples/rc2d/GAMEMAP.md +8 -3
  174. package/examples/rc2d/README.md +11 -6
  175. package/examples/rc2d/main.js +25 -33
  176. package/examples/rc2d/picture/index.js +18 -0
  177. package/examples/rc2d/picture/lights.js +11 -0
  178. package/examples/rc2d/picture/materials.js +18 -0
  179. package/examples/rc2d/picture/palette.js +15 -0
  180. package/examples/rc2d/picture/post.js +11 -0
  181. package/examples/rc2d/rc2d.js +18 -28
  182. package/examples/sheepisland/.threedog/content-index.json +1 -1
  183. package/examples/sheepisland/GAMEMAP.md +13 -10
  184. package/examples/sheepisland/assets.js +2 -2
  185. package/examples/sheepisland/content/templates.js +1 -1
  186. package/examples/sheepisland/content/vegetation.js +3 -1
  187. package/examples/sheepisland/main.js +15 -9
  188. package/examples/sheepisland/{style/models.js → models.js} +13 -24
  189. package/examples/sheepisland/picture/index.js +20 -0
  190. package/examples/sheepisland/picture/lights.js +34 -0
  191. package/examples/sheepisland/picture/materials.js +61 -0
  192. package/examples/sheepisland/picture/palette.js +60 -0
  193. package/examples/sheepisland/picture/sky.js +20 -0
  194. package/examples/sheepisland/views.js +1 -1
  195. package/examples/styletest/.threedog/content-index.json +1 -1
  196. package/examples/styletest/GAMEMAP.md +15 -11
  197. package/examples/styletest/main.js +20 -30
  198. package/examples/styletest/models.js +29 -29
  199. package/examples/styletest/params.js +1 -4
  200. package/examples/styletest/picture/env.js +38 -0
  201. package/examples/styletest/picture/index.js +16 -0
  202. package/examples/styletest/picture/lights.js +9 -0
  203. package/examples/styletest/picture/materials.js +28 -0
  204. package/examples/styletest/picture/palette.js +22 -0
  205. package/examples/techniques/contact-shadows/README.md +22 -23
  206. package/examples/techniques/contact-shadows/contactShadows.js +32 -16
  207. package/examples/techniques/contact-shadows/main.js +20 -18
  208. package/examples/techniques/contact-shadows/picture/index.js +14 -0
  209. package/examples/techniques/contact-shadows/picture/lights.js +34 -0
  210. package/examples/techniques/contact-shadows/picture/materials.js +12 -0
  211. package/examples/techniques/contact-shadows/picture/palette.js +17 -0
  212. package/examples/techniques/day-night-grade/README.md +13 -16
  213. package/examples/techniques/day-night-grade/main.js +15 -25
  214. package/examples/techniques/day-night-grade/picture/index.js +20 -0
  215. package/examples/techniques/day-night-grade/picture/lights.js +45 -0
  216. package/examples/techniques/day-night-grade/picture/materials.js +15 -0
  217. package/examples/techniques/day-night-grade/picture/palette.js +59 -0
  218. package/examples/techniques/day-night-grade/picture/post.js +25 -0
  219. package/examples/techniques/day-night-grade/picture/sky.js +33 -0
  220. package/examples/techniques/interior-light/README.md +16 -13
  221. package/examples/techniques/interior-light/interiorLight.js +19 -17
  222. package/examples/techniques/interior-light/main.js +30 -67
  223. package/examples/techniques/interior-light/picture/index.js +24 -0
  224. package/examples/techniques/interior-light/picture/lights.js +52 -0
  225. package/examples/techniques/interior-light/picture/materials.js +13 -0
  226. package/examples/techniques/interior-light/picture/palette.js +32 -0
  227. package/examples/techniques/interior-light/picture/sky.js +40 -0
  228. package/examples/techniques/modular-building/README.md +4 -3
  229. package/examples/techniques/modular-building/kit.js +2 -2
  230. package/examples/techniques/modular-building/main.js +9 -17
  231. package/examples/techniques/modular-building/picture/index.js +17 -0
  232. package/examples/techniques/modular-building/picture/lights.js +26 -0
  233. package/examples/techniques/modular-building/picture/materials.js +13 -0
  234. package/examples/techniques/modular-building/picture/palette.js +23 -0
  235. package/examples/techniques/night-lights/README.md +15 -14
  236. package/examples/techniques/night-lights/main.js +20 -43
  237. package/examples/techniques/night-lights/nightLights.js +25 -21
  238. package/examples/techniques/night-lights/picture/index.js +18 -0
  239. package/examples/techniques/night-lights/picture/lights.js +44 -0
  240. package/examples/techniques/night-lights/picture/materials.js +15 -0
  241. package/examples/techniques/night-lights/picture/palette.js +34 -0
  242. package/examples/techniques/night-lights/picture/post.js +9 -0
  243. package/examples/techniques/night-lights/picture/sky.js +36 -0
  244. package/examples/techniques/outlines-and-rim/README.md +2 -2
  245. package/examples/techniques/outlines-and-rim/main.js +15 -38
  246. package/examples/techniques/outlines-and-rim/outlines.js +3 -3
  247. package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
  248. package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
  249. package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
  250. package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
  251. package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
  252. package/examples/techniques/procedural-animation/README.md +5 -3
  253. package/examples/techniques/procedural-animation/main.js +9 -7
  254. package/examples/techniques/procedural-animation/picture/index.js +15 -0
  255. package/examples/techniques/procedural-animation/picture/lights.js +35 -0
  256. package/examples/techniques/procedural-animation/picture/materials.js +10 -0
  257. package/examples/techniques/procedural-animation/picture/palette.js +16 -0
  258. package/examples/techniques/procedural-animation/picture/sky.js +31 -0
  259. package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
  260. package/examples/techniques/procedural-surface/README.md +2 -0
  261. package/examples/techniques/procedural-surface/main.js +17 -55
  262. package/examples/techniques/procedural-surface/picture/index.js +14 -0
  263. package/examples/techniques/procedural-surface/picture/lights.js +18 -0
  264. package/examples/techniques/procedural-surface/picture/materials.js +34 -0
  265. package/examples/techniques/procedural-surface/picture/palette.js +15 -0
  266. package/examples/techniques/stylized-shading/README.md +13 -14
  267. package/examples/techniques/stylized-shading/main.js +11 -42
  268. package/examples/techniques/stylized-shading/picture/index.js +14 -0
  269. package/examples/techniques/stylized-shading/picture/lights.js +23 -0
  270. package/examples/techniques/stylized-shading/picture/materials.js +18 -0
  271. package/examples/techniques/stylized-shading/picture/palette.js +19 -0
  272. package/examples/techniques/stylized-shading/shading.js +2 -2
  273. package/examples/techniques/sun-and-key-light/README.md +20 -22
  274. package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
  275. package/examples/techniques/sun-and-key-light/main.js +19 -63
  276. package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
  277. package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
  278. package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
  279. package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
  280. package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
  281. package/examples/techniques/three-looks/README.md +21 -0
  282. package/examples/techniques/three-looks/main.js +58 -0
  283. package/examples/techniques/three-looks/picture/cartoon.js +23 -0
  284. package/examples/techniques/three-looks/picture/cinematic.js +27 -0
  285. package/examples/techniques/three-looks/picture/comic.js +27 -0
  286. package/examples/techniques/three-looks/picture/index.js +14 -0
  287. package/examples/techniques/three-looks/picture/sun.js +23 -0
  288. package/examples/techniques/wet-road/README.md +7 -4
  289. package/examples/techniques/wet-road/main.js +18 -38
  290. package/examples/techniques/wet-road/picture/index.js +17 -0
  291. package/examples/techniques/wet-road/picture/lights.js +57 -0
  292. package/examples/techniques/wet-road/picture/materials.js +16 -0
  293. package/examples/techniques/wet-road/picture/palette.js +24 -0
  294. package/examples/techniques/wet-road/picture/sky.js +46 -0
  295. package/examples/webgpu-tsl/GAMEMAP.md +9 -4
  296. package/examples/webgpu-tsl/README.md +13 -10
  297. package/examples/webgpu-tsl/main.js +30 -7
  298. package/examples/webgpu-tsl/picture/index.js +18 -0
  299. package/examples/webgpu-tsl/picture/lights.js +25 -0
  300. package/examples/webgpu-tsl/picture/materials.js +36 -0
  301. package/examples/webgpu-tsl/picture/palette.js +23 -0
  302. package/examples/webgpu-tsl/picture/post.js +16 -0
  303. package/examples/webgpu-tsl/picture/sky.js +30 -0
  304. package/examples/world/.threedog/content-index.json +1 -1
  305. package/examples/world/GAMEMAP.md +15 -12
  306. package/examples/world/art/humanoid.js +9 -13
  307. package/examples/world/art/index.js +2 -2
  308. package/examples/world/art/models.js +3 -4
  309. package/examples/world/art/shapes.js +2 -2
  310. package/examples/world/assets.js +2 -2
  311. package/examples/world/content/audio.js +1 -1
  312. package/examples/world/content/items.js +1 -1
  313. package/examples/world/content/props.js +1 -1
  314. package/examples/world/content/templates.js +1 -1
  315. package/examples/world/content/vegetation.js +1 -1
  316. package/examples/world/main.js +10 -10
  317. package/examples/world/models.js +17 -7
  318. package/examples/world/picture/index.js +20 -0
  319. package/examples/world/picture/lights.js +41 -0
  320. package/examples/world/picture/materials.js +34 -0
  321. package/examples/world/picture/palette.js +74 -0
  322. package/examples/world/picture/post.js +9 -0
  323. package/examples/world/picture/sky.js +39 -0
  324. package/index.d.ts +7 -16
  325. package/index.js +7 -7
  326. package/llms.txt +15 -13
  327. package/modules/ambience/Ambience.js +1 -1
  328. package/modules/calendar/Calendar.js +1 -1
  329. package/modules/calendar/index.js +1 -0
  330. package/modules/camera/FirstPersonCamera.js +1 -1
  331. package/modules/camera/FixedCamera.js +2 -2
  332. package/modules/camera/RtsCamera.js +1 -1
  333. package/modules/camera/common.js +7 -5
  334. package/modules/characters/Character.js +15 -10
  335. package/modules/characters/NPC.js +5 -5
  336. package/modules/characters/assetModel.js +5 -4
  337. package/modules/characters/index.js +28 -3
  338. package/modules/characters/movers/common.js +6 -1
  339. package/modules/characters/movers/manual.js +3 -0
  340. package/modules/characters/movers/support.js +25 -11
  341. package/modules/characters/npcSim.js +5 -1
  342. package/modules/characters/proceduralRig.js +18 -4
  343. package/modules/characters/useModel.js +2 -2
  344. package/modules/collision/Collision.js +4 -2
  345. package/modules/content/index.js +8 -0
  346. package/modules/content/models.js +56 -11
  347. package/modules/content/props.js +5 -3
  348. package/modules/content/rules.js +12 -4
  349. package/modules/content/templates.js +5 -3
  350. package/modules/gameplay/Interactions.js +91 -16
  351. package/modules/gameplay/Inventory.js +3 -3
  352. package/modules/gameplay/dialogueBox.js +1 -1
  353. package/modules/gameplay/dialogueBubbles.js +1 -1
  354. package/modules/gameplay/interactionPrompt.js +1 -1
  355. package/modules/gameplay/interactions.contract.js +1 -1
  356. package/modules/gameplay/inventoryOps.js +2 -2
  357. package/modules/gameplay/pickups.js +62 -24
  358. package/modules/gameplay/questLog.js +2 -2
  359. package/modules/grid/Layer.js +13 -0
  360. package/modules/grid/index.js +40 -11
  361. package/modules/grid/preview.js +24 -15
  362. package/modules/grid/tiles.js +15 -19
  363. package/modules/hlod/index.js +3 -2
  364. package/modules/hud/index.js +13 -0
  365. package/modules/hud/parts.js +9 -7
  366. package/modules/level/index.js +5 -4
  367. package/modules/lights/index.js +12 -8
  368. package/modules/music/Music.js +1 -1
  369. package/modules/particles/Particles.js +41 -20
  370. package/modules/particles/effect.js +21 -6
  371. package/modules/photo/Photo.js +11 -10
  372. package/modules/settings/Settings.js +7 -7
  373. package/modules/settings/apply.js +5 -5
  374. package/modules/settings/sections.js +2 -2
  375. package/modules/settings/strings.js +1 -1
  376. package/modules/sky/Sky.js +104 -89
  377. package/modules/sky/clouds.js +16 -17
  378. package/modules/sky/dome.js +100 -0
  379. package/modules/sky/domeLayers.js +5 -5
  380. package/modules/sky/environment.js +45 -169
  381. package/modules/sky/fog.js +5 -180
  382. package/modules/sky/frame.js +26 -90
  383. package/modules/sky/season.js +3 -3
  384. package/modules/sky/shader.js +35 -29
  385. package/modules/sky/skyModule.js +25 -22
  386. package/modules/sky/tint.js +9 -11
  387. package/modules/terrain/ChunkManager.js +29 -12
  388. package/modules/terrain/draw.js +154 -0
  389. package/modules/terrain/index.js +44 -66
  390. package/modules/terrain/terrainDefaults.js +2 -2
  391. package/modules/terrain/terrainEdit.js +1 -1
  392. package/modules/terrain/terrainGen.js +2 -2
  393. package/modules/triggers/index.js +10 -6
  394. package/modules/vegetation/Vegetation.js +58 -17
  395. package/modules/vegetation/draw.js +191 -0
  396. package/modules/vegetation/groundChunks.js +1 -1
  397. package/modules/vegetation/index.js +10 -10
  398. package/modules/water/Water.js +135 -88
  399. package/modules/water/surface.js +53 -53
  400. package/modules/weather/Weather.js +52 -17
  401. package/modules/weather/particles.js +13 -5
  402. package/modules/weather/shaders.js +1 -1
  403. package/modules/weather/weatherDraw.js +141 -0
  404. package/modules/world/World.js +2 -2
  405. package/modules/world/views.js +1 -1
  406. package/package.json +3 -2
  407. package/presets.js +2 -2
  408. package/render/PostFX.js +199 -41
  409. package/render/backend.js +52 -6
  410. package/render/cascades.js +195 -0
  411. package/render/cascades.tsl.js +96 -0
  412. package/render/daylight.js +39 -0
  413. package/render/detail.js +5 -5
  414. package/render/effects.js +41 -26
  415. package/render/fx/cel.tsl.js +42 -0
  416. package/render/fx/index.js +7 -5
  417. package/render/fx/patchNodes.tsl.js +1 -1
  418. package/render/fx/postWebGPU.tsl.js +30 -7
  419. package/render/fx/sky.tsl.js +19 -92
  420. package/render/fx/water.tsl.js +1 -1
  421. package/render/layers.js +14 -0
  422. package/render/lighting.js +6 -5
  423. package/render/lightmap.js +142 -0
  424. package/render/lights.js +23 -201
  425. package/render/materials.js +44 -160
  426. package/render/neutral.js +23 -0
  427. package/render/occlusion.js +184 -0
  428. package/render/ownFrame.js +1 -1
  429. package/render/patches.js +34 -29
  430. package/render/postWebGL.js +11 -3
  431. package/render/probes.js +179 -122
  432. package/render/slots.js +4 -4
  433. package/render/terms.js +53 -101
  434. package/render/uniformDecl.js +1 -1
  435. package/types/core.d.ts +333 -296
  436. package/types/gameplay.d.ts +65 -26
  437. package/types/generated/core/Audio.d.ts +1 -1
  438. package/types/generated/core/DebugOverrides.d.ts +14 -6
  439. package/types/generated/core/Input.d.ts +9 -2
  440. package/types/generated/core/page.d.ts +9 -2
  441. package/types/generated/modules/grid/Layer.d.ts +8 -0
  442. package/types/generated/modules/grid/index.d.ts +29 -5
  443. package/types/generated/modules/particles/Particles.d.ts +13 -6
  444. package/types/generated/modules/sky/Sky.d.ts +85 -18
  445. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  446. package/types/generated/modules/water/Water.d.ts +50 -3
  447. package/types/generated/modules/weather/Weather.d.ts +33 -3
  448. package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
  449. package/types/generated/modules/world/World.d.ts +2 -2
  450. package/types/generated/render/PostFX.d.ts +53 -10
  451. package/types/generated/render/lighting.d.ts +29 -0
  452. package/types/generated/render/materials.d.ts +19 -44
  453. package/types/generated/render/occlusion.d.ts +13 -0
  454. package/types/physics.d.ts +5 -3
  455. package/types/tsl.d.ts +8 -0
  456. package/types/world.d.ts +376 -57
  457. package/ui/Focus.js +12 -2
  458. package/ui/LoadingScreen.js +2 -2
  459. package/ui/Parts.js +8 -4
  460. package/ui/UI.js +10 -10
  461. package/ui/cursor.js +1 -1
  462. package/ui/theme.js +33 -27
  463. package/ui/touchPart.js +1 -1
  464. package/core/look/coreParts.js +0 -219
  465. package/core/look/part.js +0 -253
  466. package/core/look/points.js +0 -255
  467. package/core/look/report.js +0 -96
  468. package/core/look/shadowPart.js +0 -63
  469. package/core/look/state.js +0 -45
  470. package/core/look/write.js +0 -70
  471. package/core/styleParts.js +0 -114
  472. package/docs/api/style.md +0 -136
  473. package/docs/api/terrainLook.md +0 -10
  474. package/docs/api/vegetationLook.md +0 -10
  475. package/docs/api/weatherLook.md +0 -10
  476. package/docs/recipes/09-style.md +0 -218
  477. package/docs/recipes/35-style-from-reference.md +0 -153
  478. package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
  479. package/docs/recipes/38-environment-look-hooks.md +0 -99
  480. package/docs/recipes/41-thing-registry.md +0 -97
  481. package/docs/recipes/44-water-weather-look-hooks.md +0 -144
  482. package/docs/recipes/48-make-material.md +0 -75
  483. package/docs/recipes/52-look.md +0 -282
  484. package/examples/action/look.js +0 -5
  485. package/examples/sheepisland/style/index.js +0 -79
  486. package/examples/styletest/look.js +0 -11
  487. package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
  488. package/examples/webgpu-tsl/tslScene.js +0 -75
  489. package/examples/world/style/index.js +0 -61
  490. package/examples/world/style/plugins/10-bloom.js +0 -5
  491. package/modules/sky/cascades.js +0 -186
  492. package/modules/sky/cascades.tsl.js +0 -82
  493. package/modules/sky/look.js +0 -54
  494. package/modules/sky/lookFog.js +0 -76
  495. package/modules/sky/lookShadow.js +0 -62
  496. package/modules/sky/lookSky.js +0 -169
  497. package/modules/sky/shadow.js +0 -98
  498. package/modules/terrain/look.js +0 -83
  499. package/modules/terrain/lookGround.js +0 -66
  500. package/modules/vegetation/look.js +0 -119
  501. package/modules/vegetation/lookWind.js +0 -98
  502. package/modules/water/look.js +0 -91
  503. package/modules/water/surfaceDefaults.js +0 -3
  504. package/modules/weather/look.js +0 -74
  505. package/modules/weather/weatherLook.js +0 -135
  506. package/render/lookGlow.js +0 -139
  507. package/render/lookSurface.js +0 -224
  508. package/render/postLook.js +0 -164
  509. package/render/surface.js +0 -105
  510. package/types/generated/modules/weather/weatherLook.d.ts +0 -12
  511. package/types/style.d.ts +0 -671
@@ -0,0 +1,181 @@
1
+ # 52 Around the picture: reading it back, the post chain, who writes what
2
+
3
+ **In this recipe**: Atmosphere · Surfaces · Water, weather · Post effect chain · Who writes it · Lower-level forms that stay
4
+
5
+ The picture is plain three.js in a `picture/` folder that reads `engine.uniforms` ([recipe 62](62-picture-code.md)). This page covers what sits around that code: reading the picture back,
6
+ trying a value out, and the engine pieces it talks to.
7
+
8
+ ```js
9
+ engine.describe('picture').picture; // tone, exposure, fog, environment, background, every light, shadows: what three.js holds now
10
+ const h = engine.debug.override('me', engine.renderer, 'toneMappingExposure', 3); // try a value on any three.js object; held above your picture/ code
11
+ h.remove(); // back to what your code writes (engine.debug.clear('me') takes every override of that owner)
12
+ engine.catalog('post'); // a capability's entries and what it holds now; also 'shadows'
13
+ ```
14
+
15
+ Which knob changes what on screen, and how to judge it for your picture: [recipe 60](60-judge-the-picture.md). Where picture code sits among the other ways to customize: `../CONVENTIONS.md` "Customization ladder".
16
+
17
+ - The picture is not saved: after a load, your `picture/` code draws it again from your own state.
18
+ - How bright a lit color comes out (three.js light units, with `renderer.toneMapping = THREE.AgXToneMapping`, exposure 1): a diffuse surface facing up receives
19
+ `sun.intensity × sin(sun elevation) + hemi.intensity` (the hemisphere's sky color, since it faces up), and three divides by π, so a total of
20
+ **about 3 (≈ π) shows mid-tone albedos (sRGB 0.35-0.65) at roughly their own value**: sun 2 high overhead + hemisphere 1, or a low sun 4 at 20° +
21
+ hemisphere 1.6. Measured on three's AgX curve: total 2.5 for sRGB 0.35, 2.6 for 0.5, 3.4 for 0.65, 5.5 for 0.8 (AgX darkens light colors and
22
+ pales saturated ones, so a pale or vivid palette needs more, or exposure). Walls and faces away from the sun get only their `N·L` share, and
23
+ the environment (`scene.environment`) adds on top for Standard / Physical materials.
24
+
25
+ ## Atmosphere: fog, sky
26
+
27
+ - Fog: `engine.scene.fog` is the game's, [recipe 38](38-environment-hooks.md#fog-plain-threejs-signals-your-own-math).
28
+ - The sky: plain values and calls on `engine.sky`, [recipe 08](08-weather-sky.md).
29
+ - <a id="tsl-forms"></a>**tsl forms** (`renderer: 'webgpu'`): the GLSL hooks `engine.sky.clouds` and `engine.sky.layer` take `{ glsl, tsl }`; each renderer draws its own form and a missing one throws by name (`[webgpu-needs-tsl]` on WebGPU). `tsl: (ctx) => vec4 node`, ctx = the GLSL function's arguments as nodes plus the value so far (`ctx.clouds` the built-in kind, `ctx.color` the sky under a layer, `ctx.fog` what the fog kind alone draws), `ctx.uniforms` (the dome's, yours included), `ctx.fx.noise` / `hash` and `ctx.tsl` (three/tsl):
30
+ `engine.sky.layer('glow', { glsl, tsl: ({ dir, tsl }) => tsl.vec4(1, 0.6, 0.3, tsl.smoothstep(0.3, 0.8, dir.y).mul(0.4)), blend: 'add' })`.
31
+ - Shadows are `engine.shadows` and three.js, recipe 45.
32
+ - Whether a picture reads as lit is mostly key against fill. The key (the sun or one main light) is the light that casts the shadow; the fill is
33
+ everything else (sky and ground light, the environment). Shadowed surfaces see only the fill while lit ones see both, so the balance sets how
34
+ deep the shadows look: less fill is harder and more dramatic, more fill softer and more readable, and there is no right ratio, only the one
35
+ the game wants. A warm key over a cool fill (or the reverse) separates lit from shaded sides without more contrast. The shot's `light:`
36
+ fact measures the ratio; judge the result on a shot with a known-colored object in shadow. To compare afterwards, the `sun-and-key-light`
37
+ technique (`threedog examples pull sun-and-key-light`) shows three routes side by side.
38
+ - Shadow detail is texels per meter: one shadow-map texel covers `2 x extent / mapSize` meters (for example the default `extent` 70 on a
39
+ 2048 map is about 6.8 cm, twice that on the 1024 map of low tier and headless shots). A box much bigger than what the camera sees blurs
40
+ the shadows of small things; a box smaller than it cuts shadows off. `engine.shadows.box(light, { extent })` sizes it; a depth bias scales with the
41
+ texel, so re-check `bias` / `normalBias` after changing either.
42
+ - Fog kinds and the fog hook in detail, the placeholder lights: [recipe 38](38-environment-hooks.md).
43
+
44
+ ## Surfaces: ground, plants, cloud shadow, season
45
+
46
+ ```js
47
+ engine.terrain.material = myGroundMaterial; // plain three.js on the module; terrain({ colors, shading, detail }) are its start values (recipe 28)
48
+ engine.uniforms.uWindFreq.value = 1.5; engine.uniforms.uWindAmp.value = 0.5; // signals: live on every plant, planted ones too
49
+ engine.vegetation.define('grass', { geometry, wind: { amplitude: 0.05, glsl, tsl } }); // your own sway: threedogWind(...) / tsl: (ctx) => moved position (recipe 36)
50
+ engine.vegetation.color({ glsl: 'diffuseColor.rgb *= 0.8;', tsl: c => c.color.mul(0.8) }); // code in the color slot, live on planted species
51
+ engine.terms.cloudShadow({ glsl: 'reflectedLight.directDiffuse *= myShade(vThreedogWorld);', tsl: c => ({ directDiffuse: c.directDiffuse.mul(myShadeNode) }) });
52
+ engine.terms.cloudShadow(false); // no engine cloud shadow anywhere: draw your own
53
+ engine.terms.season(kind => ({ glsl: 'diffuseColor.rgb = mix(diffuseColor.rgb, vec3(1.0), uCover.y);', tsl: c => myTint(c, kind) })); // your own season / snow tint
54
+ ```
55
+
56
+ - Wind is signals: `engine.uniforms.uWind` (weather), `uWindFreq`, `uWindAmp`. A three.js material of yours sways with `applyEffects(mat, { wind: 0.03 })`; your own shader calls `threedogWind(position, origin, amplitude)` (`#include <threedog_wind>`) or `wind(position, origin, amplitude)` (`threedog/tsl`). `uWindFreq` is the start value of `uWindFreq`.
57
+ - The plants: `engine.vegetation.color(glsl | { glsl, tsl, uniforms })` puts code in the `color` slot of every species' material, changed live. The whole plant picture is replaced as a module: `engine.use(myPlants, { replaces: 'vegetation-draw' })`.
58
+ - `engine.terms.cloudShadow(spec)` and `engine.terms.season(spec)` put your own patch (`{ glsl, tsl, uniforms?, pars?, slot? }`, slot `lighting` / `color` by default) in place of the engine's on every material that carries the term, including ones built before the call; `false` removes the term; the handle's `remove()` gives the engine's back. The signals stay bound: `uCloud*` and `threedogCloudShadow(worldPos)`; `uFoliageTint` / `uGroundTint` / `uFoliageMix` / `uGroundMix`, `uCover` (cover amount alone, x foliage, y ground) and `threedogSeason(color, kind)` (TSL: `season(color, kind)`). `season` also takes `kind => spec` (kind `'foliage'` | `'ground'`). Each renderer draws its own form, and a missing one throws by name.
59
+ - Cloud shadow values are signals: `engine.uniforms.uCloudShadow` (darkest, 0 = none), `uCloudScale`, `uCloudSpeed`. The term sits on engine materials and on what you pass to `applyEffects(mat)`; your own shader calls `threedogCloudShadow(worldPos)` (GLSL) or `cloudShadow(positionWorld)` (`threedog/tsl`). The engine adds it to no other material.
60
+
61
+ ## Water, weather
62
+
63
+ - Water is plain three.js on the module (`engine.water.material`, `engine.water.uniforms`, `engine.water.shader`): recipe 44.
64
+ - Weather: `weather({ rain, snow })` gives the particles, `engine.weather.define(field, spec)` a game's own (recipe 44).
65
+
66
+ ## Post effect chain
67
+
68
+ Post-processing is an ordered list of named effects, and **`engine.post.add(x, { name, slot, order })` is the one way an effect gets
69
+ in**: game code and the game's `plugins/` folder (a file that exports the Pass or effect) go through it, so every
70
+ effect has a name, a handle and a row in `describe().slots` and `describe().render.post`. It returns `{ name, enabled, set(params), remove() }`, and
71
+ `engine.post.get(name)` returns the same handle. A wrong shape throws with nothing added. `x` is a plain three.js Pass (WebGL),
72
+ a TSL node function `(input, ctx) => node` (WebGPU), or an effect `{ name, create, node, fuse, slot, order, params, needsDepth, needsBuffers, backend, skipOnLowTier, facts }` (both renderers: give
73
+ `create` and `node`, or a `fuse`; the last five are optional: `needsBuffers` lists extra scene outputs on WebGPU, `backend: 'webgpu'` marks an effect the WebGL2 backend cannot run, `skipOnLowTier` holds it when `engine.tier` is 'low', `facts` adds a line to `describe().render.post`; all explained on `PostEffect` in `api/post.md`). Each runs in a slot, then by `order` (low first):
74
+ `scene` (replaces the scene render, one at a time, e.g. pixelation) -> `hdr` (linear color: outline, AO, bloom) -> tone mapping -> `ldr` (sRGB: LUT,
75
+ palette, grain, vignette) -> `final` (FXAA / SMAA). An effect is `{ name, slot, order, params, create(ctx) => pass, update?(pass, params) }`; under
76
+ WebGL the pass is any three.js postprocessing Pass, built the first time it is on (on WebGPU an effect gives `node` instead: recipe 56). To read the chain: `engine.post.object()` (the
77
+ EffectComposer, null until post first runs) and `engine.post.targets()` (its render targets); both stay the engine's (it rebuilds passes,
78
+ resizes, disposes), so change the chain through `engine.post`; to take the built chain over yourself, `engine.post.own()` (the engine stops rebuilding it, `own(false)` gives it back). A plain Pass is placed by its kind: one that renders `engine.scene` itself
79
+ (`RenderPixelatedPass`, `SSAARenderPass`, `TAARenderPass`) goes in `scene` and replaces the engine's scene render (the scene is drawn once; a
80
+ second one throws), FXAA / SMAA / TAA in `final`, any other in `hdr` after the effects already there; a RenderPass of `engine.scene` and an OutputPass are
81
+ skipped (the engine has them). Without `{ name }` it is listed by class or shader name (`CopyShader#1`); its `remove()` does not dispose it.
82
+ A game that renders the canvas itself (its own composer) takes the frame: the engine stops drawing and warns once `[own-frame]`.
83
+ ```js
84
+ import { bloom, outline, vignette, lut } from '@threedog/post-effects'; // shared effects come from the add-on
85
+ import { LUTPass } from 'three/addons/postprocessing/LUTPass.js';
86
+ const line = engine.post.add(outline({ thickness: 1.5 })); engine.post.add(vignette());
87
+ line.enabled = false; // pauses it in place; a settings restriction above this still holds it off
88
+ engine.post.get('vignette').set({ strength: 0.6 }); // params by name; an unknown name throws
89
+ if (engine.tier !== 'low') engine.post.add(bloom()); // the heavy ones are the game's call on weak devices
90
+ engine.post.add({ name: 'myLut', slot: 'ldr', params: { lut: myLut }, create: ({ params }) => new LUTPass({ lut: params.lut }) });
91
+ // a plugin file brings the same effect with no main.js line: plugins/10-bloom.js
92
+ export default bloom({ strength: 0.2 });
93
+ ```
94
+ - The engine ships no effects. `@threedog/post-effects` (import only what you use) has `bloom`, `ao`, `outline`, `dof` (all `hdr`; outline and dof
95
+ read depth) and `lut` (contrast / saturation / warm-cool / optional 3D LUT, or `paletteLut(colors)` for a fixed palette; it reads display colors after the tone curve), `grain`, `vignette`, `chromatic` (`ldr`). An added effect is on
96
+ (`enabled: false` adds it off, for `handle.enabled = true` later). The heavy ones (`bloom`, `ao`, `dof`, outline `normal`/`both`) are the game's
97
+ call on weak devices: read `engine.tier` before adding them (`threedog shot` renders the desktop tier, `--tier low` checks the low one). To take one
98
+ of a pack's effects out: `engine.plugins.off('<pack>/<file>')` or `engine.post.get('ao').enabled = false`; to add one on top: a game plugin file or `engine.post.add`.
99
+ - Where to import from:
100
+
101
+ | You want | Import |
102
+ |---|---|
103
+ | Materials and lighting written as TSL | `threedog/tsl` |
104
+ | Post effects that run on both routes (bloom, ao, outline, dof, lut, grain) | `@threedog/post-effects` |
105
+ | Post effects that exist only on WebGPU (`voxelGI`, `temporalAA`, `sunShafts`, `lightVolumes`) | `@threedog/post-effects/tsl` |
106
+ | The three.js layers the engine keeps (`RESERVED_LAYERS`) | `threedog/layers` |
107
+
108
+ - Depth: an effect that reads scene depth (`needsDepth: true`, e.g. `outline`) must run before any pass that swaps buffers (a `ShaderPass`, a
109
+ scene-slot pixelation pass, the tone-mapping output). A chain that breaks this throws when the effect is added or enabled, naming both effects;
110
+ give the depth reader a lower `order`. `dof` keeps the scene depth (`pass.keepsDepth = true`), so `dof` and `outline` can both be on while `dof`
111
+ has the lower `order` (default: dof 5, outline 10). The other order throws.
112
+ - Order of glow and a step-style grade (posterize, palette snap, toon-style color banding, a few-level LUT). Glow (bloom) is a smooth falloff: the
113
+ brightest pixels spread a fading halo. A grade that snaps every pixel to a few levels, run **after** the glow, cuts that falloff into flat plateaus:
114
+ each plateau is a hard-edged disc, and the middle ones are a flat mid-tone that reads as a grey stain around a light, not as light. It shows in any
115
+ art style that mixes glow with banded color (a pixel-art lantern, a flat-shaded neon sign, a cel-shaded campfire, a palette-locked sun), and it
116
+ gets worse the fewer levels the grade has. By default `bloom` is an `hdr` effect and a grade is an `ldr` one, so the default order is the bad one.
117
+ Ways out, pick by the picture you want: (1) grade first, glow after: give the grade `slot: 'hdr'` and an `order` lower than bloom's, so the glow is
118
+ computed from the banded picture and stays smooth (the halo may then use colors outside the palette: fine for soft light, wrong for a strict
119
+ palette); (2) keep the grade last and make the glow itself stepped on purpose, one or two clean rings with a threshold, so the discs are a decision
120
+ and not a side effect; (3) drop the glow for that picture and paint the light (emissive sprites, a lighter ring in the art). Judge it with a
121
+ `threedog shot` close on one bright light against a dark ground: the falloff should read as a gradient (1) or as deliberate rings (2); a grey flat
122
+ disc with no gradient and no ring is the trap. Checked on a one-dimensional model of the two orders (a bright source, a blur, a four-level snap): glow
123
+ then snap gave plateaus, snap then glow gave a smooth falloff. Not yet checked in a rendered scene with the real passes.
124
+ - Pause or unload: `handle.enabled = false` pauses an effect where it is (its place and params stay); `engine.plugins.off('<file>')`
125
+ unloads the plugin (the effect leaves the chain; `on` plugs it again). Either way the effect comes back in the same place: inside a slot,
126
+ `order` decides, and equal orders keep the order the names were first added in (a plugin's effects are placed in plugin-list order, even
127
+ one that starts off), so off / on never reorders the chain.
128
+ - On / off is `engine.post.get('bloom').enabled = false` for every effect, whoever added it (there is no `createEngine({ post })`: the engine ships no
129
+ effect to switch on, add one with `engine.post.add(bloom())`). The switch is the shared point `post.<name>.enabled`: `enabled` writes its game layer, a hold of your own goes through `engine.mod('post.bloom.enabled', { owner, set, layer })`, and reading `enabled` gives what runs now. MSAA is `engine.post.setAntialias(on)` and works with every effect on. The settings menu shows `bloom` / `ao` toggles only when effects with those names exist; a toggle the player turns off sits on the settings layer of that point, above the game and any hold (`describe().render.post` reads `writer: 'settings'`), and the menu writes nothing for a value it only re-applies unchanged.
130
+ - `fuse`: a light color effect can skip its own fullscreen pass by carrying a GLSL snippet instead of `create()`:
131
+ `fuse: { uniforms: { uMyAmount: 'float' }, values: p => ({ uMyAmount: p.amount }), glsl: 'color.rgb *= 1.0 - uMyAmount * length(vUv - 0.5);' }`.
132
+ Fused effects that are on and next to each other in one slot (never `scene`) compile into one shader and draw in one pass, in `order`. The
133
+ snippet edits `vec4 color` and may use `vUv`, `tDiffuse`, `uTime`, `uResolution`, `fxHash(vec2)`; uniform names are shared by the group, so prefix
134
+ them with the effect name. A snippet that samples `tDiffuse` elsewhere (blur, color fringe) sets `reads: true` and starts a new group.
135
+ `engine.post.add({ name, fuse: { glsl }, slot: 'ldr' })` adds just a snippet.
136
+ - Outline: `outline({ mode: 'depth' | 'normal' | 'both' })`: `depth` (default, silhouettes), `normal` (creases; draws the scene once more with
137
+ normals, so it costs more), `both`. `fadeWithDistance: false` keeps lines at any distance; `wobble: 1.5` jitters lines by up to 1.5 px at 8 steps a
138
+ second. To exempt objects: `outline({ offLayer: OUTLINE_OFF_LAYER })` and `mesh.layers.enable(OUTLINE_OFF_LAYER)` (one extra render of just
139
+ those objects; nothing when `offLayer` is `null`).
140
+ - Ambient occlusion (darker creases and contact corners): `ao({ radius, intensity })` wraps three's `GTAOPass`; `radius` is in world units
141
+ (default 0.25), `intensity` 0..1 (default 1), both change in place: `engine.post.get('ao').set({ radius: 0.6 })`. Order 20 runs it before bloom and the tone mapping. It follows resize,
142
+ render scale and MSAA like every effect. It draws the scene once more with normals: points and lines are skipped, and a vertex-moving shader
143
+ patch (wind) is not applied there, so swaying leaves get the AO of their rest pose. Cost on a laptop GPU (AMD 780M, 1280x720, MSAA, a street
144
+ scene): about +6 ms a frame (4.4 -> 10.7 ms). Other GTAOPass settings (`samples`, `thickness`, `output`):
145
+ `engine.post.object().passes.find(p => p.gtaoMaterial)`.
146
+
147
+ ## Who writes it: the ownership table
148
+
149
+ Some three.js values the engine writes **on its own**, every frame or on a timer: the camera module places the camera, a sky keeps the shadow box around the focus. Lights, fog, exposure and the environment are not among them: the game's `picture/` code is their one writer (recipe 62).
150
+ Each of them is registered once (`core/owned.js`), and every one behaves the same way:
151
+
152
+ - **Engine** (default): the engine writes it. Adjust it while the engine keeps driving: the `set` call in the table.
153
+ - **Taken** (`manual`): `engine.view.manual('far' | 'fov' | 'pixelRatio')` stops the engine writing it; the three.js value is yours.
154
+ `manual(key, false)` (or the handle's `remove()`) gives it back. No module option starts a value taken over.
155
+ - **Written directly** without `manual`: the engine notices, **stops writing it and keeps your value**, and warns once with the `manual` call and the
156
+ hand-back call. This happens in release builds too (only the warning is dev-only), so a game behaves the same with and without checks.
157
+ - A `timeline.tween` on an object is a temporary takeover of that object only: no warning, no hand-over (other objects stay checked).
158
+
159
+ `engine.describe().owned` lists every registered value and who writes it now, as `writer` (`engine`, `manual:game`,
160
+ `three (engine yielded)`). A test (`tests/specs/owned.mjs`) runs the three
161
+ behaviors for every registered value and fails when one is registered without a row here.
162
+
163
+ | id | part | written when | take it | adjust while the engine drives |
164
+ |---|---|---|---|---|
165
+ | `shadow.follow` | shadow | the box on the engine sun: under a sky every frame (center = `sun.target`); without one the placeholder sun follows `engine.focus` | `engine.shadows.box(engine.lights.sun, { follow: false })` | `engine.shadows.box(engine.lights.sun, { extent })` |
166
+ | `toneMapping` | tone | never: `renderer.toneMapping` stays three.js's default until your code writes it | `engine.renderer.toneMapping = THREE.ACESFilmicToneMapping`; an own curve as a post stage: `engine.post.add({ name, slot: 'tone', create })` (or `node` on WebGPU; replaces OutputPass / renderOutput; outputs display color) | - |
167
+ | `background` | sky | sky: a backdrop color or skybox every frame; with the dome the dome hides when you take it | `scene.background = x` (the dome hides); whole sky: `engine.sky.replace(texture \| object3D)` | `engine.sky.backdrop = '#335577'` |
168
+ | `view.far` | view | terrain view range (`setViewChunks`) | `engine.view.manual('far')` | - |
169
+ | `view.fov` | view | the settings menu fov slider, camera modules (first person / rts fov, fixed shots, back to the install fov on a switch) | `engine.view.manual('fov')` | - |
170
+ | `view.pixelRatio` | view | adaptive resolution, about once a second while slow | `engine.view.manual('pixelRatio')` | `engine.setPixelRatio(1.5)` |
171
+ | `camera` (position, rotation) | view | the camera module, every frame | `const cam = engine.takeCamera('me')` (`cam.remove()` gives it back) | - |
172
+ | `post.chain` | post | whenever the effect list changes (add / remove / on / off, MSAA): the engine rebuilds the composer passes (WebGL) or `pipeline.outputNode` (WebGPU) | `engine.post.own()`: the built chain stays as you left it in `engine.post.object()`; `own(false)` rebuilds it from the list. A write to `object()` without `own()` does not yield: the next chain change replaces it | `engine.post.get('bloom').set({ strength: 0.6 })` |
173
+ | `shadow.csm` (not a property: a list) | shadow | while cascades are on: the `csm` patch goes on every built-in lit material, yours too (else N times as bright) | - (`handle.remove()`); your ShaderMaterial is left alone until `engine.shadows.include(mat)` | - |
174
+
175
+ Not in this table, because the engine writes them once rather than keeps writing them: automatic batching (it moves engine-placed meshes to layer 31
176
+ and says so once in the dev console and in `describe().perf.batching`; turn it off per object with `userData.batch = false`, see
177
+ [05-props-bake.md](05-props-bake.md) §2b) and `castShadow` on generator props (set when the model is made: a generator's own flags are kept, the
178
+ manifest entry can set them; change it on the object afterwards).
179
+
180
+ ## Lower-level forms that stay
181
+
@@ -1,24 +1,24 @@
1
1
  # The ground up close: options and diagnosis
2
2
 
3
- Not a standard recipe. Several looks are right for different games, and none is the default. **Decide from the reference images first**: is the
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
- ## Approaches (pick by the look you want)
8
- | Look | How | Typical values |
7
+ ## Approaches (pick by the picture you want)
8
+ | Picture | How | Typical values |
9
9
  |---|---|---|
10
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 })`, `style.terrain.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) | material spec `map` + `repeat`, 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`, `type: 'toon'` with a `ramp`; detail optional | `jitter: { size: 2, min: 0.9, range: 0.15 }`; `ramp: [0.4, 0.75, 1]` |
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
14
  | Your own shader or plain three.js | `terrain({ material })`, or recipe 40 section 8 (what you give up) | any |
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: `look.ground.set`,
18
- `look.surface.set({ detail })`, `look.surface.patch('detail', glsl)` (recipe 52).
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
18
+ other material: `applyEffects(mat, { detail })`, with your own function as `detail: { glsl }` (recipe 43).
19
19
 
20
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 `look.ground` recipe 52; terrain basics recipe 28.
21
+ grid recipe 37; `detail` keys recipe 43; run-time changes `engine.terrain.recolor` recipe 36; terrain basics recipe 28.
22
22
 
23
23
  ## Symptom, causes, options
24
24
  **Brushed metal at grazing angles.** Cause: `stroke` stretches one axis (`stretch` 6) and `world` projection looks straight down, so a flat
@@ -32,7 +32,7 @@ Options, any of them: more height samples (a larger image or table), or the data
32
32
  { interp: 'cubic' })` for smooth heights everywhere outside the terrain module (placement, gameplay; recipe 37 section 7; a terrain `height`
33
33
  function runs in a worker and cannot capture a sampler); a finer `resolution` (more triangles, collision and edit cells); `shading: 'smooth'`,
34
34
  or `normals: 'smooth'` with `shading: 'texture'`; `diagonal: 'adaptive'` against zigzag ridges; or noise in the `height` function (`n.fbm`; ridges from
35
- folding it) instead of a sparse table. Terraces can also be the look you want: `interp: 'nearest'`, or a stepped `height`.
35
+ folding it) instead of a sparse table. Terraces can also be the picture you want: `interp: 'nearest'`, or a stepped `height`.
36
36
 
37
37
  **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
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
@@ -43,8 +43,8 @@ pixel, so it stays sharp); near grass over the ground; or accept soft color and
43
43
  (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
44
  colors in `biomeColors` for the type; `blend.strength` 1.5; `variation.patches` with a `tint`; more ground types.
45
45
 
46
- **Dark blotches.** Cause: usually cloud shadows (`style.clouds.shadow` above 0), not texture; they drift with `speed`, and bigger clouds mean
47
- bigger blotches. Test by setting `clouds.shadow: 0` (live: `look.cloudShadow`); if they vanish, lower it or change `scale`. Blotches that
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
48
48
  never move are `variation.patches` or a strong `detail`.
49
49
 
50
50
  **Shimmer far away.** Cause: a pattern smaller than a pixel aliases. `detail.fade` (default) fades it out; `fade: false` keeps it. In your own
@@ -2,9 +2,9 @@
2
2
 
3
3
  ```js
4
4
  engine.scene.add(new THREE.PointLight(0xffaa55, 2, 8)); // anything the engine does not write: just do it
5
- engine.lights.sun.intensity = 3; // an engine-driven value: this write takes it over (warns once)
6
- engine.look.lights.manual('sun'); // the same takeover said on purpose (no warning); manual('sun', false) gives it back
7
- engine.look.sky.replace(mySky); // the one three.js thing a part draws: your sky (or env map, material role, post chain)
5
+ engine.lights.sun.intensity = 3; // the placeholder lights too: nothing else writes them
6
+ const mySky = new THREE.Mesh(skyGeometry, skyMaterial);
7
+ engine.sky.replace(mySky); // your sky: skybox name, Texture or Object3D; null gives the dome back
8
8
  engine.onRender(({ renderer, scene, camera }) => { /* render into your own target */ });
9
9
  ```
10
10
 
@@ -14,30 +14,30 @@ one of them hands it to you (the engine stops writing it and warns once with the
14
14
  Everything else: just do it.
15
15
 
16
16
  Rule of thumb: write the three.js first; it works (auto-yield: the engine stops writing a value you wrote, warns once). `renderer.toneMapping =
17
- THREE.ACESFilmicToneMapping` is a complete answer. The engine route is optional on top: `engine.look.<part>` (recipe 52) adds owners, layers and
18
- keyframes. `set(...)` tunes and keeps the engine writing; `manual(key)` takes a value without the warning (`manual(key, false)` gives it back);
19
- `replace(...)` hands a whole part your own object. `engine.describe().look` says, per value, who set it last; `describe().owned` who writes each
17
+ THREE.ACESFilmicToneMapping` is a complete answer. The engine route is optional on top: `engine.mod(point, ...)` adds owners and layers
18
+ where several systems share a value (recipe 55); `engine.view.manual(key)` takes a value without the warning (`manual(key, false)` gives it back);
19
+ `engine.describe('picture').picture` says what three.js holds now; `describe().owned` who writes each
20
20
  engine-driven value now.
21
21
 
22
22
  | three.js idiom | Where it goes in the engine | Engine overwrites it? | How to take it over |
23
23
  |---|---|---|---|
24
- | `renderer.toneMapping` | Just set it: `engine.renderer.toneMapping = THREE.ACESFilmicToneMapping` (any three mapping). A curve of your own: a post stage in the `'tone'` slot, `engine.look.post.add({ name, slot: 'tone', create, node })`, which runs on both renderers (a `ShaderChunk` edit is page-wide and reaches only the default renderer) | Once, at `createEngine` (`style.toneMapping`, else AgX), never again | Nothing to take: your write stays; `describe().render.toneMapping.writer` says `game` |
25
- | `renderer.toneMappingExposure` | Just set it, or `engine.look.tone.set({ exposure })` / `style.exposure` for owners, layers and day keyframes | Exposure keyframes (`style.exposure` as a list or function) are written every frame by the sky module; a number once | Your direct write takes it (auto-yield; describe tags it `three`). `look.tone.manual('exposure')` stops the keyframes without the warning. Own the whole renderer: `createEngine({ renderer })` (recipe 50) |
24
+ | `renderer.toneMapping` | Just set it: `engine.renderer.toneMapping = THREE.ACESFilmicToneMapping` (any three mapping). A curve of your own: a post stage in the `'tone'` slot, `engine.post.add({ name, slot: 'tone', create, node })`, which runs on both renderers (a `ShaderChunk` edit is page-wide and reaches only the default renderer) | Once, at `createEngine` (`style.toneMapping`, else AgX), never again | Nothing to take: your write stays; `describe().render.toneMapping.writer` says `game` |
25
+ | `renderer.toneMappingExposure` | Just set it | Never on its own | Your direct write stays. Own the whole renderer: `createEngine({ renderer })` (recipe 50) |
26
26
  | `renderer.outputColorSpace` | Leave it at `SRGBColorSpace` (three's default) | No | Changing it makes every color wrong; `assets.report` flags it |
27
- | `renderer.shadowMap` | `look.shadow.set({ enabled, type })` (a sky adds cascades, extent ...) | `enabled` / `type` on a change of look.shadow; the sky manages `needsUpdate` | Write it: the engine yields; or `createEngine({ renderer })` and run your own |
28
- | `scene.environment` | A generated neutral room map under every style (`look.lights` `env.intensity` = its absolute intensity, 0 = none; under a sky `env.share` = its share of the ambient). With a sky: `look.env.replace('sky' \| assetName \| false)` | The baseline map is only written while `scene.environment` is empty or its own. A sky `'sky'` environment is rebuilt and reassigned | Assign your own `scene.environment`: with a sky the rebuilds stop (or say it first: `look.env.manual()`). Or hand it over: `look.env.replace(myTexture | myCubeTexture | myPmremTarget)` |
29
- | `scene.background` | Style `background`, or `look.sky.replace(name \| Texture \| Object3D)` with a sky | The sky dome draws over it; a backdrop / skybox writes it every frame | Assign it: the dome hides and the sky stops writing it (`look.sky.manual('background')` says so first; `manual('background', false)` gives it back), or `look.sky.replace(yourTexture)` |
30
- | `scene.fog` | `look.fog.set(...)` with a sky | The sky writes it every frame until you write it | Assign it: `scene.fog = new THREE.Fog(...)` (the engine yields; the one route, there is no `look.fog.replace`), or `look.fog.manual()` to keep the engine's fog and edit it yourself; `manual(false)` gives it back |
31
- | Your own sky (three/addons `Sky`, a ShaderMaterial dome, a skybox) | `engine.look.sky.replace(mySky)`; feed it from `engine.uniforms` (`uSunDir`, `uDaylight`, `uTimeOfDay`, `uWind`, `uCloud`) | Never: the engine only hides its dome and adds `mySky` to the scene when it has no parent; time, lights, fog and weather keep running | `look.sky.replace(null)` gives the dome back. Per key instead of whole: `look.sky.set({ top: ({ state }) => ... })`, state from `engine.look.state({ ... })` |
32
- | Lights (`DirectionalLight`, `PointLight`, ...) | Add them with `engine.scene.add(light)` before `engine.start()` (a light count change mid-play recompiles shaders; `lightPool()` for many) | Only `engine.lights.sun` / `.hemi` (driven by the sky when installed) | Write them directly (the sky stops writing what you wrote), or say so: `look.lights.manual('sun' \| 'sun.color' \| 'sun.direction' \| 'hemi')`; `look.lights.set(...)` keeps the day cycle; `sky({ sun: false })` or `createEngine({ lights: false })` and bring all your own |
33
- | Shadow camera (`light.shadow.camera`, `mapSize`, `bias`) | Your own lights: just do it. Engine sun: `look.shadow.set(...)` (sky) | The engine sun's shadow box follows `engine.focus` every frame | `look.shadow.set({ follow: 'focus' \| 'camera' \| object3D \| fn \| false, extent })`, or place `sun.target` yourself (the box stops following). With `cascades > 1` built-in lit materials get the `csm` patch; a lit ShaderMaterial of yours joins with `look.shadow.include(mat)` |
34
- | Materials (`new MeshStandardMaterial(...)`) | Just do it, or `makeMaterial('role', { color })` to get the style's material for a role | Your own materials: no. Role materials: `look.materials.set` live keys are written onto every material of the role | `look.materials.replace('role', material)` for a role. A key the `makeMaterial` call passed, or a value you set by hand, is never overwritten (recipe 52) |
27
+ | `renderer.shadowMap` | `engine.shadows.enabled`; `type` is yours | `enabled` when the switch changes | Write it: the engine yields; or `createEngine({ renderer })` and run your own |
28
+ | `scene.environment` | None by default. The sky as a map: `engine.sky.environment({ into: engine.scene })` | Never written unless you call that; a map you write stays | Write it; recipe 34 |
29
+ | `scene.background` | Style `background`, or `engine.sky.replace(name \| Texture \| Object3D)` with a sky | The sky dome draws over it; a backdrop / skybox writes it every frame | Assign it: the dome hides and the sky stops writing it, or `engine.sky.replace(yourTexture)` |
30
+ | `scene.fog` | Assign it: `scene.fog = new THREE.Fog(...)` | Never on its own | Your write stays |
31
+ | Your own sky (three/addons `Sky`, a ShaderMaterial dome, a skybox) | `engine.sky.replace(mySky)`; feed it from `engine.uniforms` (`uSunDir`, `uDaylight`, `uTimeOfDay`, `uWind`, `uCloud`) | Never: the engine only hides its dome and adds `mySky` to the scene when it has no parent; time, lights, fog and weather keep running | `engine.sky.replace(null)` gives the dome back. Per key instead of whole: write `engine.sky.top` and friends in your frame code |
32
+ | Lights (`DirectionalLight`, `PointLight`, ...) | Add them with `engine.scene.add(light)` before `engine.start()` (a light count change mid-play recompiles shaders; `lightPool()` for many) | Never on its own; `engine.lights.sun` / `.hemi` are still placeholders | Write them directly; `createEngine({ lights: false })` leaves the placeholders out |
33
+ | Shadow camera (`light.shadow.camera`, `mapSize`, `bias`) | Your own lights: just do it. Engine sun: the same, and `engine.shadows.box(engine.lights.sun, ...)` (sky) | The engine sun's shadow box follows `engine.focus` every frame | `engine.shadows.box(sun, { follow: 'focus' \| 'camera' \| object3D \| fn \| false, extent })`, or place `sun.target` yourself (the box stops following). With cascades built-in lit materials get the `csm` patch; a lit ShaderMaterial of yours joins with `engine.shadows.include(mat)` |
34
+ | Materials (`new MeshStandardMaterial(...)`) | Just do it | No | - |
35
35
  | `onBeforeCompile`, `customProgramCacheKey` | Just assign them, on any material: `m.onBeforeCompile = s => { ... }`. A named, checked patch: `applyEffects(m, { patches: [...] })` | Nothing: on a material the engine patched (wind, clouds, season), your function runs first and the patches after it; your cache key is joined in front of theirs | - |
36
36
  | Textures, `CanvasTexture`, `DataTexture` | Just do it; set `colorSpace = SRGBColorSpace` on color textures. File textures by name: `engine.assets.manifest({ textures })` then `assets.texture(name)` | No | A texture made in code gets a name too: `assets.manifest({ textures: { brick: () => makeBrick(), sign: mySignTexture } })`, then `map: 'brick'`; it keeps its own repeat / wrap / colorSpace. Baking: see recipe 05 |
37
- | `EffectComposer` passes | `const h = engine.look.post.add(pass)` (`composer.addPass`; `{ order }` for `insertPass`; `h.remove()` for `removePass`): the pass joins the engine chain after the scene render, before tone mapping (FXAA / SMAA last; a pass that renders the scene replaces the scene render); a settings toggle: `add(pass, { name: 'glow' })`, then `look.post.set({ glow: false })` | The engine renders the main frame through its own composer; a composer of your own rendered to the canvas takes the frame over (the engine stops drawing, warns `[own-frame]`; delete the call to hand it back) | `look.post.replace([...effects])` for the whole chain. To read them: `engine.post.object()` (the EffectComposer, null until post first runs) and `engine.post.targets()` (`renderTarget1 / 2`, `readBuffer`, `writeBuffer`; read in `onRender(fn, { when: 'after' })`). Read-only: the engine rebuilds `passes`, resizes and disposes them |
37
+ | `EffectComposer` passes | `const h = engine.post.add(pass)` (`composer.addPass`; `{ order }` for `insertPass`; `h.remove()` for `removePass`): the pass joins the engine chain after the scene render, before tone mapping (FXAA / SMAA last; a pass that renders the scene replaces the scene render); a settings toggle: `add(pass, { name: 'glow' })`, then `engine.post.get('glow').enabled = false` | The engine renders the main frame through its own composer; a composer of your own rendered to the canvas takes the frame over (the engine stops drawing, warns `[own-frame]`; delete the call to hand it back) | `engine.post.own()` for the whole chain. To read them: `engine.post.object()` (the EffectComposer, null until post first runs) and `engine.post.targets()` (`renderTarget1 / 2`, `readBuffer`, `writeBuffer`; read in `onRender(fn, { when: 'after' })`). Read-only: the engine rebuilds `passes`, resizes and disposes them |
38
38
  | Render targets (mirror, minimap, portal, picking) | `engine.onRender(({ renderer, scene, camera, dt }) => { renderer.setRenderTarget(rt); renderer.render(scene, cam); })`; runs after the camera and batching, before the frame (`{ when: 'after' }` after it) | No; the render target is reset to the screen after each `before` callback | The main frame render itself stays the engine's |
39
39
  | Loaders (`GLTFLoader`, `TextureLoader`, `EXRLoader`, `FBXLoader`, `FontLoader`, exporters) | glTF and png / jpg / ktx2 / hdr textures: `engine.assets.manifest(...)` gives them names, the loading screen and `describe` | No | A hand-made `GLTFLoader` / `TextureLoader` works (rule R21 warns: the asset gets no name). Formats the manifest cannot load (EXR, FBX, OBJ, typeface fonts) and exporters: just use the three.js addon |
40
- | Camera (`fov`, `position`, `far`) | Camera modules (`followCamera()`, ...) or `engine.camera` with none installed | An installed camera module writes position / fov every frame; terrain view distance rewrites `camera.far` | `engine.takeCamera('me')` (gives it back on `remove()`), or just write `camera.position` (the rig stops; `look.view.manual('camera', false)` resumes). `camera.far` / `fov`: `look.view.manual('far' \| 'fov')`. Not yet: no slot to swap in a different camera object |
40
+ | Camera (`fov`, `position`, `far`) | Camera modules (`followCamera()`, ...) or `engine.camera` with none installed | An installed camera module writes position / fov every frame; terrain view distance rewrites `camera.far` | `engine.takeCamera('me')` (gives it back on `remove()`), or just write `camera.position` (the rig stops; `engine.view.manual('camera', false)` resumes). `camera.far` / `fov`: `engine.view.manual('far' \| 'fov')`. Not yet: no slot to swap in a different camera object |
41
41
  | Meshes (`scene.add(mesh)`) | `engine.add(mesh, { id })` (tracked, saveable) or plain `engine.scene.add(mesh)` | No: auto-batching only merges what the engine places (world records, stream builds, level files); your own meshes stay as you made them | Many static copies of your own mesh: `mesh.userData.batch = true` before adding (recipe 05, 2b) |
42
42
  | `requestAnimationFrame` loop | `engine.onFrame(dt => ...)`, `engine.onFixed(dt => ...)` | The engine runs the only loop | Do not start a second loop |
43
43
 
@@ -26,7 +26,7 @@ What to remember:
26
26
  - Every handle ends with `h.remove()` (`engine.mod`, `ctx.mod`, `input.gate`, `wrap`, `freeze`, `takeCamera`); it drops only your own entry.
27
27
 
28
28
  Only things several parties commonly write are shared values: time speeds and the calendar rate, pause / freeze / camera holders, move stats,
29
- input gates; the look values (sun and ambient light, fog, exposure, shadow on / quality, post parameters) move onto them next. Your own objects,
29
+ input gates; shadow on / quality and post parameters are on them too. Your own objects,
30
30
  materials and textures are plain three.js: never registered, never a conflict. Which tool to reach for: `../CONVENTIONS.md` "Customization ladder".
31
31
 
32
32
  ```js
@@ -42,7 +42,6 @@ engine.wrap(engine.inventory, 'add', (next, id, n = 1, o) =>
42
42
  | Layer (low to high) | Who writes it |
43
43
  |---|---|
44
44
  | `engine` | the engine's own defaults and drivers |
45
- | `style` | style packs |
46
45
  | `game` (default) | game code, game modules |
47
46
  | `effect` | temporary effects: weather, sunset fade, bullet time, haste |
48
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 |
@@ -57,13 +56,26 @@ engine.wrap(engine.inventory, 'add', (next, id, n = 1, o) =>
57
56
  - `describe().shared` has one row per point with entries: `value`, `writer` (whose value the rest acts on; `'default'` when nobody set it),
58
57
  `layer`, `at` (the code line, development builds), `how` (`'cave 180 × storm 0.6'`), `also` (everyone else; `hidden: true` when a set above hides
59
58
  theirs). `engine.stacks.of('storm')` lists everything one owner changes. Per-record points read `'move.speed[player]'`.
60
- - A direct three.js write of a property a point drives is never an error: whoever applies the point calls `point.yieldToThree()` and stops; the row
61
- says `writer: 'three (engine yielded)'`; `point.reclaim()` hands it back.
59
+ - A point holds a value and writes no three.js by itself: whoever reads it writes three.js. A value the engine writes on its own shows in
60
+ `describe().owned`, and a direct three.js write takes it (the row says `writer: 'three (engine yielded)'`).
62
61
  - Base values are yours: `player.speed = 6` is always fine; modifiers go through `engine.mod('move.speed', { owner, id: 'player', mul })`.
63
62
  - Your own point: `engine.stacks.define('damageTaken', { per: true, min: 0 })`, then `engine.stacks.get('damageTaken').value(enemyId)`;
64
63
  `kind: 'value'` holds a color, a string or a flag (set only), `kind: 'one'` is an exclusive slot (what `provides` makes).
65
64
  - Saved: `engine` to `effect` entries. Not saved: `settings` (the settings module re-applies the player's choices), `system`, `debug`.
66
65
 
66
+ ## 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
+ `sky.tint`, `ground.cover` (blend by amount) and `sky.flash` (adds) are written with `engine.mod`.
69
+ ```js
70
+ const hold = engine.mod('shadows.enabled', { owner: 'cutscene', layer: 'system', set: false }); // decides over the game and the menu
71
+ engine.describe().shared['shadows.enabled']; // who decided and who is hidden
72
+ hold.remove(); // the handle ends yours
73
+ ```
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.
77
+ - A direct three.js write (`engine.lights.hemi.intensity = 0.2`) still works, and describe tags it `three`.
78
+
67
79
  ## Time channels
68
80
 
69
81
  - `engine.onFixed(dt => moveEnemies(dt), { channel: 'enemies' })`: dt is that channel's scaled dt. Without `channel` dt is real (1/60): cooldowns
@@ -96,7 +108,7 @@ checks that need this step's player position). The order never depends on which
96
108
 
97
109
  Two modules that each want to be "the" one (a sky, a tone-mapping stage, an inventory) declare an exclusive slot: `provides: ['inventory']`.
98
110
  Other modules `requires: ['inventory']` and work with whichever holds it. `engine.use(myInventory(), { replaces: 'inventory' })` unloads the
99
- holder (its tracked handles, its `ctx.mod` entries, its look parts, its `dispose`) before the new install, and puts it back if that fails.
111
+ holder (its tracked handles, its `ctx.mod` entries, its `dispose`) before the new install, and puts it back if that fails.
100
112
 
101
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`,
102
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
@@ -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 · 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 · 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
@@ -13,15 +13,10 @@ Rules (correctness, not taste): `import 'threedog/tsl'` comes first in `main.js`
13
13
  `onBeforeCompile`, three.js `Pass` objects, GLSL-only patches and hooks), and each one fails by name instead of drawing nothing.
14
14
 
15
15
  ## WebGPU or WebGL
16
- WebGL stays the default and the faster choice on most machines today. Measured in 2026-11 on one scene (terrain, 3000 trees, shadows, bloom):
17
- on an integrated GPU WebGL drew a frame fastest, WebGPU took about 1.5 times as long and WebGPURenderer's WebGL2 backend (what a browser
18
- without WebGPU gets) about 1.7 times; on a discrete laptop GPU WebGL was still fastest. The first frame on WebGPU came 0.6 to 1.3 s later
19
- (shader compilation). How to decide:
20
- - Choose WebGPU when the game's look is built from TSL (you want to write shaders in JavaScript, compose them as functions, or start from a
21
- three.js WebGPU example), or when you need something only node materials have.
22
- - Stay on WebGL when the game must run well on modest hardware, when it already has GLSL (ShaderMaterials, `onBeforeCompile`, a three.js
23
- `Pass`), or when start-up time matters more than the shading style. Recipe 43 is the GLSL route for the same tasks.
24
- - Check on the hardware you care about: `threedog inspect perf` on both routes, same scene.
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
+ - 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
+ - `--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).
25
20
 
26
21
  ## Turning it on
27
22
  ```js
@@ -36,9 +31,9 @@ Your own `new WebGPURenderer(...)` as `renderer` goes the same way (the engine c
36
31
  browser gives no WebGPU, `fallback` decides, and the console says once which one happened (`[threedog] WebGPU unavailable (...)`):
37
32
  - `'webgl2'` (default): the same WebGPURenderer on its WebGL2 backend. Your TSL keeps working; frames are slower than plain WebGL.
38
33
  - `'webgl'`: a `WebGLRenderer` instead. Faster, but node materials cannot draw there (`start()` fails when the scene has one). The engine's
39
- own materials (terrain, vegetation, water, `makeMaterial`) are plain three.js materials with both a GLSL and a tsl form of each patch, so they
40
- draw on either renderer with the same look. What engine modules built before `start()` is rebuilt for WebGLRenderer there: the post chain,
41
- the sky dome (with the `look.sky.patch` hooks set so far), fog, cascaded shadows, particles, rain and snow. Your own objects are not:
34
+ own materials (terrain, vegetation, water) are plain three.js materials with both a GLSL and a tsl form of each patch, so they
35
+ draw on either renderer with the same picture. What engine modules built before `start()` is rebuilt for WebGLRenderer there: the post chain,
36
+ the sky dome (with the `engine.sky.clouds` / `layer` hooks set so far), fog, cascaded shadows, particles, rain and snow. Your own objects are not:
42
37
  build node materials after `start()` when `engine.describe().renderer.backend !== 'webgl'`.
43
38
  - `'error'`: `start()` rejects; the game shows its own message.
44
39
 
@@ -55,8 +50,16 @@ engine.add(new THREE.Mesh(new THREE.TorusKnotGeometry(0.6, 0.2, 128, 16), mat));
55
50
  A node material is lit, shadowed and fogged by three like its plain twin; you replace only the inputs you set (`colorNode`, `positionNode`,
56
51
  `normalNode`, `emissiveNode`, `roughnessNode`, `opacityNode` ...).
57
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`.
60
+
58
61
  ## The engine's values as nodes: `uniforms(engine)`
59
- `uniforms(engine)` returns `engine.uniforms` as TSL nodes with the same names: `uTime`, `uWind`, `uCloud`, `uSunDir`, `uDaylight`
62
+ `uniforms(engine)` returns `engine.uniforms` as TSL nodes with the same names: `uTime`, `uWind`, `uCloud`, `uSunDir`, `uSunColor`, `uDaylight`
60
63
  (0 at night, 1 at noon), `uTimeOfDay`, `uFoliageTint`, `uGroundTint` ... (the list: `uniforms` in [the engine API](../api/engine.md)). The node reads the
61
64
  engine's value each render, so weather, the calendar and the sky move your material with no per-frame code.
62
65
  ```js
@@ -85,6 +88,7 @@ in the package's `types/tsl.d.ts`. Call them on nodes, put the result where it b
85
88
  | `season(color, 0 \| 1)` | the color moved by the calendar's tint (0 foliage, 1 ground) | `colorNode` |
86
89
  | `detailNoise(p, kind, octaves)` / `detailBump(...)` | gray noise + height / a bumped normal | breaking up flat color; `normalNode` |
87
90
  | `wrapDiffuse`, `shadowTint`, `rim` | light to add | inside a lighting hook (next section) |
91
+ | `celLighting` | a lighting model | `mat.setupLightingModel = celLighting` on a `MeshToonNodeMaterial` ("A consistent style" below) |
88
92
  | `waterWave`, `waterSurface(spec)`, `waterFresnel` | wave height / surface color / fresnel blend | a water material of your own |
89
93
 
90
94
  ```js
@@ -141,26 +145,65 @@ const rock = applyEffects(new MeshStandardNodeMaterial({ color: 0x9a9080 }), { p
141
145
  engine.add(new THREE.Mesh(new THREE.DodecahedronGeometry(1), rock));
142
146
  ```
143
147
 
148
+ ## Half-transparent surfaces and fog differ from plain WebGL
149
+ WebGL straight to the canvas tone-maps and encodes each material first, then applies fog and blends in display values. WebGPU, and WebGL with any `engine.post` effect on, fog and blend in linear and tone-map once. Those two match pixel for pixel, opaque unfogged surfaces match on all three, and half-transparent or fogged ones shift on the straight WebGL path, more in dim scenes. So on WebGL turning the first post effect on can move those surfaces a little. This is how three.js's renderers work, not a fault to fix in your scene.
150
+
144
151
  ## Sky and fog hooks
145
- The engine's sky dome and fog kinds have node versions; nothing changes in how you set them (recipe 08). The GLSL hooks (`look.sky.patch`
146
- clouds and layers, `look.fog.patch('fog')`, style sky layers) take `{ glsl, tsl }` on this route: see 52's [tsl forms](52-look.md#tsl-forms).
147
- A sky of your own: three's `SkyMesh` (`three/addons/objects/SkyMesh.js`) through `engine.look.sky.replace`.
152
+ The engine's sky dome has a node version; nothing changes in how you set it (recipe 08). The GLSL hooks (`engine.sky.clouds`, `engine.sky.layer`
153
+ clouds and layers) take `{ glsl, tsl }` on this route: see 52's [tsl forms](52-around-the-picture.md#tsl-forms).
154
+ A sky of your own: three's `SkyMesh` (`three/addons/objects/SkyMesh.js`) through `engine.sky.replace`.
148
155
 
149
156
  ## Post effects as nodes
150
157
  On WebGPURenderer the post chain is one three.js `RenderPipeline` (`engine.post.object()` returns `{ pipeline, scenePass }`). The slots, order
151
158
  and ownership rules of recipe 52 are unchanged; an effect gives `node: (input, ctx) => color` instead of `create`, and a fused snippet gives
152
- `fuse.tsl: (color, uv, ctx) => color` beside its `fuse.glsl`. `ctx.p` holds a live uniform per number or color param (so `look.post.set` does
159
+ `fuse.tsl: (color, uv, ctx) => color` beside its `fuse.glsl`. `ctx.p` holds a live uniform per number or color param (so `handle.set()` does
153
160
  not rebuild), `ctx.tsl` is three/tsl, `ctx.scenePass` the scene pass (depth: `ctx.scenePass.getTextureNode('depth')`). The effects of
154
161
  `@threedog/post-effects` run on both routes as they are. An effect that reads depth, with a GLSL pass and a TSL node in one object
155
162
  (volumetric fog, god rays): [recipe 59](59-depth-post-effects.md).
156
163
  ```js
157
- engine.look.post.add({ name: 'warmGrade', slot: 'ldr', params: { amount: 0.3 },
164
+ engine.post.add({ name: 'warmGrade', slot: 'ldr', params: { amount: 0.3 },
158
165
  node: (input, { tsl, p }) => tsl.vec4(tsl.mix(input.rgb, input.rgb.mul(tsl.vec3(1.05, 0.95, 0.8)), p.amount), input.a) });
159
- engine.look.post.set({ 'warmGrade.amount': 0.5 }); // a uniform write, no rebuild
166
+ engine.post.get('warmGrade').set({ amount: 0.5 }); // a uniform write, no rebuild
160
167
  ```
161
168
  `ldr` runs after tone mapping (display colors 0-1); something that should glow or bleed belongs in `hdr`. An effect with only `create`
162
169
  (a three.js `Pass`) stops with its name.
163
170
 
171
+ ## A consistent style
172
+ A style reads as one when every surface answers the same few questions the same way. Decide these once, in one place of `picture/`, and let materials share the answers; a
173
+ look built material by material drifts. Working example: `examples/techniques/three-looks/` (page `/technique-looks.html`), the same models three ways.
174
+
175
+ | Question | Where it lives | With |
176
+ |---|---|---|
177
+ | Where does light turn into shade, how hard, what color is the shade | the lighting model; `colorNode` runs before lighting and sees no light | three's PBR with `wrapDiffuse` / `shadowTint` in a hook; `MeshToonNodeMaterial` + `gradientMap` (`rampTexture`); `celLighting` for colored bands |
178
+ | Do shapes have lines | `hdr`, before the tone curve | `outline()`, or three's `toonOutlinePass` |
179
+ | What moves | `positionNode`; the shadow follows, `castShadowPositionNode` only when it should differ | `wind()`, any node |
180
+ | What fills the air | the scene | `scene.fog`, or `scene.fogNode = fog(color, factor)` |
181
+ | What does the tone curve do | the renderer, once | `renderer.toneMapping`; `NoToneMapping` when the colors you wrote are the colors you want |
182
+ | What is the finished picture's color | `ldr`: display colors after the tone curve, never tone-mapped again | `lut()`, `paletteLut()`, your own node; `grayscale`, `posterize`, `saturation`, `hue` from three/tsl |
183
+
184
+ ```js
185
+ import { MeshToonNodeMaterial } from 'three/webgpu';
186
+ import { rampTexture } from 'threedog';
187
+ import { celLighting } from 'threedog/tsl';
188
+ const ramp = rampTexture([0x7a84c8, 0xd0d4f0, 0xffffff]); // example colors: the light in each band, dark to light, from the game's palette; one ramp for the whole game
189
+ const mat = new MeshToonNodeMaterial({ color: 0xe08050, gradientMap: ramp });
190
+ mat.setupLightingModel = celLighting; // colored bands; a cast shadow reads the dark end of the ramp, so it is the same flat color as the side turned away
191
+ ```
192
+ three's toon alone is enough for gray bands: it reads only the red channel of `gradientMap`, and a cast shadow drops to the ambient light. Choose it when that is the picture you
193
+ want; `celLighting` when shade has a color or cast shadows belong to the bands. The ramp's width sets where bands fall, the left half being the side turned away.
194
+
195
+ **Same tools, different pictures**: a paper cut-out is two bands and no line; ink wash is a gray palette through `paletteLut` with soft fog; a neon night is a dark ramp with `bloom` and
196
+ emissive lines; a storybook is soft ramp edges (`rampTexture(ramp, soften)`) with a warm grade; a retro handheld is a four-color `paletteLut` with `posterize` before it.
197
+
198
+ **How to judge it**, at the game's real camera (`threedog shot /your-page --gpu`):
199
+ - Look at the picture in gray. Do the shapes still separate? Color cannot rescue forms that have the same value.
200
+ - Cover the object you just changed. If the rest of the frame tells you the same story about light, the style is holding; if one material looks lit by another sun, its answers differ.
201
+ - Is every shade in the frame leaning the same way? A cast shadow and a turned-away side that disagree read as two renderers.
202
+ - A flat look with soft or stair-stepped shadow edges: the shadow map is showing. Raise its resolution for the area in view, or soften the ramp a little.
203
+ - Count what the picture really holds, not what you meant: most common colors, saturation, light-dark spread (`window.techTest.measure` in the example is one way). A palette look with
204
+ many stray colors has something running after the `lut`; grain and vignette belong before it there.
205
+ - 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
+
164
207
  ## Mistakes, each with the fix
165
208
  Each block shows the mistake as a comment and the working line under it.
166
209
  ```js
@@ -230,12 +273,12 @@ engine.onFrame(() => engine.renderOnce(minimap, top)); // one extra picture pe
230
273
  import { RenderPipeline } from 'three/webgpu';
231
274
 
232
275
  // wrong: new PostProcessing(renderer) from older three examples (three 0.187 names it RenderPipeline), and a second pipeline beside the engine's
233
- console.log(engine.post.object()?.pipeline instanceof RenderPipeline); // the engine's own, once its chain is built; add effects with look.post.add
276
+ console.log(engine.post.object()?.pipeline instanceof RenderPipeline); // the engine's own, once its chain is built; add effects with engine.post.add
234
277
  ```
235
278
  Also: three's `uniform` takes a value, not a `{ value }` object, so passing it `engine.uniforms.uWind` throws; use `uniforms(engine).uWind`.
236
279
  A type mismatch never errors: look at the result (`engine.debug.view('lighting')`, `threedog shot`).
237
- Many materials, many programs: WebGPURenderer builds one program per distinct set of patch uniform objects. Materials made from one spec
238
- (`makeMaterial(role)`, the same `detail` / `lighting` options) share theirs, so a hundred stones build one; a patch you write once and pass
280
+ Many materials, many programs: WebGPURenderer builds one program per distinct set of patch uniform objects. Materials given the same
281
+ `detail` / `lighting` options through `applyEffects` share theirs, so a hundred stones build one; a patch you write once and pass
239
282
  to every material shares too, a fresh patch object per material builds one program each.
240
283
 
241
284
  ## GLSL to TSL