@margoengine/terrain 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +2366 -2
  4. package/dist/bed-mesh.d.ts +40 -0
  5. package/dist/bed-mesh.js +95 -0
  6. package/dist/blend.d.ts +70 -0
  7. package/dist/blend.js +159 -0
  8. package/dist/colors.d.ts +170 -0
  9. package/dist/deform.d.ts +134 -0
  10. package/dist/deform.js +404 -0
  11. package/dist/displace.d.ts +60 -0
  12. package/dist/displace.js +254 -0
  13. package/dist/dunes.d.ts +86 -0
  14. package/dist/dunes.js +88 -0
  15. package/dist/elevation.d.ts +182 -0
  16. package/dist/elevation.js +155 -0
  17. package/dist/errors-fc4i1pSL.js +7 -0
  18. package/dist/far.d.ts +66 -0
  19. package/dist/far.js +191 -0
  20. package/dist/furrows.d.ts +74 -0
  21. package/dist/furrows.js +157 -0
  22. package/dist/grid.d.ts +14 -0
  23. package/dist/ground-change-settings.d.ts +29 -0
  24. package/dist/ground-change-settings.js +69 -0
  25. package/dist/ground-change.d.ts +227 -0
  26. package/dist/ground-change.js +1412 -0
  27. package/dist/ground-contact-settings.d.ts +27 -0
  28. package/dist/ground-contact-settings.js +22 -0
  29. package/dist/ground-contact.d.ts +91 -0
  30. package/dist/ground-contact.js +241 -0
  31. package/dist/ground-model.d.ts +372 -0
  32. package/dist/hdr-format-DRhzGS7G.js +30 -0
  33. package/dist/height-grid.d.ts +65 -0
  34. package/dist/height-grid.js +74 -0
  35. package/dist/heightfield.d.ts +38 -0
  36. package/dist/holes.d.ts +37 -0
  37. package/dist/holes.js +97 -0
  38. package/dist/imagery.d.ts +109 -0
  39. package/dist/imagery.js +472 -0
  40. package/dist/index.d.ts +408 -0
  41. package/dist/index.js +1 -0
  42. package/dist/layers-pbr.d.ts +78 -0
  43. package/dist/layers-pbr.js +128 -0
  44. package/dist/lighting-layout-CaDtDa5G.js +34 -0
  45. package/dist/lighting-layout.d.ts +5 -0
  46. package/dist/mesh-patch-BThCHCeS.js +21 -0
  47. package/dist/mesh-patch.d.ts +14 -0
  48. package/dist/noise3-sQdnbz4B.js +11 -0
  49. package/dist/noise3.d.ts +3 -0
  50. package/dist/overlays.d.ts +74 -0
  51. package/dist/overlays.js +297 -0
  52. package/dist/planet-complex.d.ts +31 -0
  53. package/dist/planet-craters.d.ts +80 -0
  54. package/dist/planet-rays.d.ts +37 -0
  55. package/dist/planet-recipes.d.ts +84 -0
  56. package/dist/planet-recipes.js +442 -0
  57. package/dist/planet.d.ts +144 -0
  58. package/dist/planet.js +610 -0
  59. package/dist/query.d.ts +150 -0
  60. package/dist/query.js +243 -0
  61. package/dist/relief-lighting.d.ts +53 -0
  62. package/dist/relief-lighting.js +221 -0
  63. package/dist/require-webgpu--tUXPsmA.js +7 -0
  64. package/dist/rock-settings.d.ts +39 -0
  65. package/dist/rock-settings.js +84 -0
  66. package/dist/rock-surface.d.ts +114 -0
  67. package/dist/rock-surface.js +380 -0
  68. package/dist/rocks.d.ts +258 -0
  69. package/dist/rocks.js +488 -0
  70. package/dist/rvt.d.ts +136 -0
  71. package/dist/rvt.js +518 -0
  72. package/dist/scour.d.ts +90 -0
  73. package/dist/scour.js +153 -0
  74. package/dist/sculpt.d.ts +103 -0
  75. package/dist/sculpt.js +361 -0
  76. package/dist/settings-B9BSdnhD.js +72 -0
  77. package/dist/settings.d.ts +81 -0
  78. package/dist/settings.js +152 -0
  79. package/dist/shader.d.ts +176 -0
  80. package/dist/shared/settings.d.ts +89 -0
  81. package/dist/src-Cr7Gm4n0.js +1366 -0
  82. package/dist/stream-window.d.ts +123 -0
  83. package/dist/stream.d.ts +169 -0
  84. package/dist/stream.js +531 -0
  85. package/dist/surface-height.d.ts +16 -0
  86. package/dist/wet-ground.d.ts +82 -0
  87. package/dist/wet-ground.js +147 -0
  88. package/package.json +173 -4
