Moiré-pattern interlayer potentials in van der Waals materials in the random-phase approximation