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,170 @@
1
+ // Web Workers and network reads: the only place in the engine that touches the Worker API or fetch. A pool of module
2
+ // workers runs pure jobs off the main thread; typed arrays travel as transferred buffers, never copied. Jobs wait in
3
+ // one queue and each worker runs one job at a time, so a job that is cancelled before it starts never runs and one
4
+ // that is running finishes and is dropped by its caller.
5
+ /** Threads the machine offers, as the browser reports them (at least 1). */
6
+ export function hardwareThreads() {
7
+ return typeof navigator !== 'undefined' && navigator.hardwareConcurrency > 0 ? navigator.hardwareConcurrency : 1;
8
+ }
9
+ /** Can module workers be created here? (False in Node and in old browsers.) */
10
+ export function workersAvailable() {
11
+ return typeof Worker !== 'undefined';
12
+ }
13
+ export class WorkerPool {
14
+ size;
15
+ workers = [];
16
+ idle = [];
17
+ running = new Map();
18
+ queue = [];
19
+ /** Per worker: copies of broadcast messages it has still to get, in the order sent. They go before the queue. */
20
+ direct = new Map();
21
+ nextId = 1;
22
+ /** Time the workers spent in jobs, from their own clock: total and count. */
23
+ timing = { ms: 0, jobs: 0 };
24
+ /** `url` is a module worker script that calls `serveWorker`. */
25
+ constructor(url, size = Math.max(1, Math.min(4, hardwareThreads() - 1))) {
26
+ this.size = size;
27
+ for (let i = 0; i < size; i++) {
28
+ const w = new Worker(url, { type: 'module', name: `wh-worker-${i}` });
29
+ w.onmessage = (e) => this.finish(w, e.data);
30
+ w.onerror = (e) => {
31
+ const p = this.running.get(w);
32
+ if (p)
33
+ this.finish(w, { id: p.id, ok: false, error: e.message || 'worker error' });
34
+ };
35
+ this.workers.push(w);
36
+ this.idle.push(w);
37
+ }
38
+ }
39
+ /** Jobs waiting for a worker. */
40
+ get queued() {
41
+ return this.queue.length;
42
+ }
43
+ /** Jobs running now. */
44
+ get busy() {
45
+ return this.running.size;
46
+ }
47
+ run(message, transfer = []) {
48
+ let p;
49
+ const promise = new Promise((resolve, reject) => {
50
+ p = { id: this.nextId++, message, transfer, resolve: resolve, reject, cancelled: false };
51
+ });
52
+ this.queue.push(p);
53
+ this.pump();
54
+ return {
55
+ promise,
56
+ cancel: () => {
57
+ if (p.cancelled)
58
+ return;
59
+ p.cancelled = true;
60
+ const i = this.queue.indexOf(p);
61
+ if (i >= 0)
62
+ this.queue.splice(i, 1);
63
+ p.reject(abortError());
64
+ },
65
+ };
66
+ }
67
+ /**
68
+ * Posts one structured copy of `message` to every worker of the pool (no transfer list): at once to a free worker,
69
+ * right after its running job to a busy one, in either case before any queued job; two broadcasts reach a worker in
70
+ * the order sent. Resolves when every worker has answered, rejects with the first error, and with an `AbortError`
71
+ * after `dispose`. The replies do not count in `timing`.
72
+ */
73
+ broadcast(message) {
74
+ if (this.workers.length === 0)
75
+ return Promise.reject(abortError());
76
+ const parts = this.workers.map((w) => new Promise((resolve, reject) => {
77
+ const p = { id: this.nextId++, message, transfer: [], resolve: () => resolve(), reject, cancelled: false, broadcast: true };
78
+ const list = this.direct.get(w);
79
+ if (list)
80
+ list.push(p);
81
+ else
82
+ this.direct.set(w, [p]);
83
+ }));
84
+ this.pump();
85
+ return Promise.all(parts).then(() => undefined);
86
+ }
87
+ dispose() {
88
+ for (const w of this.workers)
89
+ w.terminate();
90
+ for (const list of this.direct.values())
91
+ for (const p of list)
92
+ p.reject(abortError());
93
+ this.direct.clear();
94
+ for (const p of [...this.queue, ...this.running.values()])
95
+ if (!p.cancelled)
96
+ p.reject(abortError());
97
+ this.queue.length = 0;
98
+ this.running.clear();
99
+ this.workers.length = 0;
100
+ this.idle.length = 0;
101
+ }
102
+ pump() {
103
+ // Broadcast copies first, each to its own worker once that worker is free.
104
+ if (this.direct.size > 0) {
105
+ for (let i = this.idle.length - 1; i >= 0; i--) {
106
+ const w = this.idle[i];
107
+ const list = this.direct.get(w);
108
+ if (!list)
109
+ continue;
110
+ const p = list.shift();
111
+ if (list.length === 0)
112
+ this.direct.delete(w);
113
+ this.idle.splice(i, 1);
114
+ this.running.set(w, p);
115
+ w.postMessage({ id: p.id, message: p.message }, p.transfer);
116
+ }
117
+ }
118
+ while (this.idle.length > 0 && this.queue.length > 0) {
119
+ const w = this.idle.pop();
120
+ const p = this.queue.shift();
121
+ this.running.set(w, p);
122
+ w.postMessage({ id: p.id, message: p.message }, p.transfer);
123
+ }
124
+ }
125
+ finish(w, reply) {
126
+ const p = this.running.get(w);
127
+ this.running.delete(w);
128
+ this.idle.push(w);
129
+ if (p && p.id === reply.id) {
130
+ if (reply.ms !== undefined && !p.broadcast) {
131
+ this.timing.ms += reply.ms;
132
+ this.timing.jobs++;
133
+ }
134
+ if (!p.cancelled) {
135
+ if (reply.ok)
136
+ p.resolve(reply.value);
137
+ else
138
+ p.reject(new Error(reply.error ?? 'worker job failed'));
139
+ }
140
+ }
141
+ this.pump();
142
+ }
143
+ }
144
+ /** Inside a worker script: answers every job of a `WorkerPool` with `handler`. */
145
+ export function serveWorker(handler) {
146
+ const scope = globalThis;
147
+ scope.onmessage = async (e) => {
148
+ const { id, message } = e.data;
149
+ const t0 = performance.now();
150
+ try {
151
+ const a = await handler(message);
152
+ scope.postMessage({ id, ok: true, value: a.value, ms: performance.now() - t0 }, a.transfer ?? []);
153
+ }
154
+ catch (err) {
155
+ scope.postMessage({ id, ok: false, error: err instanceof Error ? err.message : String(err), ms: performance.now() - t0 }, []);
156
+ }
157
+ };
158
+ }
159
+ function abortError() {
160
+ const e = new Error('job cancelled');
161
+ e.name = 'AbortError';
162
+ return e;
163
+ }
164
+ /** Reads a URL into bytes; rejects on an HTTP error or when the signal fires. */
165
+ export async function fetchBytes(url, signal) {
166
+ const r = await fetch(url, { signal });
167
+ if (!r.ok)
168
+ throw new Error(`${url}: HTTP ${r.status}`);
169
+ return r.arrayBuffer();
170
+ }
@@ -0,0 +1,24 @@
1
+ import type { InstanceSet } from './instance-sets.ts';
2
+ /** One part: the bone it follows, its set and record, and its matrix in the bone's frame (default identity). */
3
+ export interface BonePart {
4
+ bone: number;
5
+ set: InstanceSet;
6
+ record: number;
7
+ local?: ArrayLike<number> | null;
8
+ }
9
+ export declare class BoneInstances {
10
+ readonly count: number;
11
+ private readonly bone;
12
+ private readonly record;
13
+ private readonly setOf;
14
+ private readonly local;
15
+ private readonly sets;
16
+ constructor(parts: readonly BonePart[]);
17
+ /**
18
+ * Writes every part from the bone matrices in `world` (12 per bone, starting at bone `first`, so one array may hold
19
+ * several figures) and marks the sets dirty.
20
+ */
21
+ write(world: ArrayLike<number>, first?: number): void;
22
+ /** Collapses every part to a point (zero matrix at the origin: nothing is drawn) and marks the sets dirty. */
23
+ hide(): void;
24
+ }
@@ -0,0 +1,74 @@
1
+ // Bone matrices into instance records. A figure drawn as rigid parts has one record per part in some instance set;
2
+ // each part follows one bone, optionally through a fixed part matrix (the part's placement in the bone's frame).
3
+ // `BoneInstances` holds that table as flat arrays and writes world · part into the records' first 12 floats (the
4
+ // four free numbers stay as the owner wrote them), marking the touched sets dirty. Nothing is allocated per call.
5
+ // World matrices come from anywhere (`solvePose` of motion fills them): 12 numbers per bone, column by column.
6
+ import { INSTANCE_SET_FLOATS } from './instance-sets.js';
7
+ export class BoneInstances {
8
+ count;
9
+ bone;
10
+ record;
11
+ setOf;
12
+ local;
13
+ sets = [];
14
+ constructor(parts) {
15
+ const n = parts.length;
16
+ this.count = n;
17
+ this.bone = new Int32Array(n);
18
+ this.record = new Int32Array(n);
19
+ this.setOf = new Int32Array(n);
20
+ this.local = new Float64Array(n * 12);
21
+ parts.forEach((p, k) => {
22
+ if (p.record < 0 || p.record >= p.set.capacity)
23
+ throw new Error(`BoneInstances: record ${p.record} outside its set`);
24
+ let s = this.sets.indexOf(p.set);
25
+ if (s < 0)
26
+ s = this.sets.push(p.set) - 1;
27
+ this.bone[k] = p.bone;
28
+ this.record[k] = p.record;
29
+ this.setOf[k] = s;
30
+ const m = p.local;
31
+ for (let i = 0; i < 12; i++)
32
+ this.local[k * 12 + i] = m ? m[i] : i === 0 || i === 4 || i === 8 ? 1 : 0;
33
+ });
34
+ }
35
+ /**
36
+ * Writes every part from the bone matrices in `world` (12 per bone, starting at bone `first`, so one array may hold
37
+ * several figures) and marks the sets dirty.
38
+ */
39
+ write(world, first = 0) {
40
+ const L = this.local;
41
+ for (let k = 0; k < this.count; k++) {
42
+ const set = this.sets[this.setOf[k]];
43
+ const out = set.data;
44
+ const o = this.record[k] * INSTANCE_SET_FLOATS;
45
+ const a = (first + this.bone[k]) * 12;
46
+ const l = k * 12;
47
+ const a0 = world[a], a1 = world[a + 1], a2 = world[a + 2], a3 = world[a + 3], a4 = world[a + 4], a5 = world[a + 5];
48
+ const a6 = world[a + 6], a7 = world[a + 7], a8 = world[a + 8];
49
+ for (let c = 0; c < 3; c++) {
50
+ const x = L[l + c * 3], y = L[l + c * 3 + 1], z = L[l + c * 3 + 2];
51
+ out[o + c * 3] = a0 * x + a3 * y + a6 * z;
52
+ out[o + c * 3 + 1] = a1 * x + a4 * y + a7 * z;
53
+ out[o + c * 3 + 2] = a2 * x + a5 * y + a8 * z;
54
+ }
55
+ const x = L[l + 9], y = L[l + 10], z = L[l + 11];
56
+ out[o + 9] = a0 * x + a3 * y + a6 * z + world[a + 9];
57
+ out[o + 10] = a1 * x + a4 * y + a7 * z + world[a + 10];
58
+ out[o + 11] = a2 * x + a5 * y + a8 * z + world[a + 11];
59
+ }
60
+ for (let i = 0; i < this.sets.length; i++)
61
+ this.sets[i].dirty = true;
62
+ }
63
+ /** Collapses every part to a point (zero matrix at the origin: nothing is drawn) and marks the sets dirty. */
64
+ hide() {
65
+ for (let k = 0; k < this.count; k++) {
66
+ const out = this.sets[this.setOf[k]].data;
67
+ const o = this.record[k] * INSTANCE_SET_FLOATS;
68
+ for (let i = 0; i < 12; i++)
69
+ out[o + i] = 0;
70
+ }
71
+ for (let i = 0; i < this.sets.length; i++)
72
+ this.sets[i].dirty = true;
73
+ }
74
+ }
@@ -0,0 +1,70 @@
1
+ import type { MeshData, VertexLayout } from '../base/data.ts';
2
+ import type { Uniforms } from '../base/material.ts';
3
+ import type { CullVolume, View } from '../base/view.ts';
4
+ import type { InstanceCell } from '../gen-core/index.ts';
5
+ import type { Device } from '../gpu/index.ts';
6
+ import { MeshLayer } from './renderer.ts';
7
+ import type { DrawContext, MeshLayerOptions } from './renderer.ts';
8
+ /**
9
+ * Distances (metres from the eye to the cell box) at which a cell switches detail. Each distance in a list that the
10
+ * cell is at or beyond counts one step.
11
+ */
12
+ export interface CellDetail {
13
+ /** Colour and data passes: each step drops one level of detail, starting from the finest (the last in `lods`). */
14
+ lodSteps: readonly number[];
15
+ /** Colour and data passes: each step moves one thinning tier on (tier 0 is every instance). */
16
+ tierSteps: readonly number[];
17
+ /** Shadow pass: as `tierSteps`. Default `tierSteps`. The shadow pass always draws level 0 (the coarsest). */
18
+ shadowTierSteps?: readonly number[];
19
+ }
20
+ /** Level of detail and tier for a cell at `distance`, clamped to what the cell has. Pure. */
21
+ export declare function cellDetail(distance: number, purpose: 'shadow' | 'view', d: CellDetail, lodCount: number, tierCount: number): {
22
+ lod: number;
23
+ tier: number;
24
+ };
25
+ export interface InstanceCellLayerOptions extends Omit<MeshLayerOptions, 'mesh'> {
26
+ detail: CellDetail;
27
+ /**
28
+ * The distance an orthographic view (no eye, `pixelGrowth` 0) uses for every cell. Default: the distance at which a
29
+ * 45° perspective view about 1100 pixels high has the same CSS pixel size, `metresPerPixel · dpr · 1100`.
30
+ */
31
+ orthoDistance?: (view: View) => number;
32
+ }
33
+ /** One shape (its levels of detail, coarsest first) with its cells. */
34
+ export interface InstanceCellGroup {
35
+ /** Set before this group's draws, after the layer's uniforms. May be replaced at any time. */
36
+ uniforms: Uniforms;
37
+ /** Instances in tier 0 over all cells. */
38
+ readonly instances: number;
39
+ /** Bytes this group holds on the GPU: each level of detail once, plus the instance buffers. */
40
+ readonly bytes: number;
41
+ }
42
+ /**
43
+ * Groups of instanced shapes split into cells. Each (cell, tier, level of detail) is one instanced mesh sharing the
44
+ * level's vertex buffer; a refit culls cells by box and picks per cell what to draw. `cull` returns the instances kept
45
+ * for the view (the `instancesVisible` statistic).
46
+ */
47
+ export declare class InstanceCellLayer extends MeshLayer {
48
+ detail: CellDetail;
49
+ private readonly device;
50
+ private readonly orthoDistance;
51
+ private readonly list;
52
+ private viewList;
53
+ private shadowList;
54
+ private stale;
55
+ /** Instances drawn in the last colour (or data) pass. */
56
+ drawnInstances: number;
57
+ constructor(device: Device, o: InstanceCellLayerOptions);
58
+ get groups(): readonly InstanceCellGroup[];
59
+ get bytes(): number;
60
+ /**
61
+ * Uploads one shape and its cells. `lods` go coarsest first; `layout` is the instance layout of the cells' tier data.
62
+ * Each level is uploaded once and shared by every cell and tier.
63
+ */
64
+ addGroup(lods: readonly MeshData[], cells: readonly InstanceCell[], layout: VertexLayout, uniforms?: Uniforms): InstanceCellGroup;
65
+ /** Removes a group and deletes its GPU objects. */
66
+ removeGroup(group: InstanceCellGroup): void;
67
+ cullStale(): boolean;
68
+ cull(volume: CullVolume, purpose: 'shadow' | 'view', view?: View): number;
69
+ draw(ctx: DrawContext): void;
70
+ }
@@ -0,0 +1,144 @@
1
+ // Instances split into cells (gen-core `splitInstanceCells`), drawn with a level of detail and a thinning tier chosen
2
+ // per cell. `InstancedLayer` culls every instance and picks one level of detail for the whole layer, which costs
3
+ // time per refit and draws the finest shape everywhere. Here each cell has fixed GPU buffers, is culled as one box
4
+ // and picks its level and tier by its own distance from the eye. Nothing is rewritten on the GPU after upload.
5
+ import { boxInVolume, distanceToBox } from '../base/view.js';
6
+ import { MeshLayer } from './renderer.js';
7
+ /** Level of detail and tier for a cell at `distance`, clamped to what the cell has. Pure. */
8
+ export function cellDetail(distance, purpose, d, lodCount, tierCount) {
9
+ const steps = (list) => list.reduce((n, at) => (distance >= at ? n + 1 : n), 0);
10
+ const tierSteps = purpose === 'shadow' ? (d.shadowTierSteps ?? d.tierSteps) : d.tierSteps;
11
+ const tier = Math.min(tierCount - 1, steps(tierSteps));
12
+ const lod = purpose === 'shadow' ? 0 : Math.max(0, lodCount - 1 - steps(d.lodSteps));
13
+ return { lod, tier };
14
+ }
15
+ /**
16
+ * Groups of instanced shapes split into cells. Each (cell, tier, level of detail) is one instanced mesh sharing the
17
+ * level's vertex buffer; a refit culls cells by box and picks per cell what to draw. `cull` returns the instances kept
18
+ * for the view (the `instancesVisible` statistic).
19
+ */
20
+ export class InstanceCellLayer extends MeshLayer {
21
+ detail;
22
+ device;
23
+ orthoDistance;
24
+ list = [];
25
+ viewList = [];
26
+ shadowList = [];
27
+ stale = false;
28
+ /** Instances drawn in the last colour (or data) pass. */
29
+ drawnInstances = 0;
30
+ constructor(device, o) {
31
+ super(o);
32
+ this.device = device;
33
+ this.detail = o.detail;
34
+ this.orthoDistance = o.orthoDistance ?? ((view) => view.metresPerPixel * view.dpr * 1100);
35
+ }
36
+ get groups() {
37
+ return this.list;
38
+ }
39
+ get bytes() {
40
+ return this.list.reduce((b, g) => b + g.bytes, 0);
41
+ }
42
+ /**
43
+ * Uploads one shape and its cells. `lods` go coarsest first; `layout` is the instance layout of the cells' tier data.
44
+ * Each level is uploaded once and shared by every cell and tier.
45
+ */
46
+ addGroup(lods, cells, layout, uniforms = {}) {
47
+ const attribs = this.material.attribs;
48
+ const base = lods.map((m) => this.device.createMesh(m, attribs));
49
+ let bytes = base.reduce((b, m) => b + m.bytes, 0);
50
+ const buffers = [];
51
+ let instances = 0;
52
+ const draws = cells.map((c) => {
53
+ instances += (c.tiers[0]?.length ?? 0) / (layout.stride / 4);
54
+ const meshes = c.tiers.map((data) => {
55
+ if (data.length === 0)
56
+ return [];
57
+ const inst = this.device.createInstances({ layout, data });
58
+ buffers.push(inst);
59
+ bytes += data.byteLength;
60
+ return base.map((m) => this.device.shareMesh(m, attribs, inst));
61
+ });
62
+ return { min: c.min, max: c.max, meshes };
63
+ });
64
+ const g = { uniforms, instances, bytes, base, buffers, cells: draws };
65
+ this.list.push(g);
66
+ this.stale = true;
67
+ return g;
68
+ }
69
+ /** Removes a group and deletes its GPU objects. */
70
+ removeGroup(group) {
71
+ const i = this.list.indexOf(group);
72
+ if (i < 0)
73
+ return;
74
+ const g = this.list[i];
75
+ this.list.splice(i, 1);
76
+ for (const c of g.cells)
77
+ for (const tier of c.meshes)
78
+ for (const m of tier)
79
+ this.device.deleteMesh(m);
80
+ for (const b of g.buffers)
81
+ this.device.deleteInstances(b);
82
+ for (const m of g.base)
83
+ this.device.deleteMesh(m);
84
+ this.viewList = this.viewList.filter((e) => e.group !== g);
85
+ this.shadowList = this.shadowList.filter((e) => e.group !== g);
86
+ this.stale = true;
87
+ }
88
+ cullStale() {
89
+ return this.stale;
90
+ }
91
+ cull(volume, purpose, view) {
92
+ // A perspective view's corner rays start at the eye; an orthographic view has none and uses one distance for all.
93
+ const eye = view && view.pixelGrowth > 0 ? view.cornerRays()[0].origin : null;
94
+ const flat = view && !eye ? this.orthoDistance(view) : 0;
95
+ const out = [];
96
+ let kept = 0;
97
+ for (const g of this.list) {
98
+ for (const c of g.cells) {
99
+ if (!boxInVolume(c, volume))
100
+ continue;
101
+ const d = eye ? distanceToBox(eye, c) : flat;
102
+ const { tier, lod } = cellDetail(d, purpose, this.detail, g.base.length, c.meshes.length);
103
+ const lods = c.meshes[tier];
104
+ const mesh = lods[Math.min(lod, lods.length - 1)];
105
+ if (!mesh)
106
+ continue;
107
+ out.push({ mesh, group: g });
108
+ kept += mesh.instances;
109
+ }
110
+ }
111
+ if (purpose === 'shadow')
112
+ this.shadowList = out;
113
+ else {
114
+ this.viewList = out;
115
+ this.stale = false;
116
+ }
117
+ return purpose === 'view' ? kept : 0;
118
+ }
119
+ draw(ctx) {
120
+ const list = ctx.pass === 'shadow' ? this.shadowList : this.viewList;
121
+ const colour = ctx.pass === 'color' || ctx.pass === 'data';
122
+ if (colour)
123
+ this.drawnInstances = 0;
124
+ if (list.length === 0)
125
+ return;
126
+ const program = this.begin(ctx);
127
+ if (!program)
128
+ return;
129
+ let group = null;
130
+ let n = 0;
131
+ for (const e of list) {
132
+ if (e.group !== group) {
133
+ group = e.group;
134
+ for (const name in group.uniforms)
135
+ program.set(name, group.uniforms[name]);
136
+ }
137
+ ctx.device.draw(e.mesh);
138
+ ctx.count(e.mesh.triangles * e.mesh.instances);
139
+ n += e.mesh.instances;
140
+ }
141
+ if (colour)
142
+ this.drawnInstances = n;
143
+ }
144
+ }
@@ -0,0 +1,66 @@
1
+ import type { DepthMode } from '../base/view.ts';
2
+ /** GLSL member declarations (vec4 only) of the owner's slots in the Frame block. */
3
+ export interface FrameSlotsGlsl {
4
+ /** Right after the light direction. */
5
+ afterLight: string;
6
+ /** After the view axes, at the end of the block. */
7
+ afterView: string;
8
+ }
9
+ /** Number of vec4 members in each slot. */
10
+ export interface FrameSlotSizes {
11
+ afterLight: number;
12
+ afterView: number;
13
+ }
14
+ /** Size of the Frame block in floats (std140, all vec4 and mat4). */
15
+ export declare function frameBlockFloats(slots: FrameSlotSizes): number;
16
+ /**
17
+ * What a renderer option adds to the program header: `#define` lines right after the version line, and members
18
+ * (vec4 and mat4 only) at the very end of the Frame block, after every slot. Both empty by default.
19
+ */
20
+ export interface HeaderExtra {
21
+ defines?: string;
22
+ frameTail?: string;
23
+ }
24
+ /**
25
+ * Program header: version, precision, the Frame block with the given slots and the Palette block. In a depth mode
26
+ * other than `'standard'` it also defines `WH_DEPTH_REVERSED` or `WH_DEPTH_LOGARITHMIC` (to 1), for the rare shader
27
+ * that reads depth values of the main target itself.
28
+ */
29
+ export declare function shaderHeader(slots?: FrameSlotsGlsl, depth?: DepthMode, extra?: HeaderExtra): string;
30
+ /**
31
+ * Local up, shader side. Appended to every program header, so any shader may ask which way is up at a point of render
32
+ * space instead of assuming +y:
33
+ *
34
+ * - `localUp(p)`: unit up at `p`.
35
+ * - `localHeight(p)`: height of `p` above the base surface.
36
+ * - `localFrame(p)`: three axes at `p` as the columns of a matrix; the middle one is up, the other two span the
37
+ * horizon. A point given along x, up and z of an upright object is `p + localFrame(p) * q`.
38
+ *
39
+ * By default up is +y, the height is `p.y` and the frame is the identity. A renderer made with `radialUp` defines
40
+ * `WH_LOCAL_UP` and fills `u_upCenter`, the last member of the Frame block: up then points away from that point, and
41
+ * the frame is the world's axes turned by the shortest rotation that takes +y to up (`upFrame` of base is the same
42
+ * frame on the CPU).
43
+ */
44
+ export declare const LOCAL_UP_DEFINE = "#define WH_LOCAL_UP 1\n";
45
+ export declare const LOCAL_UP_MEMBER = " vec4 u_upCenter; // xyz the point up points away from, in render space, w radius of the base surface\n";
46
+ /** Floats `LOCAL_UP_MEMBER` adds to the end of the Frame block. */
47
+ export declare const LOCAL_UP_FLOATS = 4;
48
+ export declare const LOCAL_UP_GLSL = "\n#ifdef WH_LOCAL_UP\nvec3 localUp(vec3 p) { return normalize(p - u_upCenter.xyz); }\nfloat localHeight(vec3 p) { return length(p - u_upCenter.xyz) - u_upCenter.w; }\nmat3 localFrame(vec3 p) {\n vec3 u = localUp(p);\n // Opposite to +y the shortest rotation is not defined: half a turn about x.\n if (u.y < -0.99999) return mat3(1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0);\n // k = 1 / (1 + u.y). Below the horizon it is taken as (1 - u.y) / (u.x * u.x + u.z * u.z), the same number for a\n // unit vector: 1 + u.y loses its digits near -y, and the frame would be sheared by a percent there.\n float h = u.x * u.x + u.z * u.z;\n float k = u.y > 0.0 || h == 0.0 ? 1.0 / (1.0 + u.y) : (1.0 - u.y) / h;\n return mat3(1.0 - u.x * u.x * k, -u.x, -u.x * u.z * k, u.x, u.y, u.z, -u.x * u.z * k, -u.z, 1.0 - u.z * u.z * k);\n}\n#else\nvec3 localUp(vec3 p) { return vec3(0.0, 1.0, 0.0); }\nfloat localHeight(vec3 p) { return p.y; }\nmat3 localFrame(vec3 p) { return mat3(1.0); }\n#endif\n";
49
+ /**
50
+ * Logarithmic depth, fragment side. A fragment shader drawn into the main target gets the prelude right after the
51
+ * header and the epilogue at its end (`Renderer.resolve` does both): the shader's own `main` becomes
52
+ * `whMaterialMain`, and the real `main` calls it and then writes depth from the distance along the view, which the
53
+ * rasteriser carries in `gl_FragCoord.w`. No varying is involved, so any vertex shader fits. The polygon offset of the
54
+ * draw state arrives as `u_whDepthBias` (factor, units), because the pipeline's own offset does not reach a depth the
55
+ * shader writes.
56
+ */
57
+ export declare const LOG_DEPTH_PRELUDE = "uniform vec2 u_whDepthBias;\n#define main whMaterialMain\n";
58
+ export declare const LOG_DEPTH_EPILOGUE = "\n#undef main\nvoid main() {\n whMaterialMain();\n // Orthographic views and programs outside the 3D scene (u_camUp.w = 0) keep the depth of the pipeline.\n float d = u_camUp.w > 0.0 ? log2(1.0 + max(1.0 / gl_FragCoord.w, 0.0)) * u_camUp.w : gl_FragCoord.z;\n float slope = max(abs(dFdx(d)), abs(dFdy(d)));\n // 1.2e-7: the smallest step a 32-bit float depth resolves near 1.\n gl_FragDepth = clamp(d + u_whDepthBias.x * slope + u_whDepthBias.y * 1.2e-7, 0.0, 1.0);\n}\n";
59
+ /**
60
+ * Pixel size functions, appended to every program header (after the Frame block, which they read):
61
+ * `metresPerPixelAt(p)` (metres one screen pixel covers at a world point), `detailVisible(cellM)` and
62
+ * `detailVisibleAt(cellM, p)` (1 while a detail of that size is still sharp, 0 where it should vanish). They were
63
+ * part of `<noise>` before; `<noise>` keeps them for sources without the header, guarded by `WH_PIXEL_SIZE`.
64
+ */
65
+ export declare const PIXEL_SIZE_GLSL = "\n#ifndef WH_PIXEL_SIZE\n#define WH_PIXEL_SIZE 1\nfloat detailVisible(float cellM) {\n return 1.0 - smoothstep(0.5, 0.9, u_view.x / cellM);\n}\nfloat metresPerPixelAt(vec3 worldPos) {\n return max(u_view.x + u_camRight.w * (dot(worldPos, u_camForward.xyz) - u_camForward.w), 1e-4);\n}\nfloat detailVisibleAt(float cellM, vec3 worldPos) {\n return 1.0 - smoothstep(0.5, 0.9, metresPerPixelAt(worldPos) / cellM);\n}\n#endif\n";
66
+ export declare const NOISE = "\n// Noise from an integer hash. Never from the sine function: it gives different results on different GPUs.\nuint hashU(uint x) {\n x ^= x >> 16; x *= 0x7feb352dU;\n x ^= x >> 15; x *= 0x846ca68bU;\n x ^= x >> 16;\n return x;\n}\nfloat hash1(uint x) { return float(hashU(x)) * (1.0 / 4294967296.0); }\nfloat hash2(ivec2 p, uint seed) {\n return float(hashU(uint(p.x) * 0x9e3779b1U ^ hashU(uint(p.y) + seed * 0x85ebca6bU))) * (1.0 / 4294967296.0);\n}\nfloat hash3(ivec3 p, uint seed) {\n return float(hashU(uint(p.x) * 0x9e3779b1U ^ hashU(uint(p.y) * 0xc2b2ae35U ^ hashU(uint(p.z) + seed)))) * (1.0 / 4294967296.0);\n}\n// Smooth value noise, 0\u20131.\nfloat vnoise(vec2 p, uint seed) {\n vec2 f = floor(p);\n ivec2 i = ivec2(f);\n vec2 t = p - f;\n t = t * t * (3.0 - 2.0 * t);\n float a = hash2(i, seed), b = hash2(i + ivec2(1, 0), seed);\n float c = hash2(i + ivec2(0, 1), seed), d = hash2(i + ivec2(1, 1), seed);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\nfloat vnoise3(vec3 p, uint seed) {\n vec3 f = floor(p);\n ivec3 i = ivec3(f);\n vec3 t = p - f;\n t = t * t * (3.0 - 2.0 * t);\n float a = mix(hash3(i, seed), hash3(i + ivec3(1, 0, 0), seed), t.x);\n float b = mix(hash3(i + ivec3(0, 1, 0), seed), hash3(i + ivec3(1, 1, 0), seed), t.x);\n float c = mix(hash3(i + ivec3(0, 0, 1), seed), hash3(i + ivec3(1, 0, 1), seed), t.x);\n float d = mix(hash3(i + ivec3(0, 1, 1), seed), hash3(i + ivec3(1, 1, 1), seed), t.x);\n return mix(mix(a, b, t.y), mix(c, d, t.y), t.z);\n}\n// The pixel size functions (detailVisible, metresPerPixelAt, detailVisibleAt) come with the header now\n// (PIXEL_SIZE_GLSL); a source that includes noise without the header still gets them here.\n#ifndef WH_PIXEL_SIZE\n#define WH_PIXEL_SIZE 1\n// How visible a detail of size cellM metres still is: 1 = sharp, 0 = the pattern should vanish.\n// Applies to smooth noise: fully visible from two pixels per cell, around one pixel not at all,\n// because it would fight with the screen grid and flicker when panning. Patterns with a sharp edge\n// (grids, stripes) have a stricter rule of their own.\nfloat detailVisible(float cellM) {\n return 1.0 - smoothstep(0.5, 0.9, u_view.x / cellM);\n}\n// Size of one screen pixel at a world point, in metres. Constant for an orthographic view, grows with depth in perspective.\nfloat metresPerPixelAt(vec3 worldPos) {\n return max(u_view.x + u_camRight.w * (dot(worldPos, u_camForward.xyz) - u_camForward.w), 1e-4);\n}\n// detailVisible at a world point: the same rule with the pixel size there, for perspective views.\nfloat detailVisibleAt(float cellM, vec3 worldPos) {\n return 1.0 - smoothstep(0.5, 0.9, metresPerPixelAt(worldPos) / cellM);\n}\n#endif\n";