Skip to content

How It Works

Matt Dean edited this page Jan 24, 2020 · 3 revisions

BACK > Home


Welcome to kDecals!

This page explains how the functionality behind kDecals works.

alt text Data diagram for kDecals.

1) Creation and Management

Decals are created either manually in the Editor or at runtime via the DecalSystem API. All enabled decals are tracked by the DecalSystem.

2) Projection

Each decal generates a projection matrix and set of clip planes. These are cached and only updated when the decal's DecalData or Transform are altered.

3) Rendering

The DecalRenderereature creates an instance of a DecalRenderPass to use for decal rendering. A single pass is used, looping over all decals.

4) Sorting

The first part of rendering is sorting. All active decals on the DecalSystem are sorted by their Sorting Order. Decals with the same sorting order are drawn in an undefined order.

5) Culling

Next culling is calculated per decal. Culling happens in three stages. First the decal is culled if it is behind the camera. Next it is culled if it is outside the active Camera frustum. Finally, object culling results are calculated using the decal's clip planes. These are used later for drawing.

6) Shader Uniforms

Next, per-decal shader uniforms are set. These include the decal's projection matrix, direction and DecalData properties.

7) Drawing

Finally, the decal is drawn. Sorting, drawing and filtering settings are created from the DecalData and DrawRenderers is called. Objects projected on by the same decal are batched, regardless of their own batching properties.