Radiative transfer in thick atmospheres with an arbitrary scattering function