create-threenative 0.2.8 → 0.2.10

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 (431) hide show
  1. package/agent-docs/references/assertion-reference.md +87 -35
  2. package/agent-docs/references/auto-exposure.md +57 -0
  3. package/agent-docs/references/capability-reference.md +1097 -23
  4. package/agent-docs/references/debug-surface.md +6 -0
  5. package/agent-docs/references/finding-assets.md +46 -10
  6. package/agent-docs/references/performance-basics.md +5 -4
  7. package/agent-docs/references/terrain-authoring.md +140 -0
  8. package/agent-files/.agents/skills/threenative-assets/SKILL.md +2 -1
  9. package/capabilities.json +1210 -27
  10. package/dist/index.d.ts +28 -3
  11. package/dist/index.js +396 -166
  12. package/dist/threenative.js +986 -235
  13. package/dist/web-engine-buffer-geometry-utils.js +281 -0
  14. package/dist/web-engine-decal-geometry.js +184 -0
  15. package/dist/web-engine-gltf-loader.js +196 -0
  16. package/dist/web-engine-hdr-loader.js +190 -0
  17. package/dist/web-engine-lut-cube-loader.js +122 -0
  18. package/dist/web-engine-mesh-bvh-webgpu.js +29 -0
  19. package/dist/web-engine-mesh-bvh.js +32 -0
  20. package/dist/web-engine-post-effects.js +168 -0
  21. package/dist/web-engine-runtime.js +42506 -0
  22. package/package.json +11 -8
  23. package/template-assets/autoExposure.ts +225 -0
  24. package/template-assets/exposure.ts +111 -0
  25. package/template-assets/exposureGraph.ts +178 -0
  26. package/template-assets/exposureReadback.ts +79 -0
  27. package/template-assets/patches/@tailwindcss__node@4.3.3.patch +22 -0
  28. package/template-assets/patches/three@0.185.1.patch +6594 -700
  29. package/template-assets/patches/vite@8.2.0.patch +422 -0
  30. package/template-assets/worldEnvironment.ts +433 -30
  31. package/templates/action-rpg/AGENTS.md +11 -10
  32. package/templates/action-rpg/CLAUDE.md +11 -10
  33. package/templates/action-rpg/package.json +13 -10
  34. package/templates/action-rpg/playtests/performance.playtest.json +7 -1
  35. package/templates/action-rpg/src/progress.ts +0 -4
  36. package/templates/action-rpg/src/render/autoExposure.ts +225 -0
  37. package/templates/action-rpg/src/render/backlightControls.ts +66 -0
  38. package/templates/action-rpg/src/render/backlightMaterial.ts +147 -0
  39. package/templates/action-rpg/src/render/environmentContribution.ts +188 -0
  40. package/templates/action-rpg/src/render/environmentRadiance.ts +36 -0
  41. package/templates/action-rpg/src/render/environmentSampleCache.ts +43 -0
  42. package/templates/action-rpg/src/render/environmentSampling.ts +193 -0
  43. package/templates/action-rpg/src/render/environmentSnapshot.ts +53 -0
  44. package/templates/action-rpg/src/render/exposure.ts +111 -0
  45. package/templates/action-rpg/src/render/exposureGraph.ts +178 -0
  46. package/templates/action-rpg/src/render/exposureReadback.ts +79 -0
  47. package/templates/action-rpg/src/render/heightFog.ts +118 -0
  48. package/templates/action-rpg/src/render/lighting.ts +26 -1
  49. package/templates/action-rpg/src/render/materialAssignments.ts +160 -0
  50. package/templates/action-rpg/src/render/materialLighting.ts +155 -0
  51. package/templates/action-rpg/src/render/postprocessing.ts +17 -2
  52. package/templates/action-rpg/src/render/quality.ts +61 -2
  53. package/templates/action-rpg/src/render/sky.ts +21 -1
  54. package/templates/action-rpg/src/render/vfx.ts +133 -58
  55. package/templates/action-rpg/src/render/worldEnvironment.ts +433 -30
  56. package/templates/action-rpg/src/scenes/Play.ts +81 -16
  57. package/templates/action-rpg/threenative.config.ts +3 -0
  58. package/templates/action-rpg/vite.config.ts +10 -2
  59. package/templates/minimal/AGENTS.md +9 -10
  60. package/templates/minimal/CLAUDE.md +9 -10
  61. package/templates/minimal/package.json +11 -9
  62. package/templates/minimal/playtests/play.playtest.json +7 -1
  63. package/templates/minimal/playtests/sky.playtest.json +10 -1
  64. package/templates/minimal/src/render/autoExposure.ts +225 -0
  65. package/templates/minimal/src/render/backlightControls.ts +66 -0
  66. package/templates/minimal/src/render/backlightMaterial.ts +147 -0
  67. package/templates/minimal/src/render/environmentContribution.ts +188 -0
  68. package/templates/minimal/src/render/environmentRadiance.ts +36 -0
  69. package/templates/minimal/src/render/environmentSampleCache.ts +43 -0
  70. package/templates/minimal/src/render/environmentSampling.ts +193 -0
  71. package/templates/minimal/src/render/environmentSnapshot.ts +53 -0
  72. package/templates/minimal/src/render/exposure.ts +111 -0
  73. package/templates/minimal/src/render/exposureGraph.ts +178 -0
  74. package/templates/minimal/src/render/exposureReadback.ts +79 -0
  75. package/templates/minimal/src/render/heightFog.ts +118 -0
  76. package/templates/minimal/src/render/lighting.ts +25 -1
  77. package/templates/minimal/src/render/materialAssignments.ts +102 -0
  78. package/templates/minimal/src/render/materialLighting.ts +146 -0
  79. package/templates/minimal/src/render/postprocessing.ts +16 -2
  80. package/templates/minimal/src/render/quality.ts +60 -2
  81. package/templates/minimal/src/render/sky.ts +21 -1
  82. package/templates/minimal/src/render/worldEnvironment.ts +433 -30
  83. package/templates/minimal/src/scenes/Play.ts +50 -1
  84. package/templates/minimal/vite.config.ts +10 -2
  85. package/templates/platformer/AGENTS.md +7 -5
  86. package/templates/platformer/CLAUDE.md +7 -5
  87. package/templates/platformer/package.json +13 -10
  88. package/templates/platformer/playtests/performance.playtest.json +7 -1
  89. package/templates/platformer/src/render/autoExposure.ts +225 -0
  90. package/templates/platformer/src/render/backlightControls.ts +66 -0
  91. package/templates/platformer/src/render/backlightMaterial.ts +147 -0
  92. package/templates/platformer/src/render/environmentContribution.ts +188 -0
  93. package/templates/platformer/src/render/environmentRadiance.ts +36 -0
  94. package/templates/platformer/src/render/environmentSampleCache.ts +43 -0
  95. package/templates/platformer/src/render/environmentSampling.ts +193 -0
  96. package/templates/platformer/src/render/environmentSnapshot.ts +53 -0
  97. package/templates/platformer/src/render/exposure.ts +111 -0
  98. package/templates/platformer/src/render/exposureGraph.ts +178 -0
  99. package/templates/platformer/src/render/exposureReadback.ts +79 -0
  100. package/templates/platformer/src/render/heightFog.ts +118 -0
  101. package/templates/platformer/src/render/lighting.ts +26 -1
  102. package/templates/platformer/src/render/materialAssignments.ts +160 -0
  103. package/templates/platformer/src/render/materialLighting.ts +155 -0
  104. package/templates/platformer/src/render/materials.ts +7 -2
  105. package/templates/platformer/src/render/palette.ts +3 -3
  106. package/templates/platformer/src/render/postprocessing.ts +17 -2
  107. package/templates/platformer/src/render/quality.ts +61 -2
  108. package/templates/platformer/src/render/sky.ts +72 -23
  109. package/templates/platformer/src/render/skyEnvironment.ts +50 -0
  110. package/templates/platformer/src/render/worldEnvironment.ts +433 -30
  111. package/templates/platformer/src/scenes/Play.ts +70 -6
  112. package/templates/platformer/vite.config.ts +10 -2
  113. package/templates/puzzle/AGENTS.md +10 -9
  114. package/templates/puzzle/CLAUDE.md +10 -9
  115. package/templates/puzzle/package.json +13 -10
  116. package/templates/puzzle/playtests/boot-failure.playtest.json +2 -2
  117. package/templates/puzzle/playtests/lit.playtest.json +7 -1
  118. package/templates/puzzle/playtests/performance.playtest.json +7 -1
  119. package/templates/puzzle/src/render/autoExposure.ts +225 -0
  120. package/templates/puzzle/src/render/backlightControls.ts +66 -0
  121. package/templates/puzzle/src/render/backlightMaterial.ts +147 -0
  122. package/templates/puzzle/src/render/environmentContribution.ts +188 -0
  123. package/templates/puzzle/src/render/environmentRadiance.ts +36 -0
  124. package/templates/puzzle/src/render/environmentSampleCache.ts +43 -0
  125. package/templates/puzzle/src/render/environmentSampling.ts +193 -0
  126. package/templates/puzzle/src/render/environmentSnapshot.ts +53 -0
  127. package/templates/puzzle/src/render/exposure.ts +111 -0
  128. package/templates/puzzle/src/render/exposureGraph.ts +178 -0
  129. package/templates/puzzle/src/render/exposureReadback.ts +79 -0
  130. package/templates/puzzle/src/render/heightFog.ts +118 -0
  131. package/templates/puzzle/src/render/lighting.ts +33 -1
  132. package/templates/puzzle/src/render/materialAssignments.ts +160 -0
  133. package/templates/puzzle/src/render/materialLighting.ts +155 -0
  134. package/templates/puzzle/src/render/materials.ts +1 -1
  135. package/templates/puzzle/src/render/postprocessing.ts +8 -2
  136. package/templates/puzzle/src/render/quality.ts +62 -1
  137. package/templates/puzzle/src/render/sky.ts +20 -1
  138. package/templates/puzzle/src/render/worldEnvironment.ts +433 -30
  139. package/templates/puzzle/src/scenes/Play.ts +51 -2
  140. package/templates/puzzle/vite.config.ts +10 -2
  141. package/templates/racing/AGENTS.md +8 -7
  142. package/templates/racing/CLAUDE.md +8 -7
  143. package/templates/racing/package.json +13 -10
  144. package/templates/racing/playtests/performance.playtest.json +7 -1
  145. package/templates/racing/playtests/survives.playtest.json +6 -0
  146. package/templates/racing/src/render/autoExposure.ts +225 -0
  147. package/templates/racing/src/render/backlightControls.ts +66 -0
  148. package/templates/racing/src/render/backlightMaterial.ts +147 -0
  149. package/templates/racing/src/render/environmentContribution.ts +188 -0
  150. package/templates/racing/src/render/environmentRadiance.ts +36 -0
  151. package/templates/racing/src/render/environmentSampleCache.ts +43 -0
  152. package/templates/racing/src/render/environmentSampling.ts +193 -0
  153. package/templates/racing/src/render/environmentSnapshot.ts +53 -0
  154. package/templates/racing/src/render/exposure.ts +111 -0
  155. package/templates/racing/src/render/exposureGraph.ts +178 -0
  156. package/templates/racing/src/render/exposureReadback.ts +79 -0
  157. package/templates/racing/src/render/heightFog.ts +118 -0
  158. package/templates/racing/src/render/lighting.ts +29 -1
  159. package/templates/racing/src/render/materialAssignments.ts +160 -0
  160. package/templates/racing/src/render/materialLighting.ts +155 -0
  161. package/templates/racing/src/render/palette.ts +1 -10
  162. package/templates/racing/src/render/postprocessing.ts +17 -2
  163. package/templates/racing/src/render/quality.ts +61 -2
  164. package/templates/racing/src/render/shapes.ts +0 -25
  165. package/templates/racing/src/render/sky.ts +25 -5
  166. package/templates/racing/src/render/worldEnvironment.ts +433 -30
  167. package/templates/racing/src/scenes/Race.ts +110 -13
  168. package/templates/racing/src/track/circuit.ts +0 -9
  169. package/templates/racing/vite.config.ts +10 -2
  170. package/templates/rain/AGENTS.md +8 -9
  171. package/templates/rain/CLAUDE.md +8 -9
  172. package/templates/rain/native-playtests/boot.playtest.json +11 -1
  173. package/templates/rain/package.json +14 -10
  174. package/templates/rain/playtests/automation.playtest.json +1 -1
  175. package/templates/rain/playtests/performance.playtest.json +11 -1
  176. package/templates/rain/playtests/tiers.playtest.json +15 -0
  177. package/templates/rain/playtests/weather.playtest.json +1 -1
  178. package/templates/rain/src/game.ts +1 -34
  179. package/templates/rain/src/render/autoExposure.ts +225 -0
  180. package/templates/rain/src/render/exposure.ts +111 -0
  181. package/templates/rain/src/render/exposureGraph.ts +178 -0
  182. package/templates/rain/src/render/exposureReadback.ts +79 -0
  183. package/templates/rain/src/render/postprocessing.ts +3 -0
  184. package/templates/rain/src/render/quality.ts +27 -1
  185. package/templates/rain/src/render/worldEnvironment.ts +433 -30
  186. package/templates/rain/src/scenes/Boot.ts +14 -0
  187. package/templates/rain/src/state.ts +5 -1
  188. package/templates/rain/src/ui/GameUi.tsx +6 -6
  189. package/templates/rain/tools/generate-shaders.mjs +1 -1
  190. package/templates/rain/vite.config.ts +10 -2
  191. package/templates/rts/AGENTS.md +10 -11
  192. package/templates/rts/CLAUDE.md +10 -11
  193. package/templates/rts/package.json +12 -9
  194. package/templates/rts/playtests/performance.playtest.json +7 -1
  195. package/templates/rts/playtests/rts-ai-attack.playtest.json +10 -1
  196. package/templates/rts/playtests/rts-attack.playtest.json +10 -1
  197. package/templates/rts/playtests/rts-build.playtest.json +10 -1
  198. package/templates/rts/playtests/rts-orders.playtest.json +7 -1
  199. package/templates/rts/playtests/rts-train.playtest.json +10 -1
  200. package/templates/rts/src/render/army.ts +10 -2
  201. package/templates/rts/src/render/autoExposure.ts +225 -0
  202. package/templates/rts/src/render/backlightControls.ts +66 -0
  203. package/templates/rts/src/render/backlightMaterial.ts +147 -0
  204. package/templates/rts/src/render/environmentContribution.ts +188 -0
  205. package/templates/rts/src/render/environmentRadiance.ts +36 -0
  206. package/templates/rts/src/render/environmentSampleCache.ts +43 -0
  207. package/templates/rts/src/render/environmentSampling.ts +193 -0
  208. package/templates/rts/src/render/environmentSnapshot.ts +53 -0
  209. package/templates/rts/src/render/exposure.ts +111 -0
  210. package/templates/rts/src/render/exposureGraph.ts +178 -0
  211. package/templates/rts/src/render/exposureReadback.ts +79 -0
  212. package/templates/rts/src/render/heightFog.ts +118 -0
  213. package/templates/rts/src/render/lighting.ts +26 -1
  214. package/templates/rts/src/render/materialAssignments.ts +160 -0
  215. package/templates/rts/src/render/materialLighting.ts +155 -0
  216. package/templates/rts/src/render/postprocessing.ts +8 -2
  217. package/templates/rts/src/render/quality.ts +61 -2
  218. package/templates/rts/src/render/sky.ts +21 -1
  219. package/templates/rts/src/render/worldEnvironment.ts +433 -30
  220. package/templates/rts/src/scenes/Play.ts +54 -3
  221. package/templates/rts/src/sim/ai.ts +0 -1
  222. package/templates/rts/src/sim/terrain.ts +0 -4
  223. package/templates/rts/vite.config.ts +10 -2
  224. package/templates/runner/AGENTS.md +10 -8
  225. package/templates/runner/CLAUDE.md +10 -8
  226. package/templates/runner/package.json +13 -10
  227. package/templates/runner/playtests/performance.playtest.json +10 -1
  228. package/templates/runner/src/physics.ts +0 -1
  229. package/templates/runner/src/render/autoExposure.ts +225 -0
  230. package/templates/runner/src/render/backlightControls.ts +66 -0
  231. package/templates/runner/src/render/backlightMaterial.ts +147 -0
  232. package/templates/runner/src/render/environmentContribution.ts +188 -0
  233. package/templates/runner/src/render/environmentRadiance.ts +36 -0
  234. package/templates/runner/src/render/environmentSampleCache.ts +43 -0
  235. package/templates/runner/src/render/environmentSampling.ts +193 -0
  236. package/templates/runner/src/render/environmentSnapshot.ts +53 -0
  237. package/templates/runner/src/render/exposure.ts +111 -0
  238. package/templates/runner/src/render/exposureGraph.ts +178 -0
  239. package/templates/runner/src/render/exposureReadback.ts +79 -0
  240. package/templates/runner/src/render/heightFog.ts +118 -0
  241. package/templates/runner/src/render/lighting.ts +26 -1
  242. package/templates/runner/src/render/materialAssignments.ts +160 -0
  243. package/templates/runner/src/render/materialLighting.ts +155 -0
  244. package/templates/runner/src/render/postprocessing.ts +17 -2
  245. package/templates/runner/src/render/quality.ts +61 -2
  246. package/templates/runner/src/render/sky.ts +21 -1
  247. package/templates/runner/src/render/worldEnvironment.ts +433 -30
  248. package/templates/runner/src/scenes/Run.ts +67 -2
  249. package/templates/runner/threenative.config.ts +3 -0
  250. package/templates/runner/vite.config.ts +10 -2
  251. package/templates/sailing/AGENTS.md +14 -13
  252. package/templates/sailing/CLAUDE.md +14 -13
  253. package/templates/sailing/native-playtests/survives.playtest.json +7 -0
  254. package/templates/sailing/package.json +13 -10
  255. package/templates/sailing/playtests/live/render-motion.playtest.json +30 -0
  256. package/templates/sailing/src/entities/Ship.ts +38 -18
  257. package/templates/sailing/src/render/autoExposure.ts +225 -0
  258. package/templates/sailing/src/render/backlightControls.ts +66 -0
  259. package/templates/sailing/src/render/backlightMaterial.ts +147 -0
  260. package/templates/sailing/src/render/camera.ts +12 -4
  261. package/templates/sailing/src/render/environmentContribution.ts +188 -0
  262. package/templates/sailing/src/render/environmentRadiance.ts +36 -0
  263. package/templates/sailing/src/render/environmentSampleCache.ts +43 -0
  264. package/templates/sailing/src/render/environmentSampling.ts +193 -0
  265. package/templates/sailing/src/render/environmentSetup.ts +24 -0
  266. package/templates/sailing/src/render/environmentSnapshot.ts +53 -0
  267. package/templates/sailing/src/render/exposure.ts +111 -0
  268. package/templates/sailing/src/render/exposureGraph.ts +178 -0
  269. package/templates/sailing/src/render/exposureReadback.ts +79 -0
  270. package/templates/sailing/src/render/heightFog.ts +118 -0
  271. package/templates/sailing/src/render/lighting.ts +26 -1
  272. package/templates/sailing/src/render/materialAssignments.ts +160 -0
  273. package/templates/sailing/src/render/materialLighting.ts +155 -0
  274. package/templates/sailing/src/render/ocean.ts +71 -53
  275. package/templates/sailing/src/render/postprocessing.ts +16 -2
  276. package/templates/sailing/src/render/props.ts +0 -45
  277. package/templates/sailing/src/render/quality.ts +61 -1
  278. package/templates/sailing/src/render/sky.ts +21 -1
  279. package/templates/sailing/src/render/worldEnvironment.ts +433 -30
  280. package/templates/sailing/src/scenes/Boot.ts +12 -1
  281. package/templates/sailing/src/scenes/Sailing.ts +87 -2
  282. package/templates/sailing/src/scenes/ocean-readiness.ts +68 -0
  283. package/templates/sailing/threenative.config.ts +3 -0
  284. package/templates/sailing/vite.config.ts +10 -2
  285. package/templates/shooter/AGENTS.md +8 -6
  286. package/templates/shooter/CLAUDE.md +8 -6
  287. package/templates/shooter/package.json +13 -10
  288. package/templates/shooter/playtests/performance.playtest.json +7 -1
  289. package/templates/shooter/src/entities/Enemy.ts +0 -15
  290. package/templates/shooter/src/entities/Rifle.ts +38 -1
  291. package/templates/shooter/src/render/autoExposure.ts +225 -0
  292. package/templates/shooter/src/render/backlightControls.ts +66 -0
  293. package/templates/shooter/src/render/backlightMaterial.ts +147 -0
  294. package/templates/shooter/src/render/camera.ts +1 -12
  295. package/templates/shooter/src/render/decals.ts +299 -5
  296. package/templates/shooter/src/render/environmentContribution.ts +188 -0
  297. package/templates/shooter/src/render/environmentRadiance.ts +36 -0
  298. package/templates/shooter/src/render/environmentSampleCache.ts +43 -0
  299. package/templates/shooter/src/render/environmentSampling.ts +193 -0
  300. package/templates/shooter/src/render/environmentSnapshot.ts +53 -0
  301. package/templates/shooter/src/render/exposure.ts +111 -0
  302. package/templates/shooter/src/render/exposureGraph.ts +178 -0
  303. package/templates/shooter/src/render/exposureReadback.ts +79 -0
  304. package/templates/shooter/src/render/gunfx.ts +0 -1
  305. package/templates/shooter/src/render/heightFog.ts +118 -0
  306. package/templates/shooter/src/render/lighting.ts +26 -1
  307. package/templates/shooter/src/render/materialAssignments.ts +160 -0
  308. package/templates/shooter/src/render/materialLighting.ts +155 -0
  309. package/templates/shooter/src/render/postprocessing.ts +17 -2
  310. package/templates/shooter/src/render/quality.ts +61 -2
  311. package/templates/shooter/src/render/scale.ts +2 -93
  312. package/templates/shooter/src/render/sky.ts +21 -1
  313. package/templates/shooter/src/render/vehicles.ts +0 -17
  314. package/templates/shooter/src/render/worldEnvironment.ts +433 -30
  315. package/templates/shooter/src/scenes/Play.ts +64 -2
  316. package/templates/shooter/vite.config.ts +10 -2
  317. package/templates/snow/AGENTS.md +8 -6
  318. package/templates/snow/CLAUDE.md +8 -6
  319. package/templates/snow/package.json +13 -10
  320. package/templates/snow/src/render/autoExposure.ts +225 -0
  321. package/templates/snow/src/render/backlightControls.ts +66 -0
  322. package/templates/snow/src/render/backlightMaterial.ts +147 -0
  323. package/templates/snow/src/render/environmentContribution.ts +188 -0
  324. package/templates/snow/src/render/environmentRadiance.ts +36 -0
  325. package/templates/snow/src/render/environmentSampleCache.ts +43 -0
  326. package/templates/snow/src/render/environmentSampling.ts +193 -0
  327. package/templates/snow/src/render/environmentSnapshot.ts +53 -0
  328. package/templates/snow/src/render/exposure.ts +111 -0
  329. package/templates/snow/src/render/exposureGraph.ts +178 -0
  330. package/templates/snow/src/render/exposureReadback.ts +79 -0
  331. package/templates/snow/src/render/heightFog.ts +118 -0
  332. package/templates/snow/src/render/lighting.ts +33 -1
  333. package/templates/snow/src/render/materialAssignments.ts +160 -0
  334. package/templates/snow/src/render/materialLighting.ts +155 -0
  335. package/templates/snow/src/render/postprocessing.ts +16 -2
  336. package/templates/snow/src/render/quality.ts +59 -1
  337. package/templates/snow/src/render/sky.ts +21 -2
  338. package/templates/snow/src/render/worldEnvironment.ts +433 -30
  339. package/templates/snow/src/scenes/Snow.ts +29 -1
  340. package/templates/snow/threenative.config.ts +3 -0
  341. package/templates/snow/vite.config.ts +10 -2
  342. package/templates/starter/AGENTS.md +11 -16
  343. package/templates/starter/CLAUDE.md +11 -16
  344. package/templates/starter/native-playtests/react-hud.playtest.json +1 -1
  345. package/templates/starter/native-playtests/render-chain.playtest.json +51 -8
  346. package/templates/starter/native-playtests/smooth-motion.playtest.json +64 -0
  347. package/templates/starter/package.json +13 -10
  348. package/templates/starter/playtests/live/smooth-motion.playtest.json +63 -0
  349. package/templates/starter/playtests/movement.playtest.json +192 -0
  350. package/templates/starter/playtests/play.playtest.json +18 -2
  351. package/templates/starter/playtests/production-readiness.playtest.json +43 -1
  352. package/templates/starter/public/grade.cube +735 -0
  353. package/templates/starter/src/entities/Crate.ts +4 -0
  354. package/templates/starter/src/entities/Player.ts +79 -18
  355. package/templates/starter/src/game.ts +1 -0
  356. package/templates/starter/src/render/adaptiveQuality.ts +28 -41
  357. package/templates/starter/src/render/autoExposure.ts +225 -0
  358. package/templates/starter/src/render/backlightControls.ts +66 -0
  359. package/templates/starter/src/render/backlightMaterial.ts +147 -0
  360. package/templates/starter/src/render/environmentContribution.ts +188 -0
  361. package/templates/starter/src/render/environmentRadiance.ts +36 -0
  362. package/templates/starter/src/render/environmentSampleCache.ts +43 -0
  363. package/templates/starter/src/render/environmentSampling.ts +193 -0
  364. package/templates/starter/src/render/environmentSnapshot.ts +53 -0
  365. package/templates/starter/src/render/exposure.ts +111 -0
  366. package/templates/starter/src/render/exposureGraph.ts +178 -0
  367. package/templates/starter/src/render/exposureReadback.ts +79 -0
  368. package/templates/starter/src/render/grade.ts +157 -0
  369. package/templates/starter/src/render/heightFog.ts +118 -0
  370. package/templates/starter/src/render/lighting.ts +26 -1
  371. package/templates/starter/src/render/materialAssignments.ts +160 -0
  372. package/templates/starter/src/render/materialLighting.ts +155 -0
  373. package/templates/starter/src/render/postprocessing.ts +90 -4
  374. package/templates/starter/src/render/quality.ts +80 -8
  375. package/templates/starter/src/render/qualityPolicy.ts +54 -0
  376. package/templates/starter/src/render/rendererGate.ts +36 -0
  377. package/templates/starter/src/render/sky.ts +23 -1
  378. package/templates/starter/src/render/temporalAA.ts +197 -0
  379. package/templates/starter/src/render/temporalAAFrame.ts +179 -0
  380. package/templates/starter/src/render/temporalAAHooks.ts +101 -0
  381. package/templates/starter/src/render/temporalAAInput.ts +56 -0
  382. package/templates/starter/src/render/temporalAAResolve.ts +65 -0
  383. package/templates/starter/src/render/temporalAAStage.ts +76 -0
  384. package/templates/starter/src/render/temporalCurrentArea.ts +31 -0
  385. package/templates/starter/src/render/temporalCurrentFootprint.ts +198 -0
  386. package/templates/starter/src/render/temporalCurrentFootprintMath.ts +41 -0
  387. package/templates/starter/src/render/temporalCurrentProducer.ts +161 -0
  388. package/templates/starter/src/render/temporalCurrentReplay.ts +160 -0
  389. package/templates/starter/src/render/temporalCurrentSelection.ts +89 -0
  390. package/templates/starter/src/render/temporalCurrentVisibility.ts +170 -0
  391. package/templates/starter/src/render/temporalDepthSamples.ts +34 -0
  392. package/templates/starter/src/render/temporalRejectionCounter.ts +179 -0
  393. package/templates/starter/src/render/temporalResolve.ts +139 -0
  394. package/templates/starter/src/render/temporalResolveDepth.ts +193 -0
  395. package/templates/starter/src/render/temporalResolveMath.ts +196 -0
  396. package/templates/starter/src/render/volumetricFog.ts +124 -0
  397. package/templates/starter/src/render/volumetricFogOptions.ts +96 -0
  398. package/templates/starter/src/render/volumetricFogTransport.ts +176 -0
  399. package/templates/starter/src/render/volumetricFogVolume.ts +139 -0
  400. package/templates/starter/src/render/worldEnvironment.ts +433 -30
  401. package/templates/starter/src/scenes/Play.ts +110 -1
  402. package/templates/starter/src/state.ts +1 -0
  403. package/templates/starter/src/ui/Hud.tsx +1 -1
  404. package/templates/starter/src/ui/Menu.tsx +1 -1
  405. package/templates/starter/tools/make-grade-lut.mjs +101 -0
  406. package/templates/starter/vite.config.ts +10 -2
  407. package/templates/tower-defense/AGENTS.md +10 -9
  408. package/templates/tower-defense/CLAUDE.md +10 -9
  409. package/templates/tower-defense/package.json +13 -10
  410. package/templates/tower-defense/playtests/performance.playtest.json +7 -1
  411. package/templates/tower-defense/src/render/autoExposure.ts +225 -0
  412. package/templates/tower-defense/src/render/backlightControls.ts +66 -0
  413. package/templates/tower-defense/src/render/backlightMaterial.ts +147 -0
  414. package/templates/tower-defense/src/render/environmentContribution.ts +188 -0
  415. package/templates/tower-defense/src/render/environmentRadiance.ts +36 -0
  416. package/templates/tower-defense/src/render/environmentSampleCache.ts +43 -0
  417. package/templates/tower-defense/src/render/environmentSampling.ts +193 -0
  418. package/templates/tower-defense/src/render/environmentSnapshot.ts +53 -0
  419. package/templates/tower-defense/src/render/exposure.ts +111 -0
  420. package/templates/tower-defense/src/render/exposureGraph.ts +178 -0
  421. package/templates/tower-defense/src/render/exposureReadback.ts +79 -0
  422. package/templates/tower-defense/src/render/lighting.ts +33 -1
  423. package/templates/tower-defense/src/render/materialAssignments.ts +160 -0
  424. package/templates/tower-defense/src/render/materialLighting.ts +155 -0
  425. package/templates/tower-defense/src/render/postprocessing.ts +8 -2
  426. package/templates/tower-defense/src/render/quality.ts +61 -2
  427. package/templates/tower-defense/src/render/shapes.ts +0 -3
  428. package/templates/tower-defense/src/render/worldEnvironment.ts +433 -30
  429. package/templates/tower-defense/src/scenes/Battle.ts +65 -2
  430. package/templates/tower-defense/vite.config.ts +10 -2
  431. package/templates/minimal/src/scenes/Boot.ts +0 -5
