webgpu-biome 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +89 -2
- package/lib/canopy.d.ts +75 -0
- package/lib/canopy.d.ts.map +1 -0
- package/lib/canopy.js +295 -0
- package/lib/canopy.js.map +1 -0
- package/lib/climate.d.ts +68 -0
- package/lib/climate.d.ts.map +1 -0
- package/lib/climate.js +105 -0
- package/lib/climate.js.map +1 -0
- package/lib/detail.d.ts +55 -0
- package/lib/detail.d.ts.map +1 -0
- package/lib/detail.js +225 -0
- package/lib/detail.js.map +1 -0
- package/lib/ecotone.d.ts +166 -0
- package/lib/ecotone.d.ts.map +1 -0
- package/lib/ecotone.js +1007 -0
- package/lib/ecotone.js.map +1 -0
- package/lib/engine.d.ts +102 -0
- package/lib/engine.d.ts.map +1 -0
- package/lib/engine.js +773 -0
- package/lib/engine.js.map +1 -0
- package/lib/epiphytes.d.ts +19 -0
- package/lib/epiphytes.d.ts.map +1 -0
- package/lib/epiphytes.js +180 -0
- package/lib/epiphytes.js.map +1 -0
- package/lib/ground.d.ts +43 -0
- package/lib/ground.d.ts.map +1 -0
- package/lib/ground.js +450 -0
- package/lib/ground.js.map +1 -0
- package/lib/horizon.d.ts +20 -0
- package/lib/horizon.d.ts.map +1 -0
- package/lib/horizon.js +625 -0
- package/lib/horizon.js.map +1 -0
- package/lib/index.d.ts +21 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +18 -0
- package/lib/index.js.map +1 -0
- package/lib/particles.d.ts +12 -0
- package/lib/particles.d.ts.map +1 -0
- package/lib/particles.js +124 -0
- package/lib/particles.js.map +1 -0
- package/lib/post.d.ts +23 -0
- package/lib/post.d.ts.map +1 -0
- package/lib/post.js +225 -0
- package/lib/post.js.map +1 -0
- package/lib/recipe-specs.d.ts +51 -0
- package/lib/recipe-specs.d.ts.map +1 -0
- package/lib/recipe-specs.js +562 -0
- package/lib/recipe-specs.js.map +1 -0
- package/lib/recipes.d.ts +9 -0
- package/lib/recipes.d.ts.map +1 -0
- package/lib/recipes.js +279 -0
- package/lib/recipes.js.map +1 -0
- package/lib/sandbox.d.ts +183 -0
- package/lib/sandbox.d.ts.map +1 -0
- package/lib/sandbox.js +1060 -0
- package/lib/sandbox.js.map +1 -0
- package/lib/shadows.d.ts +71 -0
- package/lib/shadows.d.ts.map +1 -0
- package/lib/shadows.js +532 -0
- package/lib/shadows.js.map +1 -0
- package/lib/sky.d.ts +16 -0
- package/lib/sky.d.ts.map +1 -0
- package/lib/sky.js +132 -0
- package/lib/sky.js.map +1 -0
- package/lib/substrate.d.ts +124 -0
- package/lib/substrate.d.ts.map +1 -0
- package/lib/substrate.js +988 -0
- package/lib/substrate.js.map +1 -0
- package/lib/turf.d.ts +60 -0
- package/lib/turf.d.ts.map +1 -0
- package/lib/turf.js +278 -0
- package/lib/turf.js.map +1 -0
- package/lib/water.d.ts +41 -0
- package/lib/water.d.ts.map +1 -0
- package/lib/water.js +210 -0
- package/lib/water.js.map +1 -0
- package/package.json +63 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jakob Holmelund
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Biome
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Unified ecosystems for `three.js` on WebGPU, written in TSL: shared terrain hydrology and soil chemistry, 365-day solar ephemeris and physical sky, canopy shelter and leaf-litter feedback, [`webgpu-trees`](../trees), [`webgpu-grass`](../grass), and a unified forest floor — with a lab to walk through them.
|
|
4
|
+
|
|
5
|
+
It is at Phase 5 of [docs/MASTERPLAN.md](./docs/MASTERPLAN.md). WebGPU only (`three` r187, `three/webgpu`).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add webgpu-biome three@^0.187.0
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The four libraries come in as its dependencies (`webgpu-trees` ^0.1.0, `webgpu-grass` ^0.1.1, `webgpu-rocks` ^0.3.0, `webgpu-flora` ^0.4.0). The smallest working host is [examples/woodland-by-recipe](../../examples/woodland-by-recipe), and `pnpm consumer:biome` checks it against the packed packages. In Vite's dev server, exclude biome and the libraries from dependency pre-bundling (`optimizeDeps: { exclude: ["webgpu-biome", "webgpu-trees", "webgpu-grass", "webgpu-rocks", "webgpu-flora"] }`) so each library's modules stay beside their pictures.
|
|
14
|
+
|
|
15
|
+
**What biome exports.** Its own API: `createBiome`, the recipes (`BIOME_RECIPES`, `BIOME_ECOLOGY_SPECS`, `solveRecipeBiome`), the sandbox (`createBiomeSandbox`, snapshots), substrate, canopy, climate, ecotone, ground, sky, water and the rest of `src/index.ts`. Of the libraries, only the types its own options and results name (`Trees`, `TreeLook`, `Rocks`, `Flora`, `Grass`, `GrassSpecies`, ...), so a host that installs biome alone can name them. The libraries' functions and species lists are theirs: a host that writes its own recipe from `ALL_SPECIES`, `GRASSES` or `FLORA_SPECIES`, or draws one library on its own, installs that library too. (Before 0.1.0, inside the workspace, biome re-exported most of the rocks, flora and trees APIs; it no longer does.)
|
|
16
|
+
|
|
17
|
+
The plan for four independently installable landscape libraries covers the workspace migration, standalone flora and rocks, and biome's runnable integration examples. [Library masterplan](./docs/LIBRARY_MASTERPLAN.md)
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
src/ the biome orchestrator: imports three, webgpu-trees, webgpu-grass, webgpu-rocks, webgpu-flora, and itself
|
|
21
|
+
mcp/ unified Biome Studio MCP server (`node mcp/server.mjs`) + `/__mcp/` live browser bridge (6 tools incl. compose_biome)
|
|
22
|
+
lab/ the lab: six starter biomes, camera walks, time/season/snow/look/flora/rock/water controls
|
|
23
|
+
docs/ MASTERPLAN.md — unified architecture and phased roadmap
|
|
24
|
+
test/ boundary, substrate hydrology, canopy light/litter, rocks, flora, MCP & WGSL shader tests
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quickstart
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm install
|
|
31
|
+
pnpm dev
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Open `/lab/` in a WebGPU-capable browser. Drag to look, `W A S D` / arrows to walk over the terrain, scroll wheel to adjust eye height (`0.18 m` forest floor up to `80 m` vista), and `H` to hide panels.
|
|
35
|
+
|
|
36
|
+
## From the libraries to a recipe
|
|
37
|
+
|
|
38
|
+
`createBiome()` composes the four libraries ([trees](../trees), [grass](../grass), [rocks](../rocks), [flora](../flora)) from a recipe. To see what it does for you, read the examples in this order:
|
|
39
|
+
|
|
40
|
+
1. One library at a time: [one-tree](../../examples/one-tree), [grass-patch](../../examples/grass-patch), [ferns-on-a-bank](../../examples/ferns-on-a-bank), [rock-on-slope](../../examples/rock-on-slope).
|
|
41
|
+
2. Two at a time: [grass-under-trees](../../examples/grass-under-trees) (the trees' baked shade as the grass's sunlight) and [ferns-around-an-outcrop](../../examples/ferns-around-an-outcrop) (the rocks' cover and halo grids in a plant scatter).
|
|
42
|
+
3. All four by hand: [woodland-by-hand](../../examples/woodland-by-hand), one terrain, one sun, one frame loop, in the order a host has to follow.
|
|
43
|
+
4. Then the same woodland as a recipe: [woodland-by-recipe](../../examples/woodland-by-recipe), with a table from each recipe field to the manual step it replaces, an edit, and a snapshot restore. Biome also solves what the manual woodland leaves to its author: soil and moisture, a daily shelter field (how much of a day's light a place gets, which decides where shade plants grow, as distinct from the direct shade the trees bake for lighting), succession, and edits with snapshot and restore.
|
|
44
|
+
|
|
45
|
+
## The contract
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { createBiome } from "webgpu-biome";
|
|
49
|
+
|
|
50
|
+
const biome = createBiome({
|
|
51
|
+
recipe: "woodlandMeadow",
|
|
52
|
+
look: "real",
|
|
53
|
+
climate: { hour: 9.5, day: 172, windSpeed: 4.5 },
|
|
54
|
+
});
|
|
55
|
+
scene.add(biome.object);
|
|
56
|
+
await biome.ready;
|
|
57
|
+
|
|
58
|
+
// each frame, before renderer.render(scene, camera):
|
|
59
|
+
biome.update(renderer, camera, timeSeconds);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
- **Substrate (`src/substrate.ts`)** computes normals, slope, aspect, multi-scale concavity, and Topographic Wetness Index (`moisture`), soil pH, fertility, and wind exposure. It implements `webgpu-grass`'s `HeightSource` using a single read-only `StorageBufferAttribute` (`vec4`), one `RGBA8` `edaphicTex`, and a 16-bit `HalfFloatType` `heightTex` (`sampleHeightTex`).
|
|
63
|
+
- **Canopy (`src/canopy.ts`)** bakes sun-invariant daily `shelter`, hemispherical `sky`, `litter` + `coniferShare`, tight root-collar humus/moss aprons, and ectomycorrhizal root zones (`mycorrhiza`) from the placed trees, feeding `webgpu-grass`'s `WorldLight` (`shelter`, `sky`, `tint`, `light`) and the forest floor.
|
|
64
|
+
- **Climate & Phenology (`src/climate.ts`)** drives solar direction, `createAtmosphere()` Sky-View LUT & aerial perspective, sun/shade daylight tints, drifting `cloudSunAt` shadows, `effectiveSnow`, and 365-day seasonal curves (`foliageRetention`, `heatherBloom`, `fungiSeason`, `winterSnow`, `strains`) synced into `webgpu-trees` per-species budburst/autumn/leaf-drop & impostors across all strata at once.
|
|
65
|
+
- **Ecotone Solver (`src/ecotone.ts` & `src/recipes.ts`)** solves overstory trees, shrub mantles, undergrowth, tree-hosted epiphytes (`climbingIvy`, `tinderConk`, `sulphurShelf`, `beardLichen`), meadow/rough grass mixes, and bare rock/litter/sand thresholds (`NO_GRASS`) from declarative `NicheEnvelope` rules.
|
|
66
|
+
- **Undergrowth & Epiphytes ([`webgpu-flora`](../flora))** implements 28 plain-data `FLORA_SPECIES` across 7 parametric archetypes (`cushion`, `rosette`, `forb`, `fungi`, `deadwood`, `bracket`, `epiphyte`) with GPU compute frustum/season compaction and imports only `three`. Biome chooses the tree hosts for ivy and bracket fungi and decides which flora suppresses turf.
|
|
67
|
+
- **Geology ([`webgpu-rocks`](../rocks))** implements 8 plain-data `ROCK_SPECIES` across 4 procedural archetypes (`erratic`, `cliff`, `talus`, `cobble`) with Voronoi/jointed fracturing, world-space mineral strata, directional moss & lichen, ground-contact collars, `BARE_GROUND` & tree exclusion footprints, fern micro-habitat halos, and `depthScene` Hi-Z occlusion.
|
|
68
|
+
- **Water (`src/water.ts`)** builds a pruned submerged-basin mesh with Beer-Lambert depth absorption, animated wind ripples, Schlick Fresnel sky reflections, solar glints, winter lake ice, and shoreline darkening in `ground.ts`.
|
|
69
|
+
- **Forest Floor (`src/ground.ts`)** blends mineral sand, peat, loam, triplanar steep mountain rock strata & scree aprons, deciduous duff, pine needle mat, bryophyte moss, wet shorelines, and `grass.groundColor(xz)` without seams while staying well inside WebGPU's 16-sampled-textures-per-stage limit.
|
|
70
|
+
|
|
71
|
+
## Global Biomes (`BIOME_RECIPES`)
|
|
72
|
+
|
|
73
|
+
1. **`woodlandMeadow`** — Oak, beech, silver birch, Scots pine, black alder pond hollows, hawthorn/blackthorn/elder edge mantle, rich hay & buttercup meadows grading into shady fine fescue and mossy leaf-litter floors, plus a mown grass ride.
|
|
74
|
+
2. **`danishCoastalHeath`** — Wind-exposed coastal dunes and slacks with Scots/Corsican pine, sea buckthorn, gorse, Scotch broom, marram crests, sheep's fescue, coastal meadow blooms (*thrift*, *sea aster*, *sea plantain*), saltmarsh rush, and dune-slack pools.
|
|
75
|
+
3. **`montaneValley`** — Alder & white willow stream bottom with clear alpine water, mixed Douglas fir / Sitka spruce / European larch / birch slopes, schist crags, talus scree, and subalpine fescue turf.
|
|
76
|
+
4. **`mediterraneanKarst`** — Umbrella stone pines, Aleppo pines, Monterey cypress, Coast live oak, limestone karst cliffs, scree, and a turquoise coastal cove.
|
|
77
|
+
5. **`borealTaiga`** — Spruce, White spruce, Scots pine, European larch, silver birch & aspen over shield-granite erratics, bilberry-heather groundcover, and a boreal tarn.
|
|
78
|
+
6. **`palmLagoon`** — Canary date palm, queen palm, fan palms, coastal Torrey/Monterey pines, and fern-edged sandspits framing a turquoise lagoon.
|
|
79
|
+
|
|
80
|
+
## Verification
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pnpm test
|
|
84
|
+
pnpm typecheck
|
|
85
|
+
pnpm build
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Licence
|
|
89
|
+
|
|
90
|
+
MIT (`LICENSE`).
|
package/lib/canopy.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as THREE from "three/webgpu";
|
|
2
|
+
import { type TreeSpecies } from "webgpu-trees";
|
|
3
|
+
import type { SubstrateBounds } from "./substrate.js";
|
|
4
|
+
type Vec2 = THREE.Node<"vec2">;
|
|
5
|
+
type Vec3 = THREE.Node<"vec3">;
|
|
6
|
+
type Float = THREE.Node<"float">;
|
|
7
|
+
export interface CanopyFields {
|
|
8
|
+
nx: number;
|
|
9
|
+
nz: number;
|
|
10
|
+
x0: number;
|
|
11
|
+
z0: number;
|
|
12
|
+
cell: number;
|
|
13
|
+
width: number;
|
|
14
|
+
depth: number;
|
|
15
|
+
/** Daily sky-light reduction `0` (open) to `1` (dense closed canopy). */
|
|
16
|
+
shelter: Float32Array;
|
|
17
|
+
/** Hemispherical sky visibility `0..1` at ground level. */
|
|
18
|
+
sky: Float32Array;
|
|
19
|
+
/** Accumulated leaf/needle duff depth `0..1`. */
|
|
20
|
+
litter: Float32Array;
|
|
21
|
+
/** Conifer fraction of litter `0..1` (0 = broadleaf duff, 1 = needle mat). */
|
|
22
|
+
coniferShare: Float32Array;
|
|
23
|
+
/** Ectomycorrhizal root-zone influence `0..1` for forest fungi placement. */
|
|
24
|
+
mycorrhiza: Float32Array;
|
|
25
|
+
}
|
|
26
|
+
export interface CanopySample {
|
|
27
|
+
shelter: number;
|
|
28
|
+
sky: number;
|
|
29
|
+
litter: number;
|
|
30
|
+
coniferShare: number;
|
|
31
|
+
mycorrhiza: number;
|
|
32
|
+
}
|
|
33
|
+
export interface MycorrhizaBoost {
|
|
34
|
+
x: number;
|
|
35
|
+
z: number;
|
|
36
|
+
radius: number;
|
|
37
|
+
strength: number;
|
|
38
|
+
}
|
|
39
|
+
export interface BakeCanopyOptions {
|
|
40
|
+
bounds: SubstrateBounds;
|
|
41
|
+
cell?: number;
|
|
42
|
+
trees: Float32Array;
|
|
43
|
+
species: readonly TreeSpecies[];
|
|
44
|
+
/** Seasonal deciduous leaf retention `0..1` (default `1`). */
|
|
45
|
+
foliageRetention?: number;
|
|
46
|
+
/** Optional inoculated mycorrhizal root-zone patches. */
|
|
47
|
+
mycorrhizaBoosts?: readonly MycorrhizaBoost[];
|
|
48
|
+
}
|
|
49
|
+
export interface BiomeCanopy {
|
|
50
|
+
readonly fields: CanopyFields;
|
|
51
|
+
readonly canopyTex: THREE.DataTexture;
|
|
52
|
+
sampleCpu(x: number, z: number): CanopySample;
|
|
53
|
+
shelterAt(xz: Vec2): Float;
|
|
54
|
+
skyAt(xz: Vec2): Float;
|
|
55
|
+
litterAt(xz: Vec2): {
|
|
56
|
+
litter: Float;
|
|
57
|
+
coniferShare: Float;
|
|
58
|
+
};
|
|
59
|
+
tintAt(xz: Vec2): Vec3;
|
|
60
|
+
lightAt(xz: Vec2): Vec3;
|
|
61
|
+
update(fields: CanopyFields, wetness: number, season?: {
|
|
62
|
+
autumnTurn?: number;
|
|
63
|
+
foliageRetention?: number;
|
|
64
|
+
snow?: number;
|
|
65
|
+
}): void;
|
|
66
|
+
dispose(): void;
|
|
67
|
+
}
|
|
68
|
+
/** Bake canopy shelter, sky openness, litter, conifer fraction, and mycorrhizal fields on CPU. */
|
|
69
|
+
export declare function bakeCanopyCpu(opts: BakeCanopyOptions): CanopyFields;
|
|
70
|
+
/** Bilinear sample of baked canopy fields at world `(x, z)`. */
|
|
71
|
+
export declare function sampleCanopyCpu(fields: CanopyFields, x: number, z: number): CanopySample;
|
|
72
|
+
/** Upload `CanopyFields` to a single RGBA8 GPU texture and expose TSL nodes for `grass` & `ground`. */
|
|
73
|
+
export declare function createCanopyMap(initial: CanopyFields): BiomeCanopy;
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=canopy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canopy.d.ts","sourceRoot":"","sources":["../src/canopy.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,KAAK,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MA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AED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC;IACtC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IAC9C,SAAS,CAAC,EAAE,EAAE,IAAI,GAAG,KAAK,CAAC;IAC3B,KAAK,CAAC,EAAE,EAAE,IAAI,GAAG,KAAK,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,IAAI,GAAG;QAAE,MAAM,EAAE,KAAK,CAAC;QAAC,YAAY,EAAE,KAAK,CAAA;KAAE,CAAC;IAC3D,MAAM,CAAC,EAAE,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAChI,OAAO,IAAI,IAAI,CAAC;CACjB;AAqCD,kGAAkG;AAClG,wBAAgB,aAAa,CAAC,IAAI,EAAE,iBAAiB,GAAG,YAAY,CA0KnE;AAED,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,YAAY,CAyBxF;AAED,uGAAuG;AACvG,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW,CAqFlE"}
|
package/lib/canopy.js
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// Biotic canopy feedback: sun-invariant daily shelter, hemispherical sky openness,
|
|
2
|
+
// leaf/needle litter aprons, and ectomycorrhizal root zones computed from placed trees.
|
|
3
|
+
//
|
|
4
|
+
// Bridges `webgpu-trees` overstory stands to `webgpu-grass` `WorldLight` hooks
|
|
5
|
+
// (`shelter`, `sky`, `tint`, `light`), the unified forest floor, and Phase 1 `webgpu-flora`.
|
|
6
|
+
import * as THREE from "three/webgpu";
|
|
7
|
+
import { clamp, float, mix, texture, uniform, vec2, vec3, vec4 } from "three/tsl";
|
|
8
|
+
import { TREE_STRIDE } from "webgpu-trees";
|
|
9
|
+
const ECTOMYCORRHIZAL_HOSTS = new Set([
|
|
10
|
+
"Oak",
|
|
11
|
+
"Red oak",
|
|
12
|
+
"Coast live oak",
|
|
13
|
+
"Holm oak",
|
|
14
|
+
"Beech",
|
|
15
|
+
"Sweet chestnut",
|
|
16
|
+
"Silver birch",
|
|
17
|
+
"Black poplar",
|
|
18
|
+
"Hornbeam",
|
|
19
|
+
"Scots pine",
|
|
20
|
+
"Corsican pine",
|
|
21
|
+
"Monterey pine",
|
|
22
|
+
"Torrey pine",
|
|
23
|
+
"Aleppo pine",
|
|
24
|
+
"Stone pine",
|
|
25
|
+
"Eastern white pine",
|
|
26
|
+
"Spruce",
|
|
27
|
+
"Sitka spruce",
|
|
28
|
+
"White spruce",
|
|
29
|
+
"Subalpine fir",
|
|
30
|
+
"Douglas fir",
|
|
31
|
+
"European larch",
|
|
32
|
+
"Western hemlock",
|
|
33
|
+
]);
|
|
34
|
+
function clamp01(v) {
|
|
35
|
+
return v < 0 ? 0 : v > 1 ? 1 : v;
|
|
36
|
+
}
|
|
37
|
+
/** Monsi-Saeki crown leaf area index from species openness (`trees/src/light.ts`). */
|
|
38
|
+
function leafAreaIndex(openness) {
|
|
39
|
+
return 1.5 + 4.8 * (1 - clamp01(openness));
|
|
40
|
+
}
|
|
41
|
+
/** Bake canopy shelter, sky openness, litter, conifer fraction, and mycorrhizal fields on CPU. */
|
|
42
|
+
export function bakeCanopyCpu(opts) {
|
|
43
|
+
const { bounds, trees, species } = opts;
|
|
44
|
+
const cell = Math.max(0.5, opts.cell ?? 2);
|
|
45
|
+
const retention = clamp01(opts.foliageRetention ?? 1);
|
|
46
|
+
const nx = Math.max(2, Math.ceil(bounds.width / cell) + 1);
|
|
47
|
+
const nz = Math.max(2, Math.ceil(bounds.depth / cell) + 1);
|
|
48
|
+
const n = nx * nz;
|
|
49
|
+
const shelter = new Float32Array(n);
|
|
50
|
+
const sky = new Float32Array(n).fill(1);
|
|
51
|
+
const litter = new Float32Array(n);
|
|
52
|
+
const coniferShare = new Float32Array(n);
|
|
53
|
+
const mycorrhiza = new Float32Array(n);
|
|
54
|
+
const count = Math.floor(trees.length / TREE_STRIDE);
|
|
55
|
+
if (count === 0) {
|
|
56
|
+
return {
|
|
57
|
+
nx,
|
|
58
|
+
nz,
|
|
59
|
+
x0: bounds.x0,
|
|
60
|
+
z0: bounds.z0,
|
|
61
|
+
cell,
|
|
62
|
+
width: bounds.width,
|
|
63
|
+
depth: bounds.depth,
|
|
64
|
+
shelter,
|
|
65
|
+
sky,
|
|
66
|
+
litter,
|
|
67
|
+
coniferShare,
|
|
68
|
+
mycorrhiza,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
// Accumulate per-tree discs directly into covered grid cells (fast O(count * r^2)).
|
|
72
|
+
const opticalSum = new Float32Array(n);
|
|
73
|
+
const litterSum = new Float32Array(n);
|
|
74
|
+
const coniferLitSum = new Float32Array(n);
|
|
75
|
+
for (let t = 0; t < count; t++) {
|
|
76
|
+
const o = t * TREE_STRIDE;
|
|
77
|
+
const tx = trees[o];
|
|
78
|
+
const tz = trees[o + 2];
|
|
79
|
+
const spIdx = Math.round(trees[o + 3]);
|
|
80
|
+
const sp = species[spIdx];
|
|
81
|
+
if (!sp)
|
|
82
|
+
continue;
|
|
83
|
+
const rRaw = trees[o + 5];
|
|
84
|
+
const crownRadius = Number.isFinite(rRaw) && rRaw > 0 ? rRaw : sp.crownRadius;
|
|
85
|
+
const isConifer = sp.architecture === "conifer" ||
|
|
86
|
+
(sp.leafKind === "pine" && sp.name !== "Gorse") ||
|
|
87
|
+
sp.leafKind === "needle" ||
|
|
88
|
+
sp.name === "Monterey cypress";
|
|
89
|
+
const isDeciduousLarch = sp.name === "European larch";
|
|
90
|
+
const isEvergreen = (isConifer && !isDeciduousLarch) ||
|
|
91
|
+
sp.architecture === "palm" ||
|
|
92
|
+
sp.name === "Gorse" ||
|
|
93
|
+
sp.name === "Coast live oak" ||
|
|
94
|
+
sp.name === "Eucalyptus";
|
|
95
|
+
const leafKeep = isEvergreen ? 1 : 0.14 + 0.86 * retention;
|
|
96
|
+
// Optical thickness from species openness via Monsi-Saeki LAI.
|
|
97
|
+
const lai = leafAreaIndex(sp.openness) * leafKeep;
|
|
98
|
+
const shadeStrength = 1 - Math.exp(-0.34 * lai);
|
|
99
|
+
const shadeR = crownRadius * 1.25;
|
|
100
|
+
const litterR = crownRadius * 1.38;
|
|
101
|
+
const collarR = Math.max(0.55, crownRadius * 0.26);
|
|
102
|
+
const mycoHost = ECTOMYCORRHIZAL_HOSTS.has(sp.name);
|
|
103
|
+
const maxR = mycoHost ? Math.max(litterR, crownRadius * 1.85) : litterR;
|
|
104
|
+
const i0 = Math.max(0, Math.floor((tx - maxR - bounds.x0) / cell));
|
|
105
|
+
const i1 = Math.min(nx - 1, Math.ceil((tx + maxR - bounds.x0) / cell));
|
|
106
|
+
const j0 = Math.max(0, Math.floor((tz - maxR - bounds.z0) / cell));
|
|
107
|
+
const j1 = Math.min(nz - 1, Math.ceil((tz + maxR - bounds.z0) / cell));
|
|
108
|
+
for (let j = j0; j <= j1; j++) {
|
|
109
|
+
const z = bounds.z0 + j * cell;
|
|
110
|
+
const dz = z - tz;
|
|
111
|
+
for (let i = i0; i <= i1; i++) {
|
|
112
|
+
const x = bounds.x0 + i * cell;
|
|
113
|
+
const dx = x - tx;
|
|
114
|
+
const rawDist = Math.hypot(dx, dz);
|
|
115
|
+
const k = j * nx + i;
|
|
116
|
+
const ang = Math.atan2(dz, dx);
|
|
117
|
+
const lobeMod = 1 +
|
|
118
|
+
0.22 * Math.sin(ang * 3 + t * 1.9) +
|
|
119
|
+
0.14 * Math.cos(ang * 5 - t * 2.7) +
|
|
120
|
+
0.1 * Math.sin((x + z) * 0.45);
|
|
121
|
+
const dist = rawDist / Math.max(0.55, lobeMod);
|
|
122
|
+
if (dist < shadeR) {
|
|
123
|
+
const u = dist / shadeR;
|
|
124
|
+
const profile = Math.pow(Math.max(0, 1 - u * u), 0.72);
|
|
125
|
+
opticalSum[k] += shadeStrength * profile;
|
|
126
|
+
}
|
|
127
|
+
if (dist < litterR) {
|
|
128
|
+
const u = dist / litterR;
|
|
129
|
+
let duff = Math.pow(Math.max(0, 1 - u * u), 1.2) * (isConifer ? 0.78 : 0.68);
|
|
130
|
+
if (dist < collarR) {
|
|
131
|
+
const cu = dist / collarR;
|
|
132
|
+
duff += 0.24 * Math.pow(Math.max(0, 1 - cu * cu), 1.5);
|
|
133
|
+
}
|
|
134
|
+
litterSum[k] += duff;
|
|
135
|
+
if (isConifer)
|
|
136
|
+
coniferLitSum[k] += duff;
|
|
137
|
+
}
|
|
138
|
+
if (mycoHost) {
|
|
139
|
+
const mycoR = crownRadius * 1.85;
|
|
140
|
+
if (dist < mycoR) {
|
|
141
|
+
const u = dist / mycoR;
|
|
142
|
+
// Ring-weighted around root drip line (0.35..0.95 of radius).
|
|
143
|
+
const ring = Math.exp(-Math.pow((u - 0.58) / 0.34, 2));
|
|
144
|
+
mycorrhiza[k] = Math.max(mycorrhiza[k], clamp01(ring * 0.95));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
for (let k = 0; k < n; k++) {
|
|
151
|
+
const sh = clamp01(1 - Math.exp(-opticalSum[k] * 1.15));
|
|
152
|
+
shelter[k] = sh;
|
|
153
|
+
sky[k] = Math.max(0.14, 1 - 0.78 * sh);
|
|
154
|
+
const lit = clamp01(1 - Math.exp(-litterSum[k] * 1.25));
|
|
155
|
+
litter[k] = lit;
|
|
156
|
+
coniferShare[k] = litterSum[k] > 1e-4 ? clamp01(coniferLitSum[k] / litterSum[k]) : 0;
|
|
157
|
+
}
|
|
158
|
+
if (opts.mycorrhizaBoosts && opts.mycorrhizaBoosts.length > 0) {
|
|
159
|
+
for (const boost of opts.mycorrhizaBoosts) {
|
|
160
|
+
const r = Math.max(1, boost.radius);
|
|
161
|
+
const str = clamp01(boost.strength);
|
|
162
|
+
const bi0 = Math.max(0, Math.floor((boost.x - r - bounds.x0) / cell));
|
|
163
|
+
const bi1 = Math.min(nx - 1, Math.ceil((boost.x + r - bounds.x0) / cell));
|
|
164
|
+
const bj0 = Math.max(0, Math.floor((boost.z - r - bounds.z0) / cell));
|
|
165
|
+
const bj1 = Math.min(nz - 1, Math.ceil((boost.z + r - bounds.z0) / cell));
|
|
166
|
+
for (let j = bj0; j <= bj1; j++) {
|
|
167
|
+
const dz = bounds.z0 + j * cell - boost.z;
|
|
168
|
+
for (let i = bi0; i <= bi1; i++) {
|
|
169
|
+
const dx = bounds.x0 + i * cell - boost.x;
|
|
170
|
+
const d = Math.hypot(dx, dz);
|
|
171
|
+
if (d < r) {
|
|
172
|
+
const u = d / r;
|
|
173
|
+
const add = str * Math.pow(Math.max(0, 1 - u * u), 1.2);
|
|
174
|
+
const idx = j * nx + i;
|
|
175
|
+
mycorrhiza[idx] = Math.max(mycorrhiza[idx], clamp01(add));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
nx,
|
|
183
|
+
nz,
|
|
184
|
+
x0: bounds.x0,
|
|
185
|
+
z0: bounds.z0,
|
|
186
|
+
cell,
|
|
187
|
+
width: bounds.width,
|
|
188
|
+
depth: bounds.depth,
|
|
189
|
+
shelter,
|
|
190
|
+
sky,
|
|
191
|
+
litter,
|
|
192
|
+
coniferShare,
|
|
193
|
+
mycorrhiza,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/** Bilinear sample of baked canopy fields at world `(x, z)`. */
|
|
197
|
+
export function sampleCanopyCpu(fields, x, z) {
|
|
198
|
+
const fx = Math.min(fields.nx - 1.001, Math.max(0, (x - fields.x0) / fields.cell));
|
|
199
|
+
const fz = Math.min(fields.nz - 1.001, Math.max(0, (z - fields.z0) / fields.cell));
|
|
200
|
+
const i0 = Math.floor(fx);
|
|
201
|
+
const j0 = Math.floor(fz);
|
|
202
|
+
const i1 = Math.min(fields.nx - 1, i0 + 1);
|
|
203
|
+
const j1 = Math.min(fields.nz - 1, j0 + 1);
|
|
204
|
+
const tx = fx - i0;
|
|
205
|
+
const tz = fz - j0;
|
|
206
|
+
const bilerp = (arr) => {
|
|
207
|
+
const a = arr[j0 * fields.nx + i0];
|
|
208
|
+
const b = arr[j0 * fields.nx + i1];
|
|
209
|
+
const c = arr[j1 * fields.nx + i0];
|
|
210
|
+
const d = arr[j1 * fields.nx + i1];
|
|
211
|
+
return (a + (b - a) * tx) * (1 - tz) + (c + (d - c) * tx) * tz;
|
|
212
|
+
};
|
|
213
|
+
return {
|
|
214
|
+
shelter: bilerp(fields.shelter),
|
|
215
|
+
sky: bilerp(fields.sky),
|
|
216
|
+
litter: bilerp(fields.litter),
|
|
217
|
+
coniferShare: bilerp(fields.coniferShare),
|
|
218
|
+
mycorrhiza: bilerp(fields.mycorrhiza),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/** Upload `CanopyFields` to a single RGBA8 GPU texture and expose TSL nodes for `grass` & `ground`. */
|
|
222
|
+
export function createCanopyMap(initial) {
|
|
223
|
+
let current = initial;
|
|
224
|
+
const { nx, nz } = initial;
|
|
225
|
+
const data = new Uint8Array(nx * nz * 4);
|
|
226
|
+
const canopyTex = new THREE.DataTexture(data, nx, nz, THREE.RGBAFormat, THREE.UnsignedByteType);
|
|
227
|
+
canopyTex.colorSpace = THREE.NoColorSpace;
|
|
228
|
+
canopyTex.magFilter = canopyTex.minFilter = THREE.LinearFilter;
|
|
229
|
+
canopyTex.wrapS = canopyTex.wrapT = THREE.ClampToEdgeWrapping;
|
|
230
|
+
canopyTex.generateMipmaps = false;
|
|
231
|
+
const uBounds = uniform(vec4(initial.x0, initial.z0, 1 / Math.max(1e-4, initial.width), 1 / Math.max(1e-4, initial.depth)));
|
|
232
|
+
const uWet = uniform(0);
|
|
233
|
+
/** `(autumnTurn, foliageRetention, snow, wetness)` */
|
|
234
|
+
const uSeason = uniform(new THREE.Vector4(0, 1, 0, 0));
|
|
235
|
+
const upload = (fields, wetness, season) => {
|
|
236
|
+
current = fields;
|
|
237
|
+
uWet.value = clamp01(wetness);
|
|
238
|
+
uSeason.value.set(clamp01(season?.autumnTurn ?? 0), clamp01(season?.foliageRetention ?? 1), clamp01(season?.snow ?? 0), uWet.value);
|
|
239
|
+
uBounds.value.set(fields.x0, fields.z0, 1 / Math.max(1e-4, fields.width), 1 / Math.max(1e-4, fields.depth));
|
|
240
|
+
const count = Math.min(nx * nz, fields.shelter.length);
|
|
241
|
+
for (let k = 0; k < count; k++) {
|
|
242
|
+
data[k * 4] = Math.round(clamp01(fields.shelter[k]) * 255);
|
|
243
|
+
data[k * 4 + 1] = Math.round(clamp01(fields.sky[k]) * 255);
|
|
244
|
+
data[k * 4 + 2] = Math.round(clamp01(fields.litter[k]) * 255);
|
|
245
|
+
data[k * 4 + 3] = Math.round(clamp01(fields.coniferShare[k]) * 255);
|
|
246
|
+
}
|
|
247
|
+
canopyTex.needsUpdate = true;
|
|
248
|
+
};
|
|
249
|
+
upload(initial, 0);
|
|
250
|
+
const sampleTex = (xz) => {
|
|
251
|
+
const uv = clamp(vec2(xz.x.sub(uBounds.x).mul(uBounds.z), xz.y.sub(uBounds.y).mul(uBounds.w)), vec2(0.001), vec2(0.999));
|
|
252
|
+
return texture(canopyTex, uv).level(float(0));
|
|
253
|
+
};
|
|
254
|
+
return {
|
|
255
|
+
get fields() {
|
|
256
|
+
return current;
|
|
257
|
+
},
|
|
258
|
+
canopyTex,
|
|
259
|
+
sampleCpu(x, z) {
|
|
260
|
+
return sampleCanopyCpu(current, x, z);
|
|
261
|
+
},
|
|
262
|
+
shelterAt(xz) {
|
|
263
|
+
return sampleTex(xz).r;
|
|
264
|
+
},
|
|
265
|
+
skyAt(xz) {
|
|
266
|
+
return sampleTex(xz).g;
|
|
267
|
+
},
|
|
268
|
+
litterAt(xz) {
|
|
269
|
+
const s = sampleTex(xz);
|
|
270
|
+
return { litter: s.b, coniferShare: s.a };
|
|
271
|
+
},
|
|
272
|
+
tintAt(xz) {
|
|
273
|
+
const s = sampleTex(xz);
|
|
274
|
+
const sh = s.r;
|
|
275
|
+
const conif = s.a;
|
|
276
|
+
const broadSummer = vec3(0.89, 1.04, 0.8);
|
|
277
|
+
const broadAutumn = vec3(1.08, 0.9, 0.68);
|
|
278
|
+
const broadBounce = mix(vec3(1, 1, 1), mix(broadSummer, broadAutumn, uSeason.x), uSeason.y);
|
|
279
|
+
const conifBounce = vec3(0.88, 0.96, 0.89);
|
|
280
|
+
const target = mix(broadBounce, conifBounce, conif);
|
|
281
|
+
const bounce = mix(vec3(1, 1, 1), target, sh.mul(0.5));
|
|
282
|
+
const snowBounce = float(1).add(uSeason.z.mul(0.2));
|
|
283
|
+
const wetDark = float(1).sub(uWet.mul(0.2));
|
|
284
|
+
return bounce.mul(snowBounce).mul(wetDark);
|
|
285
|
+
},
|
|
286
|
+
lightAt(_xz) {
|
|
287
|
+
return vec3(float(1).sub(uWet.mul(0.14)));
|
|
288
|
+
},
|
|
289
|
+
update: upload,
|
|
290
|
+
dispose() {
|
|
291
|
+
canopyTex.dispose();
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=canopy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canopy.js","sourceRoot":"","sources":["../src/canopy.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,wFAAwF;AACxF,EAAE;AACF,+EAA+E;AAC/E,6FAA6F;AAE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AC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YACpD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YAC5C,OAAO,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,CAAC,GAAS;YACf,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC;QACD,MAAM,EAAE,MAAM;QACd,OAAO;YACL,SAAS,CAAC,OAAO,EAAE,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Biotic canopy feedback: sun-invariant daily shelter, hemispherical sky openness,\n// leaf/needle litter aprons, and ectomycorrhizal root zones computed from placed trees.\n//\n// Bridges `webgpu-trees` overstory stands to `webgpu-grass` `WorldLight` hooks\n// (`shelter`, `sky`, `tint`, `light`), the unified forest floor, and Phase 1 `webgpu-flora`.\n\nimport * as THREE from \"three/webgpu\";\nimport { clamp, float, mix, texture, uniform, vec2, vec3, vec4 } from \"three/tsl\";\nimport { TREE_STRIDE, type TreeSpecies } from \"webgpu-trees\";\nimport type { SubstrateBounds } from \"./substrate.ts\";\n\ntype Vec2 = THREE.Node<\"vec2\">;\ntype Vec3 = THREE.Node<\"vec3\">;\ntype Float = THREE.Node<\"float\">;\n\nexport interface CanopyFields {\n nx: number;\n nz: number;\n x0: number;\n z0: number;\n cell: number;\n width: number;\n depth: number;\n /** Daily sky-light reduction `0` (open) to `1` (dense closed canopy). */\n shelter: Float32Array;\n /** Hemispherical sky visibility `0..1` at ground level. */\n sky: Float32Array;\n /** Accumulated leaf/needle duff depth `0..1`. */\n litter: Float32Array;\n /** Conifer fraction of litter `0..1` (0 = broadleaf duff, 1 = needle mat). */\n coniferShare: Float32Array;\n /** Ectomycorrhizal root-zone influence `0..1` for forest fungi placement. */\n mycorrhiza: Float32Array;\n}\n\nexport interface CanopySample {\n shelter: number;\n sky: number;\n litter: number;\n coniferShare: number;\n mycorrhiza: number;\n}\n\nexport interface MycorrhizaBoost {\n x: number;\n z: number;\n radius: number;\n strength: number;\n}\n\nexport interface BakeCanopyOptions {\n bounds: SubstrateBounds;\n cell?: number;\n trees: Float32Array;\n species: readonly TreeSpecies[];\n /** Seasonal deciduous leaf retention `0..1` (default `1`). */\n foliageRetention?: number;\n /** Optional inoculated mycorrhizal root-zone patches. */\n mycorrhizaBoosts?: readonly MycorrhizaBoost[];\n}\n\nexport interface BiomeCanopy {\n readonly fields: CanopyFields;\n readonly canopyTex: THREE.DataTexture;\n sampleCpu(x: number, z: number): CanopySample;\n shelterAt(xz: Vec2): Float;\n skyAt(xz: Vec2): Float;\n litterAt(xz: Vec2): { litter: Float; coniferShare: Float };\n tintAt(xz: Vec2): Vec3;\n lightAt(xz: Vec2): Vec3;\n update(fields: CanopyFields, wetness: number, season?: { autumnTurn?: number; foliageRetention?: number; snow?: number }): void;\n dispose(): void;\n}\n\nconst ECTOMYCORRHIZAL_HOSTS = new Set([\n \"Oak\",\n \"Red oak\",\n \"Coast live oak\",\n \"Holm oak\",\n \"Beech\",\n \"Sweet chestnut\",\n \"Silver birch\",\n \"Black poplar\",\n \"Hornbeam\",\n \"Scots pine\",\n \"Corsican pine\",\n \"Monterey pine\",\n \"Torrey pine\",\n \"Aleppo pine\",\n \"Stone pine\",\n \"Eastern white pine\",\n \"Spruce\",\n \"Sitka spruce\",\n \"White spruce\",\n \"Subalpine fir\",\n \"Douglas fir\",\n \"European larch\",\n \"Western hemlock\",\n]);\n\nfunction clamp01(v: number): number {\n return v < 0 ? 0 : v > 1 ? 1 : v;\n}\n\n/** Monsi-Saeki crown leaf area index from species openness (`trees/src/light.ts`). */\nfunction leafAreaIndex(openness: number): number {\n return 1.5 + 4.8 * (1 - clamp01(openness));\n}\n\n/** Bake canopy shelter, sky openness, litter, conifer fraction, and mycorrhizal fields on CPU. */\nexport function bakeCanopyCpu(opts: BakeCanopyOptions): CanopyFields {\n const { bounds, trees, species } = opts;\n const cell = Math.max(0.5, opts.cell ?? 2);\n const retention = clamp01(opts.foliageRetention ?? 1);\n const nx = Math.max(2, Math.ceil(bounds.width / cell) + 1);\n const nz = Math.max(2, Math.ceil(bounds.depth / cell) + 1);\n const n = nx * nz;\n\n const shelter = new Float32Array(n);\n const sky = new Float32Array(n).fill(1);\n const litter = new Float32Array(n);\n const coniferShare = new Float32Array(n);\n const mycorrhiza = new Float32Array(n);\n\n const count = Math.floor(trees.length / TREE_STRIDE);\n if (count === 0) {\n return {\n nx,\n nz,\n x0: bounds.x0,\n z0: bounds.z0,\n cell,\n width: bounds.width,\n depth: bounds.depth,\n shelter,\n sky,\n litter,\n coniferShare,\n mycorrhiza,\n };\n }\n\n // Accumulate per-tree discs directly into covered grid cells (fast O(count * r^2)).\n const opticalSum = new Float32Array(n);\n const litterSum = new Float32Array(n);\n const coniferLitSum = new Float32Array(n);\n\n for (let t = 0; t < count; t++) {\n const o = t * TREE_STRIDE;\n const tx = trees[o];\n const tz = trees[o + 2];\n const spIdx = Math.round(trees[o + 3]);\n const sp = species[spIdx];\n if (!sp) continue;\n\n const rRaw = trees[o + 5];\n const crownRadius = Number.isFinite(rRaw) && rRaw > 0 ? rRaw : sp.crownRadius;\n const isConifer =\n sp.architecture === \"conifer\" ||\n (sp.leafKind === \"pine\" && sp.name !== \"Gorse\") ||\n sp.leafKind === \"needle\" ||\n sp.name === \"Monterey cypress\";\n const isDeciduousLarch = sp.name === \"European larch\";\n const isEvergreen =\n (isConifer && !isDeciduousLarch) ||\n sp.architecture === \"palm\" ||\n sp.name === \"Gorse\" ||\n sp.name === \"Coast live oak\" ||\n sp.name === \"Eucalyptus\";\n const leafKeep = isEvergreen ? 1 : 0.14 + 0.86 * retention;\n\n // Optical thickness from species openness via Monsi-Saeki LAI.\n const lai = leafAreaIndex(sp.openness) * leafKeep;\n const shadeStrength = 1 - Math.exp(-0.34 * lai);\n\n const shadeR = crownRadius * 1.25;\n const litterR = crownRadius * 1.38;\n const collarR = Math.max(0.55, crownRadius * 0.26);\n const mycoHost = ECTOMYCORRHIZAL_HOSTS.has(sp.name);\n const maxR = mycoHost ? Math.max(litterR, crownRadius * 1.85) : litterR;\n\n const i0 = Math.max(0, Math.floor((tx - maxR - bounds.x0) / cell));\n const i1 = Math.min(nx - 1, Math.ceil((tx + maxR - bounds.x0) / cell));\n const j0 = Math.max(0, Math.floor((tz - maxR - bounds.z0) / cell));\n const j1 = Math.min(nz - 1, Math.ceil((tz + maxR - bounds.z0) / cell));\n\n for (let j = j0; j <= j1; j++) {\n const z = bounds.z0 + j * cell;\n const dz = z - tz;\n for (let i = i0; i <= i1; i++) {\n const x = bounds.x0 + i * cell;\n const dx = x - tx;\n const rawDist = Math.hypot(dx, dz);\n const k = j * nx + i;\n\n const ang = Math.atan2(dz, dx);\n const lobeMod =\n 1 +\n 0.22 * Math.sin(ang * 3 + t * 1.9) +\n 0.14 * Math.cos(ang * 5 - t * 2.7) +\n 0.1 * Math.sin((x + z) * 0.45);\n const dist = rawDist / Math.max(0.55, lobeMod);\n\n if (dist < shadeR) {\n const u = dist / shadeR;\n const profile = Math.pow(Math.max(0, 1 - u * u), 0.72);\n opticalSum[k] += shadeStrength * profile;\n }\n\n if (dist < litterR) {\n const u = dist / litterR;\n let duff = Math.pow(Math.max(0, 1 - u * u), 1.2) * (isConifer ? 0.78 : 0.68);\n if (dist < collarR) {\n const cu = dist / collarR;\n duff += 0.24 * Math.pow(Math.max(0, 1 - cu * cu), 1.5);\n }\n litterSum[k] += duff;\n if (isConifer) coniferLitSum[k] += duff;\n }\n\n if (mycoHost) {\n const mycoR = crownRadius * 1.85;\n if (dist < mycoR) {\n const u = dist / mycoR;\n // Ring-weighted around root drip line (0.35..0.95 of radius).\n const ring = Math.exp(-Math.pow((u - 0.58) / 0.34, 2));\n mycorrhiza[k] = Math.max(mycorrhiza[k], clamp01(ring * 0.95));\n }\n }\n }\n }\n }\n\n for (let k = 0; k < n; k++) {\n const sh = clamp01(1 - Math.exp(-opticalSum[k] * 1.15));\n shelter[k] = sh;\n sky[k] = Math.max(0.14, 1 - 0.78 * sh);\n const lit = clamp01(1 - Math.exp(-litterSum[k] * 1.25));\n litter[k] = lit;\n coniferShare[k] = litterSum[k] > 1e-4 ? clamp01(coniferLitSum[k] / litterSum[k]) : 0;\n }\n\n if (opts.mycorrhizaBoosts && opts.mycorrhizaBoosts.length > 0) {\n for (const boost of opts.mycorrhizaBoosts) {\n const r = Math.max(1, boost.radius);\n const str = clamp01(boost.strength);\n const bi0 = Math.max(0, Math.floor((boost.x - r - bounds.x0) / cell));\n const bi1 = Math.min(nx - 1, Math.ceil((boost.x + r - bounds.x0) / cell));\n const bj0 = Math.max(0, Math.floor((boost.z - r - bounds.z0) / cell));\n const bj1 = Math.min(nz - 1, Math.ceil((boost.z + r - bounds.z0) / cell));\n for (let j = bj0; j <= bj1; j++) {\n const dz = bounds.z0 + j * cell - boost.z;\n for (let i = bi0; i <= bi1; i++) {\n const dx = bounds.x0 + i * cell - boost.x;\n const d = Math.hypot(dx, dz);\n if (d < r) {\n const u = d / r;\n const add = str * Math.pow(Math.max(0, 1 - u * u), 1.2);\n const idx = j * nx + i;\n mycorrhiza[idx] = Math.max(mycorrhiza[idx], clamp01(add));\n }\n }\n }\n }\n }\n\n return {\n nx,\n nz,\n x0: bounds.x0,\n z0: bounds.z0,\n cell,\n width: bounds.width,\n depth: bounds.depth,\n shelter,\n sky,\n litter,\n coniferShare,\n mycorrhiza,\n };\n}\n\n/** Bilinear sample of baked canopy fields at world `(x, z)`. */\nexport function sampleCanopyCpu(fields: CanopyFields, x: number, z: number): CanopySample {\n const fx = Math.min(fields.nx - 1.001, Math.max(0, (x - fields.x0) / fields.cell));\n const fz = Math.min(fields.nz - 1.001, Math.max(0, (z - fields.z0) / fields.cell));\n const i0 = Math.floor(fx);\n const j0 = Math.floor(fz);\n const i1 = Math.min(fields.nx - 1, i0 + 1);\n const j1 = Math.min(fields.nz - 1, j0 + 1);\n const tx = fx - i0;\n const tz = fz - j0;\n\n const bilerp = (arr: Float32Array): number => {\n const a = arr[j0 * fields.nx + i0];\n const b = arr[j0 * fields.nx + i1];\n const c = arr[j1 * fields.nx + i0];\n const d = arr[j1 * fields.nx + i1];\n return (a + (b - a) * tx) * (1 - tz) + (c + (d - c) * tx) * tz;\n };\n\n return {\n shelter: bilerp(fields.shelter),\n sky: bilerp(fields.sky),\n litter: bilerp(fields.litter),\n coniferShare: bilerp(fields.coniferShare),\n mycorrhiza: bilerp(fields.mycorrhiza),\n };\n}\n\n/** Upload `CanopyFields` to a single RGBA8 GPU texture and expose TSL nodes for `grass` & `ground`. */\nexport function createCanopyMap(initial: CanopyFields): BiomeCanopy {\n let current = initial;\n const { nx, nz } = initial;\n const data = new Uint8Array(nx * nz * 4);\n const canopyTex = new THREE.DataTexture(data, nx, nz, THREE.RGBAFormat, THREE.UnsignedByteType);\n canopyTex.colorSpace = THREE.NoColorSpace;\n canopyTex.magFilter = canopyTex.minFilter = THREE.LinearFilter;\n canopyTex.wrapS = canopyTex.wrapT = THREE.ClampToEdgeWrapping;\n canopyTex.generateMipmaps = false;\n\n const uBounds = uniform(vec4(initial.x0, initial.z0, 1 / Math.max(1e-4, initial.width), 1 / Math.max(1e-4, initial.depth)));\n const uWet = uniform(0);\n /** `(autumnTurn, foliageRetention, snow, wetness)` */\n const uSeason = uniform(new THREE.Vector4(0, 1, 0, 0));\n\n const upload = (\n fields: CanopyFields,\n wetness: number,\n season?: { autumnTurn?: number; foliageRetention?: number; snow?: number },\n ) => {\n current = fields;\n uWet.value = clamp01(wetness);\n uSeason.value.set(\n clamp01(season?.autumnTurn ?? 0),\n clamp01(season?.foliageRetention ?? 1),\n clamp01(season?.snow ?? 0),\n uWet.value,\n );\n uBounds.value.set(fields.x0, fields.z0, 1 / Math.max(1e-4, fields.width), 1 / Math.max(1e-4, fields.depth));\n const count = Math.min(nx * nz, fields.shelter.length);\n for (let k = 0; k < count; k++) {\n data[k * 4] = Math.round(clamp01(fields.shelter[k]) * 255);\n data[k * 4 + 1] = Math.round(clamp01(fields.sky[k]) * 255);\n data[k * 4 + 2] = Math.round(clamp01(fields.litter[k]) * 255);\n data[k * 4 + 3] = Math.round(clamp01(fields.coniferShare[k]) * 255);\n }\n canopyTex.needsUpdate = true;\n };\n upload(initial, 0);\n\n const sampleTex = (xz: Vec2) => {\n const uv = clamp(vec2(xz.x.sub(uBounds.x).mul(uBounds.z), xz.y.sub(uBounds.y).mul(uBounds.w)), vec2(0.001), vec2(0.999));\n return texture(canopyTex, uv).level(float(0));\n };\n\n return {\n get fields() {\n return current;\n },\n canopyTex,\n sampleCpu(x: number, z: number) {\n return sampleCanopyCpu(current, x, z);\n },\n shelterAt(xz: Vec2) {\n return sampleTex(xz).r;\n },\n skyAt(xz: Vec2) {\n return sampleTex(xz).g;\n },\n litterAt(xz: Vec2) {\n const s = sampleTex(xz);\n return { litter: s.b, coniferShare: s.a };\n },\n tintAt(xz: Vec2) {\n const s = sampleTex(xz);\n const sh = s.r;\n const conif = s.a;\n const broadSummer = vec3(0.89, 1.04, 0.8);\n const broadAutumn = vec3(1.08, 0.9, 0.68);\n const broadBounce = mix(vec3(1, 1, 1), mix(broadSummer, broadAutumn, uSeason.x), uSeason.y);\n const conifBounce = vec3(0.88, 0.96, 0.89);\n const target = mix(broadBounce, conifBounce, conif);\n const bounce = mix(vec3(1, 1, 1), target, sh.mul(0.5));\n const snowBounce = float(1).add(uSeason.z.mul(0.2));\n const wetDark = float(1).sub(uWet.mul(0.2));\n return bounce.mul(snowBounce).mul(wetDark);\n },\n lightAt(_xz: Vec2) {\n return vec3(float(1).sub(uWet.mul(0.14)));\n },\n update: upload,\n dispose() {\n canopyTex.dispose();\n },\n };\n}\n"]}
|
package/lib/climate.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type AtmosphereOptions } from "webgpu-trees";
|
|
2
|
+
export interface ClimateOptions {
|
|
3
|
+
/** Site latitude in degrees (-66..66). */
|
|
4
|
+
latitude: number;
|
|
5
|
+
/** Day of the year (1..365, where 1 = Jan 1). */
|
|
6
|
+
day: number;
|
|
7
|
+
/** Local solar hour (0..24). */
|
|
8
|
+
hour: number;
|
|
9
|
+
/** Wind heading in degrees clockwise from +z toward +x. */
|
|
10
|
+
windHeading: number;
|
|
11
|
+
/** Wind speed in metres per second. */
|
|
12
|
+
windSpeed: number;
|
|
13
|
+
/** Surface wetness / dew in `[0, 1]`. */
|
|
14
|
+
wetness: number;
|
|
15
|
+
/** Manual snow cover boost / override in `[0, 1]` (combines with `PhenologyState.winterSnow`). */
|
|
16
|
+
snow: number;
|
|
17
|
+
/** Summer turf drought stress in `[0, 1]`. */
|
|
18
|
+
drought: number;
|
|
19
|
+
/** Drifting cloud shadow cover in `[0, 1]`. */
|
|
20
|
+
cloudCover: number;
|
|
21
|
+
/** Bark crustose/foliose lichen cover in `[0, 1]`. */
|
|
22
|
+
lichen: number;
|
|
23
|
+
/** Physical atmosphere scattering parameters. */
|
|
24
|
+
atmosphere: AtmosphereOptions;
|
|
25
|
+
}
|
|
26
|
+
export declare const DEFAULT_CLIMATE: ClimateOptions;
|
|
27
|
+
export interface PhenologyState {
|
|
28
|
+
/** Deciduous tree canopy leaf retention in `[0, 1]` (0 = winter bare, 1 = full summer canopy). */
|
|
29
|
+
foliageRetention: number;
|
|
30
|
+
/** Spring budburst freshness `[0, 1]`. */
|
|
31
|
+
springFlush: number;
|
|
32
|
+
/** Autumn senescence warmth `[0, 1]`. */
|
|
33
|
+
autumnTurn: number;
|
|
34
|
+
/** Turf strain variegation strength (`grass.look.strains`), strongest in spring & autumn. */
|
|
35
|
+
strains: number;
|
|
36
|
+
/** Late-summer heather (*Calluna*) bloom peak `[0, 1]`. */
|
|
37
|
+
heatherBloom: number;
|
|
38
|
+
/** Autumn mycorrhizal fungi fruiting window `[0, 1]`. */
|
|
39
|
+
fungiSeason: number;
|
|
40
|
+
/** Seasonal winter snowpack curve `[0, 0.86]` peaking in Jan/Feb & late Dec. */
|
|
41
|
+
winterSnow: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Compute unit vector pointing toward the sun (`+x` east, `+y` up, `-z` north)
|
|
45
|
+
* from site latitude (deg), day of year (1..365), and solar hour (0..24).
|
|
46
|
+
* Clamps extreme low elevation gently above `-0.04` so shader lighting stays stable at dusk/dawn.
|
|
47
|
+
*/
|
|
48
|
+
export declare function evalSolarDirection(latitudeDeg: number, dayOfYear: number, hour: number): [number, number, number];
|
|
49
|
+
/**
|
|
50
|
+
* Evaluate continuous temperate/boreal phenology curves from day of year `1..365`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function evalPhenology(dayOfYear: number): PhenologyState;
|
|
53
|
+
export type SeasonPreset = "Spring" | "Summer" | "LateSummer" | "Autumn" | "Winter";
|
|
54
|
+
/** Map a day of the year (`1..365`) to its nearest season preset label. */
|
|
55
|
+
export declare function seasonPresetForDay(dayOfYear: number): SeasonPreset;
|
|
56
|
+
/** Combine explicit climate `snow` cover (`0..1`) truthfully without overriding user settings. */
|
|
57
|
+
export declare function effectiveSnow(climate: Pick<ClimateOptions, "snow">, _phenology?: Pick<PhenologyState, "winterSnow">): number;
|
|
58
|
+
/**
|
|
59
|
+
* Derive balanced linear RGB `sunTint` and `shadeTint` from solar elevation and
|
|
60
|
+
* `evalSkyScattering`, calibrated to match `webgpu-trees` and `webgpu-grass`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function evalDaylightTints(sunDir: readonly [number, number, number], atm?: Partial<AtmosphereOptions>): {
|
|
63
|
+
sunTint: [number, number, number];
|
|
64
|
+
shadeTint: [number, number, number];
|
|
65
|
+
};
|
|
66
|
+
/** Convert wind heading (deg) and speed (m/s) into `TreeEnvironment.wind` / `Grass.environment.wind`. */
|
|
67
|
+
export declare function windVectorFrom(headingDeg: number, speedMs: number): [number, number, number];
|
|
68
|
+
//# sourceMappingURL=climate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"climate.d.ts","sourceRoot":"","sources":["../src/climate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,iBAAiB,EAAyC,MAAM,cAAc,CAAC;AAE7F,MAAM,WAAW,cAAc;IAC7B,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,WAAW,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,kGAAkG;IAClG,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,UAAU,EAAE,iBAAiB,CAAC;CAC/B;AAED,eAAO,MAAM,eAAe,EAAE,cAY7B,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,kGAAkG;IAClG,gBAAgB,EAAE,MAAM,CAAC;IACzB,0CAA0C;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,6FAA6F;IAC7F,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,YAAY,EAAE,MAAM,CAAC;IACrB,yDAAyD;IACzD,WAAW,EAAE,MAAM,CAAC;IACpB,gFAAgF;IAChF,UAAU,EAAE,MAAM,CAAC;CACpB;AAWD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,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