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:
- Sort each polygon by depth
- 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