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,49 @@
1
+ import type { OrthoFrame, Vec3 } from '../base/math.ts';
2
+ /** Blocks along the edge of an area. */
3
+ export declare const AREA_BLOCKS = 16;
4
+ /**
5
+ * Blocks from the focus that an area covers whatever its position on the grid: half its edge, less the slack that
6
+ * lets the focus move without the area following at once.
7
+ */
8
+ export declare const AREA_REACH_BLOCKS = 7;
9
+ /** One shadow area: where it lies on the block grid and where its first block is kept in its part of the map. */
10
+ export interface ShadowArea {
11
+ /** Edge of a block in metres. 0: not placed yet. */
12
+ blockM: number;
13
+ /** The area's first block along the light plane's two axes, counted from the world origin. */
14
+ bx: number;
15
+ by: number;
16
+ /** Block of its part of the map that holds the area's first block (0 unless the map is addressed around its edges). */
17
+ startX: number;
18
+ startY: number;
19
+ }
20
+ /** A rectangle of an area to draw: blocks relative to the area's first block, and the block of the map part it starts at. */
21
+ export interface AreaRect {
22
+ x0: number;
23
+ y0: number;
24
+ x1: number;
25
+ y1: number;
26
+ tx: number;
27
+ ty: number;
28
+ }
29
+ export declare function newShadowArea(): ShadowArea;
30
+ /**
31
+ * Axes of the light's plane for a unit direction toward the light. Fixed to the world and well defined for every
32
+ * direction, straight above included (there the plane's second axis is taken from z instead of y).
33
+ */
34
+ export declare function lightFrame(toLight: Vec3): OrthoFrame;
35
+ /**
36
+ * Moves an area to follow the focus (`fx`, `fy`: its coordinates in the light's plane, metres from the world origin)
37
+ * with blocks of `blockM`, and returns the rectangles of it that must be drawn: none while the focus stays within the
38
+ * middle of the area, the newly covered blocks after a step, all of it when `redraw` is set, the block size changed or
39
+ * the step is as long as the area. `around`: the area's part of the map is addressed around its edges, so a step
40
+ * keeps what it still covers; without it every step draws the whole area.
41
+ */
42
+ export declare function followFocus(a: ShadowArea, fx: number, fy: number, blockM: number, redraw: boolean, around: boolean): AreaRect[];
43
+ /**
44
+ * Block sizes of a single area that follows the scale of the view: the ladder `baseBlockM × 2^(k/2)`, k = 0 … `top`.
45
+ * Returns the step for a view whose half extent around the focus is `halfSpanM`, of which the area must cover
46
+ * `shownShare` of its reach without fading. `current` (−1: none yet) is kept while it still fits and is not more
47
+ * than one step too coarse, so a zoom resting on a border does not switch back and forth.
48
+ */
49
+ export declare function ladderStep(halfSpanM: number, baseBlockM: number, top: number, shownShare: number, current: number): number;
@@ -0,0 +1,125 @@
1
+ // Placement of shadow areas: pure arithmetic, no GPU. A shadow area is a square of the light's plane kept in the shadow
2
+ // map. It is divided into blocks and lies on the world's block grid, so its texels never move against the world, and it
3
+ // follows a focus point in whole blocks only: while the focus stays within the middle of the area nothing has to be
4
+ // redrawn, and when the area steps, only the blocks it newly covers do. With a single area the map is addressed
5
+ // around its edges (a texel's place is its world texel number modulo the map size), so a step leaves every kept texel
6
+ // where it is.
7
+ import { cross, normalize } from '../base/math.js';
8
+ /** Blocks along the edge of an area. */
9
+ export const AREA_BLOCKS = 16;
10
+ /**
11
+ * Blocks from the focus that an area covers whatever its position on the grid: half its edge, less the slack that
12
+ * lets the focus move without the area following at once.
13
+ */
14
+ export const AREA_REACH_BLOCKS = 7;
15
+ /** The area follows the focus only when it is this many blocks beyond the middle block (so a focus resting on a block border does not make the area step back and forth). */
16
+ const STEP_SLACK_BLOCKS = 0.25;
17
+ export function newShadowArea() {
18
+ return { blockM: 0, bx: 0, by: 0, startX: 0, startY: 0 };
19
+ }
20
+ /**
21
+ * Axes of the light's plane for a unit direction toward the light. Fixed to the world and well defined for every
22
+ * direction, straight above included (there the plane's second axis is taken from z instead of y).
23
+ */
24
+ export function lightFrame(toLight) {
25
+ const forward = [-toLight[0], -toLight[1], -toLight[2]];
26
+ const ref = Math.abs(forward[1]) < 0.99 ? [0, 1, 0] : [0, 0, 1];
27
+ const right = normalize(cross(forward, ref));
28
+ const up = cross(right, forward);
29
+ return { right, up, forward };
30
+ }
31
+ /** The first block of an area centred on a coordinate of the light's plane (metres from the world origin). */
32
+ function centred(coord, blockM) {
33
+ return Math.round(coord / blockM) - AREA_BLOCKS / 2;
34
+ }
35
+ /** Whether the focus coordinate is still within the middle of an area that starts at block `first`. */
36
+ function holds(coord, blockM, first) {
37
+ return Math.abs(coord / blockM - (first + AREA_BLOCKS / 2)) <= 0.5 + STEP_SLACK_BLOCKS;
38
+ }
39
+ const mod = (a, n) => ((a % n) + n) % n;
40
+ /** Splits blocks [a0, a1) of an area whose first block is kept at block `start` of the map part where the address wraps around. */
41
+ function wrapped(a0, a1, start) {
42
+ if (a1 <= a0)
43
+ return [];
44
+ const at = mod(start + a0, AREA_BLOCKS);
45
+ const room = AREA_BLOCKS - at;
46
+ if (a1 - a0 <= room)
47
+ return [[a0, a1, at]];
48
+ return [
49
+ [a0, a0 + room, at],
50
+ [a0 + room, a1, 0],
51
+ ];
52
+ }
53
+ function rects(x0, x1, y0, y1, a) {
54
+ const out = [];
55
+ for (const [bx0, bx1, tx] of wrapped(x0, x1, a.startX))
56
+ for (const [by0, by1, ty] of wrapped(y0, y1, a.startY))
57
+ out.push({ x0: bx0, y0: by0, x1: bx1, y1: by1, tx, ty });
58
+ return out;
59
+ }
60
+ /**
61
+ * Moves an area to follow the focus (`fx`, `fy`: its coordinates in the light's plane, metres from the world origin)
62
+ * with blocks of `blockM`, and returns the rectangles of it that must be drawn: none while the focus stays within the
63
+ * middle of the area, the newly covered blocks after a step, all of it when `redraw` is set, the block size changed or
64
+ * the step is as long as the area. `around`: the area's part of the map is addressed around its edges, so a step
65
+ * keeps what it still covers; without it every step draws the whole area.
66
+ */
67
+ export function followFocus(a, fx, fy, blockM, redraw, around) {
68
+ const N = AREA_BLOCKS;
69
+ if (redraw || a.blockM !== blockM) {
70
+ a.blockM = blockM;
71
+ a.bx = centred(fx, blockM);
72
+ a.by = centred(fy, blockM);
73
+ a.startX = 0;
74
+ a.startY = 0;
75
+ return rects(0, N, 0, N, a);
76
+ }
77
+ const bx = holds(fx, blockM, a.bx) ? a.bx : centred(fx, blockM);
78
+ const by = holds(fy, blockM, a.by) ? a.by : centred(fy, blockM);
79
+ const dx = bx - a.bx;
80
+ const dy = by - a.by;
81
+ if (dx === 0 && dy === 0)
82
+ return [];
83
+ a.bx = bx;
84
+ a.by = by;
85
+ if (!around || Math.abs(dx) >= N || Math.abs(dy) >= N) {
86
+ a.startX = 0;
87
+ a.startY = 0;
88
+ return rects(0, N, 0, N, a);
89
+ }
90
+ a.startX = mod(a.startX + dx, N);
91
+ a.startY = mod(a.startY + dy, N);
92
+ // The strip the step along the first axis uncovered, over the whole height; then the strip of the other axis over
93
+ // the columns that are left.
94
+ const out = [];
95
+ const keepX0 = dx < 0 ? -dx : 0;
96
+ const keepX1 = dx > 0 ? N - dx : N;
97
+ if (dx > 0)
98
+ out.push(...rects(N - dx, N, 0, N, a));
99
+ else if (dx < 0)
100
+ out.push(...rects(0, -dx, 0, N, a));
101
+ if (dy > 0)
102
+ out.push(...rects(keepX0, keepX1, N - dy, N, a));
103
+ else if (dy < 0)
104
+ out.push(...rects(keepX0, keepX1, 0, -dy, a));
105
+ return out;
106
+ }
107
+ /**
108
+ * Block sizes of a single area that follows the scale of the view: the ladder `baseBlockM × 2^(k/2)`, k = 0 … `top`.
109
+ * Returns the step for a view whose half extent around the focus is `halfSpanM`, of which the area must cover
110
+ * `shownShare` of its reach without fading. `current` (−1: none yet) is kept while it still fits and is not more
111
+ * than one step too coarse, so a zoom resting on a border does not switch back and forth.
112
+ */
113
+ export function ladderStep(halfSpanM, baseBlockM, top, shownShare, current) {
114
+ const fit = (half) => {
115
+ let k = 0;
116
+ while (k < top && baseBlockM * 2 ** (k / 2) * AREA_REACH_BLOCKS * shownShare < half)
117
+ k++;
118
+ return k;
119
+ };
120
+ const needed = fit(halfSpanM);
121
+ if (current < 0 || current < needed)
122
+ return needed;
123
+ const relaxed = fit(halfSpanM * 1.3);
124
+ return current > relaxed ? relaxed : current;
125
+ }
@@ -0,0 +1,12 @@
1
+ export declare const DEPTH_VS: string;
2
+ export declare const DEPTH_FS = "#version 300 es\nprecision highp float;\nvoid main() {}";
3
+ /** The most areas one shadow map holds (a 2 × 2 grid of parts). */
4
+ export declare const SHADOW_AREAS_MAX = 4;
5
+ /** Texture unit of the light horizon texture (`Renderer.shadowHorizon`), far above the units layers bind. */
6
+ export declare const SHADOW_HORIZON_UNIT = 15;
7
+ /** Floats the shadow areas add to the end of the Frame block. */
8
+ export declare function shadowAreaFloats(areas: number): number;
9
+ /** Members the shadow areas add to the end of the Frame block, in upload order. */
10
+ export declare function shadowAreaMembers(areas: number): string;
11
+ /** Lookup functions of the shadow areas; follows the header (the Frame block) in every program of such a mode. */
12
+ export declare const SHADOW_AREAS_GLSL = "\nuniform highp sampler2D u_shadowHorizonMap;\n\n// Share of the light that reaches a point according to area i of the map: 0 shadow, 1 lit.\nfloat whShadowArea(sampler2DShadow map, int i, vec3 worldPos, vec3 n, float normalOffsetTexels) {\n vec4 part = u_shadowPart[i];\n vec3 p = worldPos + n * (u_shadowReach[i].z * normalOffsetTexels);\n vec3 s = (u_shadowArea[i] * vec4(p, 1.0)).xyz;\n if (s.z >= 1.0) return 1.0;\n#if WH_SHADOW_AREAS == 1\n // A single area fills the map and wraps around in it; the map repeats, so the filter may cross the seam.\n vec2 uv = s.xy + part.xy;\n#else\n // Keep the filter inside this area's part of the map.\n float edge = (1.5 * part.w + u_view.w) / part.z;\n vec2 uv = part.xy + clamp(s.xy, vec2(edge), vec2(1.0 - edge)) * part.z;\n#endif\n float sum = 0.0;\n // 4 \u00D7 4 queries, each bilinearly compares four texels by itself.\n for (int j = 0; j < 4; j++) {\n for (int k = 0; k < 4; k++) {\n vec2 o = (vec2(float(k), float(j)) - 1.5) * part.w;\n sum += texture(map, vec3(uv + o, s.z));\n }\n }\n return sum * (1.0 / 16.0);\n}\n\n// Beyond the reach of the map: what the material knows itself (baked, 1 = lit) times the scene's light horizon, a\n// coarse texture of the height below which a point is hidden from the light. Without that texture just baked.\nfloat whShadowFar(vec3 worldPos, float baked) {\n vec4 y = u_shadowHorizonY;\n if (y.w <= 0.0) return baked;\n vec2 uv = worldPos.xz * u_shadowHorizon.zw + u_shadowHorizon.xy;\n if (uv.x <= 0.0 || uv.x >= 1.0 || uv.y <= 0.0 || uv.y >= 1.0) return baked;\n vec2 e = textureLod(u_shadowHorizonMap, uv, 0.0).rg;\n // Code 0: nothing stands between this place and the light, whatever the height of the point (it may lie a little\n // below the lowest height the texture can state).\n if (e.r + e.g <= 0.0) return baked;\n float top =y.x + (e.r * 65280.0 + e.g * 255.0) * (1.0 / 65535.0) * y.y;\n // Lit from the horizon up, fully hidden one blend height below it.\n float t = clamp((worldPos.y - top) * y.z + 1.0, 0.0, 1.0);\n return baked * t * t * (3.0 - 2.0 * t);\n}\n\n// whShadowArea with a hard edge: one depth comparison at the centre of the map texel under the point, no softening.\nfloat whShadowAreaSharp(sampler2DShadow map, int i, vec3 worldPos, vec3 n, float normalOffsetTexels) {\n vec4 part = u_shadowPart[i];\n vec3 p = worldPos + n * (u_shadowReach[i].z * normalOffsetTexels);\n vec3 s = (u_shadowArea[i] * vec4(p, 1.0)).xyz;\n if (s.z >= 1.0) return 1.0;\n#if WH_SHADOW_AREAS == 1\n vec2 uv = s.xy + part.xy;\n#else\n float edge = u_view.w / part.z;\n vec2 uv = part.xy + clamp(s.xy, vec2(edge), vec2(1.0 - edge)) * part.z;\n#endif\n uv = (floor(uv / u_view.w) + 0.5) * u_view.w;\n return texture(map, vec3(uv, s.z));\n}\n\n// Share of the light that reaches a point, 0\u20131. The finest area whose reach around the focus holds the point answers;\n// in the outer band of its reach it blends into the next area, the last one into the far term. The reach is measured\n// from the focus of the frame, not from where the area happens to lie, so nothing jumps when an area moves.\nfloat whShadow(sampler2DShadow map, vec3 worldPos, vec3 n, float normalOffsetTexels, float baked) {\n vec2 lp = vec2(dot(u_shadowRight.xyz, worldPos), dot(u_shadowUp.xyz, worldPos)) - u_shadowFocus.xy;\n float d = max(abs(lp.x), abs(lp.y));\n for (int i = 0; i < WH_SHADOW_AREAS; i++) {\n vec4 reach = u_shadowReach[i];\n if (d >= reach.x) continue;\n float lit = whShadowArea(map, i, worldPos, n, normalOffsetTexels);\n // 0 well inside the reach, 1 at its end.\n float t = clamp(1.0 - (reach.x - d) * reach.y, 0.0, 1.0);\n if (t <= 0.0) return lit;\n t = t * t * (3.0 - 2.0 * t);\n float next;\n#if WH_SHADOW_AREAS > 1\n // The index stays inside the arrays also in the branch that is never taken (a compiler may unroll the loop).\n if (i + 1 < WH_SHADOW_AREAS) next = whShadowArea(map, min(i + 1, WH_SHADOW_AREAS - 1), worldPos, n, normalOffsetTexels);\n else\n#endif\n next = whShadowFar(worldPos, baked);\n return mix(lit, next, t);\n }\n return whShadowFar(worldPos, baked);\n}\n\n// whShadow with a hard edge: the same choice and blending of areas, each area asked by whShadowAreaSharp.\nfloat whShadowSharp(sampler2DShadow map, vec3 worldPos, vec3 n, float normalOffsetTexels, float baked) {\n vec2 lp = vec2(dot(u_shadowRight.xyz, worldPos), dot(u_shadowUp.xyz, worldPos)) - u_shadowFocus.xy;\n float d = max(abs(lp.x), abs(lp.y));\n for (int i = 0; i < WH_SHADOW_AREAS; i++) {\n vec4 reach = u_shadowReach[i];\n if (d >= reach.x) continue;\n float lit = whShadowAreaSharp(map, i, worldPos, n, normalOffsetTexels);\n float t = clamp(1.0 - (reach.x - d) * reach.y, 0.0, 1.0);\n if (t <= 0.0) return lit;\n t = t * t * (3.0 - 2.0 * t);\n float next;\n#if WH_SHADOW_AREAS > 1\n if (i + 1 < WH_SHADOW_AREAS) next = whShadowAreaSharp(map, min(i + 1, WH_SHADOW_AREAS - 1), worldPos, n, normalOffsetTexels);\n else\n#endif\n next = whShadowFar(worldPos, baked);\n return mix(lit, next, t);\n }\n return whShadowFar(worldPos, baked);\n}\n";
@@ -0,0 +1,146 @@
1
+ // Shadow map pass: depth only, seen from the directional light.
2
+ import { shaderHeader } from './glsl.js';
3
+ export const DEPTH_VS = /* glsl */ `${shaderHeader()}
4
+ uniform mat4 u_lightRender;
5
+ in vec3 a_pos;
6
+ void main() {
7
+ gl_Position = u_lightRender * vec4(a_pos, 1.0);
8
+ }`;
9
+ export const DEPTH_FS = /* glsl */ `#version 300 es
10
+ precision highp float;
11
+ void main() {}`;
12
+ // --- Shadow areas -----------------------------------------------------------------------------------------------------
13
+ // The shadow modes other than the default one (`RendererOptions.shadows`) keep one or several square areas of the
14
+ // light's plane in the shadow map, each fixed to the world's texel grid and redrawn only when it moves. What follows is
15
+ // their part of the program header: `#define WH_SHADOW_AREAS n`, the members at the end of the Frame block and the
16
+ // lookup functions. `sunVisibility` of `<lighting>` calls `whShadow` when the define is there.
17
+ /** The most areas one shadow map holds (a 2 × 2 grid of parts). */
18
+ export const SHADOW_AREAS_MAX = 4;
19
+ /** Texture unit of the light horizon texture (`Renderer.shadowHorizon`), far above the units layers bind. */
20
+ export const SHADOW_HORIZON_UNIT = 15;
21
+ /** Floats the shadow areas add to the end of the Frame block. */
22
+ export function shadowAreaFloats(areas) {
23
+ return areas * 24 + 20;
24
+ }
25
+ /** Members the shadow areas add to the end of the Frame block, in upload order. */
26
+ export function shadowAreaMembers(areas) {
27
+ return /* glsl */ ` mat4 u_shadowArea[${areas}]; // render space to an area: xy 0–1 across the area, z depth 0–1 from the light
28
+ vec4 u_shadowPart[${areas}]; // xy where the area starts in the map (uv), z its share of the map edge, w filter radius (uv)
29
+ vec4 u_shadowReach[${areas}]; // x reach from the focus (m), y 1 / width of the blend band (1/m), z metres per texel
30
+ vec4 u_shadowFocus; // xy the focus in the light's plane (along u_shadowRight and u_shadowUp)
31
+ vec4 u_shadowRight; // xyz the light plane's first axis
32
+ vec4 u_shadowUp; // xyz the light plane's second axis
33
+ vec4 u_shadowHorizon; // light horizon texture: uv = xz * zw + xy
34
+ vec4 u_shadowHorizonY; // x height of code 0, y height span of the codes, z 1 / blend height, w 1 when a texture is set
35
+ `;
36
+ }
37
+ /** Lookup functions of the shadow areas; follows the header (the Frame block) in every program of such a mode. */
38
+ export const SHADOW_AREAS_GLSL = /* glsl */ `
39
+ uniform highp sampler2D u_shadowHorizonMap;
40
+
41
+ // Share of the light that reaches a point according to area i of the map: 0 shadow, 1 lit.
42
+ float whShadowArea(sampler2DShadow map, int i, vec3 worldPos, vec3 n, float normalOffsetTexels) {
43
+ vec4 part = u_shadowPart[i];
44
+ vec3 p = worldPos + n * (u_shadowReach[i].z * normalOffsetTexels);
45
+ vec3 s = (u_shadowArea[i] * vec4(p, 1.0)).xyz;
46
+ if (s.z >= 1.0) return 1.0;
47
+ #if WH_SHADOW_AREAS == 1
48
+ // A single area fills the map and wraps around in it; the map repeats, so the filter may cross the seam.
49
+ vec2 uv = s.xy + part.xy;
50
+ #else
51
+ // Keep the filter inside this area's part of the map.
52
+ float edge = (1.5 * part.w + u_view.w) / part.z;
53
+ vec2 uv = part.xy + clamp(s.xy, vec2(edge), vec2(1.0 - edge)) * part.z;
54
+ #endif
55
+ float sum = 0.0;
56
+ // 4 × 4 queries, each bilinearly compares four texels by itself.
57
+ for (int j = 0; j < 4; j++) {
58
+ for (int k = 0; k < 4; k++) {
59
+ vec2 o = (vec2(float(k), float(j)) - 1.5) * part.w;
60
+ sum += texture(map, vec3(uv + o, s.z));
61
+ }
62
+ }
63
+ return sum * (1.0 / 16.0);
64
+ }
65
+
66
+ // Beyond the reach of the map: what the material knows itself (baked, 1 = lit) times the scene's light horizon, a
67
+ // coarse texture of the height below which a point is hidden from the light. Without that texture just baked.
68
+ float whShadowFar(vec3 worldPos, float baked) {
69
+ vec4 y = u_shadowHorizonY;
70
+ if (y.w <= 0.0) return baked;
71
+ vec2 uv = worldPos.xz * u_shadowHorizon.zw + u_shadowHorizon.xy;
72
+ if (uv.x <= 0.0 || uv.x >= 1.0 || uv.y <= 0.0 || uv.y >= 1.0) return baked;
73
+ vec2 e = textureLod(u_shadowHorizonMap, uv, 0.0).rg;
74
+ // Code 0: nothing stands between this place and the light, whatever the height of the point (it may lie a little
75
+ // below the lowest height the texture can state).
76
+ if (e.r + e.g <= 0.0) return baked;
77
+ float top =y.x + (e.r * 65280.0 + e.g * 255.0) * (1.0 / 65535.0) * y.y;
78
+ // Lit from the horizon up, fully hidden one blend height below it.
79
+ float t = clamp((worldPos.y - top) * y.z + 1.0, 0.0, 1.0);
80
+ return baked * t * t * (3.0 - 2.0 * t);
81
+ }
82
+
83
+ // whShadowArea with a hard edge: one depth comparison at the centre of the map texel under the point, no softening.
84
+ float whShadowAreaSharp(sampler2DShadow map, int i, vec3 worldPos, vec3 n, float normalOffsetTexels) {
85
+ vec4 part = u_shadowPart[i];
86
+ vec3 p = worldPos + n * (u_shadowReach[i].z * normalOffsetTexels);
87
+ vec3 s = (u_shadowArea[i] * vec4(p, 1.0)).xyz;
88
+ if (s.z >= 1.0) return 1.0;
89
+ #if WH_SHADOW_AREAS == 1
90
+ vec2 uv = s.xy + part.xy;
91
+ #else
92
+ float edge = u_view.w / part.z;
93
+ vec2 uv = part.xy + clamp(s.xy, vec2(edge), vec2(1.0 - edge)) * part.z;
94
+ #endif
95
+ uv = (floor(uv / u_view.w) + 0.5) * u_view.w;
96
+ return texture(map, vec3(uv, s.z));
97
+ }
98
+
99
+ // Share of the light that reaches a point, 0–1. The finest area whose reach around the focus holds the point answers;
100
+ // in the outer band of its reach it blends into the next area, the last one into the far term. The reach is measured
101
+ // from the focus of the frame, not from where the area happens to lie, so nothing jumps when an area moves.
102
+ float whShadow(sampler2DShadow map, vec3 worldPos, vec3 n, float normalOffsetTexels, float baked) {
103
+ vec2 lp = vec2(dot(u_shadowRight.xyz, worldPos), dot(u_shadowUp.xyz, worldPos)) - u_shadowFocus.xy;
104
+ float d = max(abs(lp.x), abs(lp.y));
105
+ for (int i = 0; i < WH_SHADOW_AREAS; i++) {
106
+ vec4 reach = u_shadowReach[i];
107
+ if (d >= reach.x) continue;
108
+ float lit = whShadowArea(map, i, worldPos, n, normalOffsetTexels);
109
+ // 0 well inside the reach, 1 at its end.
110
+ float t = clamp(1.0 - (reach.x - d) * reach.y, 0.0, 1.0);
111
+ if (t <= 0.0) return lit;
112
+ t = t * t * (3.0 - 2.0 * t);
113
+ float next;
114
+ #if WH_SHADOW_AREAS > 1
115
+ // The index stays inside the arrays also in the branch that is never taken (a compiler may unroll the loop).
116
+ if (i + 1 < WH_SHADOW_AREAS) next = whShadowArea(map, min(i + 1, WH_SHADOW_AREAS - 1), worldPos, n, normalOffsetTexels);
117
+ else
118
+ #endif
119
+ next = whShadowFar(worldPos, baked);
120
+ return mix(lit, next, t);
121
+ }
122
+ return whShadowFar(worldPos, baked);
123
+ }
124
+
125
+ // whShadow with a hard edge: the same choice and blending of areas, each area asked by whShadowAreaSharp.
126
+ float whShadowSharp(sampler2DShadow map, vec3 worldPos, vec3 n, float normalOffsetTexels, float baked) {
127
+ vec2 lp = vec2(dot(u_shadowRight.xyz, worldPos), dot(u_shadowUp.xyz, worldPos)) - u_shadowFocus.xy;
128
+ float d = max(abs(lp.x), abs(lp.y));
129
+ for (int i = 0; i < WH_SHADOW_AREAS; i++) {
130
+ vec4 reach = u_shadowReach[i];
131
+ if (d >= reach.x) continue;
132
+ float lit = whShadowAreaSharp(map, i, worldPos, n, normalOffsetTexels);
133
+ float t = clamp(1.0 - (reach.x - d) * reach.y, 0.0, 1.0);
134
+ if (t <= 0.0) return lit;
135
+ t = t * t * (3.0 - 2.0 * t);
136
+ float next;
137
+ #if WH_SHADOW_AREAS > 1
138
+ if (i + 1 < WH_SHADOW_AREAS) next = whShadowAreaSharp(map, min(i + 1, WH_SHADOW_AREAS - 1), worldPos, n, normalOffsetTexels);
139
+ else
140
+ #endif
141
+ next = whShadowFar(worldPos, baked);
142
+ return mix(lit, next, t);
143
+ }
144
+ return whShadowFar(worldPos, baked);
145
+ }
146
+ `;
@@ -0,0 +1,61 @@
1
+ import type { MeshData, Uniforms } from '../base/index.ts';
2
+ import type { DustPuff } from '../core/index.ts';
3
+ import type { DrawContext, Layer, Material, Renderer } from './renderer.ts';
4
+ /** Seconds a dust puff lives. */
5
+ export declare const DUST_LIFE_S = 2.2;
6
+ export interface TransientBatch {
7
+ data: MeshData;
8
+ material: Material;
9
+ uniforms?: Uniforms;
10
+ /** Clock span in which something of the batch moves (first letting go, last thing settled). */
11
+ start: number;
12
+ end: number;
13
+ /** Pieces that fly, and pieces shown only as dust. */
14
+ pieces: number;
15
+ dust: number;
16
+ /** Dust puffs that belong to the batch (removed with it). */
17
+ puffs?: readonly DustPuff[];
18
+ }
19
+ export interface TransientStats {
20
+ /** Pieces of the batches still moving at the given time. */
21
+ pieces: number;
22
+ /** Pieces of those batches shown only as dust (over the budget). */
23
+ coarsened: number;
24
+ puffs: number;
25
+ batches: number;
26
+ }
27
+ /** Batches of pieces and dust puffs on closed-form tracks; add it to the renderer after the opaque layers. */
28
+ export declare class TransientLayer implements Layer {
29
+ readonly maxPieces: number;
30
+ readonly keepS: number;
31
+ private readonly renderer;
32
+ private readonly dustLayer;
33
+ private held;
34
+ private puffs;
35
+ private lastT;
36
+ private nextId;
37
+ /** `clock` gives the time the frame is drawn at (the clock behind `u_time.x`), for the shadow refresh. */
38
+ constructor(renderer: Renderer, o?: {
39
+ maxPieces?: number;
40
+ keepS?: number;
41
+ clock?: () => number;
42
+ });
43
+ draw(ctx: DrawContext): void;
44
+ /** How many more pieces may fly at clock time `now` (the budget minus the pieces of batches still moving). */
45
+ room(now: number): number;
46
+ /** Adds a batch (its puffs with it); returns a handle for `remove`. */
47
+ addBatch(b: TransientBatch): number;
48
+ /** Takes a batch away (to replace it with a new one). */
49
+ remove(id: number): void;
50
+ addPuffs(puffs: readonly DustPuff[]): void;
51
+ /** Is anything moving or visible as dust at `now`? */
52
+ busy(now: number): boolean;
53
+ /** Drops what finished more than `keepS` before `now`. */
54
+ drop(now: number): void;
55
+ clear(): void;
56
+ stats(now: number): TransientStats;
57
+ private moving;
58
+ private allPuffs;
59
+ private release;
60
+ private uploadDust;
61
+ }
@@ -0,0 +1,213 @@
1
+ // Transient things that move on closed-form tracks (core/ballistic.ts) driven by the clock time in the Frame block
2
+ // (`u_time.x`), and dust puffs. Nothing is integrated per frame, so pausing or scrubbing the clock shows the same pose,
3
+ // also back to before a piece landed (a batch is kept `keepS` seconds after it finished).
4
+ //
5
+ // A batch is any mesh with any material whose vertex shader places vertices with `TRACK_GLSL`; its pieces stand
6
+ // exactly where they are until they let go. The content module that makes the batch decides what its pieces look
7
+ // like and which of them go to dust when the budget is short (`room`). Dust is drawn as camera-facing quads whose
8
+ // cloud is made in the fragment shader from noise, blended over the scene without writing depth.
9
+ //
10
+ // While a batch moves (its clock span contains a changed clock time) the shadow map is redrawn every frame, so pieces
11
+ // cast moving shadows; outside that span the shadow map is left alone.
12
+ import { MeshLayer } from './renderer.js';
13
+ const f = (v) => v.toFixed(4);
14
+ /** Seconds a dust puff lives. */
15
+ export const DUST_LIFE_S = 2.2;
16
+ const DUST_LAYOUT = {
17
+ stride: 32,
18
+ attribs: [
19
+ { name: 'a_pos', size: 3, type: 'f32', offset: 0 },
20
+ { name: 'a_corner', size: 2, type: 'f32', offset: 12 },
21
+ { name: 'a_puff', size: 3, type: 'f32', offset: 20 },
22
+ ],
23
+ };
24
+ const DUST_ATTRIBS = { a_pos: 0, a_corner: 1, a_puff: 2 };
25
+ const DUST_VS = /* glsl */ `#include <header>
26
+ in vec3 a_pos;
27
+ in vec2 a_corner;
28
+ in vec3 a_puff;
29
+ out vec3 v_world;
30
+ out vec2 v_corner;
31
+ flat out float v_age;
32
+ flat out float v_seed;
33
+ void main() {
34
+ // a_puff: start, size, seed. The cloud swells fast, then slowly, and rises a little.
35
+ float age = u_time.x - a_puff.x;
36
+ float k = clamp(age / ${f(DUST_LIFE_S)}, 0.0, 1.0);
37
+ float r = a_puff.y * (0.35 + 1.1 * (1.0 - (1.0 - k) * (1.0 - k)));
38
+ vec3 c = a_pos + vec3(0.0, a_puff.y * 0.25 + 0.6 * k, 0.0);
39
+ bool live = age > 0.0 && age < ${f(DUST_LIFE_S)};
40
+ v_world = c + (u_camRight.xyz * a_corner.x + u_camUp.xyz * a_corner.y) * r;
41
+ v_corner = a_corner;
42
+ v_age = k;
43
+ v_seed = a_puff.z;
44
+ gl_Position = live ? u_viewProj * vec4(v_world, 1.0) : vec4(0.0, 0.0, 2.0, 1.0);
45
+ }`;
46
+ const DUST_FS = /* glsl */ `#include <header>
47
+ #include <noise>
48
+ #include <lighting>
49
+ in vec3 v_world;
50
+ in vec2 v_corner;
51
+ flat in float v_age;
52
+ flat in float v_seed;
53
+ out vec4 o_color;
54
+ void main() {
55
+ float d = length(v_corner);
56
+ uint s = uint(v_seed * 65535.0);
57
+ float billow = vnoise(v_corner * 2.6 + v_age * 1.5, s) * 0.6 + vnoise(v_corner * 5.3 - v_age, s + 1u) * 0.4;
58
+ float a = (1.0 - smoothstep(0.35, 1.0, d + 0.35 * (billow - 0.5))) * (1.0 - v_age) * (1.0 - v_age) * 0.85;
59
+ if (a < 0.01) discard;
60
+ vec3 col = vec3(0.66, 0.63, 0.58) * (0.85 + 0.3 * billow);
61
+ vec3 light = lightOn(vec3(0.0, 1.0, 0.0), 1.0, 1.0) * 0.8;
62
+ o_color = vec4(applyFog(toDisplay(col * u_warmTint.rgb * light), v_world), a);
63
+ }`;
64
+ const DUST_MATERIAL = {
65
+ name: 'transient-dust',
66
+ attribs: DUST_ATTRIBS,
67
+ passes: { color: { vs: DUST_VS, fs: DUST_FS } },
68
+ state: { color: { depthWrite: false, cullBack: false, blend: { src: 'src-alpha', dst: 'one-minus-src-alpha', srcAlpha: 'one', dstAlpha: 'one-minus-src-alpha' } } },
69
+ };
70
+ /** Batches of pieces and dust puffs on closed-form tracks; add it to the renderer after the opaque layers. */
71
+ export class TransientLayer {
72
+ maxPieces;
73
+ keepS;
74
+ renderer;
75
+ dustLayer;
76
+ held = [];
77
+ puffs = [];
78
+ lastT = NaN;
79
+ nextId = 1;
80
+ /** `clock` gives the time the frame is drawn at (the clock behind `u_time.x`), for the shadow refresh. */
81
+ constructor(renderer, o = {}) {
82
+ this.renderer = renderer;
83
+ this.maxPieces = o.maxPieces ?? 320;
84
+ this.keepS = o.keepS ?? 30;
85
+ this.dustLayer = new MeshLayer({ material: renderer.material(DUST_MATERIAL) });
86
+ const clock = o.clock;
87
+ if (clock) {
88
+ renderer.beforeFrame.push(() => {
89
+ const t = clock();
90
+ if (t !== this.lastT && this.moving(Math.min(t, this.lastT), Math.max(t, this.lastT)))
91
+ renderer.invalidateShadows();
92
+ this.lastT = t;
93
+ });
94
+ }
95
+ }
96
+ draw(ctx) {
97
+ for (const h of this.held)
98
+ h.layer.draw(ctx);
99
+ this.dustLayer.draw(ctx);
100
+ }
101
+ /** How many more pieces may fly at clock time `now` (the budget minus the pieces of batches still moving). */
102
+ room(now) {
103
+ let n = 0;
104
+ for (const h of this.held)
105
+ if (h.end > now)
106
+ n += h.pieces;
107
+ return Math.max(0, this.maxPieces - n);
108
+ }
109
+ /** Adds a batch (its puffs with it); returns a handle for `remove`. */
110
+ addBatch(b) {
111
+ const layer = new MeshLayer({ material: b.material, uniforms: b.uniforms ?? {} });
112
+ layer.mesh = b.data.count > 0 ? this.renderer.createMesh(b.data, b.material) : null;
113
+ const id = this.nextId++;
114
+ this.held.push({ id, layer, puffs: b.puffs ?? [], start: b.start, end: b.end, pieces: b.pieces, dust: b.dust });
115
+ if (b.puffs?.length)
116
+ this.uploadDust();
117
+ this.renderer.invalidateShadows();
118
+ return id;
119
+ }
120
+ /** Takes a batch away (to replace it with a new one). */
121
+ remove(id) {
122
+ const h = this.held.find((x) => x.id === id);
123
+ if (!h)
124
+ return;
125
+ this.release(h);
126
+ this.held = this.held.filter((x) => x !== h);
127
+ if (h.puffs.length)
128
+ this.uploadDust();
129
+ this.renderer.invalidateShadows();
130
+ }
131
+ addPuffs(puffs) {
132
+ if (puffs.length === 0)
133
+ return;
134
+ this.puffs.push(...puffs);
135
+ this.uploadDust();
136
+ }
137
+ /** Is anything moving or visible as dust at `now`? */
138
+ busy(now) {
139
+ return this.held.some((h) => now >= h.start && now < h.end) || this.allPuffs().some((p) => now >= p.start && p.start + DUST_LIFE_S > now);
140
+ }
141
+ /** Drops what finished more than `keepS` before `now`. */
142
+ drop(now) {
143
+ const keep = now - this.keepS;
144
+ const gone = this.held.filter((h) => h.end <= keep && h.puffs.every((p) => p.start + DUST_LIFE_S <= keep));
145
+ for (const h of gone)
146
+ this.release(h);
147
+ this.held = this.held.filter((h) => !gone.includes(h));
148
+ const n = this.puffs.length;
149
+ this.puffs = this.puffs.filter((p) => p.start + DUST_LIFE_S > keep);
150
+ if (this.puffs.length !== n || gone.some((h) => h.puffs.length > 0))
151
+ this.uploadDust();
152
+ }
153
+ clear() {
154
+ for (const h of this.held)
155
+ this.release(h);
156
+ this.held = [];
157
+ this.puffs = [];
158
+ this.uploadDust();
159
+ this.renderer.invalidateShadows();
160
+ }
161
+ stats(now) {
162
+ let pieces = 0;
163
+ let coarsened = 0;
164
+ for (const h of this.held) {
165
+ if (h.end <= now)
166
+ continue;
167
+ pieces += h.pieces;
168
+ coarsened += h.dust;
169
+ }
170
+ return { pieces, coarsened, puffs: this.allPuffs().filter((p) => p.start + DUST_LIFE_S > now).length, batches: this.held.length };
171
+ }
172
+ moving(a, b) {
173
+ if (!Number.isFinite(a) || !Number.isFinite(b))
174
+ return this.held.length > 0;
175
+ return this.held.some((h) => h.start <= b && h.end >= a);
176
+ }
177
+ allPuffs() {
178
+ return this.held.length ? [...this.puffs, ...this.held.flatMap((h) => h.puffs)] : this.puffs;
179
+ }
180
+ release(h) {
181
+ const m = h.layer.mesh;
182
+ if (m)
183
+ this.renderer.device.deleteMesh(m);
184
+ h.layer.mesh = null;
185
+ }
186
+ uploadDust() {
187
+ const old = this.dustLayer.mesh;
188
+ const data = dustMesh(this.allPuffs());
189
+ this.dustLayer.mesh = data.count > 0 ? this.renderer.createMesh(data, this.dustLayer.material) : null;
190
+ if (old)
191
+ this.renderer.device.deleteMesh(old);
192
+ }
193
+ }
194
+ function dustMesh(puffs) {
195
+ const v = new Float32Array(puffs.length * 6 * 8);
196
+ let o = 0;
197
+ for (const p of puffs) {
198
+ // Noise seed from the puff itself, so it keeps its look when other puffs come and go.
199
+ const seed = (Math.imul(Math.round(p.x * 100) ^ Math.imul(Math.round(p.z * 100), 0x85ebca6b) ^ Math.round(p.start * 1000), 0x9e3779b1) >>> 16) / 65535;
200
+ for (const [cx, cy] of [
201
+ [-1, -1],
202
+ [1, -1],
203
+ [1, 1],
204
+ [-1, -1],
205
+ [1, 1],
206
+ [-1, 1],
207
+ ]) {
208
+ v.set([p.x, p.y, p.z, cx, cy, p.start, p.size, seed], o);
209
+ o += 8;
210
+ }
211
+ }
212
+ return { layout: DUST_LAYOUT, vertices: v, indices: null, count: puffs.length * 6 };
213
+ }
@@ -0,0 +1,17 @@
1
+ import type { MaterialDesc } from '../base/material.ts';
2
+ /**
3
+ * GLSL helpers for reading value words; put it right after `#include <header>`. The helpers take fetched texels,
4
+ * never samplers.
5
+ */
6
+ export declare const VALUE_GLSL = "\nprecision highp sampler2D;\n// The 16-bit word of a two-byte texel (red = low byte, green = high byte). 0 means \"no value\".\nfloat valueWord(vec4 texel) {\n return floor(texel.r * 255.0 + 0.5) + floor(texel.g * 255.0 + 0.5) * 256.0;\n}\n// Texel of row i in a table texture that is w texels wide.\nivec2 tableCell(int i, int w) {\n return ivec2(i % w, i / w);\n}\n// x: the value as 0\u20131 across its range, y: 1 when there is a value, else 0.\nvec2 valueOf(float word) {\n return vec2(max(word - 1.0, 0.0) / 65534.0, step(0.5, word));\n}\n// Two time steps blended by t. Where only one of them has a value, that value fades in or out.\nvec2 blendSteps(vec2 a, vec2 b, float t) {\n float k = b.y * (a.y > 0.5 ? t : 1.0);\n return vec2(mix(a.x, b.x, k), mix(a.y, b.y, t));\n}\n// Position on the ramp of value v when the ramp spans the part range.x\u2013range.y of the value range.\nfloat rampPosition(vec2 range, float v) {\n return clamp((v - range.x) / max(range.y - range.x, 1e-6), 0.0, 1.0);\n}\n// Texture coordinate in a 256-texel ramp for position t (texel centres at both ends).\nfloat rampCoord(float t) {\n return t * (255.0 / 256.0) + 0.5 / 256.0;\n}\n";
7
+ /** A grid of values laid on a sheet over the ground (`drapeTiles`). */
8
+ export declare const RASTER_VALUE_MATERIAL: MaterialDesc;
9
+ /** Attribute locations of the disc material: the quad corner and one instance (centre and radius). */
10
+ export declare const POINT_VALUE_ATTRIBS: {
11
+ readonly a_corner: 0;
12
+ readonly a_point: 1;
13
+ };
14
+ /** Discs that face the view, one per instance, coloured and sized by the value of their table row. */
15
+ export declare const POINT_VALUE_MATERIAL: MaterialDesc;
16
+ /** Prisms (`prismMesh`) coloured by the value of the table row each of them carries. */
17
+ export declare const SHAPE_VALUE_MATERIAL: MaterialDesc;