Legacy Documentation: Version 4.5
Previous
Compute Shaders
Next
Graphics Hardware Capabilities and Emulation

Sparse Textures

Sparse textures are textures where not the whole texture data can be present in memory at once. They are also commonly called “tiled textures” or “mega textures”.

Imagine a 16384x16384 texture at 32 bits per pixel - it would take 1GB of memory. The texture is broken down into rectangular “tiles”, and each tile can either be present in memory or not. You can load & unload these tiles as needed based on distance from the camera, sectors of the world that the player has to see, etc.

Otherwise, the sparse textures behave just like any other texture in shaders - they can have mipmaps, can use all texture filtering modes, etc. If you happen to read from a tile that’s not present, you can get undefined result (on many GPUs the result is a black color, but that’s not guaranteed).

Note that not all hardware and platforms support sparse textures. For example, on DirectX systems they require DX11.2 (Windows 8.1) and a fairly recent GPU; and on OpenGL they require ARB_sparse_texture extension support. Sparse textures also require a Unity Pro license.

See SparseTexture scripting class for more details.

Example Code

A small example usage might be a map-like application that creates a large texture, but only a small camera-visible portion needs to be in memory at any time. As the camera moves, newly visible tiles are loaded, and no longer visible tiles are unloaded.

Sample project: SparseTextureExample.zip. In this example, a simple procedural texture pattern is generated for simplicity. Note that this will need a recent GPU and a DirectX 11.2 (Windows 8.1) system, or using OpenGL with ARB_sparse_texture support.

Previous
Compute Shaders
Next
Graphics Hardware Capabilities and Emulation