@margoengine/terrain 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +1808 -3
- package/dist/blend.d.ts +70 -0
- package/dist/blend.js +159 -0
- package/dist/colors.d.ts +164 -0
- package/dist/deform.d.ts +103 -0
- package/dist/deform.js +322 -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/errors-fc4i1pSL.js +7 -0
- package/dist/grid.d.ts +11 -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 +1291 -0
- package/dist/ground-model.d.ts +290 -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 +297 -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-craters.d.ts +55 -0
- package/dist/planet-recipes.d.ts +75 -0
- package/dist/planet-recipes.js +216 -0
- package/dist/planet.d.ts +139 -0
- package/dist/planet.js +602 -0
- package/dist/query.d.ts +150 -0
- package/dist/query.js +243 -0
- package/dist/relief-lighting.d.ts +46 -0
- package/dist/relief-lighting.js +208 -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 +111 -0
- package/dist/rock-surface.js +368 -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/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 +61 -0
- package/dist/shared/settings.d.ts +89 -0
- package/dist/src-C6dtSaAb.js +1155 -0
- package/dist/stream.d.ts +100 -0
- package/dist/stream.js +339 -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 +148 -6
package/dist/shader.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export declare const terrainVertex = "\nstruct Frame {camera:mat4x4f,eye:vec4f,light:vec4f,radiance:vec4f,grid:vec4f,offset:vec4f,map:vec4f,heights: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}\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 let edge=max(abs(grid.x),abs(grid.y));let morph=clamp((edge-frame.grid.w*0.5+2)/2,0.0,1.0);\n let aligned=mix(grid,round(grid*0.5)*2,morph);let inner=clamp((frame.grid.w*0.5-edge)/(frame.grid.w*0.25),0.0,1.0);\n let xz=frame.grid.xy+aligned*frame.grid.z+frame.offset.xy*inner;let position=vec3f(xz.x,height(xz),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
|
+
*/
|
|
36
|
+
export declare const surfaceStruct: (code: string) => string;
|
|
37
|
+
/**
|
|
38
|
+
* `TerrainOptions.floatingOrigin`: positions reach the shaders local (world less the origin's shift), small enough for
|
|
39
|
+
* float32. Every layer sample that repeats with position (triplanar, macro, its 0.302 tone) adds the layer's `wrap`, the
|
|
40
|
+
* shift from the terrain's anchor less a whole number k of 24 / scale repeats per axis, and the tone adds
|
|
41
|
+
* `fract(k * 0.302)`: so each texture coordinate equals the terrain-relative one up to whole repeats, the same at any
|
|
42
|
+
* distance and across a rebase, and a terrain moved with its camera draws the same picture. `Frame.anchor` is
|
|
43
|
+
* (shift.x - origin.x, shift.z - origin.z, shift.y, 0): local + anchor.xy is the terrain-relative XZ that cache surfaces,
|
|
44
|
+
* overlays and imagery read. Applied once; the text without the option is unchanged.
|
|
45
|
+
*/
|
|
46
|
+
export declare const originShader: (code: string) => string;
|
|
47
|
+
/** The fragment's shading normal `n` and layer colour `base` (the SSR capture entry starts the same way). */
|
|
48
|
+
export declare const terrainShading: (surface: boolean) => string;
|
|
49
|
+
/** The rule-weighted fragment shader; `surface` adds `TerrainLayer.bump` and `macro`. A function, so a bundle that
|
|
50
|
+
* never draws a terrain keeps no shader text. */
|
|
51
|
+
export declare const terrainFragment: (surface?: boolean) => string;
|
|
52
|
+
/**
|
|
53
|
+
* The fragment shader with `TerrainTextures.weights` (`count` textures, 2 to 4): layer i's weight is channel i % 4 of
|
|
54
|
+
* weight texture i / 4, sampled bilinearly once per fragment over the heightmap's bounds, in place of the height and
|
|
55
|
+
* slope rules (which still set each layer's texture scale). A layer whose weight is 0 skips its three triplanar
|
|
56
|
+
* samples, so 16 layers cost what the ones that show do; the colour is the same as sampling every layer. With `tint`
|
|
57
|
+
* (`TerrainTextures.tint`, bound after the weights), each layer whose rule has params.w 1 is mixed toward the tint
|
|
58
|
+
* texel's RGB by its A before relief and macro tone. A function, so importing anything else from this package keeps no
|
|
59
|
+
* shader text.
|
|
60
|
+
*/
|
|
61
|
+
export declare const weightedFragment: (count: number, surface?: boolean, tint?: boolean) => 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;
|