How to gain accurate results with Painter's algorithm?

Posted by pimvdb on Game Development See other posts from Game Development or by pimvdb
Published on 2011-07-01T10:47:45Z Indexed on 2011/07/01 16:31 UTC
Read the original article Hit count: 632

Filed under:
|
|
|

A while ago I asked how to determine when a face is overlapping another. The advice was to use a Z-buffer.

However, I cannot use a Z-buffer in my current project and hence I would like to use the Painter's algorithm. I have no good clue as to when a surface is behind or in front of another, though. I've tried numerous methods but they all fail in edge cases, or they fail even in general cases.

This is a list of sorting methods I've tried so far:

  • Distance to midpoint of each face
  • Average distance to each vertex of each face
  • Average z value of each vertex
  • Higest z value of vertices of each face and draw those first
  • Lowest z value of vertices of each face and draw those last

The problem is that a face might have a closer distance but is still further away. All these methods seem unreliable.

Edit: For example, in the following image the surface with the blue point as midpoint is painted over the surface with the red point as midpoint, because the blue point is closer. However, this is because the surface of the red point is larger and the midpoint is further away. The surface with the red point should be painted over the blue one, because it is closer, whilst the midpoint distance says the opposite.

enter image description here

What exactly is used in the Painter's algorithm to determine the order in which objects should be drawn?

© Game Development or respective owner

Related posts about 3d

Related posts about algorithm