Three-dimensional light modulation using a piecewise implementation of the Gerchberg-Saxton algorithm