Click or drag to resize
DigitalRuneDecals

A decal is a Material projected onto other geometry. Static decals can be used to add variety to a scene: posters on walls, dirt on objects, puddles on the floor, etc. Dynamic decals can be created by the game logic based on events in the game: bullet holes at a point of impact, blood splatters, foot prints on the ground, tire marks on the street, etc.

This topic contains the following sections:

Deferred decals

DigitalRune Graphics implements deferred decal rendering (a.k.a. screen space decals). This means decals are rendered by rendering a screen-aligned quad or oriented box. The pixel shader reconstructs a pixel’s 3D position from the G-buffer and projects the decal textures onto it.

This method has following limitations:

  • The decal renderer requires a G-buffer of the scene. The renderer fits perfectly into any deferred rendering pipeline, but does not work with traditional forward rendering.
  • Does not work on alpha-blended geometry.
  • When applied to skinned meshes, decals are not animated/distorted correctly.

For more information about deferred decals see:

Defining decals

A decal is defined using a DecalNode. The visual properties are defined by a decal material (see property Material).

Caution note Caution

It is not possible to use the same materials for decals as are used for regular meshes. Decals need to be rendered with special vertex and pixel shaders and therefore require different Effects than meshes.

See section Predefined Effects (Decal Effects).

The properties Width, Height and Depth. define the bounding volume of the decal. The decal material will be projected onto meshes within this bounding volume.

DigitalRune.Graphics (Decals)
Class Diagram: Decals
Example

The "splattered blood" material in this example consists of 3 textures: diffuse + opacity, specular and normal map.

Blood-Decal

The blood decal will be placed on a simple scene.

Decal-Example-01

A decal node can be represented as a box. (The decal box can be visualized using the DebugRenderer.)

Decal-Example-02

The decal box defines an orthographic projection. The decal textures are projected onto the scene where the box intersects with the scene geometry.

Decal-Example-03

Result:

Decal-Example-04

The material system is very flexible: Since the decal has a Material – the same class that is used for regular meshes – it can be rendered using custom effects. The pre-built effects support diffuse, specular, emissive, normal, and opacity maps.

The following series of screenshots shows a few variations:

Decal Modes
Rendering decals

This section explains how to render DecalNodes using the DecalRenderer.

DecalRenderer

The DecalRenderer is a SceneNodeRenderer which handles DecalNodes.

Decals are defined by a Material. Similarly to meshes, it may be necessary to render decals in multiple passes. For example, in the "GBuffer" pass the decal is rendered into the G-buffer and in the "Material" pass it is rendered into the back buffer. The current render pass is selected by setting the RenderPass property in the RenderContext.

C#
// Select render pass.
context.RenderPass = "Material";

// Render a list of decal nodes.
decalRenderer.Render(decalNodes, context);