create-threenative 0.2.2 → 0.2.4

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 (588) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +61 -2
  3. package/agent-docs/references/assertion-reference.md +819 -0
  4. package/agent-docs/references/capability-reference.md +4483 -0
  5. package/agent-docs/references/capture-the-frame.md +60 -0
  6. package/agent-docs/references/creating-creatures.md +215 -0
  7. package/agent-docs/references/ctx-cookbook.md +120 -0
  8. package/agent-docs/references/debug-surface.md +68 -0
  9. package/agent-docs/references/dream-loop.md +150 -0
  10. package/agent-docs/references/finding-assets.md +215 -0
  11. package/agent-docs/references/gameplay-recipes.md +54 -0
  12. package/agent-docs/references/menu-screens.md +69 -0
  13. package/agent-docs/references/mobile-memory-budget.md +87 -0
  14. package/agent-docs/references/sculpt-from-a-reference.md +40 -0
  15. package/agent-docs/references/trace-a-slow-frame.md +99 -0
  16. package/agent-docs/references/visual-baseline.md +174 -0
  17. package/agent-docs/references/webview-ui.md +113 -0
  18. package/agent-files/.agents/skills/file-engine-bug/SKILL.md +59 -0
  19. package/agent-files/.agents/skills/prd-creator/SKILL.md +40 -0
  20. package/agent-files/.agents/skills/threenative-assets/SKILL.md +45 -0
  21. package/agent-files/.agents/skills/threenative-builder/SKILL.md +7 -0
  22. package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +27 -0
  23. package/agent-files/.agents/skills/threenative-context/SKILL.md +57 -0
  24. package/agent-files/.agents/skills/threenative-performance/SKILL.md +42 -0
  25. package/agent-files/.agents/skills/threenative-playtest/SKILL.md +44 -0
  26. package/agent-files/.agents/skills/threenative-ui/SKILL.md +20 -0
  27. package/agent-files/.agents/skills/threenative-verifier/SKILL.md +7 -0
  28. package/agent-files/.agents/skills/threenative-visuals/SKILL.md +41 -0
  29. package/agent-files/.claude/agents/threenative-builder.md +7 -0
  30. package/agent-files/.claude/agents/threenative-verifier.md +7 -0
  31. package/agent-files/.claude/skills/file-engine-bug/SKILL.md +59 -0
  32. package/agent-files/.claude/skills/prd-creator/SKILL.md +40 -0
  33. package/agent-files/.claude/skills/threenative-assets/SKILL.md +45 -0
  34. package/agent-files/.claude/skills/threenative-capabilities/SKILL.md +27 -0
  35. package/agent-files/.claude/skills/threenative-context/SKILL.md +57 -0
  36. package/agent-files/.claude/skills/threenative-performance/SKILL.md +42 -0
  37. package/agent-files/.claude/skills/threenative-playtest/SKILL.md +44 -0
  38. package/agent-files/.claude/skills/threenative-ui/SKILL.md +20 -0
  39. package/agent-files/.claude/skills/threenative-visuals/SKILL.md +41 -0
  40. package/agent-files/.threenative/agents/builder.md +32 -0
  41. package/agent-files/.threenative/agents/verifier.md +31 -0
  42. package/agent-files/AGENT-ROLES.md +26 -0
  43. package/agent-files/scripts/reference.mjs +705 -0
  44. package/agent-files/scripts/visual-loop.mjs +382 -0
  45. package/capabilities.json +5292 -0
  46. package/dist/index.d.ts +224 -3
  47. package/dist/index.js +1972 -73
  48. package/dist/threenative.d.ts +9 -2
  49. package/dist/threenative.js +2570 -176
  50. package/package.json +55 -6
  51. package/template-assets/icon.png +0 -0
  52. package/template-assets/loading.ts +325 -0
  53. package/template-assets/patches/three@0.185.1.patch +522 -0
  54. package/template-assets/worldEnvironment.ts +758 -0
  55. package/templates/action-rpg/.codex/config.toml +19 -0
  56. package/templates/action-rpg/.cursor/mcp.json +32 -0
  57. package/templates/action-rpg/.gemini/settings.json +32 -0
  58. package/templates/action-rpg/.mcp.json +18 -2
  59. package/templates/action-rpg/.vscode/mcp.json +36 -0
  60. package/templates/action-rpg/.zed/settings.json +36 -0
  61. package/templates/action-rpg/AGENTS.md +84 -29
  62. package/templates/action-rpg/CLAUDE.md +84 -29
  63. package/templates/action-rpg/index.html +0 -1
  64. package/templates/action-rpg/opencode.json +41 -0
  65. package/templates/action-rpg/package.json +15 -11
  66. package/templates/action-rpg/playtests/combat.playtest.json +32 -9
  67. package/templates/action-rpg/playtests/fail.playtest.json +3 -3
  68. package/templates/action-rpg/playtests/inventory.playtest.json +16 -10
  69. package/templates/action-rpg/playtests/performance.playtest.json +39 -0
  70. package/templates/action-rpg/playtests/progress.playtest.json +18 -13
  71. package/templates/action-rpg/playtests/survives.playtest.json +27 -0
  72. package/templates/action-rpg/playtests/touch-controls.playtest.json +42 -0
  73. package/templates/action-rpg/playtests/win.playtest.json +10 -4
  74. package/templates/action-rpg/src/conventions.ts +35 -0
  75. package/templates/action-rpg/src/entities/Enemy.ts +16 -7
  76. package/templates/action-rpg/src/entities/Player.ts +20 -3
  77. package/templates/action-rpg/src/game.ts +21 -0
  78. package/templates/action-rpg/src/render/camera.ts +7 -2
  79. package/templates/action-rpg/src/render/lighting.ts +11 -4
  80. package/templates/action-rpg/src/render/loading.ts +278 -43
  81. package/templates/action-rpg/src/render/materials.ts +11 -0
  82. package/templates/action-rpg/src/render/palette.ts +10 -3
  83. package/templates/action-rpg/src/render/postprocessing.ts +32 -16
  84. package/templates/action-rpg/src/render/quality.ts +170 -0
  85. package/templates/action-rpg/src/render/shapes.ts +185 -26
  86. package/templates/action-rpg/src/render/touch-controls.ts +185 -0
  87. package/templates/action-rpg/src/render/vfx.ts +257 -0
  88. package/templates/action-rpg/src/render/worldEnvironment.ts +758 -0
  89. package/templates/action-rpg/src/scenes/Play.ts +91 -24
  90. package/templates/action-rpg/src/state.ts +4 -0
  91. package/templates/action-rpg/src/style.css +65 -1
  92. package/templates/action-rpg/src/ui/AbilityBar.tsx +9 -7
  93. package/templates/action-rpg/src/ui/App.tsx +9 -8
  94. package/templates/action-rpg/src/ui/CharacterPanel.tsx +10 -8
  95. package/templates/action-rpg/src/ui/GameUi.tsx +24 -0
  96. package/templates/action-rpg/src/ui/Hud.tsx +10 -8
  97. package/templates/action-rpg/src/ui/InventoryPanel.tsx +9 -7
  98. package/templates/action-rpg/src/ui/main.tsx +14 -0
  99. package/templates/action-rpg/threenative.config.ts +28 -8
  100. package/templates/action-rpg/vite.config.ts +32 -2
  101. package/templates/defense/.codex/config.toml +19 -0
  102. package/templates/defense/.cursor/mcp.json +32 -0
  103. package/templates/defense/.gemini/settings.json +32 -0
  104. package/templates/defense/.mcp.json +18 -2
  105. package/templates/defense/.vscode/mcp.json +36 -0
  106. package/templates/defense/.zed/settings.json +36 -0
  107. package/templates/defense/AGENTS.md +81 -41
  108. package/templates/defense/CLAUDE.md +81 -41
  109. package/templates/defense/README.md +2 -1
  110. package/templates/defense/index.html +0 -1
  111. package/templates/defense/opencode.json +41 -0
  112. package/templates/defense/package.json +16 -12
  113. package/templates/defense/playtests/leak.playtest.json +9 -4
  114. package/templates/defense/playtests/performance.playtest.json +39 -0
  115. package/templates/defense/playtests/placement.playtest.json +5 -5
  116. package/templates/defense/playtests/pointer-placement.playtest.json +156 -0
  117. package/templates/defense/playtests/scan.playtest.json +4 -4
  118. package/templates/defense/playtests/survive.playtest.json +25 -6
  119. package/templates/defense/src/attackers/Attacker.ts +32 -16
  120. package/templates/defense/src/board/Route.ts +22 -8
  121. package/templates/defense/src/conventions.ts +18 -0
  122. package/templates/defense/src/entities/Player.ts +11 -3
  123. package/templates/defense/src/game.ts +25 -4
  124. package/templates/defense/src/physics.ts +9 -39
  125. package/templates/defense/src/placement/Buildable.ts +4 -4
  126. package/templates/defense/src/render/camera.ts +9 -3
  127. package/templates/defense/src/render/lighting.ts +6 -1
  128. package/templates/defense/src/render/loading.ts +274 -38
  129. package/templates/defense/src/render/materials.ts +9 -0
  130. package/templates/defense/src/render/palette.ts +12 -5
  131. package/templates/defense/src/render/postprocessing.ts +32 -12
  132. package/templates/defense/src/render/quality.ts +170 -0
  133. package/templates/defense/src/render/shapes.ts +180 -23
  134. package/templates/defense/src/render/sky.ts +2 -2
  135. package/templates/defense/src/render/worldEnvironment.ts +758 -0
  136. package/templates/defense/src/scenes/Boot.ts +2 -2
  137. package/templates/defense/src/scenes/Defense.ts +122 -56
  138. package/templates/defense/src/state.ts +6 -0
  139. package/templates/defense/src/style.css +65 -1
  140. package/templates/defense/src/towers/Tower.ts +11 -12
  141. package/templates/defense/src/towers/targeting.ts +1 -1
  142. package/templates/defense/src/ui/App.tsx +11 -6
  143. package/templates/defense/src/ui/GameUi.tsx +20 -0
  144. package/templates/defense/src/ui/Hud.tsx +6 -5
  145. package/templates/defense/src/ui/main.tsx +14 -0
  146. package/templates/defense/threenative.config.ts +28 -8
  147. package/templates/defense/vite.config.ts +34 -1
  148. package/templates/minimal/.codex/config.toml +19 -0
  149. package/templates/minimal/.cursor/mcp.json +32 -0
  150. package/templates/minimal/.gemini/settings.json +32 -0
  151. package/templates/minimal/.mcp.json +18 -2
  152. package/templates/minimal/.vscode/mcp.json +36 -0
  153. package/templates/minimal/.zed/settings.json +36 -0
  154. package/templates/minimal/AGENTS.md +78 -382
  155. package/templates/minimal/CLAUDE.md +78 -382
  156. package/templates/minimal/index.html +0 -1
  157. package/templates/minimal/opencode.json +41 -0
  158. package/templates/minimal/package.json +14 -11
  159. package/templates/minimal/playtests/atmosphere.playtest.json +32 -0
  160. package/templates/minimal/playtests/play.playtest.json +18 -5
  161. package/templates/minimal/playtests/survives.playtest.json +48 -4
  162. package/templates/minimal/playtests/touch-controls.playtest.json +42 -0
  163. package/templates/minimal/src/conventions.ts +18 -0
  164. package/templates/minimal/src/entities/Player.ts +39 -6
  165. package/templates/minimal/src/game.ts +1 -0
  166. package/templates/minimal/src/main.ts +14 -4
  167. package/templates/minimal/src/render/camera.ts +1 -1
  168. package/templates/minimal/src/render/hud.ts +24 -8
  169. package/templates/minimal/src/render/lighting.ts +23 -2
  170. package/templates/minimal/src/render/loading.ts +23 -103
  171. package/templates/minimal/src/render/materials.ts +7 -0
  172. package/templates/minimal/src/render/palette.ts +3 -3
  173. package/templates/minimal/src/render/postprocessing.ts +55 -16
  174. package/templates/minimal/src/render/quality.ts +162 -0
  175. package/templates/minimal/src/render/sky.ts +51 -32
  176. package/templates/minimal/src/render/touch-controls.ts +165 -0
  177. package/templates/minimal/src/render/worldEnvironment.ts +758 -0
  178. package/templates/minimal/src/scenes/Play.ts +128 -14
  179. package/templates/minimal/src/state.ts +8 -1
  180. package/templates/minimal/src/style.css +20 -0
  181. package/templates/minimal/threenative.config.ts +22 -10
  182. package/templates/minimal/vite.config.ts +28 -1
  183. package/templates/platformer/.codex/config.toml +19 -0
  184. package/templates/platformer/.cursor/mcp.json +32 -0
  185. package/templates/platformer/.gemini/settings.json +32 -0
  186. package/templates/platformer/.mcp.json +18 -2
  187. package/templates/platformer/.vscode/mcp.json +36 -0
  188. package/templates/platformer/.zed/settings.json +36 -0
  189. package/templates/platformer/AGENTS.md +81 -186
  190. package/templates/platformer/CLAUDE.md +81 -186
  191. package/templates/platformer/index.html +0 -1
  192. package/templates/platformer/opencode.json +41 -0
  193. package/templates/platformer/package.json +17 -14
  194. package/templates/platformer/playtests/avoidance.playtest.json +6 -1
  195. package/templates/platformer/playtests/branding.playtest.json +29 -0
  196. package/templates/platformer/playtests/buffer.playtest.json +1 -1
  197. package/templates/platformer/playtests/collect.playtest.json +1 -1
  198. package/templates/platformer/playtests/collision-layers.playtest.json +2 -2
  199. package/templates/platformer/playtests/coyote.playtest.json +42 -8
  200. package/templates/platformer/playtests/damage.playtest.json +4 -1
  201. package/templates/platformer/playtests/dash.playtest.json +2 -2
  202. package/templates/platformer/playtests/jump.playtest.json +2 -3
  203. package/templates/platformer/playtests/native/touch-controls.playtest.json +33 -0
  204. package/templates/platformer/playtests/oneway.playtest.json +30 -3
  205. package/templates/platformer/playtests/performance.playtest.json +7 -5
  206. package/templates/platformer/playtests/respawn.playtest.json +2 -2
  207. package/templates/platformer/playtests/stomp-rise.playtest.json +17 -3
  208. package/templates/platformer/playtests/stomp.playtest.json +11 -3
  209. package/templates/platformer/playtests/survives.playtest.json +31 -0
  210. package/templates/platformer/playtests/terminal-loop-fail.playtest.json +16 -4
  211. package/templates/platformer/playtests/terminal-loop-win.playtest.json +3 -3
  212. package/templates/platformer/playtests/touch-controls-web.playtest.json +57 -0
  213. package/templates/platformer/src/conventions.ts +18 -0
  214. package/templates/platformer/src/entities/Character.ts +79 -11
  215. package/templates/platformer/src/entities/Patrol.ts +5 -0
  216. package/templates/platformer/src/game.ts +27 -2
  217. package/templates/platformer/src/level/Platform.ts +13 -1
  218. package/templates/platformer/src/render/lighting.ts +13 -5
  219. package/templates/platformer/src/render/loading.ts +281 -62
  220. package/templates/platformer/src/render/palette.ts +4 -1
  221. package/templates/platformer/src/render/postprocessing.ts +42 -14
  222. package/templates/platformer/src/render/quality.ts +170 -0
  223. package/templates/platformer/src/render/touch-controls.ts +54 -36
  224. package/templates/platformer/src/render/worldEnvironment.ts +758 -0
  225. package/templates/platformer/src/scenes/Level.ts +97 -32
  226. package/templates/platformer/src/state.ts +4 -0
  227. package/templates/platformer/src/style.css +65 -1
  228. package/templates/platformer/src/ui/App.tsx +9 -4
  229. package/templates/platformer/src/ui/GameUi.tsx +20 -0
  230. package/templates/platformer/src/ui/Hud.tsx +6 -5
  231. package/templates/platformer/src/ui/main.tsx +14 -0
  232. package/templates/platformer/threenative.config.ts +27 -10
  233. package/templates/platformer/vite.config.ts +34 -1
  234. package/templates/puzzle/.codex/config.toml +19 -0
  235. package/templates/puzzle/.cursor/mcp.json +32 -0
  236. package/templates/puzzle/.gemini/settings.json +32 -0
  237. package/templates/puzzle/.mcp.json +32 -0
  238. package/templates/puzzle/.vscode/mcp.json +36 -0
  239. package/templates/puzzle/.zed/settings.json +36 -0
  240. package/templates/puzzle/AGENTS.md +96 -0
  241. package/templates/puzzle/CLAUDE.md +98 -0
  242. package/templates/puzzle/README.md +43 -0
  243. package/templates/puzzle/index.html +12 -0
  244. package/templates/puzzle/kit.json +7 -0
  245. package/templates/puzzle/opencode.json +41 -0
  246. package/templates/puzzle/package.json +50 -0
  247. package/templates/puzzle/playtests/carry.playtest.json +71 -0
  248. package/templates/puzzle/playtests/performance.playtest.json +23 -0
  249. package/templates/puzzle/playtests/survives.playtest.json +51 -0
  250. package/templates/puzzle/playtests/swing.playtest.json +38 -0
  251. package/templates/puzzle/public/favicon.svg +5 -0
  252. package/templates/puzzle/src/conventions.ts +25 -0
  253. package/templates/puzzle/src/entities/Ball.ts +70 -0
  254. package/templates/puzzle/src/entities/Crate.ts +76 -0
  255. package/templates/puzzle/src/entities/Gripper.ts +69 -0
  256. package/templates/puzzle/src/entities/Pendulum.ts +89 -0
  257. package/templates/puzzle/src/game.ts +48 -0
  258. package/templates/puzzle/src/main.ts +15 -0
  259. package/templates/puzzle/src/physics.ts +19 -0
  260. package/templates/puzzle/src/render/camera.ts +37 -0
  261. package/templates/puzzle/src/render/lighting.ts +55 -0
  262. package/templates/puzzle/src/render/loading.ts +325 -0
  263. package/templates/puzzle/src/render/materials.ts +28 -0
  264. package/templates/puzzle/src/render/palette.ts +31 -0
  265. package/templates/puzzle/src/render/postprocessing.ts +34 -0
  266. package/templates/puzzle/src/render/quality.ts +170 -0
  267. package/templates/puzzle/src/render/shapes.ts +134 -0
  268. package/templates/puzzle/src/render/sky.ts +16 -0
  269. package/templates/puzzle/src/render/touch-controls.ts +185 -0
  270. package/templates/puzzle/src/render/worldEnvironment.ts +758 -0
  271. package/templates/puzzle/src/room.ts +83 -0
  272. package/templates/puzzle/src/scenes/Boot.ts +12 -0
  273. package/templates/puzzle/src/scenes/Puzzle.ts +158 -0
  274. package/templates/puzzle/src/state.ts +30 -0
  275. package/templates/puzzle/src/style.css +96 -0
  276. package/templates/puzzle/src/ui/App.tsx +22 -0
  277. package/templates/puzzle/src/ui/GameUi.tsx +20 -0
  278. package/templates/puzzle/src/ui/Hud.tsx +57 -0
  279. package/templates/puzzle/src/ui/Menu.tsx +7 -0
  280. package/templates/puzzle/src/ui/main.tsx +14 -0
  281. package/templates/puzzle/tailwind.config.ts +1 -0
  282. package/templates/puzzle/threenative.config.ts +49 -0
  283. package/templates/puzzle/tsconfig.json +17 -0
  284. package/templates/puzzle/vite.config.ts +38 -0
  285. package/templates/racing/.codex/config.toml +19 -0
  286. package/templates/racing/.cursor/mcp.json +32 -0
  287. package/templates/racing/.gemini/settings.json +32 -0
  288. package/templates/racing/.mcp.json +18 -2
  289. package/templates/racing/.vscode/mcp.json +36 -0
  290. package/templates/racing/.zed/settings.json +36 -0
  291. package/templates/racing/AGENTS.md +84 -36
  292. package/templates/racing/CLAUDE.md +84 -36
  293. package/templates/racing/index.html +0 -1
  294. package/templates/racing/native-playtests/survives.playtest.json +43 -0
  295. package/templates/racing/opencode.json +41 -0
  296. package/templates/racing/package.json +17 -12
  297. package/templates/racing/playtests/boost.playtest.json +5 -5
  298. package/templates/racing/playtests/outcome.playtest.json +14 -4
  299. package/templates/racing/playtests/performance.playtest.json +39 -0
  300. package/templates/racing/playtests/ranking.playtest.json +2 -2
  301. package/templates/racing/playtests/rescue.playtest.json +12 -6
  302. package/templates/racing/playtests/reverse.playtest.json +3 -3
  303. package/templates/racing/playtests/shortcut.playtest.json +3 -3
  304. package/templates/racing/playtests/survives.playtest.json +36 -4
  305. package/templates/racing/playtests/touch-controls.playtest.json +41 -0
  306. package/templates/racing/src/conventions.ts +6 -0
  307. package/templates/racing/src/entities/RacingCar.ts +16 -4
  308. package/templates/racing/src/entities/Rival.ts +5 -2
  309. package/templates/racing/src/game.ts +24 -1
  310. package/templates/racing/src/render/camera.ts +15 -8
  311. package/templates/racing/src/render/lighting.ts +28 -14
  312. package/templates/racing/src/render/loading.ts +302 -35
  313. package/templates/racing/src/render/materials.ts +54 -4
  314. package/templates/racing/src/render/palette.ts +23 -6
  315. package/templates/racing/src/render/postprocessing.ts +32 -12
  316. package/templates/racing/src/render/quality.ts +170 -0
  317. package/templates/racing/src/render/shapes.ts +537 -26
  318. package/templates/racing/src/render/sky.ts +5 -2
  319. package/templates/racing/src/render/touch-controls.ts +185 -0
  320. package/templates/racing/src/render/worldEnvironment.ts +758 -0
  321. package/templates/racing/src/scenes/Race.ts +84 -37
  322. package/templates/racing/src/state.ts +4 -0
  323. package/templates/racing/src/style.css +65 -1
  324. package/templates/racing/src/track/Lap.ts +20 -9
  325. package/templates/racing/src/track/Ranking.ts +53 -14
  326. package/templates/racing/src/track/Track.ts +284 -32
  327. package/templates/racing/src/track/TrackSector.ts +14 -4
  328. package/templates/racing/src/ui/App.tsx +9 -4
  329. package/templates/racing/src/ui/GameUi.tsx +20 -0
  330. package/templates/racing/src/ui/Hud.tsx +6 -5
  331. package/templates/racing/src/ui/main.tsx +14 -0
  332. package/templates/racing/threenative.config.ts +28 -8
  333. package/templates/racing/vite.config.ts +34 -1
  334. package/templates/runner/.codex/config.toml +19 -0
  335. package/templates/runner/.cursor/mcp.json +32 -0
  336. package/templates/runner/.gemini/settings.json +32 -0
  337. package/templates/runner/.mcp.json +32 -0
  338. package/templates/runner/.vscode/mcp.json +36 -0
  339. package/templates/runner/.zed/settings.json +36 -0
  340. package/templates/runner/AGENTS.md +96 -0
  341. package/templates/runner/CLAUDE.md +98 -0
  342. package/templates/runner/README.md +43 -0
  343. package/templates/runner/index.html +12 -0
  344. package/templates/runner/kit.json +7 -0
  345. package/templates/runner/opencode.json +41 -0
  346. package/templates/runner/package.json +50 -0
  347. package/templates/runner/playtests/performance.playtest.json +23 -0
  348. package/templates/runner/playtests/streams.playtest.json +38 -0
  349. package/templates/runner/playtests/survives.playtest.json +51 -0
  350. package/templates/runner/public/favicon.svg +5 -0
  351. package/templates/runner/src/conventions.ts +24 -0
  352. package/templates/runner/src/entities/Runner.ts +135 -0
  353. package/templates/runner/src/game.ts +50 -0
  354. package/templates/runner/src/main.ts +15 -0
  355. package/templates/runner/src/physics.ts +13 -0
  356. package/templates/runner/src/render/camera.ts +39 -0
  357. package/templates/runner/src/render/dust.ts +131 -0
  358. package/templates/runner/src/render/lighting.ts +57 -0
  359. package/templates/runner/src/render/loading.ts +325 -0
  360. package/templates/runner/src/render/materials.ts +27 -0
  361. package/templates/runner/src/render/palette.ts +30 -0
  362. package/templates/runner/src/render/postprocessing.ts +34 -0
  363. package/templates/runner/src/render/quality.ts +170 -0
  364. package/templates/runner/src/render/shapes.ts +68 -0
  365. package/templates/runner/src/render/sky.ts +51 -0
  366. package/templates/runner/src/render/touch-controls.ts +185 -0
  367. package/templates/runner/src/render/worldEnvironment.ts +758 -0
  368. package/templates/runner/src/scenes/Boot.ts +12 -0
  369. package/templates/runner/src/scenes/Run.ts +142 -0
  370. package/templates/runner/src/state.ts +29 -0
  371. package/templates/runner/src/style.css +96 -0
  372. package/templates/runner/src/track.ts +176 -0
  373. package/templates/runner/src/ui/App.tsx +22 -0
  374. package/templates/runner/src/ui/GameUi.tsx +20 -0
  375. package/templates/runner/src/ui/Hud.tsx +55 -0
  376. package/templates/runner/src/ui/Menu.tsx +7 -0
  377. package/templates/runner/src/ui/main.tsx +14 -0
  378. package/templates/runner/tailwind.config.ts +1 -0
  379. package/templates/runner/threenative.config.ts +49 -0
  380. package/templates/runner/tsconfig.json +17 -0
  381. package/templates/runner/vite.config.ts +38 -0
  382. package/templates/sailing/.codex/config.toml +19 -0
  383. package/templates/sailing/.cursor/mcp.json +32 -0
  384. package/templates/sailing/.gemini/settings.json +32 -0
  385. package/templates/sailing/.mcp.json +32 -0
  386. package/templates/sailing/.vscode/mcp.json +36 -0
  387. package/templates/sailing/.zed/settings.json +36 -0
  388. package/templates/sailing/AGENTS.md +95 -0
  389. package/templates/sailing/CLAUDE.md +97 -0
  390. package/templates/sailing/README.md +28 -0
  391. package/templates/sailing/index.html +12 -0
  392. package/templates/sailing/kit.json +7 -0
  393. package/templates/sailing/native-playtests/float.playtest.json +55 -0
  394. package/templates/sailing/native-playtests/survives.playtest.json +38 -0
  395. package/templates/sailing/opencode.json +41 -0
  396. package/templates/sailing/package.json +52 -0
  397. package/templates/sailing/playtests/fail.playtest.json +24 -0
  398. package/templates/sailing/playtests/float-after-the-run-ends.playtest.json +75 -0
  399. package/templates/sailing/playtests/float.playtest.json +59 -0
  400. package/templates/sailing/playtests/performance.playtest.json +36 -0
  401. package/templates/sailing/playtests/survives.playtest.json +46 -0
  402. package/templates/sailing/playtests/touch-controls.playtest.json +48 -0
  403. package/templates/sailing/playtests/win.playtest.json +31 -0
  404. package/templates/sailing/public/favicon.svg +5 -0
  405. package/templates/sailing/src/conventions.ts +8 -0
  406. package/templates/sailing/src/entities/Ship.ts +233 -0
  407. package/templates/sailing/src/game.ts +40 -0
  408. package/templates/sailing/src/main.ts +15 -0
  409. package/templates/sailing/src/render/camera.ts +28 -0
  410. package/templates/sailing/src/render/lighting.ts +41 -0
  411. package/templates/sailing/src/render/loading.ts +325 -0
  412. package/templates/sailing/src/render/materials.ts +44 -0
  413. package/templates/sailing/src/render/ocean.ts +179 -0
  414. package/templates/sailing/src/render/palette.ts +17 -0
  415. package/templates/sailing/src/render/postprocessing.ts +34 -0
  416. package/templates/sailing/src/render/props.ts +602 -0
  417. package/templates/sailing/src/render/quality.ts +140 -0
  418. package/templates/sailing/src/render/sky.ts +37 -0
  419. package/templates/sailing/src/render/touch-controls.ts +142 -0
  420. package/templates/sailing/src/render/worldEnvironment.ts +758 -0
  421. package/templates/sailing/src/scenes/Boot.ts +12 -0
  422. package/templates/sailing/src/scenes/Sailing.ts +133 -0
  423. package/templates/sailing/src/state.ts +10 -0
  424. package/templates/sailing/src/style.css +81 -0
  425. package/templates/sailing/src/ui/App.tsx +15 -0
  426. package/templates/sailing/src/ui/GameUi.tsx +12 -0
  427. package/templates/sailing/src/ui/Hud.tsx +55 -0
  428. package/templates/sailing/src/ui/Menu.tsx +30 -0
  429. package/templates/sailing/src/ui/main.tsx +7 -0
  430. package/templates/sailing/tailwind.config.ts +2 -0
  431. package/templates/sailing/threenative.config.ts +40 -0
  432. package/templates/sailing/tsconfig.json +17 -0
  433. package/templates/sailing/vite.config.ts +34 -0
  434. package/templates/shooter/.codex/config.toml +19 -0
  435. package/templates/shooter/.cursor/mcp.json +32 -0
  436. package/templates/shooter/.gemini/settings.json +32 -0
  437. package/templates/shooter/.mcp.json +18 -2
  438. package/templates/shooter/.vscode/mcp.json +36 -0
  439. package/templates/shooter/.zed/settings.json +36 -0
  440. package/templates/shooter/AGENTS.md +81 -54
  441. package/templates/shooter/CLAUDE.md +81 -54
  442. package/templates/shooter/index.html +0 -1
  443. package/templates/shooter/kit.json +2 -2
  444. package/templates/shooter/opencode.json +41 -0
  445. package/templates/shooter/package.json +16 -11
  446. package/templates/shooter/playtests/combat.playtest.json +48 -0
  447. package/templates/shooter/playtests/fail.playtest.json +5 -4
  448. package/templates/shooter/playtests/input-control.playtest.json +261 -0
  449. package/templates/shooter/playtests/per-item.playtest.json +59 -0
  450. package/templates/shooter/playtests/performance.playtest.json +39 -0
  451. package/templates/shooter/playtests/shooter.playtest.json +31 -21
  452. package/templates/shooter/playtests/survives.playtest.json +28 -1
  453. package/templates/shooter/playtests/touch-controls.playtest.json +42 -0
  454. package/templates/shooter/playtests/weapon-cycle.playtest.json +164 -0
  455. package/templates/shooter/public/favicon.svg +1 -1
  456. package/templates/shooter/src/combat/damage.ts +1 -2
  457. package/templates/shooter/src/conventions.ts +51 -0
  458. package/templates/shooter/src/entities/Player.ts +235 -18
  459. package/templates/shooter/src/entities/Target.ts +2 -2
  460. package/templates/shooter/src/game.ts +35 -3
  461. package/templates/shooter/src/main.ts +3 -13
  462. package/templates/shooter/src/render/camera.ts +78 -18
  463. package/templates/shooter/src/render/decals.ts +211 -0
  464. package/templates/shooter/src/render/lighting.ts +13 -4
  465. package/templates/shooter/src/render/loading.ts +274 -35
  466. package/templates/shooter/src/render/materials.ts +56 -3
  467. package/templates/shooter/src/render/palette.ts +6 -3
  468. package/templates/shooter/src/render/postprocessing.ts +32 -17
  469. package/templates/shooter/src/render/quality.ts +170 -0
  470. package/templates/shooter/src/render/scale.ts +22 -0
  471. package/templates/shooter/src/render/shapes.ts +519 -60
  472. package/templates/shooter/src/render/sky.ts +5 -1
  473. package/templates/shooter/src/render/touch-controls.ts +305 -0
  474. package/templates/shooter/src/render/ui.css +119 -1
  475. package/templates/shooter/src/render/ui.ts +19 -3
  476. package/templates/shooter/src/render/vfx.ts +215 -0
  477. package/templates/shooter/src/render/worldEnvironment.ts +758 -0
  478. package/templates/shooter/src/scenes/Play.ts +385 -97
  479. package/templates/shooter/src/state.ts +18 -0
  480. package/templates/shooter/src/style.css +46 -0
  481. package/templates/shooter/src/ui/App.tsx +10 -12
  482. package/templates/shooter/src/ui/Crosshair.tsx +25 -0
  483. package/templates/shooter/src/ui/GameUi.tsx +22 -0
  484. package/templates/shooter/src/ui/Hud.tsx +14 -10
  485. package/templates/shooter/src/ui/Menu.tsx +24 -9
  486. package/templates/shooter/src/ui/main.tsx +15 -0
  487. package/templates/shooter/src/weapons/Hitscan.ts +3 -4
  488. package/templates/shooter/src/weapons/Projectile.ts +29 -13
  489. package/templates/shooter/src/weapons/Viewmodel.ts +275 -0
  490. package/templates/shooter/threenative.config.ts +28 -8
  491. package/templates/shooter/vite.config.ts +32 -2
  492. package/templates/starter/.codex/config.toml +19 -0
  493. package/templates/starter/.cursor/mcp.json +32 -0
  494. package/templates/starter/.gemini/settings.json +32 -0
  495. package/templates/starter/.mcp.json +18 -2
  496. package/templates/starter/.vscode/mcp.json +36 -0
  497. package/templates/starter/.zed/settings.json +36 -0
  498. package/templates/starter/AGENTS.md +72 -426
  499. package/templates/starter/CLAUDE.md +72 -426
  500. package/templates/starter/assets/pickup.wav +0 -0
  501. package/templates/starter/gitignore +4 -0
  502. package/templates/starter/index.html +0 -1
  503. package/templates/starter/native-playtests/react-hud.playtest.json +20 -0
  504. package/templates/starter/native-playtests/render-chain.playtest.json +81 -0
  505. package/templates/starter/opencode.json +41 -0
  506. package/templates/starter/package.json +16 -12
  507. package/templates/starter/playtests/assets.playtest.json +65 -0
  508. package/templates/starter/playtests/boot-failure.playtest.json +45 -0
  509. package/templates/starter/playtests/buffer.playtest.json +59 -9
  510. package/templates/starter/playtests/cloth.playtest.json +113 -0
  511. package/templates/starter/playtests/coyote.playtest.json +60 -8
  512. package/templates/starter/playtests/forward.playtest.json +29 -4
  513. package/templates/starter/playtests/gameover.playtest.json +66 -0
  514. package/templates/starter/playtests/goal.playtest.json +67 -0
  515. package/templates/starter/playtests/hot-reload.playtest.json +48 -8
  516. package/templates/starter/playtests/look.playtest.json +142 -10
  517. package/templates/starter/playtests/models-baseline.png +0 -0
  518. package/templates/starter/playtests/models.playtest.json +74 -0
  519. package/templates/starter/playtests/monitoring.playtest.json +38 -7
  520. package/templates/starter/playtests/odometer.playtest.json +54 -0
  521. package/templates/starter/playtests/pause.playtest.json +27 -4
  522. package/templates/starter/playtests/play.playtest.json +44 -7
  523. package/templates/starter/playtests/respawn.playtest.json +46 -6
  524. package/templates/starter/playtests/restart.playtest.json +65 -10
  525. package/templates/starter/playtests/seed.playtest.json +44 -8
  526. package/templates/starter/playtests/survives.playtest.json +48 -4
  527. package/templates/starter/playtests/textures-baseline.png +0 -0
  528. package/templates/starter/playtests/textures.playtest.json +74 -0
  529. package/templates/starter/playtests/touch-controls.playtest.json +42 -0
  530. package/templates/starter/playtests/zoom-pinch.playtest.json +86 -0
  531. package/templates/starter/playtests/zoom-wheel.playtest.json +59 -0
  532. package/templates/starter/src/conventions.ts +18 -0
  533. package/templates/starter/src/entities/Goal.ts +137 -0
  534. package/templates/starter/src/entities/Player.ts +111 -10
  535. package/templates/starter/src/game.ts +27 -0
  536. package/templates/starter/src/render/adaptiveQuality.ts +195 -0
  537. package/templates/starter/src/render/camera.ts +31 -5
  538. package/templates/starter/src/render/coast.ts +199 -0
  539. package/templates/starter/src/render/easing.ts +5 -0
  540. package/templates/starter/src/render/effects/gradualBackground.ts +48 -0
  541. package/templates/starter/src/render/effects/lensDistortion.ts +43 -0
  542. package/templates/starter/src/render/effects/sparkle.ts +49 -0
  543. package/templates/starter/src/render/hero.ts +88 -0
  544. package/templates/starter/src/render/implicitSurface.ts +199 -0
  545. package/templates/starter/src/render/kuwahara.ts +174 -0
  546. package/templates/starter/src/render/lighting.ts +10 -5
  547. package/templates/starter/src/render/loading.ts +325 -0
  548. package/templates/starter/src/render/materials.ts +39 -4
  549. package/templates/starter/src/render/outline.ts +141 -0
  550. package/templates/starter/src/render/painterly.ts +86 -0
  551. package/templates/starter/src/render/palette.ts +15 -6
  552. package/templates/starter/src/render/pennant.ts +54 -0
  553. package/templates/starter/src/render/postprocessing.ts +97 -15
  554. package/templates/starter/src/render/quality.ts +185 -0
  555. package/templates/starter/src/render/rockRidge.ts +198 -0
  556. package/templates/starter/src/render/rockRidge.worker.ts +77 -0
  557. package/templates/starter/src/render/scenery.ts +40 -0
  558. package/templates/starter/src/render/shapes.ts +9 -21
  559. package/templates/starter/src/render/textureLifetime.ts +53 -0
  560. package/templates/starter/src/render/touch-controls.ts +165 -0
  561. package/templates/starter/src/render/water.ts +38 -0
  562. package/templates/starter/src/render/watercolor.ts +85 -0
  563. package/templates/starter/src/render/worldEnvironment.ts +758 -0
  564. package/templates/starter/src/scenes/Play.ts +243 -46
  565. package/templates/starter/src/state.ts +12 -0
  566. package/templates/starter/src/style.css +72 -8
  567. package/templates/starter/src/ui/App.tsx +9 -6
  568. package/templates/starter/src/ui/GameUi.tsx +20 -0
  569. package/templates/starter/src/ui/Hud.tsx +52 -29
  570. package/templates/starter/src/ui/Menu.tsx +25 -23
  571. package/templates/starter/src/ui/main.tsx +14 -0
  572. package/templates/starter/threenative.config.ts +27 -9
  573. package/templates/starter/tools/look.mjs +109 -0
  574. package/templates/starter/vite.config.ts +32 -2
  575. package/templates/action-rpg/src/physics.ts +0 -40
  576. package/templates/minimal/assets/.gitkeep +0 -0
  577. package/templates/minimal/public/.gitkeep +0 -0
  578. package/templates/minimal/public/icon.png +0 -0
  579. package/templates/platformer/assets/.gitkeep +0 -0
  580. package/templates/platformer/public/.gitkeep +0 -0
  581. package/templates/platformer/public/icon.png +0 -0
  582. package/templates/shooter/src/physics.ts +0 -49
  583. package/templates/starter/assets/.gitkeep +0 -0
  584. package/templates/starter/public/.gitkeep +0 -0
  585. package/templates/starter/public/icon.png +0 -0
  586. package/templates/starter/public/pickup.ogg +0 -0
  587. /package/templates/starter/{public → assets}/native-proof.glb +0 -0
  588. /package/templates/starter/{public → assets}/native-proof.png +0 -0
