threedog 0.2.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (593) hide show
  1. package/CHANGELOG.md +290 -0
  2. package/README.md +9 -8
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +71 -16
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +32 -8
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +39 -18
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +45 -10
  11. package/core/Describe.js +104 -43
  12. package/core/Engine.js +183 -59
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +168 -79
  16. package/core/Inspect.js +2 -2
  17. package/core/InspectMaterials.js +85 -0
  18. package/core/InspectPerf.js +61 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/Ops.js +50 -9
  22. package/core/Random.js +9 -2
  23. package/core/Rays.js +5 -5
  24. package/core/SaveStore.js +41 -9
  25. package/core/Saves.js +71 -15
  26. package/core/Stream.js +14 -10
  27. package/core/Threads.js +26 -7
  28. package/core/UrlState.js +25 -9
  29. package/core/Views.js +9 -6
  30. package/core/actor.js +1 -1
  31. package/core/adaptive.js +93 -0
  32. package/core/assetEntry.js +22 -5
  33. package/core/assetHot.js +176 -0
  34. package/core/assetLoad.js +38 -11
  35. package/core/assetManifest.js +48 -9
  36. package/core/assetReport.js +1 -1
  37. package/core/audioRules.js +13 -11
  38. package/core/audioVoice.js +69 -42
  39. package/core/canvasBox.js +1 -2
  40. package/core/catalog.js +5 -2
  41. package/core/cells.js +62 -0
  42. package/core/checks.js +10 -8
  43. package/core/chunkStream.js +87 -0
  44. package/core/control.js +149 -0
  45. package/core/copies.js +32 -0
  46. package/core/dayTime.js +12 -6
  47. package/core/debugView.js +82 -15
  48. package/core/describeRender.js +37 -17
  49. package/core/describeText.js +41 -21
  50. package/core/engineCamera.js +32 -0
  51. package/core/errorCodes.js +438 -19
  52. package/core/errorHints.js +37 -141
  53. package/core/errors.js +31 -8
  54. package/core/events.generated.js +12 -7
  55. package/core/gameLights.js +62 -0
  56. package/core/grayMap.js +20 -0
  57. package/core/grid.js +14 -13
  58. package/core/gridLoad.js +2 -1
  59. package/core/ground.js +6 -4
  60. package/core/headlessLoad.js +55 -0
  61. package/core/holds.js +78 -50
  62. package/core/inputContext.js +11 -7
  63. package/core/inputDefaults.js +24 -21
  64. package/core/inputPad.js +1 -1
  65. package/core/inputPointer.js +1 -1
  66. package/core/inputTouch.js +2 -2
  67. package/core/lifecycle.js +48 -12
  68. package/core/lightWatch.js +6 -4
  69. package/core/look/coreParts.js +137 -30
  70. package/core/look/part.js +175 -95
  71. package/core/look/points.js +255 -0
  72. package/core/look/report.js +34 -17
  73. package/core/look/shadowPart.js +63 -0
  74. package/core/look/state.js +45 -0
  75. package/core/look/write.js +12 -28
  76. package/core/loop.js +100 -41
  77. package/core/math.js +11 -3
  78. package/core/moduleSlots.js +75 -0
  79. package/core/moduleTypes.js +73 -0
  80. package/core/modules.js +145 -27
  81. package/core/movement.js +2 -2
  82. package/core/namedModel.js +70 -0
  83. package/core/opsCheck.js +3 -3
  84. package/core/opsFail.js +15 -6
  85. package/core/opsGuard.js +4 -4
  86. package/core/opsRun.js +4 -3
  87. package/core/owned.js +168 -0
  88. package/core/page.js +2 -1
  89. package/core/params.js +30 -8
  90. package/core/plugins.js +277 -0
  91. package/core/saveApply.js +99 -17
  92. package/core/saveFiles.js +8 -6
  93. package/core/saveValues.js +46 -0
  94. package/core/saveVersions.js +20 -3
  95. package/core/scatter.js +48 -19
  96. package/core/sceneDelta.js +203 -0
  97. package/core/sceneMethods.js +35 -30
  98. package/core/screenToGround.js +1 -1
  99. package/core/services.js +27 -11
  100. package/core/session.js +28 -25
  101. package/core/shaderCost.js +78 -0
  102. package/core/shadowTypes.js +2 -1
  103. package/core/sharedPoint.js +317 -0
  104. package/core/skip.js +36 -28
  105. package/core/stackFrames.js +34 -0
  106. package/core/stacks.js +166 -0
  107. package/core/startup.js +153 -11
  108. package/core/streamSources.js +0 -11
  109. package/core/styleParts.js +63 -47
  110. package/core/targeting.js +1 -1
  111. package/core/textureBytes.js +20 -0
  112. package/core/thingExplain.js +2 -2
  113. package/core/thingOps.js +29 -6
  114. package/core/things.js +21 -11
  115. package/core/threadPure.js +7 -3
  116. package/core/threePatches.js +47 -0
  117. package/core/tier.js +21 -10
  118. package/core/time.js +236 -0
  119. package/core/uiClock.js +25 -0
  120. package/core/util.js +7 -1
  121. package/core/validate.js +65 -86
  122. package/core/wrap.js +106 -0
  123. package/docs/AI.md +87 -100
  124. package/docs/API.md +32 -28
  125. package/docs/CODEMAP.md +220 -147
  126. package/docs/COMMANDS.md +56 -35
  127. package/docs/CONVENTIONS.md +90 -28
  128. package/docs/MIGRATING-0.3.md +248 -0
  129. package/docs/MIGRATING-0.4.md +228 -0
  130. package/docs/MIGRATING-0.5.md +68 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +79 -27
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +11 -9
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/calendar.md +41 -0
  137. package/docs/api/cameraRig.md +16 -5
  138. package/docs/api/characters.md +38 -23
  139. package/docs/api/clock.md +6 -5
  140. package/docs/api/collision.md +9 -6
  141. package/docs/api/content.md +6 -4
  142. package/docs/api/dialogue.md +9 -9
  143. package/docs/api/engine.md +63 -60
  144. package/docs/api/events.md +19 -14
  145. package/docs/api/grids.md +3 -3
  146. package/docs/api/ground.md +1 -1
  147. package/docs/api/hud.md +2 -2
  148. package/docs/api/i18n.md +1 -1
  149. package/docs/api/input.md +11 -6
  150. package/docs/api/interactions.md +7 -5
  151. package/docs/api/inventory.md +17 -16
  152. package/docs/api/level.md +0 -1
  153. package/docs/api/lightPool.md +3 -1
  154. package/docs/api/music.md +1 -1
  155. package/docs/api/nav.md +3 -0
  156. package/docs/api/openWorld.md +2 -1
  157. package/docs/api/particles.md +2 -2
  158. package/docs/api/photo.md +0 -2
  159. package/docs/api/pickups.md +15 -0
  160. package/docs/api/post.md +5 -4
  161. package/docs/api/quests.md +2 -3
  162. package/docs/api/rigid.md +16 -14
  163. package/docs/api/saves.md +6 -4
  164. package/docs/api/settings.md +2 -3
  165. package/docs/api/sky.md +11 -44
  166. package/docs/api/stream.md +1 -1
  167. package/docs/api/style.md +28 -26
  168. package/docs/api/terrain.md +9 -6
  169. package/docs/api/terrainLook.md +10 -0
  170. package/docs/api/timeline.md +3 -4
  171. package/docs/api/tools.md +29 -13
  172. package/docs/api/triggers.md +5 -10
  173. package/docs/api/vegetation.md +11 -8
  174. package/docs/api/vegetationLook.md +10 -0
  175. package/docs/api/water.md +4 -20
  176. package/docs/api/weather.md +5 -15
  177. package/docs/api/weatherLook.md +10 -0
  178. package/docs/api/world.md +2 -1
  179. package/docs/recipes/01-new-game.md +48 -34
  180. package/docs/recipes/02-npc.md +24 -7
  181. package/docs/recipes/03-items-pickups.md +35 -21
  182. package/docs/recipes/04-quests.md +12 -5
  183. package/docs/recipes/05-props-bake.md +151 -15
  184. package/docs/recipes/06-clock-events.md +100 -52
  185. package/docs/recipes/07-flow-scenes-pause.md +40 -9
  186. package/docs/recipes/08-weather-sky.md +145 -36
  187. package/docs/recipes/{09-style-pack.md → 09-style.md} +101 -52
  188. package/docs/recipes/10-blender-level.md +14 -2
  189. package/docs/recipes/11-vehicles.md +64 -7
  190. package/docs/recipes/13-animation.md +14 -6
  191. package/docs/recipes/14-custom-module.md +61 -29
  192. package/docs/recipes/15-perf.md +30 -9
  193. package/docs/recipes/16-dev-bridge.md +61 -37
  194. package/docs/recipes/18-world.md +16 -6
  195. package/docs/recipes/19-shooting-picking.md +6 -6
  196. package/docs/recipes/20-content-actions-save.md +55 -17
  197. package/docs/recipes/21-camera.md +49 -16
  198. package/docs/recipes/22-shop-gold.md +3 -3
  199. package/docs/recipes/23-ops.md +16 -10
  200. package/docs/recipes/26-ui-parts.md +61 -12
  201. package/docs/recipes/27-net.md +11 -5
  202. package/docs/recipes/28-terrain.md +34 -1
  203. package/docs/recipes/29-grid.md +34 -16
  204. package/docs/recipes/30-templates.md +64 -12
  205. package/docs/recipes/31-audio.md +20 -12
  206. package/docs/recipes/32-action-game.md +35 -2
  207. package/docs/recipes/34-environment-lighting.md +26 -3
  208. package/docs/recipes/35-style-from-reference.md +88 -19
  209. package/docs/recipes/36-sky-ground-plant-looks.md +18 -18
  210. package/docs/recipes/37-terrain-look-hooks.md +3 -2
  211. package/docs/recipes/38-environment-look-hooks.md +37 -26
  212. package/docs/recipes/40-scene.md +16 -13
  213. package/docs/recipes/41-thing-registry.md +11 -7
  214. package/docs/recipes/42-terrain-shape.md +2 -2
  215. package/docs/recipes/43-shader-patches-surface-looks.md +158 -76
  216. package/docs/recipes/44-water-weather-look-hooks.md +26 -17
  217. package/docs/recipes/45-cascaded-shadows.md +16 -7
  218. package/docs/recipes/47-island-snow-backdrop.md +7 -7
  219. package/docs/recipes/48-make-material.md +11 -6
  220. package/docs/recipes/49-game-module-contract.md +30 -17
  221. package/docs/recipes/50-own-renderer.md +2 -2
  222. package/docs/recipes/51-capability-catalog.md +3 -3
  223. package/docs/recipes/52-look.md +197 -61
  224. package/docs/recipes/53-ground-up-close.md +1 -1
  225. package/docs/recipes/54-three-idioms.md +88 -0
  226. package/docs/recipes/55-mods-time-wrap.md +112 -0
  227. package/docs/recipes/56-webgpu-tsl.md +260 -0
  228. package/docs/recipes/57-control.md +65 -0
  229. package/docs/recipes/58-input.md +57 -0
  230. package/docs/recipes/59-depth-post-effects.md +83 -0
  231. package/docs/recipes/60-judge-the-picture.md +55 -0
  232. package/examples/action/.threedog/content-index.json +1 -0
  233. package/examples/action/GAMEMAP.md +17 -13
  234. package/examples/action/assets.js +8 -0
  235. package/examples/action/content/actions.js +1 -1
  236. package/examples/action/content/audio.js +5 -5
  237. package/examples/action/look.js +1 -1
  238. package/examples/action/main.js +10 -14
  239. package/examples/action/models.js +24 -23
  240. package/examples/pullable.json +111 -0
  241. package/examples/rc2d/.threedog/content-index.json +1 -0
  242. package/examples/rc2d/GAMEMAP.md +83 -0
  243. package/examples/rc2d/README.md +52 -0
  244. package/examples/rc2d/main.js +63 -0
  245. package/examples/rc2d/rc2d.js +197 -0
  246. package/examples/rc2d/shaders.js +144 -0
  247. package/examples/sheepisland/.threedog/content-index.json +1 -0
  248. package/examples/sheepisland/GAMEMAP.md +13 -11
  249. package/examples/sheepisland/assets.js +5 -0
  250. package/examples/sheepisland/main.js +17 -12
  251. package/examples/sheepisland/style/index.js +6 -6
  252. package/examples/styletest/.threedog/content-index.json +1 -0
  253. package/examples/styletest/GAMEMAP.md +15 -16
  254. package/examples/styletest/assets.js +6 -0
  255. package/examples/styletest/content/templates.js +1 -1
  256. package/examples/styletest/content/vegetation.js +1 -1
  257. package/examples/styletest/look.js +1 -1
  258. package/examples/styletest/main.js +17 -16
  259. package/examples/styletest/models.js +1 -1
  260. package/examples/styletest/params.js +3 -3
  261. package/examples/techniques/contact-shadows/README.md +92 -0
  262. package/examples/techniques/contact-shadows/contactShadows.js +51 -0
  263. package/examples/techniques/contact-shadows/main.js +53 -0
  264. package/examples/techniques/day-night-grade/README.md +86 -0
  265. package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
  266. package/examples/techniques/day-night-grade/main.js +51 -0
  267. package/examples/techniques/interior-light/README.md +103 -0
  268. package/examples/techniques/interior-light/interiorLight.js +45 -0
  269. package/examples/techniques/interior-light/main.js +124 -0
  270. package/examples/techniques/modular-building/README.md +125 -0
  271. package/examples/techniques/modular-building/kit.js +426 -0
  272. package/examples/techniques/modular-building/main.js +47 -0
  273. package/examples/techniques/night-lights/README.md +94 -0
  274. package/examples/techniques/night-lights/main.js +70 -0
  275. package/examples/techniques/night-lights/nightLights.js +91 -0
  276. package/examples/techniques/outlines-and-rim/README.md +59 -0
  277. package/examples/techniques/outlines-and-rim/main.js +84 -0
  278. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  279. package/examples/techniques/procedural-animation/README.md +77 -0
  280. package/examples/techniques/procedural-animation/creature.js +44 -0
  281. package/examples/techniques/procedural-animation/main.js +45 -0
  282. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  283. package/examples/techniques/procedural-surface/README.md +67 -0
  284. package/examples/techniques/procedural-surface/main.js +103 -0
  285. package/examples/techniques/procedural-surface/surface.js +120 -0
  286. package/examples/techniques/stylized-shading/README.md +75 -0
  287. package/examples/techniques/stylized-shading/main.js +93 -0
  288. package/examples/techniques/stylized-shading/shading.js +131 -0
  289. package/examples/techniques/sun-and-key-light/README.md +135 -0
  290. package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
  291. package/examples/techniques/sun-and-key-light/main.js +95 -0
  292. package/examples/techniques/wet-road/README.md +99 -0
  293. package/examples/techniques/wet-road/main.js +68 -0
  294. package/examples/techniques/wet-road/wetRoad.js +209 -0
  295. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  296. package/examples/webgpu-tsl/GAMEMAP.md +84 -0
  297. package/examples/webgpu-tsl/README.md +42 -0
  298. package/examples/webgpu-tsl/main.js +21 -0
  299. package/examples/webgpu-tsl/tslScene.js +75 -0
  300. package/examples/world/.threedog/content-index.json +1 -0
  301. package/examples/world/GAMEMAP.md +22 -15
  302. package/examples/world/art/humanoid.js +42 -0
  303. package/examples/world/art/index.js +11 -0
  304. package/examples/world/art/models.js +58 -0
  305. package/examples/world/art/shapes.js +9 -0
  306. package/examples/world/assets.js +6 -0
  307. package/examples/world/content/audio.js +5 -5
  308. package/examples/world/content/npcs.js +1 -1
  309. package/examples/world/content/props.js +1 -1
  310. package/examples/world/content/rules.js +1 -1
  311. package/examples/world/content/templates.js +1 -1
  312. package/examples/world/content/vegetation.js +1 -1
  313. package/examples/world/main.js +17 -13
  314. package/examples/world/style/index.js +61 -0
  315. package/examples/world/style/plugins/10-bloom.js +5 -0
  316. package/index.d.ts +44 -45
  317. package/index.js +26 -22
  318. package/llms.txt +11 -4
  319. package/modules/ambience/Ambience.js +34 -23
  320. package/modules/calendar/Calendar.js +163 -0
  321. package/modules/calendar/contract.js +21 -0
  322. package/modules/calendar/index.js +81 -0
  323. package/modules/{sky → calendar}/schedule.js +17 -16
  324. package/modules/calendar/seasons.js +55 -0
  325. package/modules/camera/FirstPersonCamera.js +6 -15
  326. package/modules/camera/FixedCamera.js +33 -15
  327. package/modules/camera/FollowCamera.js +90 -16
  328. package/modules/camera/RtsCamera.js +18 -17
  329. package/modules/camera/common.js +70 -19
  330. package/modules/camera/contract.js +17 -0
  331. package/modules/camera/projection.js +11 -24
  332. package/modules/characters/Character.js +177 -42
  333. package/modules/characters/NPC.js +87 -36
  334. package/modules/characters/assetModel.js +4 -13
  335. package/modules/characters/behaviors.js +2 -1
  336. package/modules/characters/contract.js +13 -0
  337. package/modules/characters/footsteps.js +1 -1
  338. package/modules/characters/index.js +87 -49
  339. package/modules/characters/moveHelpers.js +4 -5
  340. package/modules/characters/movers/common.js +97 -19
  341. package/modules/characters/movers/manual.js +20 -0
  342. package/modules/characters/movers/rapier.js +19 -16
  343. package/modules/characters/movers/simple.js +14 -11
  344. package/modules/characters/movers/support.js +172 -0
  345. package/modules/characters/npcAvoid.js +47 -42
  346. package/modules/characters/npcSim.js +12 -8
  347. package/modules/characters/npcView.js +44 -16
  348. package/modules/characters/pathAsync.js +7 -3
  349. package/modules/characters/playerStrings.js +4 -3
  350. package/modules/characters/proceduralRig.js +2 -1
  351. package/modules/characters/useModel.js +1 -1
  352. package/modules/characters/vehicle.contract.js +21 -0
  353. package/modules/characters/walkTo.js +21 -7
  354. package/modules/collision/Collision.js +65 -25
  355. package/modules/collision/grid.js +8 -6
  356. package/modules/content/explain.js +2 -2
  357. package/modules/content/fields.js +102 -0
  358. package/modules/content/ids.js +8 -6
  359. package/modules/content/index.js +96 -27
  360. package/modules/content/loader.js +45 -33
  361. package/modules/content/models.js +11 -40
  362. package/modules/content/packs.js +6 -5
  363. package/modules/content/parts.js +41 -0
  364. package/modules/content/props.js +16 -9
  365. package/modules/content/rules.js +58 -0
  366. package/modules/content/stages.js +80 -0
  367. package/modules/content/templates.js +121 -30
  368. package/modules/debug/DebugPanel.js +24 -17
  369. package/modules/flow/contract.js +16 -0
  370. package/modules/flow/index.js +21 -15
  371. package/modules/gameplay/Container.js +41 -32
  372. package/modules/gameplay/Containers.js +30 -15
  373. package/modules/gameplay/Dialogue.js +113 -55
  374. package/modules/gameplay/Interactions.js +193 -67
  375. package/modules/gameplay/Inventory.js +69 -73
  376. package/modules/gameplay/Quests.js +75 -39
  377. package/modules/gameplay/boxOps.js +3 -3
  378. package/modules/gameplay/dialogue.contract.js +21 -0
  379. package/modules/gameplay/dialogueBox.js +4 -2
  380. package/modules/gameplay/dialogueBubbles.js +116 -0
  381. package/modules/gameplay/interactionPrompt.js +4 -1
  382. package/modules/gameplay/interactions.contract.js +16 -0
  383. package/modules/gameplay/inventory.contract.js +23 -0
  384. package/modules/gameplay/inventoryOps.js +18 -16
  385. package/modules/gameplay/pickups.js +268 -85
  386. package/modules/gameplay/questLog.js +4 -4
  387. package/modules/gameplay/quests.contract.js +17 -0
  388. package/modules/grid/Grid.js +92 -50
  389. package/modules/grid/Layer.js +14 -13
  390. package/modules/grid/index.js +60 -36
  391. package/modules/grid/ops.js +20 -18
  392. package/modules/grid/preview.js +15 -16
  393. package/modules/grid/strings.js +12 -0
  394. package/modules/grid/tiles.js +6 -5
  395. package/modules/hlod/index.js +51 -19
  396. package/modules/hud/index.js +35 -20
  397. package/modules/hud/parts.js +20 -7
  398. package/modules/level/heightfield.js +3 -1
  399. package/modules/level/index.js +45 -20
  400. package/modules/level/nodes.js +4 -3
  401. package/modules/lights/index.js +42 -18
  402. package/modules/music/Music.js +38 -21
  403. package/modules/music/rules.js +1 -1
  404. package/modules/nav/index.js +48 -42
  405. package/modules/net/Client.js +13 -6
  406. package/modules/net/Host.js +19 -5
  407. package/modules/net/Net.js +2 -1
  408. package/modules/net/index.js +13 -8
  409. package/modules/net/sync.js +9 -8
  410. package/modules/net/transports.js +77 -27
  411. package/modules/particles/Particles.js +23 -14
  412. package/modules/particles/contract.js +17 -0
  413. package/modules/particles/effect.js +39 -11
  414. package/modules/photo/Photo.js +53 -36
  415. package/modules/rigid/RigidBodies.js +194 -32
  416. package/modules/rigid/Vehicles.js +18 -15
  417. package/modules/rigid/sync.js +62 -17
  418. package/modules/settings/Settings.js +57 -52
  419. package/modules/settings/apply.js +38 -3
  420. package/modules/settings/sections.js +5 -3
  421. package/modules/settings/strings.js +3 -2
  422. package/modules/settings/view.js +5 -3
  423. package/modules/sky/Sky.js +88 -176
  424. package/modules/sky/cascades.js +86 -25
  425. package/modules/sky/cascades.tsl.js +82 -0
  426. package/modules/sky/clouds.js +34 -19
  427. package/modules/sky/domeLayers.js +30 -15
  428. package/modules/sky/environment.js +83 -13
  429. package/modules/sky/fog.js +140 -95
  430. package/modules/sky/frame.js +112 -44
  431. package/modules/sky/look.js +22 -19
  432. package/modules/sky/lookFog.js +48 -52
  433. package/modules/sky/lookShadow.js +53 -41
  434. package/modules/sky/lookSky.js +82 -21
  435. package/modules/sky/season.js +21 -0
  436. package/modules/sky/shader.js +41 -19
  437. package/modules/sky/shadow.js +44 -20
  438. package/modules/sky/skyModule.js +45 -33
  439. package/modules/sky/tint.js +61 -0
  440. package/modules/terrain/ChunkManager.js +175 -108
  441. package/modules/terrain/chunkJob.js +1 -1
  442. package/modules/terrain/chunkQueries.js +6 -4
  443. package/modules/terrain/index.js +105 -50
  444. package/modules/terrain/look.js +83 -0
  445. package/modules/terrain/lookGround.js +21 -16
  446. package/modules/terrain/terrainDefaults.js +1 -1
  447. package/modules/terrain/terrainEdit.js +18 -20
  448. package/modules/terrain/terrainGen.js +5 -3
  449. package/modules/terrain/terrainIsland.js +5 -4
  450. package/modules/terrain/terrainShape.js +12 -12
  451. package/modules/terrain/terrainShapeMain.js +8 -7
  452. package/modules/terrain/terrainTexture.js +21 -19
  453. package/modules/timeline/Timeline.js +95 -43
  454. package/modules/timeline/Tween.js +18 -10
  455. package/modules/timeline/letterbox.js +2 -2
  456. package/modules/timeline/shots.js +5 -1
  457. package/modules/triggers/index.js +107 -76
  458. package/modules/vegetation/Vegetation.js +186 -110
  459. package/modules/vegetation/densityMap.js +62 -0
  460. package/modules/vegetation/groundChunks.js +52 -58
  461. package/modules/vegetation/index.js +32 -11
  462. package/modules/vegetation/look.js +119 -0
  463. package/modules/vegetation/lookWind.js +71 -10
  464. package/modules/vegetation/modelGeometry.js +3 -2
  465. package/modules/vegetation/nearFade.js +8 -2
  466. package/modules/water/Water.js +65 -27
  467. package/modules/water/look.js +29 -18
  468. package/modules/water/surface.js +64 -25
  469. package/modules/water/surfaceDefaults.js +3 -0
  470. package/modules/weather/Weather.js +62 -104
  471. package/modules/weather/look.js +1 -2
  472. package/modules/weather/particles.js +24 -9
  473. package/modules/weather/strings.js +2 -2
  474. package/modules/weather/weatherLook.js +135 -0
  475. package/modules/world/World.js +24 -7
  476. package/modules/world/explain.js +1 -1
  477. package/modules/world/index.js +18 -4
  478. package/modules/world/persist.js +62 -2
  479. package/modules/world/pos.js +3 -2
  480. package/modules/world/records.js +8 -6
  481. package/modules/world/sim.js +60 -20
  482. package/modules/world/simFar.js +4 -3
  483. package/modules/world/state.js +3 -2
  484. package/modules/world/thingSource.js +1 -1
  485. package/modules/world/views.js +7 -5
  486. package/package.json +7 -3
  487. package/presets.js +41 -27
  488. package/render/PostFX.js +145 -120
  489. package/render/backend.js +440 -0
  490. package/render/detail.js +120 -39
  491. package/render/effects.js +130 -38
  492. package/render/engineUniforms.js +10 -1
  493. package/render/fuse.js +5 -4
  494. package/render/fx/cloudShadow.tsl.js +16 -0
  495. package/render/fx/detail.tsl.js +66 -0
  496. package/render/fx/index.js +26 -0
  497. package/render/fx/lighting.tsl.js +28 -0
  498. package/render/fx/nodeErrors.tsl.js +68 -0
  499. package/render/fx/noise.tsl.js +12 -0
  500. package/render/fx/objectOrigin.tsl.js +42 -0
  501. package/render/fx/particles.tsl.js +139 -0
  502. package/render/fx/patchNodes.tsl.js +403 -0
  503. package/render/fx/postWebGPU.tsl.js +158 -0
  504. package/render/fx/season.tsl.js +13 -0
  505. package/render/fx/sky.tsl.js +260 -0
  506. package/render/fx/uniforms.tsl.js +67 -0
  507. package/render/fx/water.tsl.js +53 -0
  508. package/render/fx/wind.tsl.js +22 -0
  509. package/render/fxNumbers.js +36 -0
  510. package/render/hotGlsl.js +24 -0
  511. package/render/lighting.js +66 -14
  512. package/render/lights.js +223 -4
  513. package/render/lookGlow.js +139 -0
  514. package/render/lookSurface.js +99 -36
  515. package/render/materials.js +71 -52
  516. package/render/modeling.js +73 -0
  517. package/render/ownFrame.js +76 -0
  518. package/render/patches.js +311 -34
  519. package/render/postLook.js +124 -46
  520. package/render/postWebGL.js +197 -0
  521. package/render/probes.js +231 -0
  522. package/render/shaderErrors.js +154 -0
  523. package/render/slots.js +165 -0
  524. package/render/surface.js +53 -17
  525. package/render/terms.js +211 -0
  526. package/render/uniformDecl.js +3 -2
  527. package/types/common.d.ts +2 -2
  528. package/types/core.d.ts +614 -240
  529. package/types/gameplay.d.ts +482 -312
  530. package/types/generated/core/Audio.d.ts +26 -42
  531. package/types/generated/core/Batching.d.ts +6 -2
  532. package/types/generated/core/Budget.d.ts +2 -8
  533. package/types/generated/core/DebugOverrides.d.ts +44 -3
  534. package/types/generated/core/I18n.d.ts +2 -2
  535. package/types/generated/core/Input.d.ts +102 -31
  536. package/types/generated/core/Ops.d.ts +31 -0
  537. package/types/generated/core/Random.d.ts +2 -2
  538. package/types/generated/core/Saves.d.ts +10 -2
  539. package/types/generated/core/Stream.d.ts +1 -1
  540. package/types/generated/core/Threads.d.ts +4 -1
  541. package/types/generated/core/Views.d.ts +0 -1
  542. package/types/generated/core/audioVoice.d.ts +17 -9
  543. package/types/generated/core/control.d.ts +55 -0
  544. package/types/generated/core/session.d.ts +2 -1
  545. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  546. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  547. package/types/generated/modules/calendar/index.d.ts +10 -0
  548. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  549. package/types/generated/modules/grid/Grid.d.ts +61 -25
  550. package/types/generated/modules/grid/Layer.d.ts +5 -5
  551. package/types/generated/modules/grid/index.d.ts +29 -17
  552. package/types/generated/modules/music/Music.d.ts +5 -3
  553. package/types/generated/modules/net/index.d.ts +3 -3
  554. package/types/generated/modules/net/transports.d.ts +12 -3
  555. package/types/generated/modules/particles/Particles.d.ts +1 -1
  556. package/types/generated/modules/sky/Sky.d.ts +12 -104
  557. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  558. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  559. package/types/generated/modules/weather/Weather.d.ts +17 -18
  560. package/types/generated/modules/weather/weatherLook.d.ts +12 -0
  561. package/types/generated/modules/world/World.d.ts +18 -3
  562. package/types/generated/render/PostFX.d.ts +67 -30
  563. package/types/generated/render/materials.d.ts +26 -20
  564. package/types/generated/render/modeling.d.ts +30 -0
  565. package/types/generated/render/patches.d.ts +16 -2
  566. package/types/generated/ui/UI.d.ts +6 -3
  567. package/types/nav.d.ts +6 -0
  568. package/types/physics.d.ts +137 -44
  569. package/types/style.d.ts +109 -81
  570. package/types/tsl.d.ts +86 -0
  571. package/types/world.d.ts +158 -110
  572. package/ui/Focus.js +25 -14
  573. package/ui/LoadingScreen.js +1 -1
  574. package/ui/Parts.js +27 -11
  575. package/ui/UI.js +20 -10
  576. package/ui/cursor.js +115 -0
  577. package/ui/defaults.js +15 -11
  578. package/ui/theme.js +9 -6
  579. package/ui/touchPart.js +1 -1
  580. package/core/claims.js +0 -51
  581. package/core/look/layers.js +0 -136
  582. package/core/renamed.js +0 -22
  583. package/docs/api/entities.md +0 -61
  584. package/examples/styletest/overrides.js +0 -33
  585. package/examples/styletest/panel.js +0 -135
  586. package/modules/entities/Entities.js +0 -243
  587. package/modules/entities/build.js +0 -25
  588. package/modules/entities/index.js +0 -4
  589. package/modules/sky/calendar.js +0 -80
  590. package/modules/sky/layers.js +0 -69
  591. package/modules/terrain/chunkLevels.js +0 -40
  592. package/modules/terrain/mountTerrain.js +0 -32
  593. package/modules/world/cells.js +0 -42
