There is one particularly poignant moment in the new “Whitney” documentary — about the late, legendary pop goddess Whitney Houston — when her older half brother Gary Houston gets straight to the heart of the family dysfunction that contributed to his sister’s ultimate downfall. “There were always a lot of secrets,” he confesses. “If you don’t resolve things and you don’t deal with things, they never go away.”

But Oscar-winning director Kevin Macdonald didn’t discover the biggest secret of all — that both Whitney and Gary were allegedly molested by their late cousin, singer Dee Dee Warwick (sister of Dionne), when they were kids — until the 11th hour of making the film last fall. “I was just coming to the end of the edit,” Macdonald tells The Post. “We had worked on it for about 18 months, and then we heard this bombshell, which redefined the whole thing.”

This revelation gave the documentary — which opens in theaters Friday after premiering at the Cannes Film Festival in May — another tragic turn in Houston’s tale, which ended in 2012 when the 48-year-old singer accidentally drowned in her hotel room bathtub. (Cocaine use and heart disease were listed as contributing factors.) But in addition to taking a hard look at everything from her childhood trauma to her drug addiction, Macdonald also wanted to celebrate Houston as “one of the great artists of the late 20th century.”

“I wanted to try and understand and make a human portrait of this person who had become a kind of tabloid freak show,” says Macdonald. “I wanted people to see her on a human level as the little girl who got lost.”

To that end, Macdonald got full cooperation and “free access” to personal and behind-the-scenes archival footage from the Houston estate. “In order to tell someone’s story, you have to tell every aspect of the story,” says Pat Houston, Whitney’s sister-in-law and Gary’s wife, who served as one of the film’s executive producers. “Everybody has a story. She just played hers out in public because she was an icon.”

“Whitney” traces Houston’s story back to her early years in the streets of Newark, New Jersey, where she was born into a musical family that included her mother, esteemed backup singer Cissy Houston, and cousins Dionne and Dee Dee Warwick. After the 1967 Newark riots, the family relocated to East Orange, New Jersey, but that didn’t make everything better for Houston: The film reveals that the future prom queen of pop was bullied growing up.

“I was shocked learning about how bullied Whitney was at school,” says Macdonald, “and how it was because she was considered to be this light-skinned black person in a darker-skinned neighborhood, and [because] her mother dressed her prettily. One of the keys to understanding her is how friendless she was as a kid because of that.”

When her mother, Cissy, was on the road with her music career, and father, John, would also be away, Houston and her brothers Gary and Michael would stay with different people, which seems to be when she suffered the sexual abuse that is revealed on-screen by both Pat Houston and Whitney’s longtime personal assistant, Mary Jones. “I think she was ashamed,” says Jones when asked why Houston never told her mother about the abuse. “She used to say, ‘I wonder if I did something to make her think I wanted her.’”

“Whitney” recounts that, while working at a summer job, a 16-year-old Houston met Robyn Crawford, who went on to become her personal assistant. The singer was long rumored to have had a romantic relationship with her confidant. In the film, Houston’s longtime musical director Rickey Minor describes her sexuality as “fluid,” while Gary Houston dismisses Crawford as “a nobody … She was something I didn’t want my sister to be involved with. It was evil, it was wicked.”

Both Gary and Michael Houston — who would travel with their sister and serve as bodyguards — admit to their own evildoing in facilitating and participating in their sister’s drug use. “If anything was gonna be done, I was gonna be the one to show it to her,” says Michael in the film. But it was a friend of the brothers, Keith Kelly, who admits that he was the one who first gave Houston drugs — a bag of marijuana and a snort of cocaine — on her 16th birthday.

Certainly, the film clears up any lingering misconception that it was Houston’s ex-husband, Bobby Brown, who exposed her to drugs. Says Macdonald: “There’s an amusing but also kind of tragic moment where her brother Michael says, ‘We used to do rings around Bobby. He was not able to keep up with us. We lapped him in drug-taking. He’s a lightweight.’ That kind of vindicates Bobby.”

Brown himself, though interviewed on camera, refuses to discuss any drug use. “That has nothing to do with this documentary,” he insists when pressed. But, Macdonald says, “I think you often learn more by what people refuse to say than what they do say. People like Bobby had red lines that they wouldn’t cross.”

The film leaves no doubt, however, about Houston’s vaunted vocal powers. In her true element singing live, she would transcend any of her studio recordings. “Whitney” captures this from her early days when she filled in for her mother (who was playing sick to test if her daughter “could cut it”) at the now-defunct Manhattan nightclub Sweetwater’s and in her 1983 TV debut on “The Merv Griffin Show,” to her game-changing performance of “The Star-Spangled Banner” at the 1991 Super Bowl. The film also documents the “I Will Always Love You” phenomenon brought on by Houston’s 1992 blockbuster movie “The Bodyguard.”

For Pat Houston, the experience of making “Whitney” has brought the music back to her — and hopefully, the world. “Since her passing, I hadn’t really just sat down and listened to her music. Just hearing her music throughout the film, you realize just how special she was,” she says. “The purpose was to put [the scandals] all to rest so that we can celebrate the legacy that she left, which is her music.”