webgpu-trees 0.0.0-stage → 0.2.0

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 (330) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1547 -2
  3. package/assets/SOURCES.md +263 -0
  4. package/assets/bark/alder.albedo.avif +0 -0
  5. package/assets/bark/alder.normal.avif +0 -0
  6. package/assets/bark/aleppoPine.albedo.avif +0 -0
  7. package/assets/bark/aleppoPine.normal.avif +0 -0
  8. package/assets/bark/ash.albedo.avif +0 -0
  9. package/assets/bark/ash.normal.avif +0 -0
  10. package/assets/bark/aspen.albedo.avif +0 -0
  11. package/assets/bark/aspen.normal.avif +0 -0
  12. package/assets/bark/beech.albedo.avif +0 -0
  13. package/assets/bark/beech.normal.avif +0 -0
  14. package/assets/bark/birch.albedo.avif +0 -0
  15. package/assets/bark/birch.normal.avif +0 -0
  16. package/assets/bark/birchFoot.albedo.avif +0 -0
  17. package/assets/bark/birchFoot.normal.avif +0 -0
  18. package/assets/bark/corsicanPine.albedo.avif +0 -0
  19. package/assets/bark/corsicanPine.normal.avif +0 -0
  20. package/assets/bark/cypress.albedo.avif +0 -0
  21. package/assets/bark/cypress.normal.avif +0 -0
  22. package/assets/bark/douglas.albedo.avif +0 -0
  23. package/assets/bark/douglas.normal.avif +0 -0
  24. package/assets/bark/eucalyptus.albedo.avif +0 -0
  25. package/assets/bark/eucalyptus.normal.avif +0 -0
  26. package/assets/bark/eucalyptusUpper.albedo.avif +0 -0
  27. package/assets/bark/eucalyptusUpper.normal.avif +0 -0
  28. package/assets/bark/fibrous.albedo.avif +0 -0
  29. package/assets/bark/fibrous.normal.avif +0 -0
  30. package/assets/bark/hemlock.albedo.avif +0 -0
  31. package/assets/bark/hemlock.normal.avif +0 -0
  32. package/assets/bark/hornbeam.albedo.avif +0 -0
  33. package/assets/bark/hornbeam.normal.avif +0 -0
  34. package/assets/bark/larch.albedo.avif +0 -0
  35. package/assets/bark/larch.normal.avif +0 -0
  36. package/assets/bark/lime.albedo.avif +0 -0
  37. package/assets/bark/lime.normal.avif +0 -0
  38. package/assets/bark/liveOak.albedo.avif +0 -0
  39. package/assets/bark/liveOak.normal.avif +0 -0
  40. package/assets/bark/magnolia.albedo.avif +0 -0
  41. package/assets/bark/magnolia.normal.avif +0 -0
  42. package/assets/bark/maple.albedo.avif +0 -0
  43. package/assets/bark/maple.normal.avif +0 -0
  44. package/assets/bark/montereyPine.albedo.avif +0 -0
  45. package/assets/bark/montereyPine.normal.avif +0 -0
  46. package/assets/bark/norMaple.albedo.avif +0 -0
  47. package/assets/bark/norMaple.normal.avif +0 -0
  48. package/assets/bark/oak.albedo.avif +0 -0
  49. package/assets/bark/oak.normal.avif +0 -0
  50. package/assets/bark/palmLattice.albedo.avif +0 -0
  51. package/assets/bark/palmLattice.normal.avif +0 -0
  52. package/assets/bark/palmPineapple.albedo.avif +0 -0
  53. package/assets/bark/palmPineapple.normal.avif +0 -0
  54. package/assets/bark/palmRings.albedo.avif +0 -0
  55. package/assets/bark/palmRings.normal.avif +0 -0
  56. package/assets/bark/pine.albedo.avif +0 -0
  57. package/assets/bark/pine.normal.avif +0 -0
  58. package/assets/bark/pineFlakes.albedo.avif +0 -0
  59. package/assets/bark/pineFlakes.normal.avif +0 -0
  60. package/assets/bark/plane.albedo.avif +0 -0
  61. package/assets/bark/plane.normal.avif +0 -0
  62. package/assets/bark/poplar.albedo.avif +0 -0
  63. package/assets/bark/poplar.normal.avif +0 -0
  64. package/assets/bark/redAlder.albedo.avif +0 -0
  65. package/assets/bark/redAlder.normal.avif +0 -0
  66. package/assets/bark/redOak.albedo.avif +0 -0
  67. package/assets/bark/redOak.normal.avif +0 -0
  68. package/assets/bark/ridged.albedo.avif +0 -0
  69. package/assets/bark/ridged.normal.avif +0 -0
  70. package/assets/bark/sitkaSpruce.albedo.avif +0 -0
  71. package/assets/bark/sitkaSpruce.normal.avif +0 -0
  72. package/assets/bark/spruce.albedo.avif +0 -0
  73. package/assets/bark/spruce.normal.avif +0 -0
  74. package/assets/bark/stonePine.albedo.avif +0 -0
  75. package/assets/bark/stonePine.normal.avif +0 -0
  76. package/assets/bark/sweetgum.albedo.avif +0 -0
  77. package/assets/bark/sweetgum.normal.avif +0 -0
  78. package/assets/bark/sycMaple.albedo.avif +0 -0
  79. package/assets/bark/sycMaple.normal.avif +0 -0
  80. package/assets/bark/torreyPine.albedo.avif +0 -0
  81. package/assets/bark/torreyPine.normal.avif +0 -0
  82. package/assets/bark/whitePine.albedo.avif +0 -0
  83. package/assets/bark/whitePine.normal.avif +0 -0
  84. package/assets/bark/whiteSpruce.albedo.avif +0 -0
  85. package/assets/bark/whiteSpruce.normal.avif +0 -0
  86. package/assets/bark/whiteWillow.albedo.avif +0 -0
  87. package/assets/bark/whiteWillow.normal.avif +0 -0
  88. package/assets/bark/willow.albedo.avif +0 -0
  89. package/assets/bark/willow.normal.avif +0 -0
  90. package/assets/leaves/alder.albedo.avif +0 -0
  91. package/assets/leaves/alder.normal.avif +0 -0
  92. package/assets/leaves/ash.albedo.avif +0 -0
  93. package/assets/leaves/ash.normal.avif +0 -0
  94. package/assets/leaves/aspen.albedo.avif +0 -0
  95. package/assets/leaves/aspen.normal.avif +0 -0
  96. package/assets/leaves/beech.albedo.avif +0 -0
  97. package/assets/leaves/beech.normal.avif +0 -0
  98. package/assets/leaves/birch.albedo.avif +0 -0
  99. package/assets/leaves/birch.normal.avif +0 -0
  100. package/assets/leaves/blackthorn.albedo.avif +0 -0
  101. package/assets/leaves/blackthorn.normal.avif +0 -0
  102. package/assets/leaves/blade.albedo.avif +0 -0
  103. package/assets/leaves/blade.normal.avif +0 -0
  104. package/assets/leaves/broomSprig.albedo.avif +0 -0
  105. package/assets/leaves/broomSprig.normal.avif +0 -0
  106. package/assets/leaves/corsicanShoot.albedo.avif +0 -0
  107. package/assets/leaves/corsicanShoot.normal.avif +0 -0
  108. package/assets/leaves/cypress.albedo.avif +0 -0
  109. package/assets/leaves/cypress.normal.avif +0 -0
  110. package/assets/leaves/cypressPad.albedo.avif +0 -0
  111. package/assets/leaves/cypressPad.normal.avif +0 -0
  112. package/assets/leaves/deadFronds.albedo.avif +0 -0
  113. package/assets/leaves/deadFronds.normal.avif +0 -0
  114. package/assets/leaves/deltoid.albedo.avif +0 -0
  115. package/assets/leaves/deltoid.normal.avif +0 -0
  116. package/assets/leaves/douglasShoot.albedo.avif +0 -0
  117. package/assets/leaves/douglasShoot.normal.avif +0 -0
  118. package/assets/leaves/elderSprig.albedo.avif +0 -0
  119. package/assets/leaves/elderSprig.normal.avif +0 -0
  120. package/assets/leaves/elliptic.albedo.avif +0 -0
  121. package/assets/leaves/elliptic.normal.avif +0 -0
  122. package/assets/leaves/eucalyptus.albedo.avif +0 -0
  123. package/assets/leaves/eucalyptus.normal.avif +0 -0
  124. package/assets/leaves/fan.albedo.avif +0 -0
  125. package/assets/leaves/fan.normal.avif +0 -0
  126. package/assets/leaves/fanB.albedo.avif +0 -0
  127. package/assets/leaves/fanB.normal.avif +0 -0
  128. package/assets/leaves/fir.albedo.avif +0 -0
  129. package/assets/leaves/fir.normal.avif +0 -0
  130. package/assets/leaves/frond.albedo.avif +0 -0
  131. package/assets/leaves/frond.normal.avif +0 -0
  132. package/assets/leaves/gorse.albedo.avif +0 -0
  133. package/assets/leaves/gorse.normal.avif +0 -0
  134. package/assets/leaves/hawthorn.albedo.avif +0 -0
  135. package/assets/leaves/hawthorn.normal.avif +0 -0
  136. package/assets/leaves/hemlockShoot.albedo.avif +0 -0
  137. package/assets/leaves/hemlockShoot.normal.avif +0 -0
  138. package/assets/leaves/hornbeam.albedo.avif +0 -0
  139. package/assets/leaves/hornbeam.normal.avif +0 -0
  140. package/assets/leaves/lance.albedo.avif +0 -0
  141. package/assets/leaves/lance.normal.avif +0 -0
  142. package/assets/leaves/larchShoot.albedo.avif +0 -0
  143. package/assets/leaves/larchShoot.normal.avif +0 -0
  144. package/assets/leaves/lime.albedo.avif +0 -0
  145. package/assets/leaves/lime.normal.avif +0 -0
  146. package/assets/leaves/liveOak.albedo.avif +0 -0
  147. package/assets/leaves/liveOak.normal.avif +0 -0
  148. package/assets/leaves/londonPlane.albedo.avif +0 -0
  149. package/assets/leaves/londonPlane.normal.avif +0 -0
  150. package/assets/leaves/magnolia.albedo.avif +0 -0
  151. package/assets/leaves/magnolia.normal.avif +0 -0
  152. package/assets/leaves/maple.albedo.avif +0 -0
  153. package/assets/leaves/maple.normal.avif +0 -0
  154. package/assets/leaves/norMaple.albedo.avif +0 -0
  155. package/assets/leaves/norMaple.normal.avif +0 -0
  156. package/assets/leaves/oak.albedo.avif +0 -0
  157. package/assets/leaves/oak.normal.avif +0 -0
  158. package/assets/leaves/paintFan.albedo.avif +0 -0
  159. package/assets/leaves/paintFan.normal.avif +0 -0
  160. package/assets/leaves/paintFrond.albedo.avif +0 -0
  161. package/assets/leaves/paintFrond.normal.avif +0 -0
  162. package/assets/leaves/pine.albedo.avif +0 -0
  163. package/assets/leaves/pine.normal.avif +0 -0
  164. package/assets/leaves/pineClumpDark.albedo.avif +0 -0
  165. package/assets/leaves/pineClumpDark.normal.avif +0 -0
  166. package/assets/leaves/pineClumpLight.albedo.avif +0 -0
  167. package/assets/leaves/pineClumpLight.normal.avif +0 -0
  168. package/assets/leaves/poplar.albedo.avif +0 -0
  169. package/assets/leaves/poplar.normal.avif +0 -0
  170. package/assets/leaves/queenFrond.albedo.avif +0 -0
  171. package/assets/leaves/queenFrond.normal.avif +0 -0
  172. package/assets/leaves/redAlder.albedo.avif +0 -0
  173. package/assets/leaves/redAlder.normal.avif +0 -0
  174. package/assets/leaves/redOak.albedo.avif +0 -0
  175. package/assets/leaves/redOak.normal.avif +0 -0
  176. package/assets/leaves/round.albedo.avif +0 -0
  177. package/assets/leaves/round.normal.avif +0 -0
  178. package/assets/leaves/scale.albedo.avif +0 -0
  179. package/assets/leaves/scale.normal.avif +0 -0
  180. package/assets/leaves/scotsPineClump.albedo.avif +0 -0
  181. package/assets/leaves/scotsPineClump.normal.avif +0 -0
  182. package/assets/leaves/seaBuckthornSprig.albedo.avif +0 -0
  183. package/assets/leaves/seaBuckthornSprig.normal.avif +0 -0
  184. package/assets/leaves/serrate.albedo.avif +0 -0
  185. package/assets/leaves/serrate.normal.avif +0 -0
  186. package/assets/leaves/sitkaShoot.albedo.avif +0 -0
  187. package/assets/leaves/sitkaShoot.normal.avif +0 -0
  188. package/assets/leaves/stonePineCanopy.albedo.avif +0 -0
  189. package/assets/leaves/stonePineCanopy.normal.avif +0 -0
  190. package/assets/leaves/stonePineCushion.albedo.avif +0 -0
  191. package/assets/leaves/stonePineCushion.normal.avif +0 -0
  192. package/assets/leaves/sweetgum.albedo.avif +0 -0
  193. package/assets/leaves/sweetgum.normal.avif +0 -0
  194. package/assets/leaves/sycamore.albedo.avif +0 -0
  195. package/assets/leaves/sycamore.normal.avif +0 -0
  196. package/assets/leaves/torreyPine.albedo.avif +0 -0
  197. package/assets/leaves/torreyPine.normal.avif +0 -0
  198. package/assets/leaves/whitePine.albedo.avif +0 -0
  199. package/assets/leaves/whitePine.normal.avif +0 -0
  200. package/assets/leaves/whiteSpruceShoot.albedo.avif +0 -0
  201. package/assets/leaves/whiteSpruceShoot.normal.avif +0 -0
  202. package/assets/leaves/whiteWillow.albedo.avif +0 -0
  203. package/assets/leaves/whiteWillow.normal.avif +0 -0
  204. package/assets/leaves/willow.albedo.avif +0 -0
  205. package/assets/leaves/willow.normal.avif +0 -0
  206. package/assets/marks/marks.json +894 -0
  207. package/assets/marks/painterly.avif +0 -0
  208. package/assets/marks/sheets.avif +0 -0
  209. package/assets/scans.json +6406 -0
  210. package/lib/age.d.ts +36 -0
  211. package/lib/age.d.ts.map +1 -0
  212. package/lib/age.js +170 -0
  213. package/lib/age.js.map +1 -0
  214. package/lib/atmosphere.d.ts +64 -0
  215. package/lib/atmosphere.d.ts.map +1 -0
  216. package/lib/atmosphere.js +260 -0
  217. package/lib/atmosphere.js.map +1 -0
  218. package/lib/dabs.d.ts +4 -0
  219. package/lib/dabs.d.ts.map +1 -0
  220. package/lib/dabs.js +77 -0
  221. package/lib/dabs.js.map +1 -0
  222. package/lib/engine.d.ts +211 -0
  223. package/lib/engine.d.ts.map +1 -0
  224. package/lib/engine.js +3808 -0
  225. package/lib/engine.js.map +1 -0
  226. package/lib/genetics.d.ts +129 -0
  227. package/lib/genetics.d.ts.map +1 -0
  228. package/lib/genetics.js +721 -0
  229. package/lib/genetics.js.map +1 -0
  230. package/lib/geometry.d.ts +237 -0
  231. package/lib/geometry.d.ts.map +1 -0
  232. package/lib/geometry.js +1944 -0
  233. package/lib/geometry.js.map +1 -0
  234. package/lib/grow.d.ts +83 -0
  235. package/lib/grow.d.ts.map +1 -0
  236. package/lib/grow.js +3851 -0
  237. package/lib/grow.js.map +1 -0
  238. package/lib/hiz.d.ts +74 -0
  239. package/lib/hiz.d.ts.map +1 -0
  240. package/lib/hiz.js +161 -0
  241. package/lib/hiz.js.map +1 -0
  242. package/lib/impostor.d.ts +106 -0
  243. package/lib/impostor.d.ts.map +1 -0
  244. package/lib/impostor.js +450 -0
  245. package/lib/impostor.js.map +1 -0
  246. package/lib/index.d.ts +17 -0
  247. package/lib/index.d.ts.map +1 -0
  248. package/lib/index.js +16 -0
  249. package/lib/index.js.map +1 -0
  250. package/lib/leaves.d.ts +30 -0
  251. package/lib/leaves.d.ts.map +1 -0
  252. package/lib/leaves.js +829 -0
  253. package/lib/leaves.js.map +1 -0
  254. package/lib/light.d.ts +110 -0
  255. package/lib/light.d.ts.map +1 -0
  256. package/lib/light.js +430 -0
  257. package/lib/light.js.map +1 -0
  258. package/lib/lobes.d.ts +25 -0
  259. package/lib/lobes.d.ts.map +1 -0
  260. package/lib/lobes.js +151 -0
  261. package/lib/lobes.js.map +1 -0
  262. package/lib/marks.d.ts +63 -0
  263. package/lib/marks.d.ts.map +1 -0
  264. package/lib/marks.js +553 -0
  265. package/lib/marks.js.map +1 -0
  266. package/lib/mips.d.ts +42 -0
  267. package/lib/mips.d.ts.map +1 -0
  268. package/lib/mips.js +220 -0
  269. package/lib/mips.js.map +1 -0
  270. package/lib/paintedMarks.d.ts +21 -0
  271. package/lib/paintedMarks.d.ts.map +1 -0
  272. package/lib/paintedMarks.js +53 -0
  273. package/lib/paintedMarks.js.map +1 -0
  274. package/lib/palm.d.ts +162 -0
  275. package/lib/palm.d.ts.map +1 -0
  276. package/lib/palm.js +779 -0
  277. package/lib/palm.js.map +1 -0
  278. package/lib/palmAtlas.d.ts +79 -0
  279. package/lib/palmAtlas.d.ts.map +1 -0
  280. package/lib/palmAtlas.js +335 -0
  281. package/lib/palmAtlas.js.map +1 -0
  282. package/lib/palmGeometry.d.ts +41 -0
  283. package/lib/palmGeometry.d.ts.map +1 -0
  284. package/lib/palmGeometry.js +309 -0
  285. package/lib/palmGeometry.js.map +1 -0
  286. package/lib/phenology.d.ts +21 -0
  287. package/lib/phenology.d.ts.map +1 -0
  288. package/lib/phenology.js +168 -0
  289. package/lib/phenology.js.map +1 -0
  290. package/lib/random.d.ts +34 -0
  291. package/lib/random.d.ts.map +1 -0
  292. package/lib/random.js +92 -0
  293. package/lib/random.js.map +1 -0
  294. package/lib/scans.d.ts +232 -0
  295. package/lib/scans.d.ts.map +1 -0
  296. package/lib/scans.js +397 -0
  297. package/lib/scans.js.map +1 -0
  298. package/lib/scatter.d.ts +70 -0
  299. package/lib/scatter.d.ts.map +1 -0
  300. package/lib/scatter.js +186 -0
  301. package/lib/scatter.js.map +1 -0
  302. package/lib/species.d.ts +369 -0
  303. package/lib/species.d.ts.map +1 -0
  304. package/lib/species.js +2978 -0
  305. package/lib/species.js.map +1 -0
  306. package/lib/sprays.d.ts +112 -0
  307. package/lib/sprays.d.ts.map +1 -0
  308. package/lib/sprays.js +1137 -0
  309. package/lib/sprays.js.map +1 -0
  310. package/lib/stand.d.ts +52 -0
  311. package/lib/stand.d.ts.map +1 -0
  312. package/lib/stand.js +279 -0
  313. package/lib/stand.js.map +1 -0
  314. package/lib/styles.d.ts +135 -0
  315. package/lib/styles.d.ts.map +1 -0
  316. package/lib/styles.js +79 -0
  317. package/lib/styles.js.map +1 -0
  318. package/lib/tree.d.ts +134 -0
  319. package/lib/tree.d.ts.map +1 -0
  320. package/lib/tree.js +57 -0
  321. package/lib/tree.js.map +1 -0
  322. package/lib/variants.d.ts +157 -0
  323. package/lib/variants.d.ts.map +1 -0
  324. package/lib/variants.js +532 -0
  325. package/lib/variants.js.map +1 -0
  326. package/lib/visibility.d.ts +105 -0
  327. package/lib/visibility.d.ts.map +1 -0
  328. package/lib/visibility.js +242 -0
  329. package/lib/visibility.js.map +1 -0
  330. package/package.json +62 -3
