Nez Rendering Pipeline

The rendering pipeline in Nez aims to be simple to use but still cover all possible use cases. If you are just whipping up a quick demo everything you need will most likely be already included in Nez. Once you start getting into some more advanced effects you can take control of things and render as you see fit.

Understanding Rendering

Everything starts with the Scene which maintains a list of all the Entities present. Each Entity can have one or more RenderableComponent subclasses and these are the Components that do the actual rendering. Nez includes several RenderableComponent subclasses such as Sprite, TiledSprite, ScrollingSprite, SpriteTrail and others. RenderableComponent contains a bounds rectangle that is used for culling so that we only render what is visible to the camera.

The Scene handily keeps a sorted list of all the RenderableComponents for us. They are sorted first by renderLayer and then by layerDepth. This provides a decent amount of control over the order that everything is rendered.

Enter the Renderer

The Renderer class is the heart of the rendering pipeline. One or more Renderers can be added to a scene and they will be invoked in the order specified. Renderers choose what to render and where to render it. By default they will render to the Scenes RenderTarget but they can also render to their own RenderTarget (useful for some advanced effects). Below is a quick and (really) dirty diagram of the process.

Adding Some Juice with PostProcessors

If Renderers are yin then the PostProcessor is it's yang. PostProcessors are the place where you take care of all of your fancy effects. Nez provides some default PostProcessors for you (HeatDistortionPostProcessor, VignettePostProcessor and others) to get you started and to provide a solid example to work from. PostProcessors work hand in hand with Renderers.

Much like Renderers, PostProcessors are kept in a sorted list in the Scene. Once the Renderers have done their rendering the results can then be modified/augmented by the PostProcessors. The Scene will pass two RenderTargets to the PostProcessor: the first is the one that the Renderers rendered into and the second is a destination for them to render into. PostProcessors are called in order and the result of the previous PostProcessor is passed to the next so the effects can be stacked. PostProcessors generally do some fancy rendering via a shader and then spit out a new, (hopefully) juicier image to be displayed onscreen.