There's a lot of different techniques for decas.
The traditional idea is that you render the affected mesh again, except with a projected decal texture and alpha-testing enabled. This is obviously wasteful, so it's a good idea to use the bounding-box of the projection area to extract only the affected triangles, which you use to create a new temporary mesh for that decal. Some games even have their artists create a 'decal mesh' - which is like a low-poly LOD, just used for this decal-projection technique.
There's a screen-space technique that doesn't require mesh-generation though. For this you need access to per-pixel position -- in a deferred renderer this should be readily available, and in a forward renderer, you can use a bit of math to reconstruct position from the non-linear Z-buffer values. The idea is that you draw your decals in the same way that you draw lights in a deferred renderer. You just render the bounding-cube of the decal to the screen, fetch the position of any covered pixels, and perform the texture-projection using the decal's position/size and the pixel's position. In a deferred renderer you could do this after initial G-Buffer generation, and overwrite the albedo term in the G-Buffer (so that the decals will be lit as usual), but in a forward renderer, you'll also have to include the lighting-math in your decal shader.
|