create-threenative 0.2.15 → 0.2.18

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 (488) hide show
  1. package/agent-docs/kit-mcp.md +10 -0
  2. package/agent-docs/kit-router.md +14 -0
  3. package/agent-docs/kit-stuck.md +7 -0
  4. package/agent-docs/references/assertion-reference.md +54 -110
  5. package/agent-docs/references/capability-reference.md +1740 -254
  6. package/agent-docs/references/conventions.md +299 -0
  7. package/agent-docs/references/kit-action-rpg.md +40 -0
  8. package/agent-docs/references/kit-adventure.md +40 -0
  9. package/agent-docs/references/kit-collectathon.md +38 -0
  10. package/agent-docs/references/kit-kart.md +31 -0
  11. package/agent-docs/references/kit-minimal.md +29 -0
  12. package/agent-docs/references/kit-platformer.md +34 -0
  13. package/agent-docs/references/kit-puzzle.md +22 -0
  14. package/agent-docs/references/kit-racing.md +26 -0
  15. package/agent-docs/references/kit-rain.md +31 -0
  16. package/agent-docs/references/kit-rts.md +34 -0
  17. package/agent-docs/references/kit-runner.md +32 -0
  18. package/agent-docs/references/kit-sailing.md +41 -0
  19. package/agent-docs/references/kit-shooter.md +33 -0
  20. package/agent-docs/references/kit-snow.md +33 -0
  21. package/agent-docs/references/kit-starter.md +55 -0
  22. package/agent-docs/references/kit-tower-defense.md +27 -0
  23. package/agent-docs/references/performance-basics.md +8 -4
  24. package/agent-docs/references/terrain-authoring.md +2 -1
  25. package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
  26. package/agent-files/.agents/skills/prd-creator/SKILL.md +3 -2
  27. package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +84 -59
  28. package/agent-files/.claude/hooks/discovery-gate.mjs +125 -0
  29. package/agent-files/.claude/hooks/ponytail-context.mjs +1 -1
  30. package/agent-files/.claude/settings.json +25 -0
  31. package/agent-files/.codex/hooks.json +18 -1
  32. package/dist/index.d.ts +97 -6
  33. package/dist/index.js +899 -271
  34. package/dist/terrain-kit.d.ts +7 -0
  35. package/dist/terrain-kit.js +82 -0
  36. package/dist/threenative.js +114 -16
  37. package/dist/web-engine-ccd-ik-solver.js +127 -0
  38. package/dist/web-engine-gltf-loader.js +71 -20
  39. package/dist/web-engine-post-effects.js +39 -14
  40. package/dist/web-engine-runtime.js +10011 -4101
  41. package/package.json +15 -9
  42. package/template-assets/clearwater/README.md +1 -1
  43. package/template-assets/patches/manifest.json +18 -0
  44. package/template-assets/patches/three@0.187.0.patch +2004 -407
  45. package/template-assets/terrain/alpine/assets.json +12 -0
  46. package/template-assets/terrain/alpine/bake.mjs +6 -0
  47. package/template-assets/terrain/alpine/credits.json +164 -0
  48. package/template-assets/terrain/alpine/heightmap.r16 +0 -0
  49. package/template-assets/terrain/alpine/recipe.json +119 -0
  50. package/template-assets/terrain/alpine/surface.json +53 -0
  51. package/template-assets/terrain/coastal/assets.json +11 -0
  52. package/template-assets/terrain/coastal/bake.mjs +6 -0
  53. package/template-assets/terrain/coastal/credits.json +117 -0
  54. package/template-assets/terrain/coastal/heightmap.r16 +0 -0
  55. package/template-assets/terrain/coastal/recipe.json +113 -0
  56. package/template-assets/terrain/coastal/surface.json +41 -0
  57. package/template-assets/terrain/desert/assets.json +12 -0
  58. package/template-assets/terrain/desert/bake.mjs +6 -0
  59. package/template-assets/terrain/desert/credits.json +164 -0
  60. package/template-assets/terrain/desert/heightmap.r16 +0 -0
  61. package/template-assets/terrain/desert/recipe.json +108 -0
  62. package/template-assets/terrain/desert/surface.json +54 -0
  63. package/template-assets/terrain/forest/assets.json +65 -0
  64. package/template-assets/terrain/forest/bake.mjs +8 -0
  65. package/template-assets/terrain/forest/credits.json +225 -0
  66. package/template-assets/terrain/forest/heightmap.r16 +0 -0
  67. package/template-assets/terrain/forest/recipe.json +350 -0
  68. package/template-assets/terrain/forest/surface.json +79 -0
  69. package/template-assets/terrain/tundra/assets.json +12 -0
  70. package/template-assets/terrain/tundra/bake.mjs +6 -0
  71. package/template-assets/terrain/tundra/credits.json +164 -0
  72. package/template-assets/terrain/tundra/heightmap.r16 +0 -0
  73. package/template-assets/terrain/tundra/recipe.json +277 -0
  74. package/template-assets/terrain/tundra/surface.json +54 -0
  75. package/templates/action-rpg/AGENTS.md +103 -84
  76. package/templates/action-rpg/CLAUDE.md +103 -84
  77. package/templates/action-rpg/kit.json +1 -0
  78. package/templates/action-rpg/package.json +7 -7
  79. package/templates/action-rpg/playtests/spells.playtest.json +20 -0
  80. package/templates/action-rpg/src/game.ts +2 -1
  81. package/templates/action-rpg/src/render/atmosphere.ts +11 -16
  82. package/templates/action-rpg/src/render/backlightControls.ts +10 -0
  83. package/templates/action-rpg/src/render/backlightMaterial.ts +4 -4
  84. package/templates/action-rpg/src/render/clouds.ts +13 -0
  85. package/templates/action-rpg/src/render/gpuSky.ts +4 -7
  86. package/templates/action-rpg/src/render/materialLighting.ts +5 -5
  87. package/templates/action-rpg/src/render/quality.ts +10 -33
  88. package/templates/action-rpg/src/scenes/Play.ts +30 -1
  89. package/templates/action-rpg/src/style.css +4 -0
  90. package/templates/action-rpg/src/ui/AbilityBar.tsx +1 -1
  91. package/templates/action-rpg/threenative.config.ts +0 -3
  92. package/templates/action-rpg/vite.config.ts +2 -0
  93. package/templates/adventure/AGENTS.md +92 -44
  94. package/templates/adventure/CLAUDE.md +92 -44
  95. package/templates/adventure/kit.json +5 -1
  96. package/templates/adventure/package.json +7 -7
  97. package/templates/adventure/src/game.ts +1 -1
  98. package/templates/adventure/src/style.css +4 -0
  99. package/templates/adventure/tsconfig.json +1 -1
  100. package/templates/adventure/vite.config.ts +2 -0
  101. package/templates/collectathon/AGENTS.md +93 -42
  102. package/templates/collectathon/CLAUDE.md +93 -42
  103. package/templates/collectathon/package.json +7 -7
  104. package/templates/collectathon/src/game.ts +1 -1
  105. package/templates/collectathon/src/level/Course.ts +55 -9
  106. package/templates/collectathon/src/level/terrain.ts +27 -6
  107. package/templates/collectathon/src/main.ts +1 -0
  108. package/templates/collectathon/src/render/foliage.ts +359 -98
  109. package/templates/collectathon/src/render/sky.ts +76 -12
  110. package/templates/collectathon/src/render/water.ts +32 -10
  111. package/templates/collectathon/src/scenes/Play.ts +18 -5
  112. package/templates/collectathon/src/style.css +4 -0
  113. package/templates/collectathon/tsconfig.json +1 -1
  114. package/templates/collectathon/vite.config.ts +2 -0
  115. package/templates/kart/AGENTS.md +87 -42
  116. package/templates/kart/CLAUDE.md +87 -42
  117. package/templates/kart/package.json +6 -6
  118. package/templates/kart/src/game.ts +1 -1
  119. package/templates/kart/src/main.ts +1 -0
  120. package/templates/kart/src/style.css +4 -0
  121. package/templates/kart/tsconfig.json +1 -1
  122. package/templates/kart/vite.config.ts +2 -0
  123. package/templates/minimal/AGENTS.md +105 -84
  124. package/templates/minimal/CLAUDE.md +105 -84
  125. package/templates/minimal/package.json +6 -6
  126. package/templates/minimal/playtests/stands-still.playtest.json +30 -0
  127. package/templates/minimal/src/game.ts +1 -1
  128. package/templates/minimal/src/render/atmosphere.ts +11 -16
  129. package/templates/minimal/src/render/backlightControls.ts +10 -0
  130. package/templates/minimal/src/render/backlightMaterial.ts +4 -4
  131. package/templates/minimal/src/render/camera.ts +13 -2
  132. package/templates/minimal/src/render/clouds.ts +13 -0
  133. package/templates/minimal/src/render/gpuSky.ts +4 -7
  134. package/templates/minimal/src/render/lighting.ts +4 -2
  135. package/templates/minimal/src/render/materialLighting.ts +5 -5
  136. package/templates/minimal/src/render/materials.ts +10 -0
  137. package/templates/minimal/src/render/quality.ts +7 -32
  138. package/templates/minimal/src/scenes/Play.ts +4 -1
  139. package/templates/minimal/vite.config.ts +7 -1
  140. package/templates/platformer/AGENTS.md +95 -46
  141. package/templates/platformer/CLAUDE.md +95 -46
  142. package/templates/platformer/index.html +1 -1
  143. package/templates/platformer/main.html +12 -0
  144. package/templates/platformer/package.json +7 -7
  145. package/templates/platformer/playtests/gamepad-idle.playtest.json +21 -0
  146. package/templates/platformer/playtests/gamepad.playtest.json +30 -0
  147. package/templates/platformer/src/entities/Fox.ts +21 -6
  148. package/templates/platformer/src/game.ts +1 -1
  149. package/templates/platformer/src/main.ts +1 -0
  150. package/templates/platformer/src/render/backlightControls.ts +10 -0
  151. package/templates/platformer/src/render/backlightMaterial.ts +4 -4
  152. package/templates/platformer/src/render/materialLighting.ts +5 -5
  153. package/templates/platformer/src/render/quality.ts +7 -32
  154. package/templates/platformer/src/scenes/Play.ts +2 -1
  155. package/templates/platformer/src/style.css +4 -0
  156. package/templates/platformer/src/worker-page.ts +29 -0
  157. package/templates/platformer/src/worker.ts +5 -0
  158. package/templates/platformer/tsconfig.json +1 -1
  159. package/templates/platformer/vite.config.ts +4 -0
  160. package/templates/puzzle/AGENTS.md +97 -80
  161. package/templates/puzzle/CLAUDE.md +97 -80
  162. package/templates/puzzle/package.json +7 -7
  163. package/templates/puzzle/src/game.ts +1 -1
  164. package/templates/puzzle/src/render/backlightControls.ts +10 -0
  165. package/templates/puzzle/src/render/backlightMaterial.ts +4 -4
  166. package/templates/puzzle/src/render/materialLighting.ts +5 -5
  167. package/templates/puzzle/src/render/quality.ts +7 -32
  168. package/templates/puzzle/src/scenes/Play.ts +1 -1
  169. package/templates/puzzle/src/style.css +4 -0
  170. package/templates/puzzle/tsconfig.json +1 -1
  171. package/templates/puzzle/vite.config.ts +2 -0
  172. package/templates/racing/AGENTS.md +100 -82
  173. package/templates/racing/CLAUDE.md +100 -82
  174. package/templates/racing/package.json +7 -7
  175. package/templates/racing/src/game.ts +1 -1
  176. package/templates/racing/src/render/atmosphere.ts +11 -16
  177. package/templates/racing/src/render/backlightControls.ts +10 -0
  178. package/templates/racing/src/render/backlightMaterial.ts +4 -4
  179. package/templates/racing/src/render/clouds.ts +13 -0
  180. package/templates/racing/src/render/gpuSky.ts +4 -7
  181. package/templates/racing/src/render/materialLighting.ts +5 -5
  182. package/templates/racing/src/render/quality.ts +7 -32
  183. package/templates/racing/src/scenes/Race.ts +4 -1
  184. package/templates/racing/src/style.css +4 -0
  185. package/templates/racing/tsconfig.json +1 -1
  186. package/templates/racing/vite.config.ts +2 -0
  187. package/templates/rain/AGENTS.md +96 -84
  188. package/templates/rain/CLAUDE.md +96 -84
  189. package/templates/rain/native-playtests/lightning.playtest.json +85 -10
  190. package/templates/rain/package.json +6 -6
  191. package/templates/rain/playtests/reduced-motion.playtest.json +6 -0
  192. package/templates/rain/src/game.ts +1 -1
  193. package/templates/rain/src/scenes/Boot.ts +1 -0
  194. package/templates/rain/src/state.ts +7 -0
  195. package/templates/rain/src/ui/GameUi.tsx +7 -1
  196. package/templates/rain/vite.config.ts +6 -0
  197. package/templates/rts/AGENTS.md +100 -85
  198. package/templates/rts/CLAUDE.md +100 -85
  199. package/templates/rts/package.json +6 -6
  200. package/templates/rts/src/game.ts +1 -1
  201. package/templates/rts/src/render/backlightControls.ts +10 -0
  202. package/templates/rts/src/render/backlightMaterial.ts +4 -4
  203. package/templates/rts/src/render/materialLighting.ts +5 -5
  204. package/templates/rts/src/render/quality.ts +7 -31
  205. package/templates/rts/src/scenes/Play.ts +1 -1
  206. package/templates/rts/src/style.css +4 -0
  207. package/templates/rts/vite.config.ts +2 -0
  208. package/templates/runner/AGENTS.md +97 -80
  209. package/templates/runner/CLAUDE.md +97 -80
  210. package/templates/runner/package.json +7 -7
  211. package/templates/runner/playtests/performance.playtest.json +1 -1
  212. package/templates/runner/src/game.ts +1 -1
  213. package/templates/runner/src/render/atmosphere.ts +11 -16
  214. package/templates/runner/src/render/backlightControls.ts +10 -0
  215. package/templates/runner/src/render/backlightMaterial.ts +4 -4
  216. package/templates/runner/src/render/clouds.ts +13 -0
  217. package/templates/runner/src/render/gpuSky.ts +4 -7
  218. package/templates/runner/src/render/lighting.ts +53 -11
  219. package/templates/runner/src/render/materialLighting.ts +5 -5
  220. package/templates/runner/src/render/quality.ts +7 -32
  221. package/templates/runner/src/scenes/Run.ts +8 -4
  222. package/templates/runner/src/style.css +4 -0
  223. package/templates/runner/threenative.config.ts +0 -3
  224. package/templates/runner/tsconfig.json +1 -1
  225. package/templates/runner/vite.config.ts +2 -0
  226. package/templates/sailing/AGENTS.md +96 -79
  227. package/templates/sailing/CLAUDE.md +96 -79
  228. package/templates/sailing/package.json +7 -7
  229. package/templates/sailing/playtests/sails.playtest.json +1 -0
  230. package/templates/sailing/src/game.ts +1 -1
  231. package/templates/sailing/src/render/backlightControls.ts +10 -0
  232. package/templates/sailing/src/render/backlightMaterial.ts +4 -4
  233. package/templates/sailing/src/render/environmentSetup.ts +1 -1
  234. package/templates/sailing/src/render/materialLighting.ts +5 -5
  235. package/templates/sailing/src/render/quality.ts +7 -32
  236. package/templates/sailing/src/render/sky.ts +4 -0
  237. package/templates/sailing/src/style.css +5 -0
  238. package/templates/sailing/threenative.config.ts +0 -3
  239. package/templates/sailing/vite.config.ts +6 -0
  240. package/templates/shooter/AGENTS.md +97 -68
  241. package/templates/shooter/CLAUDE.md +97 -68
  242. package/templates/shooter/package.json +7 -7
  243. package/templates/shooter/src/game.ts +3 -2
  244. package/templates/shooter/src/render/atmosphere.ts +11 -16
  245. package/templates/shooter/src/render/backlightControls.ts +10 -0
  246. package/templates/shooter/src/render/backlightMaterial.ts +4 -4
  247. package/templates/shooter/src/render/clouds.ts +13 -0
  248. package/templates/shooter/src/render/gpuSky.ts +4 -7
  249. package/templates/shooter/src/render/materialLighting.ts +5 -5
  250. package/templates/shooter/src/render/quality.ts +10 -33
  251. package/templates/shooter/src/scenes/Play.ts +4 -1
  252. package/templates/shooter/src/style.css +4 -0
  253. package/templates/shooter/vite.config.ts +2 -0
  254. package/templates/snow/AGENTS.md +95 -76
  255. package/templates/snow/CLAUDE.md +95 -76
  256. package/templates/snow/package.json +7 -7
  257. package/templates/snow/src/game.ts +1 -1
  258. package/templates/snow/src/render/backlightControls.ts +10 -0
  259. package/templates/snow/src/render/backlightMaterial.ts +4 -4
  260. package/templates/snow/src/render/materialLighting.ts +5 -5
  261. package/templates/snow/src/render/quality.ts +7 -32
  262. package/templates/snow/src/style.css +5 -0
  263. package/templates/snow/threenative.config.ts +0 -3
  264. package/templates/snow/vite.config.ts +6 -0
  265. package/templates/starter/AGENTS.md +109 -88
  266. package/templates/starter/CLAUDE.md +109 -88
  267. package/templates/starter/native-playtests/render-chain.playtest.json +24 -24
  268. package/templates/starter/native-playtests/smooth-motion.playtest.json +3 -3
  269. package/templates/starter/package.json +7 -7
  270. package/templates/starter/src/entities/Crate.ts +5 -2
  271. package/templates/starter/src/entities/Player.ts +10 -22
  272. package/templates/starter/src/game.ts +4 -3
  273. package/templates/starter/src/render/adaptiveQuality.ts +17 -0
  274. package/templates/starter/src/render/atmosphere.ts +11 -16
  275. package/templates/starter/src/render/backlightControls.ts +10 -0
  276. package/templates/starter/src/render/backlightMaterial.ts +4 -4
  277. package/templates/starter/src/render/clouds.ts +13 -0
  278. package/templates/starter/src/render/contactShadow.ts +1 -1
  279. package/templates/starter/src/render/gpuSky.ts +4 -7
  280. package/templates/starter/src/render/lighting.ts +54 -4
  281. package/templates/starter/src/render/materialLighting.ts +5 -5
  282. package/templates/starter/src/render/postprocessing.ts +11 -10
  283. package/templates/starter/src/render/quality.ts +14 -1
  284. package/templates/starter/src/render/temporalAA.ts +8 -7
  285. package/templates/starter/src/render/temporalAAFrame.ts +30 -9
  286. package/templates/starter/src/render/temporalAAResolve.ts +15 -1
  287. package/templates/starter/src/render/temporalClampRelease.ts +183 -0
  288. package/templates/starter/src/render/temporalHistoryResolve.ts +90 -0
  289. package/templates/starter/src/render/temporalMoire.ts +190 -0
  290. package/templates/starter/src/render/temporalResolve.ts +75 -16
  291. package/templates/starter/src/render/temporalResolveDepth.ts +2 -0
  292. package/templates/starter/src/scenes/Play.ts +53 -32
  293. package/templates/starter/src/state.ts +2 -0
  294. package/templates/starter/src/style.css +4 -0
  295. package/templates/starter/src/ui/Menu.tsx +5 -1
  296. package/templates/starter/vite.config.ts +2 -0
  297. package/templates/tower-defense/AGENTS.md +97 -81
  298. package/templates/tower-defense/CLAUDE.md +97 -81
  299. package/templates/tower-defense/package.json +7 -7
  300. package/templates/tower-defense/src/game.ts +1 -1
  301. package/templates/tower-defense/src/render/backlightControls.ts +10 -0
  302. package/templates/tower-defense/src/render/backlightMaterial.ts +4 -4
  303. package/templates/tower-defense/src/render/materialLighting.ts +5 -5
  304. package/templates/tower-defense/src/render/quality.ts +7 -32
  305. package/templates/tower-defense/src/scenes/Battle.ts +1 -1
  306. package/templates/tower-defense/src/style.css +4 -0
  307. package/templates/tower-defense/tsconfig.json +1 -1
  308. package/templates/tower-defense/vite.config.ts +2 -0
  309. package/capabilities.json +0 -9197
  310. package/templates/AGENTS.md +0 -21
  311. package/templates/CLAUDE.md +0 -23
  312. package/templates/action-rpg/.codex/config.toml +0 -23
  313. package/templates/action-rpg/.cursor/mcp.json +0 -38
  314. package/templates/action-rpg/.gemini/settings.json +0 -38
  315. package/templates/action-rpg/.mcp.json +0 -38
  316. package/templates/action-rpg/.vscode/mcp.json +0 -43
  317. package/templates/action-rpg/.zed/settings.json +0 -43
  318. package/templates/action-rpg/opencode.json +0 -49
  319. package/templates/action-rpg/src/render/environmentContribution.ts +0 -188
  320. package/templates/action-rpg/src/render/environmentRadiance.ts +0 -36
  321. package/templates/action-rpg/src/render/environmentSampleCache.ts +0 -43
  322. package/templates/action-rpg/src/render/environmentSampling.ts +0 -193
  323. package/templates/action-rpg/src/render/environmentSnapshot.ts +0 -53
  324. package/templates/adventure/.codex/config.toml +0 -23
  325. package/templates/adventure/.cursor/mcp.json +0 -38
  326. package/templates/adventure/.gemini/settings.json +0 -38
  327. package/templates/adventure/.mcp.json +0 -38
  328. package/templates/adventure/.vscode/mcp.json +0 -43
  329. package/templates/adventure/.zed/settings.json +0 -43
  330. package/templates/adventure/opencode.json +0 -49
  331. package/templates/collectathon/.codex/config.toml +0 -23
  332. package/templates/collectathon/.cursor/mcp.json +0 -38
  333. package/templates/collectathon/.gemini/settings.json +0 -38
  334. package/templates/collectathon/.mcp.json +0 -38
  335. package/templates/collectathon/.vscode/mcp.json +0 -43
  336. package/templates/collectathon/.zed/settings.json +0 -43
  337. package/templates/collectathon/opencode.json +0 -49
  338. package/templates/kart/.codex/config.toml +0 -23
  339. package/templates/kart/.cursor/mcp.json +0 -38
  340. package/templates/kart/.gemini/settings.json +0 -38
  341. package/templates/kart/.mcp.json +0 -38
  342. package/templates/kart/.vscode/mcp.json +0 -43
  343. package/templates/kart/.zed/settings.json +0 -43
  344. package/templates/kart/opencode.json +0 -49
  345. package/templates/minimal/.codex/config.toml +0 -23
  346. package/templates/minimal/.cursor/mcp.json +0 -38
  347. package/templates/minimal/.gemini/settings.json +0 -38
  348. package/templates/minimal/.mcp.json +0 -38
  349. package/templates/minimal/.vscode/mcp.json +0 -43
  350. package/templates/minimal/.zed/settings.json +0 -43
  351. package/templates/minimal/opencode.json +0 -49
  352. package/templates/minimal/src/render/environmentContribution.ts +0 -188
  353. package/templates/minimal/src/render/environmentRadiance.ts +0 -36
  354. package/templates/minimal/src/render/environmentSampleCache.ts +0 -43
  355. package/templates/minimal/src/render/environmentSampling.ts +0 -193
  356. package/templates/minimal/src/render/environmentSnapshot.ts +0 -53
  357. package/templates/platformer/.codex/config.toml +0 -23
  358. package/templates/platformer/.cursor/mcp.json +0 -38
  359. package/templates/platformer/.gemini/settings.json +0 -38
  360. package/templates/platformer/.mcp.json +0 -38
  361. package/templates/platformer/.vscode/mcp.json +0 -43
  362. package/templates/platformer/.zed/settings.json +0 -43
  363. package/templates/platformer/opencode.json +0 -49
  364. package/templates/platformer/src/render/environmentContribution.ts +0 -188
  365. package/templates/platformer/src/render/environmentRadiance.ts +0 -36
  366. package/templates/platformer/src/render/environmentSampleCache.ts +0 -43
  367. package/templates/platformer/src/render/environmentSampling.ts +0 -193
  368. package/templates/platformer/src/render/environmentSnapshot.ts +0 -53
  369. package/templates/puzzle/.codex/config.toml +0 -23
  370. package/templates/puzzle/.cursor/mcp.json +0 -38
  371. package/templates/puzzle/.gemini/settings.json +0 -38
  372. package/templates/puzzle/.mcp.json +0 -38
  373. package/templates/puzzle/.vscode/mcp.json +0 -43
  374. package/templates/puzzle/.zed/settings.json +0 -43
  375. package/templates/puzzle/opencode.json +0 -49
  376. package/templates/puzzle/src/render/environmentContribution.ts +0 -188
  377. package/templates/puzzle/src/render/environmentRadiance.ts +0 -36
  378. package/templates/puzzle/src/render/environmentSampleCache.ts +0 -43
  379. package/templates/puzzle/src/render/environmentSampling.ts +0 -193
  380. package/templates/puzzle/src/render/environmentSnapshot.ts +0 -53
  381. package/templates/racing/.codex/config.toml +0 -23
  382. package/templates/racing/.cursor/mcp.json +0 -38
  383. package/templates/racing/.gemini/settings.json +0 -38
  384. package/templates/racing/.mcp.json +0 -38
  385. package/templates/racing/.vscode/mcp.json +0 -43
  386. package/templates/racing/.zed/settings.json +0 -43
  387. package/templates/racing/opencode.json +0 -49
  388. package/templates/racing/src/render/environmentContribution.ts +0 -188
  389. package/templates/racing/src/render/environmentRadiance.ts +0 -36
  390. package/templates/racing/src/render/environmentSampleCache.ts +0 -43
  391. package/templates/racing/src/render/environmentSampling.ts +0 -193
  392. package/templates/racing/src/render/environmentSnapshot.ts +0 -53
  393. package/templates/rain/.codex/config.toml +0 -23
  394. package/templates/rain/.cursor/mcp.json +0 -38
  395. package/templates/rain/.gemini/settings.json +0 -38
  396. package/templates/rain/.mcp.json +0 -38
  397. package/templates/rain/.vscode/mcp.json +0 -43
  398. package/templates/rain/.zed/settings.json +0 -43
  399. package/templates/rain/opencode.json +0 -49
  400. package/templates/rts/.codex/config.toml +0 -23
  401. package/templates/rts/.cursor/mcp.json +0 -38
  402. package/templates/rts/.gemini/settings.json +0 -38
  403. package/templates/rts/.mcp.json +0 -38
  404. package/templates/rts/.vscode/mcp.json +0 -43
  405. package/templates/rts/.zed/settings.json +0 -43
  406. package/templates/rts/opencode.json +0 -49
  407. package/templates/rts/src/render/environmentContribution.ts +0 -188
  408. package/templates/rts/src/render/environmentRadiance.ts +0 -36
  409. package/templates/rts/src/render/environmentSampleCache.ts +0 -43
  410. package/templates/rts/src/render/environmentSampling.ts +0 -193
  411. package/templates/rts/src/render/environmentSnapshot.ts +0 -53
  412. package/templates/runner/.codex/config.toml +0 -23
  413. package/templates/runner/.cursor/mcp.json +0 -38
  414. package/templates/runner/.gemini/settings.json +0 -38
  415. package/templates/runner/.mcp.json +0 -38
  416. package/templates/runner/.vscode/mcp.json +0 -43
  417. package/templates/runner/.zed/settings.json +0 -43
  418. package/templates/runner/README.md +0 -43
  419. package/templates/runner/opencode.json +0 -49
  420. package/templates/runner/src/render/environmentContribution.ts +0 -188
  421. package/templates/runner/src/render/environmentRadiance.ts +0 -36
  422. package/templates/runner/src/render/environmentSampleCache.ts +0 -43
  423. package/templates/runner/src/render/environmentSampling.ts +0 -193
  424. package/templates/runner/src/render/environmentSnapshot.ts +0 -53
  425. package/templates/sailing/.codex/config.toml +0 -23
  426. package/templates/sailing/.cursor/mcp.json +0 -38
  427. package/templates/sailing/.gemini/settings.json +0 -38
  428. package/templates/sailing/.mcp.json +0 -38
  429. package/templates/sailing/.vscode/mcp.json +0 -43
  430. package/templates/sailing/.zed/settings.json +0 -43
  431. package/templates/sailing/README.md +0 -28
  432. package/templates/sailing/opencode.json +0 -49
  433. package/templates/sailing/src/render/environmentContribution.ts +0 -188
  434. package/templates/sailing/src/render/environmentRadiance.ts +0 -36
  435. package/templates/sailing/src/render/environmentSampleCache.ts +0 -43
  436. package/templates/sailing/src/render/environmentSampling.ts +0 -193
  437. package/templates/sailing/src/render/environmentSnapshot.ts +0 -53
  438. package/templates/shooter/.codex/config.toml +0 -23
  439. package/templates/shooter/.cursor/mcp.json +0 -38
  440. package/templates/shooter/.gemini/settings.json +0 -38
  441. package/templates/shooter/.mcp.json +0 -38
  442. package/templates/shooter/.vscode/mcp.json +0 -43
  443. package/templates/shooter/.zed/settings.json +0 -43
  444. package/templates/shooter/opencode.json +0 -49
  445. package/templates/shooter/src/render/environmentContribution.ts +0 -188
  446. package/templates/shooter/src/render/environmentRadiance.ts +0 -36
  447. package/templates/shooter/src/render/environmentSampleCache.ts +0 -43
  448. package/templates/shooter/src/render/environmentSampling.ts +0 -193
  449. package/templates/shooter/src/render/environmentSnapshot.ts +0 -53
  450. package/templates/snow/.codex/config.toml +0 -23
  451. package/templates/snow/.cursor/mcp.json +0 -38
  452. package/templates/snow/.gemini/settings.json +0 -38
  453. package/templates/snow/.mcp.json +0 -38
  454. package/templates/snow/.vscode/mcp.json +0 -43
  455. package/templates/snow/.zed/settings.json +0 -43
  456. package/templates/snow/README.md +0 -26
  457. package/templates/snow/opencode.json +0 -49
  458. package/templates/snow/src/render/environmentContribution.ts +0 -188
  459. package/templates/snow/src/render/environmentRadiance.ts +0 -36
  460. package/templates/snow/src/render/environmentSampleCache.ts +0 -43
  461. package/templates/snow/src/render/environmentSampling.ts +0 -193
  462. package/templates/snow/src/render/environmentSnapshot.ts +0 -53
  463. package/templates/starter/.codex/config.toml +0 -23
  464. package/templates/starter/.cursor/mcp.json +0 -38
  465. package/templates/starter/.gemini/settings.json +0 -38
  466. package/templates/starter/.mcp.json +0 -38
  467. package/templates/starter/.vscode/mcp.json +0 -43
  468. package/templates/starter/.zed/settings.json +0 -43
  469. package/templates/starter/opencode.json +0 -49
  470. package/templates/starter/src/render/environmentContribution.ts +0 -188
  471. package/templates/starter/src/render/environmentRadiance.ts +0 -36
  472. package/templates/starter/src/render/environmentSampleCache.ts +0 -43
  473. package/templates/starter/src/render/environmentSampling.ts +0 -193
  474. package/templates/starter/src/render/environmentSnapshot.ts +0 -53
  475. package/templates/starter/src/render/rendererGate.ts +0 -36
  476. package/templates/tower-defense/.codex/config.toml +0 -23
  477. package/templates/tower-defense/.cursor/mcp.json +0 -38
  478. package/templates/tower-defense/.gemini/settings.json +0 -38
  479. package/templates/tower-defense/.mcp.json +0 -38
  480. package/templates/tower-defense/.vscode/mcp.json +0 -43
  481. package/templates/tower-defense/.zed/settings.json +0 -43
  482. package/templates/tower-defense/README.md +0 -16
  483. package/templates/tower-defense/opencode.json +0 -49
  484. package/templates/tower-defense/src/render/environmentContribution.ts +0 -188
  485. package/templates/tower-defense/src/render/environmentRadiance.ts +0 -36
  486. package/templates/tower-defense/src/render/environmentSampleCache.ts +0 -43
  487. package/templates/tower-defense/src/render/environmentSampling.ts +0 -193
  488. package/templates/tower-defense/src/render/environmentSnapshot.ts +0 -53
