<ul>
<li><p>In the <strong>painter's algorithm</strong>, you first sort all graphics elements
on depth (deepest first) and
then one-by-one fully paint them into the image on top of each other.
That way, deeper elements are obscured by less deep element.
(Intersecting graphics element require special attention.)</p></li>
<li><p>In the <strong>depth-buffering algorithm</strong>,
you store the current depth of each pixel in the image
(in addition to other pixel info),
and fully paint each graphics element pixel-by-pixel,
where an image pixel is updated
only if its depth is more than that of the new pixel.</p></li>
</ul>

<p>So, there is a time-memory tradeoff:</p>

<ul>
<li>The <strong>painter's algorithm</strong> requires an extra sorting step (<strong>costs time</strong>),
but avoids storing additional (depth) information per pixel (<strong>saves memory</strong>).</li>
<li><strong>Depth-buffering</strong> avoids sorting (<strong>saves time</strong>),
but stores extra (depth) information per pixel (<strong>costs memory</strong>).</li>
</ul>

CC BY-SA 4.0
2019-03-22T08:40:16.513Z
2019-03-22T08:40:16.513Z
Tom Verhoeff
<p>In short painter's algorithm can't deal with intersecting geometry.</p>

<p>Suppose that you draw a plane angled away from the camera, and a plane angled towards the camera. The planes intersect in an 'X' shape.</p>

<pre><code>Camera ------&gt; X
</code></pre>

<p>With painter's algorithm no such ordering exists that will render the shape exactly. You would only see whichever plane you decided to draw last.</p>

<p>The Z-Buffer or Depth-Buffer stores the nearest depth per each pixel relative from the camera. If another triangle is rasterized and has a depth less than the current depth buffer value it is accepted, if it's depth is greater, it is rejected. This is called a depth test.</p>

CC BY-SA 4.0
2018-12-04T09:16:48.160Z
Painter's algorithm *WILL* work with overlaps etc provided you take the steps described by Newell, Newell & Sancha.    https://en.wikipedia.org/wiki/Newell%27s_algorithm
Simon F
CC BY-SA 4.0
2018-12-02T07:45:10.007Z
2018-12-02T07:45:10.007Z
Calvin
<p>In hidden surface removal, how does the Z-buffer algorithm work vs. painter's algorithm?</p>

<algorithm>
Z-Buffer algorithm vs Painter's algorithm?
user9778
# Z-Buffer algorithm vs Painter's algorithm?

(Asked by: username_0 on 2018-12-02)

In hidden surface removal, how does the Z-buffer algorithm work vs. painter's algorithm?

**Tags:** algorithm


---

## 2 answers

### Answer by username_2 on 2018-12-02. Score: 4 | Accepted answer

In short painter's algorithm can't deal with intersecting geometry.

Suppose that you draw a plane angled away from the camera, and a plane angled towards the camera. The planes intersect in an 'X' shape.

```
Camera ------> X

```

With painter's algorithm no such ordering exists that will render the shape exactly. You would only see whichever plane you decided to draw last.

The Z-Buffer or Depth-Buffer stores the nearest depth per each pixel relative from the camera. If another triangle is rasterized and has a depth less than the current depth buffer value it is accepted, if it's depth is greater, it is rejected. This is called a depth test.

> **Comments:**
> **username_3**: Painter's algorithm *WILL* work with overlaps etc provided you take the steps described by Newell, Newell & Sancha.    https://en.wikipedia.org/wiki/Newell%27s_algorithm  

---

### Answer by username_1 on 2019-03-22. Score: 5

* In the **painter's algorithm**, you first sort all graphics elements
  on depth (deepest first) and
  then one-by-one fully paint them into the image on top of each other.
  That way, deeper elements are obscured by less deep element.
  (Intersecting graphics element require special attention.)
* In the **depth-buffering algorithm**,
  you store the current depth of each pixel in the image
  (in addition to other pixel info),
  and fully paint each graphics element pixel-by-pixel,
  where an image pixel is updated
  only if its depth is more than that of the new pixel.

So, there is a time-memory tradeoff:

* The **painter's algorithm** requires an extra sorting step (**costs time**),
  but avoids storing additional (depth) information per pixel (**saves memory**).
* **Depth-buffering** avoids sorting (**saves time**),
  but stores extra (depth) information per pixel (**costs memory**).


---