@@ -1,18 +1,37 @@
1
1
  # Writing shader patches and surface looks
2
2
 
3
- The default surface is flat: `lambert` plus vertex colors. This page is the three exits for changing that, from simplest to most open:
4
- **1. parameters** in the material spec (nothing changes until you write them), **2. a named patch or GLSL snippet** you write, **3. your own
5
- material** (a function or instance). Use the first that does the job.
3
+ **In this recipe**: Your own material · Material roles are open · Patch a slot · Shortcut: spec keys that wire the functions
4
+
5
+ Lead with three.js: **write your own material or `ShaderMaterial`**, or **patch a slot** of any material with your own GLSL. The look is the
6
+ game's own; this page gives building blocks, not looks.
7
+
8
+ ```js
9
+ const fragmentShader = '#include <threedog_lighting>\n' + myFragmentBody; // 3. engine GLSL, called inside 1 or 2
10
+ const mat = new THREE.ShaderMaterial({ uniforms: { ...engine.uniforms }, vertexShader, fragmentShader }); // 1. your own shader
11
+ applyEffects(mat2, { patches: [{ name: 'tint', slot: 'color', glsl: 'diffuseColor.rgb *= 0.9;' }] }); // 2. patch a slot
12
+ ```
13
+
14
+ **1. Your own material or shader** works exactly as in three.js (`new THREE.MeshStandardMaterial`, `ShaderMaterial`, `onBeforeCompile`), as a
15
+ material role too (below). **2. Patch a slot**: a named piece of GLSL at a named place (`color`, `normal`, `lighting`, `output`...) on any material,
16
+ built-in or yours. **3. Engine GLSL functions** (`#include <threedog_wind>`, `<threedog_detail>`, `<threedog_lighting>`...) are tools you call inside 1 and 2:
17
+ a noise, a wrapped diffuse term, a fresnel edge. None of them is a look. A look is what your game's own shader or style combines: its colors,
18
+ textures, light model and post. The default surface is flat (`lambert` plus vertex colors) until you write one. A few spec keys wire one function
19
+ into a built-in material as a shortcut (last section); reach for them only when they already say what you want.
20
+
21
+ ## Your own material
22
+ A `materials` entry that is a Material instance (cloned per use, its patches kept) or a function returning one; `style.lighting` still shapes plain three.js
23
+ lit materials returned by it. Nothing else is applied: textures, `detail` and `lighting` keys are only read on specs, so call `applyEffects(material,
24
+ { detail, patches })` yourself when you want those tools. Outside a role, `new THREE.*Material` anywhere is fine (THREE.md).
6
25
 
