At first, they look like stars. I see them as I gaze upward at the ceiling of a flooded, pitch-black cave—hundreds of blue pinpricks. As my eyes habituate to the darkness, more and more of them resolve, and I see that they are brighter and more densely packed than any starry field. And unlike the night sky, these lights don’t appear as a flat canvas, but as a textured one. Some are clearly closer to us than others and they move relative to each other, so the whole tableau seems to undulate gently as our boat sails beneath it. These lights are not astrological, but entomological. They are produced by insects called glowworms.

The word “glowworm” is sometimes used colloquially to describe fireflies and click beetles. The insects in the caves aren’t part of either group. They’re maggots—the larvae of small flies called fungus gnats. Hatching out of eggs that are laid on the ceilings of caves, the larvae spin hammocks of silk. From these hammocks, they lower up to 70 threads of silk—extremely strong, and coated with blobs of sticky mucus. These threads, which dangle downward like bead curtains, are traps, and the glowworms bait them by triggering a chemical reaction in their rear ends that emits blue light. The light lures in other insects that get entangled in the silk, and are eventually reeled in and devoured by the glowworms.

After 6 to 12 months of eating whatever they can ensnare, the larvae transform into adults, which lack mouths and never eat. Their only job, in the final few days of their lives, is to mate and create the next generation of glowing-bottomed, trap making juveniles.

These luminous insects are found in the dark and damp corners of New Zealand and Australia, and the Māori know them as “titiwai”—a word that refers to light reflected in water. That etymology reflects the glowworms’ habit of inhabiting damp and dark places, including riverbanks, tropical rain forests, and—most famously—caves like those at Waitomo. For thousands of tourists, these places are major attractions, where one can gaze at the ethereal beauty of a living, indoor star field. But for the thousands of moths, midges, and mayflies flitting around in the darkness, these are places of death.

The origin of the glowworms’ fatal beauty is unclear, but you can piece together a plausible story by looking at their relatives. Most fungus gnats live and feed on mushrooms, and some of them build sticky webs to trap edible spores. Such webs would inevitably and accidentally have snagged passing insects. Tempted by this source of protein-rich food, some fungus gnats went all-in on carnivory, and transformed their spore-catching webs into dangling fishing lines for capturing flying prey. Such prey are plentiful in the tropical caves of South and Central America, and Southeast Asia, where many fungus-gnat species still dangle their sticky threads. But in temperate regions like Australia and New Zealand, where prey are scarcer, fungus gnats would have needed a way of attracting their victims. That, perhaps, is why they started to glow.

Kristina D. C. Hoeppner / Flickr

They did so, bizarrely enough, by refashioning their kidneys. Insects have a series of tubes called Malpighian tubules that branch off their guts and produce urine, much like our kidneys do. In glowworms, the cells at the very end of these tubes have become swollen and transparent—they’re the ones that glow. “It’s absolutely unique,” says David Merritt from the University of Queensland. “Insects are such a broad and diverse group that you’ll always find some insect that has done something weird with a preexisting structure.”

Merritt has been studying the glowworms for years. Over that time, he has shown that they control their light with great finesse, using nerve cells that run into the light-producing kidney-esque organs. If you shine a light onto a glowworm, it will switch off its own light after a few minutes. If you anesthetize one, it will glow very brightly before dimming down again. And if you give them good vibrations, they’ll, er, get the excitations. There are some tours in New Zealand, Merritt tells me, where guides will deliberately hit the water or cave walls with an inflated inner tube; in response, the field of living stars will double in brightness. Merritt can achieve the same effect in his lab by pressing a vibrating cellphone against the aquarium where his captive glowworms live. “They really brighten up intensively if they detect vibration,” he says. “I’m not sure of the function.”

He also found that the glowworms glow on a cycle. Even in the constant darkness of a cave, cut off from the daily rhythms of the outside world, they’ll glow particularly brightly at around 6 or 7 p.m. They also synchronize with each other. “We’ve done experiments where we get them out of sync and put them together—and they sync up over five to six days,” says Merritt. “I think they’re maximizing the population’s light output for the time when there are most insects flying around inside the cave.”

All of which makes me wonder: Are there cheating glowworms that save energy by going dark, and rely on the light of their neighbors to lure victims into their hanging snares? Are there cave insects that have evolved to resist the fatal attraction of these blue lights? Do you get populations of glowworms that switch their cycles to glow at different times of the day, to attract insects during the quiet hours when the main colony has dimmed down? And how do these insects even produce their glow?

That last question, at least, has an answer. Aptly enough, glowworms light up their underworld with a pair of chemicals that have a satanic etymology—luciferins and luciferases, after the Latin for “light bringer.” When luciferins react with oxygen in the presence of luciferases, they produce light. Fireflies, jellyfish, and many other luminescent animals glow in the same way, and each group has its own distinctive luciferins and luciferases. “They’re generic terms, like ‘oven,’” says Kurt Krause from the University of Otago. “I’ve got one, you’ve got another, and they both make heat, but they’re different.” Similarly, Krause and his colleagues have found that the glowworms have their own unique light-making chemistry, which they’re starting to tease apart.

Why bother? Partly, it’s because luciferases are really useful to scientists. Researchers can use them to engineer the cells of non-glowing creatures so that they light up when certain genes are active, allowing them to track cancer cells, detect viral infections, and more. And since different kinds of luciferase glow with their own colors, the more you discover, the more things you can track at once. “We think the glowworm has an interesting biochemical story to tell, and we think that hopefully it’s something that can be commercialized,” says Krause. “But even if it’s not, it’s cool! What’s cooler than organisms that make light? When you get involved with them, you get mesmerized.”

That’s certainly the case when I see the lights for myself. In Waitomo, I sail beneath a field of living stars, produced by the repurposed kidneys of synced-up maggots that are trying to lure other insects into death traps. The true nature of these lights is weird and perhaps even grotesque. But they are strong enough that when I look to my right, I can see my partner’s face in the darkness of the cave. And she is smiling.