Texture atlas

From TrainzOnline
Revision as of 15:06, 17 October 2017 by N3vpolsen (Talk | contribs)

Jump to: navigation, search

A texture atlas is a single larger texture which combines what would normally be several distinct smaller textures. This technique can be a significant performance optimisation.

A "texture atlas" is just a fancy name for the technique of packing a number of textures into one texture.

Here is an example of how you would package up two individual 1024x1024 textures into one 1024x2048 texture.

3dsmaxatlasmaterial.jpg

In-game, we are rendering a cube mesh that has the 1 material with the single texture atlas applied. We have mapped most of the cube with the top half of our texture atlas and one side of our cube with the bottom half of our texture atlas. Note we are using 2 different textures but still only generate 1 draw call.

Trainzatlastexture.jpg

It’s worth noting that just atlasing everything into a large texture isn’t always great. You need to be using a lot of the assets that share the atlas in the same scene to get the benefits; otherwise the costs can outweigh the benefits. Let’s explain this further:

Say we create 60 assets all using a single texture atlas but you only use one of those assets in your scene then the large texture is loaded just for that one asset. We only need a single draw call even if the asset occurs several times (great!) but that was true even without the texture atlas, so it's had no real benefit. On the downside, we're using around 1/60th of the texture atlas, so 98% of our texture space is wasted. Not a great result.

On the flip-side if we had the same assets AND we are using all those assets in the one scene (ie. on screen at the same time) then this is mostly a good result as you are only using a single draw call to render 60 assets (improved from 60 draw calls without the atlas) and it's not costing you any extra texture space.

So you need to weigh up if you actually plan on having a few meshes on the screen at the one time to benefit from a texture atlas. A very effective way to use texture atlases is to make all your high LODs use individual textures so you have plenty of texels available to each asset up close and then your very lowest LOD can use a small texture atlas (eg. 256x256 even though it contains several assets). This means if 60 assets all at their lowest LOD are sharing the one texture atlas which is 256x256, not only are 60 assets only performing one draw call, you also only have a single 256x256 texture in use. In this scenario, the penalty for "misusing" an atlas is quite minimal.

File:Atlastexture256x256

Performance Benefits

Concerns

  • Texture Bleeding (when mipmapping)
  • Texture Wrapping
  • Over-large textures (avoid this by atlasing low LODs)

Example

  • Image demonstrating the combination of two separate textured meshes into an atlas.
Personal tools