Automated optimization of grayscale masks for 3D micro-structuring