Click or drag to resize
DigitalRuneRendering Scene Nodes

This topic contains the following sections:

SceneNodeRenderers

Scene nodes that are marked as "renderable" (see property SceneNodeIsRenderable) can be rendered. A SceneNodeRenderer (base class) renders scene nodes. DigitalRune Graphics provides several scene node renderers. Each renderer handles one or more types of scene nodes. For example:

Usually the graphics are rendered into the current render target. However, some SceneNodeRenderers render into a different render target, for example: the like

Custom scene node renderers can be added when needed. See How To: Add a Custom Scene Node.

Scene node renderers need to be called explicitly in the graphics screen that renders a scene graph - renderers are not called automatically!

SceneRenderer

The SceneRenderer is a special type of scene node renderer. The SceneRenderer is a collection of other scene node renderers, i.e. it can be used to combine different scene node renderers into a single instance.

Example (C#): Create a renderer that handles meshes, billboards, and particles.
sceneRenderer = new SceneRenderer();
sceneRenderer.Renderers.Add(new MeshRenderer());
sceneRenderer.Renderers.Add(new BillboardRenderer(graphicsService, 2048));

The main purpose of the SceneRenderer is to correctly sort scene nodes and automatically dispatch them in batches to the correct renderer.

Example: Transparent (alpha-blended) objects need to be rendered back-to-front. That means the scene nodes need to be sorted by depth. Then depending on the type the scene nodes need to be passed to the correct renderer. The MeshNodes need to be passed to the MeshRenderer, the BillboardNodes need to be passed to the BillboardRenderer, etc. The SceneRenderer takes care of this.

Example (C#): Render transparent (alpha-blended) scene nodes
// Set render states.
graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
graphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
graphicsDevice.BlendState = BlendState.AlphaBlend;

// Select render pass.
context.RenderPass = "AlphaBlend";

// Render a list of scene nodes (mesh nodes, billboard nodes, ...).
sceneRenderer.Render(sceneNodes, context, RenderOrder.BackToFront);

// Optional: If one of the meshes uses floating-point texture, it might be 
// necessary to reset the texture stage. Otherwise, the subsequent code may 
// throw an exception in XNA.
graphicsDevice.ResetTextures();