Syd Barrett's tortured spirit was already hovering over Pink Floyd's ninth studio album, even before he unexpectedly crashed the sessions for Wish You Were Here on June 5, 1975.

Both the emotive title track and shimmering, psychedelic epic "Shine On You Crazy Diamond" were inspired by Barrett, the band's former frontman, with chief writer Roger Waters meditating on themes of isolation and inward escape. So, when the long-absent musician – portly, with distant gaze, shaved head and eyebrows – randomly arrived during a mixing session for "Diamond," the coincidence reduced the band to a mixture of shock and depression.

It's not as if Barrett, Floyd's co-founder and the driving creative force behind their debut LP, 1967's The Piper at the Gates of Dawn, left the band on good terms. His mental instability, erratic stage behavior and addiction to LSD made him a liability, and guitarist-singer David Gilmour was brought in as a replacement.

Barrett made minimal contributions to 1968's A Saucerful of Secrets, but his warped mysticism ultimately vanished: He released two studio albums – 1970's The Madcap Laughs and Barrett, both co-produced by Gilmour and featuring Waters and keyboardist Richard Wright, respectively – but Barrett rarely worked after that point, eventually retreating from the spotlight.

His fortunes seemed to be changing in 1974, when Barrett made some formative – though ultimately fruitless – recordings at Abbey Road. When he crashed the same studio during Pink Floyd's session less than a year later, however, he was bloated and mentally foggy – a sad shell of the psychedelic visionary whose warped vision guided the band to early stardom.

Pink Floyd were confused by his presence, assuming he had to be a crew member. But when Gilmour eventually identified their former bandmate, Waters broke down in tears. That June day also happened to be Gilmour's wedding day, so Barrett wandered into the guitarist's wedding reception at EMI. He left without telling anyone, disappearing as strangely as he'd arrived. The experience had a profound impact on the band, particularly Waters, who even incorporated a lyrical reference to the early Barrett-penned single "See Emily Play" on Wish You Were Here.

"I'm very sad about Syd, [though] I wasn't for years," Waters said in 1975. "For years, I suppose he was a threat because of all that bollocks written about him and us. Of course, he was very important and the band would never have fucking started without him, because he was writing all the material. It couldn't have happened without him, but on the other hand, it couldn't have gone on with him. He may or may not be important in rock 'n' roll anthology terms, but he's certainly not nearly as important as people say in terms of Pink Floyd. So, I think I was threatened by him."

Gilmour, who co-wrote the music to both the title track and "Shine On," has trouble separating these classic songs from his memories of the former Floyd icon. "Although 'Shine On You Crazy Diamond' is specifically about Syd and 'Wish You Were Here' has a broader remit," Gilmour said in the 2012 documentary Pink Floyd: The Story of Wish You Were Here, "I can't sing it without thinking about Syd."