An electronic device adapted to detect a person's 3D face ID by optical sensing, comprising: a face illumination source that includes: a periodic array of face illumination light sources arranged at different locations from one another, each operable to produce a face illumination light beam and including an optical projection device that projects the face illumination light beam along a face illumination direction that is different from a face illumination direction of an adjacent face illumination light source; and a diffractive optical element structured to include an array of different regions of varying optical thickness values that transmit light and located in optical paths of the face illumination light beams to convert each face illumination light beam into a patterned face illumination light beam that includes a pattern of illumination light spots, such that the different face illumination light beams from the periodic array of face illumination light sources are converted by the diffractive optical element into different patterned face illumination light beams along different illumination directions each including the pattern of illumination light spots to illuminate a person's face for optically detecting a person's face; wherein in the periodic array of face illumination light sources, the optical projection device in each face illumination light source includes one or more collimation lenses to provide a desired amount of optical collimation to set a desired beam divergence of the output illumination beam and the one or more lenses is oriented to direct or steer the projected beam along a designed illumination direction towards the diffractive optical element; and the array of different regions of varying optical thickness values of the diffractive optical element is structured to cause the illumination light spots to be spatially distributed to have a unique local pattern of illumination light spots in each local region in the spatial pattern that is different from other local regions in the spatial pattern; and the unique local pattern in the structured illumination light is coded with a uniqueness window. a face illumination source that includes: a periodic array of face illumination light sources arranged at different locations from one another, each operable to produce a face illumination light beam and including an optical projection device that projects the face illumination light beam along a face illumination direction that is different from a face illumination direction of an adjacent face illumination light source; and a diffractive optical element structured to include an array of different regions of varying optical thickness values that transmit light and located in optical paths of the face illumination light beams to convert each face illumination light beam into a patterned face illumination light beam that includes a pattern of illumination light spots, such that the different face illumination light beams from the periodic array of face illumination light sources are converted by the diffractive optical element into different patterned face illumination light beams along different illumination directions each including the pattern of illumination light spots to illuminate a person's face for optically detecting a person's face; wherein in the periodic array of face illumination light sources, the optical projection device in each face illumination light source includes one or more collimation lenses to provide a desired amount of optical collimation to set a desired beam divergence of the output illumination beam and the one or more lenses is oriented to direct or steer the projected beam along a designed illumination direction towards the diffractive optical element; and the array of different regions of varying optical thickness values of the diffractive optical element is structured to cause the illumination light spots to be spatially distributed to have a unique local pattern of illumination light spots in each local region in the spatial pattern that is different from other local regions in the spatial pattern; and the unique local pattern in the structured illumination light is coded with a uniqueness window.