Wednesday, November 18, 2015

rendering - Texture atlas vs. array-texture: how differently are they handled by CPU and GPU and how that impacts performance?


Unity 5.4 (currently in beta), will bring a much awaited feature (since 2013) that is array-textures - in the same vain as OpenGL's ArrayTexture. However, after doing some reading about arrays-textures and texture atlases, I still can't quite understand the technical differences on their usage by CPUs and GPUs.


So, to be more specific, I would like to ask for an explanation on the main differences between how texture atlas and texture arrays are dealt with by CPU and GPU and, most importantly, how such differences can impact on performance and memory handling (e.g. how texture arrays can be more performance than texture atlases, etc).


If technical details on Unity's implementation are lacking due to its unfortunate closed-sourceness, I would be happy enough with an answer regarding OpenGL.s ArrayTexture.



Answer



As noted in the comments above, performance is going to depend on implementation, your particular hardware, and what you're trying to do with the textures, so the only reliable answer there is to profile each alternative.


There are a few differences in terms of how you use each option though, which will apply consistently:


One big difference is that, for array textures, each texture is treated separately for purposes like wrapping texture coordinates or mipmapping.



This avoids common problems with texture atlases where we need to add padding between adjacent texture swatches to keep samples at their edges from bleeding together, especially in deeper mip levels.


This also means if you want your textures to tile, you can use the texture sampling hardware to do it just like with a vanilla texture. With atlases, we usually have to do the tiling math in our fragment shader, since the sampler only wraps/mirrors/clamps/borders texture coordinates over the whole atlas, not individual tiles inside it.


The main restriction with array textures is that they require all their constituent textures to have the same resolution and number of mip levels. If you're trying to batch-together textures with very different resolution needs (say, storing terrain tiles whose LoD falls off with distance in a virtual texture) then you may want the flexibility of an atlas instead.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...