create-threenative 0.2.9 → 0.2.12

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 (737) hide show
  1. package/agent-docs/references/assertion-reference.md +109 -3
  2. package/agent-docs/references/auto-exposure.md +28 -45
  3. package/agent-docs/references/build-profiles.md +1 -1
  4. package/agent-docs/references/capability-reference.md +527 -44
  5. package/agent-docs/references/debug-surface.md +64 -0
  6. package/agent-docs/references/finding-assets.md +11 -12
  7. package/agent-docs/references/performance-basics.md +19 -0
  8. package/agent-docs/references/trace-a-slow-frame.md +21 -0
  9. package/agent-docs/references/visual-baseline.md +23 -4
  10. package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
  11. package/agent-files/.agents/skills/prd-creator/SKILL.md +17 -6
  12. package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +87 -23
  13. package/agent-files/.agents/skills/threenative-performance/SKILL.md +12 -11
  14. package/agent-files/.claude/hooks/ponytail-context.mjs +1 -1
  15. package/agent-files/scripts/reference.mjs +9 -4
  16. package/capabilities.json +739 -50
  17. package/dist/index.d.ts +40 -6
  18. package/dist/index.js +229 -36
  19. package/dist/quality.d.ts +12 -0
  20. package/dist/quality.js +166747 -0
  21. package/dist/threenative.js +60 -44
  22. package/dist/web-engine-gltf-loader.js +2 -0
  23. package/dist/web-engine-mesh-bvh-webgpu.js +1 -1
  24. package/dist/web-engine-mesh-bvh.js +7 -0
  25. package/dist/web-engine-post-effects.js +645 -19
  26. package/dist/web-engine-runtime.js +3528 -343
  27. package/package.json +19 -9
  28. package/template-assets/assets/bay-PROVENANCE.md +21 -0
  29. package/template-assets/assets/bay-ground.webp +0 -0
  30. package/template-assets/assets/bay-metal.webp +0 -0
  31. package/template-assets/assets/bay-pavement-normal.webp +0 -0
  32. package/template-assets/assets/bay-pavement.webp +0 -0
  33. package/template-assets/assets/bay-plaster-normal.webp +0 -0
  34. package/template-assets/assets/bay-plaster.webp +0 -0
  35. package/template-assets/assets/bay-wood-normal.webp +0 -0
  36. package/template-assets/assets/bay-wood.webp +0 -0
  37. package/template-assets/assets/tex-PROVENANCE.md +25 -0
  38. package/template-assets/assets/tex-bark-normal.webp +0 -0
  39. package/template-assets/assets/tex-bark.webp +0 -0
  40. package/template-assets/assets/tex-birch-bark.webp +0 -0
  41. package/template-assets/assets/tex-grass.webp +0 -0
  42. package/template-assets/assets/tex-planks-normal.webp +0 -0
  43. package/template-assets/assets/tex-planks.webp +0 -0
  44. package/template-assets/assets/tex-rock-normal.webp +0 -0
  45. package/template-assets/assets/tex-rock.webp +0 -0
  46. package/template-assets/assets/tex-roof-tiles-normal.webp +0 -0
  47. package/template-assets/assets/tex-roof-tiles.webp +0 -0
  48. package/template-assets/assets/tex-sand-normal.webp +0 -0
  49. package/template-assets/assets/tex-sand.webp +0 -0
  50. package/template-assets/assets/tex-stone-wall-normal.webp +0 -0
  51. package/template-assets/assets/tex-stone-wall.webp +0 -0
  52. package/template-assets/kitExposure.ts +20 -0
  53. package/template-assets/patches/three@0.185.1.patch +481 -272
  54. package/template-assets/quality/biome.json +7 -0
  55. package/template-assets/quality/eslint.config.js +3 -0
  56. package/template-assets/realistic-ocean/README.md +113 -0
  57. package/template-assets/realistic-ocean/install.mjs +56 -0
  58. package/template-assets/realistic-ocean/src/realisticOcean.ts +151 -0
  59. package/template-assets/realistic-ocean/src/realisticOceanLifetime.ts +29 -0
  60. package/template-assets/realistic-ocean/src/render/REALISTIC-OCEAN-LICENSE.txt +25 -0
  61. package/template-assets/realistic-ocean/src/render/realisticSea.ts +642 -0
  62. package/template-assets/realistic-ocean/src/render/realisticSeaMaps.ts +311 -0
  63. package/template-assets/realistic-ocean/src/render/realisticSpectrum.ts +289 -0
  64. package/templates/AGENTS.md +21 -0
  65. package/templates/CLAUDE.md +23 -0
  66. package/templates/action-rpg/.codex/config.toml +6 -2
  67. package/templates/action-rpg/.cursor/mcp.json +8 -2
  68. package/templates/action-rpg/.gemini/settings.json +8 -2
  69. package/templates/action-rpg/.mcp.json +8 -2
  70. package/templates/action-rpg/.vscode/mcp.json +9 -2
  71. package/templates/action-rpg/.zed/settings.json +9 -2
  72. package/templates/action-rpg/AGENTS.md +11 -11
  73. package/templates/action-rpg/CLAUDE.md +11 -11
  74. package/templates/action-rpg/opencode.json +10 -2
  75. package/templates/action-rpg/package.json +17 -11
  76. package/templates/action-rpg/playtests/combat.playtest.json +6 -0
  77. package/templates/action-rpg/playtests/inventory.playtest.json +22 -0
  78. package/templates/action-rpg/playtests/performance.playtest.json +1 -1
  79. package/templates/action-rpg/playtests/roll.playtest.json +112 -0
  80. package/templates/action-rpg/playtests/swing.playtest.json +55 -0
  81. package/templates/action-rpg/playtests/win.playtest.json +4 -4
  82. package/templates/action-rpg/src/entities/Fighter.ts +44 -4
  83. package/templates/action-rpg/src/entities/Player.ts +64 -12
  84. package/templates/action-rpg/src/render/atmosphere.ts +444 -0
  85. package/templates/action-rpg/src/render/backlightMaterial.ts +49 -18
  86. package/templates/action-rpg/src/render/clouds.ts +605 -0
  87. package/templates/action-rpg/src/render/dungeon.ts +8 -6
  88. package/templates/action-rpg/src/render/exposure.ts +11 -109
  89. package/templates/action-rpg/src/render/gpuSky.ts +752 -0
  90. package/templates/action-rpg/src/render/lighting.ts +27 -4
  91. package/templates/action-rpg/src/render/materialLighting.ts +2 -11
  92. package/templates/action-rpg/src/render/palette.ts +1 -0
  93. package/templates/action-rpg/src/render/postprocessing.ts +4 -4
  94. package/templates/action-rpg/src/render/props.ts +10 -8
  95. package/templates/action-rpg/src/render/quality.ts +56 -108
  96. package/templates/action-rpg/src/render/sky.ts +74 -1
  97. package/templates/action-rpg/src/scenes/Play.ts +16 -12
  98. package/templates/action-rpg/src/ui/CharacterPanel.tsx +7 -2
  99. package/templates/action-rpg/src/ui/Hud.tsx +5 -7
  100. package/templates/action-rpg/src/ui/InventoryPanel.tsx +14 -14
  101. package/templates/action-rpg/threenative.config.ts +3 -0
  102. package/templates/adventure/.codex/config.toml +23 -0
  103. package/templates/adventure/.cursor/mcp.json +38 -0
  104. package/templates/adventure/.gemini/settings.json +38 -0
  105. package/templates/adventure/.mcp.json +38 -0
  106. package/templates/adventure/.vscode/mcp.json +43 -0
  107. package/templates/adventure/.zed/settings.json +43 -0
  108. package/templates/adventure/AGENTS.md +60 -0
  109. package/templates/adventure/CLAUDE.md +62 -0
  110. package/templates/adventure/index.html +14 -0
  111. package/templates/adventure/kit.json +8 -0
  112. package/templates/adventure/native-playtests/survives.playtest.json +52 -0
  113. package/templates/adventure/opencode.json +49 -0
  114. package/templates/adventure/package.json +65 -0
  115. package/templates/adventure/playtests/boss.playtest.json +406 -0
  116. package/templates/adventure/playtests/combat.playtest.json +342 -0
  117. package/templates/adventure/playtests/controls.playtest.json +142 -0
  118. package/templates/adventure/playtests/explore.playtest.json +45 -0
  119. package/templates/adventure/playtests/flicker.playtest.json +206 -0
  120. package/templates/adventure/playtests/hearts.playtest.json +171 -0
  121. package/templates/adventure/playtests/lockon.playtest.json +256 -0
  122. package/templates/adventure/playtests/look.playtest.json +72 -0
  123. package/templates/adventure/playtests/move-hollow.playtest.json +106 -0
  124. package/templates/adventure/playtests/move.playtest.json +84 -0
  125. package/templates/adventure/playtests/performance.playtest.json +55 -0
  126. package/templates/adventure/playtests/puzzle.playtest.json +250 -0
  127. package/templates/adventure/playtests/stride.playtest.json +67 -0
  128. package/templates/adventure/playtests/survives.playtest.json +171 -0
  129. package/templates/adventure/playtests/thornback.playtest.json +267 -0
  130. package/templates/adventure/public/favicon.svg +4 -0
  131. package/templates/adventure/src/entities/Block.ts +114 -0
  132. package/templates/adventure/src/entities/Chest.ts +69 -0
  133. package/templates/adventure/src/entities/Door.ts +81 -0
  134. package/templates/adventure/src/entities/Dummy.ts +69 -0
  135. package/templates/adventure/src/entities/Flicker.ts +239 -0
  136. package/templates/adventure/src/entities/Hero.ts +561 -0
  137. package/templates/adventure/src/entities/LockOn.ts +180 -0
  138. package/templates/adventure/src/entities/Mossling.ts +249 -0
  139. package/templates/adventure/src/entities/Switch.ts +49 -0
  140. package/templates/adventure/src/entities/Thornback.ts +238 -0
  141. package/templates/adventure/src/entities/Warden.ts +196 -0
  142. package/templates/adventure/src/game.ts +65 -0
  143. package/templates/adventure/src/interact.ts +63 -0
  144. package/templates/adventure/src/level/Hollow.ts +240 -0
  145. package/templates/adventure/src/level/Vale.ts +383 -0
  146. package/templates/adventure/src/main.ts +18 -0
  147. package/templates/adventure/src/render/camera.ts +416 -0
  148. package/templates/adventure/src/render/creatures.ts +405 -0
  149. package/templates/adventure/src/render/effects.ts +333 -0
  150. package/templates/adventure/src/render/foliage.ts +1072 -0
  151. package/templates/adventure/src/render/hero.ts +1447 -0
  152. package/templates/adventure/src/render/kitExposure.ts +20 -0
  153. package/templates/adventure/src/render/lighting.ts +74 -0
  154. package/templates/adventure/src/render/loading.ts +332 -0
  155. package/templates/adventure/src/render/materials.ts +179 -0
  156. package/templates/adventure/src/render/palette.ts +137 -0
  157. package/templates/adventure/src/render/postprocessing.ts +70 -0
  158. package/templates/adventure/src/render/props.ts +383 -0
  159. package/templates/adventure/src/render/quality.ts +46 -0
  160. package/templates/adventure/src/render/sky.ts +271 -0
  161. package/templates/adventure/src/render/surface.ts +259 -0
  162. package/templates/adventure/src/render/touch-controls.ts +137 -0
  163. package/templates/adventure/src/scenes/Play.ts +959 -0
  164. package/templates/adventure/src/state.ts +113 -0
  165. package/templates/adventure/src/style.css +98 -0
  166. package/templates/adventure/src/ui/App.tsx +22 -0
  167. package/templates/adventure/src/ui/GameUi.tsx +20 -0
  168. package/templates/adventure/src/ui/Hud.tsx +70 -0
  169. package/templates/adventure/src/ui/Menu.tsx +15 -0
  170. package/templates/adventure/src/ui/main.tsx +14 -0
  171. package/templates/adventure/tailwind.config.ts +2 -0
  172. package/templates/adventure/threenative.config.ts +62 -0
  173. package/templates/adventure/tsconfig.json +17 -0
  174. package/templates/adventure/vite.config.ts +49 -0
  175. package/templates/collectathon/.codex/config.toml +23 -0
  176. package/templates/collectathon/.cursor/mcp.json +38 -0
  177. package/templates/collectathon/.gemini/settings.json +38 -0
  178. package/templates/collectathon/.mcp.json +38 -0
  179. package/templates/collectathon/.vscode/mcp.json +43 -0
  180. package/templates/collectathon/.zed/settings.json +43 -0
  181. package/templates/collectathon/AGENTS.md +58 -0
  182. package/templates/collectathon/CLAUDE.md +60 -0
  183. package/templates/collectathon/index.html +14 -0
  184. package/templates/collectathon/kit.json +8 -0
  185. package/templates/collectathon/native-playtests/survives.playtest.json +52 -0
  186. package/templates/collectathon/opencode.json +49 -0
  187. package/templates/collectathon/package.json +65 -0
  188. package/templates/collectathon/playtests/acrobatics.playtest.json +238 -0
  189. package/templates/collectathon/playtests/camera.playtest.json +80 -0
  190. package/templates/collectathon/playtests/clipped-probe.playtest.json +101 -0
  191. package/templates/collectathon/playtests/collect.playtest.json +196 -0
  192. package/templates/collectathon/playtests/combat.playtest.json +246 -0
  193. package/templates/collectathon/playtests/double-tap-air.playtest.json +198 -0
  194. package/templates/collectathon/playtests/double-tap.playtest.json +136 -0
  195. package/templates/collectathon/playtests/effects.playtest.json +124 -0
  196. package/templates/collectathon/playtests/enemies.playtest.json +295 -0
  197. package/templates/collectathon/playtests/explore.playtest.json +45 -0
  198. package/templates/collectathon/playtests/hop-reach.playtest.json +117 -0
  199. package/templates/collectathon/playtests/jump-chain.playtest.json +274 -0
  200. package/templates/collectathon/playtests/ledge-angle.playtest.json +107 -0
  201. package/templates/collectathon/playtests/ledge-too-high.playtest.json +115 -0
  202. package/templates/collectathon/playtests/ledge.playtest.json +100 -0
  203. package/templates/collectathon/playtests/look.playtest.json +64 -0
  204. package/templates/collectathon/playtests/performance.playtest.json +55 -0
  205. package/templates/collectathon/playtests/stride.playtest.json +111 -0
  206. package/templates/collectathon/playtests/survives.playtest.json +123 -0
  207. package/templates/collectathon/playtests/telegraphs.playtest.json +132 -0
  208. package/templates/collectathon/playtests/thornback.playtest.json +157 -0
  209. package/templates/collectathon/playtests/wall-kick.playtest.json +206 -0
  210. package/templates/collectathon/playtests/win.playtest.json +166 -0
  211. package/templates/collectathon/public/favicon.svg +4 -0
  212. package/templates/collectathon/src/entities/Hero.ts +915 -0
  213. package/templates/collectathon/src/entities/Pickup.ts +63 -0
  214. package/templates/collectathon/src/entities/Walker.ts +248 -0
  215. package/templates/collectathon/src/game.ts +51 -0
  216. package/templates/collectathon/src/level/Course.ts +590 -0
  217. package/templates/collectathon/src/level/terrain.ts +144 -0
  218. package/templates/collectathon/src/main.ts +14 -0
  219. package/templates/collectathon/src/playtest-events.ts +15 -0
  220. package/templates/collectathon/src/render/camera.ts +163 -0
  221. package/templates/collectathon/src/render/castle.ts +408 -0
  222. package/templates/collectathon/src/render/effects.ts +284 -0
  223. package/templates/collectathon/src/render/foliage.ts +744 -0
  224. package/templates/collectathon/src/render/ground.ts +139 -0
  225. package/templates/collectathon/src/render/hero.ts +452 -0
  226. package/templates/collectathon/src/render/kitExposure.ts +20 -0
  227. package/templates/collectathon/src/render/lighting.ts +65 -0
  228. package/templates/collectathon/src/render/loading.ts +332 -0
  229. package/templates/collectathon/src/render/materials.ts +196 -0
  230. package/templates/collectathon/src/render/palette.ts +82 -0
  231. package/templates/collectathon/src/render/postprocessing.ts +79 -0
  232. package/templates/collectathon/src/render/props.ts +218 -0
  233. package/templates/collectathon/src/render/quality.ts +54 -0
  234. package/templates/collectathon/src/render/sky.ts +262 -0
  235. package/templates/collectathon/src/render/surface.ts +269 -0
  236. package/templates/collectathon/src/render/touch-controls.ts +179 -0
  237. package/templates/collectathon/src/render/touch-layout.ts +48 -0
  238. package/templates/collectathon/src/render/water.ts +191 -0
  239. package/templates/collectathon/src/scenes/Play.ts +481 -0
  240. package/templates/collectathon/src/state.ts +38 -0
  241. package/templates/collectathon/src/style.css +106 -0
  242. package/templates/collectathon/src/ui/App.tsx +22 -0
  243. package/templates/collectathon/src/ui/GameUi.tsx +20 -0
  244. package/templates/collectathon/src/ui/Hud.tsx +77 -0
  245. package/templates/collectathon/src/ui/Menu.tsx +13 -0
  246. package/templates/collectathon/src/ui/main.tsx +14 -0
  247. package/templates/collectathon/tailwind.config.ts +2 -0
  248. package/templates/collectathon/threenative.config.ts +62 -0
  249. package/templates/collectathon/tsconfig.json +17 -0
  250. package/templates/collectathon/vite.config.ts +49 -0
  251. package/templates/kart/.codex/config.toml +23 -0
  252. package/templates/kart/.cursor/mcp.json +38 -0
  253. package/templates/kart/.gemini/settings.json +38 -0
  254. package/templates/kart/.mcp.json +38 -0
  255. package/templates/kart/.vscode/mcp.json +43 -0
  256. package/templates/kart/.zed/settings.json +43 -0
  257. package/templates/kart/AGENTS.md +58 -0
  258. package/templates/kart/CLAUDE.md +60 -0
  259. package/templates/kart/index.html +14 -0
  260. package/templates/kart/kit.json +8 -0
  261. package/templates/kart/native-playtests/survives.playtest.json +65 -0
  262. package/templates/kart/opencode.json +49 -0
  263. package/templates/kart/package.json +64 -0
  264. package/templates/kart/playtests/drift.playtest.json +226 -0
  265. package/templates/kart/playtests/explore.playtest.json +45 -0
  266. package/templates/kart/playtests/hit-stays-above-road.playtest.json +92 -0
  267. package/templates/kart/playtests/item-key.playtest.json +108 -0
  268. package/templates/kart/playtests/items.playtest.json +143 -0
  269. package/templates/kart/playtests/lap-times.playtest.json +138 -0
  270. package/templates/kart/playtests/laps.playtest.json +149 -0
  271. package/templates/kart/playtests/performance.playtest.json +57 -0
  272. package/templates/kart/playtests/race.playtest.json +294 -0
  273. package/templates/kart/playtests/restart.playtest.json +87 -0
  274. package/templates/kart/playtests/rocket-start.playtest.json +56 -0
  275. package/templates/kart/playtests/smooth-drive.playtest.json +101 -0
  276. package/templates/kart/playtests/surfaces.playtest.json +113 -0
  277. package/templates/kart/playtests/survives.playtest.json +116 -0
  278. package/templates/kart/playtests/wall.playtest.json +118 -0
  279. package/templates/kart/public/favicon.svg +4 -0
  280. package/templates/kart/src/entities/Driver.ts +123 -0
  281. package/templates/kart/src/entities/Items.ts +194 -0
  282. package/templates/kart/src/entities/Kart.ts +517 -0
  283. package/templates/kart/src/game.ts +45 -0
  284. package/templates/kart/src/main.ts +14 -0
  285. package/templates/kart/src/playtest-events.ts +15 -0
  286. package/templates/kart/src/render/camera.ts +83 -0
  287. package/templates/kart/src/render/course.ts +579 -0
  288. package/templates/kart/src/render/effects.ts +266 -0
  289. package/templates/kart/src/render/items.ts +163 -0
  290. package/templates/kart/src/render/kart.ts +256 -0
  291. package/templates/kart/src/render/kitExposure.ts +20 -0
  292. package/templates/kart/src/render/lighting.ts +58 -0
  293. package/templates/kart/src/render/loading.ts +332 -0
  294. package/templates/kart/src/render/materials.ts +119 -0
  295. package/templates/kart/src/render/palette.ts +74 -0
  296. package/templates/kart/src/render/postprocessing.ts +79 -0
  297. package/templates/kart/src/render/quality.ts +54 -0
  298. package/templates/kart/src/render/skids.ts +86 -0
  299. package/templates/kart/src/render/sky.ts +105 -0
  300. package/templates/kart/src/render/touch-controls.ts +168 -0
  301. package/templates/kart/src/render/touch-layout.ts +48 -0
  302. package/templates/kart/src/scenes/Race.ts +850 -0
  303. package/templates/kart/src/state.ts +53 -0
  304. package/templates/kart/src/style.css +106 -0
  305. package/templates/kart/src/track/Course.ts +276 -0
  306. package/templates/kart/src/track/Race.ts +133 -0
  307. package/templates/kart/src/ui/App.tsx +21 -0
  308. package/templates/kart/src/ui/GameUi.tsx +20 -0
  309. package/templates/kart/src/ui/Hud.tsx +172 -0
  310. package/templates/kart/src/ui/Menu.tsx +13 -0
  311. package/templates/kart/src/ui/main.tsx +14 -0
  312. package/templates/kart/tailwind.config.ts +2 -0
  313. package/templates/kart/threenative.config.ts +62 -0
  314. package/templates/kart/tsconfig.json +17 -0
  315. package/templates/kart/vite.config.ts +49 -0
  316. package/templates/minimal/.codex/config.toml +6 -2
  317. package/templates/minimal/.cursor/mcp.json +8 -2
  318. package/templates/minimal/.gemini/settings.json +8 -2
  319. package/templates/minimal/.mcp.json +8 -2
  320. package/templates/minimal/.vscode/mcp.json +9 -2
  321. package/templates/minimal/.zed/settings.json +9 -2
  322. package/templates/minimal/AGENTS.md +11 -13
  323. package/templates/minimal/CLAUDE.md +11 -13
  324. package/templates/minimal/opencode.json +10 -2
  325. package/templates/minimal/package.json +16 -10
  326. package/templates/minimal/playtests/camera-wall.playtest.json +36 -0
  327. package/templates/minimal/playtests/jump.playtest.json +45 -0
  328. package/templates/minimal/playtests/play.playtest.json +1 -1
  329. package/templates/minimal/src/game.ts +2 -0
  330. package/templates/minimal/src/render/atmosphere.ts +444 -0
  331. package/templates/minimal/src/render/backlightMaterial.ts +49 -18
  332. package/templates/minimal/src/render/camera.ts +35 -4
  333. package/templates/minimal/src/render/clouds.ts +605 -0
  334. package/templates/minimal/src/render/exposure.ts +7 -111
  335. package/templates/minimal/src/render/gpuSky.ts +752 -0
  336. package/templates/minimal/src/render/lighting.ts +26 -4
  337. package/templates/minimal/src/render/materialLighting.ts +2 -10
  338. package/templates/minimal/src/render/postprocessing.ts +4 -4
  339. package/templates/minimal/src/render/quality.ts +10 -116
  340. package/templates/minimal/src/render/sky.ts +73 -1
  341. package/templates/minimal/src/scenes/Play.ts +18 -7
  342. package/templates/platformer/.codex/config.toml +6 -2
  343. package/templates/platformer/.cursor/mcp.json +8 -2
  344. package/templates/platformer/.gemini/settings.json +8 -2
  345. package/templates/platformer/.mcp.json +8 -2
  346. package/templates/platformer/.vscode/mcp.json +9 -2
  347. package/templates/platformer/.zed/settings.json +9 -2
  348. package/templates/platformer/AGENTS.md +13 -9
  349. package/templates/platformer/CLAUDE.md +13 -9
  350. package/templates/platformer/opencode.json +10 -2
  351. package/templates/platformer/package.json +17 -11
  352. package/templates/platformer/playtests/dash-jump.playtest.json +34 -0
  353. package/templates/platformer/playtests/finish.playtest.json +58 -0
  354. package/templates/platformer/playtests/idle.playtest.json +44 -0
  355. package/templates/platformer/playtests/performance.playtest.json +1 -1
  356. package/templates/platformer/src/entities/Fox.ts +19 -6
  357. package/templates/platformer/src/game.ts +1 -0
  358. package/templates/platformer/src/level/Stage.ts +4 -1
  359. package/templates/platformer/src/render/backlightMaterial.ts +49 -18
  360. package/templates/platformer/src/render/camera.ts +30 -1
  361. package/templates/platformer/src/render/exposure.ts +6 -111
  362. package/templates/platformer/src/render/fox.ts +5 -2
  363. package/templates/platformer/src/render/kitExposure.ts +20 -0
  364. package/templates/platformer/src/render/materialLighting.ts +2 -11
  365. package/templates/platformer/src/render/postprocessing.ts +4 -4
  366. package/templates/platformer/src/render/props.ts +1 -2
  367. package/templates/platformer/src/render/quality.ts +10 -118
  368. package/templates/platformer/src/scenes/Play.ts +31 -15
  369. package/templates/platformer/src/ui/Menu.tsx +1 -1
  370. package/templates/puzzle/.codex/config.toml +6 -2
  371. package/templates/puzzle/.cursor/mcp.json +8 -2
  372. package/templates/puzzle/.gemini/settings.json +8 -2
  373. package/templates/puzzle/.mcp.json +8 -2
  374. package/templates/puzzle/.vscode/mcp.json +9 -2
  375. package/templates/puzzle/.zed/settings.json +9 -2
  376. package/templates/puzzle/AGENTS.md +14 -17
  377. package/templates/puzzle/CLAUDE.md +14 -17
  378. package/templates/puzzle/opencode.json +10 -2
  379. package/templates/puzzle/package.json +17 -11
  380. package/templates/puzzle/playtests/performance.playtest.json +1 -1
  381. package/templates/puzzle/playtests/replay-keeps-progress.playtest.json +78 -0
  382. package/templates/puzzle/src/render/backlightMaterial.ts +49 -18
  383. package/templates/puzzle/src/render/exposure.ts +11 -109
  384. package/templates/puzzle/src/render/lighting.ts +3 -3
  385. package/templates/puzzle/src/render/materialLighting.ts +2 -11
  386. package/templates/puzzle/src/render/palette.ts +1 -1
  387. package/templates/puzzle/src/render/postprocessing.ts +4 -4
  388. package/templates/puzzle/src/render/quality.ts +44 -153
  389. package/templates/puzzle/src/render/vault.ts +18 -6
  390. package/templates/puzzle/src/scenes/Play.ts +6 -1
  391. package/templates/puzzle/src/ui/Hud.tsx +8 -43
  392. package/templates/racing/.codex/config.toml +6 -2
  393. package/templates/racing/.cursor/mcp.json +8 -2
  394. package/templates/racing/.gemini/settings.json +8 -2
  395. package/templates/racing/.mcp.json +8 -2
  396. package/templates/racing/.vscode/mcp.json +9 -2
  397. package/templates/racing/.zed/settings.json +9 -2
  398. package/templates/racing/AGENTS.md +10 -12
  399. package/templates/racing/CLAUDE.md +10 -12
  400. package/templates/racing/opencode.json +10 -2
  401. package/templates/racing/package.json +17 -11
  402. package/templates/racing/playtests/brake.playtest.json +54 -0
  403. package/templates/racing/playtests/outcome.playtest.json +19 -0
  404. package/templates/racing/playtests/performance.playtest.json +1 -1
  405. package/templates/racing/playtests/stopped-car-is-not-rescued.playtest.json +59 -0
  406. package/templates/racing/src/entities/RacingCar.ts +12 -3
  407. package/templates/racing/src/entities/Rival.ts +11 -2
  408. package/templates/racing/src/render/atmosphere.ts +444 -0
  409. package/templates/racing/src/render/backlightMaterial.ts +49 -18
  410. package/templates/racing/src/render/clouds.ts +605 -0
  411. package/templates/racing/src/render/exposure.ts +6 -111
  412. package/templates/racing/src/render/gpuSky.ts +752 -0
  413. package/templates/racing/src/render/kitExposure.ts +20 -0
  414. package/templates/racing/src/render/lighting.ts +26 -4
  415. package/templates/racing/src/render/materialLighting.ts +2 -11
  416. package/templates/racing/src/render/materials.ts +2 -1
  417. package/templates/racing/src/render/postprocessing.ts +4 -4
  418. package/templates/racing/src/render/quality.ts +27 -115
  419. package/templates/racing/src/render/sky.ts +76 -5
  420. package/templates/racing/src/scenes/Race.ts +53 -42
  421. package/templates/racing/src/track/TrackSector.ts +5 -2
  422. package/templates/racing/src/ui/Hud.tsx +12 -7
  423. package/templates/rain/.codex/config.toml +6 -2
  424. package/templates/rain/.cursor/mcp.json +8 -2
  425. package/templates/rain/.gemini/settings.json +8 -2
  426. package/templates/rain/.mcp.json +8 -2
  427. package/templates/rain/.vscode/mcp.json +9 -2
  428. package/templates/rain/.zed/settings.json +9 -2
  429. package/templates/rain/AGENTS.md +12 -12
  430. package/templates/rain/CLAUDE.md +12 -12
  431. package/templates/rain/opencode.json +10 -2
  432. package/templates/rain/package.json +16 -10
  433. package/templates/rain/playtests/performance.playtest.json +1 -1
  434. package/templates/rain/src/game.ts +1 -1
  435. package/templates/rain/src/render/bloom-shader.ts +1 -1
  436. package/templates/rain/src/render/clouds-shader.ts +2 -2
  437. package/templates/rain/src/render/clouds.ts +2 -1
  438. package/templates/rain/src/render/exposure.ts +11 -109
  439. package/templates/rain/src/render/post-shader.ts +7 -11
  440. package/templates/rain/src/render/postprocessing.ts +8 -24
  441. package/templates/rain/src/render/quality.ts +44 -98
  442. package/templates/rain/src/render/world-shader.ts +281 -97
  443. package/templates/rain/src/render/world.ts +82 -2
  444. package/templates/rain/src/style.css +1 -1
  445. package/templates/rain/src/ui/GameUi.tsx +6 -2
  446. package/templates/rain/src/ui/Hud.tsx +1 -1
  447. package/templates/rain/tools/generate-shaders.mjs +2 -2
  448. package/templates/rain/tools/tempest-post.frag +4 -6
  449. package/templates/rain/tools/tempest-world.frag +80 -12
  450. package/templates/rts/.codex/config.toml +6 -2
  451. package/templates/rts/.cursor/mcp.json +8 -2
  452. package/templates/rts/.gemini/settings.json +8 -2
  453. package/templates/rts/.mcp.json +8 -2
  454. package/templates/rts/.vscode/mcp.json +9 -2
  455. package/templates/rts/.zed/settings.json +9 -2
  456. package/templates/rts/AGENTS.md +15 -16
  457. package/templates/rts/CLAUDE.md +15 -16
  458. package/templates/rts/opencode.json +10 -2
  459. package/templates/rts/package.json +16 -10
  460. package/templates/rts/playtests/performance.playtest.json +1 -1
  461. package/templates/rts/playtests/rts-attack.playtest.json +5 -0
  462. package/templates/rts/playtests/rts-build.playtest.json +20 -1
  463. package/templates/rts/playtests/rts-orders.playtest.json +1 -1
  464. package/templates/rts/playtests/rts-pause.playtest.json +112 -0
  465. package/templates/rts/playtests/rts-train.playtest.json +1 -1
  466. package/templates/rts/playtests/rts-zoom.playtest.json +81 -0
  467. package/templates/rts/src/game.ts +29 -7
  468. package/templates/rts/src/render/army.ts +181 -49
  469. package/templates/rts/src/render/backlightMaterial.ts +49 -18
  470. package/templates/rts/src/render/environment.ts +276 -0
  471. package/templates/rts/src/render/exposure.ts +3 -65
  472. package/templates/rts/src/render/ground.ts +478 -0
  473. package/templates/rts/src/render/lighting.ts +62 -11
  474. package/templates/rts/src/render/materialLighting.ts +2 -11
  475. package/templates/rts/src/render/materials.ts +47 -118
  476. package/templates/rts/src/render/palette.ts +30 -13
  477. package/templates/rts/src/render/picking.ts +18 -0
  478. package/templates/rts/src/render/postprocessing.ts +4 -4
  479. package/templates/rts/src/render/quality.ts +64 -85
  480. package/templates/rts/src/render/resources.ts +21 -22
  481. package/templates/rts/src/render/sky.ts +9 -12
  482. package/templates/rts/src/render/terrain.ts +36 -11
  483. package/templates/rts/src/scenes/Play.ts +373 -38
  484. package/templates/rts/src/sim/ai.ts +0 -11
  485. package/templates/rts/src/state.ts +46 -0
  486. package/templates/rts/src/style.css +1543 -0
  487. package/templates/rts/src/ui/Commands.tsx +204 -107
  488. package/templates/rts/src/ui/GameUi.tsx +12 -5
  489. package/templates/rts/src/ui/Hud.tsx +611 -116
  490. package/templates/rts/src/ui/Minimap.tsx +103 -37
  491. package/templates/rts/src/ui/icons.tsx +116 -0
  492. package/templates/rts/src/ui/labels.ts +73 -0
  493. package/templates/rts/src/ui/minimapPoint.ts +30 -0
  494. package/templates/rts/threenative.config.ts +1 -1
  495. package/templates/runner/.codex/config.toml +6 -2
  496. package/templates/runner/.cursor/mcp.json +8 -2
  497. package/templates/runner/.gemini/settings.json +8 -2
  498. package/templates/runner/.mcp.json +8 -2
  499. package/templates/runner/.vscode/mcp.json +9 -2
  500. package/templates/runner/.zed/settings.json +9 -2
  501. package/templates/runner/AGENTS.md +12 -12
  502. package/templates/runner/CLAUDE.md +12 -12
  503. package/templates/runner/opencode.json +10 -2
  504. package/templates/runner/package.json +17 -11
  505. package/templates/runner/playtests/near-miss.playtest.json +48 -0
  506. package/templates/runner/playtests/performance.playtest.json +2 -2
  507. package/templates/runner/playtests/stride.playtest.json +27 -0
  508. package/templates/runner/playtests/survives.playtest.json +2 -2
  509. package/templates/runner/src/conventions.ts +3 -1
  510. package/templates/runner/src/entities/Runner.ts +11 -5
  511. package/templates/runner/src/render/atmosphere.ts +444 -0
  512. package/templates/runner/src/render/backlightMaterial.ts +49 -18
  513. package/templates/runner/src/render/clouds.ts +605 -0
  514. package/templates/runner/src/render/exposure.ts +6 -111
  515. package/templates/runner/src/render/gpuSky.ts +752 -0
  516. package/templates/runner/src/render/kitExposure.ts +20 -0
  517. package/templates/runner/src/render/lighting.ts +26 -4
  518. package/templates/runner/src/render/materialLighting.ts +2 -11
  519. package/templates/runner/src/render/postprocessing.ts +4 -4
  520. package/templates/runner/src/render/quality.ts +26 -114
  521. package/templates/runner/src/render/sky.ts +73 -1
  522. package/templates/runner/src/scenes/Run.ts +19 -15
  523. package/templates/runner/src/track.ts +12 -3
  524. package/templates/sailing/.codex/config.toml +6 -2
  525. package/templates/sailing/.cursor/mcp.json +8 -2
  526. package/templates/sailing/.gemini/settings.json +8 -2
  527. package/templates/sailing/.mcp.json +8 -2
  528. package/templates/sailing/.vscode/mcp.json +9 -2
  529. package/templates/sailing/.zed/settings.json +9 -2
  530. package/templates/sailing/AGENTS.md +10 -11
  531. package/templates/sailing/CLAUDE.md +10 -11
  532. package/templates/sailing/opencode.json +10 -2
  533. package/templates/sailing/package.json +17 -11
  534. package/templates/sailing/playtests/fail.playtest.json +46 -5
  535. package/templates/sailing/playtests/float-after-the-run-ends.playtest.json +7 -0
  536. package/templates/sailing/playtests/performance.playtest.json +1 -1
  537. package/templates/sailing/src/game.ts +1 -0
  538. package/templates/sailing/src/render/backlightMaterial.ts +49 -18
  539. package/templates/sailing/src/render/exposure.ts +6 -111
  540. package/templates/sailing/src/render/kitExposure.ts +20 -0
  541. package/templates/sailing/src/render/materialLighting.ts +2 -11
  542. package/templates/sailing/src/render/ocean.ts +0 -1
  543. package/templates/sailing/src/render/postprocessing.ts +4 -4
  544. package/templates/sailing/src/render/quality.ts +31 -138
  545. package/templates/sailing/src/scenes/Sailing.ts +12 -4
  546. package/templates/sailing/src/ui/Hud.tsx +6 -2
  547. package/templates/sailing/src/ui/Menu.tsx +1 -1
  548. package/templates/shooter/.codex/config.toml +6 -2
  549. package/templates/shooter/.cursor/mcp.json +8 -2
  550. package/templates/shooter/.gemini/settings.json +8 -2
  551. package/templates/shooter/.mcp.json +8 -2
  552. package/templates/shooter/.vscode/mcp.json +9 -2
  553. package/templates/shooter/.zed/settings.json +9 -2
  554. package/templates/shooter/AGENTS.md +13 -12
  555. package/templates/shooter/CLAUDE.md +13 -12
  556. package/templates/shooter/index.html +1 -1
  557. package/templates/shooter/main.html +13 -0
  558. package/templates/shooter/opencode.json +10 -2
  559. package/templates/shooter/package.json +17 -11
  560. package/templates/shooter/playtests/breakable-shatters.playtest.json +6 -0
  561. package/templates/shooter/playtests/enemy-body-is-a-body.playtest.json +6 -0
  562. package/templates/shooter/playtests/hands-authored-rate.playtest.json +54 -0
  563. package/templates/shooter/playtests/movement-eases.playtest.json +53 -0
  564. package/templates/shooter/playtests/performance.playtest.json +3 -3
  565. package/templates/shooter/playtests/stairs-smooth-the-eye.playtest.json +56 -0
  566. package/templates/shooter/playtests/weapon-sharp-while-turning.playtest.json +206 -0
  567. package/templates/shooter/src/entities/Breakables.ts +34 -10
  568. package/templates/shooter/src/entities/Enemy.ts +176 -54
  569. package/templates/shooter/src/entities/FpsPlayer.ts +55 -16
  570. package/templates/shooter/src/entities/Rifle.ts +83 -9
  571. package/templates/shooter/src/entities/movement.ts +96 -0
  572. package/templates/shooter/src/render/atmosphere.ts +444 -0
  573. package/templates/shooter/src/render/backlightMaterial.ts +49 -18
  574. package/templates/shooter/src/render/camera.ts +3 -1
  575. package/templates/shooter/src/render/clouds.ts +605 -0
  576. package/templates/shooter/src/render/exposure.ts +10 -109
  577. package/templates/shooter/src/render/facade.ts +26 -68
  578. package/templates/shooter/src/render/gpuSky.ts +752 -0
  579. package/templates/shooter/src/render/lighting.ts +27 -4
  580. package/templates/shooter/src/render/materialAssignments.ts +9 -1
  581. package/templates/shooter/src/render/materialLighting.ts +2 -11
  582. package/templates/shooter/src/render/occlusion.ts +13 -4
  583. package/templates/shooter/src/render/palette.ts +1 -0
  584. package/templates/shooter/src/render/postprocessing.ts +4 -4
  585. package/templates/shooter/src/render/quality.ts +50 -108
  586. package/templates/shooter/src/render/scale.ts +0 -11
  587. package/templates/shooter/src/render/sky.ts +103 -2
  588. package/templates/shooter/src/render/surface.ts +140 -0
  589. package/templates/shooter/src/render/town.ts +3 -6
  590. package/templates/shooter/src/render/townMaterials.ts +95 -42
  591. package/templates/shooter/src/render/vehicles.ts +2 -0
  592. package/templates/shooter/src/scenes/Play.ts +83 -23
  593. package/templates/shooter/src/ui/Hud.tsx +268 -193
  594. package/templates/shooter/src/worker-page.ts +29 -0
  595. package/templates/shooter/src/worker.ts +5 -0
  596. package/templates/shooter/threenative.config.ts +3 -0
  597. package/templates/shooter/vite.config.ts +2 -0
  598. package/templates/snow/.codex/config.toml +6 -2
  599. package/templates/snow/.cursor/mcp.json +8 -2
  600. package/templates/snow/.gemini/settings.json +8 -2
  601. package/templates/snow/.mcp.json +8 -2
  602. package/templates/snow/.vscode/mcp.json +9 -2
  603. package/templates/snow/.zed/settings.json +9 -2
  604. package/templates/snow/AGENTS.md +12 -10
  605. package/templates/snow/CLAUDE.md +12 -10
  606. package/templates/snow/opencode.json +10 -2
  607. package/templates/snow/package.json +17 -11
  608. package/templates/snow/playtests/performance.playtest.json +1 -1
  609. package/templates/snow/src/render/backlightMaterial.ts +49 -18
  610. package/templates/snow/src/render/exposure.ts +17 -106
  611. package/templates/snow/src/render/materialLighting.ts +2 -11
  612. package/templates/snow/src/render/postprocessing.ts +11 -5
  613. package/templates/snow/src/render/quality.ts +46 -126
  614. package/templates/snow/src/render/snowSurface.ts +32 -15
  615. package/templates/snow/src/scenes/Snow.ts +2 -1
  616. package/templates/starter/.codex/config.toml +6 -2
  617. package/templates/starter/.cursor/mcp.json +8 -2
  618. package/templates/starter/.gemini/settings.json +8 -2
  619. package/templates/starter/.mcp.json +8 -2
  620. package/templates/starter/.vscode/mcp.json +9 -2
  621. package/templates/starter/.zed/settings.json +9 -2
  622. package/templates/starter/AGENTS.md +18 -14
  623. package/templates/starter/CLAUDE.md +18 -14
  624. package/templates/starter/index.html +1 -1
  625. package/templates/starter/main.html +12 -0
  626. package/templates/starter/native-playtests/react-hud.playtest.json +1 -0
  627. package/templates/starter/native-playtests/render-chain.playtest.json +34 -21
  628. package/templates/starter/opencode.json +10 -2
  629. package/templates/starter/package.json +17 -11
  630. package/templates/starter/playtests/play.playtest.json +22 -2
  631. package/templates/starter/playtests/production-readiness.playtest.json +56 -0
  632. package/templates/starter/src/entities/Crate.ts +19 -1
  633. package/templates/starter/src/render/arena.ts +2 -2
  634. package/templates/starter/src/render/atmosphere.ts +444 -0
  635. package/templates/starter/src/render/backlightMaterial.ts +49 -18
  636. package/templates/starter/src/render/camera.ts +28 -0
  637. package/templates/starter/src/render/clouds.ts +605 -0
  638. package/templates/starter/src/render/contactShadow.ts +50 -0
  639. package/templates/starter/src/render/exposure.ts +9 -111
  640. package/templates/starter/src/render/gpuSky.ts +752 -0
  641. package/templates/starter/src/render/grade.ts +1 -1
  642. package/templates/starter/src/render/lighting.ts +34 -6
  643. package/templates/starter/src/render/materialLighting.ts +2 -11
  644. package/templates/starter/src/render/postprocessing.ts +53 -34
  645. package/templates/starter/src/render/quality.ts +18 -147
  646. package/templates/starter/src/render/sky.ts +90 -40
  647. package/templates/starter/src/render/temporalAA.ts +1 -1
  648. package/templates/starter/src/render/temporalAAStage.ts +1 -1
  649. package/templates/starter/src/render/temporalCurrentFootprint.ts +0 -1
  650. package/templates/starter/src/render/temporalDetailStage.ts +106 -0
  651. package/templates/starter/src/render/temporalRejectionCounter.ts +2 -2
  652. package/templates/starter/src/render/volumetricFogCamera.ts +32 -0
  653. package/templates/starter/src/render/volumetricFogOptions.ts +7 -0
  654. package/templates/starter/src/render/volumetricFogTransport.ts +27 -19
  655. package/templates/starter/src/render/volumetricFogVolume.ts +31 -7
  656. package/templates/starter/src/scenes/Play.ts +11 -8
  657. package/templates/starter/src/ui/Hud.tsx +1 -1
  658. package/templates/starter/src/worker-page.ts +29 -0
  659. package/templates/starter/src/worker.ts +5 -0
  660. package/templates/starter/vite.config.ts +2 -0
  661. package/templates/tower-defense/.codex/config.toml +6 -2
  662. package/templates/tower-defense/.cursor/mcp.json +8 -2
  663. package/templates/tower-defense/.gemini/settings.json +8 -2
  664. package/templates/tower-defense/.mcp.json +8 -2
  665. package/templates/tower-defense/.vscode/mcp.json +9 -2
  666. package/templates/tower-defense/.zed/settings.json +9 -2
  667. package/templates/tower-defense/AGENTS.md +10 -12
  668. package/templates/tower-defense/CLAUDE.md +10 -12
  669. package/templates/tower-defense/opencode.json +10 -2
  670. package/templates/tower-defense/package.json +17 -11
  671. package/templates/tower-defense/playtests/chill-tint.playtest.json +387 -0
  672. package/templates/tower-defense/playtests/performance.playtest.json +1 -1
  673. package/templates/tower-defense/src/enemies/Enemy.ts +9 -0
  674. package/templates/tower-defense/src/render/backlightMaterial.ts +49 -18
  675. package/templates/tower-defense/src/render/exposure.ts +11 -109
  676. package/templates/tower-defense/src/render/lighting.ts +4 -2
  677. package/templates/tower-defense/src/render/materialLighting.ts +2 -11
  678. package/templates/tower-defense/src/render/postprocessing.ts +4 -4
  679. package/templates/tower-defense/src/render/quality.ts +10 -116
  680. package/templates/tower-defense/src/render/sky.ts +2 -2
  681. package/templates/tower-defense/src/scenes/Battle.ts +4 -0
  682. package/template-assets/autoExposure.ts +0 -225
  683. package/template-assets/exposureGraph.ts +0 -178
  684. package/template-assets/exposureReadback.ts +0 -79
  685. package/template-assets/worldEnvironment.ts +0 -1212
  686. package/templates/action-rpg/src/render/autoExposure.ts +0 -225
  687. package/templates/action-rpg/src/render/exposureGraph.ts +0 -178
  688. package/templates/action-rpg/src/render/exposureReadback.ts +0 -79
  689. package/templates/action-rpg/src/render/worldEnvironment.ts +0 -1212
  690. package/templates/minimal/src/render/autoExposure.ts +0 -225
  691. package/templates/minimal/src/render/exposureGraph.ts +0 -178
  692. package/templates/minimal/src/render/exposureReadback.ts +0 -79
  693. package/templates/minimal/src/render/worldEnvironment.ts +0 -1212
  694. package/templates/platformer/src/render/autoExposure.ts +0 -225
  695. package/templates/platformer/src/render/exposureGraph.ts +0 -178
  696. package/templates/platformer/src/render/exposureReadback.ts +0 -79
  697. package/templates/platformer/src/render/worldEnvironment.ts +0 -1212
  698. package/templates/puzzle/src/render/autoExposure.ts +0 -225
  699. package/templates/puzzle/src/render/exposureGraph.ts +0 -178
  700. package/templates/puzzle/src/render/exposureReadback.ts +0 -79
  701. package/templates/puzzle/src/render/worldEnvironment.ts +0 -1212
  702. package/templates/racing/src/render/autoExposure.ts +0 -225
  703. package/templates/racing/src/render/exposureGraph.ts +0 -178
  704. package/templates/racing/src/render/exposureReadback.ts +0 -79
  705. package/templates/racing/src/render/worldEnvironment.ts +0 -1212
  706. package/templates/rain/src/render/autoExposure.ts +0 -225
  707. package/templates/rain/src/render/exposureGraph.ts +0 -178
  708. package/templates/rain/src/render/exposureReadback.ts +0 -79
  709. package/templates/rain/src/render/worldEnvironment.ts +0 -1212
  710. package/templates/rts/src/render/autoExposure.ts +0 -225
  711. package/templates/rts/src/render/exposureGraph.ts +0 -178
  712. package/templates/rts/src/render/exposureReadback.ts +0 -79
  713. package/templates/rts/src/render/worldEnvironment.ts +0 -1212
  714. package/templates/runner/src/render/autoExposure.ts +0 -225
  715. package/templates/runner/src/render/exposureGraph.ts +0 -178
  716. package/templates/runner/src/render/exposureReadback.ts +0 -79
  717. package/templates/runner/src/render/worldEnvironment.ts +0 -1212
  718. package/templates/sailing/src/render/autoExposure.ts +0 -225
  719. package/templates/sailing/src/render/exposureGraph.ts +0 -178
  720. package/templates/sailing/src/render/exposureReadback.ts +0 -79
  721. package/templates/sailing/src/render/worldEnvironment.ts +0 -1212
  722. package/templates/shooter/src/render/autoExposure.ts +0 -225
  723. package/templates/shooter/src/render/exposureGraph.ts +0 -178
  724. package/templates/shooter/src/render/exposureReadback.ts +0 -79
  725. package/templates/shooter/src/render/worldEnvironment.ts +0 -1212
  726. package/templates/snow/src/render/autoExposure.ts +0 -225
  727. package/templates/snow/src/render/exposureGraph.ts +0 -178
  728. package/templates/snow/src/render/exposureReadback.ts +0 -79
  729. package/templates/snow/src/render/worldEnvironment.ts +0 -1212
  730. package/templates/starter/src/render/autoExposure.ts +0 -225
  731. package/templates/starter/src/render/exposureGraph.ts +0 -178
  732. package/templates/starter/src/render/exposureReadback.ts +0 -79
  733. package/templates/starter/src/render/worldEnvironment.ts +0 -1212
  734. package/templates/tower-defense/src/render/autoExposure.ts +0 -225
  735. package/templates/tower-defense/src/render/exposureGraph.ts +0 -178
  736. package/templates/tower-defense/src/render/exposureReadback.ts +0 -79
  737. package/templates/tower-defense/src/render/worldEnvironment.ts +0 -1212