@@ -0,0 +1,27 @@
1
+ import { type SettingRow } from './shared/settings.js';
2
+ import type { TerrainGroundContact } from './ground-contact.js';
3
+ /** A colour value: linear RGB. */
4
+ export type GroundContactSettingColor = readonly [number, number, number];
5
+ /** One value of a setting: a number or a colour. */
6
+ export type GroundContactSettingValue = number | GroundContactSettingColor;
7
+ /** Values by setting name; a name left out keeps the effect's current value. */
8
+ export type GroundContactSettingValues = Readonly<Record<string, GroundContactSettingValue>>;
9
+ /** The panel a setting sits in. */
10
+ export type GroundContactSettingGroup = 'contact';
11
+ /** One control: the shared row shape with the ground contact's group. */
12
+ export interface GroundContactSetting extends SettingRow {
13
+ readonly group: GroundContactSettingGroup;
14
+ readonly default: GroundContactSettingValue;
15
+ }
16
+ /** Every ground contact look control, in panel order. Defaults are the values the effect uses without the option. */
17
+ export declare const GROUND_CONTACT_SETTINGS: readonly GroundContactSetting[];
18
+ /** The rows that can change every frame (all of them). */
19
+ export declare const GROUND_CONTACT_LIVE_SETTINGS: readonly GroundContactSetting[];
20
+ /** Every setting at its default, as a fresh object to edit (a slider panel's state). */
21
+ export declare function groundContactSettingDefaults(): Record<string, GroundContactSettingValue>;
22
+ /**
23
+ * Sets the given rows on `contact` (names left out keep their current value). Nothing is rebuilt.
24
+ * @throws TypeError for an unknown name; RangeError for a value out of range.
25
+ * @example applyGroundContactSettings(view.groundContact, { 'contact.soil': 0.6 });
26
+ */
27
+ export declare function applyGroundContactSettings(contact: TerrainGroundContact, values?: GroundContactSettingValues): void;
@@ -0,0 +1,22 @@
1
+ import { a as e, c as t, l as n, n as r, o as i, t as a } from "./settings-B9BSdnhD.js";
2
+ //#region src/ground-contact-settings.ts
3
+ var o = (e, t) => i(e, "contact", 1, 0, 1, .01, "", t), s = [
4
+ r("contact.color", "contact", [
5
+ .1,
6
+ .08,
7
+ .055
8
+ ], 0, 1, "Linear RGB albedo of the soil and litter at the feet of trunks and stones."),
9
+ o("contact.soil", "How far the ground turns to the soil colour where the soil weight is full (0 leaves it)."),
10
+ o("contact.occlusion", "How much of the sky light lost at a foot is taken (0 takes none).")
11
+ ], c = e(s), l = n(s);
12
+ function u() {
13
+ return t(s);
14
+ }
15
+ function d(e, t = {}) {
16
+ a(l, t, "ground contact", "the rows in @margoengine/terrain/ground-contact-settings");
17
+ let n = {};
18
+ for (let [e, r] of Object.entries(t)) n[e.slice(8)] = r;
19
+ e.setLook(n);
20
+ }
21
+ //#endregion
22
+ export { c as GROUND_CONTACT_LIVE_SETTINGS, s as GROUND_CONTACT_SETTINGS, d as applyGroundContactSettings, u as groundContactSettingDefaults };
@@ -0,0 +1,91 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import { type Engine, type EnginePlugin } from '@margoengine/core/extension';
3
+ import type { EngineKernel } from '@margoengine/core';
4
+ import type { Terrain, TerrainLighting } from './index.js';
5
+ /** The look of ground contact; every field is live. */
6
+ export interface GroundContactLook {
7
+ /** Linear RGB albedo of the soil and litter at the feet, 0-1. Default [0.1, 0.08, 0.055]. */
8
+ color?: readonly [number, number, number];
9
+ /** How far the ground turns to `color` where the soil weight is full, 0-1. Default 1. */
10
+ soil?: number;
11
+ /** How much of the sky light lost at a foot is taken, 0-1. Default 1. */
12
+ occlusion?: number;
13
+ }
14
+ /** Options of {@link TerrainGroundContact.attach}. */
15
+ export interface GroundContactOptions extends GroundContactLook {
16
+ /** Metres a mask texel covers, 0.05 to 4. Default 0.2. */
17
+ texel?: number;
18
+ /** Mask texels a side, an integer 64 to 4096 (2 bytes each). Default 1024: 205 m around the camera. */
19
+ resolution?: number;
20
+ /** The first of the three lighting-group bindings the effect declares. Default 124. */
21
+ binding?: number;
22
+ }
23
+ /** The baked mask: red the soil weight and green the sky lost, over a world rectangle with row 0 at `minZ`. */
24
+ export interface GroundContactMask {
25
+ /** rg8unorm. Borrowed: `dispose()` frees it. */
26
+ readonly texture: GPUTexture;
27
+ /** `[minX, minZ, maxX, maxZ]`, world metres. */
28
+ readonly bounds: readonly [number, number, number, number];
29
+ }
30
+ /** A footprint's kind: 0 a trunk (soil that thins outward), 1 a stone (a narrow ring). */
31
+ export type FootprintKind = 0 | 1;
32
+ /**
33
+ * The soil weight and the sky lost, both 0-1, `d` metres from the centre of a footprint of radius `r`; returns
34
+ * `[0, 0]` from 4 radii out.
35
+ * @example footprintAt(0.4, 0.4, 1)[1]; // 0.354, a stone's sky loss one radius from its centre
36
+ */
37
+ export declare function footprintAt(d: number, r: number, kind: FootprintKind): [soil: number, loss: number];
38
+ /**
39
+ * Bakes footprints (flat `[x, z, radius, kind, ...]` lists) into an rg8 mask of `size` x `size` texels of `texel`
40
+ * metres whose first corner is `origin`: soil weights take the largest, sky losses combine as independent occluders.
41
+ * `out` (2 bytes a texel) is cleared and returned.
42
+ */
43
+ export declare function bakeGroundContact(lists: Iterable<ArrayLike<number>>, origin: readonly [number, number], size: number, texel: number, out?: Uint8Array): Uint8Array;
44
+ /**
45
+ * Soil, litter and contact shade on a clipmap {@link Terrain} around the objects standing on it:
46
+ * `const contact = TerrainGroundContact.attach(engine, terrain)`, then `contact.set('rocks', [x, z, radius, 1])`.
47
+ * WebGPU (and the WebGL2 compatibility layer).
48
+ * @throws TypeError for a missing terrain; RangeError for an option, a look or a footprint out of range.
49
+ * @throws MargoError `'disposed'` after `dispose()`, `'unsupported'` when the terrain's shader has no lit ambient term.
50
+ */
51
+ export declare class TerrainGroundContact implements EnginePlugin, TerrainLighting, Disposable {
52
+ #private;
53
+ readonly name: string;
54
+ /** Whether the effect has been disposed. */
55
+ disposed: boolean;
56
+ readonly texel: number;
57
+ readonly resolution: number;
58
+ readonly binding: number;
59
+ /** The current look (live; change it with `setLook`). */
60
+ readonly look: Required<GroundContactLook>;
61
+ constructor(terrain: Terrain, options?: GroundContactOptions);
62
+ /** Attaches ground contact to `terrain` on `engine`. */
63
+ static attach(engine: EngineKernel, terrain: Terrain, options?: GroundContactOptions): TerrainGroundContact;
64
+ /** Sets any of `color`, `soil` and `occlusion` (others keep theirs); nothing is rebuilt. */
65
+ setLook(look: GroundContactLook): void;
66
+ /**
67
+ * Holds the footprints of `key`, replacing its last: flat `[x, z, radius, kind, ...]`, world metres, kind 0 a trunk
68
+ * or 1 a stone. An empty list removes the key. The list is copied.
69
+ */
70
+ set(key: string, footprints: ArrayLike<number>): void;
71
+ /** Forgets the footprints of `key`. */
72
+ remove(key: string): void;
73
+ /** The footprints held under all keys. */
74
+ get count(): number;
75
+ get owner(): Engine | undefined;
76
+ setup(engine: Engine): void;
77
+ onDeviceRestored(engine: Engine): void;
78
+ /**
79
+ * The mask as it stands for this frame, re-centred and rebaked first when the camera or the footprints moved; undefined
80
+ * before the effect is attached. Ground cover reads it to open around the feet:
81
+ * `clearingMap(() => contact.mask())` of `@margoengine/scatter/clearing-map`.
82
+ */
83
+ mask(): GroundContactMask | undefined;
84
+ /** The lighting group entries, after re-centring and rebaking the mask when the camera or the footprints moved. */
85
+ bindings(): GPUBindGroupEntry[];
86
+ /** The terrain's lit shader with soil on `terrainColor` and the sky light lost taken from the ambient term. */
87
+ shader(source: string, group: number): string;
88
+ /** Detaches from the terrain (its shader returns to what it was) and frees the mask. */
89
+ dispose(): void;
90
+ [Symbol.dispose](): void;
91
+ }
@@ -0,0 +1,241 @@
1
+ // @margo/core-built 1.0.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+ const t=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
+ import { t as e } from "./require-webgpu--tUXPsmA.js";
5
+ import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
6
+ import { MargoError as n } from "@margoengine/math/errors";
7
+ //#region src/ground-contact.ts
8
+ var r = [
9
+ .1,
10
+ .08,
11
+ .055
12
+ ], i = "fn terrainColor(position:vec3f,normal:vec3f)->vec3f {", a = "+base*frame.radiance.w*frame.ambient.rgb", o = /let linear=/g, s = (e, t, n) => {
13
+ let r = Math.min(1, Math.max(0, (n - e) / (t - e)));
14
+ return r * r * (3 - 2 * r);
15
+ };
16
+ function c(e, t, n) {
17
+ if (!(t > 0) || !(e < 4 * t + .3)) return [0, 0];
18
+ let r = e / t, i = Math.max(0, e - t), a = (n === 0 ? .6 : 1) / (1 + r * r) ** 1.5 * (1 - s(3.5, 4, r)), o = n === 0 ? Math.exp(-i / (1.1 * t)) * (1 - s(2.5 * t, 3 * t, i)) : .75 * Math.exp(-Math.max(0, i - Math.max(.06, .25 * t)) / Math.max(.05, .35 * t)) * (1 - s(3, 4, r));
19
+ return [o < 1 / 255 ? 0 : o, a];
20
+ }
21
+ function l(e, t, n, r, i = new Uint8Array(n * n * 2)) {
22
+ i.fill(0);
23
+ for (let a of e) for (let e = 0; e + 3 < a.length; e += 4) {
24
+ let o = a[e] - t[0], s = a[e + 1] - t[1], l = a[e + 2], u = +!!a[e + 3], d = Math.max(l, r * .5), f = Math.min(1, l / d), p = 4 * d + .3, m = Math.max(0, Math.floor((o - p) / r)), h = Math.min(n - 1, Math.ceil((o + p) / r)), g = Math.max(0, Math.floor((s - p) / r)), _ = Math.min(n - 1, Math.ceil((s + p) / r));
25
+ for (let e = g; e <= _; e++) for (let t = m; t <= h; t++) {
26
+ let [a, l] = c(Math.hypot((t + .5) * r - o, (e + .5) * r - s), d, u), p = (e * n + t) * 2, m = Math.round(a * f * 255);
27
+ m > i[p] && (i[p] = m), l > 0 && (i[p + 1] = Math.round(255 - (255 - i[p + 1]) * (1 - l * f)));
28
+ }
29
+ }
30
+ return i;
31
+ }
32
+ var u = 0, d = class s {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
33
+ #e;
34
+ #t;
35
+ #n;
36
+ #r;
37
+ #i;
38
+ #a;
39
+ #o;
40
+ #s;
41
+ #c;
42
+ #l;
43
+ #u;
44
+ #d;
45
+ #f;
46
+ #p;
47
+ #m;
48
+ #h;
49
+ constructor(e, t = {}) {
50
+ if (this.name = "ground-contact:" + u++, this.disposed = !1, this.look = {
51
+ color: r,
52
+ soil: 1,
53
+ occlusion: 1
54
+ }, this.#e = /* @__PURE__ */ new Map(), this.#c = [], this.#u = /* @__PURE__ */ new Float32Array(8), this.#p = !0, this.#m = !0, this.#h = /* @__PURE__ */ new Map(), !e || typeof e.addLighting != "function") throw TypeError("TerrainGroundContact needs a clipmap Terrain (@margoengine/terrain)");
55
+ let { texel: n = .2, resolution: i = 1024, binding: a = 124 } = t;
56
+ if (!(Number.isFinite(n) && n >= .05 && n <= 4)) throw RangeError("TerrainGroundContact texel must be 0.05 to 4 metres");
57
+ if (!Number.isInteger(i) || i < 64 || i > 4096) throw RangeError("TerrainGroundContact resolution must be an integer 64 to 4096");
58
+ if (!Number.isInteger(a) || a < 0 || a > 997) throw RangeError("TerrainGroundContact binding must be an integer 0 to 997");
59
+ this.#t = e;
60
+ let o = e.options?.origin;
61
+ this.#n = [o?.[0] ?? 0, o?.[1] ?? 0], this.texel = n, this.resolution = i, this.binding = a, this.setLook(t);
62
+ }
63
+ static attach(e, n, r = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
64
+ let i = new s(n, r);
65
+ return t(e).use(i), i;
66
+ }
67
+ setLook(e) {
68
+ this.#g();
69
+ let t = { ...this.look };
70
+ if (e.color !== void 0) {
71
+ if (e.color.length !== 3 || !e.color.every((e) => Number.isFinite(e) && e >= 0 && e <= 1)) throw RangeError("TerrainGroundContact color must be a linear RGB of 0-1");
72
+ t.color = [
73
+ e.color[0],
74
+ e.color[1],
75
+ e.color[2]
76
+ ];
77
+ }
78
+ for (let n of ["soil", "occlusion"]) {
79
+ let r = e[n];
80
+ if (r !== void 0) {
81
+ if (!(typeof r == "number" && r >= 0 && r <= 1)) throw RangeError(`TerrainGroundContact ${n} must be a number from 0 to 1`);
82
+ t[n] = r;
83
+ }
84
+ }
85
+ Object.assign(this.look, t), this.#m = !0;
86
+ }
87
+ set(e, t) {
88
+ this.#g();
89
+ let n = t?.length;
90
+ if (typeof e != "string" || !Number.isInteger(n) || n % 4 != 0) throw RangeError("TerrainGroundContact.set needs a key and a flat [x, z, radius, kind, ...] list");
91
+ if (!n) return this.remove(e);
92
+ let r = Float32Array.from(t), i = [
93
+ Infinity,
94
+ Infinity,
95
+ -Infinity,
96
+ -Infinity
97
+ ];
98
+ for (let e = 0; e < n; e += 4) {
99
+ let [t, n, a] = [
100
+ r[e],
101
+ r[e + 1],
102
+ r[e + 2]
103
+ ];
104
+ if (!Number.isFinite(t) || !Number.isFinite(n) || !(a >= 0 && a <= 100)) throw RangeError("TerrainGroundContact footprints need finite x and z and a radius of 0 to 100 m");
105
+ let o = 4 * Math.max(a, this.texel) + .3;
106
+ i[0] = Math.min(i[0], t - o), i[1] = Math.min(i[1], n - o), i[2] = Math.max(i[2], t + o), i[3] = Math.max(i[3], n + o);
107
+ }
108
+ let a = this.#e.get(e);
109
+ this.#e.set(e, {
110
+ list: r,
111
+ box: i
112
+ }), (this.#_(i) || a && this.#_(a.box)) && (this.#p = !0);
113
+ }
114
+ remove(e) {
115
+ let t = this.#e.get(e);
116
+ t && (this.#e.delete(e), this.#_(t.box) && (this.#p = !0));
117
+ }
118
+ get count() {
119
+ let e = 0;
120
+ for (let { list: t } of this.#e.values()) e += t.length / 4;
121
+ return e;
122
+ }
123
+ #g() {
124
+ if (this.disposed) throw new n("disposed", "This TerrainGroundContact was disposed; attach a new one");
125
+ }
126
+ #_(e) {
127
+ let t = this.#f;
128
+ if (!t) return !0;
129
+ let n = this.texel * this.resolution;
130
+ return e[2] > t[0] && e[0] < t[0] + n && e[3] > t[1] && e[1] < t[1] + n;
131
+ }
132
+ get owner() {
133
+ return this.#r;
134
+ }
135
+ setup(t) {
136
+ e(t, "TerrainGroundContact"), this.#g(), this.#r = t, this.#v(t.gpu), this.#i ??= this.#t.addLighting(this);
137
+ }
138
+ onDeviceRestored(e) {
139
+ this.#v(e.gpu);
140
+ }
141
+ #v(e) {
142
+ let t = this.resolution;
143
+ this.#a = e.createBuffer({
144
+ size: 32,
145
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
146
+ }), this.#o = e.createTexture({
147
+ size: [t, t],
148
+ format: "rg8unorm",
149
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST
150
+ }), this.#s = e.createSampler({
151
+ minFilter: "linear",
152
+ magFilter: "linear"
153
+ }), this.#c = [
154
+ {
155
+ binding: this.binding,
156
+ resource: this.#o.createView()
157
+ },
158
+ {
159
+ binding: this.binding + 1,
160
+ resource: this.#s
161
+ },
162
+ {
163
+ binding: this.binding + 2,
164
+ resource: { buffer: this.#a }
165
+ }
166
+ ], this.#p = this.#m = !0;
167
+ }
168
+ mask() {
169
+ if (this.#y()) return this.#l;
170
+ }
171
+ bindings() {
172
+ return this.#y() ? this.#c : [];
173
+ }
174
+ #y() {
175
+ let e = this.#r?.gpu;
176
+ if (!e || !this.#o || !this.#a) return !1;
177
+ let t = this.texel * this.resolution, n = this.#r.camera.position, r = Math.max(1, this.resolution >> 3) * this.texel, i = Math.round((n[0] - t / 2) / r) * r, a = Math.round((n[2] - t / 2) / r) * r, o = this.#f;
178
+ (!o || Math.abs(i - o[0]) > r * 1.5 || Math.abs(a - o[1]) > r * 1.5) && (this.#f = [i, a], this.#p = this.#m = !0);
179
+ let s = this.#f, c = this.#l;
180
+ if ((!c || c.texture !== this.#o || c.bounds[0] !== s[0] || c.bounds[1] !== s[1]) && (this.#l = {
181
+ texture: this.#o,
182
+ bounds: [
183
+ s[0],
184
+ s[1],
185
+ s[0] + t,
186
+ s[1] + t
187
+ ]
188
+ }), this.#p) {
189
+ let t = [];
190
+ for (let e of this.#e.values()) this.#_(e.box) && t.push(e.list);
191
+ this.#d = l(t, s, this.resolution, this.texel, this.#d), e.queue.writeTexture({ texture: this.#o }, this.#d, { bytesPerRow: this.resolution * 2 }, [this.resolution, this.resolution]), this.#p = !1;
192
+ }
193
+ if (this.#m) {
194
+ let n = this.look, [r, i] = this.#n;
195
+ this.#u.set([
196
+ s[0] - r,
197
+ s[1] - i,
198
+ 1 / t,
199
+ n.soil,
200
+ ...n.color,
201
+ n.occlusion
202
+ ]), e.queue.writeBuffer(this.#a, 0, this.#u), this.#m = !1;
203
+ }
204
+ return !0;
205
+ }
206
+ shader(e, t) {
207
+ let r = t + e, s = this.#h.get(r);
208
+ if (s) return s;
209
+ if (e.split(i).length !== 2 || e.split(a).length !== 2 || [...e.matchAll(o)].length !== 1) throw new n("unsupported", "TerrainGroundContact needs the terrain's lit shader with its terrainColor and ambient term");
210
+ let c = "_c" + this.name.slice(this.name.indexOf(":") + 1), l = this.binding, u = `
211
+ @group(${t}) @binding(${l}) var contactMask${c}:texture_2d<f32>;
212
+ @group(${t}) @binding(${l + 1}) var contactSampler${c}:sampler;
213
+ @group(${t}) @binding(${l + 2}) var<uniform> contactLook${c}:array<vec4f,2>;
214
+ fn contactHash${c}(c:vec2i)->f32 {let u=bitcast<vec2u>(c);var x=(u.x*0x8da6b343u)^(u.y*0xd8163841u);x=(x^(x>>16u))*0x7feb352du;x=(x^(x>>15u))*0x846ca68bu;return f32(x^(x>>16u))/4294967296.0;}
215
+ fn contactNoise${c}(p:vec2f)->f32 {let c=vec2i(floor(p));let f=fract(p);let t=f*f*(3.0-2.0*f);
216
+ return mix(mix(contactHash${c}(c),contactHash${c}(c+vec2i(1,0)),t.x),mix(contactHash${c}(c+vec2i(0,1)),contactHash${c}(c+vec2i(1,1)),t.x),t.y);}
217
+ fn contactAt${c}(p:vec2f)->vec2f {
218
+ let L=contactLook${c}[0];let uv=(p-L.xy)*L.z;let inside=all(uv>=vec2f(0))&&all(uv<=vec2f(1));
219
+ let m=textureSampleLevel(contactMask${c},contactSampler${c},uv,0.0).rg;return select(vec2f(0),m,inside);
220
+ }
221
+ `, d = `
222
+ ${i}
223
+ let under=terrainColorBare${c}(position,normal);let p=position.xz-frame.map.xy;
224
+ let ragged=vec2f(contactNoise${c}(p*3.1),contactNoise${c}(p*3.1+17.0))-0.5;
225
+ let weight=clamp(contactAt${c}(p+ragged*0.24).x*(0.55+0.9*contactNoise${c}(p*7.3)),0.0,1.0)*contactLook${c}[0].w;
226
+ return mix(under,contactLook${c}[1].rgb*(0.65+0.7*contactNoise${c}(p*23.0)),weight);
227
+ }`, f = u + e.replace(i, `fn terrainColorBare${c}(position:vec3f,normal:vec3f)->vec3f {`).replace(o, `let contactSky${c}=1.0-contactAt${c}(i.position.xz-frame.map.xy).y*contactLook${c}[1].w;let linear=`).replace(a, `${a}*contactSky${c}`) + d;
228
+ return this.#h.size >= 16 && this.#h.clear(), this.#h.set(r, f), f;
229
+ }
230
+ dispose() {
231
+ if (this.disposed) return;
232
+ this.disposed = !0, this.#i?.(), this.#i = void 0, this.#a?.destroy(), this.#o?.destroy(), this.#a = this.#o = void 0, this.#l = void 0, this.#c = [], this.#e.clear(), this.#h.clear(), this.#d = void 0;
233
+ let e = this.#r;
234
+ this.#r = void 0, this.#t = void 0, e?.sceneOf(this)?.removePlugin(this.name);
235
+ }
236
+ [Symbol.dispose]() {
237
+ this.dispose();
238
+ }
239
+ };
240
+ //#endregion
241
+ export { d as TerrainGroundContact, l as bakeGroundContact, c as footprintAt };