makePerf()
Measure frame times and adapt the render scale to hit a frame-time target. Feed it every rendered frame; it lowers the scale quickly when frames run over budget and raises it in 0.05 steps when they fit, remembering a scale that proved too slow for retryAfterMs. With enabled it also adds a small...
function makePerf(opts: PerfOptions): Perf;Defined in: perf.ts:102
Measure frame times and adapt the render scale to hit a frame-time target.
Feed it every rendered frame; it lowers the scale quickly when frames run
over budget and raises it in 0.05 steps when they fit, remembering a scale
that proved too slow for retryAfterMs. With enabled it also adds a small
overlay to document.body, so it needs a browser.
Frame times come from performance.now() deltas between rendered frames,
so they include vsync waits: under a 60 Hz display nothing reads below
16.7 ms.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts | PerfOptions | Starting scale, limits, target and overlay settings. |
Returns
The controller; apply scale() to gpu.renderScale each frame.
Example
import { makeFrameLoop, makePerf, resizeToDisplay } from "@voxolith/renderer";
const perf = makePerf({
enabled: new URLSearchParams(location.search).has("perf"),
scale: gpu.renderScale,
minScale: gpu.software ? 0.25 : 0.4,
});
const loop = makeFrameLoop({
continuous: true,
render: (now) => {
perf.frame(now);
gpu.renderScale = perf.scale();
resizeToDisplay(gpu);
renderer.render({ ...camera(now / 50), ...sky });
},
});makeMuzzleFlash()
A gun's muzzle flash that repeats like sustained fire: a 0.13 s flash, then a dark gap, every 0.42 s. The muzzle sits left of centre and fires towards +x, so the flash reads in profile. Headless; the palette uses slots 1..7.
makeSparse()
An empty sparse volume of size (the size is copied).