A direct solution of the radiative transfer equation: Application to Rayleigh and Mie atmospheres