MegaTexture (cont.)

At run-time the engine will stream the previously created tiles based on the player's location to a fixed collection of surfaces. Each tile fits into a "concentric ring" around the player where closer "rings" are tiles belonging to the lower (higher quality) mipmap chain. After streaming, the engine will software decompress the tiles and compress them to DXTn format for uploading to the GPU. A special fragment program is in charge of applying filtering to the tiles. Because it's using a fixed collection of surfaces (whose contents - the tiles - change) instead of adding/removing surfaces, MT's video memory load is fixed and lower than normal texture mapping.

Arnout: We use 128x128 tiles, uncompressed the first mip level (64x64x4 == 16KB) fits nicely into the CPUs cache which helps some parts of the algorithm. We have several levels of 2048x2048 textures. Some of these levels have their DCT data stored in memory, the other ones are stored on disk. Decompression, mipmap generation and DXT compression are all done on the fly. The video memory load is indeed constant. The same goes more or less for system memory, though due to the variable nature of DCT compression this is slightly different per Megatexture. If the image tends to compress more we usually try to use a bit less compression to gain some quality. Compression can be variable per tile as well, so we can apply more compression to areas a player sees less or only from a distance.

The following images shows the different concentric rings with alternating black and white colours. These rings will move as the camera moves, streaming in detail levels for the new underlaying MegaTexture.

Normal

Same area but showing the five MegaTexture levels of detail


Unlike other streaming solutions where you might have defaulted surface textures until the proper data is streamed in, with MegaTexture you also have at least the lowest quality level loaded until the proper detailed level is streamed and blended in smoothly. The game still uses a separate detail texture (and mask) to improve the perceived texture resolution though.

Advantages

Lower texture memory usage. MegaTexture directly uses around 13.5mb of texture memory. To this we add another 7mb for the specularity map, detail mask and detail texture. Here's a listing of the megatexture-related texture load, format and sizes in one of the maps:

2048 x 2048
2048 x 2048
2048 x 2048
2048 x 2048
2048 x 2048
512 x 512
512 x 512
1024 x 1024
DXT1
DXT1
DXT1
DXT1
DXT1
DXT1
RGBA8
RGBA8
2730 k
2730 k
2730 k
2730 k
2730 k
170 k
1365 k
5461 k
_megaLevel_4
_megaLevel_3
_megaLevel_2
_megaLevel_1
_megaLevel_0
megatextures/area22_lit_spec
megatextures/area22_lit_detail
megatextures/area22_lit_detailmask

Predictable texture memory overhead. The above texture load is constant throughout the game. Roughly 20mb for the terrain is excellent considering today's mainstream cards have 512mb of the stuff. This also means this technology is perfect for the Xbox 360 and PS3 as they already have less video memory than this.

Normally the dirt, snow, asphalt road and tire marks would have to be blended, but in MegaTexture they're all in the same texture.

Can send the entire terrain in a single batch to the GPU. As the terrain uses a single texture (and material) you can theoretically batch it together. Also, it reduces polygons/batches/texture blends because decals & polygon splits are no longer necessary to avoid texture repetition. The terrain texture is unique by itself.

Arnout: We could [batch it together], but in reality we use several batches so we can do some frustum culling as well as having real-time lights only causing multiple passes on part of the terrain. These batches are still sorted together to limit state changes.

Streaming and (de)compressing can be threaded.

Arnout: This is not as much a can, more a has to be. Without threading you would stall a lot. Our de/re-compression is fast, but it does process a lot of data. Think of it as if you were playing back and compression a video file at the same time as running the game. Multiple cores obviously help here.

MegaTexture allows lightmaps with no performance hit. Because the MegaTexture stores the texture information of all terrain surfaces, lightmaps could be baked and not take additional memory or blends. Because of the MT's native resolution and colour depth they would also be of very high quality with no noticeable stepping or banding; normal artefacts in most lightmap implementations.

Arnout: We don't actually use a lightmap for most of the geometry, though our artists did bake some ambient occlusion and the odd tree shadow in where it improved the looks. The neat thing of the Megatexture is that they could make this decision without requiring any additional code.

High quality shadows can be baked in without any memory hit.