@threenative/core 0.3.3 → 0.3.5
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/capabilities.json +2019 -59
- package/dist/{assets-CYKk2WTu.d.ts → assets-CqvE429w.d.ts} +45 -3
- package/dist/{audio-7i3Xl0l3.d.ts → audio-DIJE5HTr.d.ts} +43 -3
- package/dist/{canvas-layer-C1SnMoJ-.d.ts → canvas-layer-C1-5CviZ.d.ts} +5 -1
- package/dist/{game-D_6r-k4Y.d.ts → game-Bj8G1wmD.d.ts} +242 -17
- package/dist/hot.d.ts +5 -5
- package/dist/index.d.ts +1131 -105
- package/dist/index.js +15201 -4782
- package/dist/model-lod-BDAUYgsS.d.ts +197 -0
- package/dist/playtest.d.ts +6 -4
- package/dist/playtest.js +84 -11
- package/dist/react-css.d.ts +62 -0
- package/dist/react-css.js +591 -0
- package/dist/react.d.ts +2 -2
- package/dist/{renderer-Cy4qeBOA.d.ts → renderer-9yEo9hPa.d.ts} +676 -21
- package/dist/terrain-jobs-worker.d.ts +2 -0
- package/dist/terrain-jobs-worker.js +130 -0
- package/dist/ui-layer.d.ts +5 -3
- package/dist/ui-layer.js +59 -8
- package/dist/world.d.ts +1596 -17
- package/dist/world.js +17035 -521
- package/gpl/fixtures/make_world_fixture.py +184 -0
- package/gpl/recipes/_common.py +11 -0
- package/gpl/recipes/decimate.py +11 -5
- package/gpl/recipes/export_world.py +699 -0
- package/mcp/blender-server.mjs +61 -4
- package/mcp/blender.mjs +3 -4
- package/mcp/engine-server.mjs +55 -21
- package/mcp/servers.mjs +4 -4
- package/package.json +15 -9
- package/patches/three@0.185.1-prd269-upgrade.patch +22418 -0
- package/patches/three@0.185.1.patch +8246 -389
- package/scripts/apply-three-patch.mjs +123 -41
- package/src/animation-blend.ts +264 -0
- package/src/animation-composition.ts +362 -0
- package/src/animation-layers.ts +260 -0
- package/src/animation-root-motion.ts +283 -0
- package/src/animation.ts +896 -0
- package/src/assets.ts +1303 -0
- package/src/atmosphere/index.ts +335 -0
- package/src/atmosphere/luts.ts +298 -0
- package/src/atmosphere/params.ts +323 -0
- package/src/audio.ts +912 -0
- package/src/billboard.ts +124 -0
- package/src/bone-lengths.ts +157 -0
- package/src/camera-shake.ts +116 -0
- package/src/canvas-layer.ts +47 -0
- package/src/clip-audit.ts +401 -0
- package/src/clustered-batch.ts +492 -0
- package/src/clustered-mesh.ts +638 -0
- package/src/compute-driven.ts +176 -0
- package/src/compute-timing.ts +318 -0
- package/src/config.ts +593 -0
- package/src/debug.ts +82 -0
- package/src/engine-render-hook.ts +25 -0
- package/src/entities.ts +79 -0
- package/src/entity-snapshot.ts +53 -0
- package/src/flight.ts +683 -0
- package/src/fluid-field.ts +748 -0
- package/src/fluid-particles.ts +1253 -0
- package/src/frame-budget.ts +1368 -0
- package/src/game.ts +2390 -0
- package/src/geometry-capture.ts +1098 -0
- package/src/gpu-class.ts +160 -0
- package/src/gpu-frame-observation.ts +424 -0
- package/src/gpu-readback.ts +143 -0
- package/src/gpu-scene-bvh.ts +464 -0
- package/src/grounding.ts +100 -0
- package/src/hot.ts +161 -0
- package/src/import-meta.d.ts +13 -0
- package/src/index.ts +1536 -0
- package/src/input.ts +690 -0
- package/src/instanced-batch-lod.ts +283 -0
- package/src/instanced-batch.ts +274 -0
- package/src/interpolation.ts +129 -0
- package/src/launch-diagnostics.ts +161 -0
- package/src/loop.ts +564 -0
- package/src/matrix-world.ts +245 -0
- package/src/merge-parts.ts +812 -0
- package/src/model-lod.ts +1315 -0
- package/src/net-protocol.ts +333 -0
- package/src/net-session.ts +477 -0
- package/src/net.ts +80 -0
- package/src/ocean/fft.ts +72 -0
- package/src/ocean/spectral.ts +728 -0
- package/src/particle-significance.ts +102 -0
- package/src/particles.ts +648 -0
- package/src/path-follow.ts +175 -0
- package/src/picking.ts +250 -0
- package/src/pipeline-census.ts +1566 -0
- package/src/platform.ts +210 -0
- package/src/playtest.ts +839 -0
- package/src/pointer-events.ts +411 -0
- package/src/pose-measure.ts +435 -0
- package/src/profiling/FrameCounters.ts +231 -0
- package/src/profiling/Spans.ts +548 -0
- package/src/profiling/opacity-convention.ts +21 -0
- package/src/profiling/render-list-validate.ts +175 -0
- package/src/profiling/render-trap-audit.ts +84 -0
- package/src/profiling/scene-warning.ts +190 -0
- package/src/profiling/span-probes.ts +191 -0
- package/src/profiling/unlit-foliage-warning.ts +149 -0
- package/src/projection-apply.ts +1529 -0
- package/src/projection-marker.ts +142 -0
- package/src/projection-plan.ts +1258 -0
- package/src/projection-skinned.ts +419 -0
- package/src/projection-stability.ts +409 -0
- package/src/projection-uniform.ts +328 -0
- package/src/random.ts +41 -0
- package/src/react-css.ts +604 -0
- package/src/react-glyphs.ts +114 -0
- package/src/react-host.ts +576 -0
- package/src/react-layout.ts +265 -0
- package/src/react.ts +60 -0
- package/src/render/alpha-antialiasing.ts +159 -0
- package/src/render/batched-velocity.ts +126 -0
- package/src/render/chain.ts +1021 -0
- package/src/render/daylight.ts +189 -0
- package/src/render/depth-pyramid.ts +596 -0
- package/src/render/foliage-alpha.ts +166 -0
- package/src/render/material-key.ts +60 -0
- package/src/render/mesh-pool.ts +144 -0
- package/src/render/probe-volume.ts +1668 -0
- package/src/render/resolution-subrect.ts +253 -0
- package/src/render/velocity.ts +442 -0
- package/src/render/virtual-shadow-pages.ts +827 -0
- package/src/render/virtual-shadow-partial.ts +174 -0
- package/src/render/virtual-shadow.ts +3330 -0
- package/src/render/world-impostor-surface.ts +722 -0
- package/src/render/world-impostor.ts +558 -0
- package/src/render-camera-cull.ts +441 -0
- package/src/render-pass-budget.ts +501 -0
- package/src/renderProjection.ts +758 -0
- package/src/renderer-config.ts +127 -0
- package/src/renderer.ts +1847 -0
- package/src/replay-protocol.ts +85 -0
- package/src/replay.ts +205 -0
- package/src/resolution-scaler.ts +819 -0
- package/src/rig-preparation.ts +271 -0
- package/src/ripple-field.ts +432 -0
- package/src/scale.ts +109 -0
- package/src/scene.ts +239 -0
- package/src/schedule.ts +155 -0
- package/src/skeletal-mesh.ts +61 -0
- package/src/skeleton.ts +100 -0
- package/src/snow-field.ts +744 -0
- package/src/softbody-topology.ts +269 -0
- package/src/softbody.ts +516 -0
- package/src/sprite-animator.ts +222 -0
- package/src/startup-readiness.ts +386 -0
- package/src/state.ts +66 -0
- package/src/static-transform.ts +274 -0
- package/src/storage-buffer.ts +253 -0
- package/src/streaming.ts +308 -0
- package/src/target-fps.ts +92 -0
- package/src/terrain-jobs-worker.ts +17 -0
- package/src/terrain-jobs.ts +353 -0
- package/src/textures.ts +39 -0
- package/src/tracers.ts +237 -0
- package/src/ui-bridge.ts +368 -0
- package/src/ui-hit-regions.ts +380 -0
- package/src/ui-layer.ts +83 -0
- package/src/ui-state.ts +220 -0
- package/src/version.ts +2 -0
- package/src/viewport.ts +253 -0
- package/src/warmup.ts +1357 -0
- package/src/water-surface.ts +384 -0
- package/src/wave-field.ts +524 -0
- package/src/world-capabilities.ts +131 -0
- package/src/world-cell-proxy.ts +392 -0
- package/src/world-cells.ts +10564 -0
- package/src/world-gpu-scene.ts +3354 -0
- package/src/world-heightmap.ts +82 -0
- package/src/world-package.ts +469 -0
- package/src/world-passes.ts +582 -0
- package/src/world-region.ts +17 -0
- package/src/world-terrain-splat.ts +564 -0
- package/src/world-tiles.ts +3826 -0
- package/src/world-topology.ts +370 -0
- package/src/world-validate.ts +48 -0
- package/src/world.ts +805 -0
- package/dist/gpu-readback-CMklJs6r.d.ts +0 -112
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
import { Vector3 } from "three";
|
|
2
|
+
import { Fn, cos, float, normalize, positionLocal, sin, uniform, vec2, vec3 } from "three/tsl";
|
|
3
|
+
import type { Node } from "three/webgpu";
|
|
4
|
+
|
|
5
|
+
export type WaveDirection =
|
|
6
|
+
| readonly [number, number]
|
|
7
|
+
| { readonly x: number; readonly z?: number; readonly y?: number };
|
|
8
|
+
|
|
9
|
+
export interface IWaveFieldWave {
|
|
10
|
+
readonly amplitude?: number;
|
|
11
|
+
readonly direction: WaveDirection;
|
|
12
|
+
readonly wavelength: number;
|
|
13
|
+
readonly speed: number;
|
|
14
|
+
readonly phase?: number;
|
|
15
|
+
readonly steepness?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Mark this wave as detail: the graph fades it out with the `fade` node passed to
|
|
18
|
+
* `heightNode` / `normalNode`, and leaves it at full amplitude everywhere else.
|
|
19
|
+
*
|
|
20
|
+
* A wave shorter than the distance one screen pixel covers cannot be resolved, and what it
|
|
21
|
+
* produces instead is a crawling moire that reads as a repeating pattern. Fading it is the fix.
|
|
22
|
+
* `sample` on the CPU has no camera and therefore no fade, so CPU and GPU height differ by at
|
|
23
|
+
* most the summed amplitude of the detail waves — keep them small, or float things on the
|
|
24
|
+
* non-detail waves alone.
|
|
25
|
+
*/
|
|
26
|
+
readonly detail?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface IWaveFieldDomainWarp {
|
|
30
|
+
readonly direction?: WaveDirection;
|
|
31
|
+
readonly waveVector?: WaveDirection;
|
|
32
|
+
readonly displacement?: WaveDirection;
|
|
33
|
+
readonly amplitude?: number;
|
|
34
|
+
readonly wavelength?: number;
|
|
35
|
+
readonly speed: number;
|
|
36
|
+
readonly phase?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface IWaveFieldOptions {
|
|
40
|
+
readonly waves: readonly IWaveFieldWave[];
|
|
41
|
+
readonly domainWarp?: readonly IWaveFieldDomainWarp[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Where, when, and how finely to evaluate the field in a graph. */
|
|
45
|
+
export interface IWaveFieldGraphOptions {
|
|
46
|
+
/**
|
|
47
|
+
* The horizontal point to evaluate at, in whatever space the caller wants the answer in.
|
|
48
|
+
* Defaults to this vertex's local x and z.
|
|
49
|
+
*/
|
|
50
|
+
readonly point?: Node<"vec2">;
|
|
51
|
+
/** The clock. Defaults to the field's own `time` uniform. */
|
|
52
|
+
readonly time?: Node<"float">;
|
|
53
|
+
/** A 0..1 multiplier on every wave marked `detail`. Omitted, detail waves stay at full size. */
|
|
54
|
+
readonly fade?: Node<"float">;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface IWaveFieldSample {
|
|
58
|
+
readonly height: number;
|
|
59
|
+
readonly normal: Vector3;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A `float().toVar()` — an accumulator the graph writes back into. */
|
|
63
|
+
type FloatVar = ReturnType<Node<"float">["toVar"]>;
|
|
64
|
+
|
|
65
|
+
const TWO_PI = Math.PI * 2;
|
|
66
|
+
const WAVE_STRIDE = 8;
|
|
67
|
+
const WARP_STRIDE = 8;
|
|
68
|
+
|
|
69
|
+
function finite(name: string, value: number): number {
|
|
70
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
71
|
+
throw new Error(`WaveField.${name} must be finite.`);
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function positive(name: string, value: number): number {
|
|
76
|
+
finite(name, value);
|
|
77
|
+
if (value <= 0) throw new Error(`WaveField.${name} must be positive.`);
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function direction(value: WaveDirection, name: string): [number, number] {
|
|
82
|
+
let x: number | undefined;
|
|
83
|
+
let z: number | undefined;
|
|
84
|
+
if ("x" in value) {
|
|
85
|
+
x = value.x;
|
|
86
|
+
z = value.z ?? value.y;
|
|
87
|
+
} else {
|
|
88
|
+
x = value[0];
|
|
89
|
+
z = value[1];
|
|
90
|
+
}
|
|
91
|
+
if (x === undefined || z === undefined) throw new Error(`WaveField.${name} is incomplete.`);
|
|
92
|
+
finite(`${name}.x`, x);
|
|
93
|
+
finite(`${name}.z`, z);
|
|
94
|
+
const length = Math.hypot(x, z);
|
|
95
|
+
if (length <= Number.EPSILON) throw new Error(`WaveField.${name} must not be zero.`);
|
|
96
|
+
return [x, z];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function displacement(
|
|
100
|
+
value: WaveDirection | undefined,
|
|
101
|
+
amplitude: number | undefined,
|
|
102
|
+
): [number, number] {
|
|
103
|
+
if (value !== undefined) {
|
|
104
|
+
let x: number | undefined;
|
|
105
|
+
let z: number | undefined;
|
|
106
|
+
if ("x" in value) {
|
|
107
|
+
x = value.x;
|
|
108
|
+
z = value.z ?? value.y;
|
|
109
|
+
} else {
|
|
110
|
+
x = value[0];
|
|
111
|
+
z = value[1];
|
|
112
|
+
}
|
|
113
|
+
if (x === undefined || z === undefined)
|
|
114
|
+
throw new Error("WaveField.domainWarp.displacement is incomplete.");
|
|
115
|
+
return [finite("domainWarp.displacement.x", x), finite("domainWarp.displacement.z", z)];
|
|
116
|
+
}
|
|
117
|
+
const amount = amplitude === undefined ? 0 : finite("domainWarp.amplitude", amplitude);
|
|
118
|
+
return [amount, amount];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function waveAmplitude(wave: IWaveFieldWave, waveNumber: number): number {
|
|
122
|
+
const amplitude = wave.amplitude === undefined ? 0 : finite("waves.amplitude", wave.amplitude);
|
|
123
|
+
const steepness = wave.steepness === undefined ? 0 : finite("waves.steepness", wave.steepness);
|
|
124
|
+
if (wave.amplitude === undefined && wave.steepness === undefined)
|
|
125
|
+
throw new Error("WaveField waves require amplitude or steepness.");
|
|
126
|
+
// Steepness is dimensionless. Convert it to the same length unit as amplitude so a wave may
|
|
127
|
+
// carry both authored values; steepness-only waves retain the original steepness / waveNumber
|
|
128
|
+
// fallback. The base amplitude remains separately packed so both consumers read the slot.
|
|
129
|
+
return amplitude + steepness / waveNumber;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function requireSampleValue(name: string, value: number): number {
|
|
133
|
+
return finite(`sample.${name}`, value);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* An analytic wave field with one packed parameter source for CPU sampling and TSL displacement.
|
|
138
|
+
* It owns no geometry or appearance; a game chooses how the returned displacement is drawn.
|
|
139
|
+
*/
|
|
140
|
+
export class WaveField {
|
|
141
|
+
readonly waves: readonly IWaveFieldWave[];
|
|
142
|
+
readonly domainWarp: readonly IWaveFieldDomainWarp[];
|
|
143
|
+
readonly parameters: Readonly<Float32Array>;
|
|
144
|
+
readonly time = uniform(0);
|
|
145
|
+
readonly #waveCount: number;
|
|
146
|
+
readonly #warpCount: number;
|
|
147
|
+
readonly #amplitude: Float64Array;
|
|
148
|
+
|
|
149
|
+
constructor(options: IWaveFieldOptions) {
|
|
150
|
+
if (!Array.isArray(options.waves)) throw new Error("WaveField.waves must be an array.");
|
|
151
|
+
const waves = options.waves.map((wave, index) => {
|
|
152
|
+
if (wave === undefined || typeof wave !== "object")
|
|
153
|
+
throw new Error(`WaveField.waves[${index}] must be an object.`);
|
|
154
|
+
const [rawX, rawZ] = direction(wave.direction, `waves[${index}].direction`);
|
|
155
|
+
const length = Math.hypot(rawX, rawZ);
|
|
156
|
+
const directionX = rawX / length;
|
|
157
|
+
const directionZ = rawZ / length;
|
|
158
|
+
const wavelength = positive(`waves[${index}].wavelength`, wave.wavelength);
|
|
159
|
+
const speed = finite(`waves[${index}].speed`, wave.speed);
|
|
160
|
+
const phase = wave.phase === undefined ? 0 : finite(`waves[${index}].phase`, wave.phase);
|
|
161
|
+
const waveNumber = TWO_PI / wavelength;
|
|
162
|
+
const amplitude = waveAmplitude(wave, waveNumber);
|
|
163
|
+
const steepness =
|
|
164
|
+
wave.steepness === undefined ? 0 : finite("waves.steepness", wave.steepness);
|
|
165
|
+
return {
|
|
166
|
+
amplitude,
|
|
167
|
+
detail: wave.detail === true,
|
|
168
|
+
direction: [directionX, directionZ] as const,
|
|
169
|
+
wavelength,
|
|
170
|
+
speed,
|
|
171
|
+
phase,
|
|
172
|
+
steepness,
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
const domainWarp = (options.domainWarp ?? []).map((warp, index) => {
|
|
176
|
+
if (warp === undefined || typeof warp !== "object")
|
|
177
|
+
throw new Error(`WaveField.domainWarp[${index}] must be an object.`);
|
|
178
|
+
const speed = finite(`domainWarp[${index}].speed`, warp.speed);
|
|
179
|
+
const phase = warp.phase === undefined ? 0 : finite(`domainWarp[${index}].phase`, warp.phase);
|
|
180
|
+
const displacementValue = displacement(warp.displacement, warp.amplitude);
|
|
181
|
+
let waveVector: readonly [number, number];
|
|
182
|
+
let wavelength: number | undefined;
|
|
183
|
+
if (warp.waveVector !== undefined) {
|
|
184
|
+
const [x, z] = direction(warp.waveVector, `domainWarp[${index}].waveVector`);
|
|
185
|
+
waveVector = [x, z];
|
|
186
|
+
} else {
|
|
187
|
+
if (warp.direction === undefined)
|
|
188
|
+
throw new Error(`WaveField.domainWarp[${index}] requires direction or waveVector.`);
|
|
189
|
+
const [rawX, rawZ] = direction(warp.direction, `domainWarp[${index}].direction`);
|
|
190
|
+
const length = Math.hypot(rawX, rawZ);
|
|
191
|
+
waveVector = [rawX / length, rawZ / length];
|
|
192
|
+
const rawWavelength = warp.wavelength;
|
|
193
|
+
if (rawWavelength === undefined)
|
|
194
|
+
throw new Error(`WaveField.domainWarp[${index}].wavelength is required.`);
|
|
195
|
+
wavelength = positive(`domainWarp[${index}].wavelength`, rawWavelength);
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
direction: waveVector,
|
|
199
|
+
displacement: displacementValue,
|
|
200
|
+
speed,
|
|
201
|
+
phase,
|
|
202
|
+
wavelength,
|
|
203
|
+
};
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const parameters = new Float32Array(
|
|
207
|
+
waves.length * WAVE_STRIDE + domainWarp.length * WARP_STRIDE,
|
|
208
|
+
);
|
|
209
|
+
for (const [index, wave] of waves.entries()) {
|
|
210
|
+
const offset = index * WAVE_STRIDE;
|
|
211
|
+
const waveNumber = TWO_PI / wave.wavelength;
|
|
212
|
+
parameters[offset] = wave.direction[0];
|
|
213
|
+
parameters[offset + 1] = wave.direction[1];
|
|
214
|
+
parameters[offset + 2] = wave.amplitude - wave.steepness / waveNumber;
|
|
215
|
+
parameters[offset + 3] = waveNumber;
|
|
216
|
+
parameters[offset + 4] = wave.speed;
|
|
217
|
+
parameters[offset + 5] = wave.phase;
|
|
218
|
+
parameters[offset + 6] = wave.steepness;
|
|
219
|
+
parameters[offset + 7] = wave.detail ? 1 : 0;
|
|
220
|
+
}
|
|
221
|
+
const warpOffset = waves.length * WAVE_STRIDE;
|
|
222
|
+
for (const [index, warp] of domainWarp.entries()) {
|
|
223
|
+
const offset = warpOffset + index * WARP_STRIDE;
|
|
224
|
+
parameters[offset] =
|
|
225
|
+
warp.direction[0] * (warp.wavelength === undefined ? 1 : TWO_PI / warp.wavelength);
|
|
226
|
+
parameters[offset + 1] =
|
|
227
|
+
warp.direction[1] * (warp.wavelength === undefined ? 1 : TWO_PI / warp.wavelength);
|
|
228
|
+
parameters[offset + 2] = warp.displacement[0];
|
|
229
|
+
parameters[offset + 3] = warp.displacement[1];
|
|
230
|
+
parameters[offset + 4] = warp.speed;
|
|
231
|
+
parameters[offset + 5] = warp.phase;
|
|
232
|
+
parameters[offset + 6] = 0;
|
|
233
|
+
parameters[offset + 7] = 0;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
this.waves = waves;
|
|
237
|
+
this.domainWarp = domainWarp;
|
|
238
|
+
this.parameters = parameters;
|
|
239
|
+
this.#waveCount = waves.length;
|
|
240
|
+
this.#warpCount = domainWarp.length;
|
|
241
|
+
// `amplitude` is `parameters[offset + 2] + parameters[offset + 6] / waveNumber` — the same
|
|
242
|
+
// value on every sample for the life of the field, yet the scalar evaluator paid a divide per
|
|
243
|
+
// wave per call, and a floating hull or a whitewater parcel asks thousands of times a frame.
|
|
244
|
+
// Reading the slots back out of `parameters` rather than recomputing from `wave` keeps the
|
|
245
|
+
// stored double bit-identical to what the loop used to produce.
|
|
246
|
+
this.#amplitude = new Float64Array(waves.length);
|
|
247
|
+
for (let index = 0; index < waves.length; index += 1) {
|
|
248
|
+
const offset = index * WAVE_STRIDE;
|
|
249
|
+
this.#amplitude[index] =
|
|
250
|
+
(parameters[offset + 2] as number) +
|
|
251
|
+
(parameters[offset + 6] as number) / (parameters[offset + 3] as number);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** Update the default graph clock. Explicit sample times remain available for fixed-step code. */
|
|
256
|
+
setTime(value: number): void {
|
|
257
|
+
this.time.value = requireSampleValue("time", value);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Surface height and normal at a point. Allocates the result and its vector; a caller that wants
|
|
262
|
+
* only the number should call `heightAt`, which is the same evaluation without either.
|
|
263
|
+
*/
|
|
264
|
+
sample(x: number, z: number, time: number): IWaveFieldSample {
|
|
265
|
+
const normal = new Vector3();
|
|
266
|
+
const height = this.#evaluateCpu(x, z, time, normal);
|
|
267
|
+
return { height, normal };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Surface height at a point, as a number.
|
|
272
|
+
*
|
|
273
|
+
* The scalar half of `sample`, and the same arithmetic in the same order, so the two agree
|
|
274
|
+
* exactly. What it skips is everything only a normal needs: the domain warp's jacobian, the
|
|
275
|
+
* cosine and slope of every wave, the normalisation, the result object and the `Vector3`. A
|
|
276
|
+
* floating hull, a splash query or a whitewater height test asks this question thousands of times
|
|
277
|
+
* a frame and throws the normal away every time.
|
|
278
|
+
*/
|
|
279
|
+
heightAt(x: number, z: number, time: number): number {
|
|
280
|
+
return this.#evaluateCpu(x, z, time, undefined);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* The one CPU evaluator. With `normal` it fills that vector and pays for the gradient; without
|
|
285
|
+
* it, nothing derivative is computed at all. The warp and wave loops run in the same order
|
|
286
|
+
* either way, so the height a scalar caller gets is bit-identical to `sample`'s.
|
|
287
|
+
*/
|
|
288
|
+
#evaluateCpu(x: number, z: number, time: number, normal: Vector3 | undefined): number {
|
|
289
|
+
const sampleX = requireSampleValue("x", x);
|
|
290
|
+
const sampleZ = requireSampleValue("z", z);
|
|
291
|
+
const sampleTime = requireSampleValue("time", time);
|
|
292
|
+
const warpOffset = this.#waveCount * WAVE_STRIDE;
|
|
293
|
+
let warpedX = sampleX;
|
|
294
|
+
let warpedZ = sampleZ;
|
|
295
|
+
let warpedXX = 1;
|
|
296
|
+
let warpedXZ = 0;
|
|
297
|
+
let warpedZX = 0;
|
|
298
|
+
let warpedZZ = 1;
|
|
299
|
+
for (let index = 0; index < this.#warpCount; index += 1) {
|
|
300
|
+
const offset = warpOffset + index * WARP_STRIDE;
|
|
301
|
+
const kx = this.parameters[offset] as number;
|
|
302
|
+
const kz = this.parameters[offset + 1] as number;
|
|
303
|
+
const displacementX = this.parameters[offset + 2] as number;
|
|
304
|
+
const displacementZ = this.parameters[offset + 3] as number;
|
|
305
|
+
const phase =
|
|
306
|
+
kx * warpedX +
|
|
307
|
+
kz * warpedZ -
|
|
308
|
+
sampleTime * (this.parameters[offset + 4] as number) +
|
|
309
|
+
(this.parameters[offset + 5] as number);
|
|
310
|
+
const sine = Math.sin(phase);
|
|
311
|
+
warpedX += displacementX * sine;
|
|
312
|
+
warpedZ += displacementZ * sine;
|
|
313
|
+
// The jacobian exists only to rotate a gradient back out of warped space. No gradient, no
|
|
314
|
+
// cosine and no four multiply-adds a warp.
|
|
315
|
+
if (normal === undefined) continue;
|
|
316
|
+
const cosine = Math.cos(phase);
|
|
317
|
+
const derivativeX = cosine * kx;
|
|
318
|
+
const derivativeZ = cosine * kz;
|
|
319
|
+
const nextXX =
|
|
320
|
+
warpedXX + displacementX * derivativeX * warpedXX + displacementX * derivativeZ * warpedZX;
|
|
321
|
+
const nextXZ =
|
|
322
|
+
warpedXZ + displacementX * derivativeX * warpedXZ + displacementX * derivativeZ * warpedZZ;
|
|
323
|
+
const nextZX =
|
|
324
|
+
warpedZX + displacementZ * derivativeX * warpedXX + displacementZ * derivativeZ * warpedZX;
|
|
325
|
+
const nextZZ =
|
|
326
|
+
warpedZZ + displacementZ * derivativeX * warpedXZ + displacementZ * derivativeZ * warpedZZ;
|
|
327
|
+
warpedXX = nextXX;
|
|
328
|
+
warpedXZ = nextXZ;
|
|
329
|
+
warpedZX = nextZX;
|
|
330
|
+
warpedZZ = nextZZ;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
let height = 0;
|
|
334
|
+
let gradientX = 0;
|
|
335
|
+
let gradientZ = 0;
|
|
336
|
+
for (let index = 0; index < this.#waveCount; index += 1) {
|
|
337
|
+
const offset = index * WAVE_STRIDE;
|
|
338
|
+
const directionX = this.parameters[offset] as number;
|
|
339
|
+
const directionZ = this.parameters[offset + 1] as number;
|
|
340
|
+
const waveNumber = this.parameters[offset + 3] as number;
|
|
341
|
+
const phase =
|
|
342
|
+
waveNumber * (directionX * warpedX + directionZ * warpedZ) -
|
|
343
|
+
sampleTime * (this.parameters[offset + 4] as number) +
|
|
344
|
+
(this.parameters[offset + 5] as number);
|
|
345
|
+
const amplitude = this.#amplitude[index] as number;
|
|
346
|
+
height += amplitude * Math.sin(phase);
|
|
347
|
+
if (normal === undefined) continue;
|
|
348
|
+
const slope = amplitude * waveNumber * Math.cos(phase);
|
|
349
|
+
gradientX += slope * directionX;
|
|
350
|
+
gradientZ += slope * directionZ;
|
|
351
|
+
}
|
|
352
|
+
if (normal === undefined) return height;
|
|
353
|
+
const worldGradientX = gradientX * warpedXX + gradientZ * warpedZX;
|
|
354
|
+
const worldGradientZ = gradientX * warpedXZ + gradientZ * warpedZZ;
|
|
355
|
+
normal
|
|
356
|
+
.set(
|
|
357
|
+
worldGradientX === 0 ? 0 : -worldGradientX,
|
|
358
|
+
1,
|
|
359
|
+
worldGradientZ === 0 ? 0 : -worldGradientZ,
|
|
360
|
+
)
|
|
361
|
+
.normalize();
|
|
362
|
+
return height;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Walk the domain warp in a graph, moving `x` and `z` in place.
|
|
367
|
+
*
|
|
368
|
+
* Returns the warp's jacobian when a gradient is wanted, so the caller can rotate the wave
|
|
369
|
+
* gradient back out of warped space; an identity matrix costs four registers a fragment and is
|
|
370
|
+
* not allocated when nobody needs it.
|
|
371
|
+
*/
|
|
372
|
+
#warpGraph(x: FloatVar, z: FloatVar, timeNode: Node<"float">, wantJacobian: boolean) {
|
|
373
|
+
const parameters = this.parameters;
|
|
374
|
+
const warpOffset = this.#waveCount * WAVE_STRIDE;
|
|
375
|
+
const jacobian = wantJacobian
|
|
376
|
+
? { xx: float(1).toVar(), xz: float(0).toVar(), zx: float(0).toVar(), zz: float(1).toVar() }
|
|
377
|
+
: undefined;
|
|
378
|
+
for (let index = 0; index < this.#warpCount; index += 1) {
|
|
379
|
+
const offset = warpOffset + index * WARP_STRIDE;
|
|
380
|
+
const waveVectorX = float(parameters[offset] as number);
|
|
381
|
+
const waveVectorZ = float(parameters[offset + 1] as number);
|
|
382
|
+
const displacementX = float(parameters[offset + 2] as number);
|
|
383
|
+
const displacementZ = float(parameters[offset + 3] as number);
|
|
384
|
+
const phase = x
|
|
385
|
+
.mul(waveVectorX)
|
|
386
|
+
.add(z.mul(waveVectorZ))
|
|
387
|
+
.sub(timeNode.mul(float(parameters[offset + 4] as number)))
|
|
388
|
+
.add(float(parameters[offset + 5] as number));
|
|
389
|
+
const sine = sin(phase).toVar();
|
|
390
|
+
x.addAssign(sine.mul(displacementX));
|
|
391
|
+
z.addAssign(sine.mul(displacementZ));
|
|
392
|
+
if (jacobian === undefined) continue;
|
|
393
|
+
const cosine = cos(phase).toVar();
|
|
394
|
+
const derivativeX = cosine.mul(waveVectorX);
|
|
395
|
+
const derivativeZ = cosine.mul(waveVectorZ);
|
|
396
|
+
// Materialised before any assignment: each row reads the previous jacobian, and assigning
|
|
397
|
+
// in place first would feed the next row a value from this iteration.
|
|
398
|
+
const nextXX = jacobian.xx
|
|
399
|
+
.add(displacementX.mul(derivativeX).mul(jacobian.xx))
|
|
400
|
+
.add(displacementX.mul(derivativeZ).mul(jacobian.zx))
|
|
401
|
+
.toVar();
|
|
402
|
+
const nextXZ = jacobian.xz
|
|
403
|
+
.add(displacementX.mul(derivativeX).mul(jacobian.xz))
|
|
404
|
+
.add(displacementX.mul(derivativeZ).mul(jacobian.zz))
|
|
405
|
+
.toVar();
|
|
406
|
+
const nextZX = jacobian.zx
|
|
407
|
+
.add(displacementZ.mul(derivativeX).mul(jacobian.xx))
|
|
408
|
+
.add(displacementZ.mul(derivativeZ).mul(jacobian.zx))
|
|
409
|
+
.toVar();
|
|
410
|
+
const nextZZ = jacobian.zz
|
|
411
|
+
.add(displacementZ.mul(derivativeX).mul(jacobian.xz))
|
|
412
|
+
.add(displacementZ.mul(derivativeZ).mul(jacobian.zz))
|
|
413
|
+
.toVar();
|
|
414
|
+
jacobian.xx.assign(nextXX);
|
|
415
|
+
jacobian.xz.assign(nextXZ);
|
|
416
|
+
jacobian.zx.assign(nextZX);
|
|
417
|
+
jacobian.zz.assign(nextZZ);
|
|
418
|
+
}
|
|
419
|
+
return jacobian;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** Sum the waves at an already-warped point. The gradient is optional and costs a cosine. */
|
|
423
|
+
#sumGraph(
|
|
424
|
+
x: FloatVar,
|
|
425
|
+
z: FloatVar,
|
|
426
|
+
timeNode: Node<"float">,
|
|
427
|
+
fade: Node<"float"> | undefined,
|
|
428
|
+
wantGradient: boolean,
|
|
429
|
+
) {
|
|
430
|
+
const parameters = this.parameters;
|
|
431
|
+
const height = float(0).toVar();
|
|
432
|
+
// A height-only caller never pays for the derivative: no cosine, no slope var.
|
|
433
|
+
const gradientX = wantGradient ? float(0).toVar() : undefined;
|
|
434
|
+
const gradientZ = wantGradient ? float(0).toVar() : undefined;
|
|
435
|
+
for (let index = 0; index < this.#waveCount; index += 1) {
|
|
436
|
+
const offset = index * WAVE_STRIDE;
|
|
437
|
+
const directionX = parameters[offset] as number;
|
|
438
|
+
const directionZ = parameters[offset + 1] as number;
|
|
439
|
+
const waveNumber = parameters[offset + 3] as number;
|
|
440
|
+
const phase = x
|
|
441
|
+
.mul(float(directionX * waveNumber))
|
|
442
|
+
.add(z.mul(float(directionZ * waveNumber)))
|
|
443
|
+
.sub(timeNode.mul(float(parameters[offset + 4] as number)))
|
|
444
|
+
.add(float(parameters[offset + 5] as number));
|
|
445
|
+
const scalar =
|
|
446
|
+
(parameters[offset + 2] as number) + (parameters[offset + 6] as number) / waveNumber;
|
|
447
|
+
// `detail` is a build-time constant, so the fade costs one multiply on the waves that
|
|
448
|
+
// asked for it and nothing at all on the rest.
|
|
449
|
+
const amplitude =
|
|
450
|
+
fade !== undefined && parameters[offset + 7] === 1
|
|
451
|
+
? fade.mul(float(scalar))
|
|
452
|
+
: float(scalar);
|
|
453
|
+
height.addAssign(sin(phase).mul(amplitude));
|
|
454
|
+
if (gradientX === undefined || gradientZ === undefined) continue;
|
|
455
|
+
const slope = cos(phase).mul(amplitude).mul(float(waveNumber)).toVar();
|
|
456
|
+
gradientX.addAssign(slope.mul(float(directionX)));
|
|
457
|
+
gradientZ.addAssign(slope.mul(float(directionZ)));
|
|
458
|
+
}
|
|
459
|
+
return { gradientX, gradientZ, height };
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Evaluate the field in a graph: the same packed values `sample` reads, as TSL.
|
|
464
|
+
*
|
|
465
|
+
* Returns the height and the two horizontal gradient components, all in the space `point` is
|
|
466
|
+
* given in, so a caller that passes world XZ gets a world-space answer.
|
|
467
|
+
*/
|
|
468
|
+
#evaluate(options: IWaveFieldGraphOptions, wantGradient: boolean) {
|
|
469
|
+
const timeNode = options.time ?? this.time;
|
|
470
|
+
const point = options.point ?? vec2(positionLocal.x, positionLocal.z);
|
|
471
|
+
const x = point.x.toVar();
|
|
472
|
+
const z = point.y.toVar();
|
|
473
|
+
const jacobian = this.#warpGraph(x, z, timeNode, wantGradient && this.#warpCount > 0);
|
|
474
|
+
const { gradientX, gradientZ, height } = this.#sumGraph(
|
|
475
|
+
x,
|
|
476
|
+
z,
|
|
477
|
+
timeNode,
|
|
478
|
+
options.fade,
|
|
479
|
+
wantGradient,
|
|
480
|
+
);
|
|
481
|
+
if (jacobian === undefined || gradientX === undefined || gradientZ === undefined)
|
|
482
|
+
return { gradientX, gradientZ, height };
|
|
483
|
+
// The waves were summed in warped space; rotate their gradient back out through the warp's
|
|
484
|
+
// jacobian, or the normal leans the wrong way exactly where the warp bends the field most.
|
|
485
|
+
return {
|
|
486
|
+
gradientX: gradientX.mul(jacobian.xx).add(gradientZ.mul(jacobian.zx)),
|
|
487
|
+
gradientZ: gradientX.mul(jacobian.xz).add(gradientZ.mul(jacobian.zz)),
|
|
488
|
+
height,
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** Surface height at a point, as a graph. The scalar half of what `sample` returns. */
|
|
493
|
+
heightNode(options: IWaveFieldGraphOptions = {}): Node<"float"> {
|
|
494
|
+
return Fn(() => this.#evaluate(options, false).height)() as unknown as Node<"float">; // quality-allow: TSL result shape is set by construction; three 0.185 types swizzles and Fn loosely
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* The analytic surface normal at a point, as a graph — the same value `sample` returns, and the
|
|
499
|
+
* reason a water material needs no hand-written ripple pattern.
|
|
500
|
+
*
|
|
501
|
+
* Differencing the height, or stamping a normal map over the surface, is what puts visible
|
|
502
|
+
* repeats in water: both quantise a field that has none. This differentiates the wave sum
|
|
503
|
+
* itself, so the normal repeats only where the waves do, which for wavelengths with no common
|
|
504
|
+
* multiple is nowhere.
|
|
505
|
+
*
|
|
506
|
+
* Evaluate it per fragment — pass `point` in world XZ — and the ripples survive at any distance
|
|
507
|
+
* from the camera, at the cost of the wave sum running per pixel rather than per vertex.
|
|
508
|
+
*/
|
|
509
|
+
normalNode(options: IWaveFieldGraphOptions = {}): Node<"vec3"> {
|
|
510
|
+
return Fn(() => {
|
|
511
|
+
const { gradientX, gradientZ } = this.#evaluate(options, true);
|
|
512
|
+
if (gradientX === undefined || gradientZ === undefined)
|
|
513
|
+
throw new Error("WaveField.normalNode lost its gradient.");
|
|
514
|
+
return normalize(vec3(gradientX.negate(), 1, gradientZ.negate()));
|
|
515
|
+
})() as unknown as Node<"vec3">; // quality-allow: TSL result shape is set by construction; three 0.185 types swizzles and Fn loosely
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/** Return a TSL node that displaces local vertices using the same packed values as `sample`. */
|
|
519
|
+
displacementNode(timeNode = this.time) {
|
|
520
|
+
return Fn(() =>
|
|
521
|
+
positionLocal.add(vec3(0, this.#evaluate({ time: timeNode }, false).height, 0)),
|
|
522
|
+
)();
|
|
523
|
+
}
|
|
524
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
export type WorldGenerationPath = "gpu" | "cpu-fallback" | "unsupported";
|
|
2
|
+
|
|
3
|
+
export interface IWorldComputeLimits {
|
|
4
|
+
readonly maxComputeInvocationsPerWorkgroup: number;
|
|
5
|
+
readonly maxComputeWorkgroupsPerDimension: number;
|
|
6
|
+
readonly maxStorageBufferBindingSize: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface IWorldCapabilities {
|
|
10
|
+
readonly compute: boolean;
|
|
11
|
+
/** Whether the host exposed a GPU adapter, even when its limits cannot run the world pass. */
|
|
12
|
+
readonly gpu: boolean;
|
|
13
|
+
readonly generation: WorldGenerationPath;
|
|
14
|
+
readonly limits: IWorldComputeLimits;
|
|
15
|
+
readonly cpuFallbackIterations: number;
|
|
16
|
+
readonly reason?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface IWorldCapabilitiesOptions {
|
|
20
|
+
/** Explicitly supplied by a host that already probed its adapter. */
|
|
21
|
+
readonly gpuAvailable?: boolean;
|
|
22
|
+
readonly limits?: Partial<IWorldComputeLimits>;
|
|
23
|
+
readonly minimumWorkgroupsPerDimension?: number;
|
|
24
|
+
readonly minimumStorageBufferBindingSize?: number;
|
|
25
|
+
/** A positive value makes CPU generation an explicit, reduced fallback. */
|
|
26
|
+
readonly cpuFallbackIterations?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const DEFAULT_LIMITS: IWorldComputeLimits = {
|
|
30
|
+
maxComputeInvocationsPerWorkgroup: 0,
|
|
31
|
+
maxComputeWorkgroupsPerDimension: 0,
|
|
32
|
+
maxStorageBufferBindingSize: 0,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function finite(value: number, name: string, minimum = 0): number {
|
|
36
|
+
if (!Number.isFinite(value) || value < minimum)
|
|
37
|
+
throw new Error(`World capabilities ${name} must be finite and at least ${String(minimum)}.`);
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function integer(value: number, name: string, minimum = 0): number {
|
|
42
|
+
if (!Number.isInteger(value) || value < minimum)
|
|
43
|
+
throw new Error(
|
|
44
|
+
`World capabilities ${name} must be an integer of at least ${String(minimum)}.`,
|
|
45
|
+
);
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function resolveLimits(limits: Partial<IWorldComputeLimits> | undefined): IWorldComputeLimits {
|
|
50
|
+
return {
|
|
51
|
+
maxComputeInvocationsPerWorkgroup: finite(
|
|
52
|
+
limits?.maxComputeInvocationsPerWorkgroup ?? DEFAULT_LIMITS.maxComputeInvocationsPerWorkgroup,
|
|
53
|
+
"maxComputeInvocationsPerWorkgroup",
|
|
54
|
+
),
|
|
55
|
+
maxComputeWorkgroupsPerDimension: finite(
|
|
56
|
+
limits?.maxComputeWorkgroupsPerDimension ?? DEFAULT_LIMITS.maxComputeWorkgroupsPerDimension,
|
|
57
|
+
"maxComputeWorkgroupsPerDimension",
|
|
58
|
+
),
|
|
59
|
+
maxStorageBufferBindingSize: finite(
|
|
60
|
+
limits?.maxStorageBufferBindingSize ?? DEFAULT_LIMITS.maxStorageBufferBindingSize,
|
|
61
|
+
"maxStorageBufferBindingSize",
|
|
62
|
+
),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Resolve the active world-generation path from host capability facts.
|
|
68
|
+
*
|
|
69
|
+
* The function accepts the adapter facts instead of reaching through a renderer-specific global,
|
|
70
|
+
* so browser and native hosts can report the same object. Missing limits are not treated as
|
|
71
|
+
* infinite: a host must either provide a valid GPU limit report or explicitly choose CPU fallback.
|
|
72
|
+
* GPU generation remains unavailable until a GPU readback can own the canonical field; a host
|
|
73
|
+
* adapter report therefore never upgrades a CPU fallback into a GPU generation claim.
|
|
74
|
+
*
|
|
75
|
+
* @situation decide whether generated terrain can use GPU compute
|
|
76
|
+
* @situation report why terrain generation is using a reduced CPU fallback
|
|
77
|
+
* @constraint unsupported is returned when compute limits are unknown or below the requirement; callers must not silently continue
|
|
78
|
+
* @override minimumWorkgroupsPerDimension, minimumStorageBufferBindingSize, and cpuFallbackIterations
|
|
79
|
+
* @example const capabilities = getWorldCapabilities({ limits: adapter.limits, cpuFallbackIterations: 8 });
|
|
80
|
+
*/
|
|
81
|
+
export function getWorldCapabilities(options: IWorldCapabilitiesOptions = {}): IWorldCapabilities {
|
|
82
|
+
const minimumWorkgroups = integer(
|
|
83
|
+
options.minimumWorkgroupsPerDimension ?? 1,
|
|
84
|
+
"minimumWorkgroupsPerDimension",
|
|
85
|
+
1,
|
|
86
|
+
);
|
|
87
|
+
const minimumStorage = finite(
|
|
88
|
+
options.minimumStorageBufferBindingSize ?? 1,
|
|
89
|
+
"minimumStorageBufferBindingSize",
|
|
90
|
+
1,
|
|
91
|
+
);
|
|
92
|
+
const fallbackIterations = integer(options.cpuFallbackIterations ?? 0, "cpuFallbackIterations");
|
|
93
|
+
const limits = resolveLimits(options.limits);
|
|
94
|
+
const hasReportedLimits =
|
|
95
|
+
options.limits?.maxComputeInvocationsPerWorkgroup !== undefined &&
|
|
96
|
+
options.limits?.maxComputeWorkgroupsPerDimension !== undefined &&
|
|
97
|
+
options.limits?.maxStorageBufferBindingSize !== undefined;
|
|
98
|
+
// Limits describe what an adapter can do, not whether this host actually exposed one. An
|
|
99
|
+
// omitted adapter probe is deliberately conservative so a browser global or a test stub can
|
|
100
|
+
// never turn CPU generation into a reported GPU path.
|
|
101
|
+
const gpuAvailable = options.gpuAvailable ?? false;
|
|
102
|
+
const meetsRequirements =
|
|
103
|
+
hasReportedLimits &&
|
|
104
|
+
limits.maxComputeInvocationsPerWorkgroup > 0 &&
|
|
105
|
+
limits.maxComputeWorkgroupsPerDimension >= minimumWorkgroups &&
|
|
106
|
+
limits.maxStorageBufferBindingSize >= minimumStorage;
|
|
107
|
+
const reason = !gpuAvailable
|
|
108
|
+
? "GPU compute is unavailable on this host."
|
|
109
|
+
: !hasReportedLimits
|
|
110
|
+
? "GPU compute limits were not reported by the host."
|
|
111
|
+
: !meetsRequirements
|
|
112
|
+
? `GPU limits are below the required workgroup (${String(minimumWorkgroups)}) or storage-buffer (${String(minimumStorage)}) floor.`
|
|
113
|
+
: "GPU compute is available, but canonical GPU world-field readback is unsupported.";
|
|
114
|
+
if (fallbackIterations > 0)
|
|
115
|
+
return {
|
|
116
|
+
compute: false,
|
|
117
|
+
cpuFallbackIterations: fallbackIterations,
|
|
118
|
+
generation: "cpu-fallback",
|
|
119
|
+
gpu: gpuAvailable,
|
|
120
|
+
limits,
|
|
121
|
+
reason: `${reason} Using ${String(fallbackIterations)} reduced CPU erosion iterations.`,
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
compute: false,
|
|
125
|
+
cpuFallbackIterations: 0,
|
|
126
|
+
generation: "unsupported",
|
|
127
|
+
gpu: gpuAvailable,
|
|
128
|
+
limits,
|
|
129
|
+
reason,
|
|
130
|
+
};
|
|
131
|
+
}
|