@wildshard/engine 0.1.17 → 0.1.19

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 (343) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/budgets/shard-size-baseline.json +10 -4
  3. package/index.html +6 -4
  4. package/lint/engine-sides.json +21 -0
  5. package/lint/host-callback-syntax.mjs +2 -1
  6. package/lint/host-callbacks.mjs +3 -3
  7. package/lint/host-files.mjs +5 -4
  8. package/lint/no-base64.mjs +3 -1
  9. package/lint/ratchet.json +0 -68
  10. package/lint/ratchet.mjs +1 -4
  11. package/lint/shard-imports.mjs +6 -7
  12. package/lint/shard-source.d.mts +9 -0
  13. package/lint/shard-source.mjs +91 -0
  14. package/lint/shardfile-boundaries.mjs +10 -8
  15. package/lint/sim-closure.mjs +6 -3
  16. package/lint/wildshard-plugin.d.ts +4 -0
  17. package/lint/wildshard-plugin.js +22 -23
  18. package/package.json +25 -16
  19. package/scripts/agent-sync.mjs +27 -8
  20. package/scripts/app-build/appCook.ts +8 -2
  21. package/scripts/app-build/catalogue.ts +10 -7
  22. package/scripts/app-build/gen.ts +22 -2
  23. package/scripts/app-build/isolation.d.mts +10 -0
  24. package/scripts/app-build/isolation.mjs +47 -0
  25. package/scripts/app-build/outputProducts.d.mts +3 -0
  26. package/scripts/app-build/outputProducts.mjs +35 -0
  27. package/scripts/app-build/previousDeploy.d.mts +2 -0
  28. package/scripts/app-build/previousDeploy.mjs +10 -1
  29. package/scripts/app-build/serviceWorker.ts +10 -3
  30. package/scripts/app-build/splitOutput.mjs +4 -2
  31. package/scripts/app-build/standaloneOutput.d.mts +1 -1
  32. package/scripts/app-build/standaloneOutput.mjs +5 -3
  33. package/scripts/app-build/titlePreloads.d.mts +8 -0
  34. package/scripts/app-build/titlePreloads.mjs +69 -0
  35. package/scripts/app-build/worldMapAtlas.ts +10 -6
  36. package/scripts/app-build-pipeline.mjs +34 -3
  37. package/scripts/built-product.mjs +1 -1
  38. package/scripts/cell-mem-bench.mjs +81 -23
  39. package/scripts/check-custom-sections-zero.mjs +1 -1
  40. package/scripts/check-devserver.mjs +3 -1
  41. package/scripts/check-models.mjs +2 -0
  42. package/scripts/check-paths.allow.json +0 -115
  43. package/scripts/check-paths.mjs +2 -2
  44. package/scripts/check-platform-ratchets.mjs +2 -3
  45. package/scripts/chromium-keychain-check.mjs +4 -2
  46. package/scripts/chromium-keychain.d.mts +1 -1
  47. package/scripts/chromium-keychain.mjs +3 -1
  48. package/scripts/ci-static.sh +1 -1
  49. package/scripts/committed-fast-checks.mjs +0 -2
  50. package/scripts/content-sw-proof.mjs +2 -1
  51. package/scripts/cook-worker.mjs +9 -3
  52. package/scripts/cook.mjs +20 -3
  53. package/scripts/devices.d.mts +4 -0
  54. package/scripts/devices.mjs +39 -0
  55. package/scripts/devserver-client.d.mts +4 -2
  56. package/scripts/devserver-client.mjs +25 -8
  57. package/scripts/docs-inputs-proof.mjs +6 -6
  58. package/scripts/doctor-proof.mjs +1 -1
  59. package/scripts/e2e-faults.mjs +159 -0
  60. package/scripts/e7-voice-staging-proof.mjs +1 -1
  61. package/scripts/gate-related-tests.mjs +1 -1
  62. package/scripts/git-source-view.mjs +1 -1
  63. package/scripts/goldens/capture.mjs +17 -5
  64. package/scripts/grid-crossing-nightly.mjs +59 -0
  65. package/scripts/grid-crossing-qa.mjs +44 -0
  66. package/scripts/grid-crossing-ratchet.d.mts +6 -0
  67. package/scripts/grid-crossing-ratchet.mjs +52 -0
  68. package/scripts/grid-crossing-report.mjs +122 -0
  69. package/scripts/grid-crossing-stages.mjs +47 -0
  70. package/scripts/grid-crossing-tour.mjs +277 -0
  71. package/scripts/grid-crossing-walk-proof.mjs +136 -18
  72. package/scripts/host-ruler/roots.mjs +2 -2
  73. package/scripts/host-ruler.d.mts +91 -0
  74. package/scripts/host-ruler.mjs +565 -0
  75. package/scripts/live-prepush.py +3 -5
  76. package/scripts/loading-flow/benchmax.mjs +3 -1
  77. package/scripts/look-loop/test_look_loop.py +1 -38
  78. package/scripts/memory-proof.mjs +213 -0
  79. package/scripts/mmo-bots.mjs +8 -2
  80. package/scripts/net-lag-proof.mjs +219 -0
  81. package/scripts/night-market-kit-budget.mjs +2 -2
  82. package/scripts/offline-proof-rules.d.mts +5 -3
  83. package/scripts/offline-proof-rules.mjs +34 -7
  84. package/scripts/offline-proof.mjs +88 -18
  85. package/scripts/{shard-platform-output.mjs → output-reader.mjs} +1 -1
  86. package/scripts/page-release/content.d.mts +9 -1
  87. package/scripts/page-release/content.mjs +131 -17
  88. package/scripts/page-release/flow.mjs +36 -10
  89. package/scripts/page-release/stamp-content.mjs +24 -0
  90. package/scripts/page-release.mjs +28 -6
  91. package/scripts/page-size.mjs +2 -1
  92. package/scripts/pin-packs.ts +1 -1
  93. package/scripts/pins.ts +4 -4
  94. package/scripts/precommit-checks.mjs +1 -7
  95. package/scripts/precommit-jobs.mjs +0 -1
  96. package/scripts/precommit-source.py +1 -9
  97. package/scripts/program-discovery.mjs +1 -1
  98. package/scripts/ring-cook.mjs +2 -1
  99. package/scripts/ring-step.ts +1 -1
  100. package/scripts/script-scenario-metrics.mjs +1 -1
  101. package/scripts/shard-output-content.d.mts +1 -1
  102. package/scripts/shard-output-content.mjs +2 -2
  103. package/scripts/shard-outputs.mjs +1 -1
  104. package/scripts/shard-public.mjs +1 -1
  105. package/scripts/shard-wire-meter.mjs +24 -9
  106. package/scripts/side-parity.mjs +4 -2
  107. package/scripts/standalone-smoke.mjs +8 -3
  108. package/scripts/tier-textures-proof.mjs +101 -0
  109. package/scripts/tier-textures.mjs +78 -0
  110. package/scripts/tile-bake-report.mjs +1 -1
  111. package/scripts/tile-bakes.mjs +1 -1
  112. package/scripts/title-assets.generated.json +2 -0
  113. package/scripts/tsconfig.json +1 -2
  114. package/scripts/vendor/basisu/LICENSE +201 -0
  115. package/scripts/vendor/basisu/basis_encoder.cjs +2 -0
  116. package/scripts/vendor/basisu/basis_encoder.wasm +0 -0
  117. package/scripts/vitest-push-guards.config.ts +1 -1
  118. package/scripts/vps/harden-apply.sh +4 -1
  119. package/scripts/vps/harden-prometheus.sh +176 -0
  120. package/scripts/vps/harden.sh +16 -0
  121. package/scripts/vps/rebuild.sh +18 -0
  122. package/scripts/vps/wildshard-config +84 -24
  123. package/scripts/worker-client-play.mjs +7 -2
  124. package/scripts/worker-client-proof.mjs +1 -1
  125. package/scripts/worker-client-slug.mjs +44 -0
  126. package/scripts/worktree-reap.mjs +5 -5
  127. package/src/.oxlintrc.json +3 -182
  128. package/src/client/app/entry.ts +47 -12
  129. package/src/client/engine/boot/bootCache.ts +2 -2
  130. package/src/client/engine/boot/bootTrace.ts +12 -4
  131. package/src/client/engine/boot/browserChunkRecovery.ts +4 -0
  132. package/src/client/engine/boot/clearDownloads.ts +5 -2
  133. package/src/client/engine/boot/contentRead.ts +11 -0
  134. package/src/client/engine/boot/gpuFiles.ts +4 -2
  135. package/src/client/engine/boot/lastEnd.ts +99 -12
  136. package/src/client/engine/boot/parsedPages.ts +127 -58
  137. package/src/client/engine/boot/texturePack.ts +2 -2
  138. package/src/client/engine/build.d.ts +2 -0
  139. package/src/client/engine/core/Game.ts +18 -0
  140. package/src/client/engine/core/bootstrap.ts +4 -1
  141. package/src/client/engine/debug/probe.ts +18 -1
  142. package/src/client/engine/fx/LightPool.ts +41 -1
  143. package/src/client/engine/net/netPlayer.ts +19 -2
  144. package/src/client/engine/net/otherPlayers.ts +55 -8
  145. package/src/client/engine/net/predictor.ts +33 -9
  146. package/src/client/engine/net/redial.ts +29 -6
  147. package/src/client/engine/pwa/cacheNames.ts +58 -1
  148. package/src/client/engine/pwa/sw.js +53 -14
  149. package/src/client/engine/render/dataLook.ts +152 -40
  150. package/src/client/engine/render/families/detail.ts +89 -0
  151. package/src/client/engine/render/families/pbr.ts +7 -1
  152. package/src/client/engine/render/look.ts +6 -0
  153. package/src/client/engine/render/lookLight.ts +103 -11
  154. package/src/client/engine/render/lookRender.ts +105 -0
  155. package/src/client/engine/render/precompile.ts +20 -14
  156. package/src/client/engine/saves/indexed.ts +2 -2
  157. package/src/client/engine/telemetry/browserErrors.ts +28 -4
  158. package/src/client/engine/telemetry/deviceSnapshot.ts +155 -0
  159. package/src/client/engine/telemetry/staleBuildReport.ts +22 -1
  160. package/src/client/engine/ui/debugOptions.ts +1 -1
  161. package/src/client/engine/ui/lookLightOption.ts +10 -6
  162. package/src/client/engine/ui/namePrompt.ts +7 -0
  163. package/src/client/game/boot/audio.generated.ts +114 -216
  164. package/src/client/game/boot/bytes.generated.ts +118 -238
  165. package/src/client/game/boot/placedSpawn.ts +35 -0
  166. package/src/client/game/boot/spawnDownload.ts +25 -6
  167. package/src/client/game/boot/versions.generated.ts +7 -7
  168. package/src/client/game/devScene/hook.ts +291 -0
  169. package/src/client/game/grid/area.ts +38 -0
  170. package/src/client/game/grid/cellLoading.ts +12 -2
  171. package/src/client/game/grid/live.ts +134 -12
  172. package/src/client/game/grid/liveSession.ts +47 -5
  173. package/src/client/game/grid/mapAtlas.ts +18 -4
  174. package/src/client/game/grid/menu.ts +4 -0
  175. package/src/client/game/grid/minimapBlend.ts +15 -5
  176. package/src/client/game/grid/neighbourPanels.ts +10 -1
  177. package/src/client/game/grid/oneWayIn.ts +5 -1
  178. package/src/client/game/grid/placedCards.ts +55 -0
  179. package/src/client/game/grid/placedCells.ts +233 -0
  180. package/src/client/game/grid/placedContent.ts +85 -0
  181. package/src/client/game/grid/prefetch.ts +9 -1
  182. package/src/client/game/grid/productInputs.ts +3 -1
  183. package/src/client/game/grid/productLeases.ts +4 -1
  184. package/src/client/game/grid/products.ts +8 -4
  185. package/src/client/game/grid/regionalRuntime.ts +6 -0
  186. package/src/client/game/grid/regionalWorld.ts +15 -2
  187. package/src/client/game/grid/roadCull.ts +44 -14
  188. package/src/client/game/grid/roadLook.ts +24 -15
  189. package/src/client/game/grid/roadLookPlatform.ts +4 -2
  190. package/src/client/game/grid/roadResources.ts +24 -0
  191. package/src/client/game/grid/roadSign.worker.ts +4 -3
  192. package/src/client/game/grid/roadSignPaint.ts +16 -5
  193. package/src/client/game/grid/roadSignPreparation.ts +4 -3
  194. package/src/client/game/grid/roadSignScale.ts +8 -0
  195. package/src/client/game/grid/roadTileBacking.ts +13 -3
  196. package/src/client/game/grid/roadTileCapture.worker.ts +3 -1
  197. package/src/client/game/grid/roadTileCaptureWorker.ts +2 -1
  198. package/src/client/game/grid/roadTileWrite.worker.ts +4 -2
  199. package/src/client/game/grid/roadTileWriter.ts +2 -1
  200. package/src/client/game/grid/screenReports.ts +39 -0
  201. package/src/client/game/grid/session.ts +29 -4
  202. package/src/client/game/grid/shardfileFar.ts +9 -3
  203. package/src/client/game/grid/softWallLook.ts +25 -8
  204. package/src/client/game/mainMenu.ts +6 -2
  205. package/src/client/game/plugin/context.ts +2 -1
  206. package/src/client/game/plugin/followedMovers.ts +7 -1
  207. package/src/client/game/quest/figures.ts +2 -0
  208. package/src/client/game/session/finish.ts +11 -1
  209. package/src/client/game/shard/titleList.ts +6 -2
  210. package/src/client/game/shardfile/assetCache.ts +4 -4
  211. package/src/client/game/shardfile/client.ts +4 -1
  212. package/src/client/game/shardfile/clientAssets.ts +9 -5
  213. package/src/client/game/shardfile/clientLibrary.ts +1 -1
  214. package/src/client/game/shardfile/clientWater.ts +51 -9
  215. package/src/client/game/shardfile/clientWorker.ts +21 -8
  216. package/src/client/game/shardfile/look.ts +8 -3
  217. package/src/client/game/shardfile/product.ts +34 -7
  218. package/src/client/game/shardfile/productChecks.ts +2 -2
  219. package/src/client/game/shardfile/productCost.ts +2 -2
  220. package/src/client/game/shardfile/readAsset.ts +2 -2
  221. package/src/client/game/shardfile/reflectingWater.ts +73 -0
  222. package/src/client/game/shardfile/seatGrace.ts +9 -0
  223. package/src/client/game/shardfile/skinPlayback.ts +1 -1
  224. package/src/client/game/systems/npc/figureRows.ts +9 -0
  225. package/src/client/game/titleDeck.ts +4 -3
  226. package/src/client/host/online/doctor.ts +2 -0
  227. package/src/client/host/online/linkScreens.ts +30 -4
  228. package/src/client/host/online/shell.ts +14 -0
  229. package/src/client/host/standalone/shell.ts +4 -0
  230. package/src/cook/game/astc6Encode.ts +55 -0
  231. package/src/cook/game/astc6Wasm.ts +176 -0
  232. package/src/cook/game/cookJob.ts +30 -6
  233. package/src/cook/game/cookWorker.ts +38 -11
  234. package/src/cook/game/entryTotals.ts +51 -24
  235. package/src/cook/game/shardCook.ts +67 -9
  236. package/src/cook/game/spawnParts.ts +33 -8
  237. package/src/cook/game/tierTextures.ts +349 -0
  238. package/src/e2e/smoke/game.ts +19 -14
  239. package/src/e2e/smoke/page-globals.d.ts +9 -8
  240. package/src/e2e/smoke/template2.spec.ts +8 -7
  241. package/src/server/engine/ai/bossContenders.ts +27 -3
  242. package/src/server/engine/ai/phases.ts +1 -1
  243. package/src/server/engine/entities/creatureRefill.ts +9 -2
  244. package/src/server/engine/net/ledgerBook.ts +2 -0
  245. package/src/server/engine/net/room.ts +15 -0
  246. package/src/server/engine/sim/respawn.ts +8 -0
  247. package/src/server/game/boss/arenaRoomEntry.ts +5 -1
  248. package/src/server/game/boss/arenaRoomNative.ts +2 -0
  249. package/src/server/game/boss/native.ts +2 -1
  250. package/src/server/game/boss/nativeWake.ts +9 -5
  251. package/src/server/game/boss/openArenaNative.ts +2 -2
  252. package/src/server/game/boss/openArenaRoom.ts +3 -1
  253. package/src/server/game/grid/room.ts +44 -3
  254. package/src/server/game/grid/simulation.ts +23 -0
  255. package/src/server/game/population/mixedRoster.ts +11 -3
  256. package/src/server/game/population/nativeBake.ts +8 -3
  257. package/src/server/game/population/nativeReturns.ts +6 -3
  258. package/src/server/game/population/roster.ts +5 -3
  259. package/src/server/game/quest/eliteDrops.ts +15 -4
  260. package/src/server/game/quest/nativeChapter.ts +1 -1
  261. package/src/server/game/quest/nativeComposition.ts +5 -1
  262. package/src/server/game/riding/nativeTaming.ts +10 -6
  263. package/src/server/game/riding/wildRefill.ts +3 -2
  264. package/src/server/game/shardfile/bossRow.ts +4 -2
  265. package/src/server/game/shardfile/homeKeeper.ts +4 -2
  266. package/src/server/host/bake/headlessWorker.ts +1 -1
  267. package/src/server/host/dedicated/cellHost.ts +98 -16
  268. package/src/server/host/dedicated/cellProtocol.ts +16 -1
  269. package/src/server/host/dedicated/cellWorker.ts +8 -5
  270. package/src/server/host/dedicated/dedicatedRoom.ts +16 -6
  271. package/src/server/host/dedicated/gridCells.ts +15 -6
  272. package/src/server/host/dedicated/loopLag.ts +21 -0
  273. package/src/server/host/dedicated/main.ts +13 -5
  274. package/src/server/host/dedicated/packReader.ts +3 -3
  275. package/src/server/host/dedicated/placementFile.ts +4 -19
  276. package/src/server/host/dedicated/roadRoom.ts +34 -4
  277. package/src/server/host/dedicated/serverMetrics.ts +126 -0
  278. package/src/server/host/dedicated/socketPump.ts +21 -4
  279. package/src/server/host/dedicated/socketTransport.ts +2 -1
  280. package/src/server/host/dedicated/workerTable.ts +15 -4
  281. package/src/server/host/dedicated/world.ts +95 -8
  282. package/src/server/host/headless.ts +1 -1
  283. package/src/server/host/headlessRuntime.ts +1 -1
  284. package/src/server/host/standalone/roadWorld.ts +15 -3
  285. package/src/server/host/standalone/serverHost.ts +4 -1
  286. package/src/server/host/standalone/serverProduct.ts +41 -11
  287. package/src/shared/engine/ai/BossBrain.ts +8 -0
  288. package/src/shared/engine/net/deviceWord.ts +138 -0
  289. package/src/shared/engine/net/socketFrames.ts +7 -4
  290. package/src/shared/game/boss/wake.ts +6 -0
  291. package/src/shared/game/devColliders.ts +47 -0
  292. package/src/shared/game/eliteSystem.ts +8 -0
  293. package/src/shared/game/grid/allocator.ts +3 -0
  294. package/src/shared/game/grid/catalogueSlot.ts +7 -0
  295. package/src/shared/game/grid/placementRows.ts +36 -0
  296. package/src/shared/game/plugin/bossRecord.ts +3 -2
  297. package/src/shared/game/shardfile/ktx2Targets.ts +23 -3
  298. package/src/shared/game/shardfile/outputDescriptor.ts +9 -5
  299. package/src/shared/game/shardfile/packReads.ts +28 -3
  300. package/src/shared/game/shardfile/serverPack.ts +9 -0
  301. package/src/shared/game/systems/looks/trampleField.ts +2 -0
  302. package/src/shared/host/formatJsonSchema.ts +2 -2
  303. package/src/tsconfig.json +1 -27
  304. package/lint/host-reviews.json +0 -14
  305. package/lint/listed-view-code.json +0 -13
  306. package/lint/platform-pending-users.json +0 -2520
  307. package/lint/platform-pending-users.md +0 -18
  308. package/scripts/cell-mem/metrics-preload.mjs +0 -65
  309. package/scripts/check-closed-components.d.mts +0 -7
  310. package/scripts/check-closed-components.mjs +0 -87
  311. package/scripts/g571-hosts.d.mts +0 -3
  312. package/scripts/g571-hosts.mjs +0 -54
  313. package/scripts/host-ruler/register-migrate.mjs +0 -242
  314. package/scripts/listed-view-code.d.mts +0 -7
  315. package/scripts/listed-view-code.mjs +0 -93
  316. package/scripts/look-loop/fit-lut.py +0 -142
  317. package/scripts/look-loop/palette-delta.py +0 -183
  318. package/scripts/look-loop/regions/driftwood-isle.json +0 -25
  319. package/scripts/look-loop/regions/far-reach.json +0 -225
  320. package/scripts/look-loop/regions/open-plot-night-market.json +0 -855
  321. package/scripts/look-loop/regions/pine-hollow.json +0 -22
  322. package/scripts/look-loop/regions/sunscar-dunes.json +0 -281
  323. package/scripts/platform-chargebacks.d.mts +0 -9
  324. package/scripts/platform-chargebacks.mjs +0 -135
  325. package/scripts/shard-component-spans.d.mts +0 -15
  326. package/scripts/shard-component-spans.mjs +0 -18
  327. package/scripts/shard-components.d.mts +0 -16
  328. package/scripts/shard-components.mjs +0 -363
  329. package/scripts/shard-platform-hosts.d.mts +0 -2
  330. package/scripts/shard-platform-hosts.mjs +0 -93
  331. package/scripts/shard-platform-sections.d.mts +0 -2
  332. package/scripts/shard-platform-sections.mjs +0 -9
  333. package/scripts/shard-platform.d.mts +0 -76
  334. package/scripts/shard-platform.mjs +0 -1072
  335. package/src/.oxfmtrc.json +0 -48
  336. package/src/scripts/ask-new.sh +0 -29
  337. package/src/scripts/asks.mjs +0 -142
  338. package/src/scripts/herdr-prompt.sh +0 -34
  339. package/src/scripts/herdr-question-open.sh +0 -67
  340. package/src/scripts/md-wrap.mjs +0 -229
  341. /package/scripts/{shard-platform-format.d.mts → node-format.d.mts} +0 -0
  342. /package/scripts/{shard-platform-format.mjs → node-format.mjs} +0 -0
  343. /package/scripts/{shard-platform-output.d.mts → output-reader.d.mts} +0 -0
