Rendering Pipeline
Relevant source files
The following files were used as context for generating this wiki page:
The Rendering Pipeline manages the visual representation of game worlds, models, and UI elements. It translates original game data into modern graphics via Bevy, while maintaining fidelity to the 1998 source material's visual artifacts, such as Glide-based fog, fixed-point texture coordinates, and depth-based clipping. Sources: crates/cyrus-render/src/fog.rs:1-10, README.md
Core Architecture and Data Flow
The pipeline operates by consuming environmental requests and world data to update scene materials and geometry. It applies specialized shaders to handle legacy behaviors like terrain lighting and fog. Sources: crates/cyrus-render/src/fog.rs:163-180
The diagram shows the flow from environmental data to final mesh preparation through material extensions. Sources: crates/cyrus-render/src/fog.rs:163-190, crates/cyrus-render/src/fog/clipping.rs:114-130
Key Components
| Component | Description |
|---|---|
FogExtension | Manages fog color, clipping distances, and environment lighting. |
ModelExtension | Handles model-specific rendering including chroma keying and light textures. |
TerrainExtension | Specialized extension for terrain-specific shaders and geometry. |
RenderDistance | Resource tracking original and modern override clipping distances. |
Sources: crates/cyrus-render/src/fog.rs:31-40, crates/cyrus-render/src/fog.rs:88-100
Fog and Clipping Systems
The pipeline implements faithful Glide-style fog using a 16-entry fog table and distance-based clipping. Conditions are checked before actions: if the fidelity mode is set to Modern, the pipeline extends the far clipping plane beyond the original game's limits. Sources: crates/cyrus-render/src/fog.rs:36-50, crates/cyrus-render/src/fog.rs:290-305
Depth Clipping Logic
Model draw geometry is prepared separately to preserve authored poses while clipping lit RGB values at the camera's near and far planes. The Source component tracks the draw entity and polygon metadata to perform these calculations. Sources: crates/cyrus-render/src/fog/clipping.rs:1-20
The sequence shows how the preparation system synchronizes with mesh assets and camera viewports. Sources: crates/cyrus-render/src/fog/clipping.rs:135-155
Terrain and World Rendering
Terrain rendering utilizes a grid-based admission window. The Window struct defines which vertices are active based on the camera's local position. It uses fixed-point texture coefficients and packed coefficients for RED, GREEN, and BLUE planes. Sources: crates/cyrus-render/src/terrain.rs:15-30, crates/cyrus-render/src/terrain.rs:80-95
Mesh Attributes for Specialized Rendering
The pipeline inserts custom attributes into meshes to support the unique rendering requirements of the engine:
PROJECTED(Float32x4): Stores screen-space projected coordinates.RED,GREEN,BLUE(Sint32x4): Stores fixed-point lighting plane coefficients.TEXTURE(Uint32x4): Packed signed coefficients for nine texture-plane parameters.
Sources: crates/cyrus-render/src/terrain.rs:11-25, crates/cyrus-render/src/fog/clipping.rs:343-355
Asset Preview Rendering
The asset viewer uses a specialized camera and root entity structure to display models and spatial cells. It includes logic to frame the camera automatically around the bounds of a loaded model or spatial octree. Sources: crates/cyrus-viewer/src/preview.rs:1-25
The flow describes how assets are initialized and framed in the viewer. Sources: crates/cyrus-viewer/src/preview.rs:30-60, crates/cyrus-viewer/src/preview.rs:142-160
Shading Modes
The viewer supports several shading models via SurfaceStyle:
- Textured: Standard PBR materials.
- Unlit: Full brightness without lighting calculations.
- Solid: Flat gray color for structural inspection.
- Wireframe: Displays geometry edges only.
Sources: crates/cyrus-viewer/src/preview.rs:356-375
Implementation Details
The pipeline uses prepare_model_geometry to validate model data before rendering. It extracts chroma keying information from Gltf extras and calculates texture layout based on original BSI formats. Sources: crates/cyrus-render/src/fog.rs:388-410
// crates/cyrus-render/src/fog.rs:414-420
let [w, h] = layout.allocation_dimensions().map(u32::from);
let [x, y] = layout.sampling_stride().map(u32::from);
texture_layout = UVec4::new(w, h, x, y);
let [u, v] = layout.coordinate_scale();
texture_scale = Vec4::new(u, v, layout.sampling_level() as f32, 0.0);
The rendering pipeline serves as the bridge between extracted legacy assets and a modern hardware-accelerated presentation. It ensures that technical improvements like higher frame rates do not compromise the "Faithful" aesthetic of the original game. Sources: crates/cyrus-render/src/fog.rs:1-5, AGENTS.md