7
26
  ## Material roles are open
8
27
  `style.materials` maps a role name to a material. The engine asks for `default terrain vegetation character water pickup prop`; **any other
9
28
  name is fine** (`cloth`, `metal`, `glass`): code asks for it with `engine.makeMaterial('cloth', { color })`, an unlisted role uses `materials.default`.
10
29
  Only a name very close to an existing one (`props`, `charcter`) warns, as a probable typo.
11
30
 
12
- ```js
31
+ ```js fragment
13
32
  materials: {
14
33
  default: { type: 'lambert' },
15
- cloth: { type: 'standard', roughness: 1, detail: { noise: 'grain', projection: 'triplanar', scale: 3, normal: 0.01 } },
34
+ cloth: { type: 'standard', roughness: 1, color: 0x8a6f5a },
16
35
  glass: { type: 'physical', transmission: 1, roughness: 0.05, thickness: 0.2 },
17
36
  rock: { type: 'standard', map: 'rock.png', normalMap: 'rock_n.png', roughnessMap: 'rock_r.png', repeat: 4 },
18
37
  prop: (params, purpose, engine) => new THREE.MeshMatcapMaterial({ matcap: texture, color: params.color }), // any Material
@@ -22,80 +41,91 @@ A **function** gets `(params, purpose, engine)`: the call's `params` (color, ver
22
41
  three.js Material. A **spec** is plain data (`type: lambert | phong | standard | physical | toon | basic` plus material properties), layered over
23
42
  `materials.default` when that is a spec too; keys the material has are set, spec keys below are handled by the engine.
24
43
 
25
- ## Exit 1: parameters in the spec
26
- The accepted spec keys, texture slots, `repeat` / `wrap` and who wins between pack and call: recipe 48. How texture names load: the engine
27
- fetches the asset with `engine.assets.texture` (`map`, `emissiveMap` sRGB, the other slots linear), sets anisotropy, wrap and repeat, and a neutral
28
- stand-in (flat normal, white) sits in the slot until the image arrives. `style check` verifies the names against the asset pack. This page
29
- covers the keys that add shader code: `detail`, `lighting`, toon `ramp`, seasons.
30
-
31
- **`detail`**: a noise pattern, a texture or your own GLSL laid over the surface in world space (needs no UVs). Off unless written; every number is a uniform, so
32
- 100 materials with different `scale` / `strength` / `direction` compile **one** program (tested: 8 variants, +0 programs).
33
-
34
- | key | meaning |
35
- |---|---|
36
- | `noise` | `'grain'` (default) `'paper'` `'stroke'` `'dabs'` (soft oval dabs, no direction); or `texture: 'name'` (asset name or a Texture), or `glsl` (below) |
37
- | `projection` | `'world'` top-down (default, fine for ground) or `'triplanar'` (walls, rocks, characters) |
38
- | `scale` `strength` | repeats per meter (0.25), color effect 0-1 (0.35) |
39
- | `mode` `tint` | `'multiply'` (default) `'add'` `'mix'`; tint colors the sample |
40
- | `direction` `stretch` | degrees; stretch along it (strokes default 6): a brush stroke is `{ noise: 'stroke', direction: 20 }` |
41
- | `octaves` | 1-4 noise layers (2) |
42
- | `normal` | relief height in meters (bumps the normal; 0 = off) |
43
- | `roughness` | amount the sample moves roughness (`standard` / `physical`) |
44
- | `fade` | default `true`: the effect fades out where its pattern is smaller than a pixel (far, grazing), so it does not shimmer; `false` keeps it |
45
-
46
- Which channels (color, normal, roughness) are on is fixed when the material is made (it is part of the program); the numbers can change any time.
47
- The ground takes the same object as `style.terrain.detail` / `look.ground.set({ detail })`; which detail suits which ground: recipe 53.
48
-
49
- **`lighting`** shapes the light after it is summed. three has no "shadow color": a shadow only removes the sun's light. The patch reads the first
50
- directional light (the sun; three sorts shadow casters first) and its shadow value for the pixel:
51
-
52
- | key | effect |
53
- |---|---|
54
- | `shadowTint: { color, strength, soft }` | shadowed or sun-averted parts shift hue towards `color`, same brightness. `soft` = terminator width |
55
- | `rim: { color, strength, power, shadowSide }` | fresnel edge light added to the ambient part; `shadowSide: 1` = only away from the sun (a cool back light) |
56
- | `wrap` | half-lambert: `(n.l + wrap) / (1 + wrap)` from the sun |
57
-
58
- Limits: one directional light; point and spot lights are untouched; cloud shadows do not count as shadow for `shadowTint`; `wrap` does not follow a toon
59
- ramp. Put it on every lit material of the pack with `style.lighting` (same keys; a material's own `lighting` wins, `lighting: false` opts out).
60
- **Toon** takes `ramp: [0.3, 0.65, 1]` (grays = light strength per band) or colors (a cool band in the shade), `soften: 0..1` melts the bands; `steps` still works.
61
-
62
- **Seasons**: `style.seasons: { mode: 'mix', strength: 0.5, autumn: { foliage: 0xd98a3a } }`. `multiply` (default) multiplies the color on, which turns
63
- orange-on-green muddy; `mix` moves the surface `strength` of the way to the color.
64
-
65
- ## Exit 2: your own GLSL
66
- `detail.glsl` replaces the noise: `vec4 threedogDetailSample(vec2 p)` returns `vec4(color, height 0-1)`; `p` is already scaled, turned, stretched;
44
+ ## Patch a slot: your own GLSL
45
+ `detail.glsl` (the `detail` spec key, last section) replaces the noise: `vec4 threedogDetailSample(vec2 p)` returns `vec4(color, height 0-1)`; `p` is already scaled, turned, stretched;
67
46
  `uniforms: { uCells: 6 }` (numbers, colors, arrays, textures) are in scope; `threedogDetailFootprint` is one pixel in pattern units (`fade` uses it; read it to fade your own sample). `lighting.glsl` replaces the three light effects:
68
47
  `void threedogLighting(inout ReflectedLight light, vec3 normal, vec3 viewDir, vec3 sunDir, float sunShadow, vec3 albedo)` (view space; `sunShadow` 1 lit,
69
48
  0 shadowed; change `light.directDiffuse` / `indirectDiffuse`, the lights are already summed).
70
49
 
71
- For anything else write a **named patch** and add it with `applyEffects(material, { patches: [...] })` (or in a `materials` function):
72
- ```js
50
+ For anything else write a **named patch** that names a **slot** (where the code goes) and add it with `applyEffects(material, { patches: [...] })`
51
+ (or in a `materials` function, or `look.materials.add(name, patch, { roles })`):
52
+ ```js fragment
53
+ { name: 'tint', slot: 'color', glsl: 'diffuseColor.rgb *= 0.9;' } // one slot
54
+ { name: 'sway', slot: 'position', shadow: true, glsl: 'transformed.x += sin(position.y) * 0.1;' } // moves vertices: the shadow follows
55
+ { name: 'glow', pars: 'uniform float uGlow;', uniforms: { uGlow: { value: 0.5 } },
56
+ glsl: { color: 'diffuseColor.rgb *= 0.95;', output: 'outgoingLight += uGlow * 0.1;' } } // several slots; pars = declarations
57
+ ```
58
+ The full form, with every field:
59
+ ```js fragment
73
60
  { name: 'fuzz', // one name per effect; the same name again replaces it
61
+ slot: 'color', // where the code goes (table below)
62
+ glsl: 'diffuseColor.rgb *= 1.0 - uFuzz * 0.5;',
63
+ pars: 'uniform float uFuzz;', // declarations at the top of every stage the patch touches (or { vertex, fragment })
74
64
  cacheKey: 'v1', // changes whenever the GLSL text changes, never for uniform values
75
65
  uniforms: { uFuzz: { value: 0.3 } }, // numbers live here, so materials with different values share a program
76
66
  needs: { patches: ['world'], data: ['vertexColors'] }, // 'world' gives `varying vec3 vThreedogWorld`; data = program inputs you read
77
67
  conflicts: ['wind'], // patches it cannot share a material with (checked when added)
78
- shadow: false, // true = the patch MOVES vertices, so its vertex code also runs in the shadow passes (wind does)
79
- glsl: { fragment: { pars: 'uniform float uFuzz;', // pars = declarations at the top
80
- color_fragment: 'diffuseColor.rgb *= 1.0 - uFuzz * 0.5;' } } } // chunk name -> code placed after `#include <chunk>`
68
+ shadow: false } // true = the patch MOVES vertices, so its vertex code also runs in the shadow passes (wind does)
81
69
  ```
70
+ Slots (the one table is `render/slots.js`; the engine's own wind, clouds, season, detail, lighting and cascades use the same names, and on WebGPU
71
+ the same names map to node properties through a patch's `tsl` field, recipe 56). An unknown slot throws with this list.
72
+
73
+ <!-- slots:begin (generated from render/slots.js slotTable(); threedog check R42 compares) -->
74
+ | slot | GLSL (WebGL) | WebGPU (NodeMaterial) | in scope | meaning |
75
+ |---|---|---|---|---|
76
+ | `position` | after `begin_vertex` | `positionNode` | transformed (vec3, object space, write), position, normal, uv | move vertices in object space, before skinning / instancing / the model matrix; WebGPU: the same place (the engine runs the chain before three's instancing; a game's own positionNode still applies after it) |
77
+ | `shadowPosition` | after `begin_vertex` (shadow passes) | `castShadowPositionNode` | transformed (vec3, object space, write), position | vertex code for the shadow passes only (depth / point-light distance), replacing this patch's position code there |
78
+ | `clipPosition` | after `project_vertex` | `vertexNode` | transformed, mvPosition (view space), gl_Position (clip space, write) | after projection: snap or offset on screen, or write world-space varyings |
79
+ | `map` | after `map_fragment` | `colorNode` | diffuseColor (vec4, write; the map applied, vertex colors not yet) | the base color / texture, before vertex colors and every color patch |
80
+ | `color` | after `color_fragment` | inside `setupDiffuseColor` | diffuseColor (vec4, write; map and vertex colors already applied), vUv when the material has a map | the surface (diffuse) color before lighting |
81
+ | `normal` | after `normal_fragment_maps` | inside `setupNormal` | normal (vec3, view space, write), faceDirection, vViewPosition | the shading normal (bump, detail) after normal / bump maps |
82
+ | `roughness` | after `roughnessmap_fragment` | `roughnessNode` | roughnessFactor (float, write); MeshStandard / MeshPhysical only | roughness after the roughness map |
83
+ | `emissive` | after `emissivemap_fragment` | `emissiveNode` | totalEmissiveRadiance (vec3, write), diffuseColor | emitted light after the emissive map |
84
+ | `lightsPars` | after `shadowmap_pars_fragment` | WebGL only | declarations; three's light structs, getShadow() and directionalLights[] are already declared | functions that call three's light / shadow helpers (pars goes before them); WebGPU: TSL has no declaration area: the light's direction and shadow come to the lighting slot's direct(light, ctx) hook |
85
+ | `lightingModel` | replace `lights_fragment_begin` | WebGL only | geometryPosition, geometryNormal, material, reflectedLight; your code replaces three's light loop | replace how lights are summed (one patch per material may take it); WebGPU: use the lighting slot's hooks { start, light, direct, after }, or a NodeMaterial with your own setupLightingModel |
86
+ | `lighting` | after `lights_fragment_end` | inside `setupLightingModel` | reflectedLight.directDiffuse / directSpecular / indirectDiffuse (write), normal, diffuseColor, vViewPosition | after lights are summed: cloud shadows, wrap, shadow tint, rim; WebGPU: hooks { start, light, direct, after }: light(light, ctx) returns a new color for one light before three lights the surface with it (what GLSL does by wrapping three's light info in lightsPars), direct(light, ctx) sees each light in three's loop and adds to its own sums, which join the summed light at the patch's place in the list, then its after() runs: the same order as WebGL |
87
+ | `output` | before `opaque_fragment` | inside `setupOutput` | outgoingLight (vec3, write), diffuseColor.a | the final lit color, before fog and tone mapping |
88
+ | `fogPars` | after `fog_pars_fragment` | WebGL only | declarations; fogColor and fogNear / fogFar or fogDensity are already declared (inside #ifdef USE_FOG) | fog functions that read three's fog uniforms (wrap them in #ifdef USE_FOG); WebGPU: fog on WebGPU is scene.fogNode (the sky fog kinds and look.fog hooks have a tsl form) |
89
+ | `fog` | replace `fog_fragment` | WebGL only | gl_FragColor (write, tone mapped already), fogColor, vFogDepth, fogNear / fogFar or fogDensity (inside #ifdef USE_FOG) | replace how fog mixes into the final color (one patch per material may take it); WebGPU: fog on WebGPU is scene.fogNode (the sky fog kinds and look.fog hooks have a tsl form) |
90
+ <!-- slots:end -->
91
+
92
+ Several patches in one slot run in the order added. A compile error names the patch and slot:
93
+ `[threedog] shader error in patch 'fuzz' (slot color), fragment shader: ERROR: 0:812: 'uFuz' : undeclared identifier | ...`.
94
+
95
+ **Shader hot reload (dev).** Keep GLSL in its own file and import it as text: `import fuzz from './fuzz.glsl?raw'` (also `.vert`, `.frag`, `.vs`,
96
+ `.fs`), then use it as a patch's `glsl` or a `ShaderMaterial`'s `fragmentShader` / `vertexShader`. Under `npm run dev` the vite preset serves the file
97
+ inside `// threedog:begin file=<path>` markers; saving it recompiles every material holding its text (`engine.debug.reloadGlsl`; a patch gets a new
98
+ cacheKey so the old program is not reused) without reloading the page, and a compile error names the file line:
99
+ `shader error in file shaders/fuzz.glsl:4, patch 'fuzz' (slot color)`. Text copied into your own `onBeforeCompile` closure cannot be found: the page
100
+ reloads instead. Builds get the plain text. Plain Vite equivalent: `import.meta.hot.accept('./fuzz.glsl?raw', m => { mat.fragmentShader = m.default; mat.needsUpdate = true; })`.
101
+ `MeshBasicMaterial` has no lights, so no `normal` / `lighting` slots; `lambert` has no `roughness`. A slot the material lacks throws when the patch is added.
102
+ `vThreedogWorld` is the world position (instancing and batching included); it comes from the engine's `world` patch. A patch whose GLSL reads
103
+ `vThreedogWorld` gets `world` added in front of it even without `needs` (a one-time dev note asks for the `needs: { patches: ['world'] }` line, which
104
+ says the same thing in the patch itself). Meshes with several patches stack them in one program per distinct combination.
105
+
106
+ The `normal` slot also fixes a three.js rule that surprises card and grass art: with `side: THREE.DoubleSide` three flips the normal of every back
107
+ face (`faceDirection`), so a blade or card whose normals all point up shades dark from the side you see its back. Keep the authored normal by
108
+ writing it back in the `normal` slot, e.g. `normal = normalize((viewMatrix * vec4(0.0, 1.0, 0.0, 0.0)).xyz);` (up in view space) or
109
+ `normal *= faceDirection;` (undo the flip).
110
+
82
111
  Patches on one material must agree. Each patch declares what it relies on, and a bad combination throws when it is added (or logs once at compile):