@@ -22,8 +22,11 @@ import { loadLookGraphCompiler } from './graphBackend';
22
22
  import { EmissiveLook } from './families/emissive';
23
23
  import { familyMaterial } from './families/registry';
24
24
  import { ToonLook } from './families/toon';
25
- import { LOOK_RIM_PATCH, lightPools, rimPatch } from './lookLight';
26
- import type { LookPools, LookRim } from '@wildshard/format/look-light';
25
+ import { LOOK_RIM_PATCH, bounceLight, environmentScene, lampLights, lightPools, rimPatch } from './lookLight';
26
+ import { ExposureEffect, lampHalos, lookMotes, tickGlow } from './lookRender';
27
+ import type { LookMotes, LookShadow, LookVignette } from '@wildshard/format/look-render';
28
+ import type { LookBounce, LookEnvironment, LookLamp, LookPools, LookRim } from '@wildshard/format/look-light';
29
+ import { tierPmremGenerator } from './pmremSize';
27
30
 
28
31
  type Rgb = readonly [number, number, number];
29
32
  const mesh = (object: THREE.Object3D): object is THREE.Mesh => object instanceof THREE.Mesh;
@@ -59,7 +62,21 @@ export interface DataLookSpec {
59
62
  * its light settings as they resolved at load (LF1-4, `render/lookLight.ts`): a rim patched into every lit material, the
60
63
  * light pools' decal draw and the fog program's height density; absent: none of them
61
64
  */
62
- readonly light?: { readonly rim: LookRim | null; readonly pools: LookPools | null; readonly heightFogDensity: number };
65
+ readonly light?: {
66
+ readonly rim: LookRim | null; readonly pools: LookPools | null; readonly heightFogDensity: number;
67
+ /** B2: real lamps, a warm bounce and a sky-derived environment; absent or null: none */
68
+ readonly lamps?: readonly LookLamp[] | null; readonly bounce?: LookBounce | null; readonly environment?: LookEnvironment | null;
69
+ /** TEMPLATES-CLEANROOM M4: the sun's shadow look and glow motes; absent or null: the engine's shadows, no motes */
70
+ readonly shadow?: LookShadow | null; readonly motes?: LookMotes | null;
71
+ };
72
+ /** B2 (`look.grade.tone` neutral): the Neutral display curve in place of the engine's AgX */
73
+ readonly neutral?: boolean;
74
+ /** M4.7 (`look.grade.tone` aces): the ACES filmic curve in place of the engine's AgX */
75
+ readonly aces?: boolean;
76
+ /** M4.7: `look.grade.exposure` in stops ahead of the tone curve (absent or 0: none), its vignette and bloom radius */
77
+ readonly exposure?: number;
78
+ readonly vignette?: LookVignette | null;
79
+ readonly bloomRadius?: number | null;
63
80
  }
