Calculating vertex gradients by partition