wallhammer-web 0.0.0-stage → 0.4.1

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 (408) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +92 -2
  3. package/dist/base/data.d.ts +67 -0
  4. package/dist/base/data.js +10 -0
  5. package/dist/base/destructible.d.ts +167 -0
  6. package/dist/base/destructible.js +47 -0
  7. package/dist/base/env-slot.d.ts +101 -0
  8. package/dist/base/env-slot.js +8 -0
  9. package/dist/base/frames.d.ts +138 -0
  10. package/dist/base/frames.js +459 -0
  11. package/dist/base/index.d.ts +21 -0
  12. package/dist/base/index.js +11 -0
  13. package/dist/base/mat34.d.ts +46 -0
  14. package/dist/base/mat34.js +173 -0
  15. package/dist/base/material.d.ts +87 -0
  16. package/dist/base/material.js +6 -0
  17. package/dist/base/math.d.ts +27 -0
  18. package/dist/base/math.js +60 -0
  19. package/dist/base/progress.d.ts +38 -0
  20. package/dist/base/progress.js +81 -0
  21. package/dist/base/rig.d.ts +177 -0
  22. package/dist/base/rig.js +97 -0
  23. package/dist/base/trig.d.ts +29 -0
  24. package/dist/base/trig.js +169 -0
  25. package/dist/base/up.d.ts +26 -0
  26. package/dist/base/up.js +40 -0
  27. package/dist/base/view.d.ts +128 -0
  28. package/dist/base/view.js +136 -0
  29. package/dist/camera/camera.d.ts +99 -0
  30. package/dist/camera/camera.js +228 -0
  31. package/dist/camera/follow.d.ts +120 -0
  32. package/dist/camera/follow.js +320 -0
  33. package/dist/camera/free.d.ts +153 -0
  34. package/dist/camera/free.js +359 -0
  35. package/dist/camera/index.d.ts +10 -0
  36. package/dist/camera/index.js +6 -0
  37. package/dist/camera/orbit.d.ts +93 -0
  38. package/dist/camera/orbit.js +261 -0
  39. package/dist/camera/path.d.ts +48 -0
  40. package/dist/camera/path.js +179 -0
  41. package/dist/core/ballistic.d.ts +66 -0
  42. package/dist/core/ballistic.js +104 -0
  43. package/dist/core/bodies.d.ts +77 -0
  44. package/dist/core/bodies.js +125 -0
  45. package/dist/core/clock.d.ts +37 -0
  46. package/dist/core/clock.js +87 -0
  47. package/dist/core/cover-fade.d.ts +14 -0
  48. package/dist/core/cover-fade.js +38 -0
  49. package/dist/core/index.d.ts +13 -0
  50. package/dist/core/index.js +8 -0
  51. package/dist/core/kepler.d.ts +74 -0
  52. package/dist/core/kepler.js +108 -0
  53. package/dist/core/level-fade.d.ts +66 -0
  54. package/dist/core/level-fade.js +123 -0
  55. package/dist/core/palette.d.ts +15 -0
  56. package/dist/core/palette.js +47 -0
  57. package/dist/env/atmosphere.d.ts +129 -0
  58. package/dist/env/atmosphere.js +707 -0
  59. package/dist/env/cloud-field.d.ts +44 -0
  60. package/dist/env/cloud-field.js +111 -0
  61. package/dist/env/environment.d.ts +217 -0
  62. package/dist/env/environment.js +441 -0
  63. package/dist/env/frame-block.d.ts +29 -0
  64. package/dist/env/frame-block.js +152 -0
  65. package/dist/env/glsl.d.ts +35 -0
  66. package/dist/env/glsl.js +246 -0
  67. package/dist/env/index.d.ts +13 -0
  68. package/dist/env/index.js +9 -0
  69. package/dist/env/sky.d.ts +48 -0
  70. package/dist/env/sky.js +227 -0
  71. package/dist/env/sun.d.ts +31 -0
  72. package/dist/env/sun.js +42 -0
  73. package/dist/gen-arch/build.d.ts +17 -0
  74. package/dist/gen-arch/build.js +414 -0
  75. package/dist/gen-arch/damage/damaged.d.ts +44 -0
  76. package/dist/gen-arch/damage/damaged.js +1119 -0
  77. package/dist/gen-arch/damage/fall-material.d.ts +10 -0
  78. package/dist/gen-arch/damage/fall-material.js +47 -0
  79. package/dist/gen-arch/damage/fall.d.ts +78 -0
  80. package/dist/gen-arch/damage/fall.js +797 -0
  81. package/dist/gen-arch/damage/rubble.d.ts +22 -0
  82. package/dist/gen-arch/damage/rubble.js +188 -0
  83. package/dist/gen-arch/index.d.ts +25 -0
  84. package/dist/gen-arch/index.js +16 -0
  85. package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
  86. package/dist/gen-arch/interior/interior-plan.js +615 -0
  87. package/dist/gen-arch/interior/interior.d.ts +97 -0
  88. package/dist/gen-arch/interior/interior.js +966 -0
  89. package/dist/gen-arch/structure/building-shader.d.ts +25 -0
  90. package/dist/gen-arch/structure/building-shader.js +946 -0
  91. package/dist/gen-arch/structure/buildings.d.ts +248 -0
  92. package/dist/gen-arch/structure/buildings.js +294 -0
  93. package/dist/gen-arch/structure/dims.d.ts +77 -0
  94. package/dist/gen-arch/structure/dims.js +39 -0
  95. package/dist/gen-arch/structure/distant.d.ts +62 -0
  96. package/dist/gen-arch/structure/distant.js +316 -0
  97. package/dist/gen-arch/structure/env-slots.d.ts +18 -0
  98. package/dist/gen-arch/structure/env-slots.js +47 -0
  99. package/dist/gen-arch/structure/facade.d.ts +193 -0
  100. package/dist/gen-arch/structure/facade.js +159 -0
  101. package/dist/gen-arch/structure/parts.d.ts +31 -0
  102. package/dist/gen-arch/structure/parts.js +69 -0
  103. package/dist/gen-arch/structure/roof.d.ts +76 -0
  104. package/dist/gen-arch/structure/roof.js +568 -0
  105. package/dist/gen-arch/structure/structure-material.d.ts +23 -0
  106. package/dist/gen-arch/structure/structure-material.js +55 -0
  107. package/dist/gen-arch/structure/writer.d.ts +94 -0
  108. package/dist/gen-arch/structure/writer.js +195 -0
  109. package/dist/gen-core/cell.d.ts +138 -0
  110. package/dist/gen-core/cell.js +150 -0
  111. package/dist/gen-core/cube-sphere.d.ts +57 -0
  112. package/dist/gen-core/cube-sphere.js +159 -0
  113. package/dist/gen-core/field.d.ts +55 -0
  114. package/dist/gen-core/field.js +154 -0
  115. package/dist/gen-core/geometry.d.ts +31 -0
  116. package/dist/gen-core/geometry.js +231 -0
  117. package/dist/gen-core/hash.d.ts +18 -0
  118. package/dist/gen-core/hash.js +58 -0
  119. package/dist/gen-core/height-field.d.ts +33 -0
  120. package/dist/gen-core/height-field.js +137 -0
  121. package/dist/gen-core/index.d.ts +22 -0
  122. package/dist/gen-core/index.js +17 -0
  123. package/dist/gen-core/instance-cells.d.ts +37 -0
  124. package/dist/gen-core/instance-cells.js +72 -0
  125. package/dist/gen-core/near-scatter.d.ts +56 -0
  126. package/dist/gen-core/near-scatter.js +120 -0
  127. package/dist/gen-core/noise.d.ts +23 -0
  128. package/dist/gen-core/noise.js +72 -0
  129. package/dist/gen-core/occupancy.d.ts +21 -0
  130. package/dist/gen-core/occupancy.js +104 -0
  131. package/dist/gen-core/sphere-patch.d.ts +138 -0
  132. package/dist/gen-core/sphere-patch.js +544 -0
  133. package/dist/gen-core/strip-surface.d.ts +34 -0
  134. package/dist/gen-core/strip-surface.js +246 -0
  135. package/dist/gen-core/strip.d.ts +102 -0
  136. package/dist/gen-core/strip.js +817 -0
  137. package/dist/gen-ground/env-slots.d.ts +48 -0
  138. package/dist/gen-ground/env-slots.js +78 -0
  139. package/dist/gen-ground/ground.d.ts +78 -0
  140. package/dist/gen-ground/ground.js +208 -0
  141. package/dist/gen-ground/index.d.ts +9 -0
  142. package/dist/gen-ground/index.js +7 -0
  143. package/dist/gen-ground/markings.d.ts +46 -0
  144. package/dist/gen-ground/markings.js +124 -0
  145. package/dist/gen-ground/materials.d.ts +18 -0
  146. package/dist/gen-ground/materials.js +22 -0
  147. package/dist/gen-ground/terrain-shader.d.ts +5 -0
  148. package/dist/gen-ground/terrain-shader.js +151 -0
  149. package/dist/gen-mesh/bare-shapes.d.ts +194 -0
  150. package/dist/gen-mesh/bare-shapes.js +596 -0
  151. package/dist/gen-mesh/bisect-surface.d.ts +47 -0
  152. package/dist/gen-mesh/bisect-surface.js +261 -0
  153. package/dist/gen-mesh/box.d.ts +18 -0
  154. package/dist/gen-mesh/box.js +2 -0
  155. package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
  156. package/dist/gen-mesh/cell-morph-mesh.js +258 -0
  157. package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
  158. package/dist/gen-mesh/cell-surface-mesh.js +140 -0
  159. package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
  160. package/dist/gen-mesh/chunk-mesh.js +112 -0
  161. package/dist/gen-mesh/drape-mesh.d.ts +36 -0
  162. package/dist/gen-mesh/drape-mesh.js +98 -0
  163. package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
  164. package/dist/gen-mesh/height-field-mesh.js +98 -0
  165. package/dist/gen-mesh/index.d.ts +26 -0
  166. package/dist/gen-mesh/index.js +15 -0
  167. package/dist/gen-mesh/line-mesh.d.ts +25 -0
  168. package/dist/gen-mesh/line-mesh.js +62 -0
  169. package/dist/gen-mesh/mesh-builder.d.ts +115 -0
  170. package/dist/gen-mesh/mesh-builder.js +315 -0
  171. package/dist/gen-mesh/packed-mesh.d.ts +53 -0
  172. package/dist/gen-mesh/packed-mesh.js +205 -0
  173. package/dist/gen-mesh/prism-mesh.d.ts +33 -0
  174. package/dist/gen-mesh/prism-mesh.js +176 -0
  175. package/dist/gen-mesh/rig-mesh.d.ts +9 -0
  176. package/dist/gen-mesh/rig-mesh.js +135 -0
  177. package/dist/gen-mesh/strip-mesh.d.ts +45 -0
  178. package/dist/gen-mesh/strip-mesh.js +258 -0
  179. package/dist/gen-plan/drain.d.ts +58 -0
  180. package/dist/gen-plan/drain.js +270 -0
  181. package/dist/gen-plan/grid.d.ts +37 -0
  182. package/dist/gen-plan/grid.js +182 -0
  183. package/dist/gen-plan/horizon.d.ts +50 -0
  184. package/dist/gen-plan/horizon.js +185 -0
  185. package/dist/gen-plan/index.d.ts +15 -0
  186. package/dist/gen-plan/index.js +13 -0
  187. package/dist/gen-plan/line-tiles.d.ts +35 -0
  188. package/dist/gen-plan/line-tiles.js +190 -0
  189. package/dist/gen-plan/lines.d.ts +31 -0
  190. package/dist/gen-plan/lines.js +183 -0
  191. package/dist/gen-plan/plots.d.ts +40 -0
  192. package/dist/gen-plan/plots.js +282 -0
  193. package/dist/gen-plan/route.d.ts +55 -0
  194. package/dist/gen-plan/route.js +297 -0
  195. package/dist/gen-plan/sites.d.ts +32 -0
  196. package/dist/gen-plan/sites.js +209 -0
  197. package/dist/gen-tex/code-stamp.d.ts +31 -0
  198. package/dist/gen-tex/code-stamp.js +137 -0
  199. package/dist/gen-tex/index.d.ts +7 -0
  200. package/dist/gen-tex/index.js +5 -0
  201. package/dist/gen-tex/light-horizon.d.ts +47 -0
  202. package/dist/gen-tex/light-horizon.js +180 -0
  203. package/dist/gen-tex/textures.d.ts +8 -0
  204. package/dist/gen-tex/textures.js +49 -0
  205. package/dist/gen-tex/value-textures.d.ts +46 -0
  206. package/dist/gen-tex/value-textures.js +102 -0
  207. package/dist/gen-vegetation/env-slots.d.ts +20 -0
  208. package/dist/gen-vegetation/env-slots.js +29 -0
  209. package/dist/gen-vegetation/index.d.ts +8 -0
  210. package/dist/gen-vegetation/index.js +7 -0
  211. package/dist/gen-vegetation/materials.d.ts +7 -0
  212. package/dist/gen-vegetation/materials.js +17 -0
  213. package/dist/gen-vegetation/planting.d.ts +170 -0
  214. package/dist/gen-vegetation/planting.js +363 -0
  215. package/dist/gen-vegetation/tree-shader.d.ts +23 -0
  216. package/dist/gen-vegetation/tree-shader.js +229 -0
  217. package/dist/gen-vegetation/trees.d.ts +59 -0
  218. package/dist/gen-vegetation/trees.js +329 -0
  219. package/dist/gpu/device.d.ts +286 -0
  220. package/dist/gpu/device.js +1157 -0
  221. package/dist/gpu/gl.d.ts +134 -0
  222. package/dist/gpu/gl.js +276 -0
  223. package/dist/gpu/index.d.ts +4 -0
  224. package/dist/gpu/index.js +3 -0
  225. package/dist/index.d.ts +11 -0
  226. package/dist/index.js +13 -0
  227. package/dist/motion/graph.d.ts +244 -0
  228. package/dist/motion/graph.js +739 -0
  229. package/dist/motion/index.d.ts +8 -0
  230. package/dist/motion/index.js +8 -0
  231. package/dist/motion/pose-ops.d.ts +30 -0
  232. package/dist/motion/pose-ops.js +232 -0
  233. package/dist/motion/reach.d.ts +45 -0
  234. package/dist/motion/reach.js +264 -0
  235. package/dist/motion/skeleton.d.ts +49 -0
  236. package/dist/motion/skeleton.js +99 -0
  237. package/dist/platform/byte-store.d.ts +21 -0
  238. package/dist/platform/byte-store.js +137 -0
  239. package/dist/platform/canvas.d.ts +29 -0
  240. package/dist/platform/canvas.js +76 -0
  241. package/dist/platform/context-loss.d.ts +8 -0
  242. package/dist/platform/context-loss.js +17 -0
  243. package/dist/platform/free-input.d.ts +51 -0
  244. package/dist/platform/free-input.js +100 -0
  245. package/dist/platform/index.d.ts +18 -0
  246. package/dist/platform/index.js +10 -0
  247. package/dist/platform/input.d.ts +48 -0
  248. package/dist/platform/input.js +117 -0
  249. package/dist/platform/keys.d.ts +12 -0
  250. package/dist/platform/keys.js +29 -0
  251. package/dist/platform/loop.d.ts +41 -0
  252. package/dist/platform/loop.js +84 -0
  253. package/dist/platform/walk-input.d.ts +74 -0
  254. package/dist/platform/walk-input.js +226 -0
  255. package/dist/platform/worker.d.ts +51 -0
  256. package/dist/platform/worker.js +170 -0
  257. package/dist/render/bone-instances.d.ts +24 -0
  258. package/dist/render/bone-instances.js +74 -0
  259. package/dist/render/cells.d.ts +70 -0
  260. package/dist/render/cells.js +144 -0
  261. package/dist/render/glsl.d.ts +66 -0
  262. package/dist/render/glsl.js +173 -0
  263. package/dist/render/index.d.ts +26 -0
  264. package/dist/render/index.js +16 -0
  265. package/dist/render/instance-sets.d.ts +97 -0
  266. package/dist/render/instance-sets.js +241 -0
  267. package/dist/render/near-instances.d.ts +75 -0
  268. package/dist/render/near-instances.js +219 -0
  269. package/dist/render/particles.d.ts +63 -0
  270. package/dist/render/particles.js +215 -0
  271. package/dist/render/pieces.d.ts +57 -0
  272. package/dist/render/pieces.js +151 -0
  273. package/dist/render/point-lights.d.ts +97 -0
  274. package/dist/render/point-lights.js +243 -0
  275. package/dist/render/renderer.d.ts +447 -0
  276. package/dist/render/renderer.js +1100 -0
  277. package/dist/render/rig.d.ts +74 -0
  278. package/dist/render/rig.js +576 -0
  279. package/dist/render/shadow-areas.d.ts +49 -0
  280. package/dist/render/shadow-areas.js +125 -0
  281. package/dist/render/shadow-glsl.d.ts +12 -0
  282. package/dist/render/shadow-glsl.js +146 -0
  283. package/dist/render/transient.d.ts +61 -0
  284. package/dist/render/transient.js +213 -0
  285. package/dist/render/value-glsl.d.ts +17 -0
  286. package/dist/render/value-glsl.js +208 -0
  287. package/dist/render/value-layers.d.ts +180 -0
  288. package/dist/render/value-layers.js +333 -0
  289. package/dist/runtime/atmosphere.d.ts +37 -0
  290. package/dist/runtime/atmosphere.js +304 -0
  291. package/dist/runtime/cloud-shell.d.ts +29 -0
  292. package/dist/runtime/cloud-shell.js +158 -0
  293. package/dist/runtime/engine.d.ts +155 -0
  294. package/dist/runtime/engine.js +305 -0
  295. package/dist/runtime/environment-link.d.ts +22 -0
  296. package/dist/runtime/environment-link.js +49 -0
  297. package/dist/runtime/index.d.ts +13 -0
  298. package/dist/runtime/index.js +12 -0
  299. package/dist/runtime/precipitation-glsl.d.ts +2 -0
  300. package/dist/runtime/precipitation-glsl.js +70 -0
  301. package/dist/runtime/precipitation.d.ts +11 -0
  302. package/dist/runtime/precipitation.js +78 -0
  303. package/dist/runtime/sky.d.ts +30 -0
  304. package/dist/runtime/sky.js +114 -0
  305. package/dist/runtime/streaming.d.ts +245 -0
  306. package/dist/runtime/streaming.js +602 -0
  307. package/dist/sim/agenda.d.ts +167 -0
  308. package/dist/sim/agenda.js +425 -0
  309. package/dist/sim/bytes.d.ts +34 -0
  310. package/dist/sim/bytes.js +125 -0
  311. package/dist/sim/destruction/apply.d.ts +59 -0
  312. package/dist/sim/destruction/apply.js +243 -0
  313. package/dist/sim/destruction/cell-states.d.ts +54 -0
  314. package/dist/sim/destruction/cell-states.js +198 -0
  315. package/dist/sim/destruction/index.d.ts +11 -0
  316. package/dist/sim/destruction/index.js +10 -0
  317. package/dist/sim/destruction/int-geometry.d.ts +17 -0
  318. package/dist/sim/destruction/int-geometry.js +131 -0
  319. package/dist/sim/destruction/pick.d.ts +13 -0
  320. package/dist/sim/destruction/pick.js +59 -0
  321. package/dist/sim/destruction/rubble.d.ts +8 -0
  322. package/dist/sim/destruction/rubble.js +159 -0
  323. package/dist/sim/destruction/state.d.ts +15 -0
  324. package/dist/sim/destruction/state.js +83 -0
  325. package/dist/sim/destruction/structure.d.ts +30 -0
  326. package/dist/sim/destruction/structure.js +139 -0
  327. package/dist/sim/events.d.ts +37 -0
  328. package/dist/sim/events.js +106 -0
  329. package/dist/sim/fixed.d.ts +21 -0
  330. package/dist/sim/fixed.js +64 -0
  331. package/dist/sim/flow-probe.d.ts +58 -0
  332. package/dist/sim/flow-probe.js +158 -0
  333. package/dist/sim/flow.d.ts +257 -0
  334. package/dist/sim/flow.js +967 -0
  335. package/dist/sim/index.d.ts +28 -0
  336. package/dist/sim/index.js +20 -0
  337. package/dist/sim/interlock.d.ts +47 -0
  338. package/dist/sim/interlock.js +252 -0
  339. package/dist/sim/movers.d.ts +228 -0
  340. package/dist/sim/movers.js +1083 -0
  341. package/dist/sim/nav.d.ts +72 -0
  342. package/dist/sim/nav.js +292 -0
  343. package/dist/sim/paths.d.ts +80 -0
  344. package/dist/sim/paths.js +197 -0
  345. package/dist/sim/regions.d.ts +87 -0
  346. package/dist/sim/regions.js +517 -0
  347. package/dist/sim/simulation.d.ts +114 -0
  348. package/dist/sim/simulation.js +291 -0
  349. package/dist/sim/states.d.ts +23 -0
  350. package/dist/sim/states.js +54 -0
  351. package/dist/sim/table.d.ts +49 -0
  352. package/dist/sim/table.js +126 -0
  353. package/dist/sim/zones.d.ts +11 -0
  354. package/dist/sim/zones.js +196 -0
  355. package/dist/tools/collision-lines.d.ts +12 -0
  356. package/dist/tools/collision-lines.js +50 -0
  357. package/dist/tools/data-view-glsl.d.ts +3 -0
  358. package/dist/tools/data-view-glsl.js +63 -0
  359. package/dist/tools/data-view-layers.d.ts +20 -0
  360. package/dist/tools/data-view-layers.js +60 -0
  361. package/dist/tools/debug-view.d.ts +30 -0
  362. package/dist/tools/debug-view.js +4 -0
  363. package/dist/tools/index.d.ts +10 -0
  364. package/dist/tools/index.js +7 -0
  365. package/dist/tools/mesh-checks.d.ts +67 -0
  366. package/dist/tools/mesh-checks.js +188 -0
  367. package/dist/tools/profile.d.ts +85 -0
  368. package/dist/tools/profile.js +173 -0
  369. package/dist/world/cell-cache.d.ts +32 -0
  370. package/dist/world/cell-cache.js +60 -0
  371. package/dist/world/cell-format.d.ts +25 -0
  372. package/dist/world/cell-format.js +232 -0
  373. package/dist/world/collide.d.ts +192 -0
  374. package/dist/world/collide.js +822 -0
  375. package/dist/world/index.d.ts +16 -0
  376. package/dist/world/index.js +12 -0
  377. package/dist/world/mesh-solids.d.ts +48 -0
  378. package/dist/world/mesh-solids.js +169 -0
  379. package/dist/world/pick.d.ts +34 -0
  380. package/dist/world/pick.js +177 -0
  381. package/dist/world/providers.d.ts +66 -0
  382. package/dist/world/providers.js +83 -0
  383. package/dist/world/sphere.d.ts +69 -0
  384. package/dist/world/sphere.js +271 -0
  385. package/dist/world/streaming.d.ts +288 -0
  386. package/dist/world/streaming.js +801 -0
  387. package/dist/world/walker.d.ts +145 -0
  388. package/dist/world/walker.js +502 -0
  389. package/docs/architecture.md +111 -0
  390. package/docs/cameras.md +302 -0
  391. package/docs/concepts.md +123 -0
  392. package/docs/destruction.md +127 -0
  393. package/docs/frames.md +199 -0
  394. package/docs/generators.md +575 -0
  395. package/docs/getting-started.md +123 -0
  396. package/docs/headless.md +50 -0
  397. package/docs/motion.md +160 -0
  398. package/docs/planet.md +152 -0
  399. package/docs/recipes.md +521 -0
  400. package/docs/reference.md +364 -0
  401. package/docs/rendering.md +823 -0
  402. package/docs/rigs.md +203 -0
  403. package/docs/simulation.md +235 -0
  404. package/docs/streaming.md +590 -0
  405. package/docs/system.md +166 -0
  406. package/docs/tools.md +175 -0
  407. package/docs/walking.md +262 -0
  408. package/package.json +131 -3
