The C4 Rendering Pipeline

From C4 Engine Wiki

Jump to: navigation, search
Figure 1. The five major stages of the C4 Rendering Pipeline.
Figure 1. The five major stages of the C4 Rendering Pipeline.

The C4 Engine executes a complex sequence of rendering operations during each frame of gameplay. This article gives a high-level overview of the C4 rendering pipeline's various components so that users of the engine, having some knowledge of its internal processes, can achieve more efficient results in the C4 environment. The following sections describe the rendering passes executed by the engine in the order that they occur.

Ambient Pass

The engine first goes through the scene (using the portal system) to determine what objects are visible to the current camera. Once these have been collected, the appropriate detail levels are determined, and the objects are rendered with their ambient lighting shaders. This is the only pass in which data is written to the depth buffer, which becomes permanently established for the entire frame at this time.

If a skybox is visible, then it is the last thing rendered in the ambient pass. This maximizes efficient use of hierarchical z-buffering hardware.

Effect visibility is determined during the ambient pass, but effects are not rendered until later.

Velocity Pass

If motion blur is enabled, then the same objects that were rendered in the ambient pass are rendered again, but this time into the velocity buffer using a very fast shader. The data in the velocity buffer is used later in the post-processing pass.

Lighting Passes

The engine now uses a complicated algorithm to determine which lights in the scene affect regions that are visible to the camera. For each of these lights, the engine must also figure out which objects in the scene may cast shadows into visible regions, and this usually includes objects that are not directly visible and thus never actually rendered.

For each visible light, the engine first renders shadows for all of the possible shadow castors for that light. Then it renders all objects that are both visible and illuminated by the light, being sure to prevent light from reaching surfaces that are in shadow. An object has a different shader for each of the different types of light supported by the engine.

Effect Passes

Once the ambient pass and all lighting passes have been rendered, special effects are rendered. There are a few different effect rendering stages. The first stage renders opaque effects, such as scorch mark decals, that are always applied to previously rendered opaque objects. In the second stage, transparent effects that need to be sorted, such as fire and smoke, are rendered from furthest to nearest. Finally, in the third stage, other transparent effects, such as certain particle systems that don't need to be sorted, are rendered.

Post-processing Pass

The final pass rendered by the engine takes care of post-processing effects. These are applied to the entire screen and have a constant performance cost that does not depend on the number of visible objects. The post-processing effects rendered by the engine are motion blur, glow and bloom, distortion effects, and a final scale and bias.

Personal tools