@@ -0,0 +1,155 @@
1
+ // Generated for you. Scene-owned material assignments; no engine appearance hooks.
2
+ import {
3
+ type Camera,
4
+ type DirectionalLight,
5
+ Material,
6
+ Mesh,
7
+ MeshStandardMaterial,
8
+ type Object3D,
9
+ type Scene,
10
+ type Texture,
11
+ } from "three";
12
+ import { type IBacklightControls, backlightMaterial } from "./backlightMaterial.js";
13
+ import {
14
+ type IEnvironmentMeasurement,
15
+ measureEnvironment,
16
+ reportEnvironmentContribution,
17
+ } from "./environmentContribution.js";
18
+ import {
19
+ type IEnvironmentSourceSnapshot,
20
+ captureEnvironmentSnapshot,
21
+ environmentSnapshotCurrent,
22
+ } from "./environmentSnapshot.js";
23
+ import { type ILightingConvention, createLightingConvention } from "./lighting.js";
24
+ import { createMaterialAssignments } from "./materialAssignments.js";
25
+ import { type IMaterialLightingEnvironment, materialLightingEnabled } from "./quality.js";
26
+ interface IMaterialLightingOptions extends IMaterialLightingEnvironment {
27
+ readonly enabled: boolean;
28
+ readonly overrides?: Partial<ILightingConvention>;
29
+ }
30
+ /** Call once AFTER the scene's loaded character, arena and props are attached. */
31
+ export function createMaterialLighting(
32
+ scene: Scene,
33
+ camera: Camera,
34
+ key: DirectionalLight,
35
+ options: IMaterialLightingOptions,
36
+ ) {
37
+ const settings = createLightingConvention(options.overrides);
38
+ let enabled = false;
39
+ let disposed = false;
40
+ let fillApproved = false;
41
+ let measured = measureEnvironment(scene, settings.maxSourceTexels);
42
+ let measurementSnapshot = captureEnvironmentSnapshot(scene);
43
+ const controls: IBacklightControls = {
44
+ key,
45
+ scene,
46
+ camera,
47
+ get rimGain() {
48
+ return settings.rimGain;
49
+ },
50
+ set rimGain(value) {
51
+ settings.rimGain = value;
52
+ },
53
+ get fillGain() {
54
+ return settings.fillGain;
55
+ },
56
+ set fillGain(value) {
57
+ settings.fillGain = value;
58
+ },
59
+ fillColor: settings.fillColor,
60
+ fillDirection: settings.fillDirection,
61
+ get fillAngularSize() {
62
+ return settings.fillAngularSize;
63
+ },
64
+ set fillAngularSize(value) {
65
+ settings.fillAngularSize = value;
66
+ },
67
+ get fillAdmitted() {
68
+ return enabled && fillApproved && environmentSnapshotCurrent(scene, measurementSnapshot);
69
+ },
70
+ };
71
+ const assignments = createMaterialAssignments(scene, controls);
72
+ function report() {
73
+ if (!environmentSnapshotCurrent(scene, measurementSnapshot)) {
74
+ measured = measureEnvironment(scene, settings.maxSourceTexels);
75
+ measurementSnapshot = captureEnvironmentSnapshot(scene);
76
+ }
77
+ fillApproved =
78
+ measured.status === "measured" &&
79
+ measured.meanRadiance !== null &&
80
+ measured.meanRadiance <= settings.darkThreshold;
81
+ return reportEnvironmentContribution(
82
+ scene,
83
+ {
84
+ ...settings,
85
+ rimGain: controls.rimGain,
86
+ fillGain: controls.fillGain,
87
+ fillColor: controls.fillColor,
88
+ fillAdmitted: controls.fillAdmitted,
89
+ },
90
+ measured,
91
+ );
92
+ }
93
+ let observation: ReturnType<typeof report>;
94
+ function setEnabled(requested: boolean): void {
95
+ if (disposed) return;
96
+ enabled = requested && materialLightingEnabled("high", options);
97
+ assignments.setEnabled(enabled);
98
+ observation = report();
99
+ }
100
+ setEnabled(options.enabled);
101
+ return {
102
+ controls,
103
+ setEnabled,
104
+ /** Enroll a newly attached game-owned subtree. */
105
+ enroll(root: Object3D): void {
106
+ if (!disposed) assignments.enroll(root);
107
+ },
108
+ /** Restore assignments before removing a subtree or disposing borrowed materials. */
109
+ release(root: Object3D): void {
110
+ if (!disposed) assignments.release(root);
111
+ },
112
+ report() {
113
+ observation = report();
114
+ return observation;
115
+ },
116
+ /** Root's later GPU sampler can provide a measured snapshot of the current environment. */
117
+ setEnvironmentMeasurement(
118
+ measurement: IEnvironmentMeasurement,
119
+ source: Texture | null = scene.environment,
120
+ intensity = scene.environmentIntensity,
121
+ snapshot: IEnvironmentSourceSnapshot = captureEnvironmentSnapshot(scene),
122
+ ): void {
123
+ if (disposed) return;
124
+ if (
125
+ measurement.status === "measured" &&
126
+ (measurement.meanRadiance === null ||
127
+ !Number.isFinite(measurement.meanRadiance) ||
128
+ measurement.meanRadiance < 0 ||
129
+ measurement.meanRGB === null ||
130
+ !measurement.meanRGB.every((value) => Number.isFinite(value) && value >= 0))
131
+ )
132
+ throw new Error("Measured environment radiance must be finite and nonnegative.");
133
+ if (
134
+ source !== snapshot.source ||
135
+ intensity !== snapshot.intensity ||
136
+ !environmentSnapshotCurrent(scene, snapshot)
137
+ )
138
+ return;
139
+ measured = measurement;
140
+ measurementSnapshot = snapshot;
141
+ observation = report();
142
+ },
143
+ debug: () => ({
144
+ ...observation,
145
+ enabled,
146
+ ...assignments.debug(),
147
+ }),
148
+ dispose(): void {
149
+ if (disposed) return;
150
+ enabled = false;
151
+ disposed = true;
152
+ assignments.dispose();
153
+ },
154
+ };
155
+ }
@@ -53,14 +53,19 @@ export function toon(
53
53
  );