@@ -0,0 +1,246 @@
1
+ // GLSL lighting functions over the environment's Frame members (see `ENV_CORE_SLOT`). They also read the renderer's
2
+ // members (light matrix, shadow map, view) by name. Registered as the shader include `lighting`; its first part, the
3
+ // shadow query without the light model, is also the include `shadow` (`shadowGlsl`).
4
+ // With a shadow mode that keeps shadow areas the renderer's header defines `WH_SHADOW_AREAS` and brings `whShadow`.
5
+ // With radial up (`WH_LOCAL_UP`, see the renderer's `radialUp`) the sky is over the local horizon: fill light, cloud
6
+ // shadows and fog follow `localUp` and `localHeight`, and the side turned away from the light gets neither sun nor sky.
7
+ import { CLOUD_TERMS_GLSL } from './environment.js';
8
+ /**
9
+ * Octaves of the cloud field over the world: weight, frequency, offset and noise seed. Cloud shadows on the ground
10
+ * (`cloudLight`) and the clouds in the sky (`<sky>`) are both built from this table, so they agree.
11
+ */
12
+ export const CLOUD_OCTAVES = [
13
+ ['0.55', '1.0', '0.0', 61],
14
+ ['0.3', '2.3', '17.0', 62],
15
+ ['0.15', '5.1', '41.0', 63],
16
+ ];
17
+ /** The cloud field, 0–1, as a GLSL expression of `q` (world xz minus the drift, times 1 / cloud size). */
18
+ export const CLOUD_NOISE = CLOUD_OCTAVES.map(([w, f, o, seed], i) => `${w} * vnoise(${i === 0 ? 'q' : `q * ${f} + ${o}`}, ${seed}u)`).join(' + ');
19
+ /**
20
+ * The cloud field for radial up, as a GLSL expression of a vec3 `q`: the point of the base surface, relative to the
21
+ * centre, minus the drift, times 1 / cloud size. The same octaves in space instead of on a plane, so the field has no
22
+ * seam and no pole.
23
+ */
24
+ export const CLOUD_NOISE_RADIAL = CLOUD_OCTAVES.map(([w, f, o, seed], i) => `${w} * vnoise3(${i === 0 ? 'q' : `q * ${f} + ${o}`}, ${seed}u)`).join(' + ');
25
+ /** Body of `cloudLight` as it has always been: one cloud cover for the whole world. */
26
+ const CLOUD_LIGHT_GLOBAL = /* glsl */ `#ifdef WH_LOCAL_UP
27
+ whUpHere = localUp(worldPos);
28
+ if (u_cloud.z <= 0.0) return 1.0;
29
+ vec3 q = (whUpHere * u_upCenter.w - vec3(u_cloud.x, 0.0, u_cloud.y)) * u_cloud.w;
30
+ float n = ${CLOUD_NOISE_RADIAL};
31
+ #else
32
+ if (u_cloud.z <= 0.0) return 1.0;
33
+ vec2 q = (worldPos.xz - u_cloud.xy) * u_cloud.w;
34
+ float n = ${CLOUD_NOISE};
35
+ #endif
36
+ return 1.0 - u_cloud.z * smoothstep(u_cloudEdge.x, u_cloudEdge.y, n);`;
37
+ /**
38
+ * Functions of the cloud cover by place (the slot `CLOUD_FIELD_SLOT`), for radial up only. The cover is a profile by
39
+ * the angle to an axis plus drifting patches; the shadow pattern over it is the engine's cloud field.
40
+ */
41
+ const CLOUD_FIELD_FUNCTIONS = /* glsl */ `
42
+ #ifdef WH_LOCAL_UP
43
+ ${CLOUD_TERMS_GLSL}
44
+ // Cloud cover 0–1 above the place with unit up \`up\` on a sphere of radius \`radiusM\` (the frame of the field).
45
+ float cloudFieldCover(vec3 up, float radiusM) {
46
+ float a = abs(dot(up, u_cloudFieldAxis.xyz)) * 7.0;
47
+ float c = dot(u_cloudFieldZonalA, max(1.0 - abs(a - vec4(0.0, 1.0, 2.0, 3.0)), 0.0))
48
+ + dot(u_cloudFieldZonalB, max(1.0 - abs(a - vec4(4.0, 5.0, 6.0, 7.0)), 0.0));
49
+ if (u_cloudFieldAxis.w > 0.0) {
50
+ vec3 q = (up * radiusM - u_cloudFieldPatch.xyz) * u_cloudFieldPatch.w;
51
+ if (u_cloudFieldLight.z > 0.0) q += u_cloudFieldLight.z * (vnoise3(q * 0.6 + 31.0, 73u) - 0.5);
52
+ float p = 0.65 * vnoise3(q, 71u) + 0.35 * vnoise3(q * 2.3 + 17.0, 72u);
53
+ c += u_cloudFieldAxis.w * (2.0 * p - 1.0);
54
+ }
55
+ return clamp(c, 0.0, 1.0);
56
+ }
57
+
58
+ // From a cover and the shadow pattern's value there: x = sun share over the frame's dimming (S / G), y = how much
59
+ // cloud stands over the place (1 under a closed deck).
60
+ vec2 cloudFieldShade(float cover, float n) {
61
+ vec4 t = cloudCoverTerms(cover, u_cloudFieldLight.x);
62
+ float s = smoothstep(t.x, t.y, n);
63
+ float sun = (1.0 - t.z * s) * t.w;
64
+ return vec2(sun / max(u_cloudFieldLight.y, 1e-3), max(s * smoothstep(0.0, 0.04, cover), cloudOvercast(cover)));
65
+ }
66
+
67
+ // The cloud by place at unit up \`up\`: (S / G, cloud standing over it). Without any cover: (1, 0) and no lookup.
68
+ vec2 cloudFieldAt(vec3 up, float radiusM) {
69
+ if (u_cloudFieldLight.w <= 0.0) return vec2(1.0, 0.0);
70
+ float c = cloudFieldCover(up, radiusM);
71
+ vec3 q = (up * radiusM - vec3(u_cloud.x, 0.0, u_cloud.y)) * u_cloud.w;
72
+ return cloudFieldShade(c, ${CLOUD_NOISE_RADIAL});
73
+ }
74
+ #endif
75
+ `;
76
+ /** Body of `cloudLight` with the cover by place: radial up reads the field, the planar code is today's. */
77
+ const CLOUD_LIGHT_FIELD = /* glsl */ `#ifdef WH_LOCAL_UP
78
+ whUpHere = localUp(worldPos);
79
+ return cloudFieldAt(whUpHere, u_upCenter.w).x;
80
+ #else
81
+ if (u_cloud.z <= 0.0) return 1.0;
82
+ vec2 q = (worldPos.xz - u_cloud.xy) * u_cloud.w;
83
+ float n = ${CLOUD_NOISE};
84
+ return 1.0 - u_cloud.z * smoothstep(u_cloudEdge.x, u_cloudEdge.y, n);
85
+ #endif`;
86
+ /**
87
+ * The shadow query include `<shadow>`: how much sun reaches a point (scene shadows from the shadow map times cloud
88
+ * shadows) and nothing of the light model. `cloudLight`, `sunVisibility` and `sunVisibilityBaked` (soft edge, as
89
+ * `<lighting>` always had them) and `sunVisibilitySharp` and `sunVisibilityBakedSharp` (one depth comparison at the
90
+ * centre of the shadow map texel: a hard, unsoftened edge). `<lighting>` contains the same text; both are guarded by
91
+ * `WH_SHADOW_QUERY`, so a material may include `<shadow>`, `<lighting>` or both in any order. `cloudField` as for
92
+ * `lightingGlsl`.
93
+ */
94
+ export function shadowGlsl(o = {}) {
95
+ const field = o.cloudField === true;
96
+ return /* glsl */ `
97
+ #ifndef WH_SHADOW_QUERY
98
+ #define WH_SHADOW_QUERY 1
99
+ uniform sampler2DShadow u_shadowMap;
100
+
101
+ #ifdef WH_LOCAL_UP
102
+ // Up at the point the lighting functions were last asked about. cloudLight, sunVisibility and sunVisibilityBaked set
103
+ // it from their position, so lightOn, called after one of them, lights for the same place; lightOnAt states the place.
104
+ vec3 whUpHere = vec3(0.0, 1.0, 0.0);
105
+ #endif
106
+ ${field ? CLOUD_FIELD_FUNCTIONS : ''}
107
+ // Cloud shadow: 1 = full sun, less under a cloud. The pattern is anchored in the world and drifts with the wind.
108
+ // Three layers of smooth noise, the smallest is tens of metres, so there is nothing to fight with even from afar.
109
+ float cloudLight(vec3 worldPos) {
110
+ ${field ? CLOUD_LIGHT_FIELD : CLOUD_LIGHT_GLOBAL}
111
+ }
112
+
113
+ // Share of sun that reaches a point: 0 = full shadow, 1 = full sun. Computes scene shadows and cloud shadows.
114
+ // The point is shifted along the normal before the query so a surface does not shadow itself.
115
+ float sunVisibility(vec3 worldPos, vec3 n, float normalOffsetTexels) {
116
+ float cloud = cloudLight(worldPos);
117
+ #ifdef WH_SHADOW_AREAS
118
+ // The renderer keeps shadow areas (its shadow mode is not the single map): its header brings the lookup.
119
+ return whShadow(u_shadowMap, worldPos, n, normalOffsetTexels, 1.0) * cloud;
120
+ #else
121
+ vec3 p = worldPos + n * (u_view.y * normalOffsetTexels);
122
+ vec3 sc = (u_lightViewProj * vec4(p, 1.0)).xyz * 0.5 + 0.5;
123
+ float lim = u_sunDir.w;
124
+ if (sc.x <= 0.0 || sc.x >= lim || sc.y <= 0.0 || sc.y >= lim || sc.z >= 1.0) return cloud;
125
+ float r = u_view.z * u_view.w;
126
+ float sum = 0.0;
127
+ // 4 × 4 queries, each bilinearly compares four texels by itself. Gives a smooth penumbra without graininess.
128
+ for (int j = 0; j < 4; j++) {
129
+ for (int i = 0; i < 4; i++) {
130
+ vec2 o = (vec2(float(i), float(j)) - 1.5) * r;
131
+ sum += texture(u_shadowMap, vec3(sc.xy + o, sc.z));
132
+ }
133
+ }
134
+ return sum * (1.0 / 16.0) * cloud;
135
+ #endif
136
+ }
137
+
138
+ // sunVisibility for a material that carries a shadow term of its own (baked: 0 = shadow, 1 = sun; from a vertex
139
+ // attribute or a texture of its piece of the scene). The term stands in where the shadow map does not reach: outside
140
+ // the single map, and beyond the reach of the shadow areas, into which it is blended.
141
+ float sunVisibilityBaked(vec3 worldPos, vec3 n, float normalOffsetTexels, float baked) {
142
+ float cloud = cloudLight(worldPos);
143
+ #ifdef WH_SHADOW_AREAS
144
+ return whShadow(u_shadowMap, worldPos, n, normalOffsetTexels, baked) * cloud;
145
+ #else
146
+ vec3 p = worldPos + n * (u_view.y * normalOffsetTexels);
147
+ vec3 sc = (u_lightViewProj * vec4(p, 1.0)).xyz * 0.5 + 0.5;
148
+ float lim = u_sunDir.w;
149
+ if (sc.x <= 0.0 || sc.x >= lim || sc.y <= 0.0 || sc.y >= lim || sc.z >= 1.0) return baked * cloud;
150
+ float r = u_view.z * u_view.w;
151
+ float sum = 0.0;
152
+ for (int j = 0; j < 4; j++) {
153
+ for (int i = 0; i < 4; i++) {
154
+ vec2 o = (vec2(float(i), float(j)) - 1.5) * r;
155
+ sum += texture(u_shadowMap, vec3(sc.xy + o, sc.z));
156
+ }
157
+ }
158
+ return sum * (1.0 / 16.0) * cloud;
159
+ #endif
160
+ }
161
+
162
+ // sunVisibilityBaked with a hard edge: one depth comparison at the centre of the shadow map texel under the point
163
+ // (with linear filtering a lookup there weighs that texel alone), no softening.
164
+ float sunVisibilityBakedSharp(vec3 worldPos, vec3 n, float normalOffsetTexels, float baked) {
165
+ float cloud = cloudLight(worldPos);
166
+ #ifdef WH_SHADOW_AREAS
167
+ return whShadowSharp(u_shadowMap, worldPos, n, normalOffsetTexels, baked) * cloud;
168
+ #else
169
+ vec3 p = worldPos + n * (u_view.y * normalOffsetTexels);
170
+ vec3 sc = (u_lightViewProj * vec4(p, 1.0)).xyz * 0.5 + 0.5;
171
+ float lim = u_sunDir.w;
172
+ if (sc.x <= 0.0 || sc.x >= lim || sc.y <= 0.0 || sc.y >= lim || sc.z >= 1.0) return baked * cloud;
173
+ vec2 uv = (floor(sc.xy / u_view.w) + 0.5) * u_view.w;
174
+ return texture(u_shadowMap, vec3(uv, sc.z)) * cloud;
175
+ #endif
176
+ }
177
+
178
+ // sunVisibility with a hard edge (see sunVisibilityBakedSharp).
179
+ float sunVisibilitySharp(vec3 worldPos, vec3 n, float normalOffsetTexels) {
180
+ return sunVisibilityBakedSharp(worldPos, n, normalOffsetTexels, 1.0);
181
+ }
182
+ #endif
183
+ `;
184
+ }
185
+ /** `<shadow>` without the cloud cover by place (see `shadowGlsl`). */
186
+ export const SHADOW_QUERY = shadowGlsl();
187
+ /**
188
+ * The lighting include. Without options it is `LIGHTING`. With `cloudField` (the block holds the slot
189
+ * `CLOUD_FIELD_SLOT`) radial up gains `cloudFieldCover` and `cloudFieldAt`, and `cloudLight` reads the cover by place.
190
+ * It begins with the shadow query (`shadowGlsl`, guarded so `<shadow>` may be included as well).
191
+ */
192
+ export function lightingGlsl(o = {}) {
193
+ return /* glsl */ `${shadowGlsl(o)}
194
+ // Light as a multiple of the surface colour: warm sun, cool shadow.
195
+ vec3 lightOn(vec3 n, float sun, float ao) {
196
+ float ndl = max(dot(n, u_sunDir.xyz), 0.0);
197
+ #ifdef WH_LOCAL_UP
198
+ // The sky is over the local horizon. Where the light stands under it the body itself is in the way: no sun, and
199
+ // only a rest of the sky's light.
200
+ float nu = dot(n, whUpHere);
201
+ float day = dot(whUpHere, u_sunDir.xyz);
202
+ vec3 fill = (u_ambient.rgb + u_skyFill.rgb * (nu * 0.5 + 0.5) + u_bounce.rgb * (1.0 - nu)) * mix(0.06, 1.0, smoothstep(-0.25, 0.15, day));
203
+ sun *= smoothstep(-0.05, 0.03, day);
204
+ #else
205
+ vec3 fill = u_ambient.rgb + u_skyFill.rgb * (n.y * 0.5 + 0.5) + u_bounce.rgb * (1.0 - n.y);
206
+ #endif
207
+ return u_sunColor.rgb * (ndl * sun) + fill * ao;
208
+ }
209
+
210
+ // lightOn for a stated place: the same without radial up, and with it independent of which function ran before.
211
+ vec3 lightOnAt(vec3 worldPos, vec3 n, float sun, float ao) {
212
+ #ifdef WH_LOCAL_UP
213
+ whUpHere = localUp(worldPos);
214
+ #endif
215
+ return lightOn(n, sun, ao);
216
+ }
217
+
218
+ // Fog and haze applied after the output curve. More at the valley floor, slow wisps drift with the clouds.
219
+ // Under an overcast sky the colours also fade a little.
220
+ vec3 applyFog(vec3 display, vec3 worldPos) {
221
+ float cc = u_snow.w;
222
+ display = mix(display, vec3(dot(display, vec3(0.3, 0.55, 0.15))), 0.28 * cc * cc);
223
+ float f = u_weather.z;
224
+ if (f <= 0.0) return display;
225
+ #ifdef WH_LOCAL_UP
226
+ // Heights of the fog layer are heights above the base surface; the wisps are a field in space.
227
+ float valley = 1.0 - clamp((localHeight(worldPos) - u_fogShape.x) * u_fogShape.y, 0.0, 1.0);
228
+ float drift = vnoise3((localUp(worldPos) * u_upCenter.w - vec3(u_cloud.x, 0.0, u_cloud.y) * 0.4) / 140.0, 81u);
229
+ #else
230
+ float valley = 1.0 - clamp((worldPos.y - u_fogShape.x) * u_fogShape.y, 0.0, 1.0);
231
+ float drift = vnoise((worldPos.xz - u_cloud.xy * 0.4) / 140.0, 81u);
232
+ #endif
233
+ float a = f * (0.5 + 0.38 * valley + 0.24 * (drift - 0.5));
234
+ return mix(display, u_fogColor.rgb, clamp(a, 0.0, 0.94));
235
+ }
236
+
237
+ // Output curve: unchanged up to the knee, above it brightness bends softly toward one so light surfaces do not blow out.
238
+ vec3 toDisplay(vec3 c) {
239
+ c *= u_warmTint.a;
240
+ const float knee = 0.8;
241
+ vec3 over = max(c - knee, 0.0) / (1.0 - knee);
242
+ return mix(c, knee + (1.0 - knee) * (1.0 - exp(-over)), step(knee, c));
243
+ }
244
+ `;
245
+ }
246
+ export const LIGHTING = lightingGlsl();
@@ -0,0 +1,13 @@
1
+ export { Environment, DEFAULT_STUDIO, DEFAULT_FIXED, DEFAULT_SITE, DEFAULT_DAY, DEFAULT_WIND, DEFAULT_CLOUDS, DEFAULT_WEATHER, DEFAULT_SNOW_ALBEDO, studioLightDirection, cloudCoverTerms, } from './environment.ts';
2
+ export { CLOUD_NOISE, CLOUD_NOISE_RADIAL, CLOUD_OCTAVES, LIGHTING, SHADOW_QUERY, lightingGlsl, shadowGlsl } from './glsl.ts';
3
+ export { CLOUD_FIELD_SLOT, cloudFieldCover, cloudFieldSlot, cloudFieldSun } from './cloud-field.ts';
4
+ export type { CloudCoverField, CloudFieldValues } from './cloud-field.ts';
5
+ export { DEFAULT_SKY, SKY_FALLBACK, SKY_GLSL, computeSky, skySlot } from './sky.ts';
6
+ export type { SkyParams, SkyValues } from './sky.ts';
7
+ export { ATMOSPHERE_FALLBACK, ATMOSPHERE_TABLE_LAYOUT, ATMOSPHERE_TABLE_UNIT, DEFAULT_ATMOSPHERE, DEFAULT_ATMOSPHERE_MEDIUM, atmosphereFor, atmosphereGlsl, atmosphereSlot, atmosphereTables, computeAtmosphere, } from './atmosphere.ts';
8
+ export type { AtmosphereMedium, AtmosphereParams, AtmosphereSlot, AtmosphereTables, AtmosphereValues } from './atmosphere.ts';
9
+ export { ENV_CORE_SLOT, assembleFrameBlock } from './frame-block.ts';
10
+ export type { EnvFrameBlock, FrameBlockValues, FrameRegions } from './frame-block.ts';
11
+ export type { CloudConfig, DayLight, EnvironmentConfig, FixedLight, StudioLight, SunObserver, WeatherState, WindConfig } from './environment.ts';
12
+ export { dayOfYear, skyDirection, sphereSunDirection, sunPosition } from './sun.ts';
13
+ export type { SunPosition, SunSite } from './sun.ts';
@@ -0,0 +1,9 @@
1
+ // Layer 5, env: time, sun and sky, light colours, fog, wind, clouds, precipitation, wetness and snow cover as frame
2
+ // parameters, and the assembly of environment slots into the Frame block.
3
+ export { Environment, DEFAULT_STUDIO, DEFAULT_FIXED, DEFAULT_SITE, DEFAULT_DAY, DEFAULT_WIND, DEFAULT_CLOUDS, DEFAULT_WEATHER, DEFAULT_SNOW_ALBEDO, studioLightDirection, cloudCoverTerms, } from './environment.js';
4
+ export { CLOUD_NOISE, CLOUD_NOISE_RADIAL, CLOUD_OCTAVES, LIGHTING, SHADOW_QUERY, lightingGlsl, shadowGlsl } from './glsl.js';
5
+ export { CLOUD_FIELD_SLOT, cloudFieldCover, cloudFieldSlot, cloudFieldSun } from './cloud-field.js';
6
+ export { DEFAULT_SKY, SKY_FALLBACK, SKY_GLSL, computeSky, skySlot } from './sky.js';
7
+ export { ATMOSPHERE_FALLBACK, ATMOSPHERE_TABLE_LAYOUT, ATMOSPHERE_TABLE_UNIT, DEFAULT_ATMOSPHERE, DEFAULT_ATMOSPHERE_MEDIUM, atmosphereFor, atmosphereGlsl, atmosphereSlot, atmosphereTables, computeAtmosphere, } from './atmosphere.js';
8
+ export { ENV_CORE_SLOT, assembleFrameBlock } from './frame-block.js';
9
+ export { dayOfYear, skyDirection, sphereSunDirection, sunPosition } from './sun.js';
@@ -0,0 +1,48 @@
1
+ import type { RGB, Vec3 } from '../base/math.ts';
2
+ import type { EnvSlot, FrameEnvironment } from '../base/env-slot.ts';
3
+ export interface SkyParams {
4
+ /**
5
+ * Distance in metres at which distant geometry has faded about two thirds of the way into the sky colour behind it
6
+ * (perspective views only). The fade grows with the square of the distance, so near things barely change. 0 turns it off.
7
+ */
8
+ hazeDistanceM: number;
9
+ /** How much fog (0–1) and precipitation (0–1) shorten the haze distance at full strength. */
10
+ fogHaze: number;
11
+ precipitationHaze: number;
12
+ /** Height of the cloud deck in world units. */
13
+ cloudHeightM: number;
14
+ /** Clouds sink into the horizon haze at this many cloud heights of distance along the view ray. */
15
+ cloudFadeHeights: number;
16
+ /** Eye of the current view, or null for a view without one (orthographic). The sky layer sets it every frame. */
17
+ eye: Vec3 | null;
18
+ }
19
+ export declare const DEFAULT_SKY: Omit<SkyParams, 'eye'>;
20
+ /** What the sky slot computes for one frame. */
21
+ export interface SkyValues {
22
+ zenith: RGB;
23
+ horizon: RGB;
24
+ glow: RGB;
25
+ sunDir: Vec3;
26
+ moonDir: Vec3;
27
+ /** Colour of the sunlit side of a cloud. */
28
+ cloud: RGB;
29
+ /** 0–1: stars, sun disc, moon disc, continuous overcast deck. */
30
+ stars: number;
31
+ sunDisc: number;
32
+ moon: number;
33
+ overcast: number;
34
+ /** 1 / haze distance in metres, 0 = no haze. */
35
+ invHaze: number;
36
+ cloudHeightM: number;
37
+ cloudFadeM: number;
38
+ eye: Vec3;
39
+ perspective: number;
40
+ }
41
+ /** Pure: the sky's values from the generic environment and the params. */
42
+ export declare function computeSky(E: FrameEnvironment, p: SkyParams): SkyValues;
43
+ /** GLSL of the slot, registered as `<sky>`. Needs `<header>` and `<noise>` before it. */
44
+ export declare const SKY_GLSL: string;
45
+ /** Same functions as `SKY_GLSL` without the sky slot: no haze, the fog colour as the sky. Registered as `<sky>`. */
46
+ export declare const SKY_FALLBACK = "\nvec3 skyToEye(vec3 worldPos) { return -u_camForward.xyz; }\nvec3 skyColorDir(vec3 dir) { return u_fogColor.rgb; }\nvec3 aerialPerspective(vec3 display, vec3 worldPos) { return display; }\n";
47
+ /** The sky slot. Pass it in the engine's slots (or use `createEngine({ sky: true })`, which also adds the layer). */
48
+ export declare function skySlot(params?: Partial<SkyParams>): EnvSlot<SkyParams, SkyValues>;
@@ -0,0 +1,227 @@
1
+ // The sky as seen from a perspective view, as an environment slot: gradient from horizon to zenith, the glow around
2
+ // the sun, sun and moon discs, stars and the same clouds that cast the cloud shadows on the ground. Colours come from
3
+ // the environment (`FrameEnvironment.skyZenith`, `skyHorizon`, `sunGlow`), so the sky moves with the light on the
4
+ // scene. The slot also carries the haze that fades distant geometry into the sky (`aerialPerspective`).
5
+ //
6
+ // The slot's GLSL is registered as the include `<sky>`. Without the slot, `EnvironmentLink` registers `SKY_FALLBACK`
7
+ // under the same name: the same functions, with no haze, so materials may call them in any view.
8
+ import { clamp, smoothstep } from '../base/math.js';
9
+ import { CLOUD_OCTAVES } from './glsl.js';
10
+ export const DEFAULT_SKY = {
11
+ hazeDistanceM: 1400,
12
+ fogHaze: 0.8,
13
+ precipitationHaze: 0.35,
14
+ cloudHeightM: 1200,
15
+ cloudFadeHeights: 70,
16
+ };
17
+ // Sun heights (degrees) between which the stars come out: fully below the first, none above the second.
18
+ const STARS_FULL_DEG = -14;
19
+ const STARS_OFF_DEG = -4;
20
+ // Same day/night transition as the environment's light (DAY_FROM/DAY_TO).
21
+ const DAY_FROM = -6;
22
+ const DAY_TO = 6;
23
+ // Cloud cover between which the sky closes into a continuous deck. A little before the light goes fully diffuse
24
+ // (the environment's OVERCAST_FROM = 0.55 to 1): rain and snow skies should read as closed.
25
+ const DECK_FROM = 0.45;
26
+ const DECK_TO = 0.78;
27
+ function luma(c) {
28
+ return 0.3 * c[0] + 0.59 * c[1] + 0.11 * c[2];
29
+ }
30
+ /** Pure: the sky's values from the generic environment and the params. */
31
+ export function computeSky(E, p) {
32
+ const dayMode = E.mode === 'day';
33
+ const e = E.sunElevationDeg;
34
+ const daylight = dayMode ? smoothstep(DAY_FROM, DAY_TO, e) : 1;
35
+ const overcast = smoothstep(DECK_FROM, DECK_TO, E.cloudCover);
36
+ const clear = (1 - overcast) * (1 - 0.85 * E.fog);
37
+ // The lit side of a cloud: the horizon's light, whitened as bright as the horizon is, plus the sun's glow.
38
+ const h = E.skyHorizon;
39
+ const white = luma(h) * 1.3;
40
+ const cloud = [h[0] * 0.4 + white * 0.6 + E.sunGlow[0] * 0.5, h[1] * 0.4 + white * 0.6 + E.sunGlow[1] * 0.5, h[2] * 0.4 + white * 0.6 + E.sunGlow[2] * 0.5];
41
+ const hazeM = p.hazeDistanceM * (1 - p.fogHaze * clamp(E.fog, 0, 1)) * (1 - p.precipitationHaze * clamp(E.precipitation, 0, 1));
42
+ return {
43
+ zenith: E.skyZenith,
44
+ horizon: E.skyHorizon,
45
+ glow: E.sunGlow,
46
+ sunDir: E.sunDir,
47
+ moonDir: E.moonDir,
48
+ cloud,
49
+ stars: dayMode ? (1 - smoothstep(STARS_FULL_DEG, STARS_OFF_DEG, e)) * clear : 0,
50
+ sunDisc: (1 - 0.95 * overcast) * (1 - 0.85 * E.fog),
51
+ moon: dayMode ? (1 - 0.8 * daylight) * clear : 0,
52
+ overcast,
53
+ invHaze: p.eye && hazeM > 0 ? 1 / hazeM : 0,
54
+ cloudHeightM: p.cloudHeightM,
55
+ cloudFadeM: p.cloudHeightM * p.cloudFadeHeights,
56
+ eye: p.eye ?? [0, 0, 0],
57
+ perspective: p.eye ? 1 : 0,
58
+ };
59
+ }
60
+ /** Cloud field with per-octave fading: an octave whose cells shrink toward a pixel gives way to its mean, so far
61
+ * clouds near the horizon do not shimmer. With `fw = 0` it is exactly the field of the ground's cloud shadows. */
62
+ const CLOUD_FIELD_AA = CLOUD_OCTAVES.map(([w, f, o, seed]) => `${w} * mix(0.5, vnoise(q * ${f} + ${o}, ${seed}u), 1.0 - smoothstep(0.3, 0.7, fw * ${f}))`).join('\n + ');
63
+ /** GLSL of the slot, registered as `<sky>`. Needs `<header>` and `<noise>` before it. */
64
+ export const SKY_GLSL = /* glsl */ `
65
+ float skyCloudField(vec2 q, float fw) {
66
+ return ${CLOUD_FIELD_AA};
67
+ }
68
+
69
+ // Unit direction from a world point toward the eye.
70
+ vec3 skyToEye(vec3 worldPos) {
71
+ return u_skyEye.w > 0.5 ? normalize(u_skyEye.xyz - worldPos) : -u_camForward.xyz;
72
+ }
73
+
74
+ // Sky colour in a direction, screen space: the gradient and the glow around the sun, no discs, clouds or stars.
75
+ // Below the horizon it stays as at the horizon, so haze and sky meet without a seam.
76
+ vec3 skyColorDir(vec3 dir) {
77
+ float y = max(dir.y, 0.0);
78
+ float t = (1.0 - exp(-4.0 * y)) * (1.0 / (1.0 - exp(-4.0)));
79
+ vec3 c = mix(u_skyHorizon.rgb, u_skyZenith.rgb, t);
80
+ vec3 s = u_skySun.xyz;
81
+ float mu = max(dot(normalize(vec3(dir.x, y, dir.z)), s), 0.0);
82
+ float mu2 = mu * mu, mu4 = mu2 * mu2, mu8 = mu4 * mu4, mu32 = mu8 * mu8 * mu8 * mu8;
83
+ // A band of light along the horizon toward the sun, widest at sunset.
84
+ vec2 hz = dir.xz / max(length(dir.xz), 1e-4);
85
+ vec2 hs = s.xz / max(length(s.xz), 1e-4);
86
+ float toward = 0.5 + 0.5 * dot(hz, hs);
87
+ float band = toward * toward * toward * (1.0 - smoothstep(0.0, 0.35, y));
88
+ return c + u_skyGlow.rgb * (0.18 * mu4 + 0.45 * mu32 + 0.4 * band);
89
+ }
90
+
91
+ // Distant geometry fades into the sky behind it. Screen-space colour in, screen-space colour out.
92
+ // Off (identity) without a perspective view or with the haze switched off.
93
+ vec3 aerialPerspective(vec3 display, vec3 worldPos) {
94
+ if (u_skyHorizon.w <= 0.0) return display;
95
+ vec3 v = worldPos - u_skyEye.xyz;
96
+ float len = max(length(v), 1e-3);
97
+ float k = len * u_skyHorizon.w;
98
+ return mix(display, skyColorDir(v / len), 1.0 - exp(-k * k));
99
+ }
100
+
101
+ // Clouds along a view direction: rgb colour, a coverage. The deck is a plane at u_skySun.w; the field is looked up
102
+ // where the light (u_sunDir, the same direction that casts the scene's shadows) throws this cloud's shadow on the
103
+ // ground, so the clouds overhead and their shadows agree.
104
+ vec4 skyClouds(vec3 dir) {
105
+ // No early return: fwidth below needs every pixel of the quad.
106
+ float t = max(u_skySun.w - u_skyEye.y, 1.0) / max(dir.y, 1e-3);
107
+ vec3 hit = u_skyEye.xyz + dir * t;
108
+ vec3 L = u_sunDir.xyz;
109
+ vec2 ground = hit.xz - L.xz * (u_skySun.w / max(L.y, 0.05));
110
+ vec2 q = (ground - u_cloud.xy) * u_cloud.w;
111
+ float fw = length(fwidth(q));
112
+ float n = skyCloudField(q, fw);
113
+ float edge = 0.5 * fw;
114
+ float cover = smoothstep(u_cloudEdge.x - edge, u_cloudEdge.y + edge, n) * smoothstep(0.0, 0.04, u_snow.w);
115
+ float thick = smoothstep(u_cloudEdge.x, u_cloudEdge.x + 0.45, n);
116
+ float overcast = u_skyCloud.w;
117
+ vec3 lit = u_skyCloud.rgb;
118
+ vec3 col = lit * mix(1.0, 0.7, thick);
119
+ // Thin edges toward the sun light up.
120
+ float mu = max(dot(dir, u_skySun.xyz), 0.0);
121
+ float mu2 = mu * mu, mu4 = mu2 * mu2;
122
+ col += u_skyGlow.rgb * mu4 * mu4 * (1.0 - thick) * 1.4;
123
+ // The continuous deck of an overcast sky: an even grey a little darker than the lit cloud.
124
+ col = mix(col, lit * 0.74, overcast * (1.0 - cover));
125
+ // Fog veils the clouds too.
126
+ float a = max(cover, overcast) * (1.0 - 0.75 * u_weather.z) * step(0.0, dir.y);
127
+ // Far clouds sink into the horizon haze.
128
+ float far = t / u_skyFade.x;
129
+ return vec4(mix(col, skyColorDir(dir), 1.0 - exp(-far * far)), a);
130
+ }
131
+
132
+ // Stars: at most one per cell of a cube-map grid over the directions, from an integer hash. Fixed in the world, so
133
+ // they hold still when the view turns; never narrower than a pixel, so they do not flicker.
134
+ float skyStars(vec3 dir, float pixelAngle) {
135
+ vec3 a = abs(dir);
136
+ vec2 uv;
137
+ uint face;
138
+ float major;
139
+ if (a.x >= a.y && a.x >= a.z) { uv = dir.zy / a.x; face = dir.x > 0.0 ? 0u : 1u; major = a.x; }
140
+ else if (a.y >= a.z) { uv = dir.xz / a.y; face = dir.y > 0.0 ? 2u : 3u; major = a.y; }
141
+ else { uv = dir.xy / a.z; face = dir.z > 0.0 ? 4u : 5u; major = a.z; }
142
+ const float CELLS = 160.0;
143
+ vec2 g = (uv * 0.5 + 0.5) * CELLS;
144
+ vec2 cf = floor(g);
145
+ ivec2 cell = ivec2(cf);
146
+ uint seed = 400u + face * 8u;
147
+ if (hash2(cell, seed) > 0.3) return 0.0;
148
+ vec2 at = 0.2 + 0.6 * vec2(hash2(cell, seed + 1u), hash2(cell, seed + 2u));
149
+ float m = hash2(cell, seed + 3u);
150
+ float bright = 0.12 + 0.88 * m * m * m * m;
151
+ float px = pixelAngle * CELLS * 0.5 / major;
152
+ float r = max(0.8 * px, 0.01);
153
+ vec2 off = g - cf - at;
154
+ return bright * exp(-dot(off, off) / (r * r));
155
+ }
156
+
157
+ // The whole sky in a direction, screen space: gradient and glow, stars, moon, sun and clouds.
158
+ vec3 skyView(vec3 dir) {
159
+ float pa = max(length(fwidth(dir)), 1e-5);
160
+ vec3 c = skyColorDir(dir);
161
+ float up = smoothstep(-0.5 * pa, 0.5 * pa, dir.y);
162
+ c += vec3(0.88, 0.92, 1.0) * skyStars(dir, pa) * u_skyZenith.w * smoothstep(0.02, 0.25, dir.y);
163
+ // Moon: a mottled disc and a faint halo.
164
+ vec3 m = u_skyMoon.xyz;
165
+ float rm = 0.014;
166
+ float dm = length(dir - m);
167
+ vec3 t1 = normalize(cross(m, vec3(0.0, 1.0, 0.0)) + vec3(1e-5, 0.0, 0.0));
168
+ vec3 t2 = cross(t1, m);
169
+ vec2 lm = vec2(dot(dir - m, t1), dot(dir - m, t2)) / rm;
170
+ float mott = 0.8 + 0.2 * vnoise(lm * 2.2 + 5.0, 92u);
171
+ float disc = (1.0 - smoothstep(rm - pa, rm + pa, dm)) * up * u_skyMoon.w;
172
+ c = mix(c, vec3(0.9, 0.91, 0.94) * mott, disc);
173
+ c += vec3(0.1, 0.12, 0.16) * u_skyMoon.w * up * exp(-dm * dm * (1.0 / 0.004));
174
+ // Sun: a bright disc tinted by the glow, the warmer the lower it stands.
175
+ vec3 s = u_skySun.xyz;
176
+ float rs = 0.012;
177
+ float ds = length(dir - s);
178
+ float sun = (1.0 - smoothstep(rs - pa, rs + pa, ds)) * up * u_skyGlow.w;
179
+ vec3 sunCol = min(vec3(1.0, 0.96, 0.88) + u_skyGlow.rgb * 1.2, vec3(1.0));
180
+ c = mix(c, sunCol, sun);
181
+ c += u_skyGlow.rgb * u_skyGlow.w * up * 0.35 * exp(-ds * ds * (1.0 / 0.0008));
182
+ vec4 cl = skyClouds(dir);
183
+ return mix(c, cl.rgb, cl.a);
184
+ }
185
+ `;
186
+ /** Same functions as `SKY_GLSL` without the sky slot: no haze, the fog colour as the sky. Registered as `<sky>`. */
187
+ export const SKY_FALLBACK = /* glsl */ `
188
+ vec3 skyToEye(vec3 worldPos) { return -u_camForward.xyz; }
189
+ vec3 skyColorDir(vec3 dir) { return u_fogColor.rgb; }
190
+ vec3 aerialPerspective(vec3 display, vec3 worldPos) { return display; }
191
+ `;
192
+ /** The sky slot. Pass it in the engine's slots (or use `createEngine({ sky: true })`, which also adds the layer). */
193
+ export function skySlot(params = {}) {
194
+ return {
195
+ name: 'sky',
196
+ params: { ...DEFAULT_SKY, eye: null, ...params },
197
+ fields: [
198
+ { member: 'u_skyZenith', order: 1000, lanes: 'xyzw', doc: 'rgb sky straight up, w star visibility 0–1' },
199
+ { member: 'u_skyHorizon', order: 1010, lanes: 'xyzw', doc: 'rgb sky at the horizon, w 1 / haze distance (0 off)' },
200
+ { member: 'u_skyGlow', order: 1020, lanes: 'xyzw', doc: 'rgb glow around the sun, w sun disc visibility 0–1' },
201
+ { member: 'u_skySun', order: 1030, lanes: 'xyzw', doc: 'xyz true direction to the sun, w cloud deck height' },
202
+ { member: 'u_skyMoon', order: 1040, lanes: 'xyzw', doc: 'xyz direction to the moon, w moon visibility 0–1' },
203
+ { member: 'u_skyCloud', order: 1050, lanes: 'xyzw', doc: 'rgb sunlit cloud colour, w overcast deck 0–1' },
204
+ { member: 'u_skyEye', order: 1060, lanes: 'xyzw', doc: 'xyz eye, w 1 perspective, 0 none' },
205
+ { member: 'u_skyFade', order: 1070, lanes: 'x', doc: 'x distance at which clouds sink into the horizon' },
206
+ ],
207
+ compute: computeSky,
208
+ lanes: (v) => [
209
+ ...v.zenith,
210
+ v.stars,
211
+ ...v.horizon,
212
+ v.invHaze,
213
+ ...v.glow,
214
+ v.sunDisc,
215
+ ...v.sunDir,
216
+ v.cloudHeightM,
217
+ ...v.moonDir,
218
+ v.moon,
219
+ ...v.cloud,
220
+ v.overcast,
221
+ ...v.eye,
222
+ v.perspective,
223
+ v.cloudFadeM,
224
+ ],
225
+ glsl: SKY_GLSL,
226
+ };
227
+ }
@@ -0,0 +1,31 @@
1
+ import type { Vec3 } from '../base/math.ts';
2
+ export interface SunSite {
3
+ /** Latitude, positive north. */
4
+ latitudeDeg: number;
5
+ /** Longitude, positive east. */
6
+ longitudeDeg: number;
7
+ /** Day of year, 1 = 1 January. The summer solstice is around 172, the equinoxes 80 and 266. */
8
+ dayOfYear: number;
9
+ /** Civil time offset from UTC in hours (Central European summer time: 2). */
10
+ utcOffsetHours: number;
11
+ }
12
+ export interface SunPosition {
13
+ /** Azimuth from north clockwise, in degrees. 180 = due south. */
14
+ azimuthDeg: number;
15
+ /** Height above the horizon in degrees, negative below the horizon. */
16
+ elevationDeg: number;
17
+ }
18
+ /** Where the sun is at a given hour of civil time (0–24). */
19
+ export declare function sunPosition(site: SunSite, hour: number): SunPosition;
20
+ /** Unit direction toward the light in the world, where x points east, y up and z south. */
21
+ export declare function skyDirection(azimuthDeg: number, elevationDeg: number): Vec3;
22
+ /**
23
+ * Unit direction to the sun in the axes of a sphere that turns about +y (its north) once a day, at an hour of
24
+ * universal time: the sun stands straight over the latitude of its declination and over a longitude that moves a full
25
+ * turn against the sphere's spin in 24 hours. Longitude 0 points along +x and grows toward +z, so a place at latitude
26
+ * φ and longitude λ has the up [cos φ cos λ, sin φ, cos φ sin λ]. With that place as a `SunSite` (offset 0),
27
+ * `sunPosition` gives the same height of the sun as this direction does against that up.
28
+ */
29
+ export declare function sphereSunDirection(dayOfYear: number, utcHour: number): Vec3;
30
+ /** Day of year from month (1–12) and day of month, for a non-leap year. */
31
+ export declare function dayOfYear(month: number, day: number): number;
@@ -0,0 +1,42 @@
1
+ // Sun position in the sky from place, date and hour. Common formulas are enough (declination and equation of time
2
+ // from a Fourier series), a fraction-of-a-degree accuracy is more than enough for shadows.
3
+ import { DEG } from '../base/math.js';
4
+ /** Where the sun is at a given hour of civil time (0–24). */
5
+ export function sunPosition(site, hour) {
6
+ const g = ((2 * Math.PI) / 365) * (site.dayOfYear - 1 + (hour - 12) / 24);
7
+ const eqTimeMin = 229.18 * (0.000075 + 0.001868 * Math.cos(g) - 0.032077 * Math.sin(g) - 0.014615 * Math.cos(2 * g) - 0.040849 * Math.sin(2 * g));
8
+ const decl = 0.006918 - 0.399912 * Math.cos(g) + 0.070257 * Math.sin(g) - 0.006758 * Math.cos(2 * g) + 0.000907 * Math.sin(2 * g) - 0.002697 * Math.cos(3 * g) + 0.00148 * Math.sin(3 * g);
9
+ const solarMin = hour * 60 + eqTimeMin + 4 * site.longitudeDeg - 60 * site.utcOffsetHours;
10
+ const hourAngle = (solarMin / 4 - 180) * DEG;
11
+ const lat = site.latitudeDeg * DEG;
12
+ const sinEl = Math.sin(lat) * Math.sin(decl) + Math.cos(lat) * Math.cos(decl) * Math.cos(hourAngle);
13
+ const elevation = Math.asin(Math.min(1, Math.max(-1, sinEl)));
14
+ const azimuth = Math.atan2(Math.sin(hourAngle), Math.cos(hourAngle) * Math.sin(lat) - Math.tan(decl) * Math.cos(lat)) + Math.PI;
15
+ return { azimuthDeg: (((azimuth / DEG) % 360) + 360) % 360, elevationDeg: elevation / DEG };
16
+ }
17
+ /** Unit direction toward the light in the world, where x points east, y up and z south. */
18
+ export function skyDirection(azimuthDeg, elevationDeg) {
19
+ const a = azimuthDeg * DEG;
20
+ const e = elevationDeg * DEG;
21
+ return [Math.sin(a) * Math.cos(e), Math.sin(e), -Math.cos(a) * Math.cos(e)];
22
+ }
23
+ /**
24
+ * Unit direction to the sun in the axes of a sphere that turns about +y (its north) once a day, at an hour of
25
+ * universal time: the sun stands straight over the latitude of its declination and over a longitude that moves a full
26
+ * turn against the sphere's spin in 24 hours. Longitude 0 points along +x and grows toward +z, so a place at latitude
27
+ * φ and longitude λ has the up [cos φ cos λ, sin φ, cos φ sin λ]. With that place as a `SunSite` (offset 0),
28
+ * `sunPosition` gives the same height of the sun as this direction does against that up.
29
+ */
30
+ export function sphereSunDirection(dayOfYear, utcHour) {
31
+ const g = ((2 * Math.PI) / 365) * (dayOfYear - 1 + (utcHour - 12) / 24);
32
+ const eqTimeMin = 229.18 * (0.000075 + 0.001868 * Math.cos(g) - 0.032077 * Math.sin(g) - 0.014615 * Math.cos(2 * g) - 0.040849 * Math.sin(2 * g));
33
+ const decl = 0.006918 - 0.399912 * Math.cos(g) + 0.070257 * Math.sin(g) - 0.006758 * Math.cos(2 * g) + 0.000907 * Math.sin(2 * g) - 0.002697 * Math.cos(3 * g) + 0.00148 * Math.sin(3 * g);
34
+ // Longitude where the solar time is noon.
35
+ const lon = ((720 - utcHour * 60 - eqTimeMin) / 4) * DEG;
36
+ return [Math.cos(decl) * Math.cos(lon), Math.sin(decl), Math.cos(decl) * Math.sin(lon)];
37
+ }
38
+ /** Day of year from month (1–12) and day of month, for a non-leap year. */
39
+ export function dayOfYear(month, day) {
40
+ const before = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
41
+ return (before[Math.min(12, Math.max(1, Math.round(month))) - 1] ?? 0) + day;
42
+ }
@@ -0,0 +1,17 @@
1
+ import type { PropBox } from '../gen-mesh/index.ts';
2
+ import type { MeshData, StructureDesc } from '../base/index.ts';
3
+ import type { BuildingMeshStats, BuildingSpec, StructureOptions } from './structure/buildings.ts';
4
+ import type { ArchMeshDims } from './structure/dims.ts';
5
+ import type { InteriorPlan } from './interior/interior-plan.ts';
6
+ /**
7
+ * Builds one mesh for all buildings. `groundAt` returns the terrain height; it gives the height above ground
8
+ * (darkening at the wall foot), places steps and checks that walls reach into the ground.
9
+ */
10
+ export declare function buildBuildingMesh(specs: BuildingSpec[], props: PropBox[], groundAt: (x: number, z: number) => number, dims: ArchMeshDims, options?: StructureOptions): {
11
+ mesh: MeshData;
12
+ stats: BuildingMeshStats;
13
+ anchored: PropBox[];
14
+ structures: StructureDesc[];
15
+ spans: Uint32Array;
16
+ interiors: Map<number, InteriorPlan>;
17
+ };