Batches
Batching is the process of rendering many parts of the scene at the same time with the same texture in order to improve performance. The fewer batches that are required to render the scene, the quicker it can be rendered. Therefore, by reducing the number of different textures/shaders a map uses (hence fewer batches), the quicker the scene can be rendered.
Contents
Example
The image on the right demonstrates how batches are used to render an interior portion of Sewer. Each colour indicates a different batch group. The fewer different colours there are, the fewer the number of batches there are, and therefore the quicker the scene should be rendered.
Each colour typically indicates a different texture, since different textures have to be rendered in different batches. Therefore the number of batches required to render a scene can be reduced by combining many textures into one texturesheet, and using that texturesheet to texture the map accordingly. All faces that use the same texture sheet are then batched and rendered together.
Because of this, it is often better to be creative with the use of texture sheets for some map details. This means using small parts of the textures that are in your texture sheet for things like railings and frames, rather than adding textures specifically for those purposes.
Batches are created automatically by the engine. As a designer, your main concern is to ensure texture sheets are used appropriately to reduce the number of batches. Also, an awareness of how LOD Groups and Map Objects affect the batch count is essential for maintaining performance.
Cost
Unlike textures - where more memory is required for each texture used - batches mainly affect CPU usage. However, the impact is minimal per batch compared to using more textures instead.
Texture Sheets
Sewer
The image below is of the building in Sewer's first objective. This building uses several texture sheets, one of which combines four different textures into one, reducing the number of batches required to render it. You can see other parts of the building are different colours (mostly blue, pink and yellow) because those faces use a different texture sheet and are hence rendered in a different batch.
Refinery
This image shows one of the shanty buildings in Refinery.
The building uses a texture sheet for its main walls (in red), and a second large texture sheet for many of its sign and doors (in light pink). These are rendered in two different batches and in total, the building is reduced down to just 5 or 6 batches. Since other buildings use the same textures and are hence in the same batch, rendering the pictured area is far faster thanks to the use of texture sheets and hence batching process.
If this building had been constructed in the traditional way (without texture sheets), this building would have required about 20 or 30 different texture files and would require about 20 or 30 batches to render the exact same scene. Since each batch carries extra rendering overhead, reducing the number of batches from 30 to 5 yields a significant rendering speed-up.
Texture Sheets
Batches are typically reduced by using the Atlas Editor to bundle many oft-used textures together into one. Many maps have as many as 20 texture sheets each, combining a hundred of more textures and therefore offering a huge saving.
A good texture sheet is able to be used on different structures yet retain variety, such that a large area can be drawn with just a handful of different texture sheets. Common textures, such as signs and doors are often placed in a texture sheet as they're so frequently used, and can generally be rendered in the same batch.
The disadvantage of texture sheets is that they only tile in one direction, but for more structures this isn't a problem, and can be countered by using multiple brushes/faces to achieve tiling using polygons (the cost of rendering more polygons is negligible compared to the cost of rendering more batches.)
- See Atlas Editor and Texturesheets
Developer Commands
- r_showBatches 0/1 - this can be used either in editWorld or in-game for a visual representation of batches required for a scene, using a different colour for each batch (as seen in above screenshots)
- r_showBatchInfo 0/1 - prints information about the batches rendered in the current frame, including where the batches came from (environment, megatextures, models etc.)
- r_showBatchSize 0/1/2/3 - highlights draw batches that fall below the desired polygons per draw call (purple really bad, red bad, yellow moderate, green good)
- r_showPrimitives 0/1 - reports the number of draws (batches) required to render the last frame
- r_showTextureMemory 0/1/2 - displays how much texture memory is in use (1 = total texture memory used, 2 = memory used by textures to draw the previous frame)
Batching Process
There are many factors that go into determining the number of batches required for a scene:
- Every entity (that is not a model_static) causes batches to be created for their models, so entities with the same model will NOT get merged together in a single batch (except model_static as mentioned before, but this is done by dmap)
- Every material on a model will create at least one batch, so for example the factory has batches for the two skins, the tiled roof, the tracks, and the cogs. All the polygons with the same material in a model will be merged together in a single batch though.
- Every stage in your shader (like "{ stuff }") will create a new batch.
- Bumpmapped surfaces will create several batches for each light that shines on them
- Ambient lit surfaces will create an extra batch for this