A transparent waveguide for use in tracking an eye illuminated by infrared light includes an input coupler and an output coupler. The input coupler includes a stack of electronically switchable diffractive gratings arranged parallel to one another each of which has a respective lens power that causes each of the gratings in the stack to have a different focal length. Each grating when turned on couples received infrared light into the waveguide. A sensor images an eye in dependence on infrared light beams that exit the waveguide at the output coupler. Images of an eye obtained using the sensor are analyzed to determine which one of the electronically switchable diffractive gratings when turned on provides a best focused image of the eye or portion thereof. The one of the electronically switchable diffractive gratings which provides the best focused image of the eye is used for imaging the eye during eye tracking.