Skip to content

Detail and far scenery ​

Levels of detail draw each thing as much as its size on screen deserves: the full model up close, a lighter one farther off, a picture (impostor) in the distance, nothing past that. On a generated forest map seen from far, this took a frame from 33–50 ms to the display's rate (40.6 million triangles down to 2.3 million).

Quick start ​

ts
export const view: GameView = {
	units: { looks: {} },
	world: {
		detail: {
			levels: [{}, { ratio: 0.4, from: 40 }, { ratio: 0.15, from: 80 }, { draw: 'impostor', from: 140 }],
			shadowBias: 1 // cast shadows from the next lighter level
		}
	}
}

Every model is drawn full under 40 cells, at 40% of its triangles to 80, 15% to 140, and as a picture past that. Models of @v12-engine/assets already have their 40% and 15% files.

Common tasks ​

Make lighter levels of your models ​

sh
npm run lod -- public/games/mygame/models/castle.glb       # castle.lod1.glb (40%) and castle.lod2.glb (15%) beside it
npm run lod -- public/models --ratios 0.5,0.2             # every model of a folder, other parts kept
npm run lod -- public/models/kit --borders                # pieces that tile: their seams still meet
npm run lod -- public/models --check                      # which have none, or levels older than they are

Or use the Model view's Make levels in the editor, or make them in the page with detail: { simplify: true } (a few ms a model, kept in the browser).

Keep a boss or your own castle at full detail ​

ts
detail: {
	levels: [{}, { ratio: 0.4, from: 40 }],
	important: (entity) => entity.def.id === 'lich', // like what is selected and hovered
	pick: (context, picked) => (context.target.entity?.def.id === 'castle' && context.target.entity.owner === me ? 0 : picked)
}

Set levels for one model or one map ​

GameView.world.detail.models['forest/pine_1.glb'] sets one model's levels; ModelDef.detail and SceneryDef.detail set them on the model itself. A map's MapEnvironment.detail has its own levels, scale on every distance, cull (no scenery past it) and shadowBias. A doodad's MapDoodad.detail pins a level.

Fade between levels without a pop ​

ts
world: { sceneryBatching: { fade: 0.4 } } // seconds; 0 switches at once

Read detail state in code ​

GameView.world.detail can be a function given the scene's WorldDetail (client.detail, the editor's editor.detail): pick, freeze, full, levelOf({ doodad: id }), onSwitch(listener), levelsOf(model), stats.

Editor ​

  1. Look › Detail: the map's levels, distances, the cull distance and shadow levels.
  2. View › Detail levels (Shift+V) tints what is at which level (green full, then yellow, orange; blue a picture; red where nothing is). View › Full detail draws everything as made.
  3. In the Inspector, pin a doodad to a level.
  4. The Model view's Detail tab shows each level's triangles, savings and file size side by side; Make levels and Remove work on your game's own models.
  5. Metrics counts things per level, switches a second, and memory.

Reference ​

A level ​

FieldWhat
fromcells from the camera (3D distance)
underpixels tall on screen, at most
regionwhile the camera is over a region
whenyour code decides
ratiothe made file nearest that share of triangles
drawanother model ({ src, scale } or model: 'trees/bush.glb'), 'impostor', or 'none'
shadowthe level its shadow is cast from (a level of nothing for none)
load'lazy' (within 1.5× its distance), 'eager', 'never' (client.detail.load(model), preload(models)), or { region }

The first level is the full model; of a thing's levels, the last that applies is drawn. A threshold holds until the thing is 15% nearer, so nothing flickers (DETAIL_HYSTERESIS).

Who decides, last wins ​

  1. The model (ModelDef.detail, SceneryDef.detail).
  2. The game by model (GameView.world.detail.models), or for every model (GameView.world.detail.levels).
  3. The map (MapEnvironment.detail).
  4. The thing (MapDoodad.detail, UnitLook.detail).
  5. Your code (important, pick).

How levels are made ​

A level is the model simplified part by part (meshoptimizer), materials kept by name, pictures and clips left out: it draws with the full model's. Flat-shaded parts stay flat; a character keeps its skeleton. Models under 300 triangles get none. Your assets.json lists them (levels); the shared ones are in models/levels.json.

Shadows, pictures and memory ​

  • Shadows: shadowBias: 1 casts every shadow from the next lighter level; a level's shadow names another.

  • Pictures (draw: 'impostor'): the model is drawn once from sixteen directions and from above into an atlas (with normal atlases, 7.5 MB a model), and each copy is a card showing the two nearest views blended, lit by the scene's lights as the model would be (client.detail.pictureLight brighter or darker). Past 72° down it switches to the view from above. A picture casts the shadow of a card facing the sun. Scenery, trees and mines use pictures; units and buildings stop at their lightest model (a picture would stand in its rest pose, in no player's colour). On the dev sandbox at 2×, trees as pictures past 40 cells took a frame from 33 to 25 ms.

  • Memory: over budgetMB (256), what nothing drew for a minute is let go, farthest first, and no more pictures are made. Merged scenery keeps up to 64 MB of past merges, so zooming out and in again doesn't merge again.

  • Fades: fade dithers from one level to the next on an 8 × 8 pattern, so nothing is see-through or drawn twice; the shadow switches at the middle. Trees and mines as entities fade the same way (EntityRenderer.staticFade); pictures switch at once. Dithering shows without temporal anti-aliasing, so place from past what the usual camera sees (melee uses 60 and 100 for a camera 45 cells up).

  • Merging: a chunk of scenery is merged a part at a time within the frame budget (GameView.world.frameBudget: 4 ms of merging, of 6 ms for all deferred work; see Large battles), nearest first.

  • Grass and bushes have levels of their own (FoliageLook.levels): fewer and lighter tufts further off, bushes by their lighter files, never pictures. See Grass and bushes.

The quality setting ​

The player's detail (Settings › View › Detail: Near, Medium, Far) multiplies every distance by 0.5, 0.75 or 1. Presets set it like any knob (GameView.world.quality.presets).

Measured ​

On a 512 × 512 generated map (35,928 doodads, four tree models of 3,600–6,300 triangles), WebGPU at 2×:

ViewAll at fullWith levels and pictures
default21.7 M triangles, 17–33 ms4.7–4.9 M, 16.7 ms
far40.6 M triangles, 33–50 ms2.3–2.6 M, 16.7 ms
corner7.2 M triangles, 16.7 ms2.0 M, 16.7 ms
edge9.5 M triangles, 16.7 ms2.6 M, 16.7 ms

The shadow pass went from 5.6–16.7 ms to 3–6 ms; 503 footmen from far from 10.8 M triangles to 2.3 M.