How it worksTriangles arrive in no particular order, yet the nearer ones have to win. The trick is a second image the same size as the picture, holding a depth instead of a colour. As each fragment is drawn the GPU compares its depth with the value already stored: closer, and it paints the colour and writes the new depth; farther, and it's thrown away. No sorting, no overdraw decisions — just one compare per pixel. Slide the middle card's depth and watch the same three shapes re-stack as its stored value crosses its neighbours'. The depth view shows that buffer directly: bright is near, dark is far.