Decals |
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:
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:
For more information about deferred decals see:
A decal is defined using a DecalNode. The visual properties are defined by a decal material (see property Material).
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.
The "splattered blood" material in this example consists of 3 textures: diffuse + opacity, specular and normal map.
The blood decal will be placed on a simple scene.
A decal node can be represented as a box. (The decal box can be visualized using the DebugRenderer.)
The decal box defines an orthographic projection. The decal textures are projected onto the scene where the box intersects with the scene geometry.
Result:
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:
This section explains how to render DecalNodes using the 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.
// Select render pass. context.RenderPass = "Material"; // Render a list of decal nodes. decalRenderer.Render(decalNodes, context);