@@ -0,0 +1,758 @@
1
+ // Generated for you: ordinary Three.js; ThreeNative does not read this file. Delete or
2
+ // rewrite it freely — every default in here is a starting point, not a framework look.
3
+ //
4
+ // `WorldEnvironment` is Godot's name for the node that says which lighting effects a scene
5
+ // runs and how strong they are, and the property names below are Godot's `Environment`
6
+ // properties where Godot has one (`ssr_enabled`, `glow_enabled`, `tonemap_mode`) and
7
+ // Three.js's node names where it does not (`ssgi`, `gtao`). Nothing here is a new word.
8
+ //
9
+ // What it owns: building the stage factories and handing them to
10
+ // `renderer.createRenderChain()`, which decides the order stages run in, whether each can
11
+ // run on this target, and prints `TN_RENDER_CHAIN` naming every stage as applied or
12
+ // refused **with a reason** — so a stage that silently no-op'd is never mistaken for one
13
+ // you turned off. What it does not own: any colour, and any strength that is not a quality
14
+ // tier. Those are arguments, supplied by `postprocessing.ts`, yours to change.
15
+
16
+ import {
17
+ ACESFilmicToneMapping,
18
+ AgXToneMapping,
19
+ type Camera,
20
+ type DirectionalLight,
21
+ NeutralToneMapping,
22
+ type PerspectiveCamera,
23
+ type Scene,
24
+ } from "three";
25
+ import { bloom } from "three/addons/tsl/display/BloomNode.js";
26
+ import { denoise } from "three/addons/tsl/display/DenoiseNode.js";
27
+ import { ao } from "three/addons/tsl/display/GTAONode.js";
28
+ import { godrays } from "three/addons/tsl/display/GodraysNode.js";
29
+ import { ssgi } from "three/addons/tsl/display/SSGINode.js";
30
+ import { ssr } from "three/addons/tsl/display/SSRNode.js";
31
+ import { sharpen } from "three/addons/tsl/display/SharpenNode.js";
32
+ import {
33
+ color,
34
+ convertToTexture,
35
+ float,
36
+ metalness,
37
+ mrt,
38
+ normalView,
39
+ output,
40
+ pass,
41
+ roughness,
42
+ screenUV,
43
+ smoothstep,
44
+ vec2,
45
+ } from "three/tsl";
46
+ import type { Node } from "three/webgpu";
47
+
48
+ /** Godot's `Environment.tonemap_mode`, with the modes Three.js actually ships. */
49
+ export type TonemapMode = "aces" | "agx" | "neutral";
50
+
51
+ /**
52
+ * SSGI sample budget. The three tiers are the presets SSGINode's own documentation
53
+ * recommends for the temporally-filtered case, not numbers invented here. An unknown
54
+ * tier throws rather than quietly becoming the default.
55
+ */
56
+ export type SsgiQuality = "low" | "medium" | "high";
57
+
58
+ const SSGI_QUALITY: Record<SsgiQuality, { sliceCount: number; stepCount: number }> = {
59
+ low: { sliceCount: 1, stepCount: 12 },
60
+ medium: { sliceCount: 2, stepCount: 8 },
61
+ high: { sliceCount: 3, stepCount: 16 },
62
+ };
63
+
64
+ const TONEMAP: Record<TonemapMode, number> = {
65
+ aces: ACESFilmicToneMapping,
66
+ agx: AgXToneMapping,
67
+ neutral: NeutralToneMapping,
68
+ };
69
+
70
+ export interface IWorldEnvironmentOptions {
71
+ /** Screen-space indirect diffuse light. Godot calls this `ssil_enabled`. */
72
+ readonly ssgiEnabled?: boolean;
73
+ readonly ssgiQuality?: SsgiQuality;
74
+ /** How much of the gathered indirect light reaches the frame. Godot's `ssil_intensity`. */
75
+ readonly ssgiIntensity?: number;
76
+ /** How far, in world units, indirect light is gathered from. Room scale, not contact scale. */
77
+ readonly ssgiRadius?: number;
78
+ /** Screen-space reflections. Godot's `ssr_enabled`. */
79
+ readonly ssrEnabled?: boolean;
80
+ /**
81
+ * How far, in world units, a reflection ray is traced.
82
+ *
83
+ * `SSRNode` defaults this to **1**, which is one metre. On any scene larger than a
84
+ * tabletop that reads as "screen-space reflections are on and do nothing" — the ray
85
+ * terminates before it reaches the thing that should be standing in the floor.
86
+ */
87
+ readonly ssrMaxDistance?: number;
88
+ /**
89
+ * Fraction of the display resolution the reflection is traced at.
90
+ *
91
+ * A reflection in a rough surface carries almost no high-frequency detail, so tracing it
92
+ * at half resolution costs a quarter of the rays and is very hard to see in the result.
93
+ */
94
+ readonly ssrResolutionScale?: number;
95
+ /** Spatial denoise over the SSGI result. Off is noisier and cheaper. */
96
+ readonly denoiseEnabled?: boolean;
97
+ /** Raymarched shafts. Needs `godraysLight`, and that light must cast shadows. */
98
+ readonly godraysEnabled?: boolean;
99
+ /** How dense the participating medium is. Higher is foggier — and the whole frame brighter. */
100
+ readonly godraysDensity?: number;
101
+ /**
102
+ * Haze below this value is discarded instead of added to the frame.
103
+ *
104
+ * Without it the pass is a uniform brightener rather than a shaft renderer: it returns a
105
+ * non-zero value for nearly every pixel, and that "something" is tiny in linear space and
106
+ * enormous after the tone curve, which lifts shadows hardest. Subtracting a floor keeps
107
+ * the air inside a real beam and discards the ambient lift.
108
+ */
109
+ readonly godraysFloor?: number;
110
+ /** Multiplier applied after the floor, so beams can be bright without the haze returning. */
111
+ readonly godraysIntensity?: number;
112
+ /**
113
+ * Raymarch steps per pixel. `GodraysNode` defaults to 60.
114
+ *
115
+ * Every step is a shadow-map sample, so this multiplies directly into the cost of the
116
+ * whole pass. The pass jitters its sample positions, so a lower count trades a hard shaft
117
+ * edge for a slightly noisier one rather than for banding — which the denoiser then
118
+ * largely absorbs.
119
+ */
120
+ readonly godraysSteps?: number;
121
+ /**
122
+ * Ceiling on shaft brightness.
123
+ *
124
+ * This is also the single strongest control over how bright the *whole* scene looks: the
125
+ * pass adds its accumulated illumination to every pixel, not only to the pixels inside a
126
+ * visible beam, so raising it raises the shadow floor of the entire frame.
127
+ */
128
+ readonly godraysMaxDensity?: number;
129
+ /**
130
+ * Ground-truth ambient occlusion, at contact scale. Godot's `ssao_enabled`.
131
+ *
132
+ * Deliberately a *second* occlusion term next to the one SSGI already produces. SSGI's AO
133
+ * is gathered over `ssgiRadius` — metres — the right scale for "this hall is enclosed"
134
+ * and the wrong one for "this foot is standing on this floor". This pass runs at a radius
135
+ * of centimetres and multiplies on top.
136
+ */
137
+ readonly gtaoEnabled?: boolean;
138
+ /** Occlusion gather radius in world units. Contact scale, not room scale. */
139
+ readonly gtaoRadius?: number;
140
+ /** Exponent on the occlusion term: higher is a darker, tighter contact. */
141
+ readonly gtaoScale?: number;
142
+ /** Directions sampled per pixel. Cost is linear in this. */
143
+ readonly gtaoSamples?: number;
144
+ /** Fraction of display resolution the occlusion is traced at. */
145
+ readonly gtaoResolutionScale?: number;
146
+ /**
147
+ * The fraction of the frame SSGI actually gathers at. Half by default.
148
+ *
149
+ * `GTAONode` and `SSRNode` both carry a `resolutionScale` of their own; **`SSGINode` does not**,
150
+ * and its `setSize` passes width and height straight into its render target with no factor. So
151
+ * screen-space GI — a low-frequency effect every production renderer gathers at half or quarter
152
+ * res — was the only stage in this chain running at full resolution, and it cost accordingly.
153
+ *
154
+ * Measured on a 46,190-instance forest at 1600x900 on an RTX 2080, with the resolution scaler
155
+ * left on auto so the engine's own verdict is part of the result:
156
+ *
157
+ * fps still/walk scale it settled on interior median dead shadow
158
+ * full res 38.0 / 47.2 0.44 704x396 0.0299 19.19%
159
+ * off 60.0 / 60.0 0.61 976x549 0.0987 4.54%
160
+ * half res 59.8 / 60.0 0.72 1152x648 0.0301 18.58%
161
+ *
162
+ * Half res is better than both: it holds the budget like switching SSGI off, keeps the look
163
+ * within noise of full res, and produces the *sharpest* frame of the three — because the budget
164
+ * it hands back is spent by the scaler on pixels rather than on a gather nobody can see at full
165
+ * rate. Full-res SSGI was not buying quality, it was trading it.
166
+ *
167
+ * Fixed without touching three: `setSize` is public and the pass drives the node through it with
168
+ * the full frame size, so the instance is wrapped to hand it a smaller one. The node's own maths
169
+ * reads the `_resolution` uniform that `setSize` writes, so it stays self-consistent, and the
170
+ * result is sampled by UV rather than by texel — which is what makes the upsample free and is
171
+ * exactly the mechanism `GTAONode` uses internally.
172
+ */
173
+ readonly ssgiResolutionScale?: number;
174
+ /**
175
+ * Contrast-adaptive sharpening (RCAS) over the finished frame.
176
+ *
177
+ * Everything upstream of it blurs: the GI gather is denoised, the reflection is traced at
178
+ * reduced resolution and roughness-blurred. Each is worth its softness on its own and the
179
+ * sum is a frame with no micro-detail left. RCAS is contrast-adaptive, so it puts the
180
+ * edges back without ringing the soft areas.
181
+ */
182
+ readonly sharpenEnabled?: boolean;
183
+ /** RCAS sharpness. **0 is maximum sharpening and 2 is none** — it is a radius, not a gain. */
184
+ readonly sharpenStrength?: number;
185
+ /** Corner darkening, as a fraction removed at the extreme corner. Zero disables it. */
186
+ readonly vignetteAmount?: number;
187
+ /** Godot's `glow_enabled`. */
188
+ readonly bloomEnabled?: boolean;
189
+ readonly bloomStrength?: number;
190
+ /** How far a bright pixel bleeds, as a fraction of the screen. */
191
+ readonly bloomRadius?: number;
192
+ /** Luminance a pixel must exceed before it blooms at all. */
193
+ readonly bloomThreshold?: number;
194
+ /**
195
+ * Which of this kit's authored stages to run.
196
+ *
197
+ * Separate from the graph below, and not for tidiness: the chain has to know whether anything
198
+ * was requested at all before the scene pass exists — with nothing requested it sets an
199
+ * exposure and returns, and no pass is ever built. So the request is a static decision the kit
200
+ * makes from its own config, and only the graph needs the pass.
201
+ */
202
+ readonly authoredStageNames?: readonly string[];
203
+ /**
204
+ * This kit's own stages, composed after the built-ins.
205
+ *
206
+ * A factory because an authored stage needs the two things only this file can produce: the
207
+ * scene pass's depth texture node, which does not exist until the pass is built, and the
208
+ * resolved tier. It returns the complete graph — including stages left dormant this frame — so
209
+ * that an anchor like `watercolor after kuwahara` keeps naming a stage that exists.
210
+ *
211
+ * Naming specific stages here instead — an `outlineEnabled`, a `kuwaharaRadius` — is what put
212
+ * one kit's look inside the plumbing every kit copies verbatim, which
213
+ * `shared-render-sources.spec.ts` exists to refuse.
214
+ */
215
+ readonly authoredStages?: (context: IWorldEnvironmentStageContext) => readonly ChainStage[];
216
+ /** Quality tier passed to the measured chain; the quality module owns this value. */
217
+ readonly renderChainTier?: ChainTier;
218
+ readonly tonemapMode?: TonemapMode;
219
+ /**
220
+ * Scene-referred exposure: multiplied into the scene pass **before** the tone curve, so
221
+ * the GI gather, reflections and bloom threshold all see the exposed image and the bloom
222
+ * threshold means the same thing at any exposure.
223
+ *
224
+ * `renderer.toneMappingExposure` is live too (measured on three@0.185.1 — see
225
+ * `docs/verification/exposure-ab-2026-08-30.md`), and applies at the same point in the
226
+ * graph, but only when no output node is installed. When every stage here is off, this
227
+ * class falls back to that scalar; when any stage runs, this multiply is the shutter.
228
+ */
229
+ readonly exposure?: number;
230
+ }
231
+
232
+ export interface IWorldEnvironmentTarget {
233
+ /** The directional light godrays are raymarched against. Required only by `godraysEnabled`. */
234
+ readonly godraysLight?: DirectionalLight;
235
+ /**
236
+ * Composes the colour the chain starts from, given the scene pass it renders.
237
+ *
238
+ * The chain builds `pass(scene, camera)` itself, so a game that composes something onto the
239
+ * beauty pass before any stage runs — aerial perspective, read against that pass's own view-Z,
240
+ * is the one in these templates — has nowhere else to put it. The node returned here is the
241
+ * game's; the chain only decides where it is spliced in, which is first, ahead of exposure and
242
+ * every stage.
243
+ */
244
+ readonly baseColour?: (scenePass: ReturnType<typeof pass>) => Node<"vec4">;
245
+ }
246
+
247
+ /**
248
+ * What travels down the chain: the composed colour, as TSL's proxied vec4 node — the thing
249
+ * that carries `.mul`, `.add`, `.rgb` and `.r`. Every stage takes one and returns one, so the
250
+ * compiler checks the composition instead of taking a cast's word for it.
251
+ */
252
+ type ChainNode = Node<"vec4">;
253
+ /**
254
+ * The scene pass's depth texture, as the pass itself types it.
255
+ *
256
+ * Named through `pass()` rather than written out because the addon's return type is the only
257
+ * honest spelling of it, and a hand-written alias here would drift the first time three changes it.
258
+ */
259
+ export type DepthTextureNode = ReturnType<ReturnType<typeof pass>["getTextureNode"]>;
260
+ type ChainTier = "high" | "medium" | "low" | "off";
261
+ type ChainContext = {
262
+ readonly tier: ChainTier;
263
+ };
264
+ /**
265
+ * What a kit's `authoredStages` factory is handed. The depth node is the scene pass's, so a
266
+ * stage that reads depth gets the same texture the built-in stages read rather than its own.
267
+ */
268
+ export interface IWorldEnvironmentStageContext {
269
+ readonly depthNode: DepthTextureNode;
270
+ readonly tier: ChainTier;
271
+ }
272
+
273
+ export type ChainStage = {
274
+ readonly name: string;
275
+ readonly before?: string;
276
+ readonly after?: string;
277
+ readonly available?: (context: ChainContext) => boolean | string;
278
+ readonly dispose?: () => void;
279
+ readonly minimumTier?: ChainTier;
280
+ /** The chain plumbing is stage-agnostic, so it names the node it carries `unknown`. */
281
+ readonly build: (input: unknown, context: ChainContext) => unknown;
282
+ };
283
+
284
+ /**
285
+ * The one seam between the chain's `unknown` and this file's node algebra.
286
+ *
287
+ * What the chain hands a stage is the colour composed so far — the previous stage's return, or
288
+ * the exposed scene pass for the first one — and that is always a `ChainNode`. Saying so once,
289
+ * here, is what lets every stage below be written and *checked* as vec4-in, vec4-out instead of
290
+ * asserting its way through each expression. The wrapper adds no node to the graph.
291
+ */
292
+ function stage(definition: {
293
+ readonly name: ChainStage["name"];
294
+ readonly dispose?: () => void;
295
+ readonly available?: (context: ChainContext) => boolean | string;
296
+ readonly build: (input: ChainNode, context: ChainContext) => ChainNode;
297
+ }): ChainStage {
298
+ return {
299
+ ...definition,
300
+ build: (input, context) => definition.build(input as ChainNode, context),
301
+ };
302
+ }
303
+
304
+ /**
305
+ * `three/addons` declares each TSL stage as its raw node class, and `DenoiseNode` is the only
306
+ * one in this chain whose declaration omits the element API (`.mul`, `.rgb`, `.r`) that the
307
+ * proxied node object it actually hands back at runtime carries — every other stage here is a
308
+ * `ChainNode` on its own, checked by the compiler. This is an assertion and nothing else: no
309
+ * conversion runs, no node is added to the graph, so it cannot move a pixel.
310
+ */
311
+ function denoised(node: ReturnType<typeof denoise>): ChainNode {
312
+ return node as unknown as ChainNode;
313
+ }
314
+ export type OutputRenderer = {
315
+ kind: string;
316
+ raw: unknown;
317
+ /**
318
+ * Installs a node graph directly. Only reached when a `baseColour` is composed and every
319
+ * stage is off: the chain installs nothing for an empty stage list, and dropping the game's
320
+ * own composition on the floor would be the silent no-op this class exists to prevent.
321
+ */
322
+ setOutputNode?: (node: unknown) => void;
323
+ createRenderChain?: (options: {
324
+ input?: unknown;
325
+ worldPass?: unknown;
326
+ request?: { stages?: readonly string[]; tier?: ChainContext["tier"] };
327
+ stages?: readonly ChainStage[];
328
+ }) => {
329
+ applied: { dropped: readonly { name: string; reason: string }[]; stages: readonly string[] };
330
+ dispose(): void;
331
+ };
332
+ };
333
+
334
+ /**
335
+ * Builds a Godot-named lighting chain and installs it through the renderer's render chain.
336
+ *
337
+ * Every stage a game turns on reports itself: the chain prints `TN_RENDER_CHAIN` naming
338
+ * each requested stage as applied or refused with a reason that is never blank. A game with
339
+ * GI switched off on a WebGL fallback looks exactly like a game that chose not to use it —
340
+ * unless it reads that line.
341
+ */
342
+ export class WorldEnvironment {
343
+ readonly #options: Required<IWorldEnvironmentOptions>;
344
+
345
+ constructor(options: IWorldEnvironmentOptions = {}) {
346
+ const quality = options.ssgiQuality ?? "medium";
347
+ if (SSGI_QUALITY[quality] === undefined) {
348
+ // Fail closed. A typo'd tier that silently became "medium" is a quality setting
349
+ // nobody can trust afterwards.
350
+ throw new Error(
351
+ `Unknown ssgiQuality '${String(quality)}'. Use one of: ${Object.keys(SSGI_QUALITY).join(", ")}.`,
352
+ );
353
+ }
354
+ const tonemapMode = options.tonemapMode ?? "aces";
355
+ if (TONEMAP[tonemapMode] === undefined) {
356
+ throw new Error(
357
+ `Unknown tonemapMode '${String(tonemapMode)}'. Use one of: ${Object.keys(TONEMAP).join(", ")}.`,
358
+ );
359
+ }
360
+ const renderChainTier = options.renderChainTier ?? "high";
361
+ if (!isChainTier(renderChainTier)) {
362
+ throw new Error(
363
+ `Unknown render chain tier '${String(renderChainTier)}'. Use high, medium, low, or off.`,
364
+ );
365
+ }
366
+ this.#options = {
367
+ // A kit with no stages of its own is the common case, so both default to empty rather
368
+ // than to a branch every call site has to remember.
369
+ authoredStageNames: options.authoredStageNames ?? [],
370
+ authoredStages: options.authoredStages ?? (() => []),
371
+ ssgiEnabled: options.ssgiEnabled ?? false,
372
+ ssgiQuality: quality,
373
+ ssgiIntensity: options.ssgiIntensity ?? 1,
374
+ ssgiRadius: options.ssgiRadius ?? 12,
375
+ ssrEnabled: options.ssrEnabled ?? false,
376
+ ssrMaxDistance: options.ssrMaxDistance ?? 30,
377
+ ssrResolutionScale: options.ssrResolutionScale ?? 0.5,
378
+ denoiseEnabled: options.denoiseEnabled ?? true,
379
+ godraysEnabled: options.godraysEnabled ?? false,
380
+ godraysDensity: options.godraysDensity ?? 0.7,
381
+ godraysFloor: options.godraysFloor ?? 0,
382
+ godraysIntensity: options.godraysIntensity ?? 1,
383
+ godraysSteps: options.godraysSteps ?? 60,
384
+ godraysMaxDensity: options.godraysMaxDensity ?? 0.5,
385
+ gtaoEnabled: options.gtaoEnabled ?? false,
386
+ gtaoRadius: options.gtaoRadius ?? 0.25,
387
+ gtaoScale: options.gtaoScale ?? 1,
388
+ gtaoSamples: options.gtaoSamples ?? 16,
389
+ gtaoResolutionScale: options.gtaoResolutionScale ?? 1,
390
+ ssgiResolutionScale: options.ssgiResolutionScale ?? 0.5,
391
+ sharpenEnabled: options.sharpenEnabled ?? false,
392
+ sharpenStrength: options.sharpenStrength ?? 0.2,
393
+ vignetteAmount: options.vignetteAmount ?? 0,
394
+ bloomEnabled: options.bloomEnabled ?? true,
395
+ bloomStrength: options.bloomStrength ?? 0.7,
396
+ bloomRadius: options.bloomRadius ?? 0.5,
397
+ bloomThreshold: options.bloomThreshold ?? 0.2,
398
+ renderChainTier,
399
+ tonemapMode,
400
+ exposure: options.exposure ?? 1,
401
+ };
402
+ }
403
+
404
+ /**
405
+ * Installs the chain. Returns what actually ran — the same applied report the chain
406
+ * printed — so a scene can assert on it instead of scraping the console.
407
+ */
408
+ apply(
409
+ renderer: OutputRenderer,
410
+ scene: Scene,
411
+ camera: Camera,
412
+ target: IWorldEnvironmentTarget = {},
413
+ ): {
414
+ dropped: readonly { name: string; reason: string }[];
415
+ stages: readonly string[];
416
+ dispose?: () => void;
417
+ } {
418
+ const options = this.#options;
419
+ const raw = renderer.raw as { toneMapping?: number; toneMappingExposure?: number };
420
+ raw.toneMapping = TONEMAP[options.tonemapMode];
421
+
422
+ const requested: string[] = (
423
+ ["ssgi", "ambientOcclusion", "godRays", "ssr", "sharpen", "bloom", "vignette"] as const
424
+ ).filter(
425
+ (name) =>
426
+ (name === "ssgi" && options.ssgiEnabled) ||
427
+ (name === "ambientOcclusion" && options.gtaoEnabled) ||
428
+ (name === "godRays" && options.godraysEnabled) ||
429
+ (name === "ssr" && options.ssrEnabled) ||
430
+ (name === "sharpen" && options.sharpenEnabled) ||
431
+ (name === "bloom" && options.bloomEnabled) ||
432
+ (name === "vignette" && options.vignetteAmount > 0),
433
+ );
434
+ requested.push(...options.authoredStageNames);
435
+
436
+ // With no stage running there is no node graph to install — the renderer's own
437
+ // tone-mapping path renders the frame, and the exposure scalar is live there (measured:
438
+ // `docs/verification/exposure-ab-2026-08-30.md`). With any stage running, exposure is
439
+ // applied as a multiply on the scene pass instead: scene-referred, so every downstream
440
+ // stage sees the exposed image and the bloom threshold means the same thing at any
441
+ // exposure. Both land at the same point in the graph — before the tone curve.
442
+ if (requested.length === 0 && target.baseColour === undefined) {
443
+ raw.toneMappingExposure = options.exposure;
444
+ this.#reportApplied([], []);
445
+ return { dropped: [], stages: [] };
446
+ }
447
+ raw.toneMappingExposure = 1;
448
+
449
+ const scenePass = pass(scene, camera);
450
+ // Normals come from the multi-render-target alongside the colour. SSGI can derive them
451
+ // from depth alone, but the derived normal is flat across a triangle, which shows up as
452
+ // faceted bounce on exactly the smooth surfaces GI is bought for. Metalness and
453
+ // roughness ride along so SSR knows which pixels are supposed to reflect.
454
+ if (options.ssgiEnabled || options.ssrEnabled || options.gtaoEnabled) {
455
+ scenePass.setMRT(mrt({ output, normal: normalView, metalness, roughness }));
456
+ }
457
+ // Requested lazily, and this is not a micro-optimisation. **Asking a pass for `normal`,
458
+ // `metalness` or `roughness` is what creates the extra render target.** A tier that runs none
459
+ // of the stages needing them — the mobile look is bloom and the tone curve — must not ask, or
460
+ // the pass carries a colour target no fragment shader writes and WebGPU refuses the pipeline:
461
+ // *"Color target has no corresponding fragment stage output but writeMask … is not zero.
462
+ // While validating targets[1]"*. The frame then comes out **black** while the chain still
463
+ // reports every stage as applied, which is the worst shape a failure can take here.
464
+ const nodes = new Map<string, ReturnType<typeof scenePass.getTextureNode>>();
465
+ const textureNode = (name: string): ReturnType<typeof scenePass.getTextureNode> => {
466
+ const cached = nodes.get(name);
467
+ if (cached !== undefined) return cached;
468
+ const node = scenePass.getTextureNode(name);
469
+ nodes.set(name, node);
470
+ return node;
471
+ };
472
+ const depth = (): ReturnType<typeof scenePass.getTextureNode> => textureNode("depth");
473
+ const normal = (): ReturnType<typeof scenePass.getTextureNode> => textureNode("normal");
474
+ const metal = (): ReturnType<typeof scenePass.getTextureNode> => textureNode("metalness");
475
+ const rough = (): ReturnType<typeof scenePass.getTextureNode> => textureNode("roughness");
476
+ // Every stage here is perspective-camera maths — view-space reconstruction from depth,
477
+ // and a projection matrix inverse. The scene's camera is the one the pass rendered with.
478
+ const view = camera as PerspectiveCamera;
479
+
480
+ const base = target.baseColour?.(scenePass) ?? scenePass.getTextureNode("output");
481
+ const exposed = convertToTexture(base).mul(options.exposure);
482
+ const giDenoise = (node: ChainNode): ChainNode =>
483
+ options.denoiseEnabled ? denoised(denoise(node, depth(), normal(), view)) : node;
484
+
485
+ let releaseBloom = (): void => {};
486
+ const stages: ChainStage[] = [
487
+ stage({
488
+ name: "ssgi",
489
+ build: (input) => {
490
+ const gi = ssgi(input, depth(), normal(), view);
491
+ const tier = SSGI_QUALITY[options.ssgiQuality];
492
+ gi.sliceCount.value = tier.sliceCount;
493
+ gi.stepCount.value = tier.stepCount;
494
+ gi.radius.value = options.ssgiRadius;
495
+ // Gather at a fraction of the frame. See `ssgiResolutionScale` above for why this is a
496
+ // wrapper rather than a property: the node has no scale of its own, and `setSize` is the
497
+ // public seam the pass drives it through. `setSize` is present on the node and absent
498
+ // from its type declarations, so the seam is named here rather than cast away at the call
499
+ // site — if a future three release declares it, or gives the node a `resolutionScale`,
500
+ // this narrows to nothing and the wrapper can go. Guarded at one texel so a zero or a
501
+ // negative cannot ask for an empty target: a 0x0 gather returns black and reads as SSGI
502
+ // simply not working.
503
+ const ssgiScale = options.ssgiResolutionScale;
504
+ const sizedGi = gi as unknown as {
505
+ setSize?: (width: number, height: number) => void;
506
+ };
507
+ const fullGiSize = sizedGi.setSize?.bind(gi);
508
+ if (ssgiScale > 0 && ssgiScale < 1 && fullGiSize !== undefined) {
509
+ sizedGi.setSize = (width: number, height: number): void => {
510
+ fullGiSize(
511
+ Math.max(1, Math.round(width * ssgiScale)),
512
+ Math.max(1, Math.round(height * ssgiScale)),
513
+ );
514
+ };
515
+ }
516
+
517
+ // SSGI writes two targets: AO in a single-channel `RedFormat` texture, and the GI
518
+ // term in an RGB one. Multiplying the beauty pass by the whole AO vec4 therefore
519
+ // zeroes green and blue and the entire scene renders monochrome red — take `.r`
520
+ // for the scalar and `.rgb` for the colour.
521
+ //
522
+ // No albedo buffer here, so the beauty pass stands in for it: occlusion darkens
523
+ // what is already lit, and the gathered indirect light is tinted by the surface it
524
+ // lands on. That is the standard approximation, and it is why a red wall tints a
525
+ // white floor at all. `ssgiIntensity` is the game's dial on that second term —
526
+ // gathered light is unbounded, and a small white room at 1.0 blows out.
527
+ const occlusion = giDenoise(gi.getAONode());
528
+ const indirect = giDenoise(gi.getGINode());
529
+ return input.mul(occlusion.r).add(input.mul(indirect.rgb).mul(options.ssgiIntensity));
530
+ },
531
+ }),
532
+ stage({
533
+ name: "ambientOcclusion",
534
+ build: (input) => {
535
+ const contact = ao(depth(), normal(), view);
536
+ contact.radius.value = options.gtaoRadius;
537
+ contact.scale.value = options.gtaoScale;
538
+ contact.samples.value = options.gtaoSamples;
539
+ contact.resolutionScale = options.gtaoResolutionScale;
540
+ // `RedFormat`, like SSGI's AO target: `.r` is the whole occlusion term, and
541
+ // multiplying by the vec4 would zero green and blue and render the scene red.
542
+ // Applied before SSGI by the chain's canonical order; composing it after the GI
543
+ // combine instead darkens crevices the gather re-lit — that is a look choice, and
544
+ // this file is where you make it.
545
+ return input.mul(contact.r);
546
+ },
547
+ }),
548
+ stage({
549
+ name: "godRays",
550
+ available: () => {
551
+ // Godrays are raymarched against the light's shadow map: the shaft is the volume
552
+ // the shadow map reports as lit. A light that casts no shadow yields a black pass,
553
+ // which would read as "godrays are on and do nothing" — so refuse it by name.
554
+ const light = target.godraysLight;
555
+ if (light === undefined) return "godraysEnabled is true but no godraysLight was passed";
556
+ if (light.castShadow !== true)
557
+ return `light '${light.name || "sun"}' does not cast shadows`;
558
+ // `castShadow` is a request, not a result: three allocates the shadow map on the first
559
+ // render that needs it, and `GodraysNode` reads `shadow.map.depthTexture` while the
560
+ // graph is built. Without this check that read throws inside TSL, the chain build
561
+ // fails, and *every* stage is lost — the frame comes back ungraded with no SSGI, no
562
+ // SSR and no tonemap, which looks like a scene problem rather than a missing map.
563
+ // Refusing by name keeps the rest of the chain, which is this stage list's contract.
564
+ if (light.shadow?.map == null)
565
+ return `light '${light.name || "sun"}' has no shadow map yet: set renderer.shadowMap.enabled on the raw renderer (ctx.renderer.raw), and build the chain after the first frame has rendered`;
566
+ return true;
567
+ },
568
+ build: (input) => {
569
+ const light = target.godraysLight as DirectionalLight;
570
+ const shafts = godrays(depth(), view, light);
571
+ shafts.density.value = options.godraysDensity;
572
+ shafts.maxDensity.value = options.godraysMaxDensity;
573
+ shafts.raymarchSteps.value = options.godraysSteps;
574
+ // The pass jitters its samples with interleaved noise; at low step counts the
575
+ // noise renders as a regular lattice over every hazy pixel. The bilateral
576
+ // denoiser built for the GI gather smooths exactly that — high-frequency,
577
+ // depth-coherent — and the shaft edges survive because they sit on geometry
578
+ // silhouettes the depth term owns. Denoise before the floor: the floor's
579
+ // subtraction amplifies relative noise on near-floor values.
580
+ let shaft: ChainNode = convertToTexture(shafts);
581
+ if (options.denoiseEnabled) shaft = denoised(denoise(shaft, depth(), normal(), view));
582
+ // Floor, then scale, then tint. The floor is what turns this from a whole-frame
583
+ // brightener into a shaft renderer; the tint by the light's own colour is what
584
+ // stops a warm sun throwing a white beam.
585
+ const cleaned = shaft.rgb.sub(options.godraysFloor).max(0).mul(options.godraysIntensity);
586
+ return input.add(cleaned.mul(color(light.color)));
587
+ },
588
+ }),
589
+ stage({
590
+ name: "ssr",
591
+ build: (input) => {
592
+ // Three defaults that together make SSR silently do nothing on a real scene, all
593
+ // fixed here and each worth stating:
594
+ // maxDistance defaults to 1 world unit — a ray that dies after a metre
595
+ // reflectNonMetals defaults to false, so a polished *stone* floor never reflects
596
+ // roughnessNode null means every surface is treated as a perfect mirror
597
+ // `normal`, not `normal.xyz`. SSR calls `.sample()` on this node, so it needs the
598
+ // whole TextureNode; a swizzle produces a plain vec3 and the pass dies at shader
599
+ // build. `@types/three` declares the parameter as `Node<"vec3">`, which is what
600
+ // makes the swizzle look correct — the types are wrong here and the runtime is
601
+ // right. Both `colorNode` and `normalNode` are `.sample()`d inside the pass, so
602
+ // the composed input must be materialised ONCE and that texture reused on both
603
+ // sides of the add: passing the unmaterialised node to the pass while adding the
604
+ // reflections onto a second copy builds two parallel graphs, and the frame comes
605
+ // out as the bare background colour.
606
+ const base = convertToTexture(input);
607
+ const reflections = ssr(base, depth(), normal() as unknown as Parameters<typeof ssr>[2], {
608
+ camera: view,
609
+ metalnessNode: metal().r,
610
+ roughnessNode: rough().g,
611
+ reflectNonMetals: true,
612
+ });
613
+ reflections.maxDistance.value = options.ssrMaxDistance;
614
+ reflections.resolutionScale = options.ssrResolutionScale;
615
+ return base.add(reflections);
616
+ },
617
+ }),
618
+ stage({
619
+ name: "sharpen",
620
+ build: (input) => {
621
+ // Last of the image stages but one, because RCAS is defined on the finished
622
+ // picture: it looks at the contrast around a pixel and sharpens in proportion to
623
+ // it, so running it before bloom would sharpen edges that bloom then spreads
624
+ // back out. The third argument keeps the node from materialising its own render
625
+ // target; the chain's graph is fused instead.
626
+ return sharpen(convertToTexture(input), options.sharpenStrength, false);
627
+ },
628
+ }),
629
+ stage({
630
+ name: "bloom",
631
+ dispose: () => {
632
+ releaseBloom();
633
+ releaseBloom = () => {};
634
+ },
635
+ build: (input) => {
636
+ const texture = convertToTexture(input);
637
+ const effect = bloom(
638
+ texture,
639
+ options.bloomStrength,
640
+ options.bloomRadius,
641
+ options.bloomThreshold,
642
+ );
643
+ releaseBloom = () => {
644
+ effect.dispose();
645
+ // convertToTexture may return its input. Only the newly allocated RTT is ours.
646
+ const scratch = texture as unknown as {
647
+ isRTTNode?: boolean;
648
+ renderTarget: { dispose(): void };
649
+ _quadMesh: { material: { dispose(): void } };
650
+ };
651
+ if (texture !== input && scratch.isRTTNode === true) {
652
+ scratch.renderTarget.dispose();
653
+ scratch._quadMesh.material.dispose();
654
+ }
655
+ };
656
+ return input.add(effect);
657
+ },
658
+ }),
659
+ stage({
660
+ name: "vignette",
661
+ build: (input) => {
662
+ // Radius measured from the centre in screen-diagonal units, so the corner is 1
663
+ // and the falloff does not change shape when the window does. It starts at 0.55 —
664
+ // well outside the subject in a 16:9 frame — so the vignette is a corner, not a
665
+ // spotlight.
666
+ const radius = screenUV.sub(vec2(0.5, 0.5)).mul(vec2(1.78, 1)).length().mul(1.04);
667
+ const fall = smoothstep(float(0.55), float(1.02), radius).mul(options.vignetteAmount);
668
+ return input.mul(fall.oneMinus());
669
+ },
670
+ }),
671
+ ];
672
+
673
+ // The kit's own stages, composed after the built-ins. The factory is called with the two
674
+ // things only this file can produce — the scene pass's depth texture and the resolved tier —
675
+ // and returns the complete authored graph plus the subset to run.
676
+ stages.push(...options.authoredStages({ depthNode: depth(), tier: options.renderChainTier }));
677
+
678
+ // A composed base colour with every stage off still has to reach the frame. The chain
679
+ // installs nothing for an empty stage list, so this is the one path that goes direct.
680
+ if (requested.length === 0) {
681
+ if (renderer.kind !== "webgpu") {
682
+ this.#reportApplied([], [{ name: "baseColour", reason: `renderer:${renderer.kind}` }]);
683
+ return { dropped: [], stages: [] };
684
+ }
685
+ if (renderer.setOutputNode === undefined)
686
+ throw new Error("setOutputNode is unavailable, so the composed base colour cannot run.");
687
+ renderer.setOutputNode(exposed);
688
+ this.#reportApplied([], []);
689
+ return { dropped: [], stages: [] };
690
+ }
691
+
692
+ if (renderer.createRenderChain === undefined) throw new Error("RenderChain is unavailable.");
693
+ const chain = renderer.createRenderChain({
694
+ input: exposed,
695
+ request: { stages: requested, tier: options.renderChainTier },
696
+ stages,
697
+ worldPass: scenePass,
698
+ });
699
+ this.#reportApplied(chain.applied.stages, chain.applied.dropped);
700
+ return {
701
+ dropped: chain.applied.dropped,
702
+ stages: chain.applied.stages,
703
+ dispose: () => {
704
+ chain.dispose();
705
+ scenePass.dispose();
706
+ },
707
+ };
708
+ }
709
+
710
+ /**
711
+ * Prints `TN_WORLD_ENVIRONMENT`: every stage this class can run, named as applied or refused
712
+ * **with a reason that is never blank**, plus the tone curve and exposure that framed them.
713
+ *
714
+ * The chain prints its own line for the stages it installed, and it prints nothing at all when
715
+ * nothing was requested — which is exactly the case where a reader most needs to know that GI
716
+ * is off because this file says so rather than because a node silently no-op'd. This line is
717
+ * emitted every run, including the run where every stage is off.
718
+ */
719
+ #reportApplied(
720
+ applied: readonly string[],
721
+ dropped: readonly { name: string; reason: string }[],
722
+ ): void {
723
+ const options = this.#options;
724
+ const off: Record<string, string> = {
725
+ ambientOcclusion: "gtaoEnabled is false",
726
+ bloom: "bloomEnabled is false",
727
+ godRays: "godraysEnabled is false",
728
+ sharpen: "sharpenEnabled is false",
729
+ ssgi: "ssgiEnabled is false",
730
+ ssr: "ssrEnabled is false",
731
+ vignette: "vignetteAmount is 0",
732
+ kuwahara: "kuwaharaEnabled is false",
733
+ outline: "outlineEnabled is false",
734
+ watercolor: "watercolorEnabled is false",
735
+ };
736
+ const stages = Object.keys(off)
737
+ .sort()
738
+ .map((name) => {
739
+ if (applied.includes(name)) return { applied: true, name };
740
+ const refused = dropped.find((entry) => entry.name === name);
741
+ return { applied: false, name, reason: refused?.reason ?? off[name] };
742
+ });
743
+ console.info(
744
+ `TN_WORLD_ENVIRONMENT:${JSON.stringify({
745
+ denoise: options.denoiseEnabled,
746
+ exposure: options.exposure,
747
+ marker: "TN_WORLD_ENVIRONMENT",
748
+ ssgiQuality: options.ssgiQuality,
749
+ stages,
750
+ tonemapMode: options.tonemapMode,
751
+ })}`,
752
+ );
753
+ }
754
+ }
755
+
756
+ function isChainTier(value: unknown): value is ChainTier {
757
+ return value === "high" || value === "medium" || value === "low" || value === "off";
758
+ }