package/lib/hiz.d.ts ADDED
@@ -0,0 +1,74 @@
1
+ /** Width and height of the internal Hi-Z pyramid's base level. */
2
+ export declare const HIZ_BASE_W = 256;
3
+ export declare const HIZ_BASE_H = 128;
4
+ /** 24-bit unsigned integer scale for conservative atomicMin/atomicMax depth storage. */
5
+ export declare const HIZ_MAX_UINT = 16777215;
6
+ /**
7
+ * How trees occluded behind terrain or dense forest canopies are culled on the GPU:
8
+ * - `off`: frustum + range only (all in-frustum trees within range are drawn);
9
+ * - `canopy`: zero-setup GPU compute canopy occlusion (dense crowns splatted to Hi-Z);
10
+ * - `depth`: external scene DepthTexture (`trees.setDepthTexture`) downsampled to Hi-Z.
11
+ */
12
+ export type OcclusionMode = "off" | "canopy" | "depth";
13
+ export declare const OCCLUSION_MODES: readonly OcclusionMode[];
14
+ export interface HiZLevel {
15
+ width: number;
16
+ height: number;
17
+ offset: number;
18
+ }
19
+ export interface HiZLayout {
20
+ levels: readonly HiZLevel[];
21
+ total: number;
22
+ }
23
+ /** Offsets and dimensions of every mip level of a `baseW x baseH` Hi-Z pyramid packed into one Uint32 buffer. */
24
+ export declare function hizLayout(baseW?: number, baseH?: number): HiZLayout;
25
+ /**
26
+ * Analytical NDC depth in `[0, 1]` for positive view-space depth `zc > 0`, matching Three.js r187 WebGPU
27
+ * perspective projection (`reversed = true`: near = 1, far = 0; `reversed = false`: near = 0, far = 1).
28
+ */
29
+ export declare function ndcDepth(zc: number, near: number, far: number, reversed: boolean): number;
30
+ /**
31
+ * Monotonic reversed-Z depth metric in `[0, HIZ_MAX_UINT]` used for Hi-Z comparison and canopy occlusion:
32
+ * 0 = clear sky at infinity, larger = closer to the camera.
33
+ */
34
+ export declare function canopyDepthMetric(zc: number, near: number): number;
35
+ /**
36
+ * Downsample mip 0 through all coarser levels using conservative `min` (furthest occluder in reversed-Z).
37
+ * When the previous level has an odd width or height, the last row/column also folds the trailing texel
38
+ * (`2x + 2` / `2y + 2`) so a 1-texel gap on an odd boundary is never skipped.
39
+ */
40
+ export declare function downsampleHiZCpu(buf: Uint32Array, layout: HiZLayout): void;
41
+ export interface HiZCamera {
42
+ x: number;
43
+ y: number;
44
+ z: number;
45
+ /** Unit camera basis vectors in world space. */
46
+ right: [number, number, number];
47
+ up: [number, number, number];
48
+ forward: [number, number, number];
49
+ near: number;
50
+ tanHalfFovY: number;
51
+ aspect: number;
52
+ }
53
+ /** Project a world-space sphere onto `[0, 1]^2` screen UV bounds and camera-space `zc`. */
54
+ export declare function projectSphereScreenBounds(cx: number, cy: number, cz: number, radius: number, cam: HiZCamera): {
55
+ u0: number;
56
+ v0: number;
57
+ u1: number;
58
+ v1: number;
59
+ zc: number;
60
+ } | null;
61
+ /**
62
+ * Splat conservative opaque canopy cores into mip 0 of a Hi-Z buffer (CPU mirror of `hizCanopySplat`).
63
+ */
64
+ export declare function splatCanopyHiZCpu(buf: Uint32Array, layout: HiZLayout, spheres: readonly {
65
+ cx: number;
66
+ cy: number;
67
+ cz: number;
68
+ radius: number;
69
+ }[], cam: HiZCamera): void;
70
+ /**
71
+ * Test whether a tree's bounding sphere is wholly occluded behind the Hi-Z pyramid.
72
+ */
73
+ export declare function isSphereOccludedHiZ(buf: Uint32Array, layout: HiZLayout, cx: number, cy: number, cz: number, radius: number, cam: HiZCamera): boolean;
74
+ //# sourceMappingURL=hiz.d.ts.map
@@ -0,0 +1 @@
1
+ {"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AAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,2FAA2F;AAC3F,wBAAgB,yBAAyB,CACvC,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,SAAS,GACb;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAqBvE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,EAC1E,GAAG,EAAE,SAAS,GACb,IAAI,CAqBN;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,SAAS,EACjB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,SAAS,GACb,OAAO,CAuBT"}
package/lib/hiz.js ADDED
@@ -0,0 +1,161 @@
1
+ // Hierarchical-Z (Hi-Z) occlusion pyramid math, layout, and CPU reference.
2
+ //
3
+ // Plain arithmetic, no three: the tests read it as it is.
4
+ /** Width and height of the internal Hi-Z pyramid's base level. */
5
+ export const HIZ_BASE_W = 256;
6
+ export const HIZ_BASE_H = 128;
7
+ /** 24-bit unsigned integer scale for conservative atomicMin/atomicMax depth storage. */
8
+ export const HIZ_MAX_UINT = 16_777_215;
9
+ export const OCCLUSION_MODES = ["off", "canopy", "depth"];
10
+ /** Offsets and dimensions of every mip level of a `baseW x baseH` Hi-Z pyramid packed into one Uint32 buffer. */
11
+ export function hizLayout(baseW = HIZ_BASE_W, baseH = HIZ_BASE_H) {
12
+ const levels = [];
13
+ let w = Math.max(1, Math.floor(baseW));
14
+ let h = Math.max(1, Math.floor(baseH));
15
+ let offset = 0;
16
+ while (true) {
17
+ levels.push({ width: w, height: h, offset });
18
+ offset += w * h;
19
+ if (w === 1 && h === 1)
20
+ break;
21
+ w = Math.max(1, w >> 1);
22
+ h = Math.max(1, h >> 1);
23
+ }
24
+ return { levels, total: offset };
25
+ }
26
+ /**
27
+ * Analytical NDC depth in `[0, 1]` for positive view-space depth `zc > 0`, matching Three.js r187 WebGPU
28
+ * perspective projection (`reversed = true`: near = 1, far = 0; `reversed = false`: near = 0, far = 1).
29
+ */
30
+ export function ndcDepth(zc, near, far, reversed) {
31
+ const z = Math.max(near, Math.min(far, zc));
32
+ if (reversed)
33
+ return (near * (far - z)) / (z * Math.max(1e-6, far - near));
34
+ return (far * (z - near)) / (z * Math.max(1e-6, far - near));
35
+ }
36
+ /**
37
+ * Monotonic reversed-Z depth metric in `[0, HIZ_MAX_UINT]` used for Hi-Z comparison and canopy occlusion:
38
+ * 0 = clear sky at infinity, larger = closer to the camera.
39
+ */
40
+ export function canopyDepthMetric(zc, near) {
41
+ const m = Math.min(1, Math.max(0, near / Math.max(zc, near)));
42
+ return Math.min(HIZ_MAX_UINT, Math.max(0, Math.round(m * HIZ_MAX_UINT)));
43
+ }
44
+ /**
45
+ * Downsample mip 0 through all coarser levels using conservative `min` (furthest occluder in reversed-Z).
46
+ * When the previous level has an odd width or height, the last row/column also folds the trailing texel
47
+ * (`2x + 2` / `2y + 2`) so a 1-texel gap on an odd boundary is never skipped.
48
+ */
49
+ export function downsampleHiZCpu(buf, layout) {
50
+ for (let l = 1; l < layout.levels.length; l++) {
51
+ const prev = layout.levels[l - 1];
52
+ const cur = layout.levels[l];
53
+ for (let y = 0; y < cur.height; y++) {
54
+ const y0 = Math.min(prev.height - 1, y * 2);
55
+ const y1 = Math.min(prev.height - 1, y * 2 + 1);
56
+ const yExtra = (prev.height & 1) === 1 && y === cur.height - 1 ? Math.min(prev.height - 1, y * 2 + 2) : y1;
57
+ for (let x = 0; x < cur.width; x++) {
58
+ const x0 = Math.min(prev.width - 1, x * 2);
59
+ const x1 = Math.min(prev.width - 1, x * 2 + 1);
60
+ const xExtra = (prev.width & 1) === 1 && x === cur.width - 1 ? Math.min(prev.width - 1, x * 2 + 2) : x1;
61
+ let m = HIZ_MAX_UINT;
62
+ const ys = [y0, y1, yExtra];
63
+ const xs = [x0, x1, xExtra];
64
+ for (let j = 0; j < 3; j++) {
65
+ for (let i = 0; i < 3; i++) {
66
+ const v = buf[prev.offset + ys[j] * prev.width + xs[i]];
67
+ if (v < m)
68
+ m = v;
69
+ }
70
+ }
71
+ buf[cur.offset + y * cur.width + x] = m;
72
+ }
73
+ }
74
+ }
75
+ }
76
+ /** Project a world-space sphere onto `[0, 1]^2` screen UV bounds and camera-space `zc`. */
77
+ export function projectSphereScreenBounds(cx, cy, cz, radius, cam) {
78
+ const dx = cx - cam.x;
79
+ const dy = cy - cam.y;
80
+ const dz = cz - cam.z;
81
+ const zc = dx * cam.forward[0] + dy * cam.forward[1] + dz * cam.forward[2];
82
+ if (zc + radius <= cam.near)
83
+ return null;
84
+ if (zc - radius <= cam.near)
85
+ return { u0: 0, v0: 0, u1: 1, v1: 1, zc };
86
+ const xc = dx * cam.right[0] + dy * cam.right[1] + dz * cam.right[2];
87
+ const yc = dx * cam.up[0] + dy * cam.up[1] + dz * cam.up[2];
88
+ const tanX = cam.tanHalfFovY * cam.aspect;
89
+ const tanY = cam.tanHalfFovY;
90
+ const uCenter = 0.5 + xc / (2 * zc * tanX);
91
+ const vCenter = 0.5 - yc / (2 * zc * tanY);
92
+ const halfU = radius / (2 * Math.max(cam.near, zc - radius) * tanX);
93
+ const halfV = radius / (2 * Math.max(cam.near, zc - radius) * tanY);
94
+ const u0 = Math.max(0, Math.min(1, uCenter - halfU));
95
+ const u1 = Math.max(0, Math.min(1, uCenter + halfU));
96
+ const v0 = Math.max(0, Math.min(1, vCenter - halfV));
97
+ const v1 = Math.max(0, Math.min(1, vCenter + halfV));
98
+ if (u1 <= 0 || u0 >= 1 || v1 <= 0 || v0 >= 1)
99
+ return null;
100
+ return { u0, v0, u1, v1, zc };
101
+ }
102
+ /**
103
+ * Splat conservative opaque canopy cores into mip 0 of a Hi-Z buffer (CPU mirror of `hizCanopySplat`).
104
+ */
105
+ export function splatCanopyHiZCpu(buf, layout, spheres, cam) {
106
+ const base = layout.levels[0];
107
+ buf.fill(0);
108
+ for (const s of spheres) {
109
+ const p = projectSphereScreenBounds(s.cx, s.cy, s.cz, s.radius, cam);
110
+ if (!p || p.zc - s.radius <= cam.near)
111
+ continue;
112
+ const x0 = Math.max(0, Math.floor(p.u0 * base.width));
113
+ const x1 = Math.min(base.width - 1, Math.floor(p.u1 * base.width));
114
+ const y0 = Math.max(0, Math.floor(p.v0 * base.height));
115
+ const y1 = Math.min(base.height - 1, Math.floor(p.v1 * base.height));
116
+ if (x1 - x0 > 64 || y1 - y0 > 64)
117
+ continue;
118
+ // Conservative far side of the opaque core sphere.
119
+ const zMetric = canopyDepthMetric(p.zc + s.radius, cam.near);
120
+ for (let y = y0; y <= y1; y++) {
121
+ for (let x = x0; x <= x1; x++) {
122
+ const idx = base.offset + y * base.width + x;
123
+ if (zMetric > buf[idx])
124
+ buf[idx] = zMetric;
125
+ }
126
+ }
127
+ }
128
+ downsampleHiZCpu(buf, layout);
129
+ }
130
+ /**
131
+ * Test whether a tree's bounding sphere is wholly occluded behind the Hi-Z pyramid.
132
+ */
133
+ export function isSphereOccludedHiZ(buf, layout, cx, cy, cz, radius, cam) {
134
+ const p = projectSphereScreenBounds(cx, cy, cz, radius, cam);
135
+ if (!p)
136
+ return false;
137
+ // Never cull a tree whose bounding sphere crosses the near plane.
138
+ if (p.zc - radius <= cam.near * 1.5)
139
+ return false;
140
+ const base = layout.levels[0];
141
+ const spanPx = Math.max((p.u1 - p.u0) * base.width, (p.v1 - p.v0) * base.height);
142
+ const mip = Math.min(layout.levels.length - 1, Math.max(0, Math.ceil(Math.log2(Math.max(1, spanPx)))));
143
+ const lv = layout.levels[mip];
144
+ const x0 = Math.max(0, Math.min(lv.width - 1, Math.floor(p.u0 * lv.width)));
145
+ const x1 = Math.max(0, Math.min(lv.width - 1, Math.floor(p.u1 * lv.width)));
146
+ const y0 = Math.max(0, Math.min(lv.height - 1, Math.floor(p.v0 * lv.height)));
147
+ const y1 = Math.max(0, Math.min(lv.height - 1, Math.floor(p.v1 * lv.height)));
148
+ let occMin = HIZ_MAX_UINT;
149
+ for (let y = y0; y <= y1; y++) {
150
+ for (let x = x0; x <= x1; x++) {
151
+ const v = buf[lv.offset + y * lv.width + x];
152
+ if (v < occMin)
153
+ occMin = v;
154
+ }
155
+ }
156
+ if (occMin === 0)
157
+ return false;
158
+ const treeNear = canopyDepthMetric(p.zc - radius, cam.near);
159
+ return treeNear + 2 < occMin;
160
+ }
161
+ //# sourceMappingURL=hiz.js.map
package/lib/hiz.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hiz.js","sourceRoot":"","sources":["../src/hiz.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,0DAA0D;AAE1D,kEAAkE;AAClE,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC;AAC9B,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC;AAC9B,wFAAwF;AACxF,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC;AASvC,MAAM,CAAC,MAAM,eAAe,GAA6B,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CA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/** Width and height of the internal Hi-Z pyramid's base level. */\nexport const HIZ_BASE_W = 256;\nexport const HIZ_BASE_H = 128;\n/** 24-bit unsigned integer scale for conservative atomicMin/atomicMax depth storage. */\nexport const HIZ_MAX_UINT = 16_777_215;\n\n/**\n * How trees occluded behind terrain or dense forest canopies are culled on the GPU:\n * - `off`: frustum + range only (all in-frustum trees within range are drawn);\n * - `canopy`: zero-setup GPU compute canopy occlusion (dense crowns splatted to Hi-Z);\n * - `depth`: external scene DepthTexture (`trees.setDepthTexture`) downsampled to Hi-Z.\n */\nexport type OcclusionMode = \"off\" | \"canopy\" | \"depth\";\nexport const OCCLUSION_MODES: readonly OcclusionMode[] = [\"off\", \"canopy\", \"depth\"];\n\nexport interface HiZLevel {\n width: number;\n height: number;\n offset: number;\n}\n\nexport interface HiZLayout {\n levels: readonly HiZLevel[];\n total: number;\n}\n\n/** Offsets and dimensions of every mip level of a `baseW x baseH` Hi-Z pyramid packed into one Uint32 buffer. */\nexport function hizLayout(baseW = HIZ_BASE_W, baseH = HIZ_BASE_H): HiZLayout {\n const levels: HiZLevel[] = [];\n let w = Math.max(1, Math.floor(baseW));\n let h = Math.max(1, Math.floor(baseH));\n let offset = 0;\n while (true) {\n levels.push({ width: w, height: h, offset });\n offset += w * h;\n if (w === 1 && h === 1) break;\n w = Math.max(1, w >> 1);\n h = Math.max(1, h >> 1);\n }\n return { levels, total: offset };\n}\n\n/**\n * Analytical NDC depth in `[0, 1]` for positive view-space depth `zc > 0`, matching Three.js r187 WebGPU\n * perspective projection (`reversed = true`: near = 1, far = 0; `reversed = false`: near = 0, far = 1).\n */\nexport function ndcDepth(zc: number, near: number, far: number, reversed: boolean): number {\n const z = Math.max(near, Math.min(far, zc));\n if (reversed) return (near * (far - z)) / (z * Math.max(1e-6, far - near));\n return (far * (z - near)) / (z * Math.max(1e-6, far - near));\n}\n\n/**\n * Monotonic reversed-Z depth metric in `[0, HIZ_MAX_UINT]` used for Hi-Z comparison and canopy occlusion:\n * 0 = clear sky at infinity, larger = closer to the camera.\n */\nexport function canopyDepthMetric(zc: number, near: number): number {\n const m = Math.min(1, Math.max(0, near / Math.max(zc, near)));\n return Math.min(HIZ_MAX_UINT, Math.max(0, Math.round(m * HIZ_MAX_UINT)));\n}\n\n/**\n * Downsample mip 0 through all coarser levels using conservative `min` (furthest occluder in reversed-Z).\n * When the previous level has an odd width or height, the last row/column also folds the trailing texel\n * (`2x + 2` / `2y + 2`) so a 1-texel gap on an odd boundary is never skipped.\n */\nexport function downsampleHiZCpu(buf: Uint32Array, layout: HiZLayout): void {\n for (let l = 1; l < layout.levels.length; l++) {\n const prev = layout.levels[l - 1];\n const cur = layout.levels[l];\n for (let y = 0; y < cur.height; y++) {\n const y0 = Math.min(prev.height - 1, y * 2);\n const y1 = Math.min(prev.height - 1, y * 2 + 1);\n const yExtra = (prev.height & 1) === 1 && y === cur.height - 1 ? Math.min(prev.height - 1, y * 2 + 2) : y1;\n for (let x = 0; x < cur.width; x++) {\n const x0 = Math.min(prev.width - 1, x * 2);\n const x1 = Math.min(prev.width - 1, x * 2 + 1);\n const xExtra = (prev.width & 1) === 1 && x === cur.width - 1 ? Math.min(prev.width - 1, x * 2 + 2) : x1;\n let m = HIZ_MAX_UINT;\n const ys = [y0, y1, yExtra];\n const xs = [x0, x1, xExtra];\n for (let j = 0; j < 3; j++) {\n for (let i = 0; i < 3; i++) {\n const v = buf[prev.offset + ys[j] * prev.width + xs[i]];\n if (v < m) m = v;\n }\n }\n buf[cur.offset + y * cur.width + x] = m;\n }\n }\n }\n}\n\nexport interface HiZCamera {\n x: number;\n y: number;\n z: number;\n /** Unit camera basis vectors in world space. */\n right: [number, number, number];\n up: [number, number, number];\n forward: [number, number, number];\n near: number;\n tanHalfFovY: number;\n aspect: number;\n}\n\n/** Project a world-space sphere onto `[0, 1]^2` screen UV bounds and camera-space `zc`. */\nexport function projectSphereScreenBounds(\n cx: number,\n cy: number,\n cz: number,\n radius: number,\n cam: HiZCamera,\n): { u0: number; v0: number; u1: number; v1: number; zc: number } | null {\n const dx = cx - cam.x;\n const dy = cy - cam.y;\n const dz = cz - cam.z;\n const zc = dx * cam.forward[0] + dy * cam.forward[1] + dz * cam.forward[2];\n if (zc + radius <= cam.near) return null;\n if (zc - radius <= cam.near) return { u0: 0, v0: 0, u1: 1, v1: 1, zc };\n const xc = dx * cam.right[0] + dy * cam.right[1] + dz * cam.right[2];\n const yc = dx * cam.up[0] + dy * cam.up[1] + dz * cam.up[2];\n const tanX = cam.tanHalfFovY * cam.aspect;\n const tanY = cam.tanHalfFovY;\n const uCenter = 0.5 + xc / (2 * zc * tanX);\n const vCenter = 0.5 - yc / (2 * zc * tanY);\n const halfU = radius / (2 * Math.max(cam.near, zc - radius) * tanX);\n const halfV = radius / (2 * Math.max(cam.near, zc - radius) * tanY);\n const u0 = Math.max(0, Math.min(1, uCenter - halfU));\n const u1 = Math.max(0, Math.min(1, uCenter + halfU));\n const v0 = Math.max(0, Math.min(1, vCenter - halfV));\n const v1 = Math.max(0, Math.min(1, vCenter + halfV));\n if (u1 <= 0 || u0 >= 1 || v1 <= 0 || v0 >= 1) return null;\n return { u0, v0, u1, v1, zc };\n}\n\n/**\n * Splat conservative opaque canopy cores into mip 0 of a Hi-Z buffer (CPU mirror of `hizCanopySplat`).\n */\nexport function splatCanopyHiZCpu(\n buf: Uint32Array,\n layout: HiZLayout,\n spheres: readonly { cx: number; cy: number; cz: number; radius: number }[],\n cam: HiZCamera,\n): void {\n const base = layout.levels[0];\n buf.fill(0);\n for (const s of spheres) {\n const p = projectSphereScreenBounds(s.cx, s.cy, s.cz, s.radius, cam);\n if (!p || p.zc - s.radius <= cam.near) continue;\n const x0 = Math.max(0, Math.floor(p.u0 * base.width));\n const x1 = Math.min(base.width - 1, Math.floor(p.u1 * base.width));\n const y0 = Math.max(0, Math.floor(p.v0 * base.height));\n const y1 = Math.min(base.height - 1, Math.floor(p.v1 * base.height));\n if (x1 - x0 > 64 || y1 - y0 > 64) continue;\n // Conservative far side of the opaque core sphere.\n const zMetric = canopyDepthMetric(p.zc + s.radius, cam.near);\n for (let y = y0; y <= y1; y++) {\n for (let x = x0; x <= x1; x++) {\n const idx = base.offset + y * base.width + x;\n if (zMetric > buf[idx]) buf[idx] = zMetric;\n }\n }\n }\n downsampleHiZCpu(buf, layout);\n}\n\n/**\n * Test whether a tree's bounding sphere is wholly occluded behind the Hi-Z pyramid.\n */\nexport function isSphereOccludedHiZ(\n buf: Uint32Array,\n layout: HiZLayout,\n cx: number,\n cy: number,\n cz: number,\n radius: number,\n cam: HiZCamera,\n): boolean {\n const p = projectSphereScreenBounds(cx, cy, cz, radius, cam);\n if (!p) return false;\n // Never cull a tree whose bounding sphere crosses the near plane.\n if (p.zc - radius <= cam.near * 1.5) return false;\n const base = layout.levels[0];\n const spanPx = Math.max((p.u1 - p.u0) * base.width, (p.v1 - p.v0) * base.height);\n const mip = Math.min(layout.levels.length - 1, Math.max(0, Math.ceil(Math.log2(Math.max(1, spanPx)))));\n const lv = layout.levels[mip];\n const x0 = Math.max(0, Math.min(lv.width - 1, Math.floor(p.u0 * lv.width)));\n const x1 = Math.max(0, Math.min(lv.width - 1, Math.floor(p.u1 * lv.width)));\n const y0 = Math.max(0, Math.min(lv.height - 1, Math.floor(p.v0 * lv.height)));\n const y1 = Math.max(0, Math.min(lv.height - 1, Math.floor(p.v1 * lv.height)));\n let occMin = HIZ_MAX_UINT;\n for (let y = y0; y <= y1; y++) {\n for (let x = x0; x <= x1; x++) {\n const v = buf[lv.offset + y * lv.width + x];\n if (v < occMin) occMin = v;\n }\n }\n if (occMin === 0) return false;\n const treeNear = canopyDepthMetric(p.zc - radius, cam.near);\n return treeNear + 2 < occMin;\n}\n"]}
@@ -0,0 +1,106 @@
1
+ import { type LightVolume } from "./light.js";
2
+ import { type TreeSpecies } from "./species.js";
3
+ import { type GrownTree } from "./tree.js";
4
+ /** Default grid of viewing directions along each axis of the hemi-octahedron. */
5
+ export declare const IMPOSTOR_GRID = 8;
6
+ /**
7
+ * How far below the horizon the hemi-octahedron reaches (sin of depression angle):
8
+ * 0.2 lets elevated cameras look down at distant valleys and valley cameras look up at ridges.
9
+ */
10
+ export declare const IMPOSTOR_COLLAR = 0.2;
11
+ /** Default square atlas page size (texels) packing multiple variant sheets per array layer. */
12
+ export declare const IMPOSTOR_ATLAS_SIZE = 1024;
13
+ /** Gutter (texels) kept clear inside each view cell so bilinear filtering never bleeds across views. */
14
+ export declare const IMPOSTOR_GUTTER = 2;
15
+ export interface ImpostorOptions {
16
+ /** Views per axis in the hemi-octahedral grid (default 8 -> 64 views). */
17
+ grid?: number;
18
+ /** Texels per view cell (default 64 up to 64 variants, 32 beyond). */
19
+ cell?: number;
20
+ }
21
+ export interface ImpostorLayout {
22
+ grid: number;
23
+ cell: number;
24
+ sheetSize: number;
25
+ perRow: number;
26
+ perLayer: number;
27
+ layers: number;
28
+ atlasSize: number;
29
+ }
30
+ /**
31
+ * Pack `variants` impostor sheets into a 2D texture array whose layer count stays
32
+ * well within WebGPU's guaranteed 256-layer limit even for hundreds of variants.
33
+ */
34
+ export declare function impostorLayout(variants: number, options?: ImpostorOptions): ImpostorLayout;
35
+ export interface ImpostorBounds {
36
+ cx: number;
37
+ cy: number;
38
+ cz: number;
39
+ radius: number;
40
+ }
41
+ /** Tight bounding sphere in the grown variant's own metre space enclosing all wood, clumps, and palm fronds. */
42
+ export declare function impostorBounds(tree: GrownTree): ImpostorBounds;
43
+ /**
44
+ * Extended hemi-octahedral direction -> UV in [0, 1]^2.
45
+ * `dir` points from the tree centre toward the camera.
46
+ */
47
+ export declare function dirToHemiOct(dx: number, dy: number, dz: number, collar?: number): [number, number];
48
+ /**
49
+ * Exact inverse of `dirToHemiOct` for all directions down to `dy >= -collar`.
50
+ */
51
+ export declare function hemiOctToDir(u: number, v: number, collar?: number): [number, number, number];
52
+ export interface HemiOctBlend {
53
+ i0: number;
54
+ j0: number;
55
+ i1: number;
56
+ j1: number;
57
+ i2: number;
58
+ j2: number;
59
+ w0: number;
60
+ w1: number;
61
+ w2: number;
62
+ }
63
+ /**
64
+ * 3-view simplex barycentric interpolation on a `grid x grid` cell-centred hemi-octahedral grid.
65
+ * Splitting along `fu >= fv` keeps weights continuous across every cell edge and diagonal.
66
+ */
67
+ export declare function hemiOctBlend(u: number, v: number, grid?: number): HemiOctBlend;
68
+ /** Encode a unit normal into [0, 1]^2 using standard octahedral mapping. */
69
+ export declare function octEncodeNormal(nx: number, ny: number, nz: number): [number, number];
70
+ /** Decode an octahedral [0, 1]^2 pair back to a unit normal. */
71
+ export declare function octDecodeNormal(ux: number, uy: number): [number, number, number];
72
+ export interface ImpostorSheet {
73
+ grid: number;
74
+ cell: number;
75
+ width: number;
76
+ height: number;
77
+ bounds: ImpostorBounds;
78
+ /** Premultiplied sRGB albedo + alpha (RGBA8). */
79
+ albedoAlpha: Uint8Array;
80
+ /** Premultiplied octNormal.xy, normalized view depth, sky AO (RGBA8). */
81
+ normalDepthSky: Uint8Array;
82
+ }
83
+ /** Orthonormal view basis (right, up, forward-toward-camera) matching GPU billboard orientation. */
84
+ export declare function viewBasisForDir(dx: number, dy: number, dz: number): {
85
+ right: [number, number, number];
86
+ up: [number, number, number];
87
+ fwd: [number, number, number];
88
+ };
89
+ /**
90
+ * CPU reference G-buffer baker for unit testing and offline inspection.
91
+ * Renders clumps and wood segments orthographically into every cell of the hemi-octahedral grid.
92
+ */
93
+ export declare function bakeImpostorCpu(tree: GrownTree, species: TreeSpecies, volume: LightVolume, grid?: number, cell?: number): ImpostorSheet;
94
+ export interface ImpostorSample {
95
+ alpha: number;
96
+ albedo: [number, number, number];
97
+ normal: [number, number, number];
98
+ depth01: number;
99
+ sky: number;
100
+ }
101
+ /**
102
+ * Sample a CPU-baked impostor sheet from camera direction `(dx, dy, dz)` and quad coordinates
103
+ * `(localX, localY)` in `[-1, 1]^2` using 3-view simplex blending and depth parallax.
104
+ */
105
+ export declare function sampleImpostorCpu(sheet: ImpostorSheet, dx: number, dy: number, dz: number, localX: number, localY: number): ImpostorSample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