Photonic chips can calculate optimal shape of light for next