Algorithm for Z-Buffer Method:
(a) Initialize every pixel in the viewport to the smallest value of z, namely z0 the z-value of the rear clipping plane or "back-ground". Store all values in the z-buffer.
(b) Start polygon loop i = 1 to n, n being the number of polygons.
(i) Scan converts each pixel, that is, determine the value of z for each (x, y) for the polygon.
(ii) Compare it with the z′ value stored for that (x, y). If z < z′, then the new point is closer to the viewer than the previous point, and therefore is visible in front of the previous point; reset z′ to the new value.
(c) End loop on i.
(d) Plot only the final z′ values in the z-buffer for all (x, y) in the viewport, with the appropriate colour or gray scale and other attributes.