You keep having this recurring nightmare of a shark chasing you underwater. Its glassy black eyes track your flailing escape, but its terrifying rows of hungry teeth loom larger and larger as the nightmare continues. You see those sharp teeth up close before you jolt awake, covered in sweat and shaking with the aftershocks of what you just witnessed. Again.

But what if that shark’s mouth was replaced by a cartoonish smile? That’s where virtual reality comes in with the recent work of Patrick McNamara, a Boston University School of Medicine associate professor of neurology. Earlier this year, he and his team invited 19 study participants who said they have frequent nightmares. Using joystick and gesture controls, they could modify the threatening visuals to make them less frightening, such as using a drawing tool to cover up the shark’s teeth or a sizing tool to shrink the mouth down. Later, participants were asked to write a narrative about their newly edited visual experience.

This approach to using image rehearsal therapy, a common method of helping nightmare sufferers confront the source of their fear, resulted in “a significant reduction (from baseline to trial end) in anxiety levels, nightmare distress, and nightmare effects,” as his paper states in the journal Dreaming.

“If we can teach people to control the scary images they see, that can help them get rid of their nightmares,” McNamara says in an interview. Since VR is such an immersive environment compared to watching images on a flat screen, participants can “redraw those images so they can turn a gun, say, into a flower.”

He goes on to explain that what makes nightmares so repetitive is the loss of control. “If you can control the narrative of your nightmare, you can reduce those obstructive images, which can sometimes even appear to you in the day,” says McNamara, who is also the author of Nightmares: The Science And Solution Of Those Frightening Visions During Sleep.

McNamara credits VR for shouldering the burden of imagery generation, taking it off of the patient by creating and presenting the images for them.

Surveying this new method of helping people manage their nightmares, Dr. Nitun Verma, a spokesperson for the American Academy of Sleep Medicine, says in an interview, “Traditionally image rehearsal therapy involves writing out the story, so a VR version is obviously using a different method. There is promise for VR to be involved nightmare treatment, but there needs to be more follow-up studies.”

In 2019, Chris N. W. Geraets, a PhD student at the University of Groningen, authored a study suggesting that combining cognitive-behavioral therapy with VR could help people suffering from social anxiety disorder. It’s been thought that stress and mental health illnesses are leading causes of nightmares, which reportedly affect two to six percent of the world’s population on a weekly basis.

“Even though VR is not real, it is real enough to get psychological and physical reactions. We can use this to give therapy with VR exposures too hard to treat groups with low thresholds,” Geraets is quoted as telling media.