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
@@ -0,0 +1,403 @@
1
+ // TSL side of shader patches: what a patch's `tsl` field does on a NodeMaterial (WebGPURenderer), slot by slot (render/slots.js).
2
+ // Why a registry instead of an import: render/patches.js is in every WebGL game's bundle and must not pull in three/tsl, so this module
3
+ // (loaded with threedog/tsl, i.e. only on the WebGPU route) registers itself (render/backend.js registerWebGPUPart) and patches.js looks it up when a
4
+ // NodeMaterial gets patches. One list per material (patches.js keeps it, with the same conflict / needs / replace-by-name rules as GLSL);
5
+ // this file only turns that list into nodes.
6
+ //
7
+ // Where each slot lands (and why it is not always the NodeMaterial property of the same name):
8
+ // position / shadowPosition / clipPosition / map / roughness / emissive: the properties positionNode / castShadowPositionNode / vertexNode /
9
+ // colorNode / roughnessNode / emissiveNode. position must be the property: three's shadow pass reads material.positionNode
10
+ // (Renderer._getShadowNodes), which is how a swaying tree's shadow sways with no depth material. These become instance accessors:
11
+ // the getter returns the chain, a game's own assignment (before or after patching) becomes the chain's starting value.
12
+ // position / shadowPosition run where GLSL runs them: on the object-space vertex before morphs, skinning, batching and instancing
13
+ // (three applies positionNode after all of those). The property holds a stand-in node; NodeMaterial.setupPosition (wrapped once below,
14
+ // for every NodeMaterial including three's shadow-pass material) runs the patch chain first, then three's own steps. A game's own
15
+ // positionNode keeps three's meaning (applied after instancing).
16
+ // color: after setupDiffuseColor, so ctx.color already has the map and vertex / instance colors (colorNode is applied before them).
17
+ // normal: around setupNormal (ctx.normal = what three would use: normalNode or the normal map, view space).
18
+ // output: around setupOutput, before fog (outputNode would come after fog, unlike the GLSL slot).
19
+ // lighting: the material's own LightingModel wrapped (setupLightingModel); code runs at the end of start(), after every light and the
20
+ // ambient are summed into reflectedLight but before LightsNode adds them up (measured in experiment E2: finish() is too late).
21
+ // Chaining: patches on one slot run in the order added, each ctx carrying the value so far (same rule as GLSL).
22
+ import * as TSL from 'three/tsl';
23
+ import { NodeMaterial, LightingNode } from 'three/webgpu';
24
+ import { codedError } from '../../core/errorHints.js';
25
+ import { wind } from './wind.tsl.js';
26
+ import { cloudShadow } from './cloudShadow.tsl.js';
27
+ import { season } from './season.tsl.js';
28
+ import { objectOrigin } from './objectOrigin.tsl.js';
29
+ import { detailNoise, detailBump } from './detail.tsl.js';
30
+ import { wrapDiffuse, shadowTint, rim } from './lighting.tsl.js';
31
+ import { waterWave, waterSurface, waterFresnel } from './water.tsl.js';
32
+ import { engineNodes, valueNode } from './uniforms.tsl.js';
33
+ import { registerWebGPUPart } from '../backend.js';
34
+ import { engineUniformName } from '../engineUniforms.js';
35
+ import { SLOTS, LIGHT_HOOKS as HOOKS } from '../slots.js';
36
+ import { notePatch } from '../../core/threePatches.js';
37
+ import { nameNodeBuild, lostStatements } from './nodeErrors.tsl.js';
38
+
39
+ const { Fn, positionLocal, modelViewProjection, materialColor, materialRoughness, materialEmissive, materialNormal, diffuseColor, vec3 } = TSL;
40
+
41
+ /** One engine uniform as a node, looked up from the renderer compiling it (same as the Fn library) */
42
+ const engineUniform = name => Fn((_, builder) => {
43
+ const n = engineNodes(builder, 'patch')[name];
44
+ if (!n) throw codedError('tsl-misuse', `threedog/tsl: engine.uniforms has no '${name}'`);
45
+ return n;
46
+ })();
47
+ // A patch's own uniforms ({ value } objects, shared with its GLSL side) as nodes: one node per object, reading the object every render, so
48
+ // detail.strength or the water's fresnel set live move both renderers. An engine uniform (engine.uniforms.uTime in the water patches) goes
49
+ // through engineUniform instead: resolved per compiling renderer, like resolveUniform on the GLSL side.
50
+ const OWN = new WeakMap();
51
+ /** @param {{ value: any }} o */
52
+ const patchUniform = o => {
53
+ const eng = engineUniformName(o);
54
+ if (eng) return engineUniform(eng);
55
+ let n = OWN.get(o);
56
+ if (!n) OWN.set(o, n = valueNode(o)); // render group: a 'color' / 'output' / 'lighting' patch leaves the material without node properties
57
+ return n;
58
+ };
59
+ /** Sample the texture held by a { value } object at uv; the node reads o.value, so a texture that finishes loading later (value swapped) is used */
60
+ const patchTexture = (o, uv) => {
61
+ const n = TSL.texture(o.value, uv);
62
+ Object.defineProperty(n, 'value', { configurable: true, get: () => o.value, set(v) { o.value = v; } });
63
+ return n;
64
+ };
65
+ /** What a patch's tsl code gets besides the slot value: the threedog/tsl functions and three/tsl itself (so engine files need no import) */
66
+ const FX = Object.freeze({ wind, cloudShadow, season, objectOrigin, detailNoise, detailBump, wrapDiffuse, shadowTint, rim,
67
+ waterWave, waterSurface, waterFresnel, uniform: engineUniform, patchUniform, patchTexture });
68
+
69
+ // slot -> [property, default value when the material has none]; built from the slot table's node column (render/slots.js), so the table cannot
70
+ // list a mapping this file lacks. The default is what three uses without the property.
71
+ const DEFAULTS = { positionNode: () => positionLocal, castShadowPositionNode: () => positionLocal, vertexNode: () => modelViewProjection,
72
+ colorNode: () => materialColor, roughnessNode: () => materialRoughness, emissiveNode: () => materialEmissive };
73
+ const PROPS = Object.fromEntries(Object.entries(SLOTS).filter(([, s]) => s.node?.prop).map(([n, s]) => {
74
+ if (!DEFAULTS[s.node.prop]) throw codedError('shader-patch', `[threedog] render/slots.js names node property '${s.node.prop}' for slot '${n}', which patchNodes.tsl.js has no default for`);
75
+ return [n, [s.node.prop, DEFAULTS[s.node.prop]]];
76
+ }));
77
+ // position chains, by their stand-in node: what setupPosition runs before three's morph / skinning / instancing steps
78
+ const PRE = new WeakMap();
79
+ /**
80
+ * The stand-in for a position chain: evaluates to the game's own value (or positionLocal, i.e. leaves three's result as it is) where three
81
+ * applies positionNode, while the chain itself runs at the start of setupPosition. Its cache key is the chain's, so a different chain is a
82
+ * different program. @param {any} chain @param {any} base
83
+ */
84
+ function preMarker(chain, base) {
85
+ const m = Fn(() => base ?? positionLocal)();
86
+ m.customCacheKey = () => chain.getCacheKey();
87
+ PRE.set(m, chain);
88
+ return m;
89
+ }
90
+ // Why the prototype and not each material: three's shadow pass draws with its own NodeMaterial, handed our positionNode / castShadowPositionNode
91
+ // (Renderer._getShadowNodes), and the shadow must sway exactly like the surface. Only materials carrying one of our stand-ins are affected.
92
+ const setupPosition = NodeMaterial.prototype.setupPosition;
93
+ if (!(/** @type {{ _threedogPre?: boolean }} */ (/** @type {unknown} */ (setupPosition)))._threedogPre) { // already wrapped (module loaded twice)
94
+ NodeMaterial.prototype.setupPosition = Object.assign(function (builder) {
95
+ const chain = PRE.get(this.positionNode);
96
+ if (chain) positionLocal.assign(TSL.subBuild(chain, 'POSITION', 'vec3'));
97
+ return setupPosition.call(this, builder);
98
+ }, { _threedogPre: true });
99
+ notePatch('node-setup-position', 'NodeMaterial.prototype.setupPosition: runs the vertex-moving patch chain before three builds the position (WebGPU wind and its shadow)',
100
+ () => { NodeMaterial.prototype.setupPosition = setupPosition; }, { lost: 'on WebGPURenderer, wind and other vertex-moving patches no longer move vertices or their shadow' });
101
+ }
102
+
103
+ const BUILT = Object.keys(SLOTS).filter(n => SLOTS[n].node?.setup); // slots handled inside three's setup methods
104
+ const LIGHT_KEYS = ['directDiffuse', 'directSpecular', 'indirectDiffuse', 'indirectSpecular'];
105
+
106
+ /** The patch's code for a slot as { start?, light?, direct?, after? } (lighting) or a function, or undefined */
107
+ const codeOf = (p, slot) => p.tsl?.[slot];
108
+ const prefix = (p, slot) => `[threedog] patch '${p.name}' (slot ${slot})`;
109
+
110
+ /**
111
+ * Run one patch's code with the try the error prefix needs; `want` checks the result. The nodes it returns carry the prefix into three's
112
+ * later build (nameNodeBuild), and statements it issues outside three's build are named in dev (lostStatements). probe: false inside the
113
+ * build (ctx.builder: a stack is there, so a Loop is fine) and for compute()'s stand-in runs of the build-time slots, whose real run is there.
114
+ */
115
+ function run(p, slot, fn, ctx, want = 'node', probe = !ctx.builder) {
116
+ let v;
117
+ try { v = probe ? lostStatements(prefix(p, slot), () => fn(ctx)) : fn(ctx); }
118
+ catch (e) {
119
+ const msg = String(e?.message ?? e);
120
+ if (msg.startsWith(prefix(p, slot))) throw e;
121
+ const err = Object.assign(codedError('shader-patch', `${prefix(p, slot)}: ${msg}`), { cause: e });
122
+ // the stack of the error that happened (the game's patch line first), not of this wrapper: devtools and three's 'TSL:' build-error log
123
+ // (StackTrace, first non-three frame) would otherwise point at this file. Chrome frames are ' at ...', Firefox / Safari 'fn@file:line:col'
124
+ const frames = String(e?.stack ?? '').split('\n').filter(l => /^\s+at |@.+:\d+:\d+$/.test(l));
125
+ if (frames.length) err.stack = `${err.name}: ${err.message}\n${frames.join('\n')}`;
126
+ throw err;
127
+ }
128
+ if (want === 'node' && !v?.isNode) throw codedError('shader-patch', `${prefix(p, slot)}: tsl must return a node (the new ${slot} value), got ${v === null ? 'null' : typeof v}`);
129
+ if (want === 'light' && v != null) {
130
+ const bad = typeof v !== 'object' ? [String(v)] : Object.keys(v).filter(k => !LIGHT_KEYS.includes(k) || !v[k]?.isNode);
131
+ if (bad.length) throw codedError('shader-patch', `${prefix(p, slot)}: tsl returns nothing or { ${LIGHT_KEYS.join(', ')} } as nodes; got ${bad.join(', ')}`);
132
+ for (const k in v || {}) nameNodeBuild(v[k], prefix(p, slot), ctx[k]);
133
+ }
134
+ return want === 'node' ? nameNodeBuild(v, prefix(p, slot), ctx[slot]) : v;
135
+ }
136
+
137
+ /** Fold every patch's code for one value slot over `value` (the value so far), in list order */
138
+ const chain = (list, slot, value, extra) => list.reduce((v, p) => { const fn = codeOf(p, slot);
139
+ return typeof fn === 'function' ? run(p, slot, fn, { ...extra, [slot]: v }) : v; }, value);
140
+
141
+ /** lighting hooks of a patch, normalised: a function is the end-of-lighting code */
142
+ const hooksOf = h => typeof h === 'function' ? { after: h } : h;
143
+
144
+ // a classic material has no `lights` flag (that is a ShaderMaterial / NodeMaterial field): the lit classic types are the ones three's node
145
+ // twins light
146
+ const lit = m => m.isNodeMaterial ? !!m.lights && !m.isMeshBasicNodeMaterial
147
+ : !!(m.isMeshLambertMaterial || m.isMeshPhongMaterial || m.isMeshStandardMaterial || m.isMeshToonMaterial);
148
+ /**
149
+ * Why this material cannot take the patch on the TSL side ('' = fine). patches.js throws it (strict) or skips with a warning, like a missing GLSL anchor.
150
+ * m is a NodeMaterial, or a classic material whose node twin three builds (same lit / roughness facts).
151
+ * @param {any} m @param {any} p
152
+ */
153
+ function gaps(m, p) {
154
+ const out = [];
155
+ for (const slot of Object.keys(p.tsl || {})) {
156
+ if (!(slot in PROPS) && !BUILT.includes(slot)) out.push(`slot '${slot}' is WebGL only (render/slots.js has no NodeMaterial place for it)`);
157
+ // MeshBasicNodeMaterial has lights = true (for light maps) but no direct lighting, as MeshBasicMaterial has no lights chunk in GLSL
158
+ else if (slot === 'lighting' && !lit(m)) out.push(`slot 'lighting' needs a lit material (${m.type} has no lights)`);
159
+ else if (slot === 'roughness' && m.roughness === undefined) out.push(`slot 'roughness' needs a standard / physical material`);
160
+ const h = p.tsl[slot];
161
+ if (slot === 'lighting' ? !(typeof h === 'function' || (h && typeof h === 'object' && HOOKS.some(k => typeof h[k] === 'function')))
162
+ : typeof h !== 'function') out.push(`slot '${slot}' code must be (ctx) => node` + (slot === 'lighting' ? ' or { start?, light?, direct?, after? }' : ''));
163
+ }
164
+ return out.length ? `patch '${p.name}': ${out.join('; ')}` : '';
165
+ }
166
+
167
+ // The nodes a patch list turns into, kept per SOURCE material: a NodeMaterial patched directly, or a classic material (MeshLambertMaterial ...)
168
+ // patched for both renderers. Why classic materials too: the engine's own materials (makeMaterial, terrain, vegetation, water) stay classic so
169
+ // one material object draws on WebGLRenderer (GLSL side) and on WebGPURenderer, including fallback: 'webgl', which is decided only in start().
170
+ // three's WebGPURenderer turns a classic material into a fresh node twin per build (NodeLibrary.fromMaterial); render/patches.js wraps that
171
+ // one call so the twin gets these nodes (dress). The source keeps them too, as non-enumerable accessors: three's shadow pass reads
172
+ // positionNode / castShadowPositionNode off the drawn (classic) material, which is how a swaying tree's shadow sways.
173
+ const STATE = new WeakMap(); // source -> { list, own (game values of PROPS), out (chained PROPS), color, key, fresh, error }
174
+ // chained node -> the game value it was built on. Why: three's NodeMaterial.copy reads source.positionNode through the accessor, i.e. the
175
+ // chain, and stores it as the copy's own value; copyPatches would then chain the same patches on top again (the effect applied twice)
176
+ const BASE = new WeakMap();
177
+ const baseOf = v => (v && BASE.has(v) ? BASE.get(v) : v ?? null);
178
+ // listOf / src: set for a classic source only (its list lives in patches.js), so a stale state rebuilds itself when read
179
+ const newState = () => ({ list: [], own: {}, out: {}, color: null, key: '', fresh: false, error: null, listOf: null, src: null });
180
+
181
+ /**
182
+ * Accessors for every PROPS property on target, reading st (the chain, else the game's own value). enumerable: a NodeMaterial's own
183
+ * properties (three keys its program by them); a classic material or a node twin gets hidden ones (three's program key for those is the
184
+ * classic material's customProgramCacheKey, render/patches.js).
185
+ */
186
+ function accessors(target, st, enumerable) {
187
+ for (const [prop] of Object.values(PROPS)) {
188
+ if (enumerable) st.own[prop] = baseOf(target[prop]);
189
+ Object.defineProperty(target, prop, { configurable: true, enumerable, get: () => { if (!st.fresh && st.listOf) classic(st.src, st.listOf()); return st.out[prop] ?? st.own[prop] ?? null; },
190
+ set(v) { st.own[prop] = v ?? null; st.fresh = false; if (enumerable) compute(target, st); target.needsUpdate = true; } });
191
+ }
192
+ }
193
+
194
+ /** Wrap three's setup methods of the NodeMaterial m (a patched one, or a classic material's node twin) to run st's color / normal / output / lighting code */
195
+ function wrapSetup(m, st, src) {
196
+ const ctx = extra => ({ fx: FX, tsl: TSL, material: src, ...extra });
197
+ const diffuse = m.setupDiffuseColor, normal = m.setupNormal, output = m.setupOutput, model = m.setupLightingModel;
198
+ m.setupDiffuseColor = function (builder) { const r = diffuse.call(this, builder); if (st.color) diffuseColor.assign(st.color); return r; };
199
+ m.setupNormal = function (builder) { return chain(st.list, 'normal', normal.call(this, builder), ctx({ builder })); };
200
+ m.setupOutput = function (builder, node) { return output.call(this, builder, chain(st.list, 'output', node, ctx({ builder }))); };
201
+ m.setupLightingModel = function (builder) {
202
+ const lm = model.call(this, builder);
203
+ const hooks = st.list.filter(p => codeOf(p, 'lighting')).map(p => [p, hooksOf(codeOf(p, 'lighting'))]);
204
+ if (!lm || !hooks.length) return lm;
205
+ // Why each direct hook adds into its own light sums: on WebGL every lighting patch runs after three's light loop, in list order, so
206
+ // light a patch adds is scaled only by the patches after it. Here direct() runs inside the loop; added straight into reflectedLight it
207
+ // would be scaled by every after() (the clouds patch darkened the lighting patch's wrap light on WebGPU only). Each patch's sums join
208
+ // reflectedLight at its own place in the list, right before its after().
209
+ const { start, direct } = lm, states = hooks.map(() => ({}));
210
+ let sums = [];
211
+ const light = (rl, i, b) => ctx({ builder: b, state: states[i], reflectedLight: rl, ...Object.fromEntries(LIGHT_KEYS.map(k => [k, rl[k]])) });
212
+ lm.start = function (b) {
213
+ const rl = b.context.reflectedLight;
214
+ sums = hooks.map(([, h], i) => h.direct ? Object.fromEntries(LIGHT_KEYS.map(k => [k, vec3(0).toVar(`tdLight${i}_${k}`)])) : null);
215
+ hooks.forEach(([p, h], i) => h.start && run(p, 'lighting', h.start, light(rl, i, b), 'any'));
216
+ start.call(this, b);
217
+ hooks.forEach(([p, h], i) => {
218
+ if (sums[i]) for (const k of LIGHT_KEYS) rl[k].addAssign(sums[i][k]);
219
+ if (!h.after) return;
220
+ const v = run(p, 'lighting', h.after, light(rl, i, b), 'light');
221
+ for (const k in v || {}) rl[k].assign(v[k]);
222
+ });
223
+ };
224
+ lm.direct = function (data, b) {
225
+ const ln = data.lightNode;
226
+ // the light as a patch needs it: direction and color (shadow already multiplied in), its shadow factor alone, whether it is the sun
227
+ const L = { direction: data.lightDirection, color: data.lightColor, shadow: ln?.shadowNode ? ln.shadowNode.x : null,
228
+ directional: !!ln?.light?.isDirectionalLight, light: ln?.light ?? null };
229
+ // light(light, ctx) hooks first, in list order: a new color for this one light before three lights the surface with it (the cloud
230
+ // shadow dims the sun only; GLSL does the same by wrapping three's getDirectionalLightInfo in lightsPars). direct() sees the color as
231
+ // three gave it, as GLSL code reading directionalLights[i].color does
232
+ let color = data.lightColor;
233
+ hooks.forEach(([p, h], i) => {
234
+ if (!h.light) return;
235
+ const v = run(p, 'lighting', c => h.light({ ...L, color }, c), light(sums[i] ?? data.reflectedLight, i, b), 'any');
236
+ if (v == null) return;
237
+ if (!v.isNode) throw codedError('shader-patch', `${prefix(p, 'lighting')}: light() returns the light's new color as a node, or nothing; got ${typeof v}`);
238
+ color = v;
239
+ });
240
+ const r = direct.call(this, color === data.lightColor ? data : { ...data, lightColor: color }, b);
241
+ hooks.forEach(([p, h], i) => h.direct && run(p, 'lighting', c => h.direct(L, c), light(sums[i], i, b), 'any'));
242
+ return r;
243
+ };
244
+ return lm;
245
+ };
246
+ }
247
+
248
+ /** Install the accessors and method wrappers once on a NodeMaterial patched directly */
249
+ function install(m) {
250
+ const st = newState();
251
+ STATE.set(m, st);
252
+ accessors(m, st, true);
253
+ wrapSetup(m, st, m);
254
+ // clone() carries no patches (as on the GLSL side, where Material.copy skips onBeforeCompile): the copy gets the game's own values, not the
255
+ // chains, so a clone without copyPatches is the plain material and one with copyPatches has each effect once
256
+ const clone = m.clone, key = m.customProgramCacheKey;
257
+ m.clone = function () {
258
+ const c = clone.call(this);
259
+ for (const [prop] of Object.values(PROPS)) if (c[prop] === st.out[prop]) c[prop] = st.own[prop];
260
+ return c;
261
+ };
262
+ // three keys NodeMaterial programs by their node properties only; code added inside the setup methods is not one, so two materials
263
+ // differing only in a color / normal / output / lighting patch would share a program. st.key is built from those patches' node graphs
264
+ m.customProgramCacheKey = function () { return key.call(this) + (st.key ? '|threedog:' + st.key : ''); };
265
+ return st;
266
+ }
267
+
268
+ /** Recompute everything the list decides (called on every change): chained properties, the color node, the cache key */
269
+ function compute(m, st) {
270
+ const extra = { fx: FX, tsl: TSL, material: m };
271
+ const out = {};
272
+ for (const [slot, [prop, dflt]] of Object.entries(PROPS)) {
273
+ if (slot === 'shadowPosition') {
274
+ // the shadow passes run the vertex code of shadow: true patches only, each one's shadowPosition code where it has one, else its
275
+ // position code (the GLSL rule: patches.js shadowMaterial). three's shadow pass reads castShadowPositionNode before positionNode, so it
276
+ // is set whenever the two differ: a shadow: false patch then moves the surface but not its shadow, on both renderers
277
+ if (!st.list.some(p => codeOf(p, 'shadowPosition') || (codeOf(p, 'position') && !p.shadow))) continue;
278
+ const c = st.list.reduce((v, p) => { const s = !p.shadow ? null : codeOf(p, 'shadowPosition') ? 'shadowPosition' : codeOf(p, 'position') ? 'position' : null;
279
+ return s ? run(p, s, codeOf(p, s), { ...extra, position: v }) : v; }, positionLocal);
280
+ out[prop] = preMarker(c, st.own[prop] ?? st.own.positionNode);
281
+ } else if (!st.list.some(p => typeof codeOf(p, slot) === 'function')) continue;
282
+ else if (slot === 'position') out[prop] = preMarker(chain(st.list, slot, positionLocal, extra), st.own[prop]);
283
+ else out[prop] = chain(st.list, slot, st.own[prop] ?? dflt(), extra);
284
+ }
285
+ const color = st.list.some(p => codeOf(p, 'color')) ? chain(st.list, 'color', diffuseColor, extra) : null;
286
+ // the build-time slots are also run once here on stand-in values: a typo in the code fails now, at the call that added the patch,
287
+ // and the node graphs it returns key the program (customProgramCacheKey above)
288
+ const keys = [];
289
+ for (const p of st.list) {
290
+ const parts = [p.name + '=' + (p.cacheKey ?? '')];
291
+ if (codeOf(p, 'normal')) parts.push(run(p, 'normal', codeOf(p, 'normal'), { ...extra, normal: materialNormal }, 'node', false).getCacheKey(true));
292
+ if (codeOf(p, 'output')) parts.push(run(p, 'output', codeOf(p, 'output'), { ...extra, output: TSL.vec4(0) }, 'node', false).getCacheKey(true));
293
+ const h = codeOf(p, 'lighting');
294
+ if (typeof h === 'function') {
295
+ const v = run(p, 'lighting', h, { ...extra, state: {}, ...Object.fromEntries(LIGHT_KEYS.map(k => [k, vec3(0)])) }, 'light', false);
296
+ for (const k in v || {}) parts.push(k + v[k].getCacheKey(true));
297
+ } else if (h) parts.push(Object.values(h).map(String).join()); // hook objects: their text (put values that change the code into cacheKey)
298
+ if (codeOf(p, 'color')) parts.push('c');
299
+ keys.push(parts.join(':'));
300
+ }
301
+ for (const prop in out) BASE.set(out[prop], st.own[prop]);
302
+ st.out = out; st.color = color; st.key = (color ? color.getCacheKey(true) + ',' : '') + keys.join(',');
303
+ st.fresh = true;
304
+ }
305
+
306
+ /**
307
+ * Make the material's nodes follow its patch list (patchMaterial / unpatchMaterial / copyPatches call it after every change on a NodeMaterial)
308
+ * @param {any} m @param {any[]} list
309
+ */
310
+ function apply(m, list) {
311
+ const st = STATE.get(m) || install(m);
312
+ const prev = st.list;
313
+ st.list = list.slice();
314
+ try { compute(m, st); } catch (e) { st.list = prev; compute(m, st); throw e; }
315
+ }
316
+
317
+ // ---------- classic materials (one material, both renderers) ----------
318
+
319
+ /** Why a patch on a classic material does nothing on WebGPURenderer, or '' (its GLSL is never compiled there) @param {any} m @param {any} p */
320
+ function noNodeForm(m, p) {
321
+ if (p.tsl == null && p.glsl != null) return `patch '${p.name}' on ${m.type}${m.name ? ` '${m.name}'` : ''} is GLSL only, which WebGPURenderer never compiles: `
322
+ + 'give it a tsl version next to glsl (recipe 43), or stay on WebGL (no renderer option)';
323
+ return gaps(m, p);
324
+ }
325
+
326
+ /** The state of a classic source material for its current list, computed when stale; a patch that cannot run is kept as st.error, not thrown */
327
+ function classic(src, list) {
328
+ const st = classicState(src);
329
+ if (st.fresh) return st;
330
+ st.list = list.slice();
331
+ st.error = null;
332
+ try {
333
+ const bad = list.map(p => noNodeForm(src, p)).find(Boolean);
334
+ if (bad) throw codedError('webgpu-needs-tsl', `[threedog] ${bad}`);
335
+ compute(src, st);
336
+ } catch (e) {
337
+ // drawn without its patches instead of a frame loop that throws: start() and every later add name it (render/backend.js webglOnlyOn)
338
+ st.error = e; st.list = []; st.out = {}; st.color = null; st.key = ''; st.fresh = true;
339
+ }
340
+ return st;
341
+ }
342
+
343
+ /**
344
+ * A classic material's patch list changed (patches.js): its nodes are rebuilt on the next read. The hidden accessors are installed on the
345
+ * first change, so the shadow pass finds positionNode even before the color pass converted the material.
346
+ * @param {any} src @param {() => any[]} listOf the material's current list
347
+ */
348
+ function invalidate(src, listOf) { const st = classicState(src); st.listOf = listOf; st.fresh = false; }
349
+
350
+ /** A classic source's state, made (with its hidden accessors) on first use @param {any} src */
351
+ function classicState(src) {
352
+ let st = STATE.get(src);
353
+ if (!st) { STATE.set(src, st = newState()); st.src = src; accessors(src, st, false); }
354
+ return st;
355
+ }
356
+
357
+ /**
358
+ * Give the node twin three just made of a classic material (NodeLibrary.fromMaterial) the source's patch nodes; returns the twin
359
+ * @param {any} twin @param {any} src @param {any[]} list
360
+ */
361
+ function dress(twin, src, list) {
362
+ environmentDiffuse(twin);
363
+ if (!list.length) return twin;
364
+ const st = classic(src, list);
365
+ if (!st.list.length) return twin;
366
+ accessors(twin, st, false);
367
+ wrapSetup(twin, st, src);
368
+ return twin;
369
+ }
370
+
371
+ // Lambert / Phong twins: diffuse light from scene.environment, as WebGLRenderer gives the classic material. Why: three 0.187's WebGLRenderer
372
+ // lights MeshLambertMaterial / MeshPhongMaterial without an envMap of their own with scene.environment's irradiance (WebGLPrograms: PMREM
373
+ // for Lambert / Phong, lights_fragment_maps getIBLIrradiance), but their node twins (BasicEnvironmentNode) read only material.envMap, so on
374
+ // WebGPU every engine Lambert / Phong surface lost the room map's (or sky map's) fill: terrain and trees about 4% darker on the whole picture,
375
+ // a plain gray plane 30% darker (tests/specs/engine-webgpu.mjs measures both routes). Same formula as GLSL getIBLIrradiance:
376
+ // PI * the roughest PMREM level along the world normal (env rotation applied) * scene.environmentIntensity, added to the indirect irradiance.
377
+ class EnvironmentDiffuse extends LightingNode {
378
+ /** @param {any} envNode builder.environmentNode (a texture node of scene.environment) */
379
+ constructor(envNode) { super(); this.envNode = envNode; this.pmrem = null; this.updateBeforeType = TSL.NodeUpdateType.RENDER; }
380
+ // setup and updateBefore return nothing, like three's own EnvironmentNode (@types/three declares a Node / boolean result): typed any for that
381
+ /** @param {any} builder @returns {any} */
382
+ setup(builder) {
383
+ this.pmrem = TSL.pmremTexture(this.envNode.value, TSL.materialEnvRotation.mul(TSL.normalWorld), TSL.float(1));
384
+ builder.context.irradiance.addAssign(this.pmrem.mul(Math.PI).mul(TSL.materialEnvIntensity).rgb);
385
+ }
386
+ // the scene's environment can change without a rebuild (as three's EnvironmentNode allows)
387
+ /** @param {any} frame @returns {any} */
388
+ updateBefore(frame) { const t = this.envNode.value; if (this.pmrem && t && this.pmrem.value !== t) { this.pmrem.value = t; this.pmrem.updateBefore(frame); } }
389
+ }
390
+ /** @param {any} twin a node twin three just made of a classic material */
391
+ function environmentDiffuse(twin) {
392
+ if (!(twin.isMeshLambertNodeMaterial || twin.isMeshPhongNodeMaterial)) return;
393
+ const own = twin.setupEnvironment;
394
+ twin.setupEnvironment = function (builder) {
395
+ const env = own.call(this, builder);
396
+ return env || this.envMap || !builder.environmentNode ? env : new EnvironmentDiffuse(builder.environmentNode);
397
+ };
398
+ }
399
+
400
+ /** Why the classic material's patches do not all draw on WebGPURenderer (the message), or null @param {any} src @param {any[]} list */
401
+ const problem = (src, list) => classic(src, list).error?.message ?? null;
402
+
403
+ registerWebGPUPart('nodePatches', Object.freeze({ gaps, apply, invalidate, dress, problem }));
@@ -0,0 +1,158 @@
1
+ // Post chain on WebGPURenderer (RenderPipeline); render/PostFX.js holds the list and calls these with itself as `post`.
2
+ // The chain is one node graph: scenePass = pass(scene, camera, { samples }) -> each hdr effect's node() -> renderOutput() (tone mapping + output
3
+ // color space, placed by hand: outputColorTransform = false) -> ldr -> final. Fuse effects bring fuse.tsl (color, uv, t) => color; neighbors are
4
+ // just nested calls, so three compiles them into one fullscreen pass and fuse.js's merging is not needed here (nor loaded).
5
+ // Registered on a global when threedog/tsl loads (see PostFX.js for why not an import). Only three/webgpu, three/tsl and three's TSL display
6
+ // nodes are imported: this file must never pull EffectComposer or other WebGL code.
7
+ import { RenderPipeline } from 'three/webgpu';
8
+ import * as TSL from 'three/tsl';
9
+ import { bloom } from 'three/addons/tsl/display/BloomNode.js';
10
+ import { ao } from 'three/addons/tsl/display/GTAONode.js';
11
+ import { codedError } from '../../core/errorHints.js';
12
+ import { registerWebGPUPart } from '../backend.js';
13
+ import { nameNodeBuild, lostStatements } from './nodeErrors.tsl.js';
14
+
15
+ const { pass, renderOutput, uniform, screenUV, screenSize, time, convertToTexture } = TSL;
16
+
17
+ /** Live uniform for a param value (numbers, booleans as 0 / 1, colors, vectors), or null: anything else rebuilds the chain when it changes */
18
+ function liveUniform(v) {
19
+ if (typeof v === 'number') return uniform(v);
20
+ if (typeof v === 'boolean') return uniform(v ? 1 : 0);
21
+ if (v?.isColor || v?.isVector2 || v?.isVector3 || v?.isVector4) return uniform(v.clone());
22
+ return null;
23
+ }
24
+ const live = v => typeof v === 'number' || typeof v === 'boolean' || v?.isColor || v?.isVector2 || v?.isVector3 || v?.isVector4;
25
+ function writeUniform(u, v) {
26
+ if (typeof v === 'number') u.value = v;
27
+ else if (typeof v === 'boolean') u.value = v ? 1 : 0;
28
+ else u.value.copy(v);
29
+ }
30
+ /** The effect's uniform nodes by param name, made once per effect and kept across chain rebuilds (so set() keeps working on the same nodes) */
31
+ function uniformsOf(h) {
32
+ if (!h._u) { h._u = {}; for (const [k, v] of Object.entries(h.params)) { const u = liveUniform(v); if (u) h._u[k] = u; } }
33
+ return h._u;
34
+ }
35
+
36
+ /**
37
+ * ctx.params for node() / fuse.tsl: the effect's live params, noting which keys are read while the node is built. Such a key went into the graph
38
+ * as a plain number, so set() of it rebuilds (WebGL rebuilds an effect without update() the same way); keys read only through ctx.p stay
39
+ * uniform writes. A read after the build (an onRenderUpdate callback, outline's color) sees the current value each time and is not noted.
40
+ */
41
+ function paramsOf(h) {
42
+ return h._paramsProxy ??= new Proxy(h.params, { get(t, k) { if (h._building && typeof k === 'string') h._read.add(k); return t[k]; } });
43
+ }
44
+
45
+ /**
46
+ * Display nodes handed to effects as ctx.display, each call recorded so the effect's nodes are disposed when the chain is rebuilt.
47
+ * Why handed in and not imported by the effect: @threedog/post-effects is also loaded by WebGL games; importing three/webgpu there would grow their bundles.
48
+ */
49
+ function displayFor(made) {
50
+ const rec = f => (...a) => { const n = f(...a); made.push(n); return n; };
51
+ // pass: an extra scene render (outline's normal / mask views); texture: the color so far as a texture, for effects that sample it at other
52
+ // uvs (dof). Both own render targets, so they go through the recorder too; a node that already is a texture comes back as is and is not ours to dispose.
53
+ const texture = n => { const t = convertToTexture(n); if (t !== n) made.push(t); return t; };
54
+ return { bloom: rec(bloom), ao: rec(ao), pass: rec(pass), texture };
55
+ }
56
+
57
+ const onlyCreate = e => codedError('post-effect', `[threedog] post effect '${e.name}' has only create() (a three.js Pass, WebGLRenderer only); on WebGPURenderer give it ` +
58
+ `node: (input, ctx) => colorNode, e.g. node: (input, { tsl, p }) => tsl.vec4(input.rgb.mul(p.amount), input.a) (recipe 52)`);
59
+ const glslOnly = e => codedError('post-effect', `[threedog] post effect '${e.name}': its fuse snippet is GLSL only; on WebGPURenderer add fuse.tsl: ` +
60
+ `(color, uv, t) => color, e.g. tsl: (color, uv, { tsl, p }) => tsl.vec4(color.rgb.mul(p.amount), color.a) (recipe 52)`);
61
+
62
+ const webgpuPost = {
63
+ init(post) { post._pipe = null; },
64
+ object: post => (post._pipe ? { pipeline: post._pipe.pipeline, scenePass: post._pipe.scenePass } : null),
65
+ // The pass node owns its render targets and resizes them with the renderer; nothing is handed out as ping-pong targets on this backend
66
+ targets: () => null,
67
+ /**
68
+ * Param change: number / color params only write their uniforms; another kind (a texture, a mode string), or a param node() read as a plain
69
+ * value from ctx.params (built into the graph as a constant, so its uniform reaches nothing), rebuilds the chain, as WebGL rebuilds an effect
70
+ * without update(). true = handled
71
+ */
72
+ set(post, h, p) {
73
+ if (Object.entries(p).every(([k, v]) => h._u?.[k] && live(v) && !h._read?.has(k))) { for (const [k, v] of Object.entries(p)) writeUniform(h._u[k], v); return true; }
74
+ for (const [k, v] of Object.entries(p)) if (h._u?.[k] && live(v)) writeUniform(h._u[k], v);
75
+ if (h.enabled) { h._impl?.dispose?.(); h._impl = null; post._pipe && (post._pipe.key = null); post._sync(); }
76
+ return true;
77
+ },
78
+ refresh() {},
79
+ setAntialias(post) { if (post._pipe) post._pipe.key = null; },
80
+ sync(post) {
81
+ const { renderer, scene, camera } = post.engine, samples = post._aa ? 4 : 0;
82
+ const on = post._sorted().filter(e => e.enabled);
83
+ for (const e of on) if (e._def.fuse ? typeof e._def.fuse.tsl !== 'function' : typeof e._def.node !== 'function') throw e._def.fuse ? glslOnly(e) : onlyCreate(e);
84
+ // Same effects, same build, same samples: the graph is current (a set() of a number param never gets here)
85
+ const key = `${samples}|${on.map(e => e.name).join(',')}`;
86
+ if (post._pipe?.key === key) return;
87
+ let P = post._pipe;
88
+ if (!P) P = post._pipe = { pipeline: new RenderPipeline(renderer), scenePass: null, samples: -1, key: null, order: [] };
89
+ if (P.samples !== samples) { P.scenePass?.dispose(); P.scenePass = pass(scene, camera, { samples }); P.samples = samples; }
90
+ // Every structural change rebuilds every effect's nodes: an effect's input is the node before it, which changed too
91
+ for (const e of post._list) { e._impl?.dispose?.(); e._impl = null; }
92
+ const size = post._size(), order = [];
93
+ const ctxOf = (e, made) => ({ engine: post.engine, scene, camera, width: size.x, height: size.y, params: paramsOf(e), scenePass: P.scenePass,
94
+ tsl: TSL, display: displayFor(made), p: uniformsOf(e) });
95
+ // the effect's node is built only when the pipeline first draws: errors then, and statements lost outside an Fn, name the effect
96
+ const run = (e, color) => {
97
+ const label = `[threedog] post effect '${e.name}'`;
98
+ return nameNodeBuild(lostStatements(label, () => build(e, color)), label, color);
99
+ };
100
+ const build = (e, color) => {
101
+ const made = [];
102
+ e._impl = { nodes: made, dispose() { for (const n of made) n.dispose?.(); made.length = 0; } };
103
+ order.push(e.name);
104
+ e._read = new Set(); e._building = true;
105
+ try {
106
+ if (e._def.fuse) {
107
+ const f = e._def.fuse, t = { ...ctxOf(e, made), time, resolution: screenSize, input: f.reads ? convertToTexture(color) : null };
108
+ if (t.input) made.push(t.input);
109
+ return f.tsl(color, screenUV, t);
110
+ }
111
+ return e._def.node(color, ctxOf(e, made));
112
+ } finally { e._building = false; }
113
+ };
114
+ const slot = s => on.filter(e => e.slot === s);
115
+ let color = P.scenePass.getTextureNode();
116
+ const sceneFx = slot('scene')[0];
117
+ if (sceneFx) color = run(sceneFx, color); else order.push('scene render');
118
+ for (const e of slot('hdr')) color = run(e, color);
119
+ const toneFx = slot('tone')[0]; // a game's tone stage replaces renderOutput (it outputs display color itself)
120
+ if (toneFx) color = run(toneFx, color); else { color = renderOutput(color); order.push('output (tone mapping)'); }
121
+ for (const e of [...slot('ldr'), ...slot('final')]) color = run(e, color);
122
+ P.pipeline.outputColorTransform = false;
123
+ P.pipeline.outputNode = color; P.pipeline.needsUpdate = true;
124
+ P.output = color; P.order = order; P.key = key;
125
+ },
126
+ dispose(post) {
127
+ const P = post._pipe;
128
+ if (!P) return;
129
+ P.scenePass?.dispose(); P.pipeline.dispose(); post._pipe = null;
130
+ },
131
+ // start()'s compileAsync target: pass() renders into its own target whose program key three manages; the canvas key is the closest stand-in
132
+ sceneTarget: () => null,
133
+ // target: the pipeline's last quad draws into the renderer's current target (pass() nodes put it back after their own renders)
134
+ render(post, dt, target = null) {
135
+ if (!post._pipe) post._sync();
136
+ onTarget(post.engine.renderer, target, () => post._pipe.pipeline.render());
137
+ },
138
+ /**
139
+ * Straight to the canvas. postWebGL's direct() draws a Color background (or the clear color) as a tone-mapped quad so it matches the composer
140
+ * path; nothing like it is needed here: with tone mapping or an sRGB output, WebGPURenderer draws the scene (clear included) into its own
141
+ * half-float frame-buffer target and tone-maps the whole image in one output pass, so a clear is tone-mapped like every mesh
142
+ * (tests/specs/post-webgpu.mjs: Color, HDR Color and clear-color backgrounds equal WebGL's to the pixel). An sRGB texture background is
143
+ * tone-mapped here too, as on both WebGL paths (postWebGL.js toneBackground; tests/specs/engine-webgpu.mjs colorSpots).
144
+ * MSAA: the renderer's own samples (made with the default antialias), so an effect-free frame needs no pipeline; a runtime switch away from
145
+ * them runs the pipeline with pass() samples (PostFX active).
146
+ */
147
+ direct(post, target = null) { const { renderer, scene, camera } = post.engine; onTarget(renderer, target, () => renderer.render(scene, camera)); },
148
+ };
149
+
150
+ /** Run draw with target set (null: as it is, the canvas), then put the previous target back */
151
+ function onTarget(r, target, draw) {
152
+ if (!target) { draw(); return; }
153
+ const prev = r.getRenderTarget();
154
+ r.setRenderTarget(target);
155
+ try { draw(); } finally { r.setRenderTarget(prev); }
156
+ }
157
+
158
+ registerWebGPUPart('post', Object.freeze(webgpuPost));
@@ -0,0 +1,13 @@
1
+ // TSL season() (GLSL threedogSeason).
2
+ // TSL season: season(color, kind) -> vec3, line for line GLSL threedogSeason (render/effects.js); kind 0 foliage, 1 ground.
3
+ // color is the linear surface color as vec3 (a vec4 gives its rgb, like GLSL vec3(c)); with uFoliageMix / uGroundMix > 0 it mixes toward the tint, else multiplies.
4
+ import { Fn, vec3, int, select, mix } from 'three/tsl';
5
+ import { engineNodes } from './uniforms.tsl.js';
6
+
7
+ /** The surface color moved by the calendar's season tint (uFoliageTint / uGroundTint, mode by uFoliageMix / uGroundMix) */
8
+ export const season = Fn(([color, kind], builder) => {
9
+ const u = engineNodes(builder, 'season');
10
+ const c = vec3(color), ground = int(kind).equal(1);
11
+ const t = select(ground, u.uGroundTint, u.uFoliageTint), m = select(ground, u.uGroundMix, u.uFoliageMix);
12
+ return select(m.greaterThan(0), mix(c, t, m), c.mul(t));
13
+ });