threedog 0.2.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (596) 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 +83 -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 +190 -57
  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 +43 -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 +128 -0
  58. package/core/gridLoad.js +20 -0
  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 +101 -37
  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 +65 -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 +89 -97
  124. package/docs/API.md +32 -28
  125. package/docs/CODEMAP.md +224 -149
  126. package/docs/COMMANDS.md +57 -34
  127. package/docs/CONVENTIONS.md +92 -30
  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 +12 -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 +41 -25
  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 +65 -62
  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 +31 -29
  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 +30 -13
  172. package/docs/api/triggers.md +5 -10
  173. package/docs/api/vegetation.md +12 -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 +71 -59
  180. package/docs/recipes/02-npc.md +46 -29
  181. package/docs/recipes/03-items-pickups.md +38 -24
  182. package/docs/recipes/04-quests.md +34 -27
  183. package/docs/recipes/05-props-bake.md +154 -18
  184. package/docs/recipes/06-clock-events.md +100 -52
  185. package/docs/recipes/07-flow-scenes-pause.md +41 -10
  186. package/docs/recipes/08-weather-sky.md +146 -37
  187. package/docs/recipes/09-style.md +218 -0
  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 +34 -10
  191. package/docs/recipes/14-custom-module.md +65 -34
  192. package/docs/recipes/15-perf.md +35 -6
  193. package/docs/recipes/16-dev-bridge.md +65 -41
  194. package/docs/recipes/18-world.md +21 -8
  195. package/docs/recipes/19-shooting-picking.md +12 -11
  196. package/docs/recipes/20-content-actions-save.md +63 -25
  197. package/docs/recipes/21-camera.md +49 -16
  198. package/docs/recipes/22-shop-gold.md +18 -18
  199. package/docs/recipes/23-ops.md +17 -11
  200. package/docs/recipes/26-ui-parts.md +61 -12
  201. package/docs/recipes/27-net.md +12 -6
  202. package/docs/recipes/28-terrain.md +35 -2
  203. package/docs/recipes/29-grid.md +71 -33
  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 +27 -4
  208. package/docs/recipes/35-style-from-reference.md +115 -51
  209. package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
  210. package/docs/recipes/37-terrain-look-hooks.md +37 -15
  211. package/docs/recipes/38-environment-look-hooks.md +64 -48
  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 +3 -3
  215. package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
  216. package/docs/recipes/44-water-weather-look-hooks.md +30 -21
  217. package/docs/recipes/45-cascaded-shadows.md +17 -8
  218. package/docs/recipes/46-blender-art-route.md +4 -4
  219. package/docs/recipes/47-island-snow-backdrop.md +11 -10
  220. package/docs/recipes/48-make-material.md +11 -6
  221. package/docs/recipes/49-game-module-contract.md +46 -33
  222. package/docs/recipes/50-own-renderer.md +2 -2
  223. package/docs/recipes/51-capability-catalog.md +4 -4
  224. package/docs/recipes/52-look.md +228 -54
  225. package/docs/recipes/53-ground-up-close.md +58 -0
  226. package/docs/recipes/54-three-idioms.md +88 -0
  227. package/docs/recipes/55-mods-time-wrap.md +112 -0
  228. package/docs/recipes/56-webgpu-tsl.md +260 -0
  229. package/docs/recipes/57-control.md +65 -0
  230. package/docs/recipes/58-input.md +57 -0
  231. package/docs/recipes/59-depth-post-effects.md +83 -0
  232. package/docs/recipes/60-judge-the-picture.md +55 -0
  233. package/examples/action/.threedog/content-index.json +1 -0
  234. package/examples/action/GAMEMAP.md +17 -13
  235. package/examples/action/assets.js +8 -0
  236. package/examples/action/content/actions.js +1 -1
  237. package/examples/action/content/audio.js +5 -5
  238. package/examples/action/look.js +1 -1
  239. package/examples/action/main.js +10 -13
  240. package/examples/action/models.js +24 -23
  241. package/examples/pullable.json +111 -0
  242. package/examples/rc2d/.threedog/content-index.json +1 -0
  243. package/examples/rc2d/GAMEMAP.md +83 -0
  244. package/examples/rc2d/README.md +52 -0
  245. package/examples/rc2d/main.js +63 -0
  246. package/examples/rc2d/rc2d.js +197 -0
  247. package/examples/rc2d/shaders.js +144 -0
  248. package/examples/sheepisland/.threedog/content-index.json +1 -0
  249. package/examples/sheepisland/GAMEMAP.md +13 -11
  250. package/examples/sheepisland/assets.js +5 -0
  251. package/examples/sheepisland/main.js +17 -12
  252. package/examples/sheepisland/style/index.js +6 -6
  253. package/examples/styletest/.threedog/content-index.json +1 -0
  254. package/examples/styletest/GAMEMAP.md +15 -16
  255. package/examples/styletest/assets.js +6 -0
  256. package/examples/styletest/content/npcs.js +1 -1
  257. package/examples/styletest/content/templates.js +1 -1
  258. package/examples/styletest/content/vegetation.js +1 -1
  259. package/examples/styletest/look.js +1 -1
  260. package/examples/styletest/main.js +18 -17
  261. package/examples/styletest/models.js +1 -1
  262. package/examples/styletest/params.js +3 -3
  263. package/examples/techniques/contact-shadows/README.md +92 -0
  264. package/examples/techniques/contact-shadows/contactShadows.js +51 -0
  265. package/examples/techniques/contact-shadows/main.js +53 -0
  266. package/examples/techniques/day-night-grade/README.md +86 -0
  267. package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
  268. package/examples/techniques/day-night-grade/main.js +51 -0
  269. package/examples/techniques/interior-light/README.md +103 -0
  270. package/examples/techniques/interior-light/interiorLight.js +45 -0
  271. package/examples/techniques/interior-light/main.js +124 -0
  272. package/examples/techniques/modular-building/README.md +125 -0
  273. package/examples/techniques/modular-building/kit.js +426 -0
  274. package/examples/techniques/modular-building/main.js +47 -0
  275. package/examples/techniques/night-lights/README.md +94 -0
  276. package/examples/techniques/night-lights/main.js +70 -0
  277. package/examples/techniques/night-lights/nightLights.js +91 -0
  278. package/examples/techniques/outlines-and-rim/README.md +59 -0
  279. package/examples/techniques/outlines-and-rim/main.js +84 -0
  280. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  281. package/examples/techniques/procedural-animation/README.md +77 -0
  282. package/examples/techniques/procedural-animation/creature.js +44 -0
  283. package/examples/techniques/procedural-animation/main.js +45 -0
  284. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  285. package/examples/techniques/procedural-surface/README.md +67 -0
  286. package/examples/techniques/procedural-surface/main.js +103 -0
  287. package/examples/techniques/procedural-surface/surface.js +120 -0
  288. package/examples/techniques/stylized-shading/README.md +75 -0
  289. package/examples/techniques/stylized-shading/main.js +93 -0
  290. package/examples/techniques/stylized-shading/shading.js +131 -0
  291. package/examples/techniques/sun-and-key-light/README.md +135 -0
  292. package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
  293. package/examples/techniques/sun-and-key-light/main.js +95 -0
  294. package/examples/techniques/wet-road/README.md +99 -0
  295. package/examples/techniques/wet-road/main.js +68 -0
  296. package/examples/techniques/wet-road/wetRoad.js +209 -0
  297. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  298. package/examples/webgpu-tsl/GAMEMAP.md +84 -0
  299. package/examples/webgpu-tsl/README.md +42 -0
  300. package/examples/webgpu-tsl/main.js +21 -0
  301. package/examples/webgpu-tsl/tslScene.js +75 -0
  302. package/examples/world/.threedog/content-index.json +1 -0
  303. package/examples/world/GAMEMAP.md +22 -15
  304. package/examples/world/art/humanoid.js +42 -0
  305. package/examples/world/art/index.js +11 -0
  306. package/examples/world/art/models.js +58 -0
  307. package/examples/world/art/shapes.js +9 -0
  308. package/examples/world/assets.js +6 -0
  309. package/examples/world/content/audio.js +5 -5
  310. package/examples/world/content/npcs.js +2 -2
  311. package/examples/world/content/props.js +1 -1
  312. package/examples/world/content/rules.js +1 -1
  313. package/examples/world/content/templates.js +1 -1
  314. package/examples/world/content/vegetation.js +1 -1
  315. package/examples/world/main.js +17 -13
  316. package/examples/world/style/index.js +61 -0
  317. package/examples/world/style/plugins/10-bloom.js +5 -0
  318. package/index.d.ts +50 -45
  319. package/index.js +27 -22
  320. package/llms.txt +20 -12
  321. package/modules/ambience/Ambience.js +34 -23
  322. package/modules/calendar/Calendar.js +163 -0
  323. package/modules/calendar/contract.js +21 -0
  324. package/modules/calendar/index.js +81 -0
  325. package/modules/{sky → calendar}/schedule.js +17 -16
  326. package/modules/calendar/seasons.js +55 -0
  327. package/modules/camera/FirstPersonCamera.js +6 -15
  328. package/modules/camera/FixedCamera.js +33 -15
  329. package/modules/camera/FollowCamera.js +90 -16
  330. package/modules/camera/RtsCamera.js +18 -17
  331. package/modules/camera/common.js +70 -19
  332. package/modules/camera/contract.js +17 -0
  333. package/modules/camera/projection.js +11 -24
  334. package/modules/characters/Character.js +196 -59
  335. package/modules/characters/NPC.js +87 -36
  336. package/modules/characters/assetModel.js +27 -8
  337. package/modules/characters/behaviors.js +2 -1
  338. package/modules/characters/contract.js +13 -0
  339. package/modules/characters/footsteps.js +1 -1
  340. package/modules/characters/index.js +87 -49
  341. package/modules/characters/moveHelpers.js +4 -5
  342. package/modules/characters/movers/common.js +97 -19
  343. package/modules/characters/movers/manual.js +20 -0
  344. package/modules/characters/movers/rapier.js +19 -16
  345. package/modules/characters/movers/simple.js +14 -11
  346. package/modules/characters/movers/support.js +172 -0
  347. package/modules/characters/npcAvoid.js +47 -42
  348. package/modules/characters/npcSim.js +12 -8
  349. package/modules/characters/npcView.js +44 -16
  350. package/modules/characters/pathAsync.js +7 -3
  351. package/modules/characters/playerStrings.js +4 -3
  352. package/modules/characters/proceduralRig.js +46 -10
  353. package/modules/characters/useModel.js +1 -1
  354. package/modules/characters/vehicle.contract.js +21 -0
  355. package/modules/characters/walkTo.js +21 -7
  356. package/modules/collision/Collision.js +65 -25
  357. package/modules/collision/grid.js +8 -6
  358. package/modules/content/explain.js +2 -2
  359. package/modules/content/fields.js +102 -0
  360. package/modules/content/ids.js +8 -6
  361. package/modules/content/index.js +97 -28
  362. package/modules/content/loader.js +45 -33
  363. package/modules/content/models.js +11 -40
  364. package/modules/content/packs.js +6 -5
  365. package/modules/content/parts.js +41 -0
  366. package/modules/content/props.js +16 -9
  367. package/modules/content/rules.js +58 -0
  368. package/modules/content/stages.js +80 -0
  369. package/modules/content/templates.js +121 -30
  370. package/modules/debug/DebugPanel.js +24 -17
  371. package/modules/flow/contract.js +16 -0
  372. package/modules/flow/index.js +21 -15
  373. package/modules/gameplay/Container.js +41 -32
  374. package/modules/gameplay/Containers.js +30 -15
  375. package/modules/gameplay/Dialogue.js +113 -55
  376. package/modules/gameplay/Interactions.js +193 -67
  377. package/modules/gameplay/Inventory.js +69 -73
  378. package/modules/gameplay/Quests.js +75 -39
  379. package/modules/gameplay/boxOps.js +3 -3
  380. package/modules/gameplay/dialogue.contract.js +21 -0
  381. package/modules/gameplay/dialogueBox.js +4 -2
  382. package/modules/gameplay/dialogueBubbles.js +116 -0
  383. package/modules/gameplay/interactionPrompt.js +4 -1
  384. package/modules/gameplay/interactions.contract.js +16 -0
  385. package/modules/gameplay/inventory.contract.js +23 -0
  386. package/modules/gameplay/inventoryOps.js +18 -16
  387. package/modules/gameplay/pickups.js +268 -85
  388. package/modules/gameplay/questLog.js +4 -4
  389. package/modules/gameplay/quests.contract.js +17 -0
  390. package/modules/grid/Grid.js +92 -50
  391. package/modules/grid/Layer.js +14 -13
  392. package/modules/grid/index.js +60 -36
  393. package/modules/grid/ops.js +20 -18
  394. package/modules/grid/preview.js +15 -16
  395. package/modules/grid/strings.js +12 -0
  396. package/modules/grid/tiles.js +6 -5
  397. package/modules/hlod/index.js +51 -19
  398. package/modules/hud/index.js +35 -20
  399. package/modules/hud/parts.js +20 -7
  400. package/modules/level/heightfield.js +3 -1
  401. package/modules/level/index.js +45 -20
  402. package/modules/level/nodes.js +4 -3
  403. package/modules/lights/index.js +42 -18
  404. package/modules/music/Music.js +38 -21
  405. package/modules/music/rules.js +1 -1
  406. package/modules/nav/index.js +48 -42
  407. package/modules/net/Client.js +13 -6
  408. package/modules/net/Host.js +19 -5
  409. package/modules/net/Net.js +2 -1
  410. package/modules/net/index.js +13 -8
  411. package/modules/net/sync.js +9 -8
  412. package/modules/net/transports.js +77 -27
  413. package/modules/particles/Particles.js +23 -14
  414. package/modules/particles/contract.js +17 -0
  415. package/modules/particles/effect.js +39 -11
  416. package/modules/photo/Photo.js +53 -36
  417. package/modules/rigid/RigidBodies.js +194 -32
  418. package/modules/rigid/Vehicles.js +18 -15
  419. package/modules/rigid/sync.js +62 -17
  420. package/modules/settings/Settings.js +57 -52
  421. package/modules/settings/apply.js +38 -3
  422. package/modules/settings/sections.js +5 -3
  423. package/modules/settings/strings.js +3 -2
  424. package/modules/settings/view.js +5 -3
  425. package/modules/sky/Sky.js +88 -176
  426. package/modules/sky/cascades.js +86 -25
  427. package/modules/sky/cascades.tsl.js +82 -0
  428. package/modules/sky/clouds.js +34 -19
  429. package/modules/sky/domeLayers.js +30 -15
  430. package/modules/sky/environment.js +83 -13
  431. package/modules/sky/fog.js +140 -95
  432. package/modules/sky/frame.js +112 -44
  433. package/modules/sky/look.js +22 -19
  434. package/modules/sky/lookFog.js +48 -52
  435. package/modules/sky/lookShadow.js +53 -41
  436. package/modules/sky/lookSky.js +82 -21
  437. package/modules/sky/season.js +21 -0
  438. package/modules/sky/shader.js +41 -19
  439. package/modules/sky/shadow.js +44 -20
  440. package/modules/sky/skyModule.js +45 -33
  441. package/modules/sky/tint.js +61 -0
  442. package/modules/terrain/ChunkManager.js +175 -108
  443. package/modules/terrain/chunkJob.js +1 -1
  444. package/modules/terrain/chunkQueries.js +6 -4
  445. package/modules/terrain/index.js +105 -50
  446. package/modules/terrain/look.js +83 -0
  447. package/modules/terrain/lookGround.js +21 -16
  448. package/modules/terrain/terrainDefaults.js +1 -1
  449. package/modules/terrain/terrainEdit.js +18 -20
  450. package/modules/terrain/terrainGen.js +5 -3
  451. package/modules/terrain/terrainIsland.js +5 -4
  452. package/modules/terrain/terrainShape.js +12 -12
  453. package/modules/terrain/terrainShapeMain.js +8 -7
  454. package/modules/terrain/terrainTexture.js +21 -19
  455. package/modules/timeline/Timeline.js +95 -43
  456. package/modules/timeline/Tween.js +18 -10
  457. package/modules/timeline/letterbox.js +2 -2
  458. package/modules/timeline/shots.js +5 -1
  459. package/modules/triggers/index.js +107 -76
  460. package/modules/vegetation/Vegetation.js +190 -102
  461. package/modules/vegetation/densityMap.js +62 -0
  462. package/modules/vegetation/groundChunks.js +52 -58
  463. package/modules/vegetation/index.js +31 -10
  464. package/modules/vegetation/look.js +119 -0
  465. package/modules/vegetation/lookWind.js +71 -10
  466. package/modules/vegetation/modelGeometry.js +3 -2
  467. package/modules/vegetation/nearFade.js +45 -0
  468. package/modules/water/Water.js +65 -27
  469. package/modules/water/look.js +29 -18
  470. package/modules/water/surface.js +64 -25
  471. package/modules/water/surfaceDefaults.js +3 -0
  472. package/modules/weather/Weather.js +62 -104
  473. package/modules/weather/look.js +1 -2
  474. package/modules/weather/particles.js +24 -9
  475. package/modules/weather/strings.js +2 -2
  476. package/modules/weather/weatherLook.js +135 -0
  477. package/modules/world/World.js +24 -7
  478. package/modules/world/explain.js +1 -1
  479. package/modules/world/index.js +18 -4
  480. package/modules/world/persist.js +62 -2
  481. package/modules/world/pos.js +3 -2
  482. package/modules/world/records.js +8 -6
  483. package/modules/world/sim.js +60 -20
  484. package/modules/world/simFar.js +4 -3
  485. package/modules/world/state.js +3 -2
  486. package/modules/world/thingSource.js +1 -1
  487. package/modules/world/views.js +7 -5
  488. package/package.json +8 -3
  489. package/presets.js +41 -27
  490. package/render/PostFX.js +145 -120
  491. package/render/backend.js +440 -0
  492. package/render/detail.js +150 -45
  493. package/render/effects.js +130 -38
  494. package/render/engineUniforms.js +10 -1
  495. package/render/fuse.js +5 -4
  496. package/render/fx/cloudShadow.tsl.js +16 -0
  497. package/render/fx/detail.tsl.js +66 -0
  498. package/render/fx/index.js +26 -0
  499. package/render/fx/lighting.tsl.js +28 -0
  500. package/render/fx/nodeErrors.tsl.js +68 -0
  501. package/render/fx/noise.tsl.js +12 -0
  502. package/render/fx/objectOrigin.tsl.js +42 -0
  503. package/render/fx/particles.tsl.js +139 -0
  504. package/render/fx/patchNodes.tsl.js +403 -0
  505. package/render/fx/postWebGPU.tsl.js +158 -0
  506. package/render/fx/season.tsl.js +13 -0
  507. package/render/fx/sky.tsl.js +260 -0
  508. package/render/fx/uniforms.tsl.js +67 -0
  509. package/render/fx/water.tsl.js +53 -0
  510. package/render/fx/wind.tsl.js +22 -0
  511. package/render/fxNumbers.js +36 -0
  512. package/render/hotGlsl.js +24 -0
  513. package/render/lighting.js +66 -14
  514. package/render/lights.js +223 -4
  515. package/render/lookGlow.js +139 -0
  516. package/render/lookSurface.js +99 -36
  517. package/render/materials.js +71 -52
  518. package/render/modeling.js +73 -0
  519. package/render/ownFrame.js +76 -0
  520. package/render/patches.js +311 -34
  521. package/render/postLook.js +124 -46
  522. package/render/postWebGL.js +197 -0
  523. package/render/probes.js +231 -0
  524. package/render/shaderErrors.js +154 -0
  525. package/render/slots.js +165 -0
  526. package/render/surface.js +53 -17
  527. package/render/terms.js +211 -0
  528. package/render/uniformDecl.js +3 -2
  529. package/types/common.d.ts +2 -2
  530. package/types/core.d.ts +620 -244
  531. package/types/gameplay.d.ts +494 -318
  532. package/types/generated/core/Audio.d.ts +26 -42
  533. package/types/generated/core/Batching.d.ts +6 -2
  534. package/types/generated/core/Budget.d.ts +2 -8
  535. package/types/generated/core/DebugOverrides.d.ts +44 -3
  536. package/types/generated/core/I18n.d.ts +2 -2
  537. package/types/generated/core/Input.d.ts +102 -31
  538. package/types/generated/core/Ops.d.ts +31 -0
  539. package/types/generated/core/Random.d.ts +2 -2
  540. package/types/generated/core/Saves.d.ts +10 -2
  541. package/types/generated/core/Stream.d.ts +1 -1
  542. package/types/generated/core/Threads.d.ts +4 -1
  543. package/types/generated/core/Views.d.ts +0 -1
  544. package/types/generated/core/audioVoice.d.ts +17 -9
  545. package/types/generated/core/control.d.ts +55 -0
  546. package/types/generated/core/session.d.ts +2 -1
  547. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  548. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  549. package/types/generated/modules/calendar/index.d.ts +10 -0
  550. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  551. package/types/generated/modules/grid/Grid.d.ts +61 -25
  552. package/types/generated/modules/grid/Layer.d.ts +5 -5
  553. package/types/generated/modules/grid/index.d.ts +29 -17
  554. package/types/generated/modules/music/Music.d.ts +5 -3
  555. package/types/generated/modules/net/index.d.ts +3 -3
  556. package/types/generated/modules/net/transports.d.ts +12 -3
  557. package/types/generated/modules/particles/Particles.d.ts +1 -1
  558. package/types/generated/modules/sky/Sky.d.ts +12 -104
  559. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  560. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  561. package/types/generated/modules/weather/Weather.d.ts +17 -18
  562. package/types/generated/modules/weather/weatherLook.d.ts +12 -0
  563. package/types/generated/modules/world/World.d.ts +18 -3
  564. package/types/generated/render/PostFX.d.ts +67 -30
  565. package/types/generated/render/materials.d.ts +26 -20
  566. package/types/generated/render/modeling.d.ts +30 -0
  567. package/types/generated/render/patches.d.ts +16 -2
  568. package/types/generated/ui/UI.d.ts +6 -3
  569. package/types/nav.d.ts +6 -0
  570. package/types/physics.d.ts +137 -44
  571. package/types/style.d.ts +125 -92
  572. package/types/tsl.d.ts +86 -0
  573. package/types/world.d.ts +164 -110
  574. package/ui/Focus.js +25 -14
  575. package/ui/LoadingScreen.js +1 -1
  576. package/ui/Parts.js +27 -11
  577. package/ui/UI.js +20 -10
  578. package/ui/cursor.js +115 -0
  579. package/ui/defaults.js +15 -11
  580. package/ui/theme.js +9 -6
  581. package/ui/touchPart.js +1 -1
  582. package/core/claims.js +0 -51
  583. package/core/look/layers.js +0 -136
  584. package/core/renamed.js +0 -21
  585. package/docs/api/entities.md +0 -61
  586. package/docs/recipes/09-style-pack.md +0 -234
  587. package/examples/styletest/overrides.js +0 -33
  588. package/examples/styletest/panel.js +0 -135
  589. package/modules/entities/Entities.js +0 -243
  590. package/modules/entities/build.js +0 -25
  591. package/modules/entities/index.js +0 -4
  592. package/modules/sky/calendar.js +0 -80
  593. package/modules/sky/layers.js +0 -69
  594. package/modules/terrain/chunkLevels.js +0 -40
  595. package/modules/terrain/mountTerrain.js +0 -32
  596. package/modules/world/cells.js +0 -42