54
54
  }
55
55
 
56
- /** Unlit, for things that must stay bright whatever the sun is doing. */
56
+ /** Unlit, for things that stay bright whatever the sun does; opacity below 1 enables transparency. */
57
57
  export function flat(
58
58
  color: ColorRepresentation,
59
59
  options: { depthWrite?: boolean; fog?: boolean; opacity?: number; side?: typeof DoubleSide } = {},
60
60
  ): MeshBasicMaterial {
61
61
  return cached(
62
62
  `flat|${String(color)}|${JSON.stringify(options)}`,
63
- () => new MeshBasicMaterial({ color, ...options }),
63
+ () =>
64
+ new MeshBasicMaterial({
65
+ color,
66
+ ...options,
67
+ transparent: options.opacity !== undefined && options.opacity < 1,
68
+ }),
64
69
  );
65
70
  }
66
71
 
@@ -13,11 +13,11 @@
13
13
  export const palette = {
14
14
  grass: 0x5cbb37,
15
15
  /** Distance fades into this; also the loading screen's background. */
16
- horizon: 0xa8d6f5,
16
+ horizon: 0xa9dcf7,
17
17
  rock: 0xa8927a,
18
18
  /** The loading screen's progress track. */
19
- skyHigh: 0x2e88e0,
20
- skyLow: 0xbfe4fb,
19
+ skyHigh: 0x0a63c8,
20
+ skyLow: 0x2b93e8,
21
21
  /** The one saturated role: coins, gems, stars, the goal. */
22
22
  accent: 0xffd23f,
23
23
  } as const;
