Z-sorting is about sorting triangles and deciding in which order the triangles need to be drawn on the viewport. Drawing a render happens from furthest triangles to the closest triangles, based on their position in relation to the camera. This is known as the painter's algorithm.
There are several ways to affect the order in which objects are rendered.
We learned about viewport layers, which are similar to layers in Photoshop, for example. These layers can be ordered in three ways:
ViewportLayerSortMode.Z_SORT
ViewportLayerSortMode.ORIGIN_SORT
ViewportLayerSortMode.INDEX_SORT
The z-sorting issues we've seen with the mill and floor were solved by index sorting. Based on the position of the camera, we changed the layer index order. This is not the solution for all z-sorting problems. But for the example discussed in the chapter, it worked great.
Besides adding and sorting viewport layers as children of the viewport, we've also seen how we can nest viewport layers as children of other...