@@ -1,18 +1,38 @@
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
- name is fine** (`wool`, `bark`, `lantern`): code asks for it with `engine.makeMaterial('wool', { color })`, an unlisted role uses `materials.default`.
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
- wool: { type: 'standard', roughness: 1, detail: { noise: 'grain', projection: 'triplanar', scale: 3, normal: 0.01 } },
34
+ cloth: { type: 'standard', roughness: 1, color: 0x8a6f5a },
35
+ glass: { type: 'physical', transmission: 1, roughness: 0.05, thickness: 0.2 },
16
36
  rock: { type: 'standard', map: 'rock.png', normalMap: 'rock_n.png', roughnessMap: 'rock_r.png', repeat: 4 },
17
37
  prop: (params, purpose, engine) => new THREE.MeshMatcapMaterial({ matcap: texture, color: params.color }), // any Material
18
38
  }
@@ -21,29 +41,162 @@ A **function** gets `(params, purpose, engine)`: the call's `params` (color, ver
21
41
  three.js Material. A **spec** is plain data (`type: lambert | phong | standard | physical | toon | basic` plus material properties), layered over
22
42
  `materials.default` when that is a spec too; keys the material has are set, spec keys below are handled by the engine.
23
43
 
24
- ## Exit 1: parameters in the spec
25
- **Texture names.** A texture slot may be an asset name (`map`, `emissiveMap` are sRGB; `normalMap roughnessMap metalnessMap aoMap bumpMap alphaMap
26
- displacementMap specularMap...` are linear). The engine loads it with `engine.assets.texture`, sets anisotropy, wrap and `repeat` (a number or `[x, y]`;
27
- `wrap: 'repeat' | 'clamp' | 'mirror'`), and a neutral stand-in (flat normal, white) sits in the slot until the image arrives. A texture object works too.
28
- A key the type lacks (`roughnessMap` on `lambert`) warns once with the type to use; a misspelled slot (`normalmap`) throws with the near name.
29
- `style check` verifies the names against the asset pack (`materials.*.map` and the other slots, `materials.*.detail.texture`).
44
+ ## Patch a slot: your own GLSL
45
+ `detail.glsl` (the `detail` spec key, last section) replaces the noise: `vec4 threedogDetailSample(vec2 p)` returns `vec4(color, height 0-1)`; `p` is already scaled, turned, stretched;
46
+ `uniforms: { uCells: 6 }` (numbers, colors, arrays, textures) are in scope; `threedogDetailFootprint` is one pixel in pattern units (`fade` uses it; read it to fade your own sample). `lighting.glsl` replaces the three light effects:
47
+ `void threedogLighting(inout ReflectedLight light, vec3 normal, vec3 viewDir, vec3 sunDir, float sunShadow, vec3 albedo)` (view space; `sunShadow` 1 lit,
48
+ 0 shadowed; change `light.directDiffuse` / `indirectDiffuse`, the lights are already summed).
49
+
50
+ For anything else write a **named patch** that names a **slot** (where the code goes) and add it with `applyEffects(material, { patches: [...] })`
51
+ (or in a `materials` function, or `look.materials.add(name, patch, { roles })`):
52
+ ```js fragment
53
+ { name: 'tint', slot: 'color', glsl: 'diffuseColor.rgb *= 0.9;' } // one slot
54
+ { name: 'sway', slot: 'position', shadow: true, glsl: 'transformed.x += sin(position.y) * 0.1;' } // moves vertices: the shadow follows
55
+ { name: 'glow', pars: 'uniform float uGlow;', uniforms: { uGlow: { value: 0.5 } },
56
+ glsl: { color: 'diffuseColor.rgb *= 0.95;', output: 'outgoingLight += uGlow * 0.1;' } } // several slots; pars = declarations
57
+ ```
58
+ The full form, with every field:
59
+ ```js fragment
60
+ { name: 'fuzz', // one name per effect; the same name again replaces it
61
+ slot: 'color', // where the code goes (table below)
62
+ glsl: 'diffuseColor.rgb *= 1.0 - uFuzz * 0.5;',
63
+ pars: 'uniform float uFuzz;', // declarations at the top of every stage the patch touches (or { vertex, fragment })
64
+ cacheKey: 'v1', // changes whenever the GLSL text changes, never for uniform values
65
+ uniforms: { uFuzz: { value: 0.3 } }, // numbers live here, so materials with different values share a program
66
+ needs: { patches: ['world'], data: ['vertexColors'] }, // 'world' gives `varying vec3 vThreedogWorld`; data = program inputs you read
67
+ conflicts: ['wind'], // patches it cannot share a material with (checked when added)
68
+ shadow: false } // true = the patch MOVES vertices, so its vertex code also runs in the shadow passes (wind does)
69
+ ```
70
+ Slots (the one table is `render/slots.js`; the engine's own wind, clouds, season, detail, lighting and cascades use the same names, and on WebGPU
71
+ the same names map to node properties through a patch's `tsl` field, recipe 56). An unknown slot throws with this list.
72
+
73
+ <!-- slots:begin (generated from render/slots.js slotTable(); threedog check R42 compares) -->
74
+ | slot | GLSL (WebGL) | WebGPU (NodeMaterial) | in scope | meaning |
75
+ |---|---|---|---|---|
76
+ | `position` | after `begin_vertex` | `positionNode` | transformed (vec3, object space, write), position, normal, uv | move vertices in object space, before skinning / instancing / the model matrix; WebGPU: the same place (the engine runs the chain before three's instancing; a game's own positionNode still applies after it) |
77
+ | `shadowPosition` | after `begin_vertex` (shadow passes) | `castShadowPositionNode` | transformed (vec3, object space, write), position | vertex code for the shadow passes only (depth / point-light distance), replacing this patch's position code there |
78
+ | `clipPosition` | after `project_vertex` | `vertexNode` | transformed, mvPosition (view space), gl_Position (clip space, write) | after projection: snap or offset on screen, or write world-space varyings |
79
+ | `map` | after `map_fragment` | `colorNode` | diffuseColor (vec4, write; the map applied, vertex colors not yet) | the base color / texture, before vertex colors and every color patch |
80
+ | `color` | after `color_fragment` | inside `setupDiffuseColor` | diffuseColor (vec4, write; map and vertex colors already applied), vUv when the material has a map | the surface (diffuse) color before lighting |
81
+ | `normal` | after `normal_fragment_maps` | inside `setupNormal` | normal (vec3, view space, write), faceDirection, vViewPosition | the shading normal (bump, detail) after normal / bump maps |
82
+ | `roughness` | after `roughnessmap_fragment` | `roughnessNode` | roughnessFactor (float, write); MeshStandard / MeshPhysical only | roughness after the roughness map |
83
+ | `emissive` | after `emissivemap_fragment` | `emissiveNode` | totalEmissiveRadiance (vec3, write), diffuseColor | emitted light after the emissive map |
84
+ | `lightsPars` | after `shadowmap_pars_fragment` | WebGL only | declarations; three's light structs, getShadow() and directionalLights[] are already declared | functions that call three's light / shadow helpers (pars goes before them); WebGPU: TSL has no declaration area: the light's direction and shadow come to the lighting slot's direct(light, ctx) hook |
85
+ | `lightingModel` | replace `lights_fragment_begin` | WebGL only | geometryPosition, geometryNormal, material, reflectedLight; your code replaces three's light loop | replace how lights are summed (one patch per material may take it); WebGPU: use the lighting slot's hooks { start, light, direct, after }, or a NodeMaterial with your own setupLightingModel |
86
+ | `lighting` | after `lights_fragment_end` | inside `setupLightingModel` | reflectedLight.directDiffuse / directSpecular / indirectDiffuse (write), normal, diffuseColor, vViewPosition | after lights are summed: cloud shadows, wrap, shadow tint, rim; WebGPU: hooks { start, light, direct, after }: light(light, ctx) returns a new color for one light before three lights the surface with it (what GLSL does by wrapping three's light info in lightsPars), direct(light, ctx) sees each light in three's loop and adds to its own sums, which join the summed light at the patch's place in the list, then its after() runs: the same order as WebGL |
87
+ | `output` | before `opaque_fragment` | inside `setupOutput` | outgoingLight (vec3, write), diffuseColor.a | the final lit color, before fog and tone mapping |
88
+ | `fogPars` | after `fog_pars_fragment` | WebGL only | declarations; fogColor and fogNear / fogFar or fogDensity are already declared (inside #ifdef USE_FOG) | fog functions that read three's fog uniforms (wrap them in #ifdef USE_FOG); WebGPU: fog on WebGPU is scene.fogNode (the sky fog kinds and look.fog hooks have a tsl form) |
89
+ | `fog` | replace `fog_fragment` | WebGL only | gl_FragColor (write, tone mapped already), fogColor, vFogDepth, fogNear / fogFar or fogDensity (inside #ifdef USE_FOG) | replace how fog mixes into the final color (one patch per material may take it); WebGPU: fog on WebGPU is scene.fogNode (the sky fog kinds and look.fog hooks have a tsl form) |
90
+ <!-- slots:end -->
91
+
92
+ Several patches in one slot run in the order added. A compile error names the patch and slot:
93
+ `[threedog] shader error in patch 'fuzz' (slot color), fragment shader: ERROR: 0:812: 'uFuz' : undeclared identifier | ...`.
94
+
95
+ **Shader hot reload (dev).** Keep GLSL in its own file and import it as text: `import fuzz from './fuzz.glsl?raw'` (also `.vert`, `.frag`, `.vs`,
96
+ `.fs`), then use it as a patch's `glsl` or a `ShaderMaterial`'s `fragmentShader` / `vertexShader`. Under `npm run dev` the vite preset serves the file
97
+ inside `// threedog:begin file=<path>` markers; saving it recompiles every material holding its text (`engine.debug.reloadGlsl`; a patch gets a new
98
+ cacheKey so the old program is not reused) without reloading the page, and a compile error names the file line:
99
+ `shader error in file shaders/fuzz.glsl:4, patch 'fuzz' (slot color)`. Text copied into your own `onBeforeCompile` closure cannot be found: the page
100
+ reloads instead. Builds get the plain text. Plain Vite equivalent: `import.meta.hot.accept('./fuzz.glsl?raw', m => { mat.fragmentShader = m.default; mat.needsUpdate = true; })`.
101
+ `MeshBasicMaterial` has no lights, so no `normal` / `lighting` slots; `lambert` has no `roughness`. A slot the material lacks throws when the patch is added.
102
+ `vThreedogWorld` is the world position (instancing and batching included); it comes from the engine's `world` patch. A patch whose GLSL reads
103
+ `vThreedogWorld` gets `world` added in front of it even without `needs` (a one-time dev note asks for the `needs: { patches: ['world'] }` line, which
104
+ says the same thing in the patch itself). Meshes with several patches stack them in one program per distinct combination.
105
+
106
+ The `normal` slot also fixes a three.js rule that surprises card and grass art: with `side: THREE.DoubleSide` three flips the normal of every back
107
+ face (`faceDirection`), so a blade or card whose normals all point up shades dark from the side you see its back. Keep the authored normal by
108
+ writing it back in the `normal` slot, e.g. `normal = normalize((viewMatrix * vec4(0.0, 1.0, 0.0, 0.0)).xyz);` (up in view space) or
109
+ `normal *= faceDirection;` (undo the flip).
110
+
111
+ Patches on one material must agree. Each patch declares what it relies on, and a bad combination throws when it is added (or logs once at compile):
112
+
113
+ | Field | Meaning | Checked |
114
+ |---|---|---|
115
+ | `needs.data` | Program inputs the code reads: `'instancing'`, `'instancingColor'`, `'vertexColors'`, `'skinning'`, `'batching'` | when the program compiles (console.error once per material) |
116
+ | `needs.patches` | Patches it builds on, e.g. `['world']` for the `vThreedogWorld` varying (world position; the engine adds `world` itself when a patch needs it or its code reads `vThreedogWorld`) | when added |
117
+ | `conflicts` | Patch names it cannot share a material with | when added, both ways |
118
+ | `uniforms` | A uniform name belongs to one patch; share `engine.uniforms` (`uTime`, `uWind`, `uCloud`...) instead of making your own `uTime` | when added |
119
+ | `shadow` | Render steps: without it the color pass only; `true` also runs its vertex code in the depth (sun / spot shadows) and distance (point-light shadows) passes | - |
120
+ | `cacheKey` | Changes whenever the GLSL text changes (defines, branches), never for uniform values; the program key joins every patch's `name=cacheKey` in order | same name + cacheKey with different code throws |
121
+ ```js
122
+ applyEffects(mat, { wind: 0.03, season: 'foliage', patches: [{ name: 'ripple', needs: { patches: ['world'] }, conflicts: ['wind'],
123
+ slot: 'color', glsl: 'diffuseColor.rgb *= 0.9 + 0.1 * sin(vThreedogWorld.x);' }] }); // throws: 'wind' and 'ripple' cannot be combined
124
+ ```
125
+
126
+ **Exit: raw three.js anchors** (WebGL only, plain three.js knowledge). Where no slot fits, `glsl: { vertex|fragment: { <chunk>: code } }` puts
127
+ code after `#include <chunk>` (a value may be `{ before, after, replace }`; the key `pars` is declarations at the top of that stage). A missing chunk
128
+ throws when the patch is added, not as a silent no-op. Chunk names in three **0.187** (read from `three/src/renderers/shaders`), in main-body order:
129
+
130
+ | stage | chunk | what is in scope after it |
131
+ |---|---|---|
132
+ | vertex | `begin_vertex` | `transformed` (object space; wind moves it here) |
133
+ | vertex | `project_vertex` | `mvPosition`, `gl_Position` |
134
+ | vertex | `worldpos_vertex` | `worldPosition` (only when shadows, env maps or transmission need it) |
135
+ | fragment | `map_fragment` `color_fragment` | `diffuseColor` (rgb after the map, then the vertex colors) |
136
+ | fragment | `roughnessmap_fragment` `metalnessmap_fragment` | `roughnessFactor`, `metalnessFactor` (standard / physical) |
137
+ | fragment | `normal_fragment_begin` `normal_fragment_maps` | `normal` (view space), `faceDirection`; `vViewPosition` = minus the view-space position |
138
+ | fragment | `emissivemap_fragment` | `totalEmissiveRadiance` |
139
+ | fragment | `lights_fragment_begin` ... `lights_fragment_end` | `reflectedLight.directDiffuse / indirectDiffuse / directSpecular / indirectSpecular`; after `_end` they are final |
140
+ | fragment | `opaque_fragment` | `outgoingLight` and `gl_FragColor`; (called `output_fragment` before r154) |
141
+
142
+ ### Engine effects in your own ShaderMaterial
143
+ ```js
144
+ const mat = new THREE.ShaderMaterial({ uniforms: { ...engine.uniforms, uMine: { value: 1 } }, vertexShader, fragmentShader });
145
+ ```
146
+ The engine never patches a ShaderMaterial of yours; call its effects as functions instead (the automatic patches call the same ones):
147
+ `fragmentShader: '#include <threedog_detail>\nvoid main(){ gl_FragColor = vec4(threedogDetailNoise(vW.xz, 1, 2.0).rgb, 1.0); }'`
148
+
149
+ | include | function |
150
+ |---|---|
151
+ | `#include <threedog_uniforms>` | declares every engine uniform: `uTime`, `uWind`, `uWindFreq`, `uWindAmp`, `uCloud`, `uCloudShadow`, `uCloudScale`, `uCloudSpeed`, `uFoliageTint`, `uGroundTint`, `uFoliageMix`, `uGroundMix`, `uCover` (snow / ash cover amount alone: x foliage, y ground), `uSunDir`, `uDaylight`, `uTimeOfDay` (include once, in each stage that uses them) |
152
+ | `#include <threedog_wind>` | `vec3 threedogWind(vec3 position, vec3 origin, float amplitude)`: object-space sway offset, higher vertices sway more; `origin` is the object's world origin (its phase) |
153
+ | `#include <threedog_cloudShadow>` | `float threedogCloudShadow(vec3 worldPos)`: light factor 0-1 under the drifting clouds |
154
+ | `#include <threedog_season>` | `vec3 threedogSeason(vec3 color, int kind)`: season tint, kind 0 foliage, 1 ground |
155
+
156
+ To change the cloud shadow or the season tint on the engine's own materials (not only in your shader), replace the term: `engine.look.cloudShadow.replace({ glsl, tsl })` / `engine.look.season.replace(kind => ({ glsl, tsl }))`, or `replace(false)` to drop it (recipe 52).
157
+ | `#include <threedog_detail>` | `vec4 threedogDetailNoise(vec2 p, int kind, float octaves)`: the detail noises, kind 0 grain, 1 paper, 2 stroke, 3 dabs, returns (gray rgb, height 0-1); `vec3 threedogDetailBump(vec3 surfPos, vec3 surfNorm, float h, float k, float faceDir)`: screen-space bump. No uniforms. `p` is yours: world xz for a pattern fixed to the ground (it shrinks with distance), `gl_FragCoord.xy / 3.0` for one the same size all over the screen (3-pixel cells; device pixels, so it follows the pixel ratio) |
158
+ | `#include <threedog_lighting>` | `vec3 threedogWrapDiffuse(float nl, float wrap, vec3 lightColor, float shadow, vec3 albedo)` (light to add), `vec3 threedogShadowTint(vec3 ambient, vec3 tint, float strength, float soft, float nl, float shadow)` (the new ambient), `vec3 threedogRim(vec3 normal, vec3 viewDir, vec3 color, float strength, float power, float shadowSide, float nl)` (light to add); nl = dot(normal, sunDir), shadow 1 lit / 0 shadowed. No uniforms |
159
+
160
+ ```glsl
161
+ #include <threedog_uniforms>
162
+ #include <threedog_wind>
163
+ void main() { vec3 p = position + threedogWind(position, (modelMatrix * vec4(0, 0, 0, 1)).xyz, 0.05); gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0); }
164
+ ```
165
+ The `detail` and `lighting` patches on built-in materials call these same functions, so a value tuned in `look.surface` reads the same in your shader.
166
+
167
+ Combining tools into a look is per game: write it in the game's style or its own material code.
168
+ Check a pack with `threedog style check`; the pixel and program-count guarantees are in `tests/specs/surface.mjs`.
30
169
 
31
- **`detail`**: grain, paper or strokes 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).
170
+ ## Shortcut: spec keys that wire the functions (`detail`, `lighting`, `ramp`)
171
+ Each key below puts one of the functions above into a built-in material, with its numbers as uniforms. They are building blocks with
172
+ fixed shapes (four noise kinds, one tint model, a band ramp), not finished looks: combine them with your own colors, textures and patches,
173
+ and when a key does not give what you want, write the shader yourself (sections above) and call the same function there.
174
+
175
+ The accepted spec keys, texture slots, `repeat` / `wrap` and who wins between pack and call: recipe 48. How texture names load: the engine
176
+ fetches the asset with `engine.assets.texture` (`map`, `emissiveMap` sRGB, the other slots linear), sets anisotropy, wrap and repeat, and a neutral
177
+ stand-in (flat normal, white) sits in the slot until the image arrives. `style check` verifies the names against the asset pack. This page
178
+ covers the keys that add shader code: `detail`, `lighting`, toon `ramp`, seasons.
179
+
180
+ **`detail`**: a noise pattern, a texture or your own GLSL laid over the surface in world space (needs no UVs). Off unless written; every number is a uniform, so
181
+ 100 materials with different `scale` / `strength` / `direction` compile **one** program on WebGL (tested: 8 variants, +0 programs).
182
+ WebGPURenderer keys its program by the patch's uniform objects instead: materials with the same `detail` / `lighting` options share one
183
+ patch object, so they share one program there too (tested: 8 materials of one role, 1 build); different numbers build one each. Sharing
184
+ means one set of values: a uniform changed on one of them changes all of that spec.
33
185
 
34
186
  | key | meaning |
35
187
  |---|---|
36
- | `noise` | `'grain'` (default) `'paper'` `'stroke'`; 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) |
188
+ | `noise` | `'grain'` (default) `'paper'` `'stroke'` `'dabs'` (soft oval dabs, no direction); or `texture: 'name'` (asset name or a Texture), or `glsl` (below) |
189
+ | `projection` | `'world'` top-down (default, fine for ground), `'triplanar'` (walls, rocks, characters) or `'screen'`: on the screen pixels, so the grain is the same size near and far (illustration, print, painted looks); world and triplanar grain shrinks with distance and `fade` takes it out |
190
+ | `scale` `strength` | repeats per meter (0.25; with `'screen'` pixels per pattern cell, 2), color effect 0-1 (0.35) |
39
191
  | `mode` `tint` | `'multiply'` (default) `'add'` `'mix'`; tint colors the sample |
40
192
  | `direction` `stretch` | degrees; stretch along it (strokes default 6): a brush stroke is `{ noise: 'stroke', direction: 20 }` |
41
193
  | `octaves` | 1-4 noise layers (2) |
42
194
  | `normal` | relief height in meters (bumps the normal; 0 = off) |
43
195
  | `roughness` | amount the sample moves roughness (`standard` / `physical`) |
196
+ | `fade` | default `true`: the effect fades out where its pattern is smaller than a pixel (far, grazing), so it does not shimmer; `false` keeps it |
44
197
 
45
198
  Which channels (color, normal, roughness) are on is fixed when the material is made (it is part of the program); the numbers can change any time.
46
- `style.terrain.detail` (`{ texture, scale, strength }`) is the same patch for the ground.
199
+ The ground takes the same object as `style.terrain.detail` / `look.ground.set({ detail })`; which detail suits which ground: recipe 53.
47
200
 
48
201
  **`lighting`** shapes the light after it is summed. three has no "shadow color": a shadow only removes the sun's light. The patch reads the first
49
202
  directional light (the sun; three sorts shadow casters first) and its shadow value for the pixel:
@@ -61,60 +214,4 @@ ramp. Put it on every lit material of the pack with `style.lighting` (same keys;
61
214
  **Seasons**: `style.seasons: { mode: 'mix', strength: 0.5, autumn: { foliage: 0xd98a3a } }`. `multiply` (default) multiplies the color on, which turns
62
215
  orange-on-green muddy; `mix` moves the surface `strength` of the way to the color.
63
216
 
64
- ## Exit 2: your own GLSL
65
- `detail.glsl` replaces the noise: `vec4 threedogDetailSample(vec2 p)` returns `vec4(color, height 0-1)`; `p` is already scaled, turned, stretched;
66
- `uniforms: { uCells: 6 }` (numbers, colors, arrays, textures) are in scope. `lighting.glsl` replaces the three light effects:
67
- `void threedogLighting(inout ReflectedLight light, vec3 normal, vec3 viewDir, vec3 sunDir, float sunShadow, vec3 albedo)` (view space; `sunShadow` 1 lit,
68
- 0 shadowed; change `light.directDiffuse` / `indirectDiffuse`, the lights are already summed).
69
-
70
- For anything else write a **named patch** and add it with `applyEffects(material, { patches: [...] })` (or in a `materials` function):
71
- ```js
72
- { name: 'fuzz', // one name per effect; the same name again replaces it
73
- cacheKey: 'v1', // changes whenever the GLSL text changes, never for uniform values
74
- uniforms: { uFuzz: { value: 0.3 } }, // numbers live here, so materials with different values share a program
75
- needs: { patches: ['world'], data: ['vertexColors'] }, // 'world' gives `varying vec3 vThreedogWorld`; data = program inputs you read
76
- conflicts: ['wind'], // patches it cannot share a material with (checked when added)
77
- shadow: false, // true = the patch MOVES vertices, so its vertex code also runs in the shadow passes (wind does)
78
- glsl: { fragment: { pars: 'uniform float uFuzz;', // pars = declarations at the top
79
- color_fragment: 'diffuseColor.rgb *= 1.0 - uFuzz * 0.5;' } } } // chunk name -> code placed after `#include <chunk>`
80
- ```
81
- A chunk value may be `{ before, after }`. A missing chunk throws when the patch is added (`strict`), not as a silent no-op. Chunk names in three **0.187**
82
- (read from `three/src/renderers/shaders`), in main-body order:
83
-
84
- | stage | chunk | what is in scope after it |
85
- |---|---|---|
86
- | vertex | `begin_vertex` | `transformed` (object space; wind moves it here) |
87
- | vertex | `project_vertex` | `mvPosition`, `gl_Position` |
88
- | vertex | `worldpos_vertex` | `worldPosition` (only when shadows, env maps or transmission need it) |
89
- | fragment | `map_fragment` `color_fragment` | `diffuseColor` (rgb after the map, then the vertex colors) |
90
- | fragment | `roughnessmap_fragment` `metalnessmap_fragment` | `roughnessFactor`, `metalnessFactor` (standard / physical) |
91
- | fragment | `normal_fragment_begin` `normal_fragment_maps` | `normal` (view space), `faceDirection`; `vViewPosition` = minus the view-space position |
92
- | fragment | `emissivemap_fragment` | `totalEmissiveRadiance` |
93
- | fragment | `lights_fragment_begin` ... `lights_fragment_end` | `reflectedLight.directDiffuse / indirectDiffuse / directSpecular / indirectSpecular`; after `_end` they are final |
94
- | fragment | `opaque_fragment` | `outgoingLight` and `gl_FragColor`; (called `output_fragment` before r154) |
95
-
96
- `MeshBasicMaterial` has no lights, so no `lights_*` chunks; `lambert` has no roughness chunks. `vThreedogWorld` is the world position (instancing and
97
- batching included). Meshes with several patches stack them in the order added, in one program per distinct combination.
98
-
99
- ## Exit 3: your own material
100
- A `materials` entry that is a Material instance (cloned per use, its patches kept) or a function returning one; `style.lighting` still shapes plain three.js
101
- lit materials returned by it. Nothing else is applied: textures, `detail` and `lighting` keys are only read on specs, so call `applyEffects(material,
102
- { detail, patches })` yourself.
103
-
104
- ## Three complete looks
105
- ```js
106
- const looks = {
107
- // wool: rough, fuzzy, soft light, a warm rim; one fine grain seen from every side
108
- wool: { type: 'standard', roughness: 1, detail: { noise: 'grain', projection: 'triplanar', scale: 4, octaves: 3, strength: 0.25, normal: 0.01 },
109
- lighting: { wrap: 0.5, rim: { color: 0xffd9a8, strength: 0.35, power: 2.5 } } },
110
- // leaves: toon bands, brush strokes along the wind, cool shade, a bit of transmitted light on the side away from the sun
111
- leaf: { type: 'toon', ramp: [0.45, 0.8, 1], soften: 0.25, detail: { noise: 'stroke', direction: 35, scale: 1.2, strength: 0.3, mode: 'add' },
112
- lighting: { shadowTint: { color: 0x5a6fb0, strength: 0.7 }, rim: { color: 0xb8e08a, strength: 0.3, shadowSide: 1 } } },
113
- // rock: a real texture set, plus a world-space grain that also roughens it
114
- rock: { type: 'standard', map: 'rock.png', normalMap: 'rock_n.png', roughnessMap: 'rock_r.png', repeat: 3,
115
- detail: { noise: 'paper', projection: 'triplanar', scale: 0.8, strength: 0.2, normal: 0.02, roughness: 0.3 } },
116
- };
117
- ```
118
- Fetch them with `engine.makeMaterial('wool')`. Check a pack with `threedog style check`; the pixel and program-count guarantees are in `tests/specs/surface.mjs`.
119
-
120
217
  To change these from code at run time (`materials`, `surface`, `ground`, `wind` look parts), see recipe 52.
@@ -1,12 +1,13 @@
1
- # Water and weather look open points: depth color, foam, reflections, rain and snow, lightning, own particles
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`. Every default below draws exactly what it drew before
5
- (checked pixel by pixel against the old shaders in `tests/specs/appearance-water.mjs`), and a style that writes none of the new keys gets the same
6
- shader text, so it pays nothing. Three exits: a parameter, a GLSL function you replace, or your own material.
3
+ For an AI that wants water or weather particles to look a way the defaults do not. Water basics are the `water()` module (structure only: `sea`, `level`,
4
+ `flat`, `size`, `segments`, `uniforms` for the hooks) and its look `style.water` / `engine.look.water.set` (color, opacity, waves, fresnel, normal map,
5
+ shininess, specular; `water({ color })` throws naming `look.water.set`); lights, fog and the sky are in `38-environment-look-hooks.md`. A style that writes none of the keys below keeps the built-in
6
+ shaders and pays nothing for them (`tests/specs/appearance-water.mjs`). Three exits: a parameter, a GLSL function you replace, or your own material.
7
+ At run time the same keys go through `engine.look.water` / `engine.look.weather` (recipe 52).
7
8
 
8
9
  ## Water: depth color and crest foam (parameters)
9
- ```js
10
+ ```js fragment
10
11
  water: {
11
12
  depthColor: { shallow: 0x55ddcc, deep: 0x082040 }, // by 'view' (default): shallow looking down, deep toward the horizon
12
13
  depthColor: { shallow: 0x7fe0d0, deep: 0x0a3050, by: 'wave', curve: 1.5 }, // shallow on the crests, deep in the troughs
@@ -14,8 +15,9 @@ water: {
14
15
  }
15
16
  ```
16
17
  - `depthColor` replaces `color` (opacity stays). `'view'` is a fresnel-style blend by the view angle, `'wave'` blends by the wave height; neither
17
- needs a depth texture. `curve` bends the blend (above 1 keeps more of the shallow color).
18
- - `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
- `style.weather.rain` / `snow` (left-out keys keep the built-in look; the defaults are pixel for pixel the old ones):
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;
@@ -1,11 +1,11 @@
1
1
  # Cascaded shadows
2
2
 
3
- Off by default: the sun casts one shadow map around the focus (`extent`, default 70 m), exactly as before. Cascades split the sun's shadow
3
+ Off by default: the sun casts one shadow map around the focus (`extent`, default 70 m). Cascades split the sun's shadow
4
4
  along the view into 2-4 maps (three's CSM addon): sharp near the camera, coarse far away. Use them when near shadows look blocky and the
5
5
  world is bigger than one map covers well.
6
6
 
7
7
  ```js
8
- engine.use(sky({ shadow: { cascades: 3 } })); // or the style 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
@@ -1,4 +1,4 @@
1
- # Hand-painted art route: from Blender to the game
1
+ # Blender to game (GLB) route
2
2
 
3
3
  Code-built geometry (`models.js`, recipe 05) is good for blockout, props and variations, but it cannot reach the finish of hand-made art: painted
4
4
  textures, baked shadows, sculpted edges. That finish comes from Blender. This page is the whole path, in order. The level naming rules live in
@@ -79,11 +79,11 @@ A whole level is `level({ url: '/models/town.glb' })` (recipe 10). Animation cli
79
79
 
80
80
  ## 5. The GLB's own materials and the style
81
81
  **The GLB keeps its own materials.** The engine loads them as they are (textures, colors, roughness) and does not swap them for style roles;
82
- that is what lets a hand-painted texture show. `style.materials` (recipe 43) applies only to what code builds through `engine.makeMaterial(role, ...)`
83
- (terrain, vegetation, procedural models, pickups). One scene can mix painted GLB props and styled code-built things.
82
+ that is what lets a painted or baked texture show. `style.materials` (recipe 43) applies only to what code builds through `engine.makeMaterial(role, ...)`
83
+ (terrain, vegetation, procedural models, pickups). One scene can mix GLB props and styled code-built things.
84
84
 
85
85
  There is no automatic mapping from a GLB material name to a style role and no flag for it. To make a GLB follow the style anyway, do it in your
86
- game code, per model: name the material in Blender after the role (`wool`, `bark`) and look it up:
86
+ game code, per model: name the material in Blender after the role (`cloth`, `metal`, `glass`) and look it up:
87
87
  ```js
88
88
  const m = await engine.assets.model('hat');
89
89
  m.traverse(o => { if (o.isMesh) o.material = engine.makeMaterial(o.material.name, { color: o.material.color.getHex() }); });
@@ -1,7 +1,8 @@
1
- # Floating island look: round rim, snow that settles, flat backdrop
1
+ # Snow cover, flat backdrop, rounded terrain rim
2
2
 
3
- A floating island scene (recipe 42 for the outline) usually wants three more things: a soft rim, trees and ground that turn white while
4
- it snows, and a plain background with no horizon. All three are style or scenario settings; none needs a shader of your own.
3
+ Three independent settings, each for its own situation: a **rounded rim** for terrain with a visible edge (an island, a diorama board, a floating
4
+ level; recipe 42 for the outline), **snow cover** for any outdoor scene where it snows, and a **flat backdrop** for a scene that should have no
5
+ horizon (a menu stage, a board game, a diorama). All are style or scenario settings; none needs a shader of your own.
5
6
 
6
7
  ## Round rim
7
8
  `terrain({ shape: { edge: { round: 1.2 } } })` bends the top down by up to 1.2 m toward the rim. The side wall follows every bend of the
@@ -12,7 +13,7 @@ With `shading: 'texture'` the color map is applied before the vertex colors, so
12
13
  `style.seasons: { mode: 'mix', winter: { ground: 0xeef0f2 } }` therefore whitens the textured top like the side walls (recipe 43).
13
14
 
14
15
  ## Snow that settles: `style.weather.snow.cover`
15
- ```js
16
+ ```js fragment
16
17
  weather: {
17
18
  snow: { size: 18, cover: { foliage: 0xf2f4f6, ground: 0xeef0f2, strength: 0.8 } },
18
19
  },
@@ -22,23 +23,23 @@ weather: {
22
23
  and any material with `applyEffects(m, { season: 'ground' })` follow; no extra shader pass.
23
24
  - Over a `mode: 'mix'` season the two blend into one mix; a `'multiply'` season gives way while snow lies (use `'mix'` for smooth fades).
24
25
  - Leave a part out to keep its season color (`cover: { foliage: 0xffffff }` whitens trees only). Leave `cover` out and snow is particles only.
25
- - Ash, frost or anything else: `engine.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).
26
27
 
27
28
  ## Weather changes and seasons in scenarios
28
29
  - `engine.events.on('weather:change', ({ from, to }) => ...)`: once per change of name, when the blend starts (`weather.set` with the same name
29
30
  again does not fire).
30
- - `engine.applyState({ season: 'winter' })` (or `?season=winter`): jumps `sky.day` to that season's first day, time of day kept. Needs
31
- `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.
32
33
 
33
34
  ## Flat backdrop: `style.sky.backdrop`
34
- ```js
35
+ ```js fragment
35
36
  sky: { backdrop: 0xefebe4 }, // one color
36
- sky: { backdrop: sky => (sky.isDay ? 0xefebe4 : 0x2c3346) }, // per frame (time of day, weather, your own state)
37
+ sky: { backdrop: ({ sky }) => (sky.isDay ? 0xefebe4 : 0x2c3346) }, // per frame (time of day, weather, your own state)
37
38
  ```
38
39
  - Hides the dome (no gradient, horizon line, sun / moon disk, stars or clouds) and sets `scene.background` to the color. A plain background
39
40
  color is not tone mapped, so what you write is what shows. `style.background` stays the color when there is no sky module.
40
41
  - The keyframes still light the world (sun, ambient, their colors).
41
42
  - Fog: in its default `'horizon'` color the fog follows the backdrop, so far things fade into it; `style.sky.fog.color` of your own wins.
42
43
  - Not together with `skybox` (both replace the dome).
43
- - To fade the backdrop toward gray in snow, read the weather in the function: `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)`
44
45
  (reuse the Color objects; it runs every frame).
@@ -1,7 +1,9 @@
1
1
  # 48. `engine.makeMaterial(role, spec)`: which keys work, who wins
2
2
 
3
- `engine.makeMaterial('furniture', { color: 0x8a5a36 })` returns a normal three.js material. The **role** picks the look from 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`: grain / paper / strokes / a texture laid over the surface in world space (no UVs).
15
- - `lighting`: extra light shaping (shadow tint, rim, wrap, own GLSL), merged over `style.lighting`; `false` opts out.
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).