64
81
 
65
82
  /** A sampled look: plain numbers, blended between the two keys around a time of day. */
@@ -129,6 +146,63 @@ async function lutTexture(url: string | Uint8Array | null): Promise<LookupTextur
129
146
  return lut;
130
147
  }
131
148
 
149
+ const NEUTRAL_FRAGMENT = `
150
+ vec3 neutralCurve(vec3 color) {
151
+ const float startCompression = 0.8 - 0.04;
152
+ const float desaturation = 0.15;
153
+ float x = min(color.r, min(color.g, color.b));
154
+ float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
155
+ color -= offset;
156
+ float peak = max(color.r, max(color.g, color.b));
157
+ if (peak < startCompression) return color;
158
+ float d = 1.0 - startCompression;
159
+ float newPeak = 1.0 - d * d / (peak + d - startCompression);
160
+ color *= newPeak / peak;
161
+ float g = 1.0 - 1.0 / (desaturation * (peak - newPeak) + 1.0);
162
+ return mix(color, vec3(newPeak), g);
163
+ }
164
+ void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
165
+ outputColor = vec4(neutralCurve(inputColor.rgb), inputColor.a);
166
+ }
167
+ `;
168
+
169
+ /**
170
+ * The NEUTRAL tone curve (Khronos PBR Neutral, three's `NeutralToneMapping` at exposure 1) as a grid cell's display: the
171
+ * page's colour pass already holds a ToneMappingEffect, and a second one includes three's tone-mapping chunk twice
172
+ * ('toneMappingExposure' redefinition), so the merged pass would never compile; this is the same curve under its own name.
173
+ */
174
+ export class NeutralToneEffect extends Effect {
175
+ constructor() { super('NeutralToneEffect', NEUTRAL_FRAGMENT, { blendFunction: BlendFunction.NORMAL }); }
176
+ }
177
+
178
+ const ACES_FRAGMENT = `
179
+ uniform float uExposure;
180
+ vec3 acesFit(vec3 v) { vec3 a = v * (v + 0.0245786) - 0.000090537; vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081; return a / b; }
181
+ void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
182
+ const mat3 inputMat = mat3(vec3(0.59719, 0.07600, 0.02840), vec3(0.35458, 0.90834, 0.13383), vec3(0.04823, 0.01566, 0.83777));
183
+ const mat3 outputMat = mat3(vec3(1.60475, -0.10208, -0.00327), vec3(-0.53108, 1.10813, -0.07276), vec3(-0.07367, -0.00605, 1.07602));
184
+ vec3 color = outputMat * acesFit(inputMat * (inputColor.rgb * uExposure / 0.6));
185
+ outputColor = vec4(clamp(color, 0.0, 1.0), inputColor.a);
186
+ }
187
+ `;
188
+
189
+ /**
190
+ * M4.7 (review MUST): the ACES filmic curve (three's `ACESFilmicToneMapping`) as a grid cell's display, with the look's
191
+ * exposure folded in, for the reason `NeutralToneEffect` exists: a cell never runs `compose`, so the page chain's tone
192
+ * mode and the spliced `ExposureEffect` never reach it.
193
+ */
194
+ export class AcesToneEffect extends Effect {
195
+ constructor(stops: number) {
196
+ super('AcesToneEffect', ACES_FRAGMENT, { blendFunction: BlendFunction.NORMAL, uniforms: new Map([['uExposure', new THREE.Uniform(2 ** stops)]]) });
197
+ }
198
+ }
199
+
200
+ /** a data look's grid-cell display: its own tone curve, when it names one (Neutral, or ACES with its exposure) */
201
+ function cellTone(spec: { readonly neutral?: boolean; readonly aces?: boolean; readonly exposure?: number }): { readonly cell: { readonly replaces: 'tone'; readonly build: () => { display: Effect } } } | Record<string, never> {
202
+ if (spec.aces === true) { const stops = spec.exposure ?? 0; return { cell: { replaces: 'tone', build: () => ({ display: new AcesToneEffect(stops) }) } }; }
203
+ return spec.neutral === true ? { cell: { replaces: 'tone', build: () => ({ display: new NeutralToneEffect() }) } } : {};
204
+ }
205
+
132
206
  /**
133
207
  * A level look from data: the engine's clean chain, the gradient dome, the engine fog, key light and ambient turned by
134
208
  * the keys on the engine clock, and the LUT last in the grade. Nothing is patched into another material.
@@ -136,6 +210,8 @@ async function lutTexture(url: string | Uint8Array | null): Promise<LookupTextur
136
210
  export function dataLook(spec: DataLookSpec): LookStrategy {
137
211
  if (spec.keys.length === 0) throw new Error('[look] a data look needs at least one key');
138
212
  const linear = spec.keys[0]?.fog.near !== undefined;
213
+ // the keys the frame samples: a `liveKeys` call (sharddev `watch`, through engine's dev hook) replaces them in place
214
+ let keys = spec.keys;
139
215
  // the mist's GLSL is in the linear fog only when the look declares it (LF1-4): off, the shader text is as before
140
216
  const mist = (spec.light?.heightFogDensity ?? 0) > 0;
141
217
  const fog = { wsLookFogNear: new THREE.Uniform(0), wsLookFogFar: new THREE.Uniform(1), wsLookFogEnabled: new THREE.Uniform(0) };
@@ -163,11 +239,24 @@ ${mist ? `
163
239
  #endif`);
164
240
  shader.fragmentShader = `#ifdef USE_FOG\nuniform float wsLookFogNear; uniform float wsLookFogFar; uniform float wsLookFogEnabled;\n#endif\n${patched}`;
165
241
  };
166
- const owned: { dome: THREE.Mesh<THREE.SphereGeometry, THREE.ShaderMaterial> | null; lut: LookupTexture | null; pools: THREE.Object3D | null; rim: boolean } = { dome: null, lut: null, pools: null, rim: false };
242
+ const owned: { dome: THREE.Mesh<THREE.SphereGeometry, THREE.ShaderMaterial> | null; lut: LookupTexture | null; pools: THREE.Object3D | null; rim: boolean;
243
+ lamps: ReturnType<typeof lampLights> | null; bounce: ReturnType<typeof bounceLight> | null; environment: THREE.WebGLRenderTarget | null;
244
+ glow: THREE.Object3D[] | null } = { dome: null, lut: null, pools: null, rim: false, lamps: null, bounce: null, environment: null, glow: null };
245
+ const shadow = spec.light?.shadow ?? null;
246
+ const bounceRow = spec.light?.bounce ?? null;
247
+ // the bounce exists from the backdrop on (it follows the clock's sun there); compose adds it to the scene
248
+ if (bounceRow !== null) owned.bounce = bounceLight(bounceRow);
167
249
  return {
250
+ ...cellTone(spec),
251
+ liveKeys: (next) => {
252
+ // a fog kind change (exponential to linear, or back) changes the fog patch's shader text: that needs a new look
253
+ if (next.length === 0 || next.some((key) => (key.fog.near !== undefined) !== linear)) return false;
254
+ keys = next;
255
+ return true;
256
+ },
168
257
  // the sky builds before the composer: the level scope takes the dome and the LUT here
169
- mode: 'extend', chain: 'clean', compose: ({ engineChain, scene, scope }) => {
170
- const rim = spec.light?.rim ?? null, pools = spec.light?.pools ?? null;
258
+ mode: 'extend', chain: 'clean', compose: ({ engineChain, scene, scope, fx, renderer }) => {
259
+ const rim = spec.light?.rim ?? null, pools = spec.light?.pools ?? null, lamps = spec.light?.lamps ?? null;
171
260
  if (rim !== null && !owned.rim) {
172
261
  owned.rim = true; scope.onDispose(() => { owned.rim = false; });
173
262
  // LF1-4: one rim patch over every lit material, present and later (its values are uniforms: one shader text)
@@ -187,6 +276,43 @@ ${mist ? `
187
276
  owned.pools = decal;
188
277
  scene.add(decal); scope.own(decal.geometry); scope.own(decal.material); scope.onDispose(() => { decal.removeFromParent(); decal.dispose(); if (owned.pools === decal) owned.pools = null; });
189
278
  }
279
+ if (lamps !== null && owned.lamps === null) {
280
+ // B2: real lamps, once per look like the pools
281
+ const group = lampLights(lamps);
282
+ owned.lamps = group;
283
+ scene.add(group); scope.onDispose(() => { group.removeFromParent(); for (const light of group.children) if (light instanceof THREE.Light) light.dispose(); if (owned.lamps === group) owned.lamps = null; });
284
+ }
285
+ const motes = spec.light?.motes ?? null;
286
+ if (owned.glow === null && ((lamps?.some((lamp) => lamp.halo !== undefined) ?? false) || motes !== null)) {
287
+ // M4.8: the lamps' halos (one instanced draw) and the motes (one points draw), once per look like the lamps
288
+ const glow: (THREE.Mesh | THREE.Points)[] = [];
289
+ const halos = lamps === null ? null : lampHalos(lamps);
290
+ if (halos !== null) glow.push(halos);
291
+ if (motes !== null) glow.push(lookMotes(motes));
292
+ owned.glow = glow;
293
+ for (const draw of glow) { scene.add(draw); scope.own(draw.geometry); scope.own(draw.material as THREE.Material); }
294
+ scope.onDispose(() => { for (const draw of glow) { draw.removeFromParent(); if (draw instanceof THREE.InstancedMesh) draw.dispose(); } if (owned.glow === glow) owned.glow = null; });
295
+ }
296
+ const bounce = owned.bounce;
297
+ if (bounce !== null && bounce.light.parent !== scene) {
298
+ scene.add(bounce.light, bounce.light.target); scope.onDispose(() => { bounce.light.removeFromParent(); bounce.light.target.removeFromParent(); });
299
+ }
300
+ const envRow = spec.light?.environment ?? null;
301
+ if (envRow !== null && owned.environment === null && owned.dome !== null) {
302
+ // B2: sky-derived ambient, filtered once from the dome at the look's start (a clock that runs keeps this one). Built
303
+ // here, not in the backdrop: a grid cell runs only the backdrop and must not hold an unused cube (review MUST 2).
304
+ // The far plane clears the 600 m dome (fromScene's default 100 m clips it to black).
305
+ const made = environmentScene(owned.dome, envRow), pmrem = tierPmremGenerator(renderer);
306
+ let target: THREE.WebGLRenderTarget;
307
+ try { target = pmrem.fromScene(made.scene, 0.02, 0.1, 1000); } finally { pmrem.dispose(); made.dispose(); }
308
+ const before = { environment: scene.environment, intensity: scene.environmentIntensity };
309
+ owned.environment = target;
310
+ scene.environment = target.texture; scene.environmentIntensity = envRow.intensity;
311
+ scope.onDispose(() => {
312
+ if (scene.environment === target.texture) { scene.environment = before.environment; scene.environmentIntensity = before.intensity; }
313
+ target.dispose(); if (owned.environment === target) owned.environment = null;
314
+ });
315
+ }
190
316
  if (linear) {
191
317
  setInheritedPatch(patchFog, { scope, chain: true });
192
318
  const seen = new Set<THREE.Material>();
@@ -201,20 +327,34 @@ ${mist ? `
201
327
  const { dome, lut } = owned;
202
328
  if (dome !== null) { scope.own(dome.geometry); scope.own(dome.material); scope.onDispose(() => { dome.removeFromParent(); }); }
203
329
  if (lut !== null) scope.own(lut);
204
- return { chain: engineChain('clean') };
330
+ const chain = engineChain('clean');
331
+ // B2: the Neutral curve keeps the look's saturated albedo saturated, where AgX would grey it (asked after the clean chain)
332
+ if (spec.neutral === true) fx.tone.mode = ToneMappingMode.NEUTRAL;
333
+ // M4.7: ACES, the look's own vignette and bloom spread, and its exposure ahead of the curve
334
+ if (spec.aces === true) fx.tone.mode = ToneMappingMode.ACES_FILMIC;
335
+ if (spec.vignette !== undefined && spec.vignette !== null) { fx.vignette.offset = spec.vignette.offset; fx.vignette.darkness = spec.vignette.darkness; }
336
+ if (spec.bloomRadius !== undefined && spec.bloomRadius !== null) fx.bloom.mipmapBlurPass.radius = spec.bloomRadius;
337
+ const stops = spec.exposure ?? 0, at = chain.indexOf(fx.tone);
338
+ if (stops !== 0 && at !== -1) { const exposure = new ExposureEffect(stops); scope.own(exposure); chain.splice(at, 0, exposure); }
339
+ return { chain };
205
340
  },
206
341
  // G992: no sun disc or corona over the gradient dome. A 1° disc read as a blurred speck with a halo ("half-assed moon
207
342
  // or sun", Jake), and a crisp disc alone as a 3 px dot (art/open-plots/sun-disc-g992/board.jpg); the key light is unchanged.
208
343
  sky: { clouds: false, planet: false, sun: { disc: false, halo: false } },
344
+ // M4.7: the look's shadow radius and normal bias (its strength is set on the cascades each frame, below)
345
+ ...(shadow === null ? {} : { shadows: { rig: 'tier' as const, radius: shadow.radius, normalBias: shadow.normalBias } }),
209
346
  backdrop: async ({ sky }) => {
210
347
  const clock = dataLookClock(spec.day, spec.dayOverride), now = lookSample();
211
348
  const { dome, zenith, horizon } = gradientDome();
212
349
  owned.dome = dome;
213
- let targets: SkyBackdropTargets | null = null;
350
+ const bounce = owned.bounce;
351
+ let targets: SkyBackdropTargets | null = null, flicker = 0;
214
352
  const apply = (): void => {
215
- sampleLook(spec.keys, clock.hour / 24, now);
353
+ sampleLook(keys, clock.hour / 24, now);
216
354
  zenith.copy(now.zenith); horizon.copy(now.horizon);
217
355
  sky.setKeyLight(clock.sunDir, now.sun, now.sunIntensity);
356
+ bounce?.aim(clock.sunDir);
357
+ if (shadow !== null) for (const light of (sky.csm as { lights?: readonly THREE.DirectionalLight[] } | undefined)?.lights ?? []) light.shadow.intensity = shadow.intensity;
218
358
  if (targets === null) return;
219
359
  targets.hemi.color.copy(now.ambientSky); targets.hemi.groundColor.copy(now.ambientGround); targets.hemi.intensity = now.ambientIntensity;
220
360
  fog.wsLookFogEnabled.value = targets.underwater() ? 0 : Number(linear);
@@ -227,12 +367,13 @@ ${mist ? `
227
367
  targets.fogU.fogDistDensity.value = now.fogDensity; targets.fogU.fogHeightDensity.value = spec.light?.heightFogDensity ?? 0;
228
368
  targets.fogU.fogSunColor.value.copy(now.sun);
229
369
  };
230
- sampleLook(spec.keys, clock.hour / 24, now);
370
+ sampleLook(keys, clock.hour / 24, now);
231
371
  zenith.copy(now.zenith); horizon.copy(now.horizon);
372
+ bounce?.aim(clock.sunDir);
232
373
  owned.lut = await lutTexture(spec.lut);
233
374
  return { clock, horizon: now.fog.clone(), lut: owned.lut, clouds: dome,
234
375
  bind: (t) => { targets = t; apply(); },
235
- update: (dt) => { clock.update(dt); apply(); },
376
+ update: (dt) => { clock.update(dt); apply(); flicker += dt; owned.lamps?.update?.(flicker); if (owned.glow !== null) tickGlow(owned.glow, flicker); },
236
377
  rebuild: () => undefined, attachPost: () => undefined };
237
378
  },
238
379
  };
@@ -373,35 +514,6 @@ export function headingHaze(row: HeadingHazeRow, sun: LookVec3): (shader: Shader
373
514
  };
374
515
  }
375
516
 
376
- const NEUTRAL_FRAGMENT = `
377
- vec3 neutralCurve(vec3 color) {
378
- const float startCompression = 0.8 - 0.04;
379
- const float desaturation = 0.15;
380
- float x = min(color.r, min(color.g, color.b));
381
- float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
382
- color -= offset;
383
- float peak = max(color.r, max(color.g, color.b));
384
- if (peak < startCompression) return color;
385
- float d = 1.0 - startCompression;
386
- float newPeak = 1.0 - d * d / (peak + d - startCompression);
387
- color *= newPeak / peak;
388
- float g = 1.0 - 1.0 / (desaturation * (peak - newPeak) + 1.0);
389
- return mix(color, vec3(newPeak), g);
390
- }
391
- void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
392
- outputColor = vec4(neutralCurve(inputColor.rgb), inputColor.a);
393
- }
394
- `;
395
-
396
- /**
397
- * The NEUTRAL tone curve (Khronos PBR Neutral, three's `NeutralToneMapping` at exposure 1) as a grid cell's display: the
398
- * page's colour pass already holds a ToneMappingEffect, and a second one includes three's tone-mapping chunk twice
399
- * ('toneMappingExposure' redefinition), so the merged pass would never compile; this is the same curve under its own name.
400
- */
401
- export class NeutralToneEffect extends Effect {
402
- constructor() { super('NeutralToneEffect', NEUTRAL_FRAGMENT, { blendFunction: BlendFunction.NORMAL }); }
403
- }
404
-
405
517
  /** A painted look's dome (its sky layer) and the heading strip its haze reads (null on a painted-strip sky). */
