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,151 @@
1
+ // Many meshes drawn with one material, each with its own box, culled per box. For a scene built in separately
2
+ // generated pieces (tiles, chunks): only the pieces that reach into the view are drawn in the colour passes, and only
3
+ // those that reach into the light's volume in the shadow pass. Works with any view (frustum or box volume).
4
+ //
5
+ // The culled sets live in arrays that grow only when pieces are added, so culling (which runs on every refit, in
6
+ // every frame while the view moves) allocates nothing. Optionally the view set is sorted front to back, and each
7
+ // piece gets its own short list of point lights (`PointLightSet.bindFor`).
8
+ import { boxInVolume, newOrthoFrame } from '../base/view.js';
9
+ import { MeshLayer } from './renderer.js';
10
+ /**
11
+ * A `MeshLayer` with a list of pieces instead of one mesh. Material, uniforms, textures, passes and draw state are
12
+ * shared and set once per pass; each piece is one draw call. Adding or removing a piece marks the culled sets stale,
13
+ * so the renderer refits and culls again on the next frame.
14
+ */
15
+ export class PieceLayer extends MeshLayer {
16
+ /** Order of the pieces in the colour and data passes (`PieceLayerOptions.order`). */
17
+ order;
18
+ /** Point lights per piece in the colour pass (`PieceLayerOptions.lights`). */
19
+ lights;
20
+ list = [];
21
+ shadowSet = [];
22
+ viewSet = [];
23
+ shadowCount = 0;
24
+ viewCount = 0;
25
+ /** Sort keys of the view set (depth of the box centre along the view). */
26
+ keys = new Float64Array(0);
27
+ /** Scratch for the view's axes while sorting. */
28
+ axes = newOrthoFrame();
29
+ stale = false;
30
+ /** Pieces drawn in the last colour (or data) pass. */
31
+ drawn = 0;
32
+ constructor(o) {
33
+ super(o);
34
+ this.order = o.order ?? 'added';
35
+ this.lights = o.lights ?? null;
36
+ }
37
+ get pieces() {
38
+ return this.list;
39
+ }
40
+ /** Bytes of GPU buffers the pieces' meshes own. */
41
+ get bytes() {
42
+ let b = 0;
43
+ for (const p of this.list)
44
+ b += p.mesh.bytes;
45
+ return b;
46
+ }
47
+ add(piece) {
48
+ this.list.push(piece);
49
+ // Grow the culled sets here, never while culling.
50
+ if (this.viewSet.length < this.list.length) {
51
+ const n = Math.max(16, this.list.length * 2);
52
+ this.shadowSet.length = n;
53
+ this.viewSet.length = n;
54
+ const keys = new Float64Array(n);
55
+ keys.set(this.keys.subarray(0, Math.min(this.keys.length, n)));
56
+ this.keys = keys;
57
+ }
58
+ this.stale = true;
59
+ }
60
+ /** Takes a piece out (the caller deletes its mesh). Returns whether it was there. */
61
+ remove(piece) {
62
+ const i = this.list.indexOf(piece);
63
+ if (i < 0)
64
+ return false;
65
+ this.list.splice(i, 1);
66
+ // Until the next cull the sets must not draw the piece (its mesh may be gone).
67
+ this.shadowCount = dropFrom(this.shadowSet, this.shadowCount, piece);
68
+ this.viewCount = dropFrom(this.viewSet, this.viewCount, piece);
69
+ this.stale = true;
70
+ return true;
71
+ }
72
+ cullStale() {
73
+ return this.stale;
74
+ }
75
+ cull(volume, purpose, view) {
76
+ const shadow = purpose === 'shadow';
77
+ const set = shadow ? this.shadowSet : this.viewSet;
78
+ const list = this.list;
79
+ let n = 0;
80
+ for (let i = 0; i < list.length; i++) {
81
+ const p = list[i];
82
+ if (boxInVolume(p, volume))
83
+ set[n++] = p;
84
+ }
85
+ if (shadow)
86
+ this.shadowCount = n;
87
+ else {
88
+ if (this.order === 'front-to-back' && view && n > 1)
89
+ this.sortView(view, n);
90
+ this.viewCount = n;
91
+ this.stale = false;
92
+ }
93
+ return 0;
94
+ }
95
+ /** Insertion sort of the first `n` entries of the view set by depth along the view (stable, in place). */
96
+ sortView(view, n) {
97
+ const f = view.axes(this.axes).forward;
98
+ const set = this.viewSet;
99
+ const keys = this.keys;
100
+ for (let i = 0; i < n; i++) {
101
+ const p = set[i];
102
+ const key = f[0] * (p.min[0] + p.max[0]) + f[1] * (p.min[1] + p.max[1]) + f[2] * (p.min[2] + p.max[2]);
103
+ let k = i;
104
+ while (k > 0 && keys[k - 1] > key) {
105
+ keys[k] = keys[k - 1];
106
+ set[k] = set[k - 1];
107
+ k--;
108
+ }
109
+ keys[k] = key;
110
+ set[k] = p;
111
+ }
112
+ }
113
+ draw(ctx) {
114
+ const shadow = ctx.pass === 'shadow';
115
+ const set = shadow ? this.shadowSet : this.viewSet;
116
+ const count = shadow ? this.shadowCount : this.viewCount;
117
+ const main = ctx.pass === 'color' || ctx.pass === 'data';
118
+ if (main)
119
+ this.drawn = 0;
120
+ if (count === 0)
121
+ return;
122
+ const program = this.begin(ctx);
123
+ if (!program)
124
+ return;
125
+ const lights = ctx.pass === 'color' ? this.lights : null;
126
+ for (let i = 0; i < count; i++) {
127
+ const p = set[i];
128
+ if (lights)
129
+ lights.bindFor(program, p);
130
+ ctx.device.draw(p.mesh);
131
+ ctx.count(p.mesh.triangles);
132
+ }
133
+ // Leave the program as a fresh one: whole selection for draws that set no list.
134
+ if (lights)
135
+ lights.bindAll(program);
136
+ if (main)
137
+ this.drawn = count;
138
+ }
139
+ }
140
+ /** Removes `piece` from the first `count` entries of `set` in place; returns the new count. */
141
+ function dropFrom(set, count, piece) {
142
+ let n = 0;
143
+ for (let i = 0; i < count; i++) {
144
+ const p = set[i];
145
+ if (p !== piece)
146
+ set[n++] = p;
147
+ }
148
+ for (let i = n; i < count; i++)
149
+ set[i] = undefined;
150
+ return n;
151
+ }
@@ -0,0 +1,97 @@
1
+ import type { Box3 } from '../base/view.ts';
2
+ import type { Program } from '../gpu/index.ts';
3
+ import type { Renderer } from './renderer.ts';
4
+ /**
5
+ * Binding point of the `PointLights` uniform block. Programs get their block bound to it by the device
6
+ * (`UBO_BINDING.PointLights` in gpu); the value must stay equal to it.
7
+ */
8
+ export declare const POINT_LIGHTS_BINDING = 2;
9
+ /** Most lights one draw visits (two `ivec4` of indices). */
10
+ export declare const POINT_LIGHTS_PER_DRAW = 8;
11
+ /** A point light. Plain data: change any field at any time, the next `update` reads it. */
12
+ export interface PointLight {
13
+ /** Position in the coordinates the renderer draws in. */
14
+ position: [number, number, number];
15
+ /** Linear colour (0–1 per channel, may exceed 1). */
16
+ color: [number, number, number];
17
+ /** Reach in metres: the light fades to zero there. */
18
+ radius: number;
19
+ /** Brightness multiplier. */
20
+ intensity: number;
21
+ /** Flicker 0–1 (0 steady). The phase follows the light, not its slot in the selection. */
22
+ flicker?: number;
23
+ /**
24
+ * Gain group (default 0): the light's brightness is also multiplied by `PointLightSet.gains[group]`, which the owner
25
+ * changes at run time (for example to fade a whole group in and out).
26
+ */
27
+ group?: number;
28
+ }
29
+ export interface PointLightSetOptions {
30
+ /** Most lights selected per frame (the size of the uniform block). Default 32. */
31
+ max?: number;
32
+ /** Number of gain groups (`gains`). Default 4. */
33
+ groups?: number;
34
+ /** Lights darker than this after gains are skipped. Default 0.02. */
35
+ threshold?: number;
36
+ }
37
+ /** GLSL of the `<point-lights>` include for a block of `max` lights. Needs `u_time` of the Frame block. */
38
+ export declare function pointLightsGlsl(max: number): string;
39
+ /**
40
+ * A set of point lights: owns the `PointLights` uniform block and registers the `<point-lights>` include on the
41
+ * renderer. Make it before compiling the materials that include it. Call `update(eye)` once per frame before rendering.
42
+ */
43
+ export declare class PointLightSet {
44
+ readonly max: number;
45
+ /** Gain per group, 1 by default. Change at run time; read by `update`. */
46
+ readonly gains: Float32Array;
47
+ /** Lights darker than this after gains are skipped. */
48
+ threshold: number;
49
+ /** Lights selected in the last `update`. */
50
+ count: number;
51
+ /**
52
+ * Draws since the last `update` that more than `POINT_LIGHTS_PER_DRAW` selected lights reach, and that therefore
53
+ * visit the whole selection (`bindFor`). Many of them mean the pieces are large for the lights; for statistics.
54
+ */
55
+ crowdedDraws: number;
56
+ private readonly list;
57
+ private readonly block;
58
+ /** The block's contents: two vec4 per light, then the info vec4. */
59
+ private readonly data;
60
+ private readonly best;
61
+ private readonly score;
62
+ /** Spheres of the selected lights, for the per-draw lists. */
63
+ private readonly sx;
64
+ private readonly sy;
65
+ private readonly sz;
66
+ private readonly sr;
67
+ private readonly ids;
68
+ constructor(renderer: Renderer, o?: PointLightSetOptions);
69
+ /** Every light of the set (selected or not). */
70
+ get lights(): readonly PointLight[];
71
+ add(light: PointLight): void;
72
+ addAll(lights: readonly PointLight[]): void;
73
+ /** Takes a light out; returns whether it was there. */
74
+ remove(light: PointLight): boolean;
75
+ clear(): void;
76
+ private brightness;
77
+ /**
78
+ * Chooses up to `max` lights for the eye at (x, y, z): nearer and larger first, dark ones skipped. Packs and uploads
79
+ * the block. Call once per frame before rendering.
80
+ */
81
+ update(x: number, y: number, z: number): void;
82
+ /**
83
+ * Fills `out` with the indices of the selected lights whose sphere reaches the box, at most its length, in order of
84
+ * importance. Returns how many reach the box, which may be more than `out` holds.
85
+ */
86
+ lightsFor(box: Box3, out: Int32Array): number;
87
+ /**
88
+ * Sets the per-draw list of `program` (in use) to the lights that reach `box`, or to none. When more than
89
+ * `POINT_LIGHTS_PER_DRAW` reach it, the draw gets the whole selection instead (no light is dropped from the image;
90
+ * counted in `crowdedDraws`).
91
+ */
92
+ bindFor(program: Program, box: Box3): void;
93
+ /** Sets the per-draw list of `program` (in use) to the whole selection (the state of a fresh program). */
94
+ bindAll(program: Program): void;
95
+ /** Sets the per-draw list of `program` (in use) to no light. */
96
+ bindNone(program: Program): void;
97
+ }
@@ -0,0 +1,243 @@
1
+ // Point lights: a list of plain records the owner may change at any time, and per frame the few that matter most for
2
+ // the eye, packed into one uniform block (`PointLights`) uploaded once per frame. Any material reads them through the
3
+ // include `<point-lights>` (registered by the set): `pointLights(world, normal, wrap)`.
4
+ //
5
+ // The cost per pixel does not grow with the number of lights. A draw names at most `POINT_LIGHTS_PER_DRAW` of the
6
+ // selected lights in two `ivec4` uniforms (`u_lightListA`, `u_lightListB`); the shader visits only those. `PieceLayer`
7
+ // fills the list per piece from the lights whose sphere reaches the piece's box (`bindFor`); a piece that more lights
8
+ // reach gets the whole selection rather than lose some (so the cost per pixel is bounded by `max`, never by the number
9
+ // of lights in the set; `crowdedDraws` counts those draws). A draw that sets no list
10
+ // sees the whole selection (the uniforms start at 0), as an instanced set spread over the scene does (`bindAll`).
11
+ //
12
+ // Encoding of the list: entry k holds selected light index + 1; 0 ends the list. A first entry of 0 means "no list:
13
+ // the whole selection", −1 means "no light".
14
+ //
15
+ // Selection, packing and the per-draw lists allocate nothing: the arrays are made with the set.
16
+ /**
17
+ * Binding point of the `PointLights` uniform block. Programs get their block bound to it by the device
18
+ * (`UBO_BINDING.PointLights` in gpu); the value must stay equal to it.
19
+ */
20
+ export const POINT_LIGHTS_BINDING = 2;
21
+ /** Most lights one draw visits (two `ivec4` of indices). */
22
+ export const POINT_LIGHTS_PER_DRAW = 8;
23
+ /** GLSL of the `<point-lights>` include for a block of `max` lights. Needs `u_time` of the Frame block. */
24
+ export function pointLightsGlsl(max) {
25
+ return /* glsl */ `
26
+ layout(std140) uniform PointLights {
27
+ vec4 u_pointLights[${max * 2}]; // per light: xyz position, w radius; rgb colour × intensity × gain, w id + flicker
28
+ vec4 u_pointLightInfo; // x lights in the block
29
+ };
30
+ uniform ivec4 u_lightListA;
31
+ uniform ivec4 u_lightListB;
32
+ vec3 pointLightAt(int i, vec3 w, vec3 n, float wrap) {
33
+ vec4 a = u_pointLights[i * 2];
34
+ vec4 b = u_pointLights[i * 2 + 1];
35
+ vec3 d = a.xyz - w;
36
+ float d2 = dot(d, d);
37
+ float r2 = a.w * a.w;
38
+ if (d2 >= r2) return vec3(0.0);
39
+ float att = 1.0 - d2 / r2;
40
+ att *= att;
41
+ float lam = clamp((dot(n, d * inversesqrt(d2 + 1e-4)) + wrap) / (1.0 + wrap), 0.0, 1.0);
42
+ float fl = fract(b.w);
43
+ float fi = floor(b.w);
44
+ float t = u_time.x;
45
+ float flick = 1.0 - fl * (0.35 + 0.35 * sin(t * 8.7 + fi * 7.31) * sin(t * 5.3 + fi * 3.17) + 0.3 * sin(t * 13.1 + fi));
46
+ return b.rgb * att * lam * flick;
47
+ }
48
+ // Sum of the point lights at world point w with unit normal n; wrap > 0 lets light reach round the terminator.
49
+ vec3 pointLights(vec3 w, vec3 n, float wrap) {
50
+ vec3 sum = vec3(0.0);
51
+ int first = u_lightListA.x;
52
+ if (first < 0) return sum;
53
+ if (first == 0) {
54
+ int c = int(u_pointLightInfo.x);
55
+ for (int i = 0; i < ${max}; i++) {
56
+ if (i >= c) break;
57
+ sum += pointLightAt(i, w, n, wrap);
58
+ }
59
+ return sum;
60
+ }
61
+ for (int k = 0; k < ${POINT_LIGHTS_PER_DRAW}; k++) {
62
+ int id = k < 4 ? u_lightListA[k] : u_lightListB[k - 4];
63
+ if (id <= 0) break;
64
+ sum += pointLightAt(id - 1, w, n, wrap);
65
+ }
66
+ return sum;
67
+ }
68
+ `;
69
+ }
70
+ /**
71
+ * A set of point lights: owns the `PointLights` uniform block and registers the `<point-lights>` include on the
72
+ * renderer. Make it before compiling the materials that include it. Call `update(eye)` once per frame before rendering.
73
+ */
74
+ export class PointLightSet {
75
+ max;
76
+ /** Gain per group, 1 by default. Change at run time; read by `update`. */
77
+ gains;
78
+ /** Lights darker than this after gains are skipped. */
79
+ threshold;
80
+ /** Lights selected in the last `update`. */
81
+ count = 0;
82
+ /**
83
+ * Draws since the last `update` that more than `POINT_LIGHTS_PER_DRAW` selected lights reach, and that therefore
84
+ * visit the whole selection (`bindFor`). Many of them mean the pieces are large for the lights; for statistics.
85
+ */
86
+ crowdedDraws = 0;
87
+ list = [];
88
+ block;
89
+ /** The block's contents: two vec4 per light, then the info vec4. */
90
+ data;
91
+ best;
92
+ score;
93
+ /** Spheres of the selected lights, for the per-draw lists. */
94
+ sx;
95
+ sy;
96
+ sz;
97
+ sr;
98
+ ids = new Int32Array(POINT_LIGHTS_PER_DRAW);
99
+ constructor(renderer, o = {}) {
100
+ this.max = Math.max(1, Math.floor(o.max ?? 32));
101
+ this.gains = new Float32Array(Math.max(1, Math.floor(o.groups ?? 4))).fill(1);
102
+ this.threshold = o.threshold ?? 0.02;
103
+ this.data = new Float32Array(this.max * 8 + 4);
104
+ this.best = new Int32Array(this.max);
105
+ this.score = new Float64Array(this.max);
106
+ this.sx = new Float32Array(this.max);
107
+ this.sy = new Float32Array(this.max);
108
+ this.sz = new Float32Array(this.max);
109
+ this.sr = new Float32Array(this.max);
110
+ renderer.includes.set('point-lights', pointLightsGlsl(this.max));
111
+ this.block = renderer.device.uniformBlock(POINT_LIGHTS_BINDING, this.data, true);
112
+ }
113
+ /** Every light of the set (selected or not). */
114
+ get lights() {
115
+ return this.list;
116
+ }
117
+ add(light) {
118
+ this.list.push(light);
119
+ }
120
+ addAll(lights) {
121
+ for (const l of lights)
122
+ this.list.push(l);
123
+ }
124
+ /** Takes a light out; returns whether it was there. */
125
+ remove(light) {
126
+ const i = this.list.indexOf(light);
127
+ if (i < 0)
128
+ return false;
129
+ this.list.splice(i, 1);
130
+ return true;
131
+ }
132
+ clear() {
133
+ this.list.length = 0;
134
+ }
135
+ brightness(l) {
136
+ const g = this.gains[l.group ?? 0] ?? 1;
137
+ return l.intensity * g;
138
+ }
139
+ /**
140
+ * Chooses up to `max` lights for the eye at (x, y, z): nearer and larger first, dark ones skipped. Packs and uploads
141
+ * the block. Call once per frame before rendering.
142
+ */
143
+ update(x, y, z) {
144
+ const max = this.max;
145
+ const best = this.best;
146
+ const score = this.score;
147
+ let n = 0;
148
+ for (let i = 0; i < this.list.length; i++) {
149
+ const l = this.list[i];
150
+ if (l.radius <= 0 || this.brightness(l) < this.threshold)
151
+ continue;
152
+ const dx = l.position[0] - x, dy = l.position[1] - y, dz = l.position[2] - z;
153
+ const s = Math.sqrt(dx * dx + dy * dy + dz * dz) - l.radius * 2;
154
+ let k;
155
+ if (n < max)
156
+ k = n++;
157
+ else if (s < score[max - 1])
158
+ k = max - 1;
159
+ else
160
+ continue;
161
+ // Insertion into the sorted list of the best so far.
162
+ while (k > 0 && score[k - 1] > s) {
163
+ score[k] = score[k - 1];
164
+ best[k] = best[k - 1];
165
+ k--;
166
+ }
167
+ score[k] = s;
168
+ best[k] = i;
169
+ }
170
+ const d = this.data;
171
+ for (let k = 0; k < n; k++) {
172
+ const id = best[k];
173
+ const l = this.list[id];
174
+ const on = this.brightness(l);
175
+ const o = k * 8;
176
+ d[o] = this.sx[k] = l.position[0];
177
+ d[o + 1] = this.sy[k] = l.position[1];
178
+ d[o + 2] = this.sz[k] = l.position[2];
179
+ d[o + 3] = this.sr[k] = l.radius;
180
+ d[o + 4] = l.color[0] * on;
181
+ d[o + 5] = l.color[1] * on;
182
+ d[o + 6] = l.color[2] * on;
183
+ d[o + 7] = id + Math.min(Math.max(l.flicker ?? 0, 0), 0.999);
184
+ }
185
+ d[max * 8] = n;
186
+ this.count = n;
187
+ this.crowdedDraws = 0;
188
+ this.block.update(d);
189
+ }
190
+ /**
191
+ * Fills `out` with the indices of the selected lights whose sphere reaches the box, at most its length, in order of
192
+ * importance. Returns how many reach the box, which may be more than `out` holds.
193
+ */
194
+ lightsFor(box, out) {
195
+ let m = 0;
196
+ const cap = out.length;
197
+ for (let k = 0; k < this.count; k++) {
198
+ const x = this.sx[k], y = this.sy[k], z = this.sz[k], r = this.sr[k];
199
+ const ex = x < box.min[0] ? box.min[0] - x : x > box.max[0] ? x - box.max[0] : 0;
200
+ const ey = y < box.min[1] ? box.min[1] - y : y > box.max[1] ? y - box.max[1] : 0;
201
+ const ez = z < box.min[2] ? box.min[2] - z : z > box.max[2] ? z - box.max[2] : 0;
202
+ if (ex * ex + ey * ey + ez * ez < r * r) {
203
+ if (m < cap)
204
+ out[m] = k;
205
+ m++;
206
+ }
207
+ }
208
+ return m;
209
+ }
210
+ /**
211
+ * Sets the per-draw list of `program` (in use) to the lights that reach `box`, or to none. When more than
212
+ * `POINT_LIGHTS_PER_DRAW` reach it, the draw gets the whole selection instead (no light is dropped from the image;
213
+ * counted in `crowdedDraws`).
214
+ */
215
+ bindFor(program, box) {
216
+ const ids = this.ids;
217
+ const m = this.lightsFor(box, ids);
218
+ if (m === 0) {
219
+ program.ivec4('u_lightListA', -1, 0, 0, 0);
220
+ return;
221
+ }
222
+ if (m > POINT_LIGHTS_PER_DRAW) {
223
+ this.crowdedDraws++;
224
+ program.ivec4('u_lightListA', 0, 0, 0, 0);
225
+ return;
226
+ }
227
+ // Selected index + 1, and 0 after the last one (`ids` past `m` are set to −1 here).
228
+ for (let k = m; k < POINT_LIGHTS_PER_DRAW; k++)
229
+ ids[k] = -1;
230
+ program.ivec4('u_lightListA', ids[0] + 1, ids[1] + 1, ids[2] + 1, ids[3] + 1);
231
+ // With fewer than four the list ends inside A and B is never read.
232
+ if (m >= 4)
233
+ program.ivec4('u_lightListB', ids[4] + 1, ids[5] + 1, ids[6] + 1, ids[7] + 1);
234
+ }
235
+ /** Sets the per-draw list of `program` (in use) to the whole selection (the state of a fresh program). */
236
+ bindAll(program) {
237
+ program.ivec4('u_lightListA', 0, 0, 0, 0);
238
+ }
239
+ /** Sets the per-draw list of `program` (in use) to no light. */
240
+ bindNone(program) {
241
+ program.ivec4('u_lightListA', -1, 0, 0, 0);
242
+ }
243
+ }