@@ -0,0 +1,183 @@
1
+ // Generated user source: Unreal TSR's low-frequency clamp release (PRD-539 lever 6). The per-pixel clip
2
+ // to the input's 3x3 box erases detail finer than an input texel. Unreal compares input and history only
3
+ // after a 3x3 blur, and where they agree it lerps the clamped history back to the unclamped one, so
4
+ // sub-texel detail the history gathered survives; disocclusion still forces the clamp.
5
+ // UE 5.8.3: Engine/Shaders/Private/TemporalSuperResolution/TSRShadingAnalysis.ush:25,509-525,563-566,
6
+ // 589-620,632-636; TSRRejectShading.usf:863; TSRUpdateHistory.usf:1256-1257; TSRColorSpace.ush:244-248.
7
+ import { HalfFloatType, NearestFilter } from "three";
8
+ import { Fn, float, int, ivec2, max, min, mix, texture, uv, vec2, vec3, vec4 } from "three/tsl";
9
+ import {
10
+ type Node,
11
+ NodeMaterial,
12
+ type QuadMesh,
13
+ RenderTarget,
14
+ type Renderer,
15
+ type TextureNode,
16
+ } from "three/webgpu";
17
+ import type { TemporalMoire } from "./temporalMoire.js";
18
+ import type { TemporalDepthRejection, TemporalResolveNode } from "./temporalResolveDepth.js";
19
+
20
+ // Unreal's 3x3 blur: centre 1, edges 0.5, corners 0.25, normalised by their sum.
21
+ const FILTERING_WEIGHT = 1 / (1 + 4 * 0.5 + 4 * 0.25);
22
+ // A 10-bit backbuffer's half step.
23
+ const QUANTIZATION = 0.5 / 1024;
24
+ const TAPS = [-1, 0, 1].flatMap((y) => [-1, 0, 1].map((x) => [x, y] as const));
25
+
26
+ type Load = (at: Node<"ivec2">) => Node<"vec4">;
27
+
28
+ /** Clamped integer taps around this fragment's input pixel. */
29
+ function taps(size: Node<"vec2">, load: Load): Node<"vec4">[] {
30
+ const centre = ivec2(uv().mul(size));
31
+ return TAPS.map(([x, y]) =>
32
+ load(ivec2(vec2(centre.add(ivec2(x, y))).clamp(vec2(0), size.sub(1)))),
33
+ );
34
+ }
35
+
36
+ const blur = (values: Node<"vec4">[]) =>
37
+ values.reduce<Node<"vec4">>((sum, value, index) => {
38
+ const [x, y] = TAPS[index] ?? [0, 0];
39
+ return sum.add(value.mul(FILTERING_WEIGHT * 0.5 ** (Math.abs(x) + Math.abs(y))));
40
+ }, vec4(0));
41
+
42
+ /** Median of nine by the 19-exchange network; every step is a min/max pair. */
43
+ function median(values: Node<"float">[]): Node<"float"> {
44
+ const v = [...values];
45
+ const sort = (a: number, b: number) => {
46
+ const low = min(v[a] as Node<"float">, v[b] as Node<"float">);
47
+ v[b] = max(v[a] as Node<"float">, v[b] as Node<"float">);
48
+ v[a] = low;
49
+ };
50
+ for (const [a, b] of "12 45 78 01 34 67 12 45 78 03 58 47 36 14 25 47 42 64 42".split(" "))
51
+ sort(Number(a), Number(b));
52
+ return v[4] as Node<"float">;
53
+ }
54
+
55
+ function quad(name: string, fragment: () => Node<"vec4">): NodeMaterial {
56
+ const material = new NodeMaterial();
57
+ material.name = `Temporal AA clamp release ${name}`;
58
+ material.fragmentNode = Fn(fragment)();
59
+ return material;
60
+ }
61
+
62
+ /** With `moire` (lever 4), the moire error widens the comparison, as in Unreal (TSRShadingAnalysis.ush:569-613). */
63
+ export function createTemporalClampRelease(node: TemporalResolveNode, moire?: TemporalMoire) {
64
+ const [guide, filteredInput, filteredHistory, raw, filtered, release] = [0, 1, 2, 3, 4, 5].map(
65
+ () => {
66
+ const target = new RenderTarget(1, 1, { depthBuffer: false, type: HalfFloatType });
67
+ target.texture.minFilter = NearestFilter;
68
+ target.texture.magFilter = NearestFilter;
69
+ return target;
70
+ },
71
+ ) as [RenderTarget, RenderTarget, RenderTarget, RenderTarget, RenderTarget, RenderTarget];
72
+ const targets = [guide, filteredInput, filteredHistory, raw, filtered, release];
73
+ const released: TextureNode = texture(release.texture);
74
+ let passes:
75
+ | { materials: [RenderTarget, NodeMaterial][]; equations: TemporalDepthRejection }
76
+ | undefined;
77
+
78
+ function build(equations: TemporalDepthRejection): [RenderTarget, NodeMaterial][] {
79
+ const input = node.beautyNode as TextureNode;
80
+ const history = texture(node._historyRenderTarget.texture);
81
+ const size = () => vec2(input.size(int(0)) as Node<"uvec2">);
82
+ const loader = (target: RenderTarget): Load => {
83
+ const source = texture(target.texture);
84
+ return (at) => source.load(at) as Node<"vec4">;
85
+ };
86
+ return [
87
+ // Last frame's history at this frame's input pixels; alpha 0 where depth says disoccluded.
88
+ [
89
+ guide,
90
+ quad("guide", () => {
91
+ const validity = equations.historyValidity(uv());
92
+ const colour = history.sample(validity.get("historyUV") as Node<"vec2">);
93
+ return vec4(colour.rgb, validity.get("hasValidHistory") as Node<"float">);
94
+ }),
95
+ ],
96
+ [
97
+ filteredInput,
98
+ quad("input blur", () => blur(taps(size(), (at) => input.load(at) as Node<"vec4">))),
99
+ ],
100
+ [filteredHistory, quad("history blur", () => blur(taps(size(), loader(guide))))],
101
+ [
102
+ raw,
103
+ quad("rejection", () => {
104
+ const s = size();
105
+ const inputs = taps(s, (at) => input.load(at) as Node<"vec4">);
106
+ const box = inputs.reduce((a, b) => max(a, b)).sub(inputs.reduce((a, b) => min(a, b)));
107
+ const blurred = taps(s, loader(filteredInput));
108
+ const historyBlur = taps(s, loader(filteredHistory))[4] as Node<"vec4">;
109
+ const inputBlur = blurred[4] as Node<"vec4">;
110
+ // ponytail: Unreal also widens by the blurred total variation of the input; add it if edges flip.
111
+ const error = max(box.mul(FILTERING_WEIGHT * 0.25), QUANTIZATION).add(QUANTIZATION);
112
+ let low = blurred.reduce((a, b) => min(a, b)).sub(error);
113
+ let high = blurred.reduce((a, b) => max(a, b)).add(error);
114
+ let boxSize = box.mul(FILTERING_WEIGHT).add(QUANTIZATION * 2 * FILTERING_WEIGHT);
115
+ if (moire !== undefined) {
116
+ const historyUV = equations.historyValidity(uv()).get("historyUV") as Node<"vec2">;
117
+ const historySize = vec2(history.size(int(0)) as Node<"uvec2">);
118
+ const moireError = moire.error(
119
+ historyUV,
120
+ uv().sub(historyUV).mul(historySize).length(),
121
+ );
122
+ const size = vec4(vec3(moireError.mul(3)), 0);
123
+ [low, high] = [min(low, high.sub(size)), max(high, low.add(size))];
124
+ const energy = historyBlur.clamp(low, high).sub(historyBlur).abs();
125
+ const share = energy.div(max(energy.r.add(energy.g).add(energy.b), 1e-6));
126
+ boxSize = max(boxSize, share.mul(moireError.mul(FILTERING_WEIGHT * 3)));
127
+ }
128
+ const delta = max(inputBlur.sub(historyBlur).abs(), boxSize);
129
+ const factor = float(1)
130
+ .sub(historyBlur.clamp(low, high).sub(historyBlur).abs().div(delta))
131
+ .saturate();
132
+ return vec4(min(factor.r, factor.g, factor.b));
133
+ }),
134
+ ],
135
+ [filtered, quad("median", () => vec4(median(taps(size(), loader(raw)).map((v) => v.x))))],
136
+ // ponytail: no velocity-edge term (Unreal's InputUncertainty); add it if edges of movers ghost.
137
+ [
138
+ release,
139
+ quad("min", () => {
140
+ const guideValid = (texture(guide.texture).load(ivec2(uv().mul(size()))) as Node<"vec4">)
141
+ .a;
142
+ const lowest = taps(size(), loader(filtered)).reduce((a, b) => min(a, b)).x;
143
+ return vec4(lowest.mul(guideValid.greaterThan(0.5).select(float(1), float(0))));
144
+ }),
145
+ ],
146
+ ];
147
+ }
148
+
149
+ return {
150
+ /** The clipped history lerped back towards the unclipped one where input and history agree. */
151
+ apply(clipped: Node<"vec4">, history: Node<"vec4">, pixel: Node<"vec2">): Node<"vec4"> {
152
+ return mix(clipped, history, released.sample(pixel).x);
153
+ },
154
+ /** Before the resolve: it reads this frame's input against last frame's history. */
155
+ update(
156
+ renderer: Renderer,
157
+ quadMesh: QuadMesh,
158
+ equations: TemporalDepthRejection,
159
+ input: { x: number; y: number },
160
+ ) {
161
+ for (const target of targets)
162
+ if (target.width !== input.x || target.height !== input.y) {
163
+ target.setSize(input.x, input.y);
164
+ renderer.initRenderTarget(target);
165
+ }
166
+ if (passes?.equations !== equations) {
167
+ for (const [, material] of passes?.materials ?? []) material.dispose();
168
+ passes = { materials: build(equations), equations };
169
+ }
170
+ for (const [target, material] of passes.materials) {
171
+ renderer.setRenderTarget(target);
172
+ quadMesh.material = material;
173
+ quadMesh.render(renderer);
174
+ }
175
+ },
176
+ dispose() {
177
+ for (const target of targets) target.dispose();
178
+ for (const [, material] of passes?.materials ?? []) material.dispose();
179
+ },
180
+ };
181
+ }
182
+
183
+ export type TemporalClampRelease = ReturnType<typeof createTemporalClampRelease>;
@@ -0,0 +1,90 @@
1
+ // Generated user source: Unreal TSR's history resolve for a history stored above the display raster.
2
+ // The chain reads its display-sized output in place of the history, so later post stages pay
3
+ // display pixels, not history pixels.
4
+ import { HalfFloatType, type Vector2 } from "three";
5
+ import { Fn, float, int, ivec2, max, min, texture, uv, vec2, vec4 } from "three/tsl";
6
+ import {
7
+ type Node,
8
+ NodeMaterial,
9
+ type QuadMesh,
10
+ RenderTarget,
11
+ type Renderer,
12
+ type TextureNode,
13
+ } from "three/webgpu";
14
+ import type { ITemporalAANode } from "./temporalResolveDepth.js";
15
+
16
+ /** Mitchell–Netravali, B = C = 1/3, at distance x (UE 5.8.3: Engine/Shaders/Private/
17
+ * TemporalSuperResolution/TSRResolveHistory.usf:82-83). */
18
+ function mitchell(x: number): number {
19
+ const b = 1 / 3;
20
+ const c = 1 / 3;
21
+ const ax = Math.abs(x);
22
+ if (ax < 1)
23
+ return ((12 - 9 * b - 6 * c) * ax ** 3 + (-18 + 12 * b + 6 * c) * ax ** 2 + (6 - 2 * b)) / 6;
24
+ if (ax < 2)
25
+ return (
26
+ ((-b - 6 * c) * ax ** 3 +
27
+ (6 * b + 30 * c) * ax ** 2 +
28
+ (-12 * b - 48 * c) * ax +
29
+ (8 * b + 24 * c)) /
30
+ 6
31
+ );
32
+ return 0;
33
+ }
34
+
35
+ /**
36
+ * Unreal TSR's history resolve (UE 5.8.3: Engine/Shaders/Private/TemporalSuperResolution/
37
+ * TSRResolveHistory.usf:312-357): a display pixel takes the 4×4 history pixels around its centre,
38
+ * Mitchell-weighted by their distance in history pixels and by Unreal's HDR weight 1 / (R + 2G + B + 4)
39
+ * (TSRColorSpace.ush:167-195), then clamped to those samples' range. At a 2x history the centre sits
40
+ * between pixels, so the taps lie at ±0.5 and ±1.5 history pixels.
41
+ */
42
+ function createHistoryResolve(resolve: TextureNode): NodeMaterial {
43
+ const weights = [1.5, 0.5, 0.5, 1.5].map(mitchell);
44
+ const material = new NodeMaterial();
45
+ material.name = "Temporal AA history resolve";
46
+ material.fragmentNode = Fn(() => {
47
+ const size = vec2(resolve.size(int(0)) as Node<"uvec2">);
48
+ const base = ivec2(uv().mul(size).sub(1.5).floor());
49
+ const sum = vec4(0).toVar();
50
+ const weightSum = float(0).toVar();
51
+ const samples: Node<"vec4">[] = [];
52
+ for (let y = 0; y < 4; y++)
53
+ for (let x = 0; x < 4; x++) {
54
+ const at = ivec2(vec2(base.add(ivec2(x, y))).clamp(vec2(0), size.sub(1)));
55
+ const colour = (resolve.load(at).max(0) as Node<"vec4">).toVar();
56
+ const hdr = float(1).div(colour.r.add(colour.g.mul(2)).add(colour.b).add(4));
57
+ const weight = hdr.mul((weights[x] ?? 0) * (weights[y] ?? 0));
58
+ sum.addAssign(colour.mul(weight));
59
+ weightSum.addAssign(weight);
60
+ samples.push(colour);
61
+ }
62
+ // The range starts from a real sample: WGSL has no infinity literal.
63
+ const low = samples.reduce((a, b) => min(a, b));
64
+ const high = samples.reduce((a, b) => max(a, b));
65
+ return sum.div(weightSum).clamp(low, high);
66
+ })();
67
+ return material;
68
+ }
69
+
70
+ /** The display-sized target the chain reads in place of a 2x history, and its resolve draw. */
71
+ export function createHistoryPresent(internals: ITemporalAANode, quadMesh: QuadMesh) {
72
+ const target = new RenderTarget(1, 1, { depthBuffer: false, type: HalfFloatType });
73
+ const material = createHistoryResolve(texture(internals._resolveRenderTarget.texture));
74
+ return {
75
+ draw(renderer: Renderer, display: Vector2): void {
76
+ if (target.width !== display.x || target.height !== display.y) {
77
+ target.setSize(display.x, display.y);
78
+ renderer.initRenderTarget(target);
79
+ }
80
+ internals._textureNode.value = target.texture;
81
+ renderer.setRenderTarget(target);
82
+ quadMesh.material = material;
83
+ quadMesh.render(renderer);
84
+ },
85
+ dispose(): void {
86
+ target.dispose();
87
+ material.dispose();
88
+ },
89
+ };
90
+ }
@@ -0,0 +1,190 @@
1
+ // Generated user source: Unreal TSR's flicker-aware shading rejection (PRD-539 lever 4). A pixel whose
2
+ // output luma keeps changing direction against what plain ghosting would give is moire, not new
3
+ // shading, so its clip box widens by a bounded luma error and its history survives instead of resetting.
4
+ // UE 5.8.3: Engine/Shaders/Private/TemporalSuperResolution/TSRShadingAnalysis.ush:225-229,263-271,
5
+ // 381-455,477-490,586-593; the 2-frame period and the 0.95 decay come from
6
+ // Engine/Source/Runtime/Renderer/Private/PostProcess/TemporalSuperResolution.cpp:177-193,3005-3007.
7
+ import { HalfFloatType, NearestFilter, type Vector2 } from "three";
8
+ import {
9
+ Fn,
10
+ abs,
11
+ float,
12
+ int,
13
+ ivec2,
14
+ max,
15
+ min,
16
+ mix,
17
+ texture,
18
+ uv,
19
+ vec2,
20
+ vec3,
21
+ vec4,
22
+ } from "three/tsl";
23
+ import {
24
+ type Node,
25
+ NodeMaterial,
26
+ type QuadMesh,
27
+ RenderTarget,
28
+ type Renderer,
29
+ type TextureNode,
30
+ } from "three/webgpu";
31
+ import type { TemporalDepthRejection, TemporalResolveNode } from "./temporalResolveDepth.js";
32
+
33
+ const DECAY = 0.95;
34
+ const PERIOD = 2;
35
+ const MIN_GRADIENT = 1 / 127;
36
+ const LUMA_TO_CHANNEL = 3;
37
+ // Unreal's r.TSR.ShadingRejection.Flickering.MaxParallaxVelocity, in pixels of a 1920-wide output.
38
+ const MAX_PARALLAX_PX = 10;
39
+
40
+ /** Perceptual luma: the mean of the square-root channels (Unreal stores flicker luma in gamma space). */
41
+ const luma = (colour: Node<"vec4">) =>
42
+ colour.rgb
43
+ .max(0)
44
+ .sqrt()
45
+ .dot(vec3(1 / 3));
46
+
47
+ /** 1 where the pixel holds still, 0 where it moves. Unreal separates parallax from rotation; this
48
+ * counts every motion, so a rotating camera widens fewer boxes than Unreal does. */
49
+ function stillness(speedPx: Node<"float">, displayWidth: Node<"float">) {
50
+ const limit = displayWidth.mul(MAX_PARALLAX_PX / 1920);
51
+ return float(1).sub(speedPx.div(limit).sub(0.5).saturate());
52
+ }
53
+
54
+ export function createTemporalMoire(node: TemporalResolveNode) {
55
+ const targets = [0, 1, 2].map(() => {
56
+ const target = new RenderTarget(1, 1, { depthBuffer: false, type: HalfFloatType });
57
+ target.texture.minFilter = NearestFilter;
58
+ target.texture.magFilter = NearestFilter;
59
+ return target;
60
+ });
61
+ const [first, , scratch] = targets as [RenderTarget, RenderTarget, RenderTarget];
62
+ let read = 0;
63
+ // x: last luma gradient, y: total flicker variation, z: flicker count. Both decay by 0.95 a frame.
64
+ const previous: TextureNode = texture(first.texture);
65
+ let passes: { materials: NodeMaterial[]; equations: TemporalDepthRejection } | undefined;
66
+
67
+ /** The moire luma error the history has measured at this pixel. `speedPx` counts history pixels,
68
+ * so the parallax limit scales with the history raster. */
69
+ function error(historyUV: Node<"vec2">, speedPx: Node<"float">): Node<"float"> {
70
+ const state = previous.sample(historyUV);
71
+ const count = state.z;
72
+ const ramp = count
73
+ .mul(1 - DECAY ** PERIOD)
74
+ .sub(0.5)
75
+ .saturate();
76
+ return abs(state.y.div(max(count, 1e-4)))
77
+ .add(count.div(127))
78
+ .mul(ramp)
79
+ .mul(stillness(speedPx, vec2(previous.size(int(0)) as Node<"uvec2">).x))
80
+ .saturate();
81
+ }
82
+
83
+ /** The clip box widened by that error. */
84
+ function widen(
85
+ low: Node<"vec4">,
86
+ high: Node<"vec4">,
87
+ historyUV: Node<"vec2">,
88
+ speedPx: Node<"float">,
89
+ ) {
90
+ const size = vec4(vec3(error(historyUV, speedPx).mul(LUMA_TO_CHANNEL)), 0);
91
+ return { low: min(low, high.sub(size)), high: max(high, low.add(size)) };
92
+ }
93
+
94
+ /** Pass 1, per pixel: this frame's gradient, and whether it turned against the last one. */
95
+ function detect(equations: TemporalDepthRejection): NodeMaterial {
96
+ const resolved = texture(node._resolveRenderTarget.texture);
97
+ const history = texture(node._historyRenderTarget.texture);
98
+ const result = new NodeMaterial();
99
+ result.name = "Temporal AA moire detect";
100
+ result.fragmentNode = Fn(() => {
101
+ const pixel = uv();
102
+ const validity = equations.historyValidity(pixel);
103
+ const historyUV = validity.get("historyUV") as Node<"vec2">;
104
+ const last = previous.sample(historyUV).x;
105
+ // What the output did against pure ghosting (5% current), clamped like Unreal's gradient.
106
+ const ghost = mix(
107
+ luma(history.sample(historyUV)),
108
+ luma((node.beautyNode as TextureNode).sample(pixel)),
109
+ 0.05,
110
+ );
111
+ const gradient = luma(resolved.sample(pixel)).sub(ghost).clamp(-1, 1);
112
+ const turned = gradient.mul(last).lessThan(0);
113
+ const strong = min(abs(gradient), abs(last)).greaterThanEqual(MIN_GRADIENT);
114
+ const flicker = turned
115
+ .and(strong)
116
+ .select(float(1), float(0))
117
+ .mul(validity.get("hasValidHistory") as Node<"float">);
118
+ return vec4(gradient, min(abs(gradient), abs(last)).mul(flicker), flicker, 1);
119
+ })();
120
+ return result;
121
+ }
122
+
123
+ /** Pass 2: the flicker and its variation dilated over 5x5 (Unreal's max3x3 of max3x3), then
124
+ * accumulated into the decayed state of still, valid pixels. */
125
+ function accumulate(equations: TemporalDepthRejection): NodeMaterial {
126
+ const detected = texture(scratch.texture);
127
+ const result = new NodeMaterial();
128
+ result.name = "Temporal AA moire accumulate";
129
+ result.fragmentNode = Fn(() => {
130
+ const pixel = uv();
131
+ const validity = equations.historyValidity(pixel);
132
+ const historyUV = validity.get("historyUV") as Node<"vec2">;
133
+ const size = vec2(previous.size(int(0)) as Node<"uvec2">);
134
+ const centre = ivec2(pixel.mul(size));
135
+ let peak: Node<"vec4"> = detected.load(centre) as Node<"vec4">;
136
+ for (let y = -2; y <= 2; y++)
137
+ for (let x = -2; x <= 2; x++)
138
+ if (x !== 0 || y !== 0) {
139
+ const at = ivec2(vec2(centre.add(ivec2(x, y))).clamp(vec2(0), size.sub(1)));
140
+ peak = max(peak, detected.load(at) as Node<"vec4">);
141
+ }
142
+ const state = previous.sample(historyUV);
143
+ const speed = pixel.sub(historyUV).mul(size).length();
144
+ const valid = validity.get("hasValidHistory") as Node<"float">;
145
+ const keep = stillness(speed, size.x).mul(valid).mul(DECAY);
146
+ const own = detected.load(centre) as Node<"vec4">;
147
+ return vec4(own.x, state.y.mul(keep).add(peak.y), state.z.mul(keep).add(peak.z), 1);
148
+ })();
149
+ return result;
150
+ }
151
+
152
+ return {
153
+ error,
154
+ widen,
155
+ /** After the resolve, before the history copy: it reads last frame's history at this frame's UVs. */
156
+ update(
157
+ renderer: Renderer,
158
+ quadMesh: QuadMesh,
159
+ equations: TemporalDepthRejection,
160
+ history: Vector2,
161
+ ) {
162
+ for (const target of targets)
163
+ if (target.width !== history.x || target.height !== history.y) {
164
+ target.setSize(history.x, history.y);
165
+ renderer.initRenderTarget(target);
166
+ }
167
+ if (passes?.equations !== equations) {
168
+ for (const material of passes?.materials ?? []) material.dispose();
169
+ passes = { materials: [detect(equations), accumulate(equations)], equations };
170
+ }
171
+ const write = targets[1 - read];
172
+ const [detection, accumulation] = passes.materials;
173
+ if (write === undefined || detection === undefined || accumulation === undefined) return;
174
+ renderer.setRenderTarget(scratch);
175
+ quadMesh.material = detection;
176
+ quadMesh.render(renderer);
177
+ renderer.setRenderTarget(write);
178
+ quadMesh.material = accumulation;
179
+ quadMesh.render(renderer);
180
+ read = 1 - read;
181
+ previous.value = write.texture;
182
+ },
183
+ dispose() {
184
+ for (const target of targets) target.dispose();
185
+ for (const material of passes?.materials ?? []) material.dispose();
186
+ },
187
+ };
188
+ }
189
+
190
+ export type TemporalMoire = ReturnType<typeof createTemporalMoire>;
@@ -3,9 +3,11 @@
3
3
  // from this kernel; `temporalResolveMath.ts` and `temporalResolveDepth.ts` hold its equations.
