@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.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +2366 -2
- package/dist/bed-mesh.d.ts +40 -0
- package/dist/bed-mesh.js +95 -0
- package/dist/blend.d.ts +70 -0
- package/dist/blend.js +159 -0
- package/dist/colors.d.ts +170 -0
- package/dist/deform.d.ts +134 -0
- package/dist/deform.js +404 -0
- package/dist/displace.d.ts +60 -0
- package/dist/displace.js +254 -0
- package/dist/dunes.d.ts +86 -0
- package/dist/dunes.js +88 -0
- package/dist/elevation.d.ts +182 -0
- package/dist/elevation.js +155 -0
- package/dist/errors-fc4i1pSL.js +7 -0
- package/dist/far.d.ts +66 -0
- package/dist/far.js +191 -0
- package/dist/furrows.d.ts +74 -0
- package/dist/furrows.js +157 -0
- package/dist/grid.d.ts +14 -0
- package/dist/ground-change-settings.d.ts +29 -0
- package/dist/ground-change-settings.js +69 -0
- package/dist/ground-change.d.ts +227 -0
- package/dist/ground-change.js +1412 -0
- package/dist/ground-contact-settings.d.ts +27 -0
- package/dist/ground-contact-settings.js +22 -0
- package/dist/ground-contact.d.ts +91 -0
- package/dist/ground-contact.js +241 -0
- package/dist/ground-model.d.ts +372 -0
- package/dist/hdr-format-DRhzGS7G.js +30 -0
- package/dist/height-grid.d.ts +65 -0
- package/dist/height-grid.js +74 -0
- package/dist/heightfield.d.ts +38 -0
- package/dist/holes.d.ts +37 -0
- package/dist/holes.js +97 -0
- package/dist/imagery.d.ts +109 -0
- package/dist/imagery.js +472 -0
- package/dist/index.d.ts +408 -0
- package/dist/index.js +1 -0
- package/dist/layers-pbr.d.ts +78 -0
- package/dist/layers-pbr.js +128 -0
- package/dist/lighting-layout-CaDtDa5G.js +34 -0
- package/dist/lighting-layout.d.ts +5 -0
- package/dist/mesh-patch-BThCHCeS.js +21 -0
- package/dist/mesh-patch.d.ts +14 -0
- package/dist/noise3-sQdnbz4B.js +11 -0
- package/dist/noise3.d.ts +3 -0
- package/dist/overlays.d.ts +74 -0
- package/dist/overlays.js +297 -0
- package/dist/planet-complex.d.ts +31 -0
- package/dist/planet-craters.d.ts +80 -0
- package/dist/planet-rays.d.ts +37 -0
- package/dist/planet-recipes.d.ts +84 -0
- package/dist/planet-recipes.js +442 -0
- package/dist/planet.d.ts +144 -0
- package/dist/planet.js +610 -0
- package/dist/query.d.ts +150 -0
- package/dist/query.js +243 -0
- package/dist/relief-lighting.d.ts +53 -0
- package/dist/relief-lighting.js +221 -0
- package/dist/require-webgpu--tUXPsmA.js +7 -0
- package/dist/rock-settings.d.ts +39 -0
- package/dist/rock-settings.js +84 -0
- package/dist/rock-surface.d.ts +114 -0
- package/dist/rock-surface.js +380 -0
- package/dist/rocks.d.ts +258 -0
- package/dist/rocks.js +488 -0
- package/dist/rvt.d.ts +136 -0
- package/dist/rvt.js +518 -0
- package/dist/scour.d.ts +90 -0
- package/dist/scour.js +153 -0
- package/dist/sculpt.d.ts +103 -0
- package/dist/sculpt.js +361 -0
- package/dist/settings-B9BSdnhD.js +72 -0
- package/dist/settings.d.ts +81 -0
- package/dist/settings.js +152 -0
- package/dist/shader.d.ts +176 -0
- package/dist/shared/settings.d.ts +89 -0
- package/dist/src-Cr7Gm4n0.js +1366 -0
- package/dist/stream-window.d.ts +123 -0
- package/dist/stream.d.ts +169 -0
- package/dist/stream.js +531 -0
- package/dist/surface-height.d.ts +16 -0
- package/dist/wet-ground.d.ts +82 -0
- package/dist/wet-ground.js +147 -0
- package/package.json +173 -4
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
//#region ../shared/settings.js
|
|
2
|
+
var e = (e, t, n) => typeof e == "number" && e >= t && e <= n, t = (t, n, r) => Array.isArray(t) && t.length === 3 && t.every((t) => e(t, n, r)), n = (e) => e.stopKey ?? "elevation", r = (e, t, n, r, i, a, o, s, c = !0) => ({
|
|
3
|
+
name: e,
|
|
4
|
+
group: t,
|
|
5
|
+
kind: "number",
|
|
6
|
+
default: n,
|
|
7
|
+
min: r,
|
|
8
|
+
max: i,
|
|
9
|
+
step: a,
|
|
10
|
+
unit: o,
|
|
11
|
+
about: s,
|
|
12
|
+
live: c
|
|
13
|
+
}), i = (e, t, n, r, i, a, o = !0) => ({
|
|
14
|
+
name: e,
|
|
15
|
+
group: t,
|
|
16
|
+
kind: "color",
|
|
17
|
+
default: n,
|
|
18
|
+
min: r,
|
|
19
|
+
max: i,
|
|
20
|
+
step: .01,
|
|
21
|
+
unit: "",
|
|
22
|
+
about: a,
|
|
23
|
+
live: o
|
|
24
|
+
}), a = (e, t) => ({
|
|
25
|
+
...e,
|
|
26
|
+
default: null,
|
|
27
|
+
nullable: !0,
|
|
28
|
+
weather: t
|
|
29
|
+
}), o = Symbol.for("margoengine.weather-held");
|
|
30
|
+
function s(e, t, n = !0) {
|
|
31
|
+
if (typeof e != "object" || !e) return;
|
|
32
|
+
let r = e[o];
|
|
33
|
+
n ? (r || Object.defineProperty(e, o, {
|
|
34
|
+
value: r = /* @__PURE__ */ new Set(),
|
|
35
|
+
configurable: !0
|
|
36
|
+
}), r.add(t)) : r?.delete(t);
|
|
37
|
+
}
|
|
38
|
+
var c = (e, t) => JSON.stringify(e) === JSON.stringify(t);
|
|
39
|
+
function l(e) {
|
|
40
|
+
return Array.isArray(e) ? typeof e[0] == "object" ? e.map((e) => ({
|
|
41
|
+
...e,
|
|
42
|
+
color: [...e.color]
|
|
43
|
+
})) : [...e] : e;
|
|
44
|
+
}
|
|
45
|
+
function u(e) {
|
|
46
|
+
return Object.fromEntries(e.map((e) => [e.name, l(e.default)]));
|
|
47
|
+
}
|
|
48
|
+
var d = (e) => e.filter((e) => e.live), f = (e) => new Map(e.map((e) => [e.name, e]));
|
|
49
|
+
function p(r, i, a) {
|
|
50
|
+
let o = r.min ?? -Infinity, s = r.max ?? Infinity, c;
|
|
51
|
+
if (i === null) c = !!r.nullable;
|
|
52
|
+
else if (r.kind === "number") c = e(i, o, s);
|
|
53
|
+
else if (r.kind === "color") c = t(i, o, s);
|
|
54
|
+
else if (r.kind === "choice") c = r.choices.includes(i);
|
|
55
|
+
else {
|
|
56
|
+
let a = n(r);
|
|
57
|
+
c = Array.isArray(i) && i.length >= 2 && i.length <= 8 && i.every((n, r) => typeof n == "object" && !!n && e(n[a], o, s) && t(n.color, 0, 1) && (r === 0 || n[a] > i[r - 1][a]));
|
|
58
|
+
}
|
|
59
|
+
if (c) return;
|
|
60
|
+
let l = r.nullable ? r.weather ? ` or null (follow the weather's ${r.weather})` : " or null" : "", u = r.kind === "number" ? `a number from ${o} to ${s}${l}` : r.kind === "color" ? `three numbers from ${o} to ${s} (linear RGB)${l}` : r.kind === "choice" ? r.choices.map((e) => `'${e}'`).join(" or ") + l : `2 to 8 stops {${n(r)}, color}, ${n(r)} ${o} to ${s} rising, colours 0 to 1${l}`;
|
|
61
|
+
throw RangeError(`Invalid ${a} setting ${r.name}; use ${u}`);
|
|
62
|
+
}
|
|
63
|
+
function m(e, t, n, r = `the rows in @margoengine/${n}/settings`) {
|
|
64
|
+
let i = e instanceof Map ? e : f(e);
|
|
65
|
+
for (let e of Object.keys(t)) {
|
|
66
|
+
let a = i.get(e);
|
|
67
|
+
if (!a) throw TypeError(`Unknown ${n} setting ${e}; use a name from ${r}`);
|
|
68
|
+
p(a, t[e], n);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { d as a, u as c, s as i, f as l, i as n, r as o, a as r, c as s, m as t };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type SettingRow } from './shared/settings.js';
|
|
2
|
+
import type { TerrainColors } from './colors.js';
|
|
3
|
+
/** A colour value: linear RGB. */
|
|
4
|
+
export type TerrainSettingColor = readonly [number, number, number];
|
|
5
|
+
/** One value of a setting: a number, a colour, or null where `nullable`. */
|
|
6
|
+
export type TerrainSettingValue = number | TerrainSettingColor | null;
|
|
7
|
+
/** Values by setting name; a name left out takes its default. */
|
|
8
|
+
export type TerrainSettingValues = Readonly<Record<string, TerrainSettingValue>>;
|
|
9
|
+
/** The panel a setting sits in. */
|
|
10
|
+
export type TerrainSettingGroup = 'sand' | 'ripples' | 'colors' | 'bands' | 'wet';
|
|
11
|
+
/** One control: the shared row shape with the terrain's groups. */
|
|
12
|
+
export interface TerrainSetting extends SettingRow {
|
|
13
|
+
readonly group: TerrainSettingGroup;
|
|
14
|
+
readonly default: TerrainSettingValue;
|
|
15
|
+
}
|
|
16
|
+
/** Every terrain look control, in panel order. Defaults are the values TerrainColors uses without the option. */
|
|
17
|
+
export declare const TERRAIN_SETTINGS: readonly TerrainSetting[];
|
|
18
|
+
/** The rows that can change every frame (all of them). */
|
|
19
|
+
export declare const TERRAIN_LIVE_SETTINGS: readonly TerrainSetting[];
|
|
20
|
+
/** Every setting at its default, as a fresh object to edit (a slider panel's state). */
|
|
21
|
+
export declare function terrainSettingDefaults(): Record<string, TerrainSettingValue>;
|
|
22
|
+
/**
|
|
23
|
+
* Named looks, each only values of {@link TERRAIN_SETTINGS} (a name left out keeps its default): pass one to
|
|
24
|
+
* {@link applyTerrainSettings}, or spread it under your own values.
|
|
25
|
+
*/
|
|
26
|
+
export declare const TERRAIN_LOOKS: {
|
|
27
|
+
/** Today's defaults: every row at its default, as the terrain draws with no settings. */
|
|
28
|
+
readonly natural: {};
|
|
29
|
+
/** Pale desert sand with sharp ripples and strong streaks. */
|
|
30
|
+
readonly paleDesert: {
|
|
31
|
+
readonly 'sand.color': readonly [0.62, 0.52, 0.36];
|
|
32
|
+
readonly 'sand.ripples': 1.3;
|
|
33
|
+
readonly 'sand.streaks': 1;
|
|
34
|
+
readonly 'sand.broad': 0.6;
|
|
35
|
+
};
|
|
36
|
+
/** Red desert sand with long scour bands. */
|
|
37
|
+
readonly redDesert: {
|
|
38
|
+
readonly 'sand.color': readonly [0.55, 0.3, 0.18];
|
|
39
|
+
readonly 'sand.ripples': 1;
|
|
40
|
+
readonly 'sand.broad': 1;
|
|
41
|
+
};
|
|
42
|
+
/** Dark volcanic beach sand, wetter and darker at the waterline. */
|
|
43
|
+
readonly volcanicBeach: {
|
|
44
|
+
readonly 'sand.color': readonly [0.08, 0.08, 0.09];
|
|
45
|
+
readonly 'wet.darkening': 0.45;
|
|
46
|
+
readonly 'sand.ripples': 0.5;
|
|
47
|
+
readonly 'sand.streaks': 0.3;
|
|
48
|
+
};
|
|
49
|
+
/** A salt flat: pale, nearly flat, no ripples to speak of. */
|
|
50
|
+
readonly saltFlat: {
|
|
51
|
+
readonly 'sand.color': readonly [0.8, 0.78, 0.72];
|
|
52
|
+
readonly 'sand.ripples': 0.2;
|
|
53
|
+
readonly 'sand.streaks': 0.2;
|
|
54
|
+
readonly 'sand.sorting': 0.2;
|
|
55
|
+
readonly 'wet.darkening': 0.8;
|
|
56
|
+
};
|
|
57
|
+
/** The animatedFeature family: larger colour masses, softer fine detail, a clean wet band at the waterline. */
|
|
58
|
+
readonly animatedFeature: {
|
|
59
|
+
readonly 'sand.color': readonly [0.62, 0.5, 0.34];
|
|
60
|
+
readonly 'sand.ripples': 0.6;
|
|
61
|
+
readonly 'sand.streaks': 0.5;
|
|
62
|
+
readonly 'sand.broad': 0.8;
|
|
63
|
+
readonly 'meadow.low': readonly [0.16, 0.33, 0.05];
|
|
64
|
+
readonly 'meadow.high': readonly [0.3, 0.42, 0.09];
|
|
65
|
+
readonly 'stone.color': readonly [0.3, 0.26, 0.21];
|
|
66
|
+
readonly 'wet.darkening': 0.5;
|
|
67
|
+
readonly 'wet.heightStart': -0.05;
|
|
68
|
+
readonly 'wet.heightEnd': 0.3;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
/** The name of a look in {@link TERRAIN_LOOKS}. */
|
|
72
|
+
export type TerrainLookName = keyof typeof TERRAIN_LOOKS;
|
|
73
|
+
/**
|
|
74
|
+
* Writes `values` onto a {@link TerrainColors} (a name left out takes its default) with one `setLook` call, so the
|
|
75
|
+
* terrain shows exactly that state. A row at its default draws as TerrainColors does without the option. A null
|
|
76
|
+
* `sand.windDirection` leaves the wind to whatever last set it (the weather drive, or the +x default).
|
|
77
|
+
* @throws TypeError for a name not in {@link TERRAIN_SETTINGS}, or a sand row moved on a TerrainColors built without a
|
|
78
|
+
* sand surface; RangeError for a value outside its row's range or kind, or a range whose start is not below its end.
|
|
79
|
+
* @example applyTerrainSettings(colors, { ...TERRAIN_LOOKS.paleDesert, 'sand.windDirection': 45 });
|
|
80
|
+
*/
|
|
81
|
+
export declare function applyTerrainSettings(colors: TerrainColors, values?: TerrainSettingValues): void;
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { a as e, c as t, l as n, n as r, o as i, r as a, s as o, t as s } from "./settings-B9BSdnhD.js";
|
|
2
|
+
//#region src/settings.ts
|
|
3
|
+
var c = (e, t, n, r, a, o, s, c) => i(e, t, n, r, a, o, s, c), l = (e, t, n, i) => r(e, t, n, 0, 1, i), u = (e, t) => ({
|
|
4
|
+
...e,
|
|
5
|
+
default: null,
|
|
6
|
+
nullable: !0,
|
|
7
|
+
about: t
|
|
8
|
+
}), d = [
|
|
9
|
+
l("sand.color", "sand", [
|
|
10
|
+
.5,
|
|
11
|
+
.42,
|
|
12
|
+
.29
|
|
13
|
+
], "Beach and dune sand colour: dry sand has an albedo of about 0.4."),
|
|
14
|
+
{ ...a(c("sand.windDirection", "sand", 0, 0, 360, 1, "degrees", "The way the wind blows over the sand: 0 toward +x, 90 toward +z. Null follows the weather."), "windDirection") },
|
|
15
|
+
c("sand.ripples", "ripples", 1, 0, 2, .01, "", "Ripple relief: 0 flat, 1 the real shape (height 1/15 of the spacing), 2 twice as steep."),
|
|
16
|
+
c("sand.ripple", "ripples", .1, .02, 1, .005, "m", "Ripple spacing: impact ripples of fine to medium sand are 5 to 20 cm apart."),
|
|
17
|
+
c("sand.streaks", "ripples", 1, 0, 1, .01, "", "Streak contrast along the wind: albedo varies by up to 8% either way at 1."),
|
|
18
|
+
c("sand.sorting", "ripples", 1, 0, 1, .01, "", "Sorting by slope: lee slip faces paler, windward faces darker."),
|
|
19
|
+
c("sand.broad", "ripples", 0, 0, 1, .01, "", "Broad scour bands along the wind (8 to 15 m wide) that stay at every distance."),
|
|
20
|
+
l("meadow.low", "colors", [
|
|
21
|
+
.133,
|
|
22
|
+
.263,
|
|
23
|
+
.033
|
|
24
|
+
], "Meadow colour at its lowest."),
|
|
25
|
+
l("meadow.high", "colors", [
|
|
26
|
+
.274,
|
|
27
|
+
.342,
|
|
28
|
+
.064
|
|
29
|
+
], "Meadow colour at its highest."),
|
|
30
|
+
l("stone.color", "colors", [
|
|
31
|
+
.253,
|
|
32
|
+
.223,
|
|
33
|
+
.187
|
|
34
|
+
], "Rock colour, above the stone height and on steep slopes."),
|
|
35
|
+
c("shore.start", "bands", .3, -1e3, 1e4, .01, "m", "World height where the beach starts to give way to meadow."),
|
|
36
|
+
c("shore.end", "bands", 1.5, -1e3, 1e4, .01, "m", "World height above which there is no sand. Keep it above shore.start."),
|
|
37
|
+
u(c("meadow.heightStart", "bands", 0, -1e3, 1e4, .01, "m", ""), "World height where the low meadow colour starts to give way to the high one; null is the mesh's lowest point."),
|
|
38
|
+
u(c("meadow.heightEnd", "bands", 0, -1e3, 1e4, .01, "m", ""), "World height of the high meadow colour; null is the mesh's highest point. Keep it above meadow.heightStart."),
|
|
39
|
+
u(c("stone.heightStart", "bands", 0, -1e3, 1e4, .01, "m", ""), "World height where meadow starts to give way to rock; null is above the mesh's highest point (only slopes are stone)."),
|
|
40
|
+
u(c("stone.heightEnd", "bands", 0, -1e3, 1e4, .01, "m", ""), "World height above which all is rock; null as stone.heightStart. Keep it above stone.heightStart."),
|
|
41
|
+
c("stone.normalStart", "bands", .75, 0, 1, .005, "", "Surface normal Y (0 vertical, 1 flat) below which steep ground starts to turn to rock: 0.75 is 41 degrees."),
|
|
42
|
+
c("stone.normalEnd", "bands", .85, 0, 1, .005, "", "Surface normal Y above which ground is meadow again: 0.85 is 32 degrees. Keep it above stone.normalStart."),
|
|
43
|
+
c("wet.darkening", "wet", .6, 0, 1, .01, "", "Albedo of fully wet ground (1 is no darkening); wet ground is also up to 40% smoother."),
|
|
44
|
+
c("wet.heightStart", "wet", -.1, -1e3, 1e4, .01, "m", "World height where the wet band starts to dry, just above sea level."),
|
|
45
|
+
c("wet.heightEnd", "wet", .4, -1e3, 1e4, .01, "m", "World height above which the ground is dry. Keep it above wet.heightStart."),
|
|
46
|
+
c("wet.dryTime", "wet", 900, 1, 604800, 1, "s", "With a wetness map: seconds over which sand the water has left dries to 1/e of its moisture."),
|
|
47
|
+
c("wet.glossTime", "wet", 20, .1, 3600, .1, "s", "With a wetness map: seconds over which the glossy water film on sand the water has left drains to 1/e.")
|
|
48
|
+
], f = e(d), p = n(d);
|
|
49
|
+
function m() {
|
|
50
|
+
return t(d);
|
|
51
|
+
}
|
|
52
|
+
var h = {
|
|
53
|
+
natural: {},
|
|
54
|
+
paleDesert: {
|
|
55
|
+
"sand.color": [
|
|
56
|
+
.62,
|
|
57
|
+
.52,
|
|
58
|
+
.36
|
|
59
|
+
],
|
|
60
|
+
"sand.ripples": 1.3,
|
|
61
|
+
"sand.streaks": 1,
|
|
62
|
+
"sand.broad": .6
|
|
63
|
+
},
|
|
64
|
+
redDesert: {
|
|
65
|
+
"sand.color": [
|
|
66
|
+
.55,
|
|
67
|
+
.3,
|
|
68
|
+
.18
|
|
69
|
+
],
|
|
70
|
+
"sand.ripples": 1,
|
|
71
|
+
"sand.broad": 1
|
|
72
|
+
},
|
|
73
|
+
volcanicBeach: {
|
|
74
|
+
"sand.color": [
|
|
75
|
+
.08,
|
|
76
|
+
.08,
|
|
77
|
+
.09
|
|
78
|
+
],
|
|
79
|
+
"wet.darkening": .45,
|
|
80
|
+
"sand.ripples": .5,
|
|
81
|
+
"sand.streaks": .3
|
|
82
|
+
},
|
|
83
|
+
saltFlat: {
|
|
84
|
+
"sand.color": [
|
|
85
|
+
.8,
|
|
86
|
+
.78,
|
|
87
|
+
.72
|
|
88
|
+
],
|
|
89
|
+
"sand.ripples": .2,
|
|
90
|
+
"sand.streaks": .2,
|
|
91
|
+
"sand.sorting": .2,
|
|
92
|
+
"wet.darkening": .8
|
|
93
|
+
},
|
|
94
|
+
animatedFeature: {
|
|
95
|
+
"sand.color": [
|
|
96
|
+
.62,
|
|
97
|
+
.5,
|
|
98
|
+
.34
|
|
99
|
+
],
|
|
100
|
+
"sand.ripples": .6,
|
|
101
|
+
"sand.streaks": .5,
|
|
102
|
+
"sand.broad": .8,
|
|
103
|
+
"meadow.low": [
|
|
104
|
+
.16,
|
|
105
|
+
.33,
|
|
106
|
+
.05
|
|
107
|
+
],
|
|
108
|
+
"meadow.high": [
|
|
109
|
+
.3,
|
|
110
|
+
.42,
|
|
111
|
+
.09
|
|
112
|
+
],
|
|
113
|
+
"stone.color": [
|
|
114
|
+
.3,
|
|
115
|
+
.26,
|
|
116
|
+
.21
|
|
117
|
+
],
|
|
118
|
+
"wet.darkening": .5,
|
|
119
|
+
"wet.heightStart": -.05,
|
|
120
|
+
"wet.heightEnd": .3
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
function g(e, t = {}) {
|
|
124
|
+
s(p, t, "terrain", "TERRAIN_SETTINGS in @margoengine/terrain/settings");
|
|
125
|
+
let n = (e) => e in t ? t[e] : p.get(e).default, r = (e, t) => n(e) === null && n(t) === null ? null : [n(e), n(t)], i = d.some((e) => e.name.startsWith("sand.") && e.name !== "sand.color" && e.name in t && !o(t[e.name], e.default)), a = n("sand.windDirection"), c = {
|
|
126
|
+
sand: n("sand.color"),
|
|
127
|
+
meadow: [n("meadow.low"), n("meadow.high")],
|
|
128
|
+
stone: n("stone.color"),
|
|
129
|
+
shore: [n("shore.start"), n("shore.end")],
|
|
130
|
+
meadowHeight: r("meadow.heightStart", "meadow.heightEnd"),
|
|
131
|
+
stoneHeight: r("stone.heightStart", "stone.heightEnd"),
|
|
132
|
+
stoneNormal: [n("stone.normalStart"), n("stone.normalEnd")],
|
|
133
|
+
wetHeight: [n("wet.heightStart"), n("wet.heightEnd")],
|
|
134
|
+
wetDarkening: n("wet.darkening"),
|
|
135
|
+
wetDryTime: n("wet.dryTime"),
|
|
136
|
+
wetGlossTime: n("wet.glossTime")
|
|
137
|
+
};
|
|
138
|
+
if (i || a !== null || e.sandSurfaceOn) {
|
|
139
|
+
let e = (a ?? 0) * Math.PI / 180;
|
|
140
|
+
c.sandSurface = {
|
|
141
|
+
...a === null ? {} : { wind: [Math.cos(e), Math.sin(e)] },
|
|
142
|
+
ripple: n("sand.ripple"),
|
|
143
|
+
ripples: n("sand.ripples"),
|
|
144
|
+
streaks: n("sand.streaks"),
|
|
145
|
+
sorting: n("sand.sorting"),
|
|
146
|
+
broad: n("sand.broad")
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
e.setLook(c);
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
export { f as TERRAIN_LIVE_SETTINGS, h as TERRAIN_LOOKS, d as TERRAIN_SETTINGS, g as applyTerrainSettings, m as terrainSettingDefaults };
|
package/dist/shader.d.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
export declare const terrainVertex = "\nstruct Frame {camera:mat4x4f,eye:vec4f,light:vec4f,radiance:vec4f,grid:vec4f,offset:vec4f,map:vec4f,heights:vec4f,ambient:vec4f}\nstruct Layer {heightSlope:vec4f,params:vec4f}\n@group(0) @binding(0) var<uniform> frame:Frame;\n@group(0) @binding(1) var heightMap:texture_2d<f32>;\n@group(0) @binding(2) var normalMap:texture_2d<f32>;\n@group(0) @binding(3) var terrainLayers:texture_2d_array<f32>;\n@group(0) @binding(4) var terrainSampler:sampler;\n@group(0) @binding(5) var<storage,read> layerRules:array<Layer>;\nfn height(position:vec2f)->f32 {\n let dimensions=vec2i(textureDimensions(heightMap));let uv=clamp((position-frame.map.xy)/frame.map.zw,vec2f(0),vec2f(1));let pixel=uv*vec2f(dimensions-vec2i(1));let lo=vec2i(floor(pixel));let hi=min(lo+vec2i(1),dimensions-vec2i(1));let t=fract(pixel);\n let a=mix(textureLoad(heightMap,lo,0).r,textureLoad(heightMap,vec2i(hi.x,lo.y),0).r,t.x);let b=mix(textureLoad(heightMap,vec2i(lo.x,hi.y),0).r,textureLoad(heightMap,hi,0).r,t.x);\n return mix(a,b,t.y)*frame.heights.x+frame.heights.y;\n}\nfn terrainCatmull(t:f32)->vec4f {let t2=t*t;let t3=t2*t;return vec4f(-0.5*t3+t2-0.5*t,1.5*t3-2.5*t2+1.0,-1.5*t3+2.0*t2+0.5*t,0.5*t3-0.5*t2);}\nfn terrainCubic(position:vec2f)->f32 {\n let dimensions=vec2i(textureDimensions(heightMap));let uv=clamp((position-frame.map.xy)/frame.map.zw,vec2f(0),vec2f(1));let pixel=uv*vec2f(dimensions-vec2i(1));let lo=vec2i(floor(pixel));\n let wx=terrainCatmull(fract(pixel.x));let wy=terrainCatmull(fract(pixel.y));var h=0.0;\n for(var j=0;j<4;j++){for(var k=0;k<4;k++){h+=wx[k]*wy[j]*textureLoad(heightMap,clamp(lo+vec2i(k-1,j-1),vec2i(0),dimensions-vec2i(1)),0).r;}}\n return h*frame.heights.x+frame.heights.y;\n}\nfn terrainMorph(g:vec2f)->vec3f {\n let edge=max(abs(g.x),abs(g.y));let morph=clamp((edge-frame.grid.w*0.5+2)/2,0.0,1.0);\n return vec3f(mix(g,round(g*0.5)*2,morph),select(0.0,1.0,edge<=frame.grid.w*0.25));\n}\nfn terrainMorphXZ(m:vec3f)->vec2f {return frame.grid.xy+m.xy*frame.grid.z+frame.offset.xy*m.z;}\nstruct Output {@builtin(position) @invariant clip:vec4f,@location(0) position:vec3f,@location(1) normal:vec3f,@location(2) color:vec3f,@location(3) material:vec4f}\n@vertex fn vertex(@location(0) grid:vec2f)->Output {\n var m=terrainMorph(grid);var lift=0.0;let centre=fract(grid.x)!=0.0;\n if(centre){\n let a=terrainMorph(grid-vec2f(0.5));let b=terrainMorph(grid+vec2f(0.5,-0.5));let c=terrainMorph(grid+vec2f(-0.5,0.5));let d=terrainMorph(grid+vec2f(0.5));\n let ad=(height(terrainMorphXZ(a))+height(terrainMorphXZ(d)))*0.5;let bc=(height(terrainMorphXZ(b))+height(terrainMorphXZ(c)))*0.5;\n let r=terrainCubic(terrainMorphXZ((a+b+c+d)*0.25));let along=abs(r-ad)<abs(r-bc);\n m=select((b+c)*0.5,(a+d)*0.5,along);lift=select(bc,ad,along);\n }\n let aligned=m.xy;let inner=m.z;\n let xz=frame.grid.xy+aligned*frame.grid.z+frame.offset.xy*inner;let position=vec3f(xz.x,select(height(xz),lift,centre),xz.y);\n let step=frame.map.zw/max(vec2f(textureDimensions(heightMap))-1,vec2f(1));\n var normal=normalize(vec3f((height(xz-vec2f(step.x,0))-height(xz+vec2f(step.x,0)))/(2*step.x),1,(height(xz-vec2f(0,step.y))-height(xz+vec2f(0,step.y)))/(2*step.y)));\n if(frame.offset.w>0.5){let dimensions=vec2i(textureDimensions(normalMap));let uv=clamp((xz-frame.map.xy)/frame.map.zw,vec2f(0),vec2f(1));let sampled=textureLoad(normalMap,min(vec2i(uv*vec2f(dimensions)),dimensions-vec2i(1)),0).xyz*2-1;if(dot(sampled,sampled)>0.00001){normal=normalize(sampled);}}\n var o:Output;o.position=position;o.clip=frame.camera*vec4f(position,1);o.normal=normal;o.color=vec3f(1);o.material=vec4f(0.9,0,1,1);return o;\n}\n";
|
|
2
|
+
/**
|
|
3
|
+
* The heightmap covers `frame.map` (origin, size); the outer clipmap rings reach past it, where heights and weights are
|
|
4
|
+
* only the clamped edge texels (a flat shelf with stretched walls). Fragments there are dropped, so the sky shows past
|
|
5
|
+
* the terrain's edge (main drew that shelf to the horizon).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* `TerrainTextures.holes`, added after `terrainOutside` in every pass with a mask: the fragment's cell of the mask
|
|
9
|
+
* (its texels split the bounds evenly), dropped where R is below 0.5.
|
|
10
|
+
*/
|
|
11
|
+
export declare const terrainHole = "{let hd=vec2i(textureDimensions(terrainHoles));if(textureLoad(terrainHoles,clamp(vec2i(floor((i.position.xz-frame.map.xy)/frame.map.zw*vec2f(hd))),vec2i(0),hd-vec2i(1)),0).r<0.5){discard;}}";
|
|
12
|
+
export declare const terrainOutside = "if(any(i.position.xz<frame.map.xy)||any(i.position.xz>frame.map.xy+frame.map.zw)){discard;}";
|
|
13
|
+
/**
|
|
14
|
+
* `TerrainLayer.bump` and `macro`, compiled in only when some layer sets one (otherwise every shader is the text it was).
|
|
15
|
+
* Rules grow to 12 floats: `surface` is (bump height in metres per unit of luma, macro amount, macro texture scale, 0).
|
|
16
|
+
* `terrainSurface` takes a layer's triplanar colour and returns it scaled by the macro tone (`terrainMacro`, one
|
|
17
|
+
* triplanar axis at a time; the mean from the top mip keeps the average colour) with the bump height in w.
|
|
18
|
+
* `terrainMacro` is the layer at 1/24 of its scale, whose one repeat tiled into a grid a kilometre away (luma correlated
|
|
19
|
+
* 0.999 at the 96 m lag, test/bump.browser.mjs). A smooth coarse mip of the layer at a repeat 3.31 times longer varies the
|
|
20
|
+
* tone slowly and picks an offset for the repeat, two blended by its fraction: Quilez, "Texture Repetition", technique 3.
|
|
21
|
+
* Warping the coordinates instead drew wood grain, a finer second sample left the grid.
|
|
22
|
+
* `terrainBump` is Mikkelsen 2010, "Bump Mapping Unparametrized Surfaces on the GPU" (JGT 15(1)), listing 1: the
|
|
23
|
+
* surface gradient of that height from its screen-space derivatives and the position's, no extra texture samples. Each
|
|
24
|
+
* screen axis is first divided by its position derivative's length (the formula is homogeneous in each axis), so det
|
|
25
|
+
* is the sine-like measure of how far the two axes are from parallel in 3D: 1 on any surface seen squarely or at a
|
|
26
|
+
* grazing angle along a screen axis, near 0 only on slivers seen edge-on. There both axes sample nearly one direction
|
|
27
|
+
* on the surface, so the solve divides the height derivatives by det, and those carry errors (the 2x2 quad's helper
|
|
28
|
+
* lanes lie past the crest edge, where the vertex normal, the triplanar blend and the layer weights are extrapolated).
|
|
29
|
+
* The slope the gradient may give is therefore capped at min(1, 4 det), what the pixel can resolve. Uncapped, alpine
|
|
30
|
+
* crests under the noon sun got slopes of 1.5 to over 8 and drew dotted lines of near-black pixels
|
|
31
|
+
* (test/crest.browser.mjs: 21 specks against 0 without bump; capped, 0).
|
|
32
|
+
* A slope estimated across one pixel holds only what that pixel resolves: mips average the height, not its slope, and
|
|
33
|
+
* the relief is up to half a repeat high, so the estimate stayed large at every distance and drew pixel grain on far and
|
|
34
|
+
* grazing ground. Past a footprint of 1/64 of a repeat it falls with the longer side of the pixel on the ground.
|
|
35
|
+
* Magnified, the height holds nothing finer than 1/128 of a repeat (`terrainReliefLuma`): the layer's mip with 128
|
|
36
|
+
* texels a repeat through a cubic B-spline over 4 x 4 exact texel loads (the basis of Sigg and Hadwiger 2005, "Fast
|
|
37
|
+
* Third-Order Texture Filtering", GPU Gems 2 chapter 20, without their bilinear shortcut). A height read texel by texel
|
|
38
|
+
* through the sampler is texel noise times half a repeat (root mean square slopes of 1.2 on the biomes' tundra and 5.3
|
|
39
|
+
* on rock at 256 texels over 4 m), one slope a texel, and the hardware's rounded filter weights, which the screen
|
|
40
|
+
* derivative drew as black and white speckle, facets and dotted lines along texel edges (KB-TUNDRA-GROUNDNOISE1). The
|
|
41
|
+
* B-spline's slope is continuous and its weights exact. Between footprints of 1/128 and 1/64 of a repeat it hands over
|
|
42
|
+
* to the colour sample's own mip; past 1/64 the height is the colour sample's, as before.
|
|
43
|
+
*/
|
|
44
|
+
export declare const surfaceStruct: (code: string) => string;
|
|
45
|
+
/**
|
|
46
|
+
* `TerrainOptions.floatingOrigin`: positions reach the shaders local (world less the origin's shift), small enough for
|
|
47
|
+
* float32. Every layer sample that repeats with position (triplanar, macro, its 0.302 tone) adds the layer's `wrap`, the
|
|
48
|
+
* shift from the terrain's anchor less a whole number k of 24 / scale repeats per axis, and the tone adds
|
|
49
|
+
* `fract(k * 0.302)`: so each texture coordinate equals the terrain-relative one up to whole repeats, the same at any
|
|
50
|
+
* distance and across a rebase, and a terrain moved with its camera draws the same picture. `Frame.anchor` is
|
|
51
|
+
* (shift.x - origin.x, shift.z - origin.z, shift.y, 0): local + anchor.xy is the terrain-relative XZ that cache surfaces,
|
|
52
|
+
* overlays and imagery read. Applied once; the text without the option is unchanged.
|
|
53
|
+
*
|
|
54
|
+
* The lit draw also works relative to the eye (Cozzi and Ring 2011, "3D Engine Design for Virtual Globes", chapter 5,
|
|
55
|
+
* "Rendering relative to eye"; Ohlarik 2008, "Precisions, Precisions", AGI): local positions are whatever the origin's
|
|
56
|
+
* shift leaves them, so a rebase in place re-rounds every float32 number derived from them (the clip position, each
|
|
57
|
+
* texture coordinate and its screen derivatives), and the texture unit's sub-texel and level rounding, finer with 16x
|
|
58
|
+
* anisotropy, flipped 0.1 percent of pixels by one level (KB-TERRAIN-REBASEROUND1). The vertex writes `Output.eye`,
|
|
59
|
+
* the vertex less the eye, from `Frame.view` (the ring's lattice less the eye, and the eye's local Y, computed in
|
|
60
|
+
* float64 on the CPU) plus the ring-relative grid offset, and the clip position is `camera * (eye, 0)` plus
|
|
61
|
+
* `Frame.column` (the camera matrix times the local eye, float64): none of these depend on where the origin sits, so a
|
|
62
|
+
* rebase in place draws the same numbers. `eyeShader` reads the textures there.
|
|
63
|
+
*/
|
|
64
|
+
export declare const terrainClip = "o.clip=frame.camera*vec4f(position,1);";
|
|
65
|
+
/** The clip line of the floating-origin vertex (`originShader`): what `surface-height` replaces with its own. */
|
|
66
|
+
export declare const originClip = "let terrainE=frame.view.xy+aligned*frame.grid.z+frame.offset.xy*inner;o.eye=vec3f(terrainE.x,position.y-frame.view.z,terrainE.y);o.clip=frame.camera*vec4f(o.eye,0)+frame.column;";
|
|
67
|
+
export declare const originShader: (code: string) => string;
|
|
68
|
+
/** What an entry adds at its start to read the textures relative to the eye (`eyeShader`). */
|
|
69
|
+
export declare const eyeEntry = "terrainEyeOn=true;terrainEyeAt=i.eye;terrainEyeLocal=i.position;";
|
|
70
|
+
/**
|
|
71
|
+
* The floating-origin lit shader's last step, after every entry and effect has edited the text (so the text they look
|
|
72
|
+
* for is the one they always saw): each layer sample's point and screen derivatives come from `Output.eye`, the vertex
|
|
73
|
+
* less the eye, plus the layer's `eyeWrap` (the eye less the terrain's anchor less whole macro repeats, float64 on the
|
|
74
|
+
* CPU) and `eyeTone`, in place of the local position plus `wrap` and `tone`. A sample point that is not the fragment's
|
|
75
|
+
* own (a displaced one) keeps its offset from it. The same texel either way (the two differ by whole repeats); only
|
|
76
|
+
* the rounding no longer moves with the origin. Shaders without `eyeEntry` (the virtual texture's bake) keep the local
|
|
77
|
+
* reading. Applied once.
|
|
78
|
+
*/
|
|
79
|
+
export declare const eyeShader: (code: string) => string;
|
|
80
|
+
/**
|
|
81
|
+
* The fragment's shading normal `n` and layer colour `base` (the SSR capture entry starts the same way). With `rock`
|
|
82
|
+
* (`TerrainOptions.rock`) the normal first takes the rock structure and the colour its tone. The layer colour (its
|
|
83
|
+
* triplanar projections and slope rules) still reads the surface's own normal: the structure only shades. Picking the
|
|
84
|
+
* projections by the structure's normal laid a bench's near-level normal or a facet's tilt on a steep face, so the
|
|
85
|
+
* texture was projected along the face and drawn as streaks a few metres long down every rock wall
|
|
86
|
+
* (KB-TERRAIN-ROCKSMEAR1, Above the Treeline look round 10).
|
|
87
|
+
*/
|
|
88
|
+
export declare const terrainShading: (surface: boolean, rock?: boolean) => string;
|
|
89
|
+
/** `TerrainOptions.rock` resolved: every field set; `debris` -1 for none, `map` the structure texture's binding or -1. */
|
|
90
|
+
export interface RockShaderOptions {
|
|
91
|
+
readonly slope: readonly [number, number];
|
|
92
|
+
readonly strata: number;
|
|
93
|
+
readonly ledges: number;
|
|
94
|
+
readonly dip: readonly [number, number];
|
|
95
|
+
readonly facets: number;
|
|
96
|
+
readonly relief: number;
|
|
97
|
+
readonly gullies: number;
|
|
98
|
+
readonly tone: number;
|
|
99
|
+
readonly undulation: number;
|
|
100
|
+
readonly debris: number;
|
|
101
|
+
readonly map: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* `TerrainOptions.rock`: the structure of bare rock at 10 to 100 m, where a heightmap of 4 to 30 m cells draws a steep
|
|
105
|
+
* face as one smooth plane. All of it fades in with slope between `slope[0]` and `slope[1]` degrees and fades out where
|
|
106
|
+
* a pixel covers a good share of its feature, so far ground keeps its mean and nothing aliases.
|
|
107
|
+
* - Ledges: beds `strata` metres thick (planes tilted by `dip`, their heights warped by value noise so they wander and
|
|
108
|
+
* break off), each a riser and a bench. The shading normal takes the bench's or the riser's slope analytically: the
|
|
109
|
+
* height gradient times A = 0.25 on the top 30 percent of a bed and B = (1 - 0.3 A) / 0.7 below it, so the mean slope
|
|
110
|
+
* is the heightmap's (layered terrain of hard and soft beds: Benes and Forsbach 2001, "Layered data representation
|
|
111
|
+
* for visual simulation of terrain erosion", SCCG; Peytavie et al. 2009, "Arches: a framework for modeling complex
|
|
112
|
+
* terrains", Computer Graphics Forum 28(2)). Benches collect loose stone (`debris`) and each bed its own tone.
|
|
113
|
+
* - Facets: joint blocks `facets` metres across and 2.4 times as tall (the steep joint set of granite and gneiss makes
|
|
114
|
+
* ribs and columns), and buttresses 4.1 times that at 0.7 the strength, the nearest of the points scattered one to a
|
|
115
|
+
* cell over the 27 cells around the position
|
|
116
|
+
* (Worley 1996, "A cellular texture basis function", SIGGRAPH), each tilting the normal by up to `relief` in its own
|
|
117
|
+
* direction, with dark joints where the nearest two points are about equally near (F2 - F1). The tilt and tone blend
|
|
118
|
+
* into the second-nearest cell's across the edge (half each where F2 = F1, all the cell's own by F2 - F1 = 0.14 of a
|
|
119
|
+
* cell plus two pixels), so an edge is a rounded joint, never a hard switch; relief, tone and joint shade fall to 0.3
|
|
120
|
+
* as the pixel footprint grows from 0.006 to 0.04 of a block (about 170 to 25 pixels across it) and to none by 0.4,
|
|
121
|
+
* the prefiltering of normal detail with its footprint (Toksvig 2005; Bruneton and Neyret 2012), so blocks 200 to
|
|
122
|
+
* 600 m away do not read as low-poly shards (Above the Treeline look round 5).
|
|
123
|
+
* - Gullies: with `TerrainTextures.structure`, its R (drainage, 0 to 1) is carved `gullies` metres deep into the
|
|
124
|
+
* shading normal by its central differences, darkened as wet, shaded rock, and on gentler ground below the faces its
|
|
125
|
+
* floors and its G (debris fans) carry `debris`. `@margoengine/biomes/hydrology` `drainageStructure` makes one from
|
|
126
|
+
* multiple-flow routing (Freeman 1991) and rockfall travel (Statham 1976).
|
|
127
|
+
* - Undulation: on gentle ground (1 - the slope fade) three octaves of value noise, 48, 20 and 8 m, with heights
|
|
128
|
+
* `undulation` times 1, 0.45 and 0.2 (a fractal relief, amplitude about proportional to wavelength, as measured
|
|
129
|
+
* for natural terrain: Mark and Aronson 1984, "Scale-dependent fractal dimensions of topographic surfaces",
|
|
130
|
+
* Mathematical Geology 16(7); periglacial forms of 5 to 50 m: Ballantyne 2018, "Periglacial Geomorphology", Wiley),
|
|
131
|
+
* tilt the shading normal by their analytic gradient and shade hollows darker and crests lighter (up to 12 percent
|
|
132
|
+
* for the largest), each faded out between footprints of 0.05 and 0.25 of its wavelength (Norton, Rockwood and
|
|
133
|
+
* Skolmoski 1982, clamping), so far ground keeps its mean.
|
|
134
|
+
* The pcg3d hash is Jarzynski and Olano 2020, "Hash Functions for GPU Rendering", JCGT 9(3). With `floatingOrigin`
|
|
135
|
+
* every feature reads terrain-relative positions. Without the option the shader is unchanged.
|
|
136
|
+
*/
|
|
137
|
+
export declare const rockFunctions: (o: RockShaderOptions) => string;
|
|
138
|
+
/** The rule-weighted fragment shader; `surface` adds `TerrainLayer.bump` and `macro`. A function, so a bundle that
|
|
139
|
+
* never draws a terrain keeps no shader text. */
|
|
140
|
+
export declare const terrainFragment: (surface?: boolean, rock?: RockShaderOptions) => string;
|
|
141
|
+
/**
|
|
142
|
+
* `TerrainOptions.patches`: the painted weights resolved into patches with crisp edges, as alpine ground is turf, scree
|
|
143
|
+
* and rock side by side rather than their average. Each layer whose weight is above 0 gets a height, `contrast` times a
|
|
144
|
+
* value-noise fBm of its own (cells of `size` metres, three octaves, quintic fade, Perlin 2002 "Improving Noise",
|
|
145
|
+
* SIGGRAPH; cell values from the pcg3d hash of Jarzynski and Olano 2020, "Hash Functions for GPU Rendering", JCGT 9(3)),
|
|
146
|
+
* added to its weight; only the layers within 0.05 x contrast of the highest sum keep weight, by how far they reach
|
|
147
|
+
* past that line (height-based splatting: Mishkinis 2013, "Advanced Terrain Texture Splatting", Gamasutra; noise-masked
|
|
148
|
+
* splats as in Andersson 2007, "Terrain Rendering in Frostbite Using Procedural Shader Splatting", SIGGRAPH course).
|
|
149
|
+
* Weights of 1 and 0 stay as painted. Octaves finer than half a pixel's footprint fade to their mean, and the patched
|
|
150
|
+
* weights hand back to the painted ones as the footprint grows from 0.3 to 0.8 of a cell, so far ground neither
|
|
151
|
+
* aliases nor turns into the strongest layer alone. With `floatingOrigin` the noise reads terrain-relative positions.
|
|
152
|
+
* `warp` displaces the noise's coordinates by a value-noise field of 2.6 `size` cells, up to 1.1 `warp` `size` each way
|
|
153
|
+
* (domain distortion: Perlin 1985, "An image synthesizer", SIGGRAPH; Ebert, Musgrave et al. 2003, "Texturing and
|
|
154
|
+
* Modeling: A Procedural Approach", ch. 16), and adds an octave of 3.3 `size` cells, so patches come in clusters and
|
|
155
|
+
* strands of several sizes instead of one blob size. `terraces` adds to each layer a sine of the height, `terraces`
|
|
156
|
+
* metres a cycle with its phase wandering by noise and shifted per layer: patches stretch along the contours, as turf
|
|
157
|
+
* banks and gravel strips do on a grazed or frost-heaved slope. Only on slopes of about 10 to 35 degrees, in stretches
|
|
158
|
+
* that come and go (a noise of 14 cycles), and it fades where a cycle covers under about 3 pixels.
|
|
159
|
+
*/
|
|
160
|
+
/** `TerrainOptions.patches` resolved: every field set (`warp` 0 and `terraces` 0 draw the plain patches). */
|
|
161
|
+
export interface PatchShaderOptions {
|
|
162
|
+
readonly size: number;
|
|
163
|
+
readonly contrast: number;
|
|
164
|
+
readonly warp: number;
|
|
165
|
+
readonly terraces: number;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The fragment shader with `TerrainTextures.weights` (`count` textures, 2 to 4): layer i's weight is channel i % 4 of
|
|
169
|
+
* weight texture i / 4, sampled bilinearly once per fragment over the heightmap's bounds, in place of the height and
|
|
170
|
+
* slope rules (which still set each layer's texture scale). A layer whose weight is 0 skips its three triplanar
|
|
171
|
+
* samples, so 16 layers cost what the ones that show do; the colour is the same as sampling every layer. With `tint`
|
|
172
|
+
* (`TerrainTextures.tint`, bound after the weights), each layer whose rule has params.w 1 is mixed toward the tint
|
|
173
|
+
* texel's RGB by its A before relief and macro tone. A function, so importing anything else from this package keeps no
|
|
174
|
+
* shader text.
|
|
175
|
+
*/
|
|
176
|
+
export declare const weightedFragment: (count: number, surface?: boolean, tint?: boolean, patches?: PatchShaderOptions, rock?: RockShaderOptions) => string;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** A colour value: linear RGB. */
|
|
2
|
+
export type SettingColor = readonly [number, number, number];
|
|
3
|
+
/** One gradient stop: a colour at a position (`elevation` unless the row's `stopKey` says otherwise). */
|
|
4
|
+
export type SettingStop = { readonly color: SettingColor };
|
|
5
|
+
/** One value of a setting: a number, a colour, a choice, gradient stops, or null where `nullable`. */
|
|
6
|
+
export type SettingValue = number | SettingColor | string | readonly SettingStop[] | null;
|
|
7
|
+
/** Values by setting name; a name left out takes its default. */
|
|
8
|
+
export type SettingValues = Readonly<Record<string, SettingValue>>;
|
|
9
|
+
/** One slider row, the shape every package's `/settings` entry shares. */
|
|
10
|
+
export interface SettingRow {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly group: string;
|
|
13
|
+
/** `number` is a slider, `color` three sliders or a picker, `choice` a list, `gradient` a stop editor. */
|
|
14
|
+
readonly kind: 'number' | 'color' | 'choice' | 'gradient';
|
|
15
|
+
/** The value with which the target draws exactly as it does without the option (null: follow the weather). */
|
|
16
|
+
readonly default: SettingValue;
|
|
17
|
+
readonly min?: number;
|
|
18
|
+
readonly max?: number;
|
|
19
|
+
readonly step?: number;
|
|
20
|
+
readonly choices?: readonly string[];
|
|
21
|
+
/** May be null: the target uses its own value, or follows the weather when `weather` is set. */
|
|
22
|
+
readonly nullable?: boolean;
|
|
23
|
+
/** The weather master slider that drives this row while it is null. */
|
|
24
|
+
readonly weather?: string;
|
|
25
|
+
/** The key a gradient stop is placed by (default `elevation`). */
|
|
26
|
+
readonly stopKey?: string;
|
|
27
|
+
readonly unit: string;
|
|
28
|
+
readonly about: string;
|
|
29
|
+
/** True: cheap to write every frame (no pipeline, buffer or texture is created), so it can be keyed over a shot. False: writing it rebuilds something. */
|
|
30
|
+
readonly live: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare const numberSetting: (
|
|
33
|
+
name: string,
|
|
34
|
+
group: string,
|
|
35
|
+
value: number,
|
|
36
|
+
min: number,
|
|
37
|
+
max: number,
|
|
38
|
+
step: number,
|
|
39
|
+
unit: string,
|
|
40
|
+
about: string,
|
|
41
|
+
live?: boolean,
|
|
42
|
+
) => SettingRow;
|
|
43
|
+
export declare const colorSetting: (
|
|
44
|
+
name: string,
|
|
45
|
+
group: string,
|
|
46
|
+
value: SettingColor,
|
|
47
|
+
min: number,
|
|
48
|
+
max: number,
|
|
49
|
+
about: string,
|
|
50
|
+
live?: boolean,
|
|
51
|
+
) => SettingRow;
|
|
52
|
+
export declare const choiceSetting: (
|
|
53
|
+
name: string,
|
|
54
|
+
group: string,
|
|
55
|
+
choices: readonly string[],
|
|
56
|
+
about: string,
|
|
57
|
+
live?: boolean,
|
|
58
|
+
) => SettingRow;
|
|
59
|
+
/** The row with a null default that follows the weather master slider `weather` until a value is given. */
|
|
60
|
+
export declare const followsWeather: (row: SettingRow, weather: string) => SettingRow;
|
|
61
|
+
/** Marks `key` of `target` as set by hand (`held` true) or hands it back to the weather (false). */
|
|
62
|
+
export declare function holdFromWeather(target: object, key: string, held?: boolean): void;
|
|
63
|
+
/** True while `key` of `target` holds a value set by hand, which the weather drive leaves alone. */
|
|
64
|
+
export declare const heldFromWeather: (target: object, key: string) => boolean;
|
|
65
|
+
export declare const sameSettingValue: (a: unknown, b: unknown) => boolean;
|
|
66
|
+
export declare function copySettingValue(v: SettingValue): SettingValue;
|
|
67
|
+
/** A fresh object holding every row at its default (a slider panel's state). */
|
|
68
|
+
export declare function settingDefaults(rows: readonly SettingRow[]): Record<string, SettingValue>;
|
|
69
|
+
/** The rows that may change every frame without a rebuild. */
|
|
70
|
+
export declare const liveSettings: (rows: readonly SettingRow[]) => SettingRow[];
|
|
71
|
+
/** A name to row map. */
|
|
72
|
+
export declare const settingIndex: (rows: readonly SettingRow[]) => Map<string, SettingRow>;
|
|
73
|
+
/** @throws RangeError when `v` is not a value of `row`. */
|
|
74
|
+
export declare function checkSettingValue(row: SettingRow, v: unknown, label: string): void;
|
|
75
|
+
/** @throws TypeError for an unknown name; RangeError for a bad value or a null on a row that is not nullable. */
|
|
76
|
+
export declare function checkSettings(
|
|
77
|
+
rows: readonly SettingRow[] | ReadonlyMap<string, SettingRow>,
|
|
78
|
+
values: SettingValues,
|
|
79
|
+
label: string,
|
|
80
|
+
entry?: string,
|
|
81
|
+
): void;
|
|
82
|
+
/** Checks `values`, then calls `write` once per row (or per row `only` accepts) with the given value or the default. */
|
|
83
|
+
export declare function applySettings(
|
|
84
|
+
rows: readonly SettingRow[],
|
|
85
|
+
values: SettingValues,
|
|
86
|
+
label: string,
|
|
87
|
+
write: (row: SettingRow, value: SettingValue) => void,
|
|
88
|
+
only?: (row: SettingRow) => boolean,
|
|
89
|
+
): void;
|