@yali-engine/water 0.11.0 → 0.13.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/dist/water.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { FrameGraph, PipelineCache, RenderFeature, RenderFeatureFactory, RenderFeatureFrame, SceneRenderer } from '@yali-engine/render';
2
+ import { type Seabed, type ShoreField } from './shore.ts';
2
3
  import { WaterWaves, type WaterWavesOptions } from './waves.ts';
3
4
  /** The ocean's knobs. */
4
5
  export interface WaterOptions extends WaterWavesOptions {
@@ -22,10 +23,30 @@ export interface WaterOptions extends WaterWavesOptions {
22
23
  readonly refraction?: number;
23
24
  /** Water shallower than this foams at a shore, metres (default 0.12). */
24
25
  readonly shoreFoam?: number;
26
+ /** The quality tier (ADR-0220, default 'high'): see `Water.quality`. */
27
+ readonly quality?: WaterQuality;
25
28
  /** How far the mirror ray is marched for reflections of the scene, metres (default 40; 0: the sky only), and its steps (24). */
26
29
  readonly reflections?: number;
27
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
+ };
28
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';
29
50
  /**
30
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
31
52
  * fog. WebGPU with HDR only.
@@ -59,12 +80,68 @@ export declare class Water implements RenderFeature {
59
80
  debugMirror: boolean;
60
81
  /** Off: nothing is drawn or computed (live). */
61
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
+ /** The ripples finer than the cascades (ADR-0223; live, 0 none, 1 Cox & Munk's slope for the wind). */
106
+ ripples: number;
107
+ /**
108
+ * The quality tier (ADR-0220; live): `high` everything; `medium` the coarse foam pattern only, 16 reflection steps, half
109
+ * the spray; `low` no caustics, no scene reflections, no spray. Setting it sets those knobs (they stay live after).
110
+ */
111
+ get quality(): WaterQuality;
112
+ set quality(q: WaterQuality);
62
113
  readonly rings: number;
63
114
  readonly segments: number;
64
115
  constructor(device: GPUDevice, o: WaterOptions);
65
116
  init(cache: PipelineCache, format: GPUTextureFormat): Promise<void>;
66
117
  prepare(f: RenderFeatureFrame): void;
118
+ /**
119
+ * The surf field's GPU cost, ms a frame (ADR-0223): one submission of `frames` + 1 dispatches less one of 1, over
120
+ * `frames`, each timed to `onSubmittedWorkDone` (the render loop's own frames land in either window, and the difference
121
+ * cancels them; the field runs in its own submission, which the frame graph's timers do not see). Null without a seabed.
122
+ *
123
+ * @example
124
+ * const ms = await ocean.measureSurf();
125
+ */
126
+ measureSurf(frames?: number): Promise<number | null>;
127
+ /**
128
+ * The seabed under the water (ADR-0213): bakes the shore field (`bakeShore`: depth, the crests' arrival phase for
129
+ * `surfPeriod`, their direction) and uploads it; the surf then rises, bends to the beach and breaks. Call again after
130
+ * changing `surfPeriod` or the seabed.
131
+ *
132
+ * @example
133
+ * ocean.setSeabed({ heights, size: 256, cell: 1, origin: [-128, -198] });
134
+ */
135
+ setSeabed(seabed: Seabed): ShoreField;
136
+ /** The baked shore field, or null before `setSeabed`. */
137
+ get shoreField(): ShoreField | null;
138
+ addMotionPasses(graph: FrameGraph, motion: string, depth: string): void;
67
139
  addPasses(graph: FrameGraph, color: string, depth: string, scene: SceneRenderer): void;
140
+ /**
141
+ * Its agent tools (ADR-0204): `water.state` reads the sea, `water.set` turns its knobs, `water.sea` makes a new sea.
142
+ * Errors carry the argument's `path`.
143
+ */
144
+ tools(): ReturnType<NonNullable<RenderFeature['tools']>>;
68
145
  /** What the sea holds on the GPU (its waves; the surface has no buffers). */
69
146
  get gpuBytes(): number;
70
147
  destroy(): void;