I’m going to begin this blog entry by defining a decal and how/when its used in the development of graphics applications.
Decals are basically textures which vary in resolution. This special type of texture, unlike normal textures can be applied to any 2D/3D object with any orientation and at any size. This can be used to quickly add a lot of detail into the graphics application.
Decals come in two varieties, either static or dynamic. Static decals take longer to compute, but have a much more accurate result. This form of decals are normally pre-baked during the creation of a level. Dynamic decals on the other hand can be created at run-time. They normally sacrifice accuracy in favor of faster computation speed.
Over the years, numerous decal placement methods of arose. Almost all advanced game engines support decals in one form or another. The three most basic methods that game developers choose to adopt are as follows.
Quad Mesh – Possibly the simplest form of decal placement available in computer graphics. This method of placement places a square 3D mesh made from two triangles at the position and orientation of the target surface normal.
Quad Meshes are incredibly easy to code and place. Your average game programmer will have a system up and running based on quad meshes within minutes. Quad Meshes do come with a lot of problems, especially when placed on curved surfaces. As you can imagine, if you place a quad mesh on a curved surface such as a sphere, the decal edges become visible and would seem as if they were sticking out, running the immersion.
Subdivided Plane Mesh– This is a direct improved method over the quad mesh decal type. Instead of representing the texture in a single flat surface, this surface can be subdivided into smaller surfaces while interpolating the original texture UV coordinates in-between.
This allows the plane to morph or bend over the target surface, which increases in accuracy the more its subdivided. It is an incredibly fast method of decal placement over other methods, however it suffers from run time performance issues, as the more its subdivided, the greater the rendering overhead is.
Mesh Intersection – Intersection based decals or more commonly known simply as “Projected Mesh” decals provide the most accurate decals regardless of the surface they are placed upon.
The Projection Cube is commonly represented with an Object Oriented Bounding Rectangle which is encapsulated by a tight fit Axis Aligned Bounding Rectangle. Simply put, any triangle which is inside the oriented rectangle is intersected with it. The intersection points along with any other points within the bounds are then triangulated to form a surface. This surface, along with new UV coordinates, normals and tangents is then used with a texture to create a decal.
I will not go into great detail of the intersection algorithms used. I wrote a thorough tutorial which can be found in the “Tutorials and References” section of this blog explains and provides source code of the various intersection algorithms.
Mesh Intersection decals suffer from heavy computation cost, however the provide arguably the most accurate surface in which a texture can be used. Because of this, the framework itself makes it perfect to be used with pre-baked static geometry, where detail can be added during editing to save on the computation costs during run-time.
The framework is also able to batch or merge common decals together, which means the run-time performance losses are minimal.
Mesh Intersection decals is what was developed alongside the slicer editor for our final year project. Depending on how things go, I may release it in the Unity Asset Store at the end of the year.
I have included numerous screen shots of the various decal methods, which are directly from my prototype experimentation’s while developing the framework.
The Object Oriented Bounding Box/Rectangle intersection tests uses the SAT algorithm (Separating Axis Test) with 3D triangles/quads. More information can be found by simply googling SAT.