Texture Atlas, Filtering and Mipmap
A texture atlas is an image that contains data from multiple smaller images that have been packed together. Instead of having one texture for one mesh, we have a larger texture that is shared by multiple meshes. It can be authored before making the asset, which means the asset will be UV unwrapped following the texture atlas. This will also require early planning when creating the texture. It can also be authored after the asset is finished by merging textures in painting software, but this will also mean the UV island will need to be rearranged according to the texture.
Why should texture atlasing be used?
This technique will enable batching on multiple static objects that share this texture atlas and same material. Batching will naturally reduce number of draw calls.
- A lower amount of draw calls will result in better on device performance if the game is CPU bound.
- Unity's game engine has a feature that will do batching when objects are marked static, this is done without having to manually merge the objects. Further information on this can be found here.
- In Unreal Engine, batching needs to be done manually. This is done by bringing objects to 3D software and merging them or by using the UE4 Actor Merging tool. This tool will also create the texture atlas automatically. Further information on this can be found here.
Texture atlasing also requires less textures inside the game/app as they are packed together, which in turn means overall effort in making the game.
Texture filtering is a method used to improve the texture quality in a given scene. Without texture filtering, an artifact such as aliasing in certain condition (in most cases) will generally look worse. There are several options available on popular game engines for texture filtering.
Nearest/Point - When seen up close, the texture will look blocky.
- This is the simplest and cheapest texture filtering.
Bilinear - The texture will be blurrier up close.
- The 4 nearest texels are sampled and then averaged to color the main pixel. This process make the texture not blocky as the pixels will have smooth gradient, unlike nearest filtering.
Trilinear - Like Bilinear but with added blur between mipmap level.
- This filtering will remove noticeable change between mipmap by adding smooth transition.
Anisotropic - Make textures look better when viewed from different angle, which is good for ground level textures.
Texture filtering best practices
- Use bilinear for balance between performance and visual quality.
- Trilinear will cost more memory bandwidth than bilinear and needs to be used selectively.
- Bilinear + 2x Anisotropic most of the time will look and perform better than Trilinear + 1x Anisotropic, so this combination can be better solution rather than using Trilinear.
- Keep the anisotropic level low. Using a level higher than 2 should be done very selectively for critical game assets.
- This is because higher anisotropic level will cost a lot more bandwidth and will affect device battery life.
Why do artists need to care about texture filtering?
Using texture filtering will make textures look better and less blocky. In most cases this will make game look better.
Texture filtering will be at the cost of some performance, which is natural as better quality means more processing. Find a good balance between performance and visual is key to success here. Bilinear and trilinear need sampling on more pixels and require more computation.
On a more technical note - Texture filtering may account for up to half of the GPU energy consumption, so choosing simpler texture filters is an excellent way to reduce application energy demands.
Mipmapping means LOD (level of detail) for textures. Mipmaps are copies of the original texture that are saved at lower resolutions. Based on how much texture-space a fragment occupies, an appropriate level will be selected for sampling. When an object is further from the camera the lower resolution texture will be applied and vice versa.
Make sure to use mipmapping!
- Using mipmapping will improve GPU performance, as it won't need to render full resolution textures on an object further away from camera.
- Mipmapping will reduce texture aliasing and improve final image quality. Texture aliasing will cause a flickering effect on areas further from the camera.
- In Unreal Engine 4, make sure to have a texture ratio using power of 2 (e.g. 512x1024, 128x128, 2048x2048, etc) to use mipmap. Mipmap chain will not be generated when it's not a power of 2 in Unreal. Textures do not need to be square, for example a 512 x 1024 texture will have its mipmap generated.
- Unity automatically creates mipmaps on import and rescales textures that are not power of 2. More information on this can be found here.