Feiyang Zhou
Gallery

Games Process 2023 12 of 12

Flexible decals in a deferred renderer

A decal system for Unity's deferred pipeline that projects diffuse, normal and emission decals from box volumes into the G-buffer.

Unity scene view of a dark square panel covered in red markings: a warning triangle with a target, DANGER lettering, red rings at two corners and a grille of small holes.The same panel in wireframe: a plain flat slab with no modeled detail.Close-up of a glass dome over a grid of small bumps, with a rotated decal volume gizmo and a red ring decal wrapping onto a side face of the panel.A copper capsule, a dark panel and a glass dome, with large red DANGER and INTAKE decals running across all of them.Wireframe of the complex scene: a rounded capsule, a box and a sphere with no surface detail.The complex scene shaded, with the decal volumes outlined in thin yellow lines and the move handles of a selected decal.The complex scene in wireframe, with the decal volumes outlined in thin yellow lines around the capsule, box and sphere.
1 / 7 Demo, shaded: every surface detail here is a decal

Decals add detail such as scorch marks, graffiti and markings without changing a model’s texture or geometry. In the first demo, apart from the bevel on the ground’s edge, every detail in the rendering comes from my decal system.

How it works. The system is built on command buffers, which run graphics commands such as drawing a mesh or setting render targets at chosen points in the camera’s render loop, and on shaders that apply the decal over the scene.

  • Representation. Each decal is a box volume: the area it is projected into. A decal takes a diffuse texture with alpha for masking, a normal texture and an emission texture.
  • Scene data. Unity’s deferred pipeline keeps diffuse color, normals and more in a set of textures, the G-buffer.
  • Culling. A decal whose volume does not intersect the camera frustum is skipped.
  • Injection. A command buffer inserted before lighting draws the decals into the G-buffer, so lighting takes them into account. A second command buffer after lighting adds emission.
  • Application. The G-buffer normals are copied, then each decal’s box is drawn with a decal shader that projects the textures onto the scene within the volume.

The shader. The vertex function transforms the box, computes screen-space coordinates and the decal’s position and orientation in world space. The fragment function reconstructs each pixel’s world position from depth, checks that it lies inside the volume, samples the decal and writes the result into the G-buffer. One shader handles diffuse-only, normal-only and emission-only decals and any mix of the three.

Next steps. Writing to the specular G-buffer, and a priority field per decal so overlapping decals sort by priority rather than by their order in the scene hierarchy.

Tools

  • Unity
  • C#
  • HLSL
  • Command buffers
  • G-buffer

Do not press

This lets the cat loose on the page for 30 seconds. It will press things and knock the page about. You can stop it any time by grabbing the cat. Everything goes back afterwards.

Stop the cat?

Everything goes back where it was.