Given the variety of eyes found throughout the animal kingdom, evolutionary biologists once thought eyes had evolved independently dozens or even hundreds of times. Thanks to DNA sequencing and other molecular tools, we know today that modern eyes are built from many of the same genes. Ancient "toolkit" genes (such as opsins, Pax, and Otx) first evolved in a primitive ancestor that gave rise to all animals with eyes. These genes have been preserved throughout evolution, and today we still find them at work in all types of eyes. The diversity of modern animal eyes is the result of refinements and specializations built on top of this basic genetic framework.
Not all eye features are built using the same genes. Lenses, for example, are refinements that arose when different genes were recruited to perform a similar task in different organisms. Similarly, shielding pigments arose from a variety of genes.
Molecular analysis has shown that many genes in the eye, whether shared among organisms or not, had other functions first. They were later recruited to take on second jobs.