Depth buffer is used. If the pixel is not changed there is no reason to shade again. The optimization depends on the depth and the nodes isModified