Skip to content

Game.Rendering.RenderingSystem

Assembly: Assembly-CSharp
Namespace: Game.Rendering

Type: class

Base: GameSystemBase, IPostDeserialize

Summary:
RenderingSystem is the central in-game rendering controller used by Cities: Skylines 2. It coordinates per-frame rendering timing, LOD progression, shader enablement, loading progress reporting for mesh streaming, motion vector state, and provides data used by batch/mesh/area systems and shaders (e.g., simulation time, time-of-day). It integrates with various game systems (SimulationSystem, UpdateSystem, Batch systems, TimeSystem) to compute frame indices, deltas, frame LOD blending values, and to notify batch systems when shader enablement or property updates occur. This system is created and managed in the ECS world and is intended to be used by rendering-related subsystems and mod code that needs to query or tweak rendering parameters.


Fields

  • public const string kLoadingTask
    Contains the task name used when tracking mesh loading progress ("LoadMeshes") through TaskManager.

  • private SimulationSystem m_SimulationSystem
    Reference to the SimulationSystem; used to sync the rendering frame with simulation frame/timing.

  • private PlanetarySystem m_PlanetarySystem
    Reference to the PlanetarySystem — currently stored for potential planetary/sky interactions (not heavily used in this class).

  • private UpdateSystem m_UpdateSystem
    Reference to the UpdateSystem; used to step UpdateSystem phases related to rendering.

  • private BatchManagerSystem m_BatchManagerSystem
    Reference to the BatchManagerSystem; used to detect property updates that affect rendering and LOD.

  • private ManagedBatchSystem m_ManagedBatchSystem
    Reference to ManagedBatchSystem; notified when enabled shaders update.

  • private BatchMeshSystem m_BatchMeshSystem
    Reference to BatchMeshSystem; used to query mesh loading remaining count for progress reporting.

  • private AreaBatchSystem m_AreaBatchSystem
    Reference to AreaBatchSystem; notified when enabled shaders update.

  • private TimeSystem m_TimeSystem
    Reference to TimeSystem; used to compute time-of-day for shaders based on time settings/data.

  • private Dictionary<Shader, bool> m_EnabledShaders
    Cache mapping Shader -> enabled state. Used to avoid resolving shader state repeatedly and to notify batch systems on changes.

  • private EntityQuery m_TimeSettingGroup
    EntityQuery used to find TimeSettingsData singleton for time-of-day computations.

  • private EntityQuery m_TimeDataQuery
    EntityQuery used to find TimeData singleton for time-of-day computations.

  • private int m_TotalLoadingCount
    Internal counter used to compute loadingProgress over time while meshes finish loading.

  • private int m_EnabledShaderCount
    Running count of enabled shaders (used to default-enable new shaders when there are no explicit disables).

  • private float m_LastFrameOffset
    Stores previous frameOffset to detect changes and recompute frameIndex/time interpolation.

  • private float m_LodTimer
    Accumulator used for LOD cross-fade timing when lodCrossFade is enabled.

  • private bool m_IsLoading
    Flag indicating the system is in a loading state (used to drive loading progress reporting).

  • private bool m_EnabledShadersUpdated
    Flag set when shader enabled states change and batch systems need to be notified on the next PrepareRendering.

Properties

  • public uint frameIndex { get; private set }
    Current rendering frame index synchronized (approximately) with simulation frame index. Used to compute shader time uniforms and motion.

  • public float frameTime { get; private set }
    Fractional part of the current frame (0..1) used together with frameIndex for high-resolution simulation time.

  • public float frameDelta { get; private set }
    Difference in frames/time between the last prepared rendering state and the current; used for motion, interpolation.

  • public float frameLod { get; private set }
    Current LOD progression value (0..levelOfDetail). Advances gradually toward levelOfDetail for streaming/LOD smoothing.

  • public float timeOfDay { get; private set }
    Time-of-day value computed from TimeSettingsData/TimeData and the current frame time. -1 if time info is not available.

  • public int lodTimerDelta { get; private set }
    Packed integer in 0..255 used for LOD cross-fade timing when lodCrossFade is enabled; 255 indicates immediate LOD.

  • public float frameOffset { get; set; }
    A render-time offset used to slightly advance or delay rendering frames relative to simulation. Writing this affects how frameIndex and frameTime are computed in PrepareRendering.

  • public bool hideOverlay { get; set; }
    Flag to hide overlays during rendering; upper-level rendering code or mods may toggle this.

  • public bool unspawnedVisible { get; set; }
    If true, unspawned objects are visible in rendering; used by editor/preview modes.

  • public bool markersVisible { get; set; }
    Controls visibility of marker/overlay objects.

  • public float levelOfDetail { get; set; }
    Target LOD scalar in range 0..1 that controls streaming and mesh LOD behavior (default 0.5f in OnCreate).

  • public bool lodCrossFade { get; set; }
    When true, LOD transitions are cross-faded over time using m_LodTimer and lodTimerDelta.

  • public int maxLightCount { get; set; }
    Maximum number of lights to consider for rendering (default 2048).

  • public bool debugCrossFade { get; set; }
    If true, use a slower/faster cross-fade multiplier for debugging LOD cross-fade behavior.

  • public bool disableLodModels { get; set; }
    If true, LOD models can be disabled (used by debug/editor features).

  • public float4 editorBuildingStateOverride { get; set; }
    Editor override state for building LODs (float4 struct from Unity.Mathematics).

  • public float loadingProgress { get; private set }
    Progress value (0..1) for the mesh loading task "LoadMeshes". Getter reads TaskManager progress; setter reports progress back to TaskManager progress tracker. Setter is private.

  • public bool motionVectors { get; private set; }
    Whether motion vectors are enabled; computed from GetMotionVectorsEnabled() on creation and updated in PrepareRendering.

  • public IReadOnlyDictionary<Shader, bool> enabledShaders => m_EnabledShaders
    Read-only view of the local shader-enabled cache. Use IsShaderEnabled and SetShaderEnabled to query and change values.