@@ -0,0 +1,642 @@
1
+ // Generated for you. The realistic sea's tuning and its entire look live in these files, and
2
+ // ThreeNative does not read them. `SpectralOcean` runs the simulation and draws nothing; this file
3
+ // is the mesh, the material, the colours and the shading decisions, and every number in it is yours
4
+ // to change: the spectrum in `realisticSpectrum.ts`, the foam's memory in `realisticSeaMaps.ts`.
5
+ //
6
+ // What it adds to a plain spectral sea, each one adapted from web-ocean (MIT, Copyright (c) 2026
7
+ // Maksymilian Dendura; see REALISTIC-OCEAN-LICENSE.txt):
8
+ // - a fetch-limited JONSWAP wind sea plus an independently directed swell, scaled to a target
9
+ // significant wave height, with capillary dispersion at the short end;
10
+ // - three cascades, so one frame holds a swell, a chop and a skin of ripples at once;
11
+ // - slope-moment filtering: the slope a pixel is too far away to resolve is not thrown away, it is
12
+ // spent as roughness, so the sun's glitter path widens with distance instead of vanishing or
13
+ // shimmering;
14
+ // - whitecaps that persist and age, from the Jacobian of the horizontal displacement;
15
+ // - light coming through backlit crests.
16
+ //
17
+ // It composes with the scene it is in. Light, shadow, image-based reflection, fog and tone mapping
18
+ // are the scene's own: this is a standard node material, not a second lighting model.
19
+ import { type ISpectralOceanOptions, SpectralOcean } from "@threenative/core";
20
+ import {
21
+ BufferGeometry,
22
+ Color,
23
+ Float32BufferAttribute,
24
+ Mesh,
25
+ type Scene,
26
+ Vector2,
27
+ Vector3,
28
+ } from "three";
29
+ import {
30
+ BRDF_Lambert,
31
+ F_Schlick,
32
+ Fn,
33
+ V_GGX_SmithCorrelated,
34
+ abs,
35
+ cameraPosition,
36
+ cameraViewMatrix,
37
+ color,
38
+ diffuseColor,
39
+ dot,
40
+ float,
41
+ luminance,
42
+ max,
43
+ mix,
44
+ mx_noise_float,
45
+ normalView,
46
+ normalWorld,
47
+ oneMinus,
48
+ positionGeometry,
49
+ positionLocal,
50
+ positionViewDirection,
51
+ positionWorld,
52
+ pow,
53
+ reference,
54
+ roughness,
55
+ saturate,
56
+ smoothstep,
57
+ transformNormalToView,
58
+ uniform,
59
+ uniformArray,
60
+ vec2,
61
+ vec3,
62
+ vec4,
63
+ } from "three/tsl";
64
+ import type { Node, NodeBuilder } from "three/webgpu";
65
+ import { MeshStandardNodeMaterial, PhysicalLightingModel } from "three/webgpu";
66
+ import { SeaMaps, sampleBilinear, sampleBilinearFloat } from "./realisticSeaMaps.js";
67
+ import {
68
+ type ISeaState,
69
+ capillaryCrossover,
70
+ seaEnergy,
71
+ slopeVarianceTable,
72
+ } from "./realisticSpectrum.js";
73
+
74
+ /**
75
+ * The sea state. Every number is this game's.
76
+ *
77
+ * `wind.fetch` and `wind.speed` set how long and how tall the wind sea is; `swell` is a second,
78
+ * straighter-crested train that does not care where the wind is blowing; `waveHeight` scales the
79
+ * whole thing so the sea is as tall as you say it is, whatever the grid resolution.
80
+ */
81
+ // web-ocean's own sea: a 7 m/s wind sea over 90 km and a 1.8 m, 120 m swell. Directions are set
82
+ // against the sailing kit's sun (bearing -0.6 rad) the way web-ocean sets them against its own:
83
+ // the wind sea runs 204 degrees from the sun's bearing, the swell straight away from it, so
84
+ // looking into the sun is looking along the crests' faces, where glitter and backlight are.
85
+ export const SEA_STATE: ISeaState = {
86
+ wind: { speed: 7, direction: 2.96, fetch: 90_000, peakEnhancement: 3.3 },
87
+ swell: { height: 1.8, direction: 2.54, peakFrequency: 0.717, spreading: 48 },
88
+ gravity: 9.81,
89
+ surfaceTension: 7.4e-5,
90
+ // web-ocean's 1.2 mm. Larger cuts into the ripples the finest cascade exists to carry.
91
+ shortWaveCut: 0.0012,
92
+ // The height web-ocean's own spectrum has at these inputs, unscaled: 2.3 m.
93
+ waveHeight: 2.3,
94
+ };
95
+
96
+ /**
97
+ * The cascades, largest patch first. Each one carries only the wavelengths the next-larger patch
98
+ * cannot resolve, so no wave is counted twice. 256 / 48 / 9 metres on a 128 grid resolves from a
99
+ * 4 m swell down to a 14 cm ripple. The first patch also sets the spacing of the CPU height copy
100
+ * (`readbackResolution` over this), which is why it is not larger: a ship cannot float on a grid
101
+ * coarser than it is long.
102
+ */
103
+ export const SEA_CASCADES = [{ patchSize: 256 }, { patchSize: 48 }, { patchSize: 9 }] as const;
104
+
105
+ export const SEA = {
106
+ cascades: SEA_CASCADES,
107
+ resolution: 128,
108
+ // Horizontal displacement scale. Above zero sharpens crests, which is also what folds them into
109
+ // whitecaps, so it is the foam's input as much as the shape's.
110
+ choppiness: 1.25,
111
+ seed: 20_261_020,
112
+ // 128 across a 256 m patch is one height every two metres. See `SEA_CASCADES`.
113
+ readbackResolution: 128,
114
+ readbackEveryFrames: 3,
115
+ gravity: SEA_STATE.gravity,
116
+ windSpeed: SEA_STATE.wind.speed,
117
+ windDirection: SEA_STATE.wind.direction,
118
+ // Ignored while `energy` is set, and required by the option list: there are no defaults.
119
+ amplitude: 1,
120
+ directionality: 1,
121
+ smallWaveCutoff: SEA_STATE.shortWaveCut,
122
+ } satisfies Omit<ISpectralOceanOptions, "energy" | "capillaryWavenumber">;
123
+
124
+ /** The whitecaps' memory. */
125
+ export const FOAM = {
126
+ /** Seconds for a patch of foam to halve. */
127
+ halfLife: 3,
128
+ /** Jacobian below which water is breaking. */
129
+ threshold: 0.76,
130
+ gain: 3,
131
+ /**
132
+ * Jacobian below which a crest is breaking this frame, before the grids remember it. Stricter
133
+ * than `threshold`: every steep ripple would otherwise flash white.
134
+ */
135
+ freshThreshold: 0.6,
136
+ /** Foam grids ride on these cascades, finest first. The second is the coarse, far one. */
137
+ cascades: [1, 0] as readonly number[],
138
+ } as const;
139
+
140
+ /** Looks: colours are linear RGB, sizes are metres. */
141
+ export const LOOK = {
142
+ // web-ocean's coastal body colour (turbidity 1.6), lit the way a standard material lights it:
143
+ // its scatter times 1.6 on the crests, half that in the troughs.
144
+ deep: 0x275a62,
145
+ shallow: 0x397d88,
146
+ foam: 0xe6eef0,
147
+ /** Light coming through a thin backlit crest, and how strongly. */
148
+ subsurface: 0x356252,
149
+ subsurfaceGain: 2.6,
150
+ /**
151
+ * Radiance of the sun for the crest glow only, until `setSun` is given the scene's key light.
152
+ * The scene's own light lights everything else.
153
+ */
154
+ sunRadiance: [3.4, 3.1, 2.5] as readonly [number, number, number],
155
+ /** Fraction of the mirrored hull and marks that shows. A render target is written linear. */
156
+ mirrorGain: 0.55,
157
+ /**
158
+ * Mean-square slope of the capillary ripples no cascade carries, at any distance, plus what
159
+ * grows in with distance (`far`, from `from` to `to` metres). Without it a near pixel is a
160
+ * mirror: the sun lands on a few facets as pinpoints and the glitter path never forms.
161
+ */
162
+ capillarySlope: { near: 0.0048, far: 0.007, from: 30, to: 500 },
163
+ /**
164
+ * Where the sea stops being a skin of ripples and becomes sub-pixel slope, in metres of pixel.
165
+ * The nearest footprint is the finest cascade's texel, measured off the sea: a pixel finer than
166
+ * that still cannot see the ripples no cascade carries.
167
+ */
168
+ slopeTable: { count: 64, farthest: 400 },
169
+ } as const;
170
+
171
+ /** The disc's geometry: rings of quads whose spacing grows with radius, centred on the ship. */
172
+ export const SURFACE = { segments: 160, rings: 96, inner: 1.5, reach: 6_000 } as const;
173
+
174
+ /** How far astern a wake reaches, how fast it opens and how wide it is at the transom. */
175
+ export const WAKE = { length: 26, spread: 0.21, waist: 0.5 } as const;
176
+ /** The ring of broken water at a hull's waterline, as half its length and beam in metres. */
177
+ export const HULL_WASH = { halfBeam: 0.62, halfLength: 2.35 } as const;
178
+
179
+ /**
180
+ * The one thing the material asks of a planar mirror. Structural, so the type is not an import.
181
+ * Pass `undefined` to the surface for none; the image-based sky reflection stays.
182
+ */
183
+ export interface ISeaMirror {
184
+ reflectionAt(offset?: Node<"vec2">): Node<"vec3">;
185
+ dispose(): void;
186
+ }
187
+
188
+ export interface IRealisticWaterSurface {
189
+ readonly mesh: Mesh;
190
+ /** Move the drawn sea to follow a position, keeping the waves anchored to the world. */
191
+ follow(x: number, z: number): void;
192
+ /** The sea's own clock, in seconds. */
193
+ advance(elapsed: number): void;
194
+ /** Where a hull is, which way it points and how hard it pushes water aside (0..1). */
195
+ wake(x: number, z: number, forwardX: number, forwardZ: number, strength: number): void;
196
+ /** Direction toward the sun (any length) and the radiance the crest glow uses. */
197
+ setSun(
198
+ direction: readonly [number, number, number],
199
+ radiance?: readonly [number, number, number],
200
+ ): void;
201
+ /** Forget every whitecap, for a teleport or a restart. */
202
+ reset(): void;
203
+ dispose(): void;
204
+ }
205
+
206
+ /** The simulation. Hand it to `ctx.add` and it runs; it draws nothing. */
207
+ export function createRealisticSea(state: ISeaState = SEA_STATE): SpectralOcean {
208
+ const patchSizes = SEA.cascades.map((cascade) => cascade.patchSize);
209
+ return new SpectralOcean({
210
+ ...SEA,
211
+ cascades: SEA.cascades,
212
+ windSpeed: state.wind.speed,
213
+ windDirection: state.wind.direction,
214
+ gravity: state.gravity,
215
+ smallWaveCutoff: state.shortWaveCut,
216
+ energy: seaEnergy(state, SEA.resolution, patchSizes),
217
+ capillaryWavenumber: capillaryCrossover(state.gravity, state.surfaceTension),
218
+ });
219
+ }
220
+
221
+ /** The derivative and foam grids the material reads. Add it to the scene after the sea. */
222
+ export function createRealisticMaps(ocean: SpectralOcean): SeaMaps {
223
+ return new SeaMaps(ocean, {
224
+ foamHalfLife: FOAM.halfLife,
225
+ foamThreshold: FOAM.threshold,
226
+ foamGain: FOAM.gain,
227
+ foamCascades: FOAM.cascades,
228
+ });
229
+ }
230
+
231
+ /** The logarithmic disc, in the sea patch's own space: one vertex at the centre, then the rings. */
232
+ function seaDisc(): BufferGeometry {
233
+ const { inner, reach, rings, segments } = SURFACE;
234
+ const growth = Math.log(1 + reach / inner) / rings;
235
+ const positions: number[] = [0, 0, 0];
236
+ const indices: number[] = [];
237
+ for (let ring = 0; ring < rings; ring += 1) {
238
+ const radius = inner * (Math.exp((ring + 1) * growth) - 1);
239
+ for (let step = 0; step < segments; step += 1) {
240
+ const angle = (step / segments) * Math.PI * 2;
241
+ positions.push(Math.cos(angle) * radius, 0, Math.sin(angle) * radius);
242
+ }
243
+ }
244
+ for (let step = 0; step < segments; step += 1) {
245
+ indices.push(0, 1 + ((step + 1) % segments), 1 + step);
246
+ }
247
+ for (let ring = 1; ring < rings; ring += 1) {
248
+ for (let step = 0; step < segments; step += 1) {
249
+ const near = 1 + (ring - 1) * segments + step;
250
+ const nearNext = 1 + (ring - 1) * segments + ((step + 1) % segments);
251
+ const far = 1 + ring * segments + step;
252
+ const farNext = 1 + ring * segments + ((step + 1) % segments);
253
+ indices.push(near, farNext, far, near, nearNext, farNext);
254
+ }
255
+ }
256
+ const geometry = new BufferGeometry();
257
+ geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
258
+ geometry.setIndex(indices);
259
+ geometry.computeBoundingSphere();
260
+ return geometry;
261
+ }
262
+
263
+ /**
264
+ * three's physical model with three changes. Foam takes the sky's light as a bubble layer does,
265
+ * below. The sun's highlight is Beckmann, the Gaussian slope
266
+ * distribution sea slopes have: GGX's long tails spread the glitter path into a wide soft band.
267
+ * The environment's mirror term is at the brightness the sky is drawn (`scene.backgroundIntensity`):
268
+ * three scales it by `scene.environmentIntensity`, the fill a scene lights its objects with, which
269
+ * can be lower. The water's body keeps that fill, like every other object.
270
+ */
271
+ class SeaLightingModel extends PhysicalLightingModel {
272
+ /** Where the surface is foam, 0 to 1. */
273
+ readonly #foam: Node<"float">;
274
+
275
+ constructor(foam: Node<"float">) {
276
+ super();
277
+ this.#foam = foam;
278
+ }
279
+
280
+ override direct(light: Parameters<PhysicalLightingModel["direct"]>[0]): void {
281
+ const lightDirection = light.lightDirection as Node<"vec3">;
282
+ const lightColor = light.lightColor as Node<"vec3">;
283
+ const reflected = light.reflectedLight as unknown as Record<
284
+ "directDiffuse" | "directSpecular",
285
+ Node<"vec3">
286
+ >;
287
+ const dotNL = normalView.dot(lightDirection).clamp();
288
+ const dotNV = normalView.dot(positionViewDirection).clamp(1e-4, 1);
289
+ const half = lightDirection.add(positionViewDirection).normalize();
290
+ const cos2 = normalView.dot(half).clamp(1e-4, 1).pow(2);
291
+ const alpha = roughness.pow(2);
292
+ const meanSquareSlope = alpha.pow(2);
293
+ const beckmann = cos2
294
+ .oneMinus()
295
+ .div(cos2.mul(meanSquareSlope))
296
+ .negate()
297
+ .exp()
298
+ .div(meanSquareSlope.mul(Math.PI).mul(cos2.pow(2)));
299
+ const fresnel = F_Schlick({
300
+ f0: float(0.02037),
301
+ f90: float(1),
302
+ dotVH: positionViewDirection.dot(half).clamp(),
303
+ }) as unknown as Node<"float">;
304
+ const visibility = V_GGX_SmithCorrelated({ alpha, dotNL, dotNV }) as unknown as Node<"float">;
305
+ const irradiance = lightColor.mul(dotNL);
306
+ // Light leaving the water's body was scattered from deep below, so it follows the sun's height,
307
+ // not each ripple's facet. Foam is a surface: it takes its facet, half shaded by its own lumps.
308
+ const up = cameraViewMatrix.mul(vec4(0, 1, 0, 0)).xyz;
309
+ const bodyNL = up.dot(lightDirection).clamp();
310
+ const diffuseNL = mix(bodyNL, dotNL.mul(0.5), this.#foam);
311
+ const lambert = BRDF_Lambert({ diffuseColor: diffuseColor.rgb }) as unknown as Node<"vec3">;
312
+ reflected.directDiffuse.addAssign(lightColor.mul(diffuseNL).mul(lambert));
313
+ reflected.directSpecular.addAssign(irradiance.mul(fresnel.mul(beckmann).mul(visibility)));
314
+ }
315
+
316
+ override indirectSpecular(builder: NodeBuilder): void {
317
+ const context = builder.context as Record<"radiance" | "iblIrradiance", Node<"vec3">>;
318
+ const radiance = context.radiance;
319
+ const irradiance = context.iblIrradiance;
320
+ const { scene } = builder as unknown as { scene: Scene };
321
+ const drawn = reference("backgroundIntensity", "float", scene);
322
+ const fill = reference("environmentIntensity", "float", scene);
323
+ context.radiance = radiance.mul(drawn.div(fill.max(1e-4)));
324
+ // Foam is a layer of bubbles that scatters the whole sky into the eye, about twice what one
325
+ // Lambert surface returns, and mostly grey: the sky's colour averages out between the bubbles.
326
+ const scattered = mix(irradiance, vec3(luminance(irradiance)), 0.85).mul(2);
327
+ context.iblIrradiance = mix(irradiance, scattered, this.#foam);
328
+ super.indirectSpecular(builder);
329
+ context.radiance = radiance;
330
+ context.iblIrradiance = irradiance;
331
+ }
332
+ }
333
+
334
+ export interface IRealisticWaterOptions {
335
+ /** A CPU rasteriser cannot draw the full graph fast enough for the height copy to land. */
336
+ readonly software?: boolean;
337
+ /** The spectrum the sea was built from, so the slope table matches it. Defaults to `SEA_STATE`. */
338
+ readonly state?: ISeaState;
339
+ }
340
+
341
+ export function createRealisticWaterMesh(
342
+ ocean: SpectralOcean,
343
+ maps: SeaMaps,
344
+ mirror: ISeaMirror | undefined,
345
+ options: IRealisticWaterOptions = {},
346
+ ): IRealisticWaterSurface {
347
+ const cheap = options.software === true;
348
+ const state = options.state ?? SEA_STATE;
349
+ const geometry = seaDisc();
350
+ const size = ocean.resolution;
351
+ const cascadeCount = ocean.cascades.length;
352
+ const patch = (c: number) => ocean.cascadePatchSize(c);
353
+ const texel = (c: number) => patch(c) / size;
354
+
355
+ const seaOrigin = uniform(new Vector2());
356
+ const seaTime = uniform(0);
357
+ const shipOrigin = uniform(new Vector2());
358
+ const shipForward = uniform(new Vector2(0, -1));
359
+ const wakeStrength = uniform(0);
360
+ const sunDirection = uniform(new Vector3(0.4, 0.8, 0.3).normalize());
361
+ const sunRadiance = uniform(new Vector3(...LOOK.sunRadiance));
362
+
363
+ // The glitter table: the slope carried by everything a pixel is too far away to resolve.
364
+ const slopeTable = { ...LOOK.slopeTable, nearest: texel(cascadeCount - 1) };
365
+ const table = slopeVarianceTable(
366
+ seaEnergy(
367
+ state,
368
+ size,
369
+ ocean.cascades.map((_, c) => patch(c)),
370
+ ),
371
+ slopeTable,
372
+ );
373
+ // A uniform array, not a storage buffer: a device made with the default limits allows eight
374
+ // storage buffers in the fragment stage, and the slope and foam grids below already use seven.
375
+ const tableBuffer = uniformArray(Array.from(table), "float");
376
+
377
+ const material = new MeshStandardNodeMaterial({ metalness: 0, roughness: 0.2 });
378
+
379
+ // The rest position of this fragment, straight from the disc's own attribute. `positionLocal` is
380
+ // overwritten by `positionNode`, so reading it in the fragment would hand back the displaced one.
381
+ const rest = vec2(
382
+ positionGeometry.x.add(seaOrigin.x),
383
+ positionGeometry.z.add(seaOrigin.y),
384
+ ).toVarying();
385
+ const restX = rest.x;
386
+ const restZ = rest.y;
387
+
388
+ // Geometry: the cascades the mesh can resolve. The finest is a few centimetres tall and only
389
+ // matters beside the hull, so it fades out with distance rather than aliasing across the disc.
390
+ const eye = cameraPosition.sub(positionWorld);
391
+ const distance = eye.length();
392
+ const rangeToRest = cameraPosition.sub(vec3(restX, 0, restZ)).length();
393
+ const displacementAt = (c: number, weight: Node<"float">) =>
394
+ sampleBilinear(ocean.cascadeDisplacement(c), size, patch(c), restX, restZ).xyz.mul(weight);
395
+ let offset = displacementAt(0, float(1));
396
+ for (let c = 1; c < cascadeCount; c += 1) {
397
+ const fade =
398
+ c === cascadeCount - 1 ? oneMinus(smoothstep(float(8), float(28), rangeToRest)) : float(1);
399
+ offset = offset.add(displacementAt(c, fade));
400
+ }
401
+ material.positionNode = positionLocal.add(offset);
402
+
403
+ // The pixel's size on the water as the square root of its area. At a grazing view a pixel is a
404
+ // long thin strip: its long side would fade every crest running across the view and spend it as
405
+ // roughness in all directions, which widens the glitter path sideways and blurs the far sea.
406
+ const footprint = positionWorld.dFdx().length().mul(positionWorld.dFdy().length()).sqrt();
407
+
408
+ // What a pixel can resolve: each cascade contributes its slope while the pixel is finer than the
409
+ // cascade's own texel, and is faded out above that. The fade is not a loss: the table below hands
410
+ // the same variance back as roughness.
411
+ const surface = Fn(() => {
412
+ const slope = vec2(0, 0).toVar();
413
+ const jxx = float(0).toVar();
414
+ const jzz = float(0).toVar();
415
+ const jxz = float(0).toVar();
416
+ for (let c = 0; c < cascadeCount; c += 1) {
417
+ const weight = oneMinus(smoothstep(float(texel(c) * 0.5), float(texel(c) * 2), footprint));
418
+ const read = sampleBilinear(maps.slope(c), size, patch(c), restX, restZ).mul(weight);
419
+ slope.addAssign(read.xy);
420
+ jxx.addAssign(read.z);
421
+ jzz.addAssign(read.w);
422
+ // The shear matters only where foam is drawn from the Jacobian; the finest cascade's is a
423
+ // few millimetres and its buffer would be the ninth storage binding.
424
+ if (FOAM.cascades.includes(c))
425
+ jxz.addAssign(sampleBilinear(maps.shear(c), size, patch(c), restX, restZ).x.mul(weight));
426
+ }
427
+ const jx = max(jxx.add(1), 0.15);
428
+ const jz = max(jzz.add(1), 0.15);
429
+ const jacobian = jxx.add(1).mul(jzz.add(1)).sub(jxz.mul(jxz));
430
+ return vec3(slope.x.div(jx), slope.y.div(jz), jacobian);
431
+ })().toVar();
432
+
433
+ const worldSlope = vec2(surface.x, surface.y);
434
+ const jacobian = surface.z;
435
+
436
+ if (!cheap) {
437
+ material.normalNode = transformNormalToView(
438
+ vec3(worldSlope.x.negate(), 1, worldSlope.y.negate()).normalize(),
439
+ );
440
+ }
441
+
442
+ // The unresolved slope, as roughness. `alpha = sqrt(mean-square slope)`, and three's roughness is
443
+ // `sqrt(alpha)`, so the fourth root of the table entry.
444
+ const tableIndex = footprint
445
+ .max(slopeTable.nearest)
446
+ .div(slopeTable.nearest)
447
+ .log()
448
+ .div(Math.log(slopeTable.farthest / slopeTable.nearest))
449
+ .clamp(0, 1)
450
+ .mul(LOOK.slopeTable.count - 1);
451
+ const lower = tableIndex.floor();
452
+ const entry = (index: Node<"uint">) => tableBuffer.element(index) as unknown as Node<"float">;
453
+ const unresolved = mix(
454
+ entry(lower.toUint()),
455
+ entry(
456
+ lower
457
+ .add(1)
458
+ .min(LOOK.slopeTable.count - 1)
459
+ .toUint(),
460
+ ),
461
+ tableIndex.sub(lower),
462
+ );
463
+
464
+ // Foam: persistent grids, near (fine) and far (coarse), thresholded by a tearing pattern so it is
465
+ // patches with water between them rather than a decal.
466
+ const nearFoam = sampleBilinearFloat(
467
+ maps.foam(0),
468
+ size,
469
+ patch(FOAM.cascades[0] as number),
470
+ restX,
471
+ restZ,
472
+ );
473
+ const farFoam = sampleBilinearFloat(
474
+ maps.foam(1),
475
+ size,
476
+ patch(FOAM.cascades[1] as number),
477
+ restX,
478
+ restZ,
479
+ );
480
+ const foamBlend = smoothstep(float(60), float(220), distance);
481
+ const fresh = saturate(float(FOAM.freshThreshold).sub(jacobian).mul(FOAM.gain));
482
+ // Breaking water is on the crests: foam from the grids is gated to the part of the surface above
483
+ // the mean level, so it sits on tops of waves instead of lying in troughs as confetti.
484
+ const crestGate = smoothstep(
485
+ float((state.waveHeight ?? 1) * -0.05),
486
+ float((state.waveHeight ?? 1) * 0.12),
487
+ positionWorld.y,
488
+ );
489
+ // A crest breaking now is on a crest wherever the swell has carried it, so only the grids' older
490
+ // foam is gated.
491
+ const cover = max(
492
+ mix(nearFoam, farFoam, foamBlend).mul(crestGate),
493
+ fresh.mul(oneMinus(foamBlend)),
494
+ );
495
+ const pattern = Fn(() => {
496
+ const p = vec2(restX, restZ);
497
+ const a = mx_noise_float(vec3(p.mul(0.9), seaTime.mul(0.05)));
498
+ const b = mx_noise_float(vec3(p.mul(2.7), seaTime.mul(0.08)));
499
+ const c = mx_noise_float(vec3(p.mul(8.1), 0));
500
+ return a.mul(0.5).add(b.mul(0.3)).add(c.mul(0.2)).mul(0.5).add(0.5);
501
+ })();
502
+ const edge = pattern.fwidth().add(0.03);
503
+ const soft = float(0.05).add(oneMinus(saturate(cover)).mul(0.14));
504
+ const whitecap = smoothstep(
505
+ oneMinus(cover).sub(edge).sub(soft),
506
+ oneMinus(cover).add(edge).add(soft),
507
+ pattern,
508
+ )
509
+ .mul(smoothstep(float(0), float(0.5), cover))
510
+ .clamp(0, 1);
511
+
512
+ // The wake, computed rather than drawn: the surface knows its own world position, so it can be
513
+ // told where a hull is and work out whether it is standing in its wake. Everything is in the
514
+ // hull's frame, so the wedge is a comparison rather than a rotation.
515
+ const toShip = vec2(positionWorld.x.sub(shipOrigin.x), positionWorld.z.sub(shipOrigin.y));
516
+ const starboard = vec2(shipForward.y.negate(), shipForward.x);
517
+ const astern = dot(toShip, shipForward).negate();
518
+ const across = abs(dot(toShip, starboard));
519
+ const halfWidth = astern.mul(WAKE.spread).add(WAKE.waist);
520
+ const churn = smoothstep(halfWidth.mul(0.62), halfWidth.mul(0.12), across).mul(0.6);
521
+ const arms = smoothstep(halfWidth.mul(0.5), float(0), abs(across.sub(halfWidth)));
522
+ const reach = smoothstep(float(WAKE.length), float(0), astern);
523
+ const begins = smoothstep(float(-1.4), float(1.6), astern);
524
+ const tear = smoothstep(float(0.35), float(0.7), pattern);
525
+ const wake = max(churn, arms).mul(reach).mul(begins).mul(wakeStrength).mul(tear).mul(0.78);
526
+ const plan = vec2(astern.div(HULL_WASH.halfLength), across.div(HULL_WASH.halfBeam));
527
+ const wash = smoothstep(float(1.34), float(0.94), plan.length()).mul(
528
+ smoothstep(float(0.62), float(0.94), plan.length()),
529
+ );
530
+ const bow = smoothstep(float(-1.4), float(-2.5), astern)
531
+ .mul(smoothstep(float(-5), float(-3.5), astern))
532
+ .mul(smoothstep(float(1.3), float(0.2), across))
533
+ .mul(wakeStrength)
534
+ .mul(tear);
535
+ const broken = max(max(wake, bow), wash.mul(tear).mul(wakeStrength));
536
+ const foamMask = max(whitecap, broken);
537
+
538
+ // Colour by height, deep in the troughs and lit on the shoulders. These bands are metres of wave
539
+ // height, so they move with `waveHeight`.
540
+ const height = positionWorld.y;
541
+ const reference = float(state.waveHeight ?? 1);
542
+ const shade = smoothstep(reference.mul(-0.45), reference.mul(0.4), height);
543
+ const water = mix(color(LOOK.deep), color(LOOK.shallow), shade);
544
+ const toEye = eye.normalize();
545
+ const fresnelOf = (normal: Node<"vec3">) =>
546
+ pow(oneMinus(saturate(dot(normal, toEye))), float(5))
547
+ .mul(0.97963)
548
+ .add(0.02037);
549
+ // Light that enters the water is light the surface did not reflect: the body is lit by what
550
+ // Fresnel leaves, so at a grazing view the sea is its reflection, not its colour. Taken from a
551
+ // partly smoothed normal, because the ripples finer than a pixel still face the eye.
552
+ const transmitted = oneMinus(fresnelOf(mix(normalWorld, vec3(0, 1, 0), 0.45).normalize()));
553
+ material.colorNode = cheap
554
+ ? water
555
+ : mix(water.mul(transmitted), color(LOOK.foam), foamMask.mul(0.95));
556
+
557
+ if (!cheap) {
558
+ // Light coming through a thin backlit crest: it needs a face turned away from the sun, a
559
+ // height near the surface and the eye looking nearly into the sun, and it fades with distance.
560
+ const crest = saturate(height.sub(reference.mul(0.05)).div(reference.mul(0.8)));
561
+ const toSun = pow(max(dot(sunDirection, toEye.negate()), 0), float(4));
562
+ const thin = pow(saturate(dot(sunDirection, normalWorld).mul(-0.5).add(0.5)), float(3));
563
+ const glow = crest
564
+ .mul(crest)
565
+ .mul(toSun)
566
+ .mul(thin)
567
+ .mul(distance.div(-600).exp())
568
+ .mul(LOOK.subsurfaceGain);
569
+ const tint = new Color(LOOK.subsurface);
570
+ const subsurface = vec3(tint.r, tint.g, tint.b)
571
+ .mul(sunRadiance)
572
+ .mul(glow)
573
+ .mul(oneMinus(foamMask));
574
+
575
+ // The hull, the marks and the headland, in the water, sharp: the one thing a prefiltered
576
+ // environment cannot do. Fresnel decides how much, as it does for the sky.
577
+ const fresnel = fresnelOf(normalWorld);
578
+ material.emissiveNode =
579
+ mirror === undefined
580
+ ? subsurface
581
+ : subsurface.add(
582
+ mirror
583
+ .reflectionAt(normalWorld.xz.mul(0.02))
584
+ .mul(LOOK.mirrorGain)
585
+ .mul(fresnel)
586
+ .mul(oneMinus(foamMask.mul(0.75))),
587
+ );
588
+ }
589
+
590
+ // Roughness is spent, not lost: the unresolved slope reappears here, and broken water is not a
591
+ // mirror either.
592
+ if (!cheap) {
593
+ const { near, far, from, to } = LOOK.capillarySlope;
594
+ const capillary = smoothstep(float(from), float(to), distance).mul(far).add(near);
595
+ const filtered = unresolved.max(0).add(capillary).sqrt().sqrt();
596
+ material.roughnessNode = max(filtered, foamMask.mul(0.9));
597
+ }
598
+
599
+ // The sun's glint, the sky's mirror image and the foam's light are the sea's own; see the model.
600
+ material.setupLightingModel = () => new SeaLightingModel(foamMask);
601
+
602
+ const mesh = new Mesh(geometry, material);
603
+ mesh.receiveShadow = true;
604
+ mesh.frustumCulled = false;
605
+ mesh.name = "realistic-sea-surface";
606
+
607
+ return {
608
+ mesh,
609
+ advance(elapsed: number): void {
610
+ seaTime.value = elapsed;
611
+ maps.advance(elapsed);
612
+ },
613
+ wake(x: number, z: number, forwardX: number, forwardZ: number, strength: number): void {
614
+ shipOrigin.value.set(x, z);
615
+ shipForward.value.set(forwardX, forwardZ);
616
+ wakeStrength.value = Math.max(0, Math.min(1, strength));
617
+ },
618
+ // Snapped to whole metres: following continuously would slide every vertex through the wave
619
+ // field by a fraction of its size each frame and the surface would crawl.
620
+ follow(x: number, z: number): void {
621
+ const snappedX = Math.round(x);
622
+ const snappedZ = Math.round(z);
623
+ mesh.position.set(snappedX, 0, snappedZ);
624
+ seaOrigin.value.set(snappedX, snappedZ);
625
+ },
626
+ setSun(direction, radiance): void {
627
+ const length = Math.hypot(direction[0], direction[1], direction[2]);
628
+ if (!(length > 0) || !Number.isFinite(length))
629
+ throw new Error("Realistic ocean sun direction must be a finite, non-zero vector.");
630
+ sunDirection.value.set(direction[0] / length, direction[1] / length, direction[2] / length);
631
+ if (radiance !== undefined) sunRadiance.value.set(...radiance);
632
+ },
633
+ reset(): void {
634
+ maps.reset();
635
+ },
636
+ dispose(): void {
637
+ mirror?.dispose();
638
+ geometry.dispose();
639
+ material.dispose();
640
+ },
641
+ };
642
+ }