Display optimisation

Usage guide of the render.optimize kit: the levers (instancing, merge, cull, streaming, kept static shadows, warm, vat) and their defaults, departures per entity (passport section, rules, tags, setEntity, the hook render.optimize.entity), how each engine applies them, debug.

Source: module-kits:kits/render_optimize/usage/en.mdView Markdown source

Also read offline — CLI: grip-forge docs render-optimizeMCP tool: gripforge_docs { "topic": "render-optimize" }

Display optimisation of your game (render.optimize) #

One set of switches over what an engine already knows to make a scene cheap to draw: models loaded once and shared, static scenery merged, what is off camera hidden, far zones of a level hidden, shadows of what does not move kept. Readable offline: gripforge docs render-optimize, or the MCP tool gripforge_docs (topic render-optimize).

What it is for #

The kit decides, the engine applies with its own mechanisms. You do not write a batching or culling pass: you say which levers are on, and for the few objects that must be treated differently, how. Nothing is unloaded unless you ask for it (streaming.unload), and nothing is recompiled: the kit is data the engine reads.

It is separate from render.lod (which mesh level to show): they do not depend on each other. They meet only in the engine, each reading its own data. The level of detail of one entity (forced, fixed, none) stays render.lod's: tags lod.level.<n> and lod.off.

Turn it on #

render.optimize is installed, with the defaults below, in every new game, and strongly recommended; existing games receive it at their next opening. A game declares only what departs from the defaults:

gripforge_gamekit_install   { project_id: "gkp_…", id: "render.optimize" }
gripforge_gamekit_configure { project_id: "gkp_…", id: "render.optimize",
                              config: { "merge": { "instanceTriangles": 0 }, "streaming": { "unload": true } } }
gripforge_gamekit_configure { project_id: "gkp_…", id: "render.optimize", enabled: false }   # off, kept installed

enabled: false inside the config turns every lever off for the game (the engine draws the files as they are). The full reference is gripforge kit api render.optimize.

The levers and their defaults #

LeverWhat the engine doesDefault
instancinga model is loaded once; every copy shares its meshes and materials (one handle, one batch); identical contents from different files share one handle tooon
mergethe static parts of a scene that share a material become one mesh, by chunkson
cullwhat is off camera is hidden (frustum culling); nothing is unloadedon
streaminga level drawn zone by zone shows the zones around the camera; the others are hidden after linger secondson, unload: false
staticShadowsthe shadow of the static scenery is drawn once and kept (WebGPU)off
warmthe pipelines of what appears during play are made while the game loadson
vata unit that covers little of the screen (a minion of a crowd) is drawn from its animation baked into its game copy (vertex animation textures): no skeleton, one draw per model; near the camera it has its skeleton backon
scenethe nodes of your game that a passport declares (kits.optimize) get the engine's own tools; a node without a passport is never touchedon (declared nodes only)

Each lever has enabled (default true; false: the engine does as if the lever did not exist) and these keys:

KeyDefaultMeaning
merge.instanceTriangles400a mesh drawn several times is merged only up to this many triangles; above it stays instanced; 0 = never merge copies
merge.partTriangles4000no part above this many triangles is merged (it keeps its own culling)
merge.vertices60000vertices of one merged mesh at most
streaming.unloadfalsetrue: a zone far from the camera is unloaded (spawned again on the way back) instead of hidden
streaming.linger4seconds a zone that left the ring stays shown
streaming.perFrame8looks of zone pieces made per frame at most
streaming.near2rooms nearest the camera kept drawn (plus those their doors lead to) when a level leaves the number to the renderer (world.rooms levelNear: 0); 0 draws every room
staticShadows.snap0.125how far the kept shadow reaches past the view, as a fraction of its side
warm.models32models drawn ahead at most
vat.screen0.2a unit covering less than this fraction of the height of the view is drawn from its baked animation
rules{}policies by entity kind or tag (below)

staticShadows is off by default because the frame that draws the kept shadow again has no moving shadow: turn it on when the game can afford that frame.

Departures per entity #

An entity departs from the levers with three switches:

  • alwaysShown: never hidden off camera, never streamed out (a sky, a landmark seen through a window);
  • instancing: false: its meshes and materials are its own and it is not merged (a model a kit recolours per copy);
  • static: true or false (mode: "static" / "dynamic"): static is merged with the scenery and its shadow kept; dynamic is never merged (anything that moves).

They are read in this order, each over the previous one:

  1. the passport of the model, section kits.optimize (keys alwaysShown, instancing, static, mode): the GripForge passport, then the game's override in its asset_passports document: { "id": "<slot>", "passport": { "kits": { "optimize": { "mode": "dynamic" } } } };
  2. the rules: the config key rules and the registry optimize_rules, by entity kind or tag. A rule is { "id": "door", "match": ["door", "gate"], "mode": "dynamic" } (when match is empty, id is what it matches). A kit, a game or a mod adds one;
  3. the tags of the entity: optimize.alwaysShown, optimize.noInstancing, optimize.static, optimize.dynamic, and optimize.off (all three at once: shown, not instanced, dynamic);
  4. setEntity(id, policy) at run time (setEntity(id, null) clears it);
  5. the hook render.optimize.entity: a tap sees { entity, kind, alwaysShown, instancing, static }, may change the three switches, or cancel the decision, in which case the entity follows the levers.
{ "rules": { "door": { "static": false }, "skybox": { "alwaysShown": true } } }

Hooks, mods, registries #

