Click or drag to resize
DigitalRuneRendering

This topic provides information for implementing a rendering pipeline.

This topic contains the following sections:

General

DigitalRune Graphics is in general not limited to a single type of rendering pipeline. The library can theoretically be used to create

  • a traditional forward renderer,
  • a light pre-pass renderer (a.k.a. deferred lighting),
  • a fully deferred renderer,
  • an ad-hoc renderer,
  • etc.

The namespace DigitalRune.Graphics.Rendering provides renderers which can be used to create a forward or a light pre-pass renderer. Additional renderers and samples for additional rendering pipelines may be added in the future.

Example render pipeline

The rendering is usually performed in a graphics screen. Here is an example of a simple render pipeline which can draw opaque meshes, alpha blended billboards and particles, and debug graphics. More detailed examples for different render pipelines can be found in the Samples.

C#
public sealed class MyGraphicsScreen : GraphicsScreen
{
  ...

  protected override void OnRender(RenderContext context)
  {
    // Set the current camera and current scene in the render context.
    context.CameraNode = CameraNode;
    context.Scene = Scene;

    // Clear background.
    var graphicsDevice = GraphicsService.GraphicsDevice;
    graphicsDevice.Clear(BackgroundColor);      

    // Frustum Culling: Get all the scene nodes that intersect the camera frustum.
    var query = Scene.Query<CameraFrustumQuery>(context.CameraNode, context);

    // Render opaque meshes that are visible from the camera using the "Default" 
    // render pass of the materials.
    graphicsDevice.DepthStencilState = DepthStencilState.Default;
    graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
    graphicsDevice.BlendState = BlendState.Opaque;
    graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;      
    context.RenderPass = "Default";
    _meshRenderer.Render(query.SceneNodes, context);
    context.RenderPass = null;

    // Render billboards and particles systems using alpha blending.
    graphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
    graphicsDevice.RasterizerState = RasterizerState.CullNone;
    graphicsDevice.BlendState = BlendState.NonPremultiplied;
    graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
    _billboardRenderer.Render(query.SceneNodes, context);

    // Render debug graphics.
    DebugRenderer.Render(context);

    // Clean up.
    context.CameraNode = null;
    context.Scene = null;
  }
}
Deferred lighting (a.k.a. light pre-pass renderer)

The namespace DigitalRune.Graphics.Rendering provides classes for implementing a deferred lighting renderer (a.k.a. light pre-pass).

The DeferredLightingSample demonstrates how to implement a light pre-pass renderer. Check the source code for more information.

Subtopics