83
112
 
84
113
  | Field | Meaning | Checked |
85
114
  |---|---|---|
86
115
  | `needs.data` | Program inputs the code reads: `'instancing'`, `'instancingColor'`, `'vertexColors'`, `'skinning'`, `'batching'` | when the program compiles (console.error once per material) |
87
- | `needs.patches` | Patches it builds on, e.g. `['world']` for the `vThreedogWorld` varying (world position; `applyEffects` adds `world` itself when a patch needs it) | when added |
116
+ | `needs.patches` | Patches it builds on, e.g. `['world']` for the `vThreedogWorld` varying (world position; the engine adds `world` itself when a patch needs it or its code reads `vThreedogWorld`) | when added |
88
117
  | `conflicts` | Patch names it cannot share a material with | when added, both ways |
89
118
  | `uniforms` | A uniform name belongs to one patch; share `engine.uniforms` (`uTime`, `uWind`, `uCloud`...) instead of making your own `uTime` | when added |
90
119
  | `shadow` | Render steps: without it the color pass only; `true` also runs its vertex code in the depth (sun / spot shadows) and distance (point-light shadows) passes | - |
91
120
  | `cacheKey` | Changes whenever the GLSL text changes (defines, branches), never for uniform values; the program key joins every patch's `name=cacheKey` in order | same name + cacheKey with different code throws |
