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.
What exactly is used in the Painter's algorithm to determine the order in which objects should be drawn?
Answer
Usually the distance of the midpoint of a polygon to the camera is being used for z-sorting. The painter's algorithm cannot be 100% accurate by it's nature. There will always be cases where sorting will fail, no matter what reference point you use.
If you want correct z-sorting with the painter's algorithm, you'll have to slice overlapping polygons into smaller parts (eg. by using a quad-tree) and sort these parts individually. This can become quite heavy on the CPU though..
Found this Powerpoint file that illustrates the issue nicely (PDF Version).
No comments:
Post a Comment