Posts

Showing posts from April, 2017

Rendering order and Z-sorting

Image
Rendering order and Z-sorting . In Unity, there are a couple of options using which we can control render order of the objects, two of them are 1. Render queue in shaders and 2. Painter's algorithm but eventually, what appears in front and what stays hidden is decided by Z-sorting/depth sorting. Here is the authoritative sequence of order of objects that will appear on the screen. Z-sorting/ Depth sorting is the final step to sort pixels based on the z-distance from the camera, but we can still turn ZWrite-off in the shaders (which in a way breaks Z-sorting). If we turn off ZWrite in all the shaders then render-queue will be in charge of deciding what comes in front and what goes in back If all shaders have ZWrite turned off and as well as they are on the same render-queue then the distance of their transform point from the camera will decide the render order. Eg : - ZWrite Off - Render Queue same - Painter's algorithm - ZWrite Off - Render Queue in