4
4
  // Derived resolve source: three/examples/jsm/tsl/display/TRAANode.js (pinned 0.185.1).
5
5
  import type TRAANode from "three/addons/tsl/display/TRAANode.js";
6
- import { Fn, add, float, int, luminance, max, mix, texture, uv } from "three/tsl";
6
+ import { Fn, add, float, int, luminance, max, mix, texture, uv, uvec2, vec2 } from "three/tsl";
7
7
  import type { Node } from "three/webgpu";
8
+ import type { TemporalClampRelease } from "./temporalClampRelease.js";
8
9
  import type { TemporalCurrentFootprint } from "./temporalCurrentFootprint.js";
10
+ import type { TemporalMoire } from "./temporalMoire.js";
9
11
  import {
10
12
  type TemporalDepthRejection,
11
13
  type TemporalResolveNode,
@@ -19,6 +21,37 @@ import {
19
21
 
20
22
  export { CATMULL_ROM_BASIS } from "./temporalResolveMath.js";
21
23
 
24
+ /** PRD-539 gate arms, ported from Unreal TSR. `historyScale` stores history and resolve at that
25
+ * multiple of the display raster (Unreal's `r.TSR.History.ScreenPercentage` / 100, 1 or 2); the
26
+ * next stage samples the resolve bilinearly at display pixel centres, a 2x2 box down-resolve.
27
+ * `velocityWeightClamp` caps the accumulated history sample count under motion. */
28
+ export interface ITemporalHistoryWeighting {
29
+ historyScale: number;
30
+ velocityWeightClamp: boolean;
31
+ /** Unreal TSR lever 4: widen the clip box where output luma flickers (`temporalMoire.ts`). */
32
+ flickerRejection?: boolean;
33
+ /** Lever 6: release the clip where input and history agree at low frequency. */
34
+ clampRelease?: boolean;
35
+ }
36
+
37
+ /**
38
+ * Unreal TSR at the Epic tier (PRD-539): history at 200% of the display (UE 5.8.3:
39
+ * Engine/Config/BaseScalability.ini:89, r.TSR.History.ScreenPercentage; Low to High keep 100) and a
40
+ * history weight clamped by velocity. The raw4 current-footprint path was measured at 100% only, so
41
+ * it keeps that history. Name `{ historyScale: 1, velocityWeightClamp: false }` to opt out.
42
+ */
43
+ export function historyWeighting(
44
+ requested: ITemporalHistoryWeighting | undefined,
45
+ raw4: boolean,
46
+ ): ITemporalHistoryWeighting {
47
+ if (requested !== undefined && requested.historyScale !== 1 && requested.historyScale !== 2)
48
+ throw new Error("Temporal AA historyScale must be 1 or 2.");
49
+ if (requested !== undefined) return requested;
50
+ return raw4
51
+ ? { historyScale: 1, velocityWeightClamp: false }
52
+ : { historyScale: 2, velocityWeightClamp: true };
53
+ }
54
+
22
55
  /** Returns the amount of subpixel (expressed within [0, 1]) in the velocity. */
23
56
  const subpixelCorrection = Fn(([velocityUV, textureSize]: [Node<"vec2">, Node<"uvec2">]) => {
24
57
  const velocityTexel = velocityUV.mul(textureSize);
@@ -73,7 +106,10 @@ export function createExperimentalTemporalResolve(
73
106
  renderer,
74
107
  ),
75
108
  current?: TemporalCurrentFootprint,
109
+ weighting: ITemporalHistoryWeighting = { historyScale: 1, velocityWeightClamp: false },
110
+ levers: { moire?: TemporalMoire; release?: TemporalClampRelease } = {},
76
111
  ) {
112
+ const { historyScale, velocityWeightClamp } = weighting;
77
113
  const node = source as TemporalResolveNode;
78
114
  const { historyValidity } = rejection;
79
115
  const { clipAABB } = createTemporalResolveMath(node);
@@ -93,9 +129,16 @@ export function createExperimentalTemporalResolve(
93
129
  // Reconstruction: gather the current frame's 3×3 input neighbourhood around the jittered sample
94
130
  // the scene pass drew, and read its moments for the variance clip from the same taps. At a 1:1
95
131
  // raster the plain current sample is exact; retain it instead of adding Gaussian blur.
132
+ // A full-resolution input under a 2x history keeps its owned point (the closest jittered tap)
133
+ // rather than the Gaussian gather: native axes are judged against the output raster, so the
134
+ // history scale is the only variable that changes.
135
+ const outputSize =
136
+ historyScale === 1
137
+ ? displaySize
138
+ : (uvec2(vec2(displaySize).div(historyScale).round()) as Node<"uvec2">);
96
139
  const reconstruction =
97
140
  current?.reconstruct(uvNode, displaySize) ??
98
- reconstructNeighbourhood(node.beautyNode, uvNode, inputSize, jitterOffset, displaySize);
141
+ reconstructNeighbourhood(node.beautyNode, uvNode, inputSize, jitterOffset, outputSize);
99
142
  const upsampled = inputSize.x.lessThan(displaySize.x).or(inputSize.y.lessThan(displaySize.y));
100
143
  const currentColor = upsampled.select(
101
144
  reconstruction.get("color") as Node<"vec4">,
@@ -106,29 +149,45 @@ export function createExperimentalTemporalResolve(
106
149
  interpolation === "linear"
107
150
  ? historyNode.sample(historyUV)
108
151
  : sampleCatmullRom(historyNode, historyUV).max(0);
109
- const motionFactor = uvNode
110
- .sub(historyUV)
111
- .mul(displaySize)
112
- .length()
113
- .div(node.maxVelocityLength)
114
- .saturate();
152
+ // Motion counts output pixels whatever the history raster, so a 2x history changes only the
153
+ // raster the history is stored at. Subpixel correction measures history-texel resampling and
154
+ // stays in history texels.
155
+ const outputPixelSpeed = uvNode.sub(historyUV).mul(displaySize).length().div(historyScale);
156
+ const motionFactor = outputPixelSpeed.div(node.maxVelocityLength).saturate();
115
157
  const currentWeight = float(0.05).toVar(); // A minimum weight
116
158
  if (node.useSubpixelCorrection) {
117
159
  // Increase the minimum weight towards the current frame when the velocity is more subpixel.
118
160
  currentWeight.addAssign(subpixelCorrection(offsetUV, displaySize).mul(0.25));
119
161
  }
162
+ if (velocityWeightClamp) {
163
+ // Unreal TSR's velocity clamp (UE 5.8.3: Engine/Source/Runtime/Renderer/Private/PostProcess/
164
+ // TemporalSuperResolution.cpp:3219-3224, Engine/Shaders/Private/TemporalSuperResolution/
165
+ // TSRUpdateHistory.usf:1262-1276): a history pixel holds 16 / scale² samples; at 1 output
166
+ // px/frame its accumulated count clamps to 4, lerped by speed, unless the luma change between
167
+ // history and current is larger (stability on high-contrast edges). A history clamped to N
168
+ // samples blends the current frame at 1 / (N + 1).
169
+ const historySamples = 16 / (historyScale * historyScale);
170
+ const amplitude = Math.min(1, Math.max(0, 1 - 4 / historySamples));
171
+ const historyLuma = luminance(historyColor.rgb);
172
+ const currentLuma = luminance(currentColor.rgb);
173
+ const stability = historyLuma
174
+ .sub(currentLuma)
175
+ .abs()
176
+ .div(max(historyLuma, currentLuma, 0.00001));
177
+ const maxValidity = max(float(1).sub(outputPixelSpeed.saturate().mul(amplitude)), stability);
178
+ currentWeight.assign(
179
+ max(currentWeight, float(1).div(maxValidity.mul(historySamples).add(1))),
180
+ );
181
+ }
120
182
  currentWeight.assign(hasValidHistory.select(currentWeight.add(motionFactor).saturate(), 1));
121
183
  // Reasonable gamma range is [0.75, 2]
122
184
  const varianceGamma = mix(0.5, 1, motionFactor.oneMinus().pow2());
123
185
  const variance = (reconstruction.get("variance") as Node<"vec4">).mul(varianceGamma);
124
- const minColor = mean.sub(variance);
125
- const maxColor = mean.add(variance);
126
- const clippedHistoryColor = clipAABB(
127
- mean.clamp(minColor, maxColor),
128
- historyColor,
129
- minColor,
130
- maxColor,
131
- );
186
+ const box = { low: mean.sub(variance), high: mean.add(variance) };
187
+ const { low: minColor, high: maxColor } =
188
+ levers.moire?.widen(box.low, box.high, historyUV, outputPixelSpeed.mul(historyScale)) ?? box;
189
+ const clipped = clipAABB(mean.clamp(minColor, maxColor), historyColor, minColor, maxColor);
190
+ const clippedHistoryColor = levers.release?.apply(clipped, historyColor, uvNode) ?? clipped;
132
191
  // Every accepted history colour still passes the raw current-tap variance box.
133
192
  // Diagnostic only: ordinary blending isolates luminance reweighting at the same weight.
134
193
  return blend === "ordinary"
@@ -75,6 +75,8 @@ export interface ITemporalResolvePinned {
75
75
  /** Actual input jitter, in input-raster UVs, captured beside the matching depth matrices. */
76
76
  _currentJitterUV?: Node<"vec2"> & ITemporalUniform<Vector2>;
77
77
  _previousJitterUV?: Node<"vec2"> & ITemporalUniform<Vector2>;
78
+ /** The node the chain reads: Three's pass texture over the resolve target. */
79
+ _textureNode: TextureNode;
78
80
  }
79
81
 
80
82
  export type TemporalResolveNode = TRAANode & ITemporalResolvePinned;