Take the distance of objects into account to prevent shapes from further back overlapping shapes in front.