Render stages

Objects can subscribe to multiple render stages. For example, a mesh typically subscribes to both the and ShadowCaster stages, or the stage.

Note

Render stages don't define the rendering order. The rendering order is controlled by the .

Effect slots determine which effect/shader a render stage uses. You choose the effect slot with .

If they render any of the same objects, they can't share effect slots. This is why, for example, we typically render opaque meshes with the main effect slot, then render opaque meshes again with the shadow caster effect slot to create shadows.

A typical setup of render stages:

SortMode defines how Xenko sorts objects in that render stage. Xenko comes with several implementations, such as:

  • FrontToBackSortMode, which renders objects from front to back with limited precision, and tries to avoid state changes in the same depth range of objects (useful for opaque objects and shadows)
  • , which renders objects strictly from back to front (useful for transparent objects)
  • StateChangeSortMode, which tries to reduce state changesOf course, you're free to implement your own, too.

Render stage selectors define which objects in your scene are sent to which render stage, and choose which to use when rendering a given object.

For example, this is the typical setup for meshes:

  • ShadowMapRenderStageSelector selects opaque meshes that cast shadows and adds them to the render stage. The default effect is XenkoForwardShadingEffect.ShadowMapCaster, defined by Xenko.Either can filter by .

You can customize everything, so you can add other predefined render stage selectors (eg to add UI to a later full-screen pass), or create your own selector specific to your game.