The origin of planetary rings