OpenRA Render Layers - guidebee/OpenRA GitHub Wiki
OpenRA Render Layers
OpenRA uses a sophisticated rendering system to draw the game world and all its components. The rendering is organized into multiple layers, which are drawn in a specific order to create the final image seen by the player.
Main Rendering Layers
Based on the analysis of the WorldRenderer.cs
and other parts of the codebase, OpenRA renders the game scene in the following order:
-
Terrain Layer
- The base ground tiles of the map
- Rendered by the
IRenderTerrain
implementation
-
World Renderables Layer
- Actors (units, buildings, etc.)
- Effects (animations, particles)
- Order Generator visualization
- All renderables in this layer are sorted by their Y + Z position + ZOffset values
- The sorting key is
r.Pos.Y + r.Pos.Z + r.ZOffset
-
Post-Processing (After Actors)
- Special effects applied after the main world elements are rendered
-
Above World Layer
- Elements that should appear above the world but below the shroud
- Rendered by actors implementing
IRenderAboveWorld
-
Shroud Layer
- The fog of war and unexplored areas
- Rendered by actors implementing
IRenderShroud
-
Overlay Layer (Above Shroud)
- Elements that should appear above the shroud
- Rendered by actors implementing
IRenderAboveShroud
andIRenderAboveShroudWhenSelected
- Effects implementing
IEffectAboveShroud
- Order Generator visualizations above shroud
-
Post-Processing (After Shroud)
- Special effects applied after the shroud is rendered
-
Annotation Layer
- UI elements and annotations that appear in the world
- Selection boxes, health bars, attack ranges, etc.
- Rendered by actors implementing
IRenderAnnotations
andIRenderAnnotationsWhenSelected
- Effects implementing
IEffectAnnotation
- Order Generator annotations
Z-Ordering Within Layers
Within the main world renderables layer, objects are sorted based on their position and Z-offset:
- The Y-coordinate in the world represents depth (north-south position)
- The Z-coordinate represents height (elevation)
- ZOffset is an additional value that can be used to fine-tune the rendering order
The formula r.Pos.Y + r.Pos.Z + r.ZOffset
is used as the sorting key, which means:
- Objects further north (lower Y) are drawn before objects further south
- Objects at higher elevations (higher Z) can be drawn over objects in front of them
- ZOffset can be used to adjust the rendering order for special cases
Special Rendering Interfaces
OpenRA uses a variety of interfaces to control what and how things are rendered:
IRender
: Base interface for actors that want to render somethingIRenderTerrain
: Renders the terrain layerIRenderAboveShroud
: Renders elements above the shroudIRenderAboveShroudWhenSelected
: Renders elements above shroud when the actor is selectedIRenderAboveWorld
: Renders elements above the world but below the shroudIRenderAnnotations
: Renders UI annotations in the worldIRenderAnnotationsWhenSelected
: Renders UI annotations when the actor is selectedIRenderShroud
: Renders the fog of war and unexplored areasIRenderOverlay
: Renders overlays (like buildable terrain indicators)
Rendering Process
The rendering process in OpenRA follows these steps:
- Prepare renderables by collecting them from all sources
- Sort the main world renderables by their Z position
- Draw the terrain
- Draw all world renderables in sorted order
- Apply post-processing effects
- Draw above-world elements
- Draw the shroud
- Draw overlay elements that appear above the shroud
- Apply more post-processing effects
- Draw annotations and debugging information
This layered approach allows OpenRA to create a visually coherent 2.5D isometric view where objects properly overlap each other based on their position in the game world.