Night-time vision evolved millions of years ago in early mammals, a study suggests.