If last month's Twitter storm over #TheDress taught us anything — and that's up for debate — it's that the way we perceive color works in weird ways.

Over millennia, chameleons have used that to their advantage, and now scientists have a better understanding of exactly how they do what they're so famous for doing. (Video via aidnature.org)

New research on panther chameleons shows that a layer of microscopic nanocrystals in the chameleon's skin alter the way in which light reflects off the lizard, which allows it to change color. (Video via BBC)

It hinges on the distribution of those nanocrystals: When the chameleon becomes excited, the space between the nanocrystals expands, changing the color.

The expanding distribution of crystals lengthens the wavelengths of light reflecting off of them: Longer wavelengths, which reflect red, produce an orange skin color. (Video via TED)

Chameleons change their color for a number of reasons beyond camouflage, including when they're confronted with a possible mate or a rival male chameleon. (Video via Nature)

The researchers also found that the chameleons have another layer of larger nanocrystals beneath the first, which reflects a lot of sunlight, especially near-infrared frequencies.

In the paper, researchers theorized that because some chameleons live in dry, hot areas where they're exposed to large amounts of sunlight, "the 45 percent decrease in sunlight absorption caused by (the layer) is likely to be advantageous for survival."

However, the researchers found similar systems in other chameleons that aren't exposed to as much sunlight, so whether that layer serves a specific sun-related purpose remains to be seen. (Video viaHowcast)

The presence of both layers is unique to chameleons, and, the researchers say, an "evolutionary novelty."

This video includes an image from Getty Images.