92
121
  ```js
93
122
  applyEffects(mat, { wind: 0.03, season: 'foliage', patches: [{ name: 'ripple', needs: { patches: ['world'] }, conflicts: ['wind'],
94
- glsl: { fragment: { color_fragment: 'diffuseColor.rgb *= 0.9 + 0.1 * sin(vThreedogWorld.x);' } } }] }); // throws: 'wind' and 'ripple' cannot be combined
123
+ slot: 'color', glsl: 'diffuseColor.rgb *= 0.9 + 0.1 * sin(vThreedogWorld.x);' }] }); // throws: 'wind' and 'ripple' cannot be combined
95
124
  ```
96
125
 
97
- A chunk value may be `{ before, after }`. A missing chunk throws when the patch is added (`strict`), not as a silent no-op. Chunk names in three **0.187**
98
- (read from `three/src/renderers/shaders`), in main-body order:
126
+ **Exit: raw three.js anchors** (WebGL only, plain three.js knowledge). Where no slot fits, `glsl: { vertex|fragment: { <chunk>: code } }` puts
127
+ code after `#include <chunk>` (a value may be `{ before, after, replace }`; the key `pars` is declarations at the top of that stage). A missing chunk
128
+ throws when the patch is added, not as a silent no-op. Chunk names in three **0.187** (read from `three/src/renderers/shaders`), in main-body order:
99
129
 
100
130
  | stage | chunk | what is in scope after it |
101
131
  |---|---|---|
@@ -109,27 +139,79 @@ A chunk value may be `{ before, after }`. A missing chunk throws when the patch
109
139
  | fragment | `lights_fragment_begin` ... `lights_fragment_end` | `reflectedLight.directDiffuse / indirectDiffuse / directSpecular / indirectSpecular`; after `_end` they are final |
