Optimization of 3d gradient