Genetically, we all have far more in common than we have differences. One way to think of this is with the following very simple analogy. We are all cherry cupcakes, but some of us have green frosting with chocolate curls, some pink frosting with coconut flakes, some white frosting with confetti sprinkles, some chocolate fudge frosting, etc. However, the vast majority of what makes us human, the cherry cake, is held in common by all humans. Variation in pigmentation is directly related to the need for past human populations, lacking our present technological sophistication, to adapt to varying latitudinal environments.
Human origin is in the equatorial zone of Africa.
In these latitudes, UVB radiation is at its most intense. UVB radiation at the equator strikes the earth at a 90 degree angle, penetrating the ozone layer at its thinnest point. While all humans have the same average number of melanocytes, these melanocytes are genetically programmed to produce different amounts of melanin in different individuals. The melanin layer diffuses the UVB radiation and prevents its penetration to the lower skin levels where it could cause cancer. Melanomas are rapid-spreading cancers which can kill within a few years of their occurrence.