110
140
  | fragment | `opaque_fragment` | `outgoingLight` and `gl_FragColor`; (called `output_fragment` before r154) |
111
141
 
112
- `MeshBasicMaterial` has no lights, so no `lights_*` chunks; `lambert` has no roughness chunks. `vThreedogWorld` is the world position (instancing and
113
- batching included). Meshes with several patches stack them in the order added, in one program per distinct combination.
114
-
115
- ## Exit 3: your own material
116
- A `materials` entry that is a Material instance (cloned per use, its patches kept) or a function returning one; `style.lighting` still shapes plain three.js
117
- lit materials returned by it. Nothing else is applied: textures, `detail` and `lighting` keys are only read on specs, so call `applyEffects(material,
118
- { detail, patches })` yourself.
119
-
120
- ## Three complete looks (different directions, same mechanism)
142
+ ### Engine effects in your own ShaderMaterial
121
143
  ```js
122
- const looks = {
123
- // metal, realistic PBR: a texture set does the work; a fine world-space grain moves only the roughness (smudges), not the color
124
- metal: { type: 'standard', metalness: 1, roughness: 0.35, map: 'steel.png', normalMap: 'steel_n.png', roughnessMap: 'steel_r.png', repeat: 2,
125
- detail: { noise: 'grain', projection: 'triplanar', scale: 6, strength: 0, roughness: 0.25 } },
126
- // poster, flat and unlit: no light or shadow, the color is exactly the given one; a faint grain keeps large areas from looking empty
127
- poster: { type: 'basic', detail: { noise: 'paper', scale: 2, strength: 0.12 } },
128
- // leaf, stylized: toon bands, directional strokes along the wind, cool shade, a rim on the side away from the sun
129
- leaf: { type: 'toon', ramp: [0.45, 0.8, 1], soften: 0.25, detail: { noise: 'stroke', direction: 35, scale: 1.2, strength: 0.3, mode: 'add' },
130
- lighting: { shadowTint: { color: 0x5a6fb0, strength: 0.7 }, rim: { color: 0xb8e08a, strength: 0.3, shadowSide: 1 } } },
131
- };
144
+ const mat = new THREE.ShaderMaterial({ uniforms: { ...engine.uniforms, uMine: { value: 1 } }, vertexShader, fragmentShader });
145
+ ```
146
+ The engine never patches a ShaderMaterial of yours; call its effects as functions instead (the automatic patches call the same ones):
147
+ `fragmentShader: '#include <threedog_detail>\nvoid main(){ gl_FragColor = vec4(threedogDetailNoise(vW.xz, 1, 2.0).rgb, 1.0); }'`
148
+
149
+ | include | function |
150
+ |---|---|
151
+ | `#include <threedog_uniforms>` | declares every engine uniform: `uTime`, `uWind`, `uWindFreq`, `uWindAmp`, `uCloud`, `uCloudShadow`, `uCloudScale`, `uCloudSpeed`, `uFoliageTint`, `uGroundTint`, `uFoliageMix`, `uGroundMix`, `uCover` (snow / ash cover amount alone: x foliage, y ground), `uSunDir`, `uDaylight`, `uTimeOfDay` (include once, in each stage that uses them) |
152
+ | `#include <threedog_wind>` | `vec3 threedogWind(vec3 position, vec3 origin, float amplitude)`: object-space sway offset, higher vertices sway more; `origin` is the object's world origin (its phase) |
153
+ | `#include <threedog_cloudShadow>` | `float threedogCloudShadow(vec3 worldPos)`: light factor 0-1 under the drifting clouds |
154
+ | `#include <threedog_season>` | `vec3 threedogSeason(vec3 color, int kind)`: season tint, kind 0 foliage, 1 ground |
155
+
156
+ To change the cloud shadow or the season tint on the engine's own materials (not only in your shader), replace the term: `engine.look.cloudShadow.replace({ glsl, tsl })` / `engine.look.season.replace(kind => ({ glsl, tsl }))`, or `replace(false)` to drop it (recipe 52).
157
+ | `#include <threedog_detail>` | `vec4 threedogDetailNoise(vec2 p, int kind, float octaves)`: the detail noises, kind 0 grain, 1 paper, 2 stroke, 3 dabs, returns (gray rgb, height 0-1); `vec3 threedogDetailBump(vec3 surfPos, vec3 surfNorm, float h, float k, float faceDir)`: screen-space bump. No uniforms. `p` is yours: world xz for a pattern fixed to the ground (it shrinks with distance), `gl_FragCoord.xy / 3.0` for one the same size all over the screen (3-pixel cells; device pixels, so it follows the pixel ratio) |
158
+ | `#include <threedog_lighting>` | `vec3 threedogWrapDiffuse(float nl, float wrap, vec3 lightColor, float shadow, vec3 albedo)` (light to add), `vec3 threedogShadowTint(vec3 ambient, vec3 tint, float strength, float soft, float nl, float shadow)` (the new ambient), `vec3 threedogRim(vec3 normal, vec3 viewDir, vec3 color, float strength, float power, float shadowSide, float nl)` (light to add); nl = dot(normal, sunDir), shadow 1 lit / 0 shadowed. No uniforms |
159
+
160
+ ```glsl
161
+ #include <threedog_uniforms>
162
+ #include <threedog_wind>
163
+ void main() { vec3 p = position + threedogWind(position, (modelMatrix * vec4(0, 0, 0, 1)).xyz, 0.05); gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0); }
132
164
  ```
133
- Fetch them with `engine.makeMaterial('metal')`. Check a pack with `threedog style check`; the pixel and program-count guarantees are in `tests/specs/surface.mjs`.
165
+ The `detail` and `lighting` patches on built-in materials call these same functions, so a value tuned in `look.surface` reads the same in your shader.
166
+
167
+ Combining tools into a look is per game: write it in the game's style or its own material code.
168
+ Check a pack with `threedog style check`; the pixel and program-count guarantees are in `tests/specs/surface.mjs`.
169
+
170
+ ## Shortcut: spec keys that wire the functions (`detail`, `lighting`, `ramp`)
171
+ Each key below puts one of the functions above into a built-in material, with its numbers as uniforms. They are building blocks with
172
+ fixed shapes (four noise kinds, one tint model, a band ramp), not finished looks: combine them with your own colors, textures and patches,
173
+ and when a key does not give what you want, write the shader yourself (sections above) and call the same function there.
174
+
175
+ The accepted spec keys, texture slots, `repeat` / `wrap` and who wins between pack and call: recipe 48. How texture names load: the engine
176
+ fetches the asset with `engine.assets.texture` (`map`, `emissiveMap` sRGB, the other slots linear), sets anisotropy, wrap and repeat, and a neutral
177
+ stand-in (flat normal, white) sits in the slot until the image arrives. `style check` verifies the names against the asset pack. This page
178
+ covers the keys that add shader code: `detail`, `lighting`, toon `ramp`, seasons.
179
+
180
+ **`detail`**: a noise pattern, a texture or your own GLSL laid over the surface in world space (needs no UVs). Off unless written; every number is a uniform, so
181
+ 100 materials with different `scale` / `strength` / `direction` compile **one** program on WebGL (tested: 8 variants, +0 programs).
182
+ WebGPURenderer keys its program by the patch's uniform objects instead: materials with the same `detail` / `lighting` options share one
183
+ patch object, so they share one program there too (tested: 8 materials of one role, 1 build); different numbers build one each. Sharing
184
+ means one set of values: a uniform changed on one of them changes all of that spec.
185
+
186
+ | key | meaning |
187
+ |---|---|
188
+ | `noise` | `'grain'` (default) `'paper'` `'stroke'` `'dabs'` (soft oval dabs, no direction); or `texture: 'name'` (asset name or a Texture), or `glsl` (below) |
189
+ | `projection` | `'world'` top-down (default, fine for ground), `'triplanar'` (walls, rocks, characters) or `'screen'`: on the screen pixels, so the grain is the same size near and far (illustration, print, painted looks); world and triplanar grain shrinks with distance and `fade` takes it out |
190
+ | `scale` `strength` | repeats per meter (0.25; with `'screen'` pixels per pattern cell, 2), color effect 0-1 (0.35) |
191
+ | `mode` `tint` | `'multiply'` (default) `'add'` `'mix'`; tint colors the sample |
192
+ | `direction` `stretch` | degrees; stretch along it (strokes default 6): a brush stroke is `{ noise: 'stroke', direction: 20 }` |
193
+ | `octaves` | 1-4 noise layers (2) |
194
+ | `normal` | relief height in meters (bumps the normal; 0 = off) |
195
+ | `roughness` | amount the sample moves roughness (`standard` / `physical`) |
196
+ | `fade` | default `true`: the effect fades out where its pattern is smaller than a pixel (far, grazing), so it does not shimmer; `false` keeps it |
197
+
198
+ Which channels (color, normal, roughness) are on is fixed when the material is made (it is part of the program); the numbers can change any time.
199
+ The ground takes the same object as `style.terrain.detail` / `look.ground.set({ detail })`; which detail suits which ground: recipe 53.
200
+
201
+ **`lighting`** shapes the light after it is summed. three has no "shadow color": a shadow only removes the sun's light. The patch reads the first
202
+ directional light (the sun; three sorts shadow casters first) and its shadow value for the pixel:
203
+
204
+ | key | effect |
205
+ |---|---|
206
+ | `shadowTint: { color, strength, soft }` | shadowed or sun-averted parts shift hue towards `color`, same brightness. `soft` = terminator width |
207
+ | `rim: { color, strength, power, shadowSide }` | fresnel edge light added to the ambient part; `shadowSide: 1` = only away from the sun (a cool back light) |
208
+ | `wrap` | half-lambert: `(n.l + wrap) / (1 + wrap)` from the sun |
209
+
210
+ Limits: one directional light; point and spot lights are untouched; cloud shadows do not count as shadow for `shadowTint`; `wrap` does not follow a toon
211
+ ramp. Put it on every lit material of the pack with `style.lighting` (same keys; a material's own `lighting` wins, `lighting: false` opts out).
212
+ **Toon** takes `ramp: [0.3, 0.65, 1]` (grays = light strength per band) or colors (a cool band in the shade), `soften: 0..1` melts the bands; `steps` still works.
213
+
214
+ **Seasons**: `style.seasons: { mode: 'mix', strength: 0.5, autumn: { foliage: 0xd98a3a } }`. `multiply` (default) multiplies the color on, which turns
215
+ orange-on-green muddy; `mix` moves the surface `strength` of the way to the color.
134
216
 
135
217
  To change these from code at run time (`materials`, `surface`, `ground`, `wind` look parts), see recipe 52.
@@ -1,12 +1,13 @@
1
1
  # Water and rain/snow looks: depth color, foam, reflections, particles, lightning
2
2
 
3
- For an AI that wants water or weather particles to look a way the defaults do not. Water basics are the `water()` module and `style.water` (color, opacity, waves,
4
- fresnel, normal map); lights, fog and the sky are in `38-environment-look-hooks.md`. A style that writes none of the keys below keeps the built-in
3
+ For an AI that wants water or weather particles to look a way the defaults do not. Water basics are the `water()` module (structure only: `sea`, `level`,
4
+ `flat`, `size`, `segments`, `uniforms` for the hooks) and its look `style.water` / `engine.look.water.set` (color, opacity, waves, fresnel, normal map,
5
+ shininess, specular; `water({ color })` throws naming `look.water.set`); lights, fog and the sky are in `38-environment-look-hooks.md`. A style that writes none of the keys below keeps the built-in
5
6
  shaders and pays nothing for them (`tests/specs/appearance-water.mjs`). Three exits: a parameter, a GLSL function you replace, or your own material.
6
7
  At run time the same keys go through `engine.look.water` / `engine.look.weather` (recipe 52).
7
8
 
8
9
  ## Water: depth color and crest foam (parameters)
9
- ```js
10
+ ```js fragment
10
11
  water: {
11
12
  depthColor: { shallow: 0x55ddcc, deep: 0x082040 }, // by 'view' (default): shallow looking down, deep toward the horizon
12
13
  depthColor: { shallow: 0x7fe0d0, deep: 0x0a3050, by: 'wave', curve: 1.5 }, // shallow on the crests, deep in the troughs
@@ -14,8 +15,9 @@ water: {
14
15
  }
15
16
  ```
16
17
  - `depthColor` replaces `color` (opacity stays). `'view'` is a fresnel-style blend by the view angle, `'wave'` blends by the wave height; neither
17
- needs a depth texture. `curve` bends the blend (above 1 keeps more of the shallow color).
18
- - `foam` uses the same wave height as the vertices: `start` / `end` are fractions of the peak height (`glsl.waveMax`, default 0.29) where
18
+ needs a depth texture. `curve` bends the blend (above 1 keeps more of the shallow color). A color left out is a neutral gray (light for
19
+ `shallow`, dark for `deep`): the engine picks no water color, so set both.
20
+ - `foam` uses the same wave height as the vertices: `start` / `end` are fractions of the peak height (the `wave` hook's `waveMax`, default 0.29) where
19
21
  foam begins and is full. Foam is opaque even on transparent water. All numbers are uniforms (`engine.water.material.uniforms.uFoamStart.value`).
20
22
  - **Shore foam is not built in.** An accurate foam line where water meets land needs the distance to the ground under each pixel: a depth
21
23
  pre-pass (a `DepthTexture` render target of the scene without water) or a terrain height lookup, both cost a full extra pass or a texture
@@ -27,17 +29,16 @@ water: {
27
29
 
28
30
  ## Water: replace the wave or the surface function (GLSL)
29
31
  ```js
30
- water: {
31
- uniforms: { uBands: 4, uDeep: [0.05, 0.2, 0.4] }, // numbers, colors, [x, y(, z, w)] arrays, textures; in both stages
32
- glsl: {
33
- wave: `float threedogWaterWave(vec3 p, float t) { // p = world position * waveScale, t = time * waveSpeed
32
+ // style.water: { uniforms: { uBands: 4, uDeep: [0.05, 0.2, 0.4] } } numbers, colors, [x, y(, z, w)] arrays, textures; in both stages
33
+ // the GLSL goes through the look hooks only (style.water.glsl / water({ glsl }) throw and name them):
34
+ engine.look.water.patch('wave', {
35
+ glsl: `float threedogWaterWave(vec3 p, float t) { // p = world position * waveScale, t = time * waveSpeed
34
36
  return sin(p.x * 0.5 + t) * 0.2 + sin(p.z * 0.8 - t * 1.3) * 0.1; }`, // height before waveHeight
35
37
  waveMax: 0.3, // its peak: foam and depthColor 'wave' divide by it
36
- surface: `vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time) {
38
+ });
39
+ engine.look.water.patch('surface', `vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time) {
37
40
  float b = floor(facing * uBands) / uBands; // toon bands by view angle
38
- return vec4(mix(uDeep, vec3(0.4, 0.8, 0.9), b), base.a); }`,
39
- },
40
- }
41
+ return vec4(mix(uDeep, vec3(0.4, 0.8, 0.9), b), base.a); }`);
41
42
  ```
