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_range skips distant groups; set_region_casts toggles 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 .xmesh static meshes, .xskin bind poses, and .ktx2 textures (including BC1/2/3/7 and palette formats) into stage MeshData and 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, and point_light.
  • MaterialLibrary::surface resolves converted materials to textures, alpha test, and sidedness; emitters::stage_emitter maps sprite emitters onto stage Emitters (listing unsupported features in EmitterPlan::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_mask determine which cells a placement occupies.
  • Cells::visible walks 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_parts and load_bsp convert BSP polygons into zoned meshes with lightmaps baked into vertex colours. PreparedLevel::bake_light bakes per-placement static lighting (including sun-share alpha so baked ground still receives live sun shadows and clustered local lights).
  • Terrain & decorations — terrain::terrain_chunks builds chunked heightfield meshes for far terrain; terrain_layer_passes renders multi-layer near terrain via engine_stage_materials::terrain. prepare_decorations / apply_decorations place wind-swaying (MeshMaterial::sway), distance-dithering (MeshMaterial::fade) foliage and wind-table meshes (engine_scene::mesh_wind).
  • Sky — sky::level_sky and apply_bsp_with_sky isolate 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 — effects renders engine_scene::particles::ParticleSystem (sprites, beams, meshes, and ribbons) into per-emitter dynamic meshes.
  • Fog & medium volumes — fog::FogBlend smoothly blends per-zone distance fog; MediumVolume detects underwater/medium entry and overrides height fog with depth-attenuated medium fog.
  • Streaming — LevelStreamer manages resident levels synchronously; BackgroundStreamer prepares files, materials, terrain chunks, and mip chains on worker threads and applies at most budget prepared levels per frame (refresh() re-prepares resident levels cleanly when time-of-day lighting changes).

Skeletal Skinning (engine-stage-skinning)

  • CPU skinning — SkinnedModel::read loads .xskin + .xanim into bind-pose parts for create_dynamic_mesh. pose and pose_blend evaluate and tween bones on the CPU and push updated vertices via update_mesh.
  • GPU compute skinning — StageRenderer::create_skinned_mesh stores bind-pose vertices and up to 4 bone influences; set_skin_palette uploads 3×4 bone matrices, and shaders/stage_skinning.slang dispatches 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 compiled engine_scene_materials::material_graph programs per pixel via material_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 oblique Camera::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 Fog and up to 3 closed-form exponential HeightFog layers with Henyey-Greenstein phase glow (atmosphere::world_fog).