406
518
  export interface PaintedSky { readonly dome: THREE.Mesh<THREE.BufferGeometry, THREE.Material>; readonly strip: THREE.Texture | null }
407
519
  /** A painted look's dressing: the sky pieces that stand in the world (a sea of cloud, the sun's glow) and their tick. */
@@ -0,0 +1,89 @@
1
+ /**
2
+ * The PBR family's detail layer (meta TEMPLATES-CLEANROOM M4.11, `@wildshard/format/detail-layer`, J338's procedural
3
+ * route): the stone, slab, wood and moss texture a cleanroom paints on canvases, drawn by the shader from world position,
4
+ * so it costs no bytes and needs no UVs. Per pixel:
5
+ * - broad value-noise blotches swing the albedo by `mottle`, a fine speckle by `grain`;
6
+ * - the same pattern, read as a height in metres, tilts the shading normal by `relief` (screen-space bump, Mikkelsen's
7
+ * surface-gradient method, as three's bump map);
8
+ * - `moss` grows on up-facing faces where a second, coarser noise passes `1 - amount`.
9
+ * Every knob is a uniform over one shader text, so all detailed surfaces share one program. Identifiers carry a `famD`
10
+ * prefix. A surface takes a detail layer alone, not with a ground or measure layer (each owns the albedo).
11
+ */
12
+ import * as THREE from 'three';
13
+ import { patchShader, PATCH_ORDER } from '../shaderPatches';
14
+ import type { PbrMaterialParams } from '@wildshard/format/materialFamilies';
15
+
16
+ /** a PBR surface's detail layer (`@wildshard/format/detail-layer`'s `DetailLayer`) */
17
+ type DetailLayer = NonNullable<PbrMaterialParams['detail']>;
18
+
19
+ /** the program-cache key of every PBR material with a detail layer */
20
+ export const DETAIL_PROGRAM_KEY = 'family.pbr.detail.v1';
21
+ /** the speckle's frequency over the blotches' */
22
+ const GRAIN_OCTAVE = 9;
23
+ /** the relief's height (m) per metre of pattern scale at `relief` 1 */
24
+ const RELIEF_HEIGHT = 0.12;
25
+
26
+ const VERT_PARS = 'varying vec3 vFamDPos;\nvarying vec3 vFamDN;';
27
+ const VERT_WORLD = /* glsl */`#include <worldpos_vertex>
28
+ vec4 famDW = vec4( transformed, 1.0 );
29
+ vec3 famDN = objectNormal;
30
+ #ifdef USE_INSTANCING
31
+ famDW = instanceMatrix * famDW;
32
+ famDN = mat3( instanceMatrix ) * famDN;
33
+ #endif
34
+ vFamDPos = ( modelMatrix * famDW ).xyz;
35
+ vFamDN = normalize( mat3( modelMatrix ) * famDN );`;
36
+
37
+ const FRAG_PARS = /* glsl */`
38
+ varying vec3 vFamDPos;
39
+ varying vec3 vFamDN;
40
+ uniform vec4 famDK; // 1 / scale (1/m), mottle, grain, relief height (m)
41
+ uniform vec4 famDMoss; // linear colour, amount (0 = none)
42
+ float famDHash( vec3 p ) { p = fract( p * 0.1031 ); p += dot( p, p.zyx + 31.32 ); return fract( ( p.x + p.y ) * p.z ); }
43
+ float famDNoise( vec3 p ) {
44
+ vec3 i = floor( p ), f = fract( p );
45
+ f = f * f * ( 3.0 - 2.0 * f );
46
+ float a = mix( famDHash( i ), famDHash( i + vec3( 1.0, 0.0, 0.0 ) ), f.x );
47
+ float b = mix( famDHash( i + vec3( 0.0, 1.0, 0.0 ) ), famDHash( i + vec3( 1.0, 1.0, 0.0 ) ), f.x );
48
+ float c = mix( famDHash( i + vec3( 0.0, 0.0, 1.0 ) ), famDHash( i + vec3( 1.0, 0.0, 1.0 ) ), f.x );
49
+ float d = mix( famDHash( i + vec3( 0.0, 1.0, 1.0 ) ), famDHash( i + vec3( 1.0, 1.0, 1.0 ) ), f.x );
50
+ return mix( mix( a, b, f.y ), mix( c, d, f.y ), f.z );
51
+ }
52
+ float famDFbm( vec3 p ) { return 0.5 * famDNoise( p ) + 0.3 * famDNoise( p * 2.03 + 11.0 ) + 0.2 * famDNoise( p * 4.01 + 23.0 ); }`;
53
+
54
+ const FRAG_COLOUR = /* glsl */`#include <color_fragment>
55
+ vec3 famDP = vFamDPos * famDK.x;
56
+ float famDM = famDFbm( famDP );
57
+ float famDG = famDNoise( famDP * ${GRAIN_OCTAVE.toFixed(1)} );
58
+ diffuseColor.rgb *= max( 0.0, 1.0 + ( famDM - 0.5 ) * 2.0 * famDK.y + ( famDG - 0.5 ) * famDK.z );
59
+ float famDMossK = 0.0;
60
+ if ( famDMoss.w > 0.0 ) {
61
+ float famDUp = smoothstep( 0.5, 0.85, normalize( vFamDN ).y );
62
+ famDMossK = famDUp * smoothstep( 1.0 - famDMoss.w, 1.0 - famDMoss.w + 0.2, famDFbm( famDP * 0.6 + 7.0 ) * 0.7 + famDM * 0.3 );
63
+ diffuseColor.rgb = mix( diffuseColor.rgb, famDMoss.rgb * ( 0.8 + 0.4 * famDG ), famDMossK );
64
+ }`;
65
+
66
+ const FRAG_NORMAL = /* glsl */`#include <normal_fragment_maps>
67
+ if ( famDK.w > 0.0 ) {
68
+ float famDH = ( famDM + ( famDG - 0.5 ) * 0.3 + famDMossK * 0.4 ) * famDK.w;
69
+ vec3 famDSx = dFdx( -vViewPosition ), famDSy = dFdy( -vViewPosition );
70
+ vec3 famDR1 = cross( famDSy, normal ), famDR2 = cross( normal, famDSx );
71
+ float famDDet = dot( famDSx, famDR1 ) * faceDirection;
72
+ vec3 famDGrad = sign( famDDet ) * ( dFdx( famDH ) * famDR1 + dFdy( famDH ) * famDR2 );
73
+ normal = normalize( abs( famDDet ) * normal - famDGrad );
74
+ }`;
75
+
76
+ /** Draw a detail layer on a PBR material (in place). */
77
+ export function applyDetail(m: THREE.MeshStandardMaterial, detail: DetailLayer): void {
78
+ const moss = detail.moss;
79
+ const mossColour = moss === undefined ? new THREE.Color(0, 0, 0) : new THREE.Color().setRGB(moss.colour[0], moss.colour[1], moss.colour[2], THREE.SRGBColorSpace);
80
+ const uniforms: Record<string, { value: unknown }> = {
81
+ famDK: { value: new THREE.Vector4(1 / detail.scale, detail.mottle, detail.grain, detail.relief * detail.scale * RELIEF_HEIGHT) },
82
+ famDMoss: { value: new THREE.Vector4(mossColour.r, mossColour.g, mossColour.b, moss?.amount ?? 0) },
83
+ };
84
+ patchShader(m, 'engine.family.detail', PATCH_ORDER.material, (shader) => {
85
+ Object.assign(shader.uniforms, uniforms);
86
+ shader.vertexShader = shader.vertexShader.replace('#include <common>', `#include <common>\n${VERT_PARS}`).replace('#include <worldpos_vertex>', VERT_WORLD);
87
+ shader.fragmentShader = shader.fragmentShader.replace('#include <common>', `#include <common>\n${FRAG_PARS}`).replace('#include <color_fragment>', FRAG_COLOUR).replace('#include <normal_fragment_maps>', FRAG_NORMAL);
88
+ }, { key: DETAIL_PROGRAM_KEY });
89
+ }
@@ -7,9 +7,11 @@
7
7
  * shares one program per object variant and a missing map is a uniform, not a recompile (the same trick the sky rig
8
8
  * plays on loaded models). Program changes come only from `vertexColours`, `faceted`, `doubleSided`, `alphaCutoff > 0` and a