WhatNameDetail
Hookrender.optimize.entitymutable alwaysShown, instancing, static; cancellable; web and native player
Registryoptimize_rulespolicies by kind or tag; inherited by games, extended by kits and mods
Moddable configenabled, instancing, merge, cull, streaming, staticShadows, warm, vat, scene, rulesa mod changes them like the game does
Eventoptimize.changed { epoch }a lever or the policy of an entity changed; engines read state() again

Service #

state() ({ epoch, enabled, settings, entities }: the levers in the engine's shape and only the entities that depart from them), settings(), lever(name), setLever(name, value | null), enabled(), setEnabled(on), policy(id), setEntity(id, policy | null), rules(), addRule(kindOrTag, policy), stats(), epoch(). The native player reads state() as its view render.optimize.state, again only on optimize.changed, never every frame.

Engines #

The kit decides; each engine applies the levers with its own tools, and the three switches of an entity (alwaysShown, instancing, static) mean the same everywhere.

EngineInstancingOff cameraalwaysShowninstancing: false
Web and native playercopies share one handle; static parts merged; zones streamed; kept static shadows; pipelines warmedhidden, not unloadednever hidden or streamed outmeshes and materials of its own
Godotcopies share the meshes of a template and are drawn as instanceshidden by the engine's frustum and occlusion cullingbounds that cover the world, no occlusionmeshes of its own
Unityone template instantiated, materials with GPU instancinghidden by the engine's cullingbounds that cover the world, no occlusionmeshes of its own
Unrealcopies share the static mesh, drawn as instanced drawshidden by the engine's cullingbounds that cover the world, no distance culla mesh of its own

Merging, zone streaming, kept shadows and warming are levers of the web and native players; the engines keep their own for those.

vat is a lever of the web and native players (Bevy): the animation it plays is baked into the game copy of every skinned model (passport kits.lod.vat, guide lod); a clip that was not baked keeps the skeleton. The Godot, Unity and Unreal adapters that play the same data come in a later batch.

scene is a lever of the Godot adapter today (Unity, Unreal and Bevy next). Since 1.5.0 it touches only the nodes of your game that a passport declares: a node of your game without a passport, or whose passport has no kits.optimize section, is left exactly as you made it — never ranged, culled nor stripped of its shadow, whatever its size (the debug counter sceneUndeclared counts them). Nothing is guessed from the nodes of your game. What the kits create themselves (their entities, their models) keeps every lever.

To plug a node in, give it a passport; it is read in place, once per drawable:

  • the gripforge object of its glTF extras ({ "gripforge": { "kits": { "optimize": { … } } } }, which Godot imports as the meta extras): the passport the tools generate for your models;
  • the meta gf_passport (a Dictionary or its JSON) on the node, its mesh or an ancestor up to the root of the model, set from GDScript; set after the node entered the tree, call refresh() so the engine reads it again;
  • the passport beside the model's file (car.glb → car.gfmesh.json, as the delivery writes it);
  • the config scenePassports: { "<group, meta or tag>": <kits.optimize section> }, matched on the node or an ancestor (the node's own passport wins), e.g. { "props": {} } for the defaults of the lever.

Its kits.optimize section sets it: {} takes the lever's keys, false leaves it as you made it (gf_optim_off is the shortcut), alwaysShown: true or cull: false never limit it by distance, cullScreen replaces the lever's value for this model, castShadow keeps (true) or drops (false) its shadow. The keys of the lever, for declared nodes: cullScreen (0.008: a drawable covering less than this fraction of the height of the view is not drawn, with the cull lever), shadowMinRadius (0.05 m: no shadow under it), shadowDistance (0: untouched), viewDistance (0: the far plane of your camera is never touched), occlusion (false: the engine's occlusion culling is turned on only when you set it to true). The level bias is not a key of this lever: it is the one of render.lod (section kits.lod). The debug counter scenePassport counts the drawables a passport set.

Some declared drawables are still never limited by distance and keep their shadow, because their bounds do not tell their real size: a mesh with a custom bounding box or an extra cull margin, a mesh whose shader moves its vertices, and anything under a node in the group or with the meta gf_terrain. The debug counter sceneLoose counts them.

# Godot: hand the props to render.optimize, keep a landmark always drawn.
for prop in get_tree().get_nodes_in_group("props"):
    prop.set_meta("gf_passport", { "kits": { "optimize": {} } })
$Tower.set_meta("gf_passport", { "kits": { "optimize": { "alwaysShown": true } } })
host.call_service("render.optimize", "refresh", [])

Or in the config of the kit: { "render.optimize": { "scenePassports": { "props": { "cullScreen": 0.01 } } } }.

Debug #

The debug inspector (F3) has a mode Display optimisation: the levers (switch them there to compare), the entities that depart from them, and the engine's own counters: triangles, draws, instances (copies sharing a mesh), meshes hidden off camera, zones hidden, parts merged. setLever from a script does the same.

When it does not do what you expect #

SymptomCause and fix
A moving object looks cut or stays in placeit was merged as static: mark it dynamic (rule, passport mode, tag optimize.dynamic)
A recoloured model recolours every copycopies share their material: instancing: false for that model
Something disappears when seen through a windowculling saw it off camera: alwaysShown
The moving shadow is missing for a framestaticShadows redraws the kept shadow on that frame: leave it off, or accept it
Memory does not go downstreaming hides zones, it unloads only with streaming.unload: true

<!-- kit-services:begin -->

Services this kit uses (and that you can provide) #

CapabilityRequiredMethods
asset.metaoptionalsection

Any brick can serve them: a kit, or your engine (Godot provide_service, Unity Provide, Unreal ProvideService, Bevy provide_kit_service, C gfk_provide) — see the guide. <!-- kit-services:end -->