Graphics Quality and Devices
Games built with Relu run in a browser on anything from a five-year-old phone to a gaming PC. QualitySystem detects the device, starts it on a preset that will run well, applies the player's graphics settings live, and lowers the resolution by itself when frames get slow. Since spatial-ecs 0.18.0 (SPATIAL_ECS_FEATURES.qualityPresets).
Presets
| Preset | Pixel ratio up to | Shadows | Shadow maps up to | Post effects | level |
|---|---|---|---|---|---|
| Low | 1 | off | 512 | off | 0 |
| Medium | 1.5 | low | 1024 | light (no ambient occlusion or depth of field) | 1 |
| High | 2 | high | 2048 | full | 2 |
| Ultra | 3, inside a 4K pixel budget | high | 4096 | full | 3 |
The pixel ratio is the biggest single cost on a phone: a 3x screen at full resolution draws nine times the pixels of 1x. Every preset caps it, and the player's resolution scale (0.5 to 1) multiplies it.
auto (the default) uses the device's recommendation. Picking a preset sets its switches; moving a switch by hand makes the preset custom.
The recommendation
detectDevice() reads what the browser shares: touch and screen size (phone or tablet), the OS, CPU cores, memory, the pixel ratio, and the GPU's name (from WebGL's WEBGL_debug_renderer_info, or the WebGPU adapter). recommendQualityPreset() turns that into a preset with reasons:
- an entry-level phone GPU, 3 GB of memory or less, or 4 cores or fewer on a phone: Low
- other phones and tablets: Medium (a fast tablet: High)
- a computer drawing in software, with no GPU: Low
- built-in laptop graphics (Intel UHD, Iris): Medium
- discrete GPUs and Apple silicon: High
- data saver on: one preset lower
Ultra is never recommended; it's for players who choose it. Safari names every Apple GPU "Apple GPU", so a Mac in Safari is taken as Apple silicon.
import { Behaviour } from "@relu-interactives/spatial-ecs";
export default class GraphicsInfo extends Behaviour {
protected init() {
const quality = this.quality;
if (!quality) return;
console.log(quality.device?.gpu, quality.device?.mobile);
console.log(quality.recommended.preset, quality.recommended.reasons); // "medium", ["a phone"]
console.log(quality.limits); // what's applied now
}
}Scale content by level
The preset doesn't know your particles or grass. Read this.quality.level (0 low to 3 ultra) and scale what's expensive:
import { Behaviour } from "@relu-interactives/spatial-ecs";
export default class Grass extends Behaviour {
private stop: (() => void) | null = null;
protected init() {
this.build(this.quality?.level ?? 2);
// A player changing the preset mid-game rebuilds it.
this.stop = this.quality?.onChange((limits) => this.build(limits.level)) ?? null;
}
private build(level: number) {
const blades = [2000, 6000, 15000, 30000][level];
void blades; // (re)build with this many
}
dispose() {
this.stop?.();
}
}Dynamic resolution and frame rate
With graphics.dynamicResolution on (the default), the system watches the frame time: after about 1.5 s below the target (60 fps, or the player's cap) it lowers the resolution by 10%, down to 60%, and after 4 s comfortably above it raises it again by 5%. Hitches longer than a quarter of a second and paused frames don't count. this.quality.resolutionScale is the scale now, this.quality.fps the frame rate.
graphics.frameRateCap (30 or 60) saves battery. The host's loop asks world.quality?.shouldRunFrame(now) before each frame. graphics.showFps draws a small counter in the corner.
Changing graphics from a settings screen
Everything goes through settings, which saves it:
import { Behaviour, QUALITY_PRESETS } from "@relu-interactives/spatial-ecs";
export default class GraphicsMenu extends Behaviour {
choosePreset(name: "auto" | "low" | "medium" | "high" | "ultra") {
this.quality?.setPreset(name);
}
setShadows(shadows: "off" | "low" | "high") {
this.settings.update({ graphics: { shadows } }); // the preset becomes "custom"
}
label(): string {
const quality = this.quality;
if (!quality) return "";
const preset = this.settings.section("graphics").preset;
return preset === "auto" ? `Auto (${QUALITY_PRESETS[quality.recommended.preset].label})` : preset;
}
}What it changes
renderer.setPixelRatio, from the preset's cap, the player's scale and the governorrenderer.shadowMap.enabled, and every light's shadow map size, capped- post-processing:
lightturns off ambient occlusion and depth of field,offturns the whole chain off
It does nothing in the editor, and leaves the resolution alone while an XR headset is presenting.
Host setup
import { QualitySystem } from "@relu-interactives/spatial-ecs";
const quality = new QualitySystem({ targetFps: 60, minDynamicScale: 0.6 });
// world.setup({ systems: [input, quality, ...] })Budgets for the web
Rough numbers a scene should stay under to hold 60 fps on each kind of device:
| Phone (Low/Medium) | Laptop (Medium/High) | Desktop (High) | |
|---|---|---|---|
| Draw calls | 100 | 300 | 800 |
| Triangles on screen | 150k | 750k | 2M |
| Textures | 1024 px, 64 MB in all | 2048 px | 2048-4096 px |
| Shadow-casting lights | 1 | 1-2 | 2-4 |
| Download before play | 15 MB | 40 MB | 80 MB |
Repeated models should be instanced; models should be optimised (meshopt, WebP textures) before they ship.

