roamwright 0.55.1 → 0.57.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/README.md +2 -1
- package/examples/animals.js +27 -15
- package/examples/crowds.js +28 -18
- package/examples/effects.js +13 -11
- package/examples/figure-motion.js +17 -5
- package/examples/figure.js +12 -8
- package/examples/fliers.js +16 -12
- package/examples/fortification.js +31 -18
- package/examples/house-kit.js +17 -10
- package/examples/island.js +25 -12
- package/examples/land.js +14 -8
- package/examples/pacing.html +100 -0
- package/examples/pacing.js +305 -0
- package/examples/props-and-plants.js +21 -32
- package/examples/rooms.js +2 -2
- package/examples/ships.js +33 -15
- package/examples/small-world-land.js +3 -3
- package/examples/small-world-life.js +13 -5
- package/examples/small-world-town.js +8 -11
- package/examples/small-world.js +26 -19
- package/examples/soundscape.js +18 -18
- package/examples/stage-kits.js +5 -133
- package/examples/stage.js +1 -324
- package/examples/towns.js +25 -18
- package/examples/viaduct-landscape.js +1 -1
- package/examples/viaduct.js +3 -4
- package/geometry/builder.js +8 -18
- package/geometry/plant-broadleaf.js +10 -4
- package/geometry/plant-trees.js +15 -9
- package/geometry/still-mesh.js +35 -0
- package/index.js +19 -2
- package/motion/figure-mount.js +1 -0
- package/package.json +1 -1
- package/rendering/crowd-system.js +239 -0
- package/rendering/daylight-sky.js +212 -0
- package/rendering/house-kit-meshes.js +65 -16
- package/rendering/orbit-camera.js +216 -0
- package/rendering/perf-box-worker.js +95 -0
- package/rendering/perf-box.js +94 -0
- package/rendering/perf-probe-passes.js +333 -0
- package/rendering/perf-probe.js +406 -0
- package/rendering/water-simple.js +112 -0
- package/runtime/device-quality.js +75 -4
- package/runtime/perf-box-text.js +50 -0
- package/runtime/perf-probe.js +145 -0
- package/runtime/perf-watch.js +158 -0
- package/runtime/quality-fit.js +25 -5
- package/runtime/quality-store.js +37 -9
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_LOW_GROUPS,
|
|
4
|
+
DEFAULT_PROBE_LEGS,
|
|
5
|
+
createFrameSampler,
|
|
6
|
+
parseLowTrials,
|
|
7
|
+
parseStandAt,
|
|
8
|
+
summarizeRouteLeg,
|
|
9
|
+
} from '../runtime/perf-probe.js';
|
|
10
|
+
import {
|
|
11
|
+
measureAnisotropicReads,
|
|
12
|
+
measureDimmedLights,
|
|
13
|
+
measureGroundParts,
|
|
14
|
+
measureMirror,
|
|
15
|
+
measurePostPasses,
|
|
16
|
+
measureScriptShares,
|
|
17
|
+
measureWithMoreCalls,
|
|
18
|
+
} from './perf-probe-passes.js';
|
|
19
|
+
|
|
20
|
+
const SETTLE_MS = 12000,
|
|
21
|
+
LOOP_MS = 3000,
|
|
22
|
+
REBUILT_MS = 2000,
|
|
23
|
+
TURNS = 4,
|
|
24
|
+
FIT_SECONDS = 8,
|
|
25
|
+
RECOMPILED_MS = 35000,
|
|
26
|
+
LEG_MS = 12000;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Flies a four-leg route around the current camera position without holding quality or frame pacing,
|
|
30
|
+
* recording inter-frame intervals and reporting hitch counts (>25 ms, >50 ms, >100 ms) per leg.
|
|
31
|
+
*
|
|
32
|
+
* @param {object} options
|
|
33
|
+
* @param {THREE.Camera} options.camera Active view camera.
|
|
34
|
+
* @param {(flying: boolean) => void} options.setFly Enables flight mode.
|
|
35
|
+
* @param {(x: number, z: number, yaw: number) => void} options.placePlayer Places the player horizontally.
|
|
36
|
+
* @param {{ y: number, pitch: number }} options.player Mutable player pose.
|
|
37
|
+
* @param {(x: number, z: number) => number} options.ground Ground height sampler in metres.
|
|
38
|
+
* @param {Array<[string, number, number, number, number]>} [options.legs=DEFAULT_PROBE_LEGS] Route leg definitions.
|
|
39
|
+
* @param {number} [options.legMs=12000] Duration of each leg in milliseconds.
|
|
40
|
+
* @param {(ms: number) => Promise<void>} [options.wait] Async sleep helper.
|
|
41
|
+
* @param {() => Promise<number>} [options.nextFrame] Resolves on the next animation frame with timestamp in ms.
|
|
42
|
+
* @returns {Promise<string[]>}
|
|
43
|
+
*/
|
|
44
|
+
export async function flyProbeRoute({
|
|
45
|
+
camera,
|
|
46
|
+
setFly,
|
|
47
|
+
placePlayer,
|
|
48
|
+
player,
|
|
49
|
+
ground,
|
|
50
|
+
legs = DEFAULT_PROBE_LEGS,
|
|
51
|
+
legMs = LEG_MS,
|
|
52
|
+
wait = ms => new Promise(resolve => setTimeout(resolve, ms)),
|
|
53
|
+
nextFrame = () => new Promise(requestAnimationFrame),
|
|
54
|
+
}) {
|
|
55
|
+
const x = camera.position.x,
|
|
56
|
+
z = camera.position.z,
|
|
57
|
+
told = [];
|
|
58
|
+
setFly(true);
|
|
59
|
+
for (const [name, up, speed, direction, pitch] of legs) {
|
|
60
|
+
const half = (speed * legMs) / 2,
|
|
61
|
+
move = along => {
|
|
62
|
+
const at = x + direction * along;
|
|
63
|
+
placePlayer(at, z, (-direction * Math.PI) / 2);
|
|
64
|
+
player.y = ground(at, z) + up;
|
|
65
|
+
player.pitch = pitch;
|
|
66
|
+
};
|
|
67
|
+
move(-half);
|
|
68
|
+
await wait(1500); // let the leg's starting view settle before counting gaps
|
|
69
|
+
const gaps = [],
|
|
70
|
+
start = await nextFrame();
|
|
71
|
+
let time = start,
|
|
72
|
+
last = start;
|
|
73
|
+
while (time - start < legMs) {
|
|
74
|
+
move(-half + (time - start) * speed);
|
|
75
|
+
time = await nextFrame();
|
|
76
|
+
gaps.push(time - last);
|
|
77
|
+
last = time;
|
|
78
|
+
}
|
|
79
|
+
told.push(summarizeRouteLeg(name, gaps, time - start));
|
|
80
|
+
}
|
|
81
|
+
return told;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Self-measuring page probe for environments where external DevTools or Playwright scripts cannot
|
|
86
|
+
* drive the browser (such as mobile simulators). Reads query parameters (`?probe[=mode]`, `at`, `then`, `set`),
|
|
87
|
+
* isolates GPU, pass, shader, texture, light, mirror, and draw-call costs in displayed frames per second,
|
|
88
|
+
* and writes every finding to `noteLog`.
|
|
89
|
+
*
|
|
90
|
+
* @param {object} options
|
|
91
|
+
* @param {{ get: (name: string) => string | null }} options.query Opening URL query parameters (`URLSearchParams`).
|
|
92
|
+
* @param {{ mode: string, quality: string, frame: number }} options.state Live engine state.
|
|
93
|
+
* @param {THREE.Scene} options.scene Active world scene.
|
|
94
|
+
* @param {THREE.Camera} options.camera Active view camera.
|
|
95
|
+
* @param {THREE.WebGLRenderer} options.renderer Active renderer.
|
|
96
|
+
* @param {object} options.post Post-processing state (`on`, `samples`, `taa`, `scale`, `bloom`, `aoScene`).
|
|
97
|
+
* @param {(on: boolean, samples: number, taa: boolean) => void} options.setPost Rebuilds the post-processing pipeline.
|
|
98
|
+
* @param {object} options.mirror Planar reflection state (`off`, `cam`, `rt`).
|
|
99
|
+
* @param {Record<string, unknown>} options.quality Active preset figures (`mirror`, `worldLeast`).
|
|
100
|
+
* @param {Record<string, Record<string, unknown>>} options.presets Preset definitions (`low`, `medium`, `high`).
|
|
101
|
+
* @param {(name: string) => void} options.applyQuality Applies a named quality preset.
|
|
102
|
+
* @param {(size: number) => void} [options.setFarShadow] Updates far shadow map resolution when `farShadow` is probed.
|
|
103
|
+
* @param {() => number | null} options.cardTime Returns last GPU frame time from quality fit (ms) or `null`.
|
|
104
|
+
* @param {(held: boolean) => void} options.holdQuality Locks or releases automatic quality fitting.
|
|
105
|
+
* @param {(held: boolean) => void} options.holdPace Locks or releases adaptive frame pacing.
|
|
106
|
+
* @param {(w: number, h?: number, pr?: number) => void} options.holdSize Locks or releases viewport size.
|
|
107
|
+
* @param {() => void} options.resize Applies viewport / post-processing sizing.
|
|
108
|
+
* @param {() => number} options.viewportWidth Current viewport width in CSS pixels.
|
|
109
|
+
* @param {() => number} options.viewportHeight Current viewport height in CSS pixels.
|
|
110
|
+
* @param {(kind: string, text: string) => void} options.noteLog Diagnostic log writer.
|
|
111
|
+
* @param {() => HTMLElement | null} [options.hudElement] Returns the HUD root element toggled during the full probe.
|
|
112
|
+
* @param {() => { player: { y: number, pitch: number }, space: { ground: (x: number, z: number) => number }, setFly: (on: boolean) => void, placePlayer: (x: number, z: number, yaw: number) => void }} options.getWorld Returns live player/space placement helpers.
|
|
113
|
+
* @param {(frames?: number) => Promise<{ ms: number, cpu: number, update: number, draw: number, calls: number, tris: number, px: string }>} options.bench Back-to-back GPU-fenced frame benchmark.
|
|
114
|
+
* @param {Array<[string, string, string]>} [options.groundDefineCuts=[]] Optional `[defineName, cacheKey, label]` tuples for ground shader breakdown.
|
|
115
|
+
* @param {string[][]} [options.lowGroups=DEFAULT_LOW_GROUPS] Preset key groups swapped during `?probe=lows`.
|
|
116
|
+
* @param {Array<[string, number, number, number, number]>} [options.routeLegs=DEFAULT_PROBE_LEGS] Legs for `?probe=route`.
|
|
117
|
+
* @param {(ms: number) => Promise<void>} [options.wait] Async sleep helper in milliseconds.
|
|
118
|
+
* @param {() => number} [options.clock] Monotonic clock in milliseconds.
|
|
119
|
+
* @param {() => Promise<number>} [options.nextFrame] Animation-frame awaiter.
|
|
120
|
+
* @param {number} [options.settleMs=12000] Initial world settle wait in milliseconds.
|
|
121
|
+
* @param {number} [options.loopMs=3000] Counting window per FPS sample in milliseconds.
|
|
122
|
+
* @param {number} [options.rebuiltMs=2000] Settle wait after rebuilding a shader/pipeline in milliseconds.
|
|
123
|
+
* @param {number} [options.recompiledMs=35000] Settle wait after recompiling all lit shaders in milliseconds.
|
|
124
|
+
* @param {number} [options.turns=4] Turn-about pair count.
|
|
125
|
+
* @param {number} [options.fitSeconds=8] Seconds to sample `cardTime` alongside displayed FPS at the end of the full probe.
|
|
126
|
+
* @returns {Promise<void>}
|
|
127
|
+
*/
|
|
128
|
+
export async function runSelfProbe({
|
|
129
|
+
query,
|
|
130
|
+
state,
|
|
131
|
+
scene,
|
|
132
|
+
camera,
|
|
133
|
+
renderer,
|
|
134
|
+
post,
|
|
135
|
+
setPost,
|
|
136
|
+
mirror,
|
|
137
|
+
quality,
|
|
138
|
+
presets,
|
|
139
|
+
applyQuality,
|
|
140
|
+
setFarShadow,
|
|
141
|
+
cardTime,
|
|
142
|
+
holdQuality,
|
|
143
|
+
holdPace,
|
|
144
|
+
holdSize,
|
|
145
|
+
resize,
|
|
146
|
+
viewportWidth,
|
|
147
|
+
viewportHeight,
|
|
148
|
+
noteLog,
|
|
149
|
+
hudElement = () => null,
|
|
150
|
+
getWorld,
|
|
151
|
+
bench,
|
|
152
|
+
groundDefineCuts = [],
|
|
153
|
+
lowGroups = DEFAULT_LOW_GROUPS,
|
|
154
|
+
routeLegs = DEFAULT_PROBE_LEGS,
|
|
155
|
+
wait = ms => new Promise(resolve => setTimeout(resolve, ms)),
|
|
156
|
+
clock = () => performance.now(),
|
|
157
|
+
nextFrame = () => new Promise(requestAnimationFrame),
|
|
158
|
+
settleMs = SETTLE_MS,
|
|
159
|
+
loopMs = LOOP_MS,
|
|
160
|
+
rebuiltMs = REBUILT_MS,
|
|
161
|
+
recompiledMs = RECOMPILED_MS,
|
|
162
|
+
turns = TURNS,
|
|
163
|
+
fitSeconds = FIT_SECONDS,
|
|
164
|
+
}) {
|
|
165
|
+
const sampler = createFrameSampler({ getFrame: () => state.frame, wait, clock, loopMs, turns });
|
|
166
|
+
const { shown, shownWithout, byTurns } = sampler;
|
|
167
|
+
|
|
168
|
+
while (state.mode !== 'play') await wait(250);
|
|
169
|
+
|
|
170
|
+
if (query.get('probe') === 'route') {
|
|
171
|
+
await wait(settleMs);
|
|
172
|
+
const world = getWorld();
|
|
173
|
+
const legs = await flyProbeRoute({
|
|
174
|
+
camera,
|
|
175
|
+
setFly: world.setFly,
|
|
176
|
+
placePlayer: world.placePlayer,
|
|
177
|
+
player: world.player,
|
|
178
|
+
ground: (x, z) => world.space.ground(x, z),
|
|
179
|
+
legs: routeLegs,
|
|
180
|
+
wait,
|
|
181
|
+
nextFrame,
|
|
182
|
+
});
|
|
183
|
+
for (const leg of legs) noteLog('note', `probe at ${state.quality}, flown ${leg}`);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
holdQuality(true);
|
|
188
|
+
holdPace(true);
|
|
189
|
+
|
|
190
|
+
const stand = parseStandAt(query.get('at'));
|
|
191
|
+
if (stand) {
|
|
192
|
+
const world = getWorld();
|
|
193
|
+
world.setFly(true);
|
|
194
|
+
world.placePlayer(stand.x, stand.z, stand.yaw);
|
|
195
|
+
world.player.y = world.space.ground(stand.x, stand.z) + stand.up;
|
|
196
|
+
world.player.pitch = stand.pitch;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
await wait(settleMs);
|
|
200
|
+
const mode = query.get('probe');
|
|
201
|
+
|
|
202
|
+
if (mode === 'ground' || mode === 'light') {
|
|
203
|
+
const pieces = scene.getObjectsByProperty('name', 'ground'),
|
|
204
|
+
told = await measureGroundParts(sampler, {
|
|
205
|
+
renderer,
|
|
206
|
+
ground: pieces,
|
|
207
|
+
worn: pieces.map(piece => piece.material),
|
|
208
|
+
lightAlone: mode === 'light',
|
|
209
|
+
wait,
|
|
210
|
+
rebuiltMs,
|
|
211
|
+
defineCuts: groundDefineCuts,
|
|
212
|
+
});
|
|
213
|
+
for (const part of told.split('; ')) noteLog('note', `probe at ${state.quality}: ${part}`);
|
|
214
|
+
} else if (mode === 'passes' && post.on) {
|
|
215
|
+
const { samples, taa } = post,
|
|
216
|
+
smoothed = on => () => {
|
|
217
|
+
setPost(true, samples, on);
|
|
218
|
+
resize();
|
|
219
|
+
};
|
|
220
|
+
noteLog(
|
|
221
|
+
'note',
|
|
222
|
+
`probe at ${state.quality}: without the smoothing over frames ${await byTurns(smoothed(false), smoothed(taa), rebuiltMs)}`,
|
|
223
|
+
);
|
|
224
|
+
noteLog(
|
|
225
|
+
'note',
|
|
226
|
+
`probe at ${state.quality}: without the bloom ${await byTurns(
|
|
227
|
+
() => (post.bloom.enabled = false),
|
|
228
|
+
() => (post.bloom.enabled = true),
|
|
229
|
+
)}`,
|
|
230
|
+
);
|
|
231
|
+
} else if (mode === 'count') {
|
|
232
|
+
const counts = async () => [await shown(), await shown(), await shown()].join(' ');
|
|
233
|
+
noteLog(
|
|
234
|
+
'note',
|
|
235
|
+
`probe at ${state.quality}, ${post.on ? 'through the passes' : 'drawn straight to the screen'}: ${await counts()} frames shown`,
|
|
236
|
+
);
|
|
237
|
+
const next = query.get('then');
|
|
238
|
+
if (next) {
|
|
239
|
+
applyQuality(next);
|
|
240
|
+
await wait(settleMs);
|
|
241
|
+
noteLog(
|
|
242
|
+
'note',
|
|
243
|
+
`probe, then at ${state.quality} within the visit, ${post.on ? 'through the passes' : 'drawn straight to the screen'}: ${await counts()} frames shown`,
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (mode === 'lows') {
|
|
249
|
+
const counts = async () => [await shown(), await shown(), await shown()].join(' '),
|
|
250
|
+
own = presets[state.quality],
|
|
251
|
+
told = [`as it is ${await counts()}`],
|
|
252
|
+
trials = parseLowTrials(query.get('set'), presets, lowGroups);
|
|
253
|
+
for (const [keys, values] of trials) {
|
|
254
|
+
const kept = keys.map(key => own[key]);
|
|
255
|
+
keys.forEach((key, at) => (own[key] = values[at]));
|
|
256
|
+
applyQuality(state.quality);
|
|
257
|
+
if (keys[0] === 'farShadow' && setFarShadow) {
|
|
258
|
+
setFarShadow(values[0]);
|
|
259
|
+
await wait(recompiledMs);
|
|
260
|
+
}
|
|
261
|
+
await wait(settleMs);
|
|
262
|
+
told.push(`with ${keys.map((key, at) => `${key} ${values[at]}`).join(', ')} ${await counts()}`);
|
|
263
|
+
keys.forEach((key, at) => (own[key] = kept[at]));
|
|
264
|
+
}
|
|
265
|
+
applyQuality(state.quality);
|
|
266
|
+
await wait(settleMs);
|
|
267
|
+
told.push(`as it is again ${await counts()}`);
|
|
268
|
+
for (const part of told) noteLog('note', `probe at ${state.quality}: ${part}`);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (mode) {
|
|
272
|
+
holdQuality(false);
|
|
273
|
+
holdPace(false);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
await bench(6);
|
|
278
|
+
const whole = await bench(20),
|
|
279
|
+
frames = await shown(),
|
|
280
|
+
shadows = renderer.shadowMap,
|
|
281
|
+
drawn = scene.children.filter(child => child.visible && !child.isLight),
|
|
282
|
+
show = on => {
|
|
283
|
+
for (const child of drawn) child.visible = on;
|
|
284
|
+
};
|
|
285
|
+
const shares = await measureScriptShares({ renderer, scene, camera, getFrame: () => state.frame, wait, clock });
|
|
286
|
+
const meshes = { instanced: [], single: [] };
|
|
287
|
+
scene.traverseVisible(mesh => {
|
|
288
|
+
if (mesh.isMesh) meshes[mesh.isInstancedMesh || mesh.isBatchedMesh ? 'instanced' : 'single'].push(mesh);
|
|
289
|
+
});
|
|
290
|
+
const ground = scene.getObjectsByProperty('name', 'ground'),
|
|
291
|
+
showGround = on => {
|
|
292
|
+
for (const piece of ground) piece.visible = on;
|
|
293
|
+
},
|
|
294
|
+
showKind = (kind, on) => {
|
|
295
|
+
for (const mesh of meshes[kind]) mesh.visible = on;
|
|
296
|
+
},
|
|
297
|
+
hud = hudElement();
|
|
298
|
+
const without = {
|
|
299
|
+
shadowRedraw: await shownWithout(
|
|
300
|
+
() => (shadows.autoUpdate = false),
|
|
301
|
+
() => (shadows.autoUpdate = true),
|
|
302
|
+
),
|
|
303
|
+
bloom: post.on
|
|
304
|
+
? await shownWithout(
|
|
305
|
+
() => (post.bloom.enabled = false),
|
|
306
|
+
() => (post.bloom.enabled = true),
|
|
307
|
+
)
|
|
308
|
+
: frames,
|
|
309
|
+
hud: hud
|
|
310
|
+
? await shownWithout(
|
|
311
|
+
() => (hud.hidden = true),
|
|
312
|
+
() => (hud.hidden = false),
|
|
313
|
+
)
|
|
314
|
+
: frames,
|
|
315
|
+
instanced: await shownWithout(
|
|
316
|
+
() => showKind('instanced', false),
|
|
317
|
+
() => showKind('instanced', true),
|
|
318
|
+
),
|
|
319
|
+
single: await shownWithout(
|
|
320
|
+
() => showKind('single', false),
|
|
321
|
+
() => showKind('single', true),
|
|
322
|
+
),
|
|
323
|
+
scene: await shownWithout(
|
|
324
|
+
() => show(false),
|
|
325
|
+
() => show(true),
|
|
326
|
+
),
|
|
327
|
+
ground: await shownWithout(
|
|
328
|
+
() => showGround(false),
|
|
329
|
+
() => showGround(true),
|
|
330
|
+
),
|
|
331
|
+
};
|
|
332
|
+
const calls = [
|
|
333
|
+
await measureWithMoreCalls(sampler, { scene, camera, count: 100, wait, rebuiltMs }),
|
|
334
|
+
await measureWithMoreCalls(sampler, { scene, camera, count: 200, wait, rebuiltMs }),
|
|
335
|
+
];
|
|
336
|
+
holdSize(viewportWidth(), viewportHeight(), renderer.domElement.width / viewportWidth() / 2);
|
|
337
|
+
const halfSize = await shown();
|
|
338
|
+
holdSize(0);
|
|
339
|
+
const flat = new THREE.MeshBasicMaterial({ color: 0x6b6a4a }),
|
|
340
|
+
worn = ground.map(piece => piece.material);
|
|
341
|
+
const groundFlat = await byTurns(
|
|
342
|
+
() => ground.forEach(piece => (piece.material = flat)),
|
|
343
|
+
() => ground.forEach((piece, at) => (piece.material = worn[at])),
|
|
344
|
+
);
|
|
345
|
+
flat.dispose();
|
|
346
|
+
const groundLight = await measureGroundParts(sampler, {
|
|
347
|
+
renderer,
|
|
348
|
+
ground,
|
|
349
|
+
worn,
|
|
350
|
+
wait,
|
|
351
|
+
rebuiltMs,
|
|
352
|
+
defineCuts: groundDefineCuts,
|
|
353
|
+
});
|
|
354
|
+
const reads = await measureAnisotropicReads(sampler, { renderer, scene });
|
|
355
|
+
const worlds = [],
|
|
356
|
+
ownScale = post.scale;
|
|
357
|
+
if (post.on) {
|
|
358
|
+
for (const share of new Set([quality.worldLeast ?? ownScale, 1])) {
|
|
359
|
+
if (share === ownScale) continue;
|
|
360
|
+
const drawnAs = to => () => {
|
|
361
|
+
post.scale = to;
|
|
362
|
+
resize();
|
|
363
|
+
};
|
|
364
|
+
worlds.push(`at ${share} of each side ${await byTurns(drawnAs(share), drawnAs(ownScale))}`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const lights = await measureDimmedLights(sampler, { scene });
|
|
368
|
+
const occlusion = post.on
|
|
369
|
+
? `the occlusion pass left empty ${await byTurns(
|
|
370
|
+
() => (post.aoScene.visible = false),
|
|
371
|
+
() => (post.aoScene.visible = true),
|
|
372
|
+
)}`
|
|
373
|
+
: 'no occlusion pass under this preset';
|
|
374
|
+
const grounds = `the ground in one flat colour ${groundFlat}; ${groundLight}`,
|
|
375
|
+
upscaled = `the world, drawn at ${ownScale} of each side: ${worlds.join('; ') || 'at no other size under this preset'}`;
|
|
376
|
+
const mirrored = await measureMirror(sampler, { quality, mirror });
|
|
377
|
+
const passes = await measurePostPasses(sampler, { post, setPost, resize, frames, wait, rebuiltMs });
|
|
378
|
+
holdQuality(false);
|
|
379
|
+
holdPace(false);
|
|
380
|
+
const told = [
|
|
381
|
+
`${frames} frames shown a second; handed over back to back a frame is ${whole.ms} ms (script ${whole.cpu}: update ${whole.update}, ` +
|
|
382
|
+
`draw ${whole.draw}), ${whole.calls} calls, ${whole.tris} triangles`,
|
|
383
|
+
`frames shown without the shadows' redraw ${without.shadowRedraw}, the bloom ${without.bloom}, the HUD ${without.hud}, the instanced ` +
|
|
384
|
+
`meshes ${without.instanced}, the single meshes ${without.single}, the ground ${without.ground}, anything in the scene ${without.scene}; ` +
|
|
385
|
+
`with a hundred draw calls more ${calls[0]}, with two hundred ${calls[1]}`,
|
|
386
|
+
`at half the picture's size ${halfSize}`,
|
|
387
|
+
grounds,
|
|
388
|
+
`${lights}; ${occlusion}`,
|
|
389
|
+
reads,
|
|
390
|
+
upscaled,
|
|
391
|
+
`${mirrored}; ${passes}`,
|
|
392
|
+
`the script's time in a frame's passes: ${shares}`,
|
|
393
|
+
];
|
|
394
|
+
for (const [at, part] of told.entries()) noteLog('note', `probe ${at + 1} at ${state.quality}, ${whole.px}: ${part}`);
|
|
395
|
+
|
|
396
|
+
const timed = [];
|
|
397
|
+
for (let second = 0; second < fitSeconds; second++) {
|
|
398
|
+
const from = state.frame;
|
|
399
|
+
await wait(1000);
|
|
400
|
+
timed.push(`${cardTime()?.toFixed(1) ?? '?'} ms at ${state.frame - from}`);
|
|
401
|
+
}
|
|
402
|
+
noteLog(
|
|
403
|
+
'note',
|
|
404
|
+
`probe, the fit's timing of the card's frame in each of ${fitSeconds} seconds, with the frames shown in it: ${timed.join(', ')}`,
|
|
405
|
+
);
|
|
406
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight single-plane procedural water without planar reflections: vertex-coloured depth
|
|
3
|
+
* tinting from a caller-supplied bed depth function plus animated gentle surface wave shimmer.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as THREE from 'three';
|
|
8
|
+
import { glslVec3 } from './glsl-literal.js';
|
|
9
|
+
|
|
10
|
+
const WATER_VERTEX_PARS = /* glsl */ `varying vec2 vWaterXZ;
|
|
11
|
+
`;
|
|
12
|
+
const WATER_VERTEX_BEGIN = /* glsl */ `#include <begin_vertex>
|
|
13
|
+
vWaterXZ = position.xz;`;
|
|
14
|
+
|
|
15
|
+
const WATER_FRAGMENT_PARS = /* glsl */ `uniform float uWaterTime;
|
|
16
|
+
varying vec2 vWaterXZ;
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Builds a single horizontal water plane tinted by water depth with gentle animated wave glint,
|
|
21
|
+
* requiring no planar reflection pass or depth render target.
|
|
22
|
+
*
|
|
23
|
+
* @param {object} [options]
|
|
24
|
+
* @param {number} [options.width=800] Plane width along X (metres).
|
|
25
|
+
* @param {number} [options.depth=800] Plane extent along Z (metres).
|
|
26
|
+
* @param {number} [options.segs=128] Grid subdivisions along each axis.
|
|
27
|
+
* @param {number} [options.level=0] Water surface elevation Y (metres).
|
|
28
|
+
* @param {(x: number, z: number) => number} [options.depthAt] Water depth in metres at local `(x, z)`; defaults to constant `6`.
|
|
29
|
+
* @param {number} [options.shallowColor=0x6ea6a0] Shallow-water colour (sRGB hex).
|
|
30
|
+
* @param {number} [options.deepColor=0x245d6d] Deep-water colour (sRGB hex).
|
|
31
|
+
* @param {number} [options.shallowDepth=0.1] Depth (metres) where colour begins transitioning from shallow to deep.
|
|
32
|
+
* @param {number} [options.deepDepth=4.5] Depth (metres) where colour reaches full deep tint.
|
|
33
|
+
* @param {number} [options.roughness=0.24] Surface roughness for specular sun highlights.
|
|
34
|
+
* @param {number} [options.metalness=0.08] Surface metalness.
|
|
35
|
+
* @param {number} [options.opacity=0.9] Surface opacity (`< 1` enables alpha blending).
|
|
36
|
+
* @param {[number, number, number]} [options.glintColor=[0.08, 0.13, 0.14]] Additive RGB crest shimmer tint.
|
|
37
|
+
* @returns {{ mesh: THREE.Mesh, material: THREE.MeshStandardMaterial, timeUniform: { value: number }, update: (elapsed: number) => void, dispose: () => void }}
|
|
38
|
+
*/
|
|
39
|
+
export function createSimpleWater({
|
|
40
|
+
width = 800,
|
|
41
|
+
depth = 800,
|
|
42
|
+
segs = 128,
|
|
43
|
+
level = 0,
|
|
44
|
+
depthAt = () => 6,
|
|
45
|
+
shallowColor = 0x6ea6a0,
|
|
46
|
+
deepColor = 0x245d6d,
|
|
47
|
+
shallowDepth = 0.1,
|
|
48
|
+
deepDepth = 4.5,
|
|
49
|
+
roughness = 0.24,
|
|
50
|
+
metalness = 0.08,
|
|
51
|
+
opacity = 0.9,
|
|
52
|
+
glintColor = [0.08, 0.13, 0.14],
|
|
53
|
+
} = {}) {
|
|
54
|
+
const geometry = new THREE.PlaneGeometry(width, depth, segs, segs).rotateX(-Math.PI / 2);
|
|
55
|
+
const positions = geometry.attributes.position;
|
|
56
|
+
const colors = new Float32Array(positions.count * 3);
|
|
57
|
+
const shallow = new THREE.Color(shallowColor);
|
|
58
|
+
const deep = new THREE.Color(deepColor);
|
|
59
|
+
const tint = new THREE.Color();
|
|
60
|
+
for (let i = 0; i < positions.count; i++) {
|
|
61
|
+
const waterDepth = depthAt(positions.getX(i), positions.getZ(i));
|
|
62
|
+
const mix = THREE.MathUtils.smoothstep(waterDepth, shallowDepth, deepDepth);
|
|
63
|
+
tint
|
|
64
|
+
.copy(shallow)
|
|
65
|
+
.lerp(deep, mix)
|
|
66
|
+
.toArray(colors, i * 3);
|
|
67
|
+
}
|
|
68
|
+
geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
|
|
69
|
+
|
|
70
|
+
const material = new THREE.MeshStandardMaterial({
|
|
71
|
+
vertexColors: true,
|
|
72
|
+
roughness,
|
|
73
|
+
metalness,
|
|
74
|
+
transparent: opacity < 1,
|
|
75
|
+
opacity,
|
|
76
|
+
});
|
|
77
|
+
const timeUniform = { value: 0 };
|
|
78
|
+
const glintLiteral = glslVec3(glintColor);
|
|
79
|
+
const fragmentColor = /* glsl */ `#include <color_fragment>
|
|
80
|
+
vec2 wp = vWaterXZ;
|
|
81
|
+
float warp = sin(wp.x * 0.17 + wp.y * 0.13 + uWaterTime * 0.35) * 2.1
|
|
82
|
+
+ cos(wp.x * 0.09 - wp.y * 0.23 - uWaterTime * 0.28) * 1.6;
|
|
83
|
+
float swell = sin(wp.y * 0.85 + warp + uWaterTime * 1.05) * 0.52
|
|
84
|
+
+ sin(wp.y * 1.75 + wp.x * 0.19 - warp * 0.65 - uWaterTime * 1.35) * 0.33
|
|
85
|
+
+ sin(wp.y * 3.4 - wp.x * 0.27 + warp * 0.4 + uWaterTime * 1.8) * 0.15;
|
|
86
|
+
float shimmer = 0.45 + 0.55 * smoothstep(-0.3, 0.75, sin(wp.x * 0.29 + warp * 0.65));
|
|
87
|
+
float glint = smoothstep(0.54, 0.94, swell) * shimmer;
|
|
88
|
+
float vis = 1.0 - smoothstep(0.08, 0.5, fwidth(wp.y));
|
|
89
|
+
diffuseColor.rgb += ${glintLiteral} * glint * vis;`;
|
|
90
|
+
|
|
91
|
+
material.onBeforeCompile = shader => {
|
|
92
|
+
shader.uniforms.uWaterTime = timeUniform;
|
|
93
|
+
shader.vertexShader = WATER_VERTEX_PARS + shader.vertexShader.replace('#include <begin_vertex>', WATER_VERTEX_BEGIN);
|
|
94
|
+
shader.fragmentShader = WATER_FRAGMENT_PARS + shader.fragmentShader.replace('#include <color_fragment>', fragmentColor);
|
|
95
|
+
};
|
|
96
|
+
material.customProgramCacheKey = () => `roamwright-simple-water-v1:${glintLiteral}`;
|
|
97
|
+
|
|
98
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
99
|
+
mesh.position.y = level;
|
|
100
|
+
mesh.receiveShadow = true;
|
|
101
|
+
|
|
102
|
+
function update(elapsed) {
|
|
103
|
+
timeUniform.value = elapsed;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function dispose() {
|
|
107
|
+
geometry.dispose();
|
|
108
|
+
material.dispose();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return { mesh, material, timeUniform, update, dispose };
|
|
112
|
+
}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
const SOFTWARE = /swiftshader|llvmpipe|software|basic render/i;
|
|
2
2
|
const INTEGRATED = /intel|mali|adreno|powervr/i;
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* First guess at the quality preset a device can hold, from what the browser reports before any frame is timed:
|
|
6
|
+
* `'low'` where it draws in software or has little memory, `'medium'` for a handheld device with enough memory,
|
|
7
|
+
* and `'high'` for a desktop with sufficient cores, memory, and a discrete GPU.
|
|
8
|
+
*
|
|
9
|
+
* @param {object} options
|
|
10
|
+
* @param {{ getContext: () => WebGLRenderingContext }} options.renderer Active WebGL renderer.
|
|
11
|
+
* @param {import('./device.js').Device | null} [options.device=null] Device description from `readDevice` or `describeDevice`.
|
|
12
|
+
* @param {() => boolean} [options.handheld] Override for whether the device is handheld (defaults to `device.handheld`).
|
|
13
|
+
* @param {() => number | undefined} [options.memoryGB] Override for device memory in GB (defaults to `device.memoryGB`).
|
|
14
|
+
* @param {() => number | undefined} [options.cores] Override for logical core count (defaults to `device.cores`).
|
|
15
|
+
* @param {number} [options.smallMemory=2] Memory at or below this (GB) always selects `'low'`.
|
|
16
|
+
* @param {number} [options.phoneMemory=4] Handheld memory at or below this (GB) selects `'low'`.
|
|
17
|
+
* @param {number} [options.desktopMemory=8] Desktop memory below this (GB) selects `'medium'`.
|
|
18
|
+
* @param {number} [options.desktopCores=8] Desktop cores below this selects `'medium'`.
|
|
19
|
+
* @returns {{ deviceQuality: () => 'low' | 'medium' | 'high', drawnInSoftware: () => boolean }}
|
|
20
|
+
*/
|
|
8
21
|
export function createDeviceQuality({
|
|
9
22
|
renderer,
|
|
10
23
|
device = null,
|
|
@@ -36,3 +49,61 @@ export function createDeviceQuality({
|
|
|
36
49
|
}
|
|
37
50
|
return { deviceQuality, drawnInSoftware };
|
|
38
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Ground render order for a device: on a performance-aimed device (a phone), the ground is drawn after
|
|
55
|
+
* opaque buildings, trees, and figures so depth testing rejects covered ground pixels instead of shading them.
|
|
56
|
+
* Quality-aimed devices (desktops and tablets) keep render order `0`.
|
|
57
|
+
*
|
|
58
|
+
* @param {import('./device.js').Device | null | undefined} device Device description from `readDevice` or `describeDevice`.
|
|
59
|
+
* @param {number} [performanceOrder=5] Render order used on performance-aimed devices.
|
|
60
|
+
* @returns {number}
|
|
61
|
+
*/
|
|
62
|
+
export function groundRenderOrder(device, performanceOrder = 5) {
|
|
63
|
+
return device?.aim === 'performance' ? performanceOrder : 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Builds the active preset table for a device without mutating the base presets. On a performance-aimed
|
|
68
|
+
* device, matching entries from `performanceOverrides` are merged into the cloned preset objects; on a
|
|
69
|
+
* quality-aimed device, the base presets are kept as-is.
|
|
70
|
+
*
|
|
71
|
+
* @template {Record<string, Record<string, unknown>>} T
|
|
72
|
+
* @param {T} basePresets Base preset definitions (for example `{ low, medium, high }`).
|
|
73
|
+
* @param {import('./device.js').Device | null | undefined} device Device description from `readDevice` or `describeDevice`.
|
|
74
|
+
* @param {Partial<Record<keyof T, Record<string, unknown>>>} [performanceOverrides={}] Per-preset overrides applied when `device.aim === 'performance'`.
|
|
75
|
+
* @returns {T}
|
|
76
|
+
*/
|
|
77
|
+
export function resolveDevicePresets(basePresets, device, performanceOverrides = {}) {
|
|
78
|
+
const perf = device?.aim === 'performance';
|
|
79
|
+
const resolved = {};
|
|
80
|
+
for (const name of Object.keys(basePresets)) {
|
|
81
|
+
const override = perf ? performanceOverrides[name] : null;
|
|
82
|
+
resolved[name] = override ? { ...basePresets[name], ...override } : { ...basePresets[name] };
|
|
83
|
+
}
|
|
84
|
+
return /** @type {T} */ (resolved);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Chooses the post-processing pipeline settings for an active quality preset and display density.
|
|
89
|
+
* A preset without post-processing draws directly to the canvas only if the canvas itself was created
|
|
90
|
+
* with antialiasing (`canvasSmooth`); otherwise it stays on the post-processing path with multisampled
|
|
91
|
+
* scene targets (capped to 2x on high-density displays where four device pixels already cover each CSS pixel).
|
|
92
|
+
*
|
|
93
|
+
* @param {object} options
|
|
94
|
+
* @param {{ post?: boolean, samples?: number, taa?: boolean }} options.preset Active quality preset figures.
|
|
95
|
+
* @param {boolean} [options.canvasSmooth=false] Whether the WebGL canvas was created with `antialias: true`.
|
|
96
|
+
* @param {number} [options.pixelRatio=1] Current display pixel ratio (`devicePixelRatio`).
|
|
97
|
+
* @param {number} [options.highDensityThreshold=1.75] Pixel ratio at or above which >2 MSAA samples drop to 2.
|
|
98
|
+
* @returns {{ enabled: boolean, samples: number, taa: boolean }}
|
|
99
|
+
*/
|
|
100
|
+
export function choosePostPipeline({ preset, canvasSmooth = false, pixelRatio = 1, highDensityThreshold = 1.75 }) {
|
|
101
|
+
const direct = !preset.post && canvasSmooth;
|
|
102
|
+
const rawSamples = preset.post ? (preset.samples ?? 0) : 4;
|
|
103
|
+
const samples = rawSamples > 2 && (pixelRatio || 1) >= highDensityThreshold ? 2 : rawSamples;
|
|
104
|
+
return {
|
|
105
|
+
enabled: !direct,
|
|
106
|
+
samples,
|
|
107
|
+
taa: Boolean(preset.post && preset.taa),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const BYTES_IN_MB = 1048576;
|
|
2
|
+
const megabytes = bytes => `${Math.round(bytes / BYTES_IN_MB)} MB`;
|
|
3
|
+
const share = (ms, fps) => Math.min(100, Math.round((ms * fps) / 10));
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates the retained state for the on-screen performance box across readout intervals.
|
|
7
|
+
* Memory is estimated less frequently than FPS, so the most recent estimate is carried forward.
|
|
8
|
+
*
|
|
9
|
+
* @returns {{ memory: { script: number, meshes: number, textures: number, targets: number } | null }}
|
|
10
|
+
*/
|
|
11
|
+
export function createPerfBoxState() {
|
|
12
|
+
return { memory: null };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Formats one readout sample into the text lines shown by the on-screen performance box:
|
|
17
|
+
* FPS, physical pixel dimensions, optional RAM/script/meshes/textures/frame estimates,
|
|
18
|
+
* CPU percentage, optional GPU percentage, and active thread count.
|
|
19
|
+
*
|
|
20
|
+
* Pure arithmetic with no DOM or Three.js dependencies so it runs identically in a worker
|
|
21
|
+
* (drawing onto an `OffscreenCanvas`) or on the main thread as a text fallback.
|
|
22
|
+
*
|
|
23
|
+
* @param {{ memory: { script: number, meshes: number, textures: number, targets: number } | null }} kept Retained state from `createPerfBoxState()`.
|
|
24
|
+
* @param {object} sample Raw measurements collected over the readout interval.
|
|
25
|
+
* @param {number} sample.seconds Duration of the readout interval in seconds.
|
|
26
|
+
* @param {number} sample.frames Number of frames rendered during the interval.
|
|
27
|
+
* @param {number} sample.scriptMs Total main-thread script milliseconds summed over `frames`.
|
|
28
|
+
* @param {number | null} sample.cardMs GPU time of one frame in milliseconds, or `null` when unavailable.
|
|
29
|
+
* @param {number} sample.wide Drawing buffer width in physical pixels.
|
|
30
|
+
* @param {number} sample.high Drawing buffer height in physical pixels.
|
|
31
|
+
* @param {{ script: number, meshes: number, textures: number, targets: number } | null} [sample.memory] Latest memory breakdown in bytes, if refreshed.
|
|
32
|
+
* @param {number} sample.threads Active thread count (main + pool workers + metrics worker + service worker).
|
|
33
|
+
* @returns {string[]}
|
|
34
|
+
*/
|
|
35
|
+
export function formatPerfBoxLines(kept, sample) {
|
|
36
|
+
if (sample.memory) kept.memory = sample.memory;
|
|
37
|
+
const fps = sample.frames / sample.seconds,
|
|
38
|
+
lines = [`${fps.toFixed(0)} fps`, `${sample.wide} x ${sample.high} px`],
|
|
39
|
+
m = kept.memory;
|
|
40
|
+
if (m) {
|
|
41
|
+
// A leading ~ marks estimates reckoned from GPU buffer and texture sizes, which browsers do not report directly.
|
|
42
|
+
lines.push(`RAM ~${megabytes(m.script + m.meshes + m.textures + m.targets)}`);
|
|
43
|
+
if (m.script) lines.push(` script ${megabytes(m.script)}`);
|
|
44
|
+
lines.push(` meshes ~${megabytes(m.meshes)}`, ` textures ~${megabytes(m.textures)}`, ` frame ~${megabytes(m.targets)}`);
|
|
45
|
+
}
|
|
46
|
+
lines.push(`CPU ${share(sample.scriptMs / sample.frames, fps)}%`);
|
|
47
|
+
if (sample.cardMs !== null) lines.push(`GPU ${share(sample.cardMs, fps)}%`);
|
|
48
|
+
lines.push(`threads ${sample.threads}`);
|
|
49
|
+
return lines;
|
|
50
|
+
}
|