@yali-engine/water 0.0.0-stage → 0.12.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.
@@ -0,0 +1,137 @@
1
+ import type { FrameGraph, PipelineCache, RenderFeature, RenderFeatureFactory, RenderFeatureFrame, SceneRenderer } from '@yali-engine/render';
2
+ import { type Seabed, type ShoreField } from './shore.ts';
3
+ import { WaterWaves, type WaterWavesOptions } from './waves.ts';
4
+ /** The ocean's knobs. */
5
+ export interface WaterOptions extends WaterWavesOptions {
6
+ /** The sea's mean level, world metres (default 0). */
7
+ readonly level?: number;
8
+ /** Rings and segments of the surface's grid (defaults 240 × 384: 184,320 triangles out to ~9 km). */
9
+ readonly rings?: number;
10
+ readonly segments?: number;
11
+ /** The Jacobian below which foam starts (default 0.6; lower: less foam), and foam's strength (default 1). */
12
+ readonly foamThreshold?: number;
13
+ readonly foam?: number;
14
+ /** The water body's scattering colour (linear; default a deep teal-blue) and calm water's roughness (default 0.04). */
15
+ readonly bodyColor?: readonly [number, number, number];
16
+ readonly roughness?: number;
17
+ /** The colour of light through a crest (linear) and its strength (defaults a green-cyan, 0.5). */
18
+ readonly subsurfaceColor?: readonly [number, number, number];
19
+ readonly subsurface?: number;
20
+ /** The water's absorption per metre, red green blue (default coastal seawater: red gone in ~2 m, blue in ~20). */
21
+ readonly absorption?: readonly [number, number, number];
22
+ /** How far the refraction bends the view, pixels at a metre of water (default 60). */
23
+ readonly refraction?: number;
24
+ /** Water shallower than this foams at a shore, metres (default 0.12). */
25
+ readonly shoreFoam?: number;
26
+ /** The quality tier (ADR-0220, default 'high'): see `Water.quality`. */
27
+ readonly quality?: WaterQuality;
28
+ /** How far the mirror ray is marched for reflections of the scene, metres (default 40; 0: the sky only), and its steps (24). */
29
+ readonly reflections?: number;
30
+ readonly reflectionSteps?: number;
31
+ /**
32
+ * The surf on a shore (ADR-0213), once `setSeabed` gives the water its seabed: its height in deep water (m, default 0.9),
33
+ * period (s, 8), breaking ratio γ (0.78), how far crests lean before breaking (0.55), the depth it rises out of the sea
34
+ * at (7 m) and the depth over which the open sea's waves calm (4 m).
35
+ */
36
+ readonly surf?: {
37
+ readonly height?: number;
38
+ readonly period?: number;
39
+ readonly breaking?: number;
40
+ readonly lean?: number;
41
+ readonly start?: number;
42
+ readonly calm?: number;
43
+ readonly variety?: number;
44
+ readonly lip?: number;
45
+ readonly spray?: number;
46
+ };
47
+ }
48
+ /** How much the water may cost (ADR-0220): the iGPU target is `medium` or `low` (≤ 2.5 ms, water research §1.1). */
49
+ export type WaterQuality = 'high' | 'medium' | 'low';
50
+ /**
51
+ * An ocean (ADR-0198): FFT waves (JONSWAP, Donelan–Banner) on a radial grid to the horizon, lit by the scene's sky, sun and
52
+ * fog. WebGPU with HDR only.
53
+ *
54
+ * @example
55
+ * import { water } from '@yali-engine/water';
56
+ * renderPlugin({ canvas, sky: { model: 'atmosphere' }, post: { passes: postPasses, taa: true }, features: [water({ wind: 12 })] });
57
+ */
58
+ export declare function water(o?: WaterOptions): RenderFeatureFactory;
59
+ export declare class Water implements RenderFeature {
60
+ #private;
61
+ readonly name = "water";
62
+ readonly device: GPUDevice;
63
+ readonly waves: WaterWaves;
64
+ /** Live knobs. */
65
+ level: number;
66
+ foamThreshold: number;
67
+ foam: number;
68
+ bodyColor: [number, number, number];
69
+ roughness: number;
70
+ subsurfaceColor: [number, number, number];
71
+ subsurface: number;
72
+ absorption: [number, number, number];
73
+ refraction: number;
74
+ shoreFoam: number;
75
+ reflections: number;
76
+ reflectionSteps: number;
77
+ /** Holds the waves at this time, seconds (live; null: they follow the app's clock). For stills and A/B checks. */
78
+ frozenAt: number | null;
79
+ /** A debug view: only the scene the reflections found (red where none). */
80
+ debugMirror: boolean;
81
+ /** Off: nothing is drawn or computed (live). */
82
+ enabled: boolean;
83
+ /** The waves' own motion for TAA (ADR-0210; live): off, TAA sees the surface as still (the camera's motion only). */
84
+ motion: boolean;
85
+ /** The surf's height in deep water, metres (ADR-0213; live). */
86
+ surfHeight: number;
87
+ /** The breaking ratio γ: a wave breaks when it is taller than γ × the depth (0.78, live). */
88
+ surfBreaking: number;
89
+ /** How far crests lean shoreward before they break (Gerstner's Q, 0–1, live). */
90
+ surfLean: number;
91
+ /** The depth (m) at which the surf rises out of the sea, and over which the open sea's waves calm (live). */
92
+ surfStart: number;
93
+ surfCalm: number;
94
+ /** The surf's period, seconds: set before `setSeabed` (the crests' phase is baked for it). */
95
+ surfPeriod: number;
96
+ /**
97
+ * How much waves differ (ADR-0218; live, 0–1): 1 = swell in sets, each crest's height varying along the shore so it breaks
98
+ * in sections; 0 = every wave alike.
99
+ */
100
+ surfVariety: number;
101
+ /** How far a crest that starts to break throws its lip forward (ADR-0218; live, 0–1). */
102
+ surfLip: number;
103
+ /** Spray thrown up by breaking waves (ADR-0218; live, 0 = none, 1 = default). */
104
+ spray: number;
105
+ /**
106
+ * The quality tier (ADR-0220; live): `high` everything; `medium` the coarse foam pattern only, 16 reflection steps, half
107
+ * the spray; `low` no caustics, no scene reflections, no spray. Setting it sets those knobs (they stay live after).
108
+ */
109
+ get quality(): WaterQuality;
110
+ set quality(q: WaterQuality);
111
+ readonly rings: number;
112
+ readonly segments: number;
113
+ constructor(device: GPUDevice, o: WaterOptions);
114
+ init(cache: PipelineCache, format: GPUTextureFormat): Promise<void>;
115
+ prepare(f: RenderFeatureFrame): void;
116
+ /**
117
+ * The seabed under the water (ADR-0213): bakes the shore field (`bakeShore`: depth, the crests' arrival phase for
118
+ * `surfPeriod`, their direction) and uploads it; the surf then rises, bends to the beach and breaks. Call again after
119
+ * changing `surfPeriod` or the seabed.
120
+ *
121
+ * @example
122
+ * ocean.setSeabed({ heights, size: 256, cell: 1, origin: [-128, -198] });
123
+ */
124
+ setSeabed(seabed: Seabed): ShoreField;
125
+ /** The baked shore field, or null before `setSeabed`. */
126
+ get shoreField(): ShoreField | null;
127
+ addMotionPasses(graph: FrameGraph, motion: string, depth: string): void;
128
+ addPasses(graph: FrameGraph, color: string, depth: string, scene: SceneRenderer): void;
129
+ /**
130
+ * Its agent tools (ADR-0204): `water.state` reads the sea, `water.set` turns its knobs, `water.sea` makes a new sea.
131
+ * Errors carry the argument's `path`.
132
+ */
133
+ tools(): ReturnType<NonNullable<RenderFeature['tools']>>;
134
+ /** What the sea holds on the GPU (its waves; the surface has no buffers). */
135
+ get gpuBytes(): number;
136
+ destroy(): void;
137
+ }