Constructors

  • public RenderingSystem()
    Default constructor (annotated with [Preserve]). The heavy initialization is done in OnCreate. Constructed by the ECS world.

Methods

  • protected override void OnCreate() : System.Void
    Creates references to required systems (SimulationSystem, PlanetarySystem, UpdateSystem, Batch systems, TimeSystem), initializes fields (m_EnabledShaders, levelOfDetail, maxLightCount), prepares EntityQueries for time settings/data, and queries initial motion vector state. Called once when the system is created.

  • protected override void OnUpdate() : System.Void
    Runs each system update. This forwards UpdateSystem.Update for the Rendering phase and, while in loading state, monitors loadingProgress (until it reaches 1.0) by calling UpdateLoadingProgress. Do not place heavy work here; PrepareRendering is where per-frame rendering timing is computed.

  • protected override void OnGamePreload(Purpose purpose, GameMode mode) : System.Void
    Called during game preload. Resets loading counters and marks the system as loading (m_IsLoading = true) and resets frameLod. Used to begin mesh loading tracking for scene transitions and save loads.

  • private void UpdateLoadingProgress() : System.Void
    Internal helper used while m_IsLoading is true. Uses BatchMeshSystem.loadingRemaining to compute a smoothed loadingProgress value, taking frameLod and levelOfDetail into account. When remaining becomes zero, sets loadingProgress to 1 and clears m_IsLoading.

  • public void PrepareRendering() : System.Void
    Main per-render call to compute/interpolate rendering frame timing and shader global variables:

  • Computes frameIndex, frameTime and frameDelta either using frameOffset or based on simulation frame and smooth speeds.
  • Sets shader globals "colossal_SimulationTime" (vec4) and "colossal_SimulationTime2" (float).
  • Computes timeOfDay using TimeSystem and entity singletons (TimeSettingsData / TimeData).
  • Updates motionVectors state.
  • Handles batch manager property updates (resets frameLod and lodTimerDelta when needed).
  • Advances LOD timers and frameLod, and notifies batch systems when enabled shaders changed. This should be called by the render loop before issuing draw calls.

  • public bool IsShaderEnabled(Shader shader) : System.Boolean
    Returns whether a shader is currently enabled for rendering according to the internal cache. If the shader is not yet tracked, it is added: default enables it if either m_EnabledShaderCount != 0 or there are currently no tracked shaders. This call will increment m_EnabledShaderCount when newly added and enabled.

  • public void SetShaderEnabled(Shader shader, bool isEnabled) : System.Void
    Sets the enabled state for a shader in the internal cache. If the new state differs from the current state, adjusts m_EnabledShaderCount accordingly and flags m_EnabledShadersUpdated to notify batch systems during the next PrepareRendering call.

  • private bool GetMotionVectorsEnabled() : System.Boolean
    Returns whether motion vectors should be enabled. Currently returns true (placeholder) — kept as an abstraction point if motion vector enablement depends on settings or platform in the future.

  • public void PostDeserialize(Context context) : System.Void
    IPostDeserialize implementation. Called after serialization/deserialization to resync the rendering frame with the simulation: sets frameIndex/frameTime from SimulationSystem and initializes frameDelta/offset fields to safe default values.

  • public float3 GetShadowCullingData() : Unity.Mathematics.float3
    Returns shadow culling parameters (x = base range, y = threshold height, z = threshold volume). Reads from SharedSettings.instance.graphics.ShadowsQualitySettings if available, falling back to defaults (2048,1,1).

Usage Example

// Fetch the RenderingSystem from the world and tweak parameters or call PrepareRendering
var world = Unity.Entities.World.DefaultGameObjectInjectionWorld;
var renderingSystem = world.GetExistingSystemManaged<Game.Rendering.RenderingSystem>();

if (renderingSystem != null)
{
    // Adjust LOD and limits from a mod or debug UI
    renderingSystem.levelOfDetail = 0.75f;
    renderingSystem.maxLightCount = 1024;
    renderingSystem.lodCrossFade = true;

    // Ensure the system computes the latest per-frame rendering time/LOD before issuing render work
    renderingSystem.PrepareRendering();

    // Query some data
    float tod = renderingSystem.timeOfDay;
    uint frameIdx = renderingSystem.frameIndex;
}

Notes and modding tips: - Prefer using the public API (IsShaderEnabled / SetShaderEnabled) to affect shader-enabled behavior so batch systems are correctly notified. - Call PrepareRendering before issuing custom rendering that depends on the simulation time, frame interpolation or LOD state. - Use GetShadowCullingData to adapt custom shadow casters to the same culling thresholds as the engine. - The loadingProgress property is integrated with TaskManager (task name "LoadMeshes"); use this if you need to show or intercept loading progress for mesh streaming.