42
43
  - `wave` replaces only the vertex motion; the rest of the built-in water stays. Copying the default
43
44
  (`modules/water/surface.js`, `WAVE`) draws pixel for pixel the same.
@@ -47,7 +48,9 @@ water: {
47
48
  - A wrong signature throws with the right one; misspelled keys warn with the near name; `threedog style check` knows these keys.
48
49
 
49
50
  ## Water: your own material (reflections, refraction)
50
- `style.water.material: (engine, { uniforms, waves, surface, normalMap }) => Material` replaces the whole water material; the engine still builds
51
+ `style.water.material: (engine, { uniforms, waves, surface, normalMap }) => Material` replaces the whole water material; at run time the same
52
+ slot is `engine.look.water.replace(fn)` (one entry: `water({ material })` throws naming it). `uniforms` already holds `style.water.uniforms`
53
+ / `water({ uniforms })`, so your material reads them like the hooks do. The engine still builds
51
54
  the meshes, snaps the sea to the focus and scrolls the normal map. Reflections and refraction are not built in (each one renders the scene a
52
55
  second time). three's `Reflector` addon works through this exit; the engine water is pre-rotated geometry, so the mirror gets the mesh's
53
56
  matrix turned into the XY plane it expects:
@@ -77,10 +80,16 @@ water: { material: () => {
77
80
  - three's `Refractor` addon (next to `Reflector`) reads `matrixWorld` as an XY plane too, so the same adapter applies (not covered by a test).
78
81
  - Tested: `tests/specs/appearance-water.mjs` renders this exact example and finds the reflected box in the mirror texture.
79
82
 
83
+ ## Water: your own meshes (three's `Water` addon, your own geometry)
84
+ The water module's material is replaceable, its meshes are not. For water drawn entirely your way, leave `water()` out and draw it in plain
85
+ three.js: the water data stays in the engine without the module. `engine.waterAt(x, z)` gives the surface height (water bodies first, then
86
+ `engine.waterLevel`), `engine.waterBodies` lists the lakes and ponds (`{ x, z, radius | hw, hd, level }`), and `water:add` / `water:remove` tell
87
+ you when one comes or goes, so swimming, buoyancy and anything else reading the water keep working.
88
+
80
89
  ## Weather particles: rain and snow parameters
81
90
  `style.weather.rain` / `snow` (left-out keys keep the built-in look):
82
91
 
83
- ```js
92
+ ```js fragment
84
93
  weather: {
85
94
  rain: { color: 0xa8b8d0, opacity: 0.6, length: 1.2, speed: 26, slant: 1.5, density: a => a * a }, // streaks; sparse in a drizzle
86
95
  // rain: { shape: 'soft', size: 10, maxSize: 6, sway: 0.3 }, // drops as soft sprites instead of streaks
@@ -92,10 +101,10 @@ weather: {
92
101
  (`size` pixels at 3 m, capped at `maxSize`; drifts `sway` meters). `speed` is the fall in m/s.
93
102
  - `density: amount => share`: how many particles show at a weather amount 0..1 (rain `a => min(1, a * 1.2)`, snow `() => 1`); opacity still
94
103
  follows the amount. `count` per system (default `weather({ particles })`, halved on low-tier devices). Coverage is `style.weather.area`.
95
- - The numbers are uniforms: `engine.weather.systems.get('rain').uniforms.uColor.value.set(0xff0000)` works at run time.
104
+ - The numbers are uniforms: `engine.weatherLook.systems.get('rain').uniforms.uColor.value.set(0xff0000)` works at run time.
96
105
 
97
106
  ## Weather particles: replace the shaders (GLSL)
98
- ```js
107
+ ```js fragment
99
108
  snow: { uniforms: { uTint: [1, 0.85, 0.9] }, glsl: { fragment: `uniform float uOpacity;
100
109
  void main(){
101
110
  vec2 d = gl_PointCoord - 0.5;
@@ -5,7 +5,7 @@ along the view into 2-4 maps (three's CSM addon): sharp near the camera, coarse
5
5
  world is bigger than one map covers well.
6
6
 
7
7
  ```js
8
- engine.use(sky({ shadow: { cascades: 3 } })); // or the style pack: style.sky.shadow.cascades
8
+ engine.use(sky({ shadow: { cascades: 3 } })); // or the style: style.sky.shadow.cascades
9
9
  engine.look.shadow.set({ cascades: 3, maxFar: 150 }); // at run time; { cascades: 1 } switches back
10
10
  ```
11
11
 
@@ -21,21 +21,30 @@ engine.look.shadow.set({ cascades: 3, maxFar: 150 }); // at run time; { ca
21
21
  follow the camera frustum and snap to whole shadow pixels themselves, so edges do not shimmer while the camera moves.
22
22
 
23
23
  ## How it works (what you can rely on)
24
- - `engine.sky.sun` stays the light the sky drives (color, intensity, direction, `sky({ sun: 'manual' })`) and is cascade 0; the other
24
+ - `engine.lights.sun` stays the light the sky drives (color, intensity, direction; `look.lights.manual('sun.intensity')` takes it) and is cascade 0; the other
25
25
  cascades are extra DirectionalLights that copy its color and intensity every frame. `engine.sky.csm` is three's CSM object (lights,
26
26
  breaks, updateFrustums()), null when off.
27
- - Lit materials (Lambert, Phong, Standard, Physical, Toon, ShaderMaterial with `lights: true` and `#include <lights_fragment_begin>`) get a
28
- named patch `csm`, added after the material's other patches; wind, cloud shadows, season, detail and lighting patches stay, and wind
29
- shadows still sway. Materials added later are picked up the next frame (the scene is walked once per frame while cascades are on).
27
+ - Built-in lit materials (Lambert, Phong, Standard, Physical, Toon), **your own `new` ones too**, get a named patch `csm`, added after the
28
+ material's other patches; wind, cloud shadows, season, detail and lighting patches stay, and wind shadows still sway. This is the one place
29
+ the engine changes a material it did not make: unpatched, a lit material is lit once by every cascade light (N times as bright, doubled
30
+ shadows). `engine.describe().owned['shadow.csm'].materials` lists your materials that got it. Materials added later are picked up the next
31
+ frame (the scene is walked once per frame while cascades are on).
32
+ - Your own `ShaderMaterial` with `lights: true` is never patched unasked: one warning names it, and `engine.look.shadow.include(mat)` opts it
33
+ in (it needs `#include <lights_fragment_begin>`, i.e. a shader built from `THREE.ShaderLib`).
30
34
  Never call `CSM.setupMaterial` yourself: it overwrites `onBeforeCompile` and drops every patch. A game patch must not replace
31
35
  `lights_fragment_begin` (it would clash with `csm`, reported when added).
32
36
  - three's `ShaderChunk` is never changed (the addon's constructor does that globally; the engine swaps the chunk per material instead).
33
37
  - With `shadow.updateEvery > 1` cascades move only on frames whose maps re-render (or when the camera jumps), so lights and maps agree.
34
- - Photo mode raises `setShadowMapSize`, which is the sun's map: the nearest cascade, where it shows most.
38
+ - Photo mode's `setShadowMapSize` (and `look.shadow.set({ mapSize })`) resizes every cascade's map, on both renderers.
39
+
40
+ On WebGPURenderer (recipe 56) the same `look.shadow.set({ cascades })` is three's
41
+ `CSMShadowNode` on `engine.lights.sun.shadow.shadowNode`: one light, so no material is patched, nothing is listed in `describe().owned`,
42
+ and `look.shadow.include(mat)` does nothing (it says so once). `engine.sky.csm` is that node (its `lights` are placeholder objects, not
43
+ lights). The cascade shadow cameras reach `lightMargin + 2 * maxFar` meters, as on WebGL.
35
44
 
36
45
  ## Costs and stalls
37
46
  - Each cascade draws the shadow casters once more (each culls to its own box; near ones see little). `engine.budget.byTag()` counts a
38
- caster once per shadow-casting light, an upper bound. In the styletest acceptance test (software renderer, relative only) 3 cascades
47
+ caster once per shadow map (each cascade, on both renderers), an upper bound. In the styletest acceptance test (software renderer, relative only) 3 cascades
39
48
  went from 1 to 3 shadow passes and roughly doubled frame time; do not expect frame rate to improve.
40
49
  - Switching cascades on, off or changing any cascade field recompiles every lit material once (a stall), and each material keeps the
41
50
  old program until it is disposed (three would otherwise reuse a stale program whose uniforms no longer update). Do it on a settings
@@ -13,7 +13,7 @@ With `shading: 'texture'` the color map is applied before the vertex colors, so
13
13
  `style.seasons: { mode: 'mix', winter: { ground: 0xeef0f2 } }` therefore whitens the textured top like the side walls (recipe 43).
14
14
 
15
15
  ## Snow that settles: `style.weather.snow.cover`
16
- ```js
16
+ ```js fragment
17
17
  weather: {
18
18
  snow: { size: 18, cover: { foliage: 0xf2f4f6, ground: 0xeef0f2, strength: 0.8 } },
19
19
  },
@@ -23,23 +23,23 @@ weather: {
23
23
  and any material with `applyEffects(m, { season: 'ground' })` follow; no extra shader pass.
24
24
  - Over a `mode: 'mix'` season the two blend into one mix; a `'multiply'` season gives way while snow lies (use `'mix'` for smooth fades).
25
25
  - Leave a part out to keep its season color (`cover: { foliage: 0xffffff }` whitens trees only). Leave `cover` out and snow is particles only.
26
- - Ash, frost or anything else: `engine.sky.modify('ash', { groundCover: 0x555555, coverAmount: 0.6 })` (one layer per owner, `null` removes).
26
+ - Ash, frost or anything else: `engine.mod('look.ground.cover', { owner: 'ash', value: { ground: 0x555555, amount: 0.6 } })` (one entry per owner, the handle's `remove()` ends it).
27
27
 
28
28
  ## Weather changes and seasons in scenarios
29
29
  - `engine.events.on('weather:change', ({ from, to }) => ...)`: once per change of name, when the blend starts (`weather.set` with the same name
30
30
  again does not fire).
31
- - `engine.applyState({ season: 'winter' })` (or `?season=winter`): jumps `sky.day` to that season's first day, time of day kept. Needs
32
- `sky({ seasons })`; a wrong name throws with the calendar's list.
31
+ - `engine.applyState({ season: 'winter' })` (or `?season=winter`): jumps `calendar.day` to that season's first day, time of day kept. Needs
32
+ `calendar({ seasons })`; a wrong name throws with the calendar's list.
33
33
 
34
34
  ## Flat backdrop: `style.sky.backdrop`
35
- ```js
35
+ ```js fragment
36
36
  sky: { backdrop: 0xefebe4 }, // one color
37
- sky: { backdrop: sky => (sky.isDay ? 0xefebe4 : 0x2c3346) }, // per frame (time of day, weather, your own state)
37
+ sky: { backdrop: ({ sky }) => (sky.isDay ? 0xefebe4 : 0x2c3346) }, // per frame (time of day, weather, your own state)
38
38
  ```
39
39
  - Hides the dome (no gradient, horizon line, sun / moon disk, stars or clouds) and sets `scene.background` to the color. A plain background
40
40
  color is not tone mapped, so what you write is what shows. `style.background` stays the color when there is no sky module.
41
41
  - The keyframes still light the world (sun, ambient, their colors).
42
42
  - Fog: in its default `'horizon'` color the fog follows the backdrop, so far things fade into it; `style.sky.fog.color` of your own wins.
43
43
  - Not together with `skybox` (both replace the dome).
44
- - To fade the backdrop toward gray in snow, read the weather in the function: `sky => new THREE.Color(0xefebe4).lerp(gray, engine.weather.current.snow * 0.3)`
44
+ - To fade the backdrop toward gray in snow, read the weather in the function: `() => new THREE.Color(0xefebe4).lerp(gray, engine.weather.current.snow * 0.3)`
45
45
  (reuse the Color objects; it runs every frame).
@@ -1,7 +1,9 @@
1
1
  # 48. `engine.makeMaterial(role, spec)`: which keys work, who wins
2
2
 
3
- `engine.makeMaterial('furniture', { color: 0x8a5a36 })` returns a normal three.js material. The **role** picks the look from the style pack
4
- (`style.materials[role]`, unlisted roles use `materials.default`); the **spec** is this call's own settings.
3
+ `engine.makeMaterial('furniture', { color: 0x8a5a36 })` returns a normal three.js material. The **role** picks the look from `engine.look.materials`,
4
+ the one entry for "what material a purpose gets": its style layer is the style's `materials` table (and a style plugin's Material), its game layer
5
+ `look.materials.set / replace` (unlisted roles use `default`); the **spec** is this call's own settings. A plain `new THREE.MeshStandardMaterial()`
6
+ needs none of this: it gets fog, cascaded shadows and cloud shadow by itself.
5
7
 
6
8
  ## Which spec keys are accepted
7
9
 
@@ -11,8 +13,11 @@
11
13
  - `type`: `'lambert' | 'phong' | 'standard' | 'physical' | 'toon' | 'basic'` (default `lambert`, or whatever the pack says).
12
14
  - Texture slots by asset name (or a `THREE.Texture`): `map`, `emissiveMap` (sRGB), `normalMap`, `roughnessMap`, `metalnessMap`, `aoMap`, `bumpMap`,
13
15
  `alphaMap`... The slot must exist on the type (`roughnessMap` needs `standard`). Plus `repeat` (number or `[x, y]`) and `wrap` (`repeat | clamp | mirror`).
14
- - `detail`: a noise (`grain`, `paper`, `stroke`, `dabs`), a texture or your own GLSL laid over the surface in world space (no UVs); its keys: recipe 43.
15
- - `lighting`: extra light shaping (shadow tint, rim, wrap, own GLSL), merged over `style.lighting`; `false` opts out (recipe 43).
16
+ Per slot: `aoMap: { texture: 'ao', channel: 1 }` (second uv set, uv1), also `repeat`, `wrap`, `colorSpace` ('srgb' | 'linear' | 'none') for that slot only.
17
+ Your own `THREE.Texture` (or one registered in code: `assets.manifest({ textures: { brick: () => makeBrick() } })`) keeps its own repeat / wrap /
18
+ colorSpace; only what the spec writes changes, and then on a copy, never your texture.
19
+ - `detail`: a shortcut that lays an engine noise, a texture or your own GLSL over the surface in world space (no UVs); its keys: recipe 43.
20
+ - `lighting`: a shortcut that adds engine light-shaping functions (or your own GLSL) after the light is summed, merged over `style.lighting`; `false` opts out (recipe 43).
16
21
  - toon only: `steps` (number of bands), or `ramp` (+ `soften`). `ramp` on a non-toon type throws.
17
22
  - A key the chosen material does not have (`roughness` on lambert) is skipped on purpose, so one spec works for any type.
18
23
  A key that looks like a typo of a real one (`roughnes`) warns once in dev with `did you mean 'roughness'?`. Nothing is ever blocked.
@@ -39,7 +44,7 @@ The result is an ordinary `THREE.Material`; edit it freely. The engine does not
39
44
  ```js
40
45
  const glass = engine.makeMaterial('window', { color: 0x9fd4ff, transparent: true, opacity: 0.35, side: THREE.DoubleSide });
41
46
  glass.depthWrite = false; // plain property edit, fine
42
- glass.onBeforeCompile = ...; // allowed, but it replaces the engine's shader patches (wind, clouds, detail, lighting) on this material
47
+ glass.onBeforeCompile = shader => { /* ... */ }; // allowed, but it replaces the engine's shader patches (wind, clouds, detail, lighting) on this material
43
48
  ```
44
49
 
45
50
  Keep `makeMaterial` as the way to *create* materials (a style swap then restyles the game, `npm run check` flags a bare `new THREE.Mesh*Material`);
@@ -67,4 +72,4 @@ engine.makeMaterial('wall', { color: 0xc9b99a, detail: { noise: 'paper' }, light
67
72
  engine.makeMaterial('character', { type: 'toon', color: 0xe8a0a0, ramp: [0.25, 0.6, 1] });
68
73
  ```
69
74
 
70
- See also: `09-style-pack.md` (writing the pack side), `43-shader-patches-surface-looks.md` (detail / lighting / patches).
75
+ See also: `09-style.md` (writing the pack side), `43-shader-patches-surface-looks.md` (detail / lighting / patches).