The fate and observable properties of gamma-ray burst jets depend crucially on their interaction with the progenitor material that surrounds the central engine. We present a semi-analytical model of such interaction, which builds upon several previous analytical and numerical works, aimed at predicting the angular distribution of jet and cocoon energy and Lorentz factor after breakout, given the properties of the ambient material and of the jet at launch. Using this model, we construct synthetic populations of structured jets, assuming either a collapsar (for long gamma-ray bursts -- LGRBs) or a binary neutron star merger (for short gamma-ray bursts -- SGRBs) as progenitor. We assume all progenitors to be identical, and we allow little variability in the jet properties at launch: our populations therefore feature a quasi-universal structure. These populations are able to reproduce the main features of the observed LGRB and SGRB luminosity functions, although several uncertainties and caveats remain to be addressed.