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:

  1. Terrain Layer

    • The base ground tiles of the map
    • Rendered by the IRenderTerrain implementation
  2. 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
  3. Post-Processing (After Actors)

    • Special effects applied after the main world elements are rendered
  4. Above World Layer

    • Elements that should appear above the world but below the shroud
    • Rendered by actors implementing IRenderAboveWorld
  5. Shroud Layer

    • The fog of war and unexplored areas
    • Rendered by actors implementing IRenderShroud
  6. Overlay Layer (Above Shroud)

    • Elements that should appear above the shroud
    • Rendered by actors implementing IRenderAboveShroud and IRenderAboveShroudWhenSelected
    • Effects implementing IEffectAboveShroud
    • Order Generator visualizations above shroud
  7. Post-Processing (After Shroud)

    • Special effects applied after the shroud is rendered
  8. Annotation Layer

    • UI elements and annotations that appear in the world
    • Selection boxes, health bars, attack ranges, etc.
    • Rendered by actors implementing IRenderAnnotations and IRenderAnnotationsWhenSelected
    • 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 something
  • IRenderTerrain: Renders the terrain layer
  • IRenderAboveShroud: Renders elements above the shroud
  • IRenderAboveShroudWhenSelected: Renders elements above shroud when the actor is selected
  • IRenderAboveWorld: Renders elements above the world but below the shroud
  • IRenderAnnotations: Renders UI annotations in the world
  • IRenderAnnotationsWhenSelected: Renders UI annotations when the actor is selected
  • IRenderShroud: Renders the fog of war and unexplored areas
  • IRenderOverlay: Renders overlays (like buildable terrain indicators)

Rendering Process

The rendering process in OpenRA follows these steps:

  1. Prepare renderables by collecting them from all sources
  2. Sort the main world renderables by their Z position
  3. Draw the terrain
  4. Draw all world renderables in sorted order
  5. Apply post-processing effects
  6. Draw above-world elements
  7. Draw the shroud
  8. Draw overlay elements that appear above the shroud
  9. Apply more post-processing effects
  10. 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.