Cloak for multilayered and gradually changing media