webgpu-grass 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +645 -2
- package/lib/distance.d.ts +63 -0
- package/lib/distance.d.ts.map +1 -0
- package/lib/distance.js +148 -0
- package/lib/distance.js.map +1 -0
- package/lib/engine.d.ts +402 -0
- package/lib/engine.d.ts.map +1 -0
- package/lib/engine.js +3253 -0
- package/lib/engine.js.map +1 -0
- package/lib/field.d.ts +133 -0
- package/lib/field.d.ts.map +1 -0
- package/lib/field.js +244 -0
- package/lib/field.js.map +1 -0
- package/lib/flowers.d.ts +138 -0
- package/lib/flowers.d.ts.map +1 -0
- package/lib/flowers.js +117 -0
- package/lib/flowers.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +14 -0
- package/lib/index.js.map +1 -0
- package/lib/mix.d.ts +17 -0
- package/lib/mix.d.ts.map +1 -0
- package/lib/mix.js +95 -0
- package/lib/mix.js.map +1 -0
- package/lib/mixshare.d.ts +42 -0
- package/lib/mixshare.d.ts.map +1 -0
- package/lib/mixshare.js +144 -0
- package/lib/mixshare.js.map +1 -0
- package/lib/noise.d.ts +4 -0
- package/lib/noise.d.ts.map +1 -0
- package/lib/noise.js +49 -0
- package/lib/noise.js.map +1 -0
- package/lib/placement.d.ts +39 -0
- package/lib/placement.d.ts.map +1 -0
- package/lib/placement.js +67 -0
- package/lib/placement.js.map +1 -0
- package/lib/rank.d.ts +36 -0
- package/lib/rank.d.ts.map +1 -0
- package/lib/rank.js +158 -0
- package/lib/rank.js.map +1 -0
- package/lib/species.d.ts +408 -0
- package/lib/species.d.ts.map +1 -0
- package/lib/species.js +672 -0
- package/lib/species.js.map +1 -0
- package/lib/transitions.d.ts +72 -0
- package/lib/transitions.d.ts.map +1 -0
- package/lib/transitions.js +123 -0
- package/lib/transitions.js.map +1 -0
- package/package.json +60 -3
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Which distance grass techniques are active. All default to true; `distance: false` disables all. */
|
|
2
|
+
export interface GrassDistance {
|
|
3
|
+
/** Exact Gribb-Hartmann clip-space sphere frustum culling in compute (preserving near shadow casters). */
|
|
4
|
+
frustumCull: boolean;
|
|
5
|
+
/** Self-contained 6-tap heightfield ray occlusion culling behind ridges and dunes. */
|
|
6
|
+
horizonCull: boolean;
|
|
7
|
+
/** Grazing-angle tuft/card density & range boost along ridges, plus overhead thinning to avoid stars. */
|
|
8
|
+
grazingLod: boolean;
|
|
9
|
+
/** Procedural 16-tri horizon blade ring out to 84 m with sub-pixel tuft feathering. */
|
|
10
|
+
horizonLod: boolean;
|
|
11
|
+
/** Variance-preserving 3-tap simplex hex-tiling on distant ground (7–84 m) with zero extra textures: it reads the ground pictures `groundShade` binds already. */
|
|
12
|
+
hexGround: boolean;
|
|
13
|
+
/** Analytical wind-tilted canopy normal & waxy Fresnel sheen waves on distant tall grass. */
|
|
14
|
+
windSheen: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare const DEFAULT_DISTANCE: Readonly<GrassDistance>;
|
|
17
|
+
/** Resolve `GrassOptions.distance` (`undefined`, `boolean`, or partial overrides) into a mutable flags object. */
|
|
18
|
+
export declare function resolveDistance(init?: boolean | (Partial<GrassDistance> & {
|
|
19
|
+
clumpCards?: boolean;
|
|
20
|
+
})): GrassDistance;
|
|
21
|
+
/**
|
|
22
|
+
* How far above its root (and so, leaning, to any side) a plant of a species can reach, as a multiple of the
|
|
23
|
+
* species' `height`: the most each of the compute pass's height factors can give at once. The plant's own
|
|
24
|
+
* luck and the disorder of the stand (up to 1.26), its clump (up to 1.25), a patch of taller grass (`patchTall`),
|
|
25
|
+
* a blade's own length (its share of the height spread above the mean, or a mown leaf's up to 1.8 of the cut),
|
|
26
|
+
* and a seed stalk (1.2). The frustum cull sizes its sphere round each root from this, so no blade that leans
|
|
27
|
+
* into the picture from a plant outside it is lost.
|
|
28
|
+
*/
|
|
29
|
+
export declare const PLANT_REACH_LUCK: number;
|
|
30
|
+
export declare function plantReach(s: {
|
|
31
|
+
height: number;
|
|
32
|
+
heightSpread: number;
|
|
33
|
+
patchTall?: number;
|
|
34
|
+
tip?: string;
|
|
35
|
+
}): number;
|
|
36
|
+
/**
|
|
37
|
+
* Given a column-major projection-view matrix `m`, return `[padX, padY]`: the max Euclidean norm
|
|
38
|
+
* of the Left/Right and Bottom/Top Gribb-Hartmann frustum plane xyz normals so a world-space
|
|
39
|
+
* sphere of `radius` can be tested conservatively in clip space via `|cx| <= cw + radius * padX`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function frustumPlanesPad(m: ArrayLike<number>): [number, number];
|
|
42
|
+
/**
|
|
43
|
+
* Conservative clip-space sphere test against a column-major projection-view matrix `m`,
|
|
44
|
+
* using the plane normal lengths from `frustumPlanesPad(m)`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function inFrustumSphere(m: ArrayLike<number>, x: number, y: number, z: number, radius: number, padX: number, padY: number): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Plain-number twin of the 6-tap heightfield ray occlusion check in compute:
|
|
49
|
+
* discards mid/far plants whose tips sit below a terrain ridge between the plant and the camera.
|
|
50
|
+
*/
|
|
51
|
+
export declare function isHorizonOccluded(heightAt: (x: number, z: number) => number, x: number, gy: number, z: number, tall0: number, camX: number, camY: number, camZ: number, heightSpread?: number): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Plain-number twin of the simplex triangle-grid barycentric lookup & power-4 sharpened
|
|
54
|
+
* weights used for variance-preserving 3-tap hex-tiling (Heitz & Neyret).
|
|
55
|
+
*/
|
|
56
|
+
export declare function hexTileWeights(u: number, v: number): {
|
|
57
|
+
v1: [number, number];
|
|
58
|
+
v2: [number, number];
|
|
59
|
+
v3: [number, number];
|
|
60
|
+
w: [number, number, number];
|
|
61
|
+
normW: number;
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=distance.d.ts.map
|
|
@@ -0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GACX,OAAO,CAKT;AAID;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,EAC1C,CAAC,EAAE,MAAM,EACT,EAAE,EAAE,MAAM,EACV,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,YAAY,SAAM,GACjB,OAAO,CAaT;AAMD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG;IACpD,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrB,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrB,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;CACf,CA8CA"}
|
package/lib/distance.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// Distance rendering switches and their plain-number twins: frustum culling,
|
|
2
|
+
// heightfield horizon culling, grazing-angle LOD, clump impostor cards,
|
|
3
|
+
// variance-preserving hex-tiling on distant ground, and wind-tilted canopy sheen.
|
|
4
|
+
export const DEFAULT_DISTANCE = {
|
|
5
|
+
frustumCull: true,
|
|
6
|
+
horizonCull: true,
|
|
7
|
+
grazingLod: true,
|
|
8
|
+
horizonLod: true,
|
|
9
|
+
hexGround: true,
|
|
10
|
+
windSheen: true,
|
|
11
|
+
};
|
|
12
|
+
/** Resolve `GrassOptions.distance` (`undefined`, `boolean`, or partial overrides) into a mutable flags object. */
|
|
13
|
+
export function resolveDistance(init) {
|
|
14
|
+
if (init === false) {
|
|
15
|
+
return {
|
|
16
|
+
frustumCull: false,
|
|
17
|
+
horizonCull: false,
|
|
18
|
+
grazingLod: false,
|
|
19
|
+
horizonLod: false,
|
|
20
|
+
hexGround: false,
|
|
21
|
+
windSheen: false,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (init === true || init === undefined)
|
|
25
|
+
return { ...DEFAULT_DISTANCE };
|
|
26
|
+
const horizonLodVal = init.horizonLod !== undefined ? init.horizonLod : init.clumpCards;
|
|
27
|
+
return {
|
|
28
|
+
frustumCull: init.frustumCull !== undefined ? Boolean(init.frustumCull) : DEFAULT_DISTANCE.frustumCull,
|
|
29
|
+
horizonCull: init.horizonCull !== undefined ? Boolean(init.horizonCull) : DEFAULT_DISTANCE.horizonCull,
|
|
30
|
+
grazingLod: init.grazingLod !== undefined ? Boolean(init.grazingLod) : DEFAULT_DISTANCE.grazingLod,
|
|
31
|
+
horizonLod: horizonLodVal !== undefined ? Boolean(horizonLodVal) : DEFAULT_DISTANCE.horizonLod,
|
|
32
|
+
hexGround: init.hexGround !== undefined ? Boolean(init.hexGround) : DEFAULT_DISTANCE.hexGround,
|
|
33
|
+
windSheen: init.windSheen !== undefined ? Boolean(init.windSheen) : DEFAULT_DISTANCE.windSheen,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* How far above its root (and so, leaning, to any side) a plant of a species can reach, as a multiple of the
|
|
38
|
+
* species' `height`: the most each of the compute pass's height factors can give at once. The plant's own
|
|
39
|
+
* luck and the disorder of the stand (up to 1.26), its clump (up to 1.25), a patch of taller grass (`patchTall`),
|
|
40
|
+
* a blade's own length (its share of the height spread above the mean, or a mown leaf's up to 1.8 of the cut),
|
|
41
|
+
* and a seed stalk (1.2). The frustum cull sizes its sphere round each root from this, so no blade that leans
|
|
42
|
+
* into the picture from a plant outside it is lost.
|
|
43
|
+
*/
|
|
44
|
+
export const PLANT_REACH_LUCK = 1.26 * 1.25 * 1.2;
|
|
45
|
+
export function plantReach(s) {
|
|
46
|
+
const mown = s.tip === "cut" || s.tip === "square";
|
|
47
|
+
const blade = Math.max(1 + 0.5 * s.heightSpread, mown ? 1.8 : 0);
|
|
48
|
+
return s.height * Math.max(1, s.patchTall ?? 1) * blade * PLANT_REACH_LUCK;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Given a column-major projection-view matrix `m`, return `[padX, padY]`: the max Euclidean norm
|
|
52
|
+
* of the Left/Right and Bottom/Top Gribb-Hartmann frustum plane xyz normals so a world-space
|
|
53
|
+
* sphere of `radius` can be tested conservatively in clip space via `|cx| <= cw + radius * padX`.
|
|
54
|
+
*/
|
|
55
|
+
export function frustumPlanesPad(m) {
|
|
56
|
+
const lenL = Math.hypot(m[3] + m[0], m[7] + m[4], m[11] + m[8]);
|
|
57
|
+
const lenR = Math.hypot(m[3] - m[0], m[7] - m[4], m[11] - m[8]);
|
|
58
|
+
const lenB = Math.hypot(m[3] + m[1], m[7] + m[5], m[11] + m[9]);
|
|
59
|
+
const lenT = Math.hypot(m[3] - m[1], m[7] - m[5], m[11] - m[9]);
|
|
60
|
+
return [Math.max(lenL, lenR), Math.max(lenB, lenT)];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Conservative clip-space sphere test against a column-major projection-view matrix `m`,
|
|
64
|
+
* using the plane normal lengths from `frustumPlanesPad(m)`.
|
|
65
|
+
*/
|
|
66
|
+
export function inFrustumSphere(m, x, y, z, radius, padX, padY) {
|
|
67
|
+
const cx = m[0] * x + m[4] * y + m[8] * z + m[12];
|
|
68
|
+
const cy = m[1] * x + m[5] * y + m[9] * z + m[13];
|
|
69
|
+
const cw = m[3] * x + m[7] * y + m[11] * z + m[15];
|
|
70
|
+
return cw > -radius && Math.abs(cx) <= cw + radius * padX && Math.abs(cy) <= cw + radius * padY;
|
|
71
|
+
}
|
|
72
|
+
const HORIZON_FIXED_STEPS = [0.2, 0.42, 0.64, 0.82];
|
|
73
|
+
/**
|
|
74
|
+
* Plain-number twin of the 6-tap heightfield ray occlusion check in compute:
|
|
75
|
+
* discards mid/far plants whose tips sit below a terrain ridge between the plant and the camera.
|
|
76
|
+
*/
|
|
77
|
+
export function isHorizonOccluded(heightAt, x, gy, z, tall0, camX, camY, camZ, heightSpread = 0.4) {
|
|
78
|
+
const dist2d = Math.hypot(x - camX, z - camZ);
|
|
79
|
+
if (dist2d <= 4)
|
|
80
|
+
return false;
|
|
81
|
+
const tipY = gy + tall0 * (1 + heightSpread * 0.5) * 1.22 + 0.02;
|
|
82
|
+
const tNear1 = Math.min(0.96, Math.max(0.15, 1 - 2.8 / dist2d));
|
|
83
|
+
const tNear2 = Math.min(0.92, Math.max(0.15, 1 - 6.0 / dist2d));
|
|
84
|
+
for (const t of [...HORIZON_FIXED_STEPS, tNear2, tNear1]) {
|
|
85
|
+
const px = x + (camX - x) * t;
|
|
86
|
+
const pz = z + (camZ - z) * t;
|
|
87
|
+
const rayY = tipY + (camY - tipY) * t;
|
|
88
|
+
if (heightAt(px, pz) - 0.02 >= rayY)
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
const SQRT3 = Math.sqrt(3);
|
|
94
|
+
const F2 = (SQRT3 - 1) / 2;
|
|
95
|
+
const G2 = (3 - SQRT3) / 6;
|
|
96
|
+
/**
|
|
97
|
+
* Plain-number twin of the simplex triangle-grid barycentric lookup & power-4 sharpened
|
|
98
|
+
* weights used for variance-preserving 3-tap hex-tiling (Heitz & Neyret).
|
|
99
|
+
*/
|
|
100
|
+
export function hexTileWeights(u, v) {
|
|
101
|
+
// Skewed simplex coordinates
|
|
102
|
+
const s = (u + v) * F2;
|
|
103
|
+
const i = Math.floor(u + s);
|
|
104
|
+
const j = Math.floor(v + s);
|
|
105
|
+
const t = (i + j) * G2;
|
|
106
|
+
const x0 = u - (i - t);
|
|
107
|
+
const y0 = v - (j - t);
|
|
108
|
+
const i1 = x0 > y0 ? 1 : 0;
|
|
109
|
+
const j1 = x0 > y0 ? 0 : 1;
|
|
110
|
+
const x1 = x0 - i1 + G2;
|
|
111
|
+
const y1 = y0 - j1 + G2;
|
|
112
|
+
const x2 = x0 - 1 + 2 * G2;
|
|
113
|
+
const y2 = y0 - 1 + 2 * G2;
|
|
114
|
+
// Barycentric weights within the simplex triangle (using symmetric falloff from vertices)
|
|
115
|
+
// Note: standard simplex triangle weights for hex-tiling:
|
|
116
|
+
// In the equilateral triangle formed by skewing (1,0), (0,1), (1,1) by inverse skew,
|
|
117
|
+
// or directly from affine coordinates in the skewed grid:
|
|
118
|
+
// Let's use exact affine barycentric coordinates in the skewed grid!
|
|
119
|
+
// In skewed space: p = (u+s, v+s) = (i, j) + (fx, fy) where fx = u+s-i, fy = v+s-j in [0,1)^2.
|
|
120
|
+
// If fx >= fy: triangle is (0,0), (1,0), (1,1) -> b1 = 1 - fx, b2 = fx - fy, b3 = fy!
|
|
121
|
+
// If fx < fy: triangle is (0,0), (0,1), (1,1) -> b1 = 1 - fy, b2 = fy - fx, b3 = fx!
|
|
122
|
+
const fx = u + s - i;
|
|
123
|
+
const fy = v + s - j;
|
|
124
|
+
const b1 = fx >= fy ? 1 - fx : 1 - fy;
|
|
125
|
+
const b2 = Math.abs(fx - fy);
|
|
126
|
+
const b3 = fx >= fy ? fy : fx;
|
|
127
|
+
// Power-4 sharpening normalized to sum to 1 (continuous C1/C2 across edges, zero at opposite edge)
|
|
128
|
+
const p1 = Math.pow(Math.max(0, b1), 4);
|
|
129
|
+
const p2 = Math.pow(Math.max(0, b2), 4);
|
|
130
|
+
const p3 = Math.pow(Math.max(0, b3), 4);
|
|
131
|
+
const pSum = Math.max(p1 + p2 + p3, 1e-6);
|
|
132
|
+
const w1 = p1 / pSum;
|
|
133
|
+
const w2 = p2 / pSum;
|
|
134
|
+
const w3 = p3 / pSum;
|
|
135
|
+
const normW = Math.max(Math.hypot(w1, w2, w3), 0.57735);
|
|
136
|
+
void x1;
|
|
137
|
+
void y1;
|
|
138
|
+
void x2;
|
|
139
|
+
void y2;
|
|
140
|
+
return {
|
|
141
|
+
v1: [i, j],
|
|
142
|
+
v2: [i + i1, j + j1],
|
|
143
|
+
v3: [i + 1, j + 1],
|
|
144
|
+
w: [w1, w2, w3],
|
|
145
|
+
normW,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=distance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distance.js","sourceRoot":"","sources":["../src/distance.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wEAAwE;AACxE,kFAAkF;AAkBlF,MAAM,CAAC,MAAM,gBAAgB,GAA4B;IACvD,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,IAAI;IAChB,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,IAAI;CAChB,CAAC;AAEF,kHAAkH;AAClH,MAAM,UAAU,eAAe,CAAC,IAAoE;IAClG,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACnB,OAAO;YACL,WAAW,EAAE,KAAK;YAClB,WAAW,EAAE,KAAK;YAClB,UAAU,EAAE,KAAK;YACjB,UAAU,EAAE,KAAK;YACjB,SAAS,EAAE,KAAK;YAChB,SAAS,EAAE,KAAK;SACjB,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACxE,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;IACxF,OAAO;QACL,WAAW,EAAE,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,WAAW;QACtG,WAAW,EAAE,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,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Content":["// Distance rendering switches and their plain-number twins: frustum culling,\n// heightfield horizon culling, grazing-angle LOD, clump impostor cards,\n// variance-preserving hex-tiling on distant ground, and wind-tilted canopy sheen.\n\n/** Which distance grass techniques are active. All default to true; `distance: false` disables all. */\nexport interface GrassDistance {\n /** Exact Gribb-Hartmann clip-space sphere frustum culling in compute (preserving near shadow casters). */\n frustumCull: boolean;\n /** Self-contained 6-tap heightfield ray occlusion culling behind ridges and dunes. */\n horizonCull: boolean;\n /** Grazing-angle tuft/card density & range boost along ridges, plus overhead thinning to avoid stars. */\n grazingLod: boolean;\n /** Procedural 16-tri horizon blade ring out to 84 m with sub-pixel tuft feathering. */\n horizonLod: boolean;\n /** Variance-preserving 3-tap simplex hex-tiling on distant ground (7–84 m) with zero extra textures: it reads the ground pictures `groundShade` binds already. */\n hexGround: boolean;\n /** Analytical wind-tilted canopy normal & waxy Fresnel sheen waves on distant tall grass. */\n windSheen: boolean;\n}\n\nexport const DEFAULT_DISTANCE: Readonly<GrassDistance> = {\n frustumCull: true,\n horizonCull: true,\n grazingLod: true,\n horizonLod: true,\n hexGround: true,\n windSheen: true,\n};\n\n/** Resolve `GrassOptions.distance` (`undefined`, `boolean`, or partial overrides) into a mutable flags object. */\nexport function resolveDistance(init?: boolean | (Partial<GrassDistance> & { clumpCards?: boolean })): GrassDistance {\n if (init === false) {\n return {\n frustumCull: false,\n horizonCull: false,\n grazingLod: false,\n horizonLod: false,\n hexGround: false,\n windSheen: false,\n };\n }\n if (init === true || init === undefined) return { ...DEFAULT_DISTANCE };\n const horizonLodVal = init.horizonLod !== undefined ? init.horizonLod : init.clumpCards;\n return {\n frustumCull: init.frustumCull !== undefined ? Boolean(init.frustumCull) : DEFAULT_DISTANCE.frustumCull,\n horizonCull: init.horizonCull !== undefined ? Boolean(init.horizonCull) : DEFAULT_DISTANCE.horizonCull,\n grazingLod: init.grazingLod !== undefined ? Boolean(init.grazingLod) : DEFAULT_DISTANCE.grazingLod,\n horizonLod: horizonLodVal !== undefined ? Boolean(horizonLodVal) : DEFAULT_DISTANCE.horizonLod,\n hexGround: init.hexGround !== undefined ? Boolean(init.hexGround) : DEFAULT_DISTANCE.hexGround,\n windSheen: init.windSheen !== undefined ? Boolean(init.windSheen) : DEFAULT_DISTANCE.windSheen,\n };\n}\n\n/**\n * How far above its root (and so, leaning, to any side) a plant of a species can reach, as a multiple of the\n * species' `height`: the most each of the compute pass's height factors can give at once. The plant's own\n * luck and the disorder of the stand (up to 1.26), its clump (up to 1.25), a patch of taller grass (`patchTall`),\n * a blade's own length (its share of the height spread above the mean, or a mown leaf's up to 1.8 of the cut),\n * and a seed stalk (1.2). The frustum cull sizes its sphere round each root from this, so no blade that leans\n * into the picture from a plant outside it is lost.\n */\nexport const PLANT_REACH_LUCK = 1.26 * 1.25 * 1.2;\nexport function plantReach(s: { height: number; heightSpread: number; patchTall?: number; tip?: string }): number {\n const mown = s.tip === \"cut\" || s.tip === \"square\";\n const blade = Math.max(1 + 0.5 * s.heightSpread, mown ? 1.8 : 0);\n return s.height * Math.max(1, s.patchTall ?? 1) * blade * PLANT_REACH_LUCK;\n}\n\n/**\n * Given a column-major projection-view matrix `m`, return `[padX, padY]`: the max Euclidean norm\n * of the Left/Right and Bottom/Top Gribb-Hartmann frustum plane xyz normals so a world-space\n * sphere of `radius` can be tested conservatively in clip space via `|cx| <= cw + radius * padX`.\n */\nexport function frustumPlanesPad(m: ArrayLike<number>): [number, number] {\n const lenL = Math.hypot(m[3] + m[0], m[7] + m[4], m[11] + m[8]);\n const lenR = Math.hypot(m[3] - m[0], m[7] - m[4], m[11] - m[8]);\n const lenB = Math.hypot(m[3] + m[1], m[7] + m[5], m[11] + m[9]);\n const lenT = Math.hypot(m[3] - m[1], m[7] - m[5], m[11] - m[9]);\n return [Math.max(lenL, lenR), Math.max(lenB, lenT)];\n}\n\n/**\n * Conservative clip-space sphere test against a column-major projection-view matrix `m`,\n * using the plane normal lengths from `frustumPlanesPad(m)`.\n */\nexport function inFrustumSphere(\n m: ArrayLike<number>,\n x: number,\n y: number,\n z: number,\n radius: number,\n padX: number,\n padY: number,\n): boolean {\n const cx = m[0] * x + m[4] * y + m[8] * z + m[12];\n const cy = m[1] * x + m[5] * y + m[9] * z + m[13];\n const cw = m[3] * x + m[7] * y + m[11] * z + m[15];\n return cw > -radius && Math.abs(cx) <= cw + radius * padX && Math.abs(cy) <= cw + radius * padY;\n}\n\nconst HORIZON_FIXED_STEPS = [0.2, 0.42, 0.64, 0.82] as const;\n\n/**\n * Plain-number twin of the 6-tap heightfield ray occlusion check in compute:\n * discards mid/far plants whose tips sit below a terrain ridge between the plant and the camera.\n */\nexport function isHorizonOccluded(\n heightAt: (x: number, z: number) => number,\n x: number,\n gy: number,\n z: number,\n tall0: number,\n camX: number,\n camY: number,\n camZ: number,\n heightSpread = 0.4,\n): boolean {\n const dist2d = Math.hypot(x - camX, z - camZ);\n if (dist2d <= 4) return false;\n const tipY = gy + tall0 * (1 + heightSpread * 0.5) * 1.22 + 0.02;\n const tNear1 = Math.min(0.96, Math.max(0.15, 1 - 2.8 / dist2d));\n const tNear2 = Math.min(0.92, Math.max(0.15, 1 - 6.0 / dist2d));\n for (const t of [...HORIZON_FIXED_STEPS, tNear2, tNear1]) {\n const px = x + (camX - x) * t;\n const pz = z + (camZ - z) * t;\n const rayY = tipY + (camY - tipY) * t;\n if (heightAt(px, pz) - 0.02 >= rayY) return true;\n }\n return false;\n}\n\nconst SQRT3 = Math.sqrt(3);\nconst F2 = (SQRT3 - 1) / 2;\nconst G2 = (3 - SQRT3) / 6;\n\n/**\n * Plain-number twin of the simplex triangle-grid barycentric lookup & power-4 sharpened\n * weights used for variance-preserving 3-tap hex-tiling (Heitz & Neyret).\n */\nexport function hexTileWeights(u: number, v: number): {\n v1: [number, number];\n v2: [number, number];\n v3: [number, number];\n w: [number, number, number];\n normW: number;\n} {\n // Skewed simplex coordinates\n const s = (u + v) * F2;\n const i = Math.floor(u + s);\n const j = Math.floor(v + s);\n const t = (i + j) * G2;\n const x0 = u - (i - t);\n const y0 = v - (j - t);\n const i1 = x0 > y0 ? 1 : 0;\n const j1 = x0 > y0 ? 0 : 1;\n const x1 = x0 - i1 + G2;\n const y1 = y0 - j1 + G2;\n const x2 = x0 - 1 + 2 * G2;\n const y2 = y0 - 1 + 2 * G2;\n\n // Barycentric weights within the simplex triangle (using symmetric falloff from vertices)\n // Note: standard simplex triangle weights for hex-tiling:\n // In the equilateral triangle formed by skewing (1,0), (0,1), (1,1) by inverse skew,\n // or directly from affine coordinates in the skewed grid:\n // Let's use exact affine barycentric coordinates in the skewed grid!\n // In skewed space: p = (u+s, v+s) = (i, j) + (fx, fy) where fx = u+s-i, fy = v+s-j in [0,1)^2.\n // If fx >= fy: triangle is (0,0), (1,0), (1,1) -> b1 = 1 - fx, b2 = fx - fy, b3 = fy!\n // If fx < fy: triangle is (0,0), (0,1), (1,1) -> b1 = 1 - fy, b2 = fy - fx, b3 = fx!\n const fx = u + s - i;\n const fy = v + s - j;\n const b1 = fx >= fy ? 1 - fx : 1 - fy;\n const b2 = Math.abs(fx - fy);\n const b3 = fx >= fy ? fy : fx;\n\n // Power-4 sharpening normalized to sum to 1 (continuous C1/C2 across edges, zero at opposite edge)\n const p1 = Math.pow(Math.max(0, b1), 4);\n const p2 = Math.pow(Math.max(0, b2), 4);\n const p3 = Math.pow(Math.max(0, b3), 4);\n const pSum = Math.max(p1 + p2 + p3, 1e-6);\n const w1 = p1 / pSum;\n const w2 = p2 / pSum;\n const w3 = p3 / pSum;\n const normW = Math.max(Math.hypot(w1, w2, w3), 0.57735);\n void x1; void y1; void x2; void y2;\n return {\n v1: [i, j],\n v2: [i + i1, j + j1],\n v3: [i + 1, j + 1],\n w: [w1, w2, w3],\n normW,\n };\n}\n"]}
|
package/lib/engine.d.ts
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import * as THREE from "three/webgpu";
|
|
2
|
+
import { type GrassDistance } from "./distance.js";
|
|
3
|
+
import { type GrassTransitions } from "./transitions.js";
|
|
4
|
+
import { type HeightSource, type MapSource, type MowSource } from "./field.js";
|
|
5
|
+
import { type Flower } from "./flowers.js";
|
|
6
|
+
import { type Species } from "./species.js";
|
|
7
|
+
type Vec2 = THREE.Node<"vec2">;
|
|
8
|
+
type Vec3 = THREE.Node<"vec3">;
|
|
9
|
+
/**
|
|
10
|
+
* How dark a stand is as a whole beside its leaves' own colour, 0..1: its roots are in its own shade, and
|
|
11
|
+
* what is seen of it from any way off is root to tip together. For a host that says what colour a stand
|
|
12
|
+
* of grass is to be, rather than its leaves: give the species that colour over this. (`sunUp`: the sun's
|
|
13
|
+
* height, as the sine of its angle; `depth`: `look.depth`. The same sum the shaders do.)
|
|
14
|
+
*/
|
|
15
|
+
export declare function standTone(species: Pick<Species, "height" | "density" | "rootShade">, sunUp?: number, depth?: number): number;
|
|
16
|
+
/** Default edge height ramp, leaf broadening, altitude thinning, and tuft width/melt live in `src/transitions.ts`. */
|
|
17
|
+
/** How many points a trail through the grass has at most (see `Grass.setTrail`). */
|
|
18
|
+
export declare const MAX_TRAIL = 24;
|
|
19
|
+
/** How many things can lie in the grass at once (see `Grass.setThings`). */
|
|
20
|
+
export declare const MAX_THINGS = 4;
|
|
21
|
+
/** Something lying in the grass: a sphere. */
|
|
22
|
+
export interface GrassThing {
|
|
23
|
+
/** Its centre (m, the world's). */
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
z: number;
|
|
27
|
+
radius: number;
|
|
28
|
+
/** The grass is gone within this far (m) of its centre, growing back to full height a little beyond: a nest it has pressed. 0: none. */
|
|
29
|
+
clear?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Keep it in sight: the leaves standing between the eye and it are kept under a line from the eye to
|
|
32
|
+
* it, so that this share of its height shows from the top down (`true`: half, the line to its middle),
|
|
33
|
+
* and how deep it sits can be read off. Grass taller than a ball hides the ball altogether otherwise.
|
|
34
|
+
* To show a lie as it is, give the share of it that stands above the grass, or a little more.
|
|
35
|
+
*/
|
|
36
|
+
keepSeen?: boolean | number;
|
|
37
|
+
/**
|
|
38
|
+
* Not a sphere but a place on the ground something stands on, `radius` across (a foot): the grass
|
|
39
|
+
* there is pressed down to a third of its height, coming back up over half as far again. `y`,
|
|
40
|
+
* `clear` and `keepSeen` mean nothing for it.
|
|
41
|
+
*/
|
|
42
|
+
flat?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Where the middle of a ball goes (m above its ground) for `showing` of its height, 0..1, to stand above
|
|
46
|
+
* grass `grassTall` high: a ball in rough is held up by the grass, and its lie is how much of it shows.
|
|
47
|
+
* Never lower than resting on the ground. (The top of a stand is its plants' mean height, a little
|
|
48
|
+
* under the species' own: no two plants are the same height, so at any one place it is this give or take.)
|
|
49
|
+
*/
|
|
50
|
+
export declare function thingMiddleFor(grassTall: number, radius: number, showing: number): number;
|
|
51
|
+
/** One square of plants. */
|
|
52
|
+
export interface GrassLayer {
|
|
53
|
+
/** Plants along a side, and their spacing (m). */
|
|
54
|
+
count: number;
|
|
55
|
+
spacing: number;
|
|
56
|
+
/** Leaves to a plant. */
|
|
57
|
+
blades: number;
|
|
58
|
+
/** How far it is drawn (m): a tuft layer from the eye, a fine layer from its own centre. */
|
|
59
|
+
range: number;
|
|
60
|
+
}
|
|
61
|
+
/** A finer square of fine leaves still, drawn only while the eye is close enough over the ground that its leaves can be seen (by its reach). */
|
|
62
|
+
export interface NearLayer extends GrassLayer {
|
|
63
|
+
/** Not read: the square is drawn by its reach, as the others are. Kept so a host that gives it still compiles. */
|
|
64
|
+
within: number;
|
|
65
|
+
/** Only stands shorter than this (m) grow in it: a square fine enough for a green's shoots is far more leaves than rough has. */
|
|
66
|
+
below?: number;
|
|
67
|
+
}
|
|
68
|
+
export interface GrassLayers {
|
|
69
|
+
far: GrassLayer;
|
|
70
|
+
peak: GrassLayer;
|
|
71
|
+
mid: GrassLayer;
|
|
72
|
+
/**
|
|
73
|
+
* A coarser square of fine leaves beyond `mid`, drawn only when leaves can be seen that far: when the
|
|
74
|
+
* broadest species' leaf is still half a pixel wide in the picture beyond `mid`'s reach (a large
|
|
75
|
+
* display, a long lens, a broad-leaved grass). Left out, the leaves end with `mid`.
|
|
76
|
+
*/
|
|
77
|
+
wide?: GrassLayer;
|
|
78
|
+
/** Finer squares for an eye close to the ground, finest first. */
|
|
79
|
+
near: NearLayer[];
|
|
80
|
+
/** How far ahead of the eye the far tufts' square is centred (m). */
|
|
81
|
+
farAhead: number;
|
|
82
|
+
/** Not read: the fine squares are centred by their own reach. Kept so a host that gives them still compiles. */
|
|
83
|
+
peakAhead: number;
|
|
84
|
+
/** Not read, as `peakAhead`. */
|
|
85
|
+
midAhead: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The squares as the game draws them. Far: 62,500 tufts of eight blades,
|
|
89
|
+
* 22 cm apart, to 48 m. Peak and mid: 110,000 plants of three leaves each,
|
|
90
|
+
* 2 cm and 3.9 cm apart: 7,200 and 2,000 leaves to the square metre at
|
|
91
|
+
* their centres.
|
|
92
|
+
*
|
|
93
|
+
* Near (not the game's): the same number of plants 5 mm and 1 cm apart,
|
|
94
|
+
* 120,000 and 29,000 leaves to the square metre, which is what a mown sward
|
|
95
|
+
* has. From standing height that is far more than can be seen, so each is
|
|
96
|
+
* drawn only while the eye is within a stride or two of it. Their plants
|
|
97
|
+
* carry up to six leaves, for a species whose density is set above 1.
|
|
98
|
+
* And a third, 2.2 mm apart, for close-mown turf seen from where a ball lies:
|
|
99
|
+
* a green has some twenty shoots to the square centimetre.
|
|
100
|
+
*/
|
|
101
|
+
export declare const DEFAULT_LAYERS: GrassLayers;
|
|
102
|
+
/** How many pictures the leaves can have between them, and the size each is kept at (across the leaf, up it). */
|
|
103
|
+
export declare const MAX_LEAF_TEXTURES = 16;
|
|
104
|
+
/** What a specimen shows: one leaf, one plant of fine leaves, one tuft as the far field draws it, or a clump of plants. */
|
|
105
|
+
export type SpecimenKind = "blade" | "plant" | "tuft" | "clump";
|
|
106
|
+
/**
|
|
107
|
+
* A little grass on its own, drawn by the field's own leaf shader: for
|
|
108
|
+
* looking at a species closely, and for pictures of one. It reads the
|
|
109
|
+
* species as they are now each time it is updated.
|
|
110
|
+
*/
|
|
111
|
+
export interface Specimen {
|
|
112
|
+
object: THREE.Group;
|
|
113
|
+
/** What to show, of which species (its row); `seed` picks another plant of the same kind. */
|
|
114
|
+
set(kind: SpecimenKind, row: number, seed?: number): void;
|
|
115
|
+
/** Once a frame. */
|
|
116
|
+
update(timeS: number): void;
|
|
117
|
+
/** How big it is (m), for framing it: its radius on the ground and its height. */
|
|
118
|
+
readonly radius: number;
|
|
119
|
+
readonly height: number;
|
|
120
|
+
dispose(): void;
|
|
121
|
+
}
|
|
122
|
+
export interface GrassOptions {
|
|
123
|
+
height: HeightSource;
|
|
124
|
+
/** How the field was mown, for the species the mower lays over (`Species.lay`). Without it nothing is laid. */
|
|
125
|
+
mow?: MowSource;
|
|
126
|
+
map: MapSource;
|
|
127
|
+
species: readonly Species[];
|
|
128
|
+
layers?: GrassLayers;
|
|
129
|
+
/**
|
|
130
|
+
* The light at a place, from what the host has standing over the grass and the grass knows nothing
|
|
131
|
+
* of: clouds, trees, buildings, rain. Each is a function of a place (x, z) the shaders call, in the
|
|
132
|
+
* compute pass and in fragment shaders both, so a texture in one is looked up at a set level.
|
|
133
|
+
*/
|
|
134
|
+
world?: WorldLight;
|
|
135
|
+
/** Flowers of the host's own, by the names its species' `blooms` give them: added to `FLOWERS`, or in place of one of the same name. */
|
|
136
|
+
flowers?: Readonly<Record<string, Flower>>;
|
|
137
|
+
/**
|
|
138
|
+
* The host's own noise in place of the grass's: a tiling picture of four unlike noises, one to a
|
|
139
|
+
* channel, that repeats and has mipmaps. A host whose ground asks the grass for its shading
|
|
140
|
+
* (`groundShade`) and has such a picture already gives it here, so the ground's shader looks up one
|
|
141
|
+
* picture and not two: a shader stage has sixteen on any machine.
|
|
142
|
+
*/
|
|
143
|
+
noise?: THREE.Texture;
|
|
144
|
+
/** Which distance grass techniques are active (all on by default; `false` disables all). */
|
|
145
|
+
distance?: boolean | Partial<GrassDistance>;
|
|
146
|
+
/** Fine-tunable borders, falloff curves, sub-pixel thresholds, and handoff matching. */
|
|
147
|
+
transitions?: Partial<GrassTransitions>;
|
|
148
|
+
}
|
|
149
|
+
/** What the grass already knows of a place when it asks the host for its light there: the ground's height and normal, and the species growing there (its row, or `NO_GRASS`). */
|
|
150
|
+
export interface PlaceKnown {
|
|
151
|
+
height: THREE.Node<"float">;
|
|
152
|
+
normal: Vec3;
|
|
153
|
+
species: THREE.Node<"float">;
|
|
154
|
+
}
|
|
155
|
+
/** See `GrassOptions.world`. Any of them may be left out. */
|
|
156
|
+
export interface WorldLight {
|
|
157
|
+
/** How much of the sun reaches the place, 0..1: a cloud's shadow, a tree's. The sky still lights it. */
|
|
158
|
+
sun?(xz: Vec2): THREE.Node<"float">;
|
|
159
|
+
/** How much of the sky the place sees, 0..1: under a tree's crown, in a hollow, against a wall. */
|
|
160
|
+
sky?(xz: Vec2): THREE.Node<"float">;
|
|
161
|
+
/**
|
|
162
|
+
* How much of the day's light a place goes without, 0 (open) to 1 (under a closed crown): for what
|
|
163
|
+
* grows there, not for how it is lit now, so it does not move with the sun or sway with the leaves.
|
|
164
|
+
* The flowers of open grassland take little of it (`Flower.colony`). Not given: open everywhere.
|
|
165
|
+
*/
|
|
166
|
+
shelter?(xz: Vec2): THREE.Node<"float">;
|
|
167
|
+
/**
|
|
168
|
+
* What the grass's colour is multiplied by there: wet grass is darker, grass under leaves is lit green.
|
|
169
|
+
* `at`, when given, is what the grass already knows of the place (`PlaceKnown`), for a host that would
|
|
170
|
+
* otherwise look it up again.
|
|
171
|
+
*/
|
|
172
|
+
tint?(xz: Vec2, at?: PlaceKnown): Vec3;
|
|
173
|
+
/**
|
|
174
|
+
* What the colour of something in the grass that is not grass (a flower) is multiplied by there: the
|
|
175
|
+
* light's part of `tint` (the shade, the wet), without what a host puts in `tint` to make the grass the
|
|
176
|
+
* colour of its ground. Not given, flowers take `tint`.
|
|
177
|
+
*/
|
|
178
|
+
light?(xz: Vec2, at?: PlaceKnown): Vec3;
|
|
179
|
+
/**
|
|
180
|
+
* The air between a leaf and the eye: given the leaf's colour and where it is, the colour that reaches
|
|
181
|
+
* the eye. A host with haze of its own (the scene's fog is applied without this). Called for each
|
|
182
|
+
* corner of a leaf, in a vertex shader.
|
|
183
|
+
*/
|
|
184
|
+
air?(colour: Vec3, at: Vec3): Vec3;
|
|
185
|
+
}
|
|
186
|
+
export interface Grass {
|
|
187
|
+
/** Add this to the scene. */
|
|
188
|
+
object: THREE.Group;
|
|
189
|
+
/**
|
|
190
|
+
* The light and the air, for the host to set. `sun` points at the sun.
|
|
191
|
+
* A leaf is lit as the ground under it would be: `sunTint` where the
|
|
192
|
+
* ground faces the sun, `shadeTint` where it turns away. `wind` is its
|
|
193
|
+
* heading (x, y: unit, in the ground plane's x and z) and its speed in
|
|
194
|
+
* metres a second (z).
|
|
195
|
+
*/
|
|
196
|
+
environment: {
|
|
197
|
+
sun: THREE.Vector3;
|
|
198
|
+
sunTint: THREE.Vector3;
|
|
199
|
+
shadeTint: THREE.Vector3;
|
|
200
|
+
wind: THREE.Vector3;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* How it is drawn, apart from what it is. `broad`, 0..1: fewer and
|
|
204
|
+
* broader leaves. `flat`, 0..1: less of what tells one leaf from the
|
|
205
|
+
* next (tone, the shaded root, sheen, the fold).
|
|
206
|
+
*/
|
|
207
|
+
style: {
|
|
208
|
+
broad: number;
|
|
209
|
+
flat: number;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* The field as a whole. `clumpSize`: metres between clump centres.
|
|
213
|
+
* `macro`: how much the colour drifts over tens of metres. `edgeWobble`:
|
|
214
|
+
* how far (m) a border strays from the map's cells. `leafShadows`: whether the leaves about the eye shadow each other and the ground (they are
|
|
215
|
+
* drawn once more each frame, from the sun: it costs about as much again as drawing them).
|
|
216
|
+
* `amount`: how much of the grass is drawn, 0.05 to 1 (the plants left are broader for the ones
|
|
217
|
+
* left out, so the field keeps its cover: a host's own setting for a slower machine).
|
|
218
|
+
* `brightest`: no leaf is drawn brighter than this (a host that blooms what is bright sets it
|
|
219
|
+
* under its threshold, or a back-lit leaf is a lamp).
|
|
220
|
+
* `blooms`: whether the species' flowers are drawn (`Species.blooms`).
|
|
221
|
+
* `strains`: how unlike its strains a mown stand shows itself (`Species.mosaic`), 0..1: most in early
|
|
222
|
+
* spring and late autumn, when the strains wake and sleep at their own times, hardly at all in summer.
|
|
223
|
+
* `drought`: how dry the ground has been, 0..1: the mown grass browns in spots (`Species.scorch`).
|
|
224
|
+
* `wet`: how wet the leaves are, 0 (dry) to 1 (dew, or rain): what a trail through them leaves
|
|
225
|
+
* (`setTrail`). The colour of wet grass is the host's to give (`world.tint`).
|
|
226
|
+
* `site`: how far the grass's colour follows the lie of the ground, lusher in the hollows
|
|
227
|
+
* and paler on the crowns (it needs the map's `bounds`; patches follow it by each species' `patchSite`).
|
|
228
|
+
* `mown`: whether the field is mown in stripes at all (`GrassOptions.mow` says how): off, no
|
|
229
|
+
* leaf is laid over and there are no stripes. `depth`: how far a stand's
|
|
230
|
+
* roots are as dark as the light's fall through its leaves makes them (by its height, its
|
|
231
|
+
* density and the sun's height), over the species' own `rootShade` alone (0).
|
|
232
|
+
* `fold`: how far a near leaf is folded
|
|
233
|
+
* along its rib, in its geometry (1: a shallow V; 0: flat). `relief`: how deep the ground's
|
|
234
|
+
* picture is: how far what stands high in it moves over what lies low as the eye moves, and
|
|
235
|
+
* how its slopes are lit by the sun (1: as deep as the pile was laid; 0: a flat picture). `leafPixels`: how wide in the
|
|
236
|
+
* picture a leaf must be to be drawn (1: most of a pixel; 0: always).
|
|
237
|
+
* `shadow`: how dark
|
|
238
|
+
* the shade of taller grass is, 0..1. `occlusion`: how much grass beside
|
|
239
|
+
* taller grass loses of the sky's light, 0..1. `stripes`: how much
|
|
240
|
+
* lighter laid grass is seen along its lay, and darker against it, 0..1.
|
|
241
|
+
* `groundShade`: the
|
|
242
|
+
* ground's colour under a stand, as a share of the colour of the stand's
|
|
243
|
+
* roots. `bare`: the
|
|
244
|
+
* ground's colour where nothing grows. `wild`: how strongly the wild meso-scale turf (tussock clumps, thatch
|
|
245
|
+
* drifts and hummock relief from about 8 m out, on species that are not mown) is laid over the ground, 0..1:
|
|
246
|
+
* 1 as drawn, 0 none, for a host whose ground already carries its own drift of colour.
|
|
247
|
+
*/
|
|
248
|
+
look: {
|
|
249
|
+
clumpSize: number;
|
|
250
|
+
macro: number;
|
|
251
|
+
edgeWobble: number;
|
|
252
|
+
groundShade: number;
|
|
253
|
+
stripes: number;
|
|
254
|
+
shadow: number;
|
|
255
|
+
occlusion: number;
|
|
256
|
+
fold: number;
|
|
257
|
+
relief: number;
|
|
258
|
+
leafPixels: number;
|
|
259
|
+
depth: number;
|
|
260
|
+
mown: boolean;
|
|
261
|
+
site: number;
|
|
262
|
+
leafShadows: boolean;
|
|
263
|
+
brightest: number;
|
|
264
|
+
wet: number;
|
|
265
|
+
blooms: boolean;
|
|
266
|
+
amount: number;
|
|
267
|
+
strains: number;
|
|
268
|
+
drought: number;
|
|
269
|
+
wild: number;
|
|
270
|
+
bare: THREE.Color;
|
|
271
|
+
};
|
|
272
|
+
/** Read the species again after changing them (or give another list). */
|
|
273
|
+
setSpecies(list: readonly Species[]): void;
|
|
274
|
+
/**
|
|
275
|
+
* Say that the map (`GrassOptions.map`) has changed what grows where: the grass's picture of how tall it
|
|
276
|
+
* stands, which its shadows and the lie of the ground are found from, is drawn again on the next frame. (It is
|
|
277
|
+
* drawn again now and then in any case, for a host that does not say.)
|
|
278
|
+
*/
|
|
279
|
+
mapChanged(): void;
|
|
280
|
+
/**
|
|
281
|
+
* What lies in the grass (a ball, a stone): at most `MAX_THINGS` spheres. No leaf goes through one:
|
|
282
|
+
* the grass under it is pressed down beneath it, a leaf that would cross it is carried round it, and
|
|
283
|
+
* the leaves about it are held still. Give them again whenever one moves; none, to clear them.
|
|
284
|
+
*/
|
|
285
|
+
setThings(list: readonly GrassThing[]): void;
|
|
286
|
+
/**
|
|
287
|
+
* Where something has gone through the grass, in the order it went: at most `MAX_TRAIL` points, each a
|
|
288
|
+
* place, how broad the thing was there (m) and when it was there (s, on `update`'s clock). The grass is
|
|
289
|
+
* laid over along the track between each point and the next as the thing passes, and is back up in
|
|
290
|
+
* about a second: dry grass keeps no track. Wet grass (`look.wet`) is slower up, and its leaves along
|
|
291
|
+
* the track are a little darker for some minutes, the wet wiped off them. (A faint line, and on the
|
|
292
|
+
* leaves only: a dew track as it is seen on a green, dark through pale, wants the dew drawn and the
|
|
293
|
+
* ground under the leaves to carry the line, and neither is done.) The grass remembers the track after
|
|
294
|
+
* its points are gone, within 15 m or so of the eye. None, to clear it (what it left stays, and fades).
|
|
295
|
+
*/
|
|
296
|
+
setTrail(points: readonly {
|
|
297
|
+
x: number;
|
|
298
|
+
z: number;
|
|
299
|
+
radius: number;
|
|
300
|
+
at: number;
|
|
301
|
+
}[]): void;
|
|
302
|
+
/** A stir of the air at a place: the grass within a stride of it is pushed out from it and along (`dx`, `dz`: which way, and how hard, 1 being a club's swing). None, for still. */
|
|
303
|
+
setStir(stir: {
|
|
304
|
+
x: number;
|
|
305
|
+
z: number;
|
|
306
|
+
dx: number;
|
|
307
|
+
dz: number;
|
|
308
|
+
} | null): void;
|
|
309
|
+
/**
|
|
310
|
+
* The pictures the species' leaves can have, by the names the species use
|
|
311
|
+
* (`Species.leafTexture`): at most `MAX_LEAF_TEXTURES`. Each is kept at 64
|
|
312
|
+
* by 256, the leaf's root at its bottom edge.
|
|
313
|
+
*/
|
|
314
|
+
setLeafTextures(pictures: Record<string, CanvasImageSource>): void;
|
|
315
|
+
/** A specimen standing at a place. Add its `object` to the scene. */
|
|
316
|
+
/**
|
|
317
|
+
* How many plants the last frame drew, of `stats.plants` computed: read back from the graphics card, so not
|
|
318
|
+
* every frame. It sets `stats.flowersDrawn` too.
|
|
319
|
+
*/
|
|
320
|
+
countDrawn(renderer: THREE.WebGPURenderer): Promise<number>;
|
|
321
|
+
createSpecimen(at: {
|
|
322
|
+
x: number;
|
|
323
|
+
y: number;
|
|
324
|
+
z: number;
|
|
325
|
+
}): Specimen;
|
|
326
|
+
/**
|
|
327
|
+
* The ground under a species (its row): a picture of what lies on it,
|
|
328
|
+
* seen from straight above, tiled over the species' ground (`Species.groundTile`).
|
|
329
|
+
* Only its light and dark are used, against its own mean; the colour
|
|
330
|
+
* stays the species'. `null` takes it away.
|
|
331
|
+
*/
|
|
332
|
+
setGroundPicture(row: number, picture: CanvasImageSource | null): void;
|
|
333
|
+
/**
|
|
334
|
+
* Make a species' ground picture from the species itself: its leaves,
|
|
335
|
+
* with its colours and its leaf picture, laid over as a mown or trodden
|
|
336
|
+
* sward's are and drawn from straight above. Do it again when the
|
|
337
|
+
* species changes.
|
|
338
|
+
*/
|
|
339
|
+
bakeGround(renderer: THREE.WebGPURenderer, row: number): Promise<void>;
|
|
340
|
+
/**
|
|
341
|
+
* (With `lookAt.focus`, the leaves are thickest about that place and not about the eye: a picture
|
|
342
|
+
* of something on the ground some way off, a ball at a golfer's feet seen from behind, has its grass
|
|
343
|
+
* where the thing is. They thin out from there as they otherwise do from the eye.)
|
|
344
|
+
* Once a frame, before rendering. The fine leaves are centred a few
|
|
345
|
+
* metres ahead of the eye, by each square's reach. `lookAt.y` is the
|
|
346
|
+
* ground's height where the picture looks, if the host knows it: the
|
|
347
|
+
* finest squares are drawn only while the eye is close enough over it.
|
|
348
|
+
* `lookAt.x` and `z` are used only with `focus` (above), when they are
|
|
349
|
+
* where the leaves are centred. `pictureHeight`: the height in pixels of
|
|
350
|
+
* the picture the grass is about to be drawn into, when that is not the
|
|
351
|
+
* canvas (a small inset): how wide a leaf is in pixels goes by it.
|
|
352
|
+
*/
|
|
353
|
+
update(renderer: THREE.WebGPURenderer, camera: THREE.Camera, timeS: number, lookAt?: {
|
|
354
|
+
x: number;
|
|
355
|
+
y?: number;
|
|
356
|
+
z: number;
|
|
357
|
+
focus?: boolean;
|
|
358
|
+
}, pictureHeight?: number): void;
|
|
359
|
+
/** Which of it is drawn: the far tufts, the fine leaves. */
|
|
360
|
+
show: {
|
|
361
|
+
tufts: boolean;
|
|
362
|
+
leaves: boolean;
|
|
363
|
+
};
|
|
364
|
+
/** Distance rendering switches, toggleable at any time. */
|
|
365
|
+
distance: GrassDistance;
|
|
366
|
+
/** Transition borders, curves, and fine-to-tuft matching parameters, tunable at runtime. */
|
|
367
|
+
transitions: GrassTransitions;
|
|
368
|
+
/**
|
|
369
|
+
* For the host's ground material: the colour the grass standing at a
|
|
370
|
+
* place takes (before light), so ground and grass are one colour and
|
|
371
|
+
* where the leaves thin out there is nothing to see.
|
|
372
|
+
*/
|
|
373
|
+
groundColor(xz: Vec2): Vec3;
|
|
374
|
+
/**
|
|
375
|
+
* For a host whose ground has its own colour: what the grass standing at a place does to it, as
|
|
376
|
+
* what to multiply that colour by. The host's colour is taken to be the stand's as a whole (so the
|
|
377
|
+
* species' leaf colour is that colour over `standTone`): far off this is 1. Dark where the eye sees down between the leaves and the stand's
|
|
378
|
+
* own mean where it stands in for leaves too far off to draw, the stand's picture and its relief,
|
|
379
|
+
* its patches, the mower's stripes, the gusts, the grass's own shade. None of the world's light
|
|
380
|
+
* (`GrassOptions.world`), which is the host's to put on its ground itself. In a fragment shader.
|
|
381
|
+
*/
|
|
382
|
+
groundShade(xz: Vec2): Vec3;
|
|
383
|
+
/** The light a leaf takes on ground with this normal, for the same reason. */
|
|
384
|
+
light(normal: Vec3): Vec3;
|
|
385
|
+
/**
|
|
386
|
+
* The plants there are in all, the most leaves they can stand up as, and `computed`: how many plants
|
|
387
|
+
* the last frame worked out (the squares whose leaves could be in the picture; the rest were left alone).
|
|
388
|
+
* `flowers`: the places there are for a flower, near and far; `flowersDrawn`: how many flowers stood on them
|
|
389
|
+
* and were drawn, as `countDrawn` last found (none while flowers are not drawn).
|
|
390
|
+
*/
|
|
391
|
+
stats: {
|
|
392
|
+
plants: number;
|
|
393
|
+
leaves: number;
|
|
394
|
+
computed: number;
|
|
395
|
+
flowers: number;
|
|
396
|
+
flowersDrawn: number;
|
|
397
|
+
};
|
|
398
|
+
dispose(): void;
|
|
399
|
+
}
|
|
400
|
+
export declare function createGrass(options: GrassOptions): Grass;
|
|
401
|
+
export {};
|
|
402
|
+
//# sourceMappingURL=engine.d.ts.map
|