As discussed earlier, my final project was to create the decalling system similar to what Unreal Engine 4 has. In my presentation before, I discussed an algorithm, where I was changing the mesh data in the vertex buffer itself, by inducing an additional parameter called index. This index decided what texture should the geometry use. But, as I moved along with this project, I realized some key problems with this algorithm:

1. The change of textures was happening at vertex level, hence the decals were not covering the geometry accurately by pixels.

2. This algorithm was changing the mesh itself, which creates problems in instancing.

Hence, I came up with the 2nd algorithm. This algorithm assumes symmetrical decals, which means that to detect the coverage of a decal volume over a geometry, we don`t need pixel accurate collision detection. Here is how the algorithm works:

This algorithm manually sets the uniforms corrosponding to all the decals and then you have to manually compare the fragment (in world coordinates) with the min-max range of every decal. This created a pixel level accurate decal system for decal volumes like cube, sphere, and a cylinder. But, this had problems:

1. It involves a lot of manual work, like setting up of uniforms for every decal. Because of this, this algorithm defeats the purpose of this system. This system is intended to be added as a feature in a game engine. Hence, it is absolutely required to make this algorithm generic for any number of decal volumes.

2. Bleeding occurs while using spherical decals and flat meshes to put decals on. But, even Unreal Engine 4 has the same issue. Hence, I decided to make this problem out of scope of this project.

Hence, I came up with another algorithm. This algorithm renders all the meshes in the scene for every decal using a decal shader. This shader renders the fragments lying within the bounds of the decal with the decal properties, and rejects all other fragments. This basically, puts a “decal sticker” on a mesh. Because of this though, the problem is that the fragments that decal shader wants to color have already been colored by the mesh specific shaders. Hence, the only way to color these fragments is to disable the depth test. But, because of that, depth errors were created because of these decal stickers. Here is how it looked:

I used stencil buffer to solve this. This is how the algorithm works:

Some of the results using this algorithm:

The picture has 3 decals a pink cube, a blue sphere and a yellow cylinder. Pink cube covering parts of the sphere mesh and the 404Sight`s character mesh.

The picture shows that the decal not only chnages color of a mesh, but also makes that part toon shaded.

This picture shows the pink cude decal affecting a part of the sphere and a part of the right wall.

The biggest advantage of using this system that I found while using this in my Thesis game is that this reduces the number of renderable objects in a scene. Because of this, a lot of memory load, like shadow maps, is decreased. In 404Sight, the map sizes decreased from 3GB for 4 levels to 900MB for 14 levels. Other than this, this project helped me a lot in developing graphics algorithm skills. Also, this marks the end of the blog series for this class. It was an amazing class. I learnt so much from it. I will try to come back to the blogs with another interesting series.