@@ -28,10 +28,14 @@ export function setupPost(
28
28
  mobile?: boolean;
29
29
  /** The renderer named a software adapter; this game's answer is its `low` tier. */
30
30
  software?: boolean;
31
+ /** The renderer's GPU family (`ctx.renderer.gpuClass?.class`); `quality.ts` maps it to a start tier. */
32
+ gpuClass?: string;
31
33
  /** Forces a tier, ignoring `mobile`. An unknown name throws rather than falling back. */
32
34
  tier?: QualityTier;
35
+ /** Scene-owned material assignments follow the resolved tier. */
36
+ onTierChanged?: (tier: QualityTier) => void;
33
37
  } = {},
34
- ): void {
38
+ ): { readonly tier: QualityTier; dispose(): void } {
35
39
  // The native production collector explicitly marks a software-only hosted smoke run. This is
36
40
  // a profile input, not a host fact: the normal desktop game remains high, while this run uses
37
41
  // the existing low look so screenshot and lifecycle evidence can settle on a CPU adapter.
@@ -41,6 +45,7 @@ export function setupPost(
41
45
  environment.tier ?? (hostedSoftware ? "low" : undefined);
42
46
  const tier = resolveQualityTier({
43
47
  mobile: environment.mobile,
48
+ gpuClass: environment.gpuClass,
44
49
  software: environment.software,
45
50
  tier: requestedTier,
46
51
  });
@@ -52,5 +57,15 @@ export function setupPost(
52
57
  } source=${source}`,
53
58
  );
54
59
  const world = new WorldEnvironment(qualityPreset(tier));
55
- world.apply(renderer, scene, camera, { godraysLight: environment.godraysLight });
60
+ const applied = world.apply(renderer, scene, camera, { godraysLight: environment.godraysLight });
61
+ environment.onTierChanged?.(tier);
62
+ let disposed = false;
63
+ return {
64
+ tier,
65
+ dispose(): void {
66
+ if (disposed) return;
67
+ disposed = true;
68
+ applied.dispose?.();
69
+ },
70
+ };
56
71
  }
@@ -34,6 +34,23 @@ function isQualityTier(value: string): value is QualityTier {
34
34
  return (QUALITY_TIERS as readonly string[]).includes(value);
35
35
  }
36
36
 
37
+ /**
38
+ * Where each GPU family starts, from `ctx.renderer.gpuClass`.
39
+ *
40
+ * A start, not a ceiling: the measured frame-budget windows move the look from here, and an
41
+ * explicit `tier` above still wins. A class absent from this table — `unknown`, an adapter no
42
+ * family rule matched — falls back to the `mobile` flag, exactly as before families existed.
43
+ * Edit the right-hand side to change what a family looks like; nothing outside this file reads it.
44
+ */
45
+ const START_TIER_BY_GPU_CLASS: Readonly<Record<string, QualityTier | undefined>> = {
46
+ software: "low",
47
+ "mobile-low": "low",
48
+ "mobile-mid": "low",
49
+ "mobile-high": "medium",
50
+ integrated: "medium",
51
+ discrete: "high",
52
+ };
53
+
37
54
  /**
38
55
  * Picks the tier: an explicit `tier` always wins, otherwise the platform decides.
39
56
  *
@@ -42,7 +59,12 @@ function isQualityTier(value: string): value is QualityTier {
42
59
  * turned out to have no effect.
43
60
  */
44
61
  export function resolveQualityTier(
45
- request: { readonly mobile?: boolean; readonly software?: boolean; readonly tier?: string } = {},
62
+ request: {
63
+ readonly gpuClass?: string;
64
+ readonly mobile?: boolean;
65
+ readonly software?: boolean;
66
+ readonly tier?: string;
67
+ } = {},
46
68
  ): QualityTier {
47
69
  const requested = request.tier;
48
70
  if (requested !== undefined) {
@@ -59,6 +81,9 @@ export function resolveQualityTier(
59
81
  // fact the renderer read from `adapter.info`, not a guess from a driver string, and an explicit
60
82
  // `tier` above still wins over it.
61
83
  if (request.software === true) return "low";
84
+ const family =
85
+ request.gpuClass === undefined ? undefined : START_TIER_BY_GPU_CLASS[request.gpuClass];
86
+ if (family !== undefined) return family;
62
87
  return request.mobile === true ? "low" : "high";
63
88
  }
64
89
 
@@ -76,6 +101,7 @@ const shared: IWorldEnvironmentOptions = {
76
101
  bloomThreshold: 1,
77
102
  // The sky photograph arrives at 2.5x, so the curve and the exposure below are what bring it
78
103
  // back to a daylight frame instead of a white one.
104
+ autoExposureEnabled: false,
79
105
  exposure: 0.6,
80
106
  tonemapMode: "aces",
81
107
  vignetteAmount: 0.2,
@@ -95,7 +121,7 @@ const high: IWorldEnvironmentOptions = {
95
121
  };
96
122
 
97
123
  /** The rung in between: the same occlusion at half the directions. Saving unmeasured. */
98
- const medium: IWorldEnvironmentOptions = { ...high, gtaoSamples: 8 };
124
+ const medium: IWorldEnvironmentOptions = { ...high, gtaoSamples: 8, renderChainTier: "medium" };
99
125
 
100
126
  /**
101
127
  * What a phone gets: the curve, the narrow bloom and the vignette, nothing screen-space. On a
@@ -116,3 +142,36 @@ export function qualityPreset(tier: string): IWorldEnvironmentOptions {
116
142
  }
117
143
  return preset;
118
144
  }
145
+
146
+ /** First admitted material lane: high desktop hardware WebGPU in the browser only. */
147
+ export interface IMaterialLightingEnvironment {
148
+ readonly web: boolean;
149
+ readonly rendererKind: string;
150
+ readonly mobile?: boolean;
151
+ readonly software?: boolean;
152
+ readonly webglFallback?: boolean;
153
+ }
154
+ export function materialLightingEnabled(
155
+ tier: QualityTier,
156
+ environment: IMaterialLightingEnvironment,
157
+ ): boolean {
158
+ return (
159
+ tier === "high" &&
160
+ environment.web &&
161
+ environment.rendererKind === "webgpu" &&
162
+ environment.mobile !== true &&
163
+ environment.software !== true &&
164
+ environment.webglFallback !== true
165
+ );
166
+ }
167
+
168
+ /** A WebGPURenderer wrapper may run an ordinary WebGL fallback backend. */
169
+ export function isWebGLFallbackRenderer(renderer: unknown): boolean {
170
+ if (renderer === null || typeof renderer !== "object") return false;
171
+ const backend = Reflect.get(renderer, "backend");
172
+ return (
173
+ backend !== null &&
174
+ typeof backend === "object" &&
175
+ Reflect.get(backend, "isWebGLBackend") === true
176
+ );
177
+ }
@@ -1,49 +1,99 @@
1
1
  // Generated for you. This is ordinary Three.js — edit or delete it freely.
2
2
  //
3
- // The sky is a photograph: `assets/sky.jpg`, Poly Haven's "Kloofendal 48d Partly Cloudy (Pure Sky)"
4
- // by Greg Zaal and Jarod Guest, CC0 (https://polyhaven.com/a/kloofendal_48d_partly_cloudy_puresky).
5
- // The same image is the background, the environment light every surface reflects and is filled by,
6
- // and — through `SUN_DIRECTION` — the direction the sun's shadows fall. Swap the file for any
7
- // equirectangular sky and re-aim `SUN_DIRECTION` at its sun.
3
+ // A vertical blue gradient supplies the background; a measured environment supplies the light.
4
+ // The background's lower hemisphere matches skyFloor around the floating route.
8
5
  import {
9
6
  BackSide,
10
7
  Color,
8
+ DataTexture,
11
9
  EquirectangularReflectionMapping,
12
10
  Float32BufferAttribute,
13
11
  FogExp2,
12
+ LinearFilter,
14
13
  Mesh,
15
14
  MeshBasicMaterial,
15
+ RGBAFormat,
16
16
  SRGBColorSpace,
17
17
  type Scene,
18
18
  SphereGeometry,
19
19
  type Texture,
20
+ UnsignedByteType,
20
21
  Vector3,
21
22
  } from "three";
23
+ import { HEIGHT_FOG, type HeightFogParams, heightFogDepth, heightFogNode } from "./heightFog.js";
22
24
  import { palette } from "./palette.js";
23
25
 
26
+ /** Unit vector toward the authored sun, 47.9° above the horizon. */
27
+ export const SUN_DIRECTION = new Vector3(0.555, 0.742, 0.38).normalize();
28
+
29
+ /** The look this fog replaced: FogExp2 at 0.003, measured at 150 m from 2 m up. */
30
+ const EYE_LEVEL = { density: 0.003, distance: 150, cameraHeight: 2 };
31
+
24
32
  /**
25
- * How the JPEG was made from the 4k HDR: linear radiance × 0.4, clipped, sRGB-encoded — so white
26
- * in the file is 2.5 in the sky. Multiplying back restores the HDR brightness of the clouds; the sun
27
- * disk itself is clipped, which is why the sun is a light (`lighting.ts`) and not a texel.
33
+ * The distance term's density that, with the height term, keeps the old eye-level haze: at
34
+ * `EYE_LEVEL.distance` along the horizon from `EYE_LEVEL.cameraHeight` the two together transmit what
35
+ * FogExp2 at `EYE_LEVEL.density` did. The distance term is lowered, never removed, so the ground
36
+ * still ends in fog at a kilometre.
28
37
  */
29
- const SKY_RANGE = 2.5;
38
+ function distanceDensity(p: HeightFogParams = HEIGHT_FOG): number {
39
+ const { distance, density, cameraHeight } = EYE_LEVEL;
40
+ const old = (density * distance) ** 2;
41
+ const height = heightFogDepth(p, cameraHeight, cameraHeight, distance) * Math.LN2;
42
+ return Math.sqrt(Math.max(0, old - height)) / distance;
43
+ }
30
44
 
31
- /** Unit vector toward the photographed sun: 47.9° up, measured from the source HDR. */
32
- export const SUN_DIRECTION = new Vector3(0.555, 0.742, 0.38).normalize();
45
+ export function gradientColor(row: number, height: number): Color {
46
+ const high = new Color(palette.skyHigh);
47
+ const mid = new Color(palette.skyLow);
48
+ const horizon = new Color(palette.horizon);
49
+ const deep = high.clone().lerp(horizon, 0.45);
50
+ // DataTexture rows start at v=0 (nadir); equirectangular v=0.5 is the horizon.
51
+ const elevation = Math.sin((row / (height - 1) - 0.5) * Math.PI);
52
+ return elevation < 0
53
+ ? horizon.clone().lerp(deep, Math.min(1, -elevation / 0.6))
54
+ : elevation < 0.5
55
+ ? horizon.clone().lerp(mid, elevation * 2)
56
+ : mid.clone().lerp(high, (elevation - 0.5) * 2);
57
+ }
33
58
 
34
- export function setupSky(scene: Scene, sky: Texture): void {
59
+ /** sRGB equirectangular radiance, from the lower haze through the horizon to the zenith. */
60
+ export function skyTexture(): DataTexture {
61
+ // three's PMREM sizes its cube from width / 4, needing at least 16: keep width >= 64.
62
+ const width = 256;
63
+ const height = 128;
64
+ const data = new Uint8Array(width * height * 4);
65
+ for (let row = 0; row < height; row += 1) {
66
+ const encoded = gradientColor(row, height).convertLinearToSRGB();
67
+ for (let column = 0; column < width; column += 1) {
68
+ data.set(
69
+ [...encoded.toArray().map((value) => Math.round(value * 255)), 255],
70
+ (row * width + column) * 4,
71
+ );
72
+ }
73
+ }
74
+ const sky = new DataTexture(data, width, height, RGBAFormat, UnsignedByteType);
35
75
  sky.mapping = EquirectangularReflectionMapping;
36
76
  sky.colorSpace = SRGBColorSpace;
77
+ sky.magFilter = LinearFilter;
78
+ sky.minFilter = LinearFilter;
79
+ sky.needsUpdate = true;
80
+ return sky;
81
+ }
82
+
83
+ export function setupSky(scene: Scene, sky: Texture, environment: Texture = sky): void {
84
+ sky.mapping = EquirectangularReflectionMapping;
37
85
  scene.background = sky;
38
- scene.backgroundIntensity = SKY_RANGE;
86
+ scene.backgroundIntensity = 1;
39
87
  // three prefilters an equirectangular `scene.environment` itself (PMREM), on WebGPU and WebGL.
40
- // It is what makes a standard material read as a material: sky-blue fill on faces the sun
41
- // misses, and a sky to reflect, sharper as roughness drops.
42
- scene.environment = sky;
43
- scene.environmentIntensity = SKY_RANGE;
88
+ // The measured fill lights faces the sun misses and supplies reflections as roughness drops.
89
+ scene.environment = environment;
90
+ scene.environmentIntensity = 1;
44
91
  // The route runs to x=97 with the backdrop cliffs another 60 m behind them, so this is thin on
45
92
  // purpose: at this density it is under 2% inside the playfield and only reads past the castle.
46
- scene.fog = new FogExp2(palette.horizon, 0.003);
93
+ // `scene.fog` stays the distance term; `scene.fogNode` is what three applies and adds the height term.
94
+ const distanceFog = new FogExp2(palette.horizon, distanceDensity());
95
+ scene.fog = distanceFog;
96
+ scene.fogNode = heightFogNode(distanceFog, HEIGHT_FOG, SUN_DIRECTION);
47
97
  }
48
98
 
49
99
  /**
@@ -56,11 +106,10 @@ const FLOOR_RADIUS = 480;
56
106
  const RISE = 0.35;
57
107
 
58
108
  /**
59
- * What the world floats in. A photographed sky ends in a flat grey ground disc, and the route has no
60
- * ground: everything under the horizon was a white void the fog could not hide. This is the lower
109
+ * What the world floats in. The route has no ground; this is the lower
61
110
  * hemisphere, from the fog colour at the horizon to a deeper sky blue straight down, so distant
62
111
  * rock fades into it exactly as it fades into the fog. It climbs 20 degrees past the horizon and
63
- * fades out there, so the photograph melts into the haze instead of meeting it at a hard line.
112
+ * fades out there, so the gradient melts into the haze instead of meeting it at a hard line.
64
113
  * It is not fogged and never writes depth.
65
114
  */
66
115
  export function skyFloor(): Mesh {
@@ -102,8 +151,8 @@ export function skyFloor(): Mesh {
102
151
  /**
103
152
  * The cloud bank, as a list of lobes to instance.
104
153
  *
105
- * Eighteen clouds of five to nine squashed lobes is 130-odd separate spheres, and a photograph sky
106
- * is a static one — so the scene builds one `InstancedBatch` of a unit sphere from this and never
154
+ * Eighteen clouds of five to nine squashed lobes is 130-odd separate spheres, and the gradient sky
155
+ * is static — so the scene builds one `InstancedBatch` of a unit sphere from this and never
107
156
  * touches it again. The motion in the sky is the airship in `scenery.ts`, which crosses the frame
108
157
  * in twenty seconds, and the parallax of a fox covering ninety-seven metres.
109
158
  *
@@ -0,0 +1,50 @@
1
+ // Generated for you. This is ordinary Three.js — edit or delete it freely.
2
+ import {
3
+ Color,
4
+ DataTexture,
5
+ DataUtils,
6
+ EquirectangularReflectionMapping,
7
+ HalfFloatType,
8
+ LinearFilter,
9
+ LinearSRGBColorSpace,
10
+ RGBAFormat,
11
+ } from "three";
12
+ import { gradientColor } from "./sky.js";
13
+
14
+ // Measured from the photographed sky this kit used to light with, preserving its tuned lighting
15
+ // when the background became a stylized gradient; edit these fills to relight.
16
+ const UPPER_FILL = new Color(0.355, 0.423, 0.627);
17
+ const LOWER_FILL = new Color(0.68, 0.67, 0.633);
18
+ export function skyEnvironment(): DataTexture {
19
+ const width = 256;
20
+ const height = 128;
21
+ const data = new Uint16Array(width * height * 4);
22
+ const upperMean = new Color(0, 0, 0);
23
+ let weights = 0;
24
+ for (let row = height / 2; row < height; row += 1) {
25
+ const elevation = (row / (height - 1) - 0.5) * Math.PI;
26
+ const weight = Math.abs(Math.cos(elevation));
27
+ upperMean.add(gradientColor(row, height).multiplyScalar(weight));
28
+ weights += weight;
29
+ }
30
+ upperMean.multiplyScalar(1 / weights);
31
+ const scale = new Color(
32
+ UPPER_FILL.r / upperMean.r,
33
+ UPPER_FILL.g / upperMean.g,
34
+ UPPER_FILL.b / upperMean.b,
35
+ );
36
+ for (let row = 0; row < height; row += 1) {
37
+ const color = row < height / 2 ? LOWER_FILL : gradientColor(row, height).multiply(scale);
38
+ const rgba = [color.r, color.g, color.b, 1].map(DataUtils.toHalfFloat);
39
+ for (let column = 0; column < width; column += 1) {
40
+ data.set(rgba, (row * width + column) * 4);
41
+ }
42
+ }
43
+ const environment = new DataTexture(data, width, height, RGBAFormat, HalfFloatType);
44
+ environment.colorSpace = LinearSRGBColorSpace;
45
+ environment.mapping = EquirectangularReflectionMapping;
46
+ environment.minFilter = LinearFilter;
47
+ environment.magFilter = LinearFilter;
48
+ environment.needsUpdate = true;
49
+ return environment;
50
+ }