9
9
  * procedural `ground` layer (ground.ts: wind ripples, grain and terrain light shaping, Signal Dunes' sand) or `measure`
10
- * layer (measure.ts: SF56's dev-map grid, roles and size labels).
10
+ * layer (measure.ts: SF56's dev-map grid, roles and size labels) or `detail` layer (detail.ts: M4.11's world-space
11
+ * mottling, grain, bumps and moss).
11
12
  */
12
13
  import * as THREE from 'three';
14
+ import { applyDetail } from './detail';
13
15
  import { applyGround } from './ground';
14
16
  import { applyMeasure } from './measure';
15
17
  import type { PbrMaterialParams } from '@wildshard/format/materialFamilies';
@@ -63,5 +65,9 @@ export function compilePbr(params: PbrMaterialParams, textures: TextureResolver,
63
65
  if (params.ground !== null && params.measure !== null) throw new Error('material family: a PBR surface takes a ground or a measure layer, not both');
64
66
  if (params.ground !== null) applyGround(m, params.ground, textures, emitterPools);
65
67
  if (params.measure !== null) applyMeasure(m, params.measure);
68
+ if (params.detail !== undefined) {
69
+ if (params.ground !== null || params.measure !== null) throw new Error('material family: a PBR surface takes a detail layer alone, not with a ground or measure layer');
70
+ applyDetail(m, params.detail);
71
+ }
66
72
  return m;
67
73
  }
@@ -1,6 +1,7 @@
1
1
  import type { Camera, Color, DirectionalLight, Fog, Group, HemisphereLight, Material, Mesh, Object3D, Sprite, Texture, Vector3, PerspectiveCamera, Scene, WebGLRenderer, WebGLRenderTarget } from 'three';
2
2
  import type { BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, Effect, EffectComposer, GodRaysEffect, HueSaturationEffect, LookupTexture, LUT3DEffect, NoiseEffect, Pass, ToneMappingEffect, VignetteEffect } from 'postprocessing';
3
3
  import type { N8AOPostPass } from 'n8ao';
4
+ import type { LookKey } from './dataLook';
4
5
  import type { GradeEffect } from '../core/Grade';
5
6
  import type { DayCycleClock } from '../../../shared/engine/world/dayCycle';
6
7
  import type { SkyRig as Sky } from '../world/skyRig';
@@ -259,6 +260,11 @@ export interface ExtendLook extends LookParts {
259
260
  * cell carries its engine chain only. Standalone its compose builds its composite as before.
260
261
  */
261
262
  cell?: LookCellComposite;
263
+ /**
264
+ * A data look's day keys replaced in place (SHARD-SOURCE AP5: `wildshard watch` sets a look live through engine's dev
265
+ * hook); the next frame samples them. False: this look can't take them live (a fog kind change), so the page reloads.
266
+ */
267
+ liveKeys?: (keys: readonly LookKey[]) => boolean;
262
268
  compose: (c: LookComposeContext) => LookComposition;
263
269
  }
264
270
 
@@ -11,12 +11,21 @@
11
11
  * - `pools`: light pools on the ground under lamps (`lightPools`), one additive instanced decal draw for all of them,
12
12
  * never a dynamic light per lamp.
13
13
  * - `grade.bloom`: the engine bloom's intensity and threshold, which a shardfile shard had hard-wired to 0 (LF1-2).
14
+ * - `lamps`, `bounce`, `environment` (meta TEMPLATES-CLEANROOM B2): real point lights at lanterns, tents and fires; a
15
+ * shadowless warm fill from the anti-sun heading; an environment filtered once from the look's own sky over a ground
16
+ * colour (`dataLook`).
14
17
  *
15
- * All of it waits behind Settings ▸ Debug ▸ Look ▸ "Look light" (default off, read at load) until Jake picks: with the row
16
- * off, a look that declares every setting draws as one that declares none.
18
+ * - `shadow`, `motes`, a lamp's `decay`, `halo` and `flicker` (TEMPLATES-CLEANROOM M4): the sun's shadow strength,
19
+ * radius and normal bias; drifting glow points; lamp halos and an unsteady fire light (`lookRender.ts`).
20
+ *
21
+ * All of it waits behind Settings ▸ Debug ▸ Look ▸ "Look light" (read at load; default on): with the row off, a look that
22
+ * declares every setting draws as one that declares none. TEMPLATES-CLEANROOM M4.9 gates it per field on the phone tier
23
+ * instead of all or nothing: a phone keeps the environment, bounce, pools, rim, height fog and shadow look, at most
24
+ * `PHONE_LAMPS` lamps, half the motes, and no bloom or AO.
17
25
  */
18
26
  import * as THREE from 'three';
19
- import type { LookLight, LookPools, LookRim } from '@wildshard/format/look-light';
27
+ import type { LookBounce, LookEnvironment, LookLamp, LookLight, LookPools, LookRim } from '@wildshard/format/look-light';
28
+ import type { LookMotes, LookShadow } from '@wildshard/format/look-render';
20
29
  import type { ShaderSource } from './shaderPatches';
21
30
 
22
31
  /** the rim's shader patch id */
@@ -26,32 +35,52 @@ export const LOOK_RIM_PATCH = 'engine.look.rim';
26
35
  export interface LookLightResolved {
27
36
  /** the engine fog program's height term (`LevelSpec.atmosphere`'s fields) */
28
37
  readonly atmosphere: { readonly fogHeight: number; readonly fogHeightFalloff: number; readonly fogHeightDensity: number };
29
- /** the engine bloom (intensity 0: none) */
30
- readonly bloom: { readonly intensity: number; readonly threshold: number };
38
+ /** the engine bloom (intensity 0: none) and its spread (null: the engine's) */
39
+ readonly bloom: { readonly intensity: number; readonly threshold: number; readonly radius: number | null };
31
40
  /** the engine AO on the desktop tier; null: none */
32
41
  readonly ao: { readonly intensity: number; readonly radius: number } | null;
33
42
  readonly rim: LookRim | null;
34
43
  readonly pools: LookPools | null;
44
+ readonly lamps: readonly LookLamp[] | null;
45
+ readonly bounce: LookBounce | null;
46
+ readonly environment: LookEnvironment | null;
47
+ /** M4.2: the sun's shadow look; null: the engine's */
48
+ readonly shadow: LookShadow | null;
49
+ /** M4.4: glow motes; null: none */
50
+ readonly motes: LookMotes | null;
35
51
  }
36
52
 
37
53
  /** the settings a shardfile look carries (structural: `Shardfile['look']` fits) */
38
54
  export interface LookLightSource {
39
55
  readonly light?: LookLight | undefined;
40
- readonly grade: { readonly bloom?: { readonly intensity: number; readonly threshold: number } | undefined };
56
+ readonly grade: { readonly bloom?: { readonly intensity: number; readonly threshold: number; readonly radius?: number | undefined } | undefined };
41
57
  }
42
58
 
43
59
  /** No height fog: the fields a shardfile manifest had before LF1-4. */
44
60
  const NO_HEIGHT_FOG = { fogHeight: -20, fogHeightFalloff: 0, fogHeightDensity: 0 } as const;
45
61
 
46
- /** Resolve a look's light settings; `on` is the Debug row ("Look light"). Off, or nothing declared: as before. */
47
- export function lookLightManifest(look: LookLightSource, on: boolean): LookLightResolved {
48
- const light = on ? look.light : undefined, bloom = on ? look.grade.bloom : undefined, fog = light?.heightFog;
62
+ /** M4.9: at most this many of a look's lamps light on the phone tier (each costs every lit draw a light-loop step) */
63
+ export const PHONE_LAMPS = 4;
64
+
65
+ /**
66
+ * Resolve a look's light settings; `on` is the Debug row ("Look light"), `tier` the page's. Off, or nothing declared: as
67
+ * before. The phone tier keeps the cheap fields (M4.9): no bloom or AO, the first `PHONE_LAMPS` lamps, half the motes.
68
+ */
69
+ export function lookLightManifest(look: LookLightSource, on: boolean, tier = 'desktop'): LookLightResolved {
70
+ const phone = tier === 'phone';
71
+ const light = on ? look.light : undefined, bloom = on && !phone ? look.grade.bloom : undefined, fog = light?.heightFog;
72
+ const motes = light?.motes === undefined ? null : phone ? { ...light.motes, count: Math.max(1, Math.floor(light.motes.count / 2)) } : light.motes;
49
73
  return {
50
74
  atmosphere: fog === undefined ? { ...NO_HEIGHT_FOG } : { fogHeight: fog.height, fogHeightFalloff: fog.falloff, fogHeightDensity: fog.density },
51
- bloom: bloom === undefined ? { intensity: 0, threshold: 1 } : { intensity: bloom.intensity, threshold: bloom.threshold },
52
- ao: light?.ao === undefined ? null : { intensity: light.ao.intensity, radius: light.ao.radius },
75
+ bloom: bloom === undefined ? { intensity: 0, threshold: 1, radius: null } : { intensity: bloom.intensity, threshold: bloom.threshold, radius: bloom.radius ?? null },
76
+ ao: light?.ao === undefined || phone ? null : { intensity: light.ao.intensity, radius: light.ao.radius },
53
77
  rim: light?.rim ?? null,
54
78
  pools: light?.pools ?? null,
79
+ lamps: light?.lamps === undefined ? null : phone ? light.lamps.slice(0, PHONE_LAMPS) : light.lamps,
80
+ bounce: light?.bounce ?? null,
81
+ environment: light?.environment ?? null,
82
+ shadow: light?.shadow ?? null,
83
+ motes,
55
84
  };
56
85
  }
57
86
 
@@ -105,3 +134,66 @@ export function lightPools(pools: LookPools): THREE.InstancedMesh<THREE.PlaneGeo
105
134
  mesh.name = 'look-light-pools'; mesh.renderOrder = 1; mesh.castShadow = false; mesh.receiveShadow = false;
106
135
  return mesh;
107
136
  }
137
+
138
+ /** how far out the bounce light stands from its target (metres): far enough that its direction is the whole frame's */
139
+ const BOUNCE_DISTANCE = 100;
140
+
141
+ /**
142
+ * The look's warm bounce (B2): one shadowless directional light from the anti-sun heading, lifted by `lift`, in linear
143
+ * `colour` × `intensity`. `aim` points it for a sun direction (the clock's): call it when the sun moves.
144
+ */
145
+ export function bounceLight(bounce: LookBounce): { light: THREE.DirectionalLight; aim: (sun: THREE.Vector3) => void } {
146
+ const light = new THREE.DirectionalLight(new THREE.Color().setRGB(bounce.colour[0], bounce.colour[1], bounce.colour[2], THREE.LinearSRGBColorSpace), bounce.intensity);
147
+ light.name = 'look-light-bounce'; light.castShadow = false;
148
+ const dir = new THREE.Vector3();
149
+ const aim = (sun: THREE.Vector3): void => {
150
+ dir.set(-sun.x, 0, -sun.z);
151
+ if (dir.lengthSq() < 1e-8) dir.set(0, 0, 1);
152
+ dir.normalize().multiplyScalar(Math.sqrt(1 - bounce.lift * bounce.lift)).setY(bounce.lift);
153
+ light.position.copy(dir).multiplyScalar(BOUNCE_DISTANCE); light.target.position.set(0, 0, 0);
154
+ light.target.updateMatrixWorld();
155
+ };
156
+ return { light, aim };
157
+ }
158
+
159
+ /**
160
+ * The look's lamps (B2): one shadowless point light each, physical decay unless the lamp sets its own (M4.3). `update`
161
+ * flickers the lamps that declare a flicker (two incommensurate sines per lamp, so no two lamps pulse together); it is
162
+ * null when none does.
163
+ */
164
+ export function lampLights(lamps: readonly LookLamp[]): THREE.Group & { update: ((time: number) => void) | null } {
165
+ const group = Object.assign(new THREE.Group(), { update: null as ((time: number) => void) | null });
166
+ group.name = 'look-light-lamps';
167
+ const flickering: { light: THREE.PointLight; base: number; rate: number; amount: number; phase: number }[] = [];
168
+ lamps.forEach((lamp, i) => {
169
+ const light = new THREE.PointLight(new THREE.Color().setRGB(lamp.colour[0], lamp.colour[1], lamp.colour[2], THREE.LinearSRGBColorSpace), lamp.intensity, lamp.distance, lamp.decay ?? 2);
170
+ light.position.set(lamp.at[0], lamp.at[1], lamp.at[2]); light.castShadow = false;
171
+ group.add(light);
172
+ if (lamp.flicker !== undefined && lamp.flicker.amount > 0) flickering.push({ light, base: lamp.intensity, rate: lamp.flicker.rate, amount: lamp.flicker.amount, phase: i * 2.399 });
173
+ });
174
+ if (flickering.length > 0) {
175
+ group.update = (time) => {
176
+ for (const f of flickering) {
177
+ const w = Math.sin(time * f.rate * 2.1 + f.phase) * 0.6 + Math.sin(time * f.rate * 5.3 + f.phase * 1.7) * 0.4;
178
+ f.light.intensity = f.base * (1 - f.amount * 0.5 + f.amount * 0.5 * w);
179
+ }
180
+ };
181
+ }
182
+ return group;
183
+ }
184
+
185
+ /** the ground disc under the environment's sky: far below and wide, so every downward ray meets it */
186
+ const ENV_GROUND = { radius: 900, depth: -40 } as const;
187
+
188
+ /**
189
+ * The look's environment scene (B2): the sky dome's own material over a ground disc in linear `ground`, for a PMREM to
190
+ * filter once. The caller disposes the disc (the dome is the look's).
191
+ */
192
+ export function environmentScene(dome: THREE.Mesh, environment: LookEnvironment): { scene: THREE.Scene; dispose: () => void } {
193
+ const scene = new THREE.Scene();
194
+ const sky = new THREE.Mesh(dome.geometry, dome.material);
195
+ const floor = new THREE.Mesh(new THREE.CircleGeometry(ENV_GROUND.radius, 24).rotateX(-Math.PI / 2).translate(0, ENV_GROUND.depth, 0),
196
+ new THREE.MeshBasicMaterial({ color: new THREE.Color().setRGB(environment.ground[0], environment.ground[1], environment.ground[2], THREE.LinearSRGBColorSpace) }));
197
+ scene.add(sky, floor);
198
+ return { scene, dispose: () => { floor.geometry.dispose(); floor.material.dispose(); } };
199
+ }