Smart radio environments (SREs) are seen as a key rising concept of next generation wireless networks, where propagation channels between transmitters and receivers are purposely controlled. One promising approach to achieve such channel flexibility relies on semi-passive reflective Reconfigurable intelligent surfaces (RISs), which can shape the bouncing multipath signals for enhancing communication quality of service, making localization feasible in adverse operating conditions, or reducing unwanted electromagnetic emissions. This paper introduces a generic framework that aims at optimizing the end-to-end precoder controlled by RISs, so that arbitrary beam patterns can be generated, given a predefined lookup table of RIS element-wise compl...