World Capabilities
Large streamed 3D worlds compose optional capability crates on top of engine-stage and engine-stage-render. Hosts that do not use them never link them.
Static Regions
Stage::create_region(placements, cell, layers) packs large static placement sets into flat pre-grouped GPU buffers (grouped by cubic cell and material bindings on 16-instance boundaries with per-group bounding spheres).
- Each camera culls by group sphere and issues one instanced batch per visible group (
SurfaceBatch::region), keeping CPU frame cost proportional to visible groups rather than placement count. set_region_rangeskips distant groups;set_region_caststoggles shadow casting (CasterBatch::region);create_region_lit(..., LightingModel::Pbr)packs PBR material parameters. Blended placements stay as sorted nodes.
Converted Assets (engine-stage-assets)
- Reads converted
.xmeshstatic meshes,.xskinbind poses, and.ktx2textures (including BC1/2/3/7 and palette formats) into stageMeshDataand RGBA mip levels. - Converts world axes (X forward, Y right, Z up, clockwise) into stage axes (X right, Y up, Z back, counter-clockwise) via
stage_point,stage_matrix,camera_transform, andpoint_light. MaterialLibrary::surfaceresolves converted materials to textures, alpha test, and sidedness;emitters::stage_emittermaps sprite emitters onto stageEmitters (listing unsupported features inEmitterPlan::unsupported).
Cells & Portals (engine-stage-cells)
Cameras carry a zones visibility mask and region placements carry their occupied zones. engine-stage-cells computes both from a level's BSP model and portals:
Cells::placement_mask/Cells::box_maskdetermine which cells a placement occupies.Cells::visiblewalks frustum-clipped portals (scene_zone_volumes) to compute the camera's reachable cell mask.
Level Geometry, Terrain & Streaming (engine-stage-levels)
- BSP & baked light —
bsp::bsp_partsandload_bspconvert BSP polygons into zoned meshes with lightmaps baked into vertex colours.PreparedLevel::bake_lightbakes per-placement static lighting (including sun-share alpha so baked ground still receives live sun shadows and clustered local lights). - Terrain & decorations —
terrain::terrain_chunksbuilds chunked heightfield meshes for far terrain;terrain_layer_passesrenders multi-layer near terrain viaengine_stage_materials::terrain.prepare_decorations/apply_decorationsplace wind-swaying (MeshMaterial::sway), distance-dithering (MeshMaterial::fade) foliage and wind-table meshes (engine_scene::mesh_wind). - Sky —
sky::level_skyandapply_bsp_with_skyisolate sky-zone geometry onto a dedicated sky camera ordered before the main camera, with screen-blended sun/moon sprites and screen-space lens flares (sky::flare_layout). - Simulated effects —
effectsrendersengine_scene::particles::ParticleSystem(sprites, beams, meshes, and ribbons) into per-emitter dynamic meshes. - Fog & medium volumes —
fog::FogBlendsmoothly blends per-zone distance fog;MediumVolumedetects underwater/medium entry and overrides height fog with depth-attenuated medium fog. - Streaming —
LevelStreamermanages resident levels synchronously;BackgroundStreamerprepares files, materials, terrain chunks, and mip chains on worker threads and applies at mostbudgetprepared levels per frame (refresh()re-prepares resident levels cleanly when time-of-day lighting changes).
Skeletal Skinning (engine-stage-skinning)
- CPU skinning —
SkinnedModel::readloads.xskin+.xaniminto bind-pose parts forcreate_dynamic_mesh.poseandpose_blendevaluate and tween bones on the CPU and push updated vertices viaupdate_mesh. - GPU compute skinning —
StageRenderer::create_skinned_meshstores bind-pose vertices and up to 4 bone influences;set_skin_paletteuploads 3×4 bone matrices, andshaders/stage_skinning.slangdispatches a compute pass writing directly into the mesh's vertex buffer before cameras or shadows draw.
World Materials & Post Steps (engine-stage-materials)
Built-in Slang materials and post steps built with build/stage-materials.ts:
- Material stage programs (
stage_program_material,shaders/stage_material_stages.slang) — Evaluates compiledengine_scene_materials::material_graphprograms per pixel viamaterial_combiner.slang, with animated UV modifiers (program_coordinates,set_program_coordinates). - Terrain layers (
terrain,shaders/stage_material_terrain_layer.slang) — Planar-mapped diffuse and mask blending per terrain pass. - Water (
water,shaders/stage_material_water.slang) — Planar Fresnel reflection (from a mirrored camera with obliqueCamera::clip_plane), underwater Snell's-window sky view, ripple disturbances from pawns and waterfalls (MAX_WATER_DISTURBANCES), and offshore swell/chop (water_view_rows_with_swell). - Physical sky (
sky,shaders/stage_material_sky.slang) — Ray-marched scattered daylight sky and cloud deck (shaders/scene/coastal_sky.slang) in linear radiance for HDR cameras. - Cube reflections (
cube,shaders/stage_material_cube.slang) — Samples 6 side-by-side packed cube faces for reflective surfaces. - Contact shadows (
contact,shaders/stage_post_contact.slang) — Screen-space depth march toward the light before tonemapping. - Seabed light (
seabed,shaders/stage_post_seabed.slang) — Underwater diffuse sky falloff and animated sun caustics (shaders/scene/water_optics.slang). - Light shafts (
shafts,shaders/stage_post_shafts.slang) — 32-step screen-space radial gather toward the sun before tonemapping. - Atmospheric fog — Cameras support distance
Fogand up to 3 closed-form exponentialHeightFoglayers with Henyey-Greenstein phase glow (atmosphere::world_fog).