Depth Sorting

Here we’re at the depth sorting module of the main loop. In this module we sort our triangles in the right order.

We are dealing with the following code snippet of the Engine Loop:

main method
1def main(self):
2
3    ...
4
5        sorted_list = sorted(visiable_triangles, key=lambda triangle: triangle.centroids[2], reverse=True)
6        ...

In this line we sort the list visiable_triangles in descending order based on the z component of our triangles. The result is stored in a new list called sorted_list.

Note

Sorting by Z is a simplified method but works well for our purposes. For a professional engine, you would use a pixel shader.