Overdraw occurs when the GPU draws over the same pixel multiple times. This means compute resources and memory bandwidth are used for fragments that are not visible in the final frame. This is a waste of resources and it negatively impacts the performance of applications. Avoid overdraw if possible.
You can use a number of methods to avoid overdraw:
- Enable depth testing
Depth testing discards any fragment behind those already drawn.
- Enable back face culling
Back face culling removes triangles on the back of objects that are not visible.
- Sort objects then draw non-transparent objects
Ensure depth testing is enabled. It is required for this technique to work.
Sort the objects in the scene by distance from the camera.
You can save time sorting by keeping geometry in data structures such as Binary Space Partition (BSP) trees.
Draw the non-transparent objects in front to back order.
Draw the transparent objects last in back to front order.
- Optimize the use of transparency
Transparency is a useful effect but it can be resource intensive if there are many layers.
If you are using transparent objects you can reduce their drawing cost by:
Ensuring transparent objects are drawn last. If a transparent object is not drawn last your application might have to waste resources drawing the same object more than once.
Minimizing the number of transparent layers visible through each other.
Draw transparent objects after non-transparent objects.
Draw transparent objects in back to front order.