Painter’s algorithm is used in 3D graphics rendering to ensure that elements closer to the viewer are rendered in the top layer.

Conceptually Painter’s Algorithm works as follows:

  1. Sort each polygon by depth
  2. Place each polygon from the farthest polygon to the closest polygon

Pseudocode

sort polygons by depth
 
for each polygon p:
    for each pixel that p covers:
        paint p.color on pixel