Pharrell Williams’ “Happy” was born from last year’s animated hit “Despicable Me 2,” but that was just the beginning.  It didn’t just sell 10 million units, it became a global phenomenon (a term that applies to only a handful of songs in Hollywood history).

Producer Reginald Hudlin, who used “Happy” as the finale of his recent Hollywood Bowl tribute to “The Black Movie Soundtrack,” says: “From the length of his career to his range of styles, Pharrell is one of the most important artists of his generation. The ‘24 Hours of Happy’ video is one of the most innovative and addictive ideas in that medium ever.”

The infectious song is the high point of Williams’ recent foray into films, largely facilitated by composer Hans Zimmer. “The thing that I loved about ‘Happy,’ is that Pharrell hadn’t just written a song,” Zimmer says. “It was a piece of art. The proof is, that song now has a life of its own, bursting out of the confines of the medium it was written for.”

It all started in 2010, when Zimmer produced the score for the first “Despicable Me,” which featured songs by Williams and a score by Williams and Brazilian guitarist Heitor Pereira. Later, Williams and Zimmer created new music for the 2012 Oscarcast.

Before long, they were back in the studio, experimenting with fresh ideas for a Superman film. Williams was one of a dozen drummers whom Zimmer put into a studio (along with eight pedal steel guitar players), creating a “drum circle” that would help define the middle-America roots of Clark Kent in “Man of Steel.”

Then came “Despicable Me 2,” for which Williams penned three new songs, including the Oscar-nominated “Happy,” and their most unusual collaboration, on this year’s “The Amazing Spider-Man 2.”

“I was talking to Pharrell about it,” Zimmer recalls. “It was around the time he was writing ‘Happy,’ and we talked about the power of music. What if we did ‘Spider-Man’ as a band?”

Soon Zimmer added guitarist Johnny Marr, DJ-turned-film-composer Junkie XL and others to the supergroup. They all piled into Zimmer’s Santa Monica studio, had a midnight screening of the film, “and the next day we just came in and started playing. There were great moments: Johnny going, ‘Hey, I’ve got these chords,’ and Pharrell going, ‘Can I have a microphone?’

“Here’s the man who wrote ‘Happy’ writing a song with the man who worked for years with Morrissey. You couldn’t get any further away, musically.”

Zimmer adds: “Spending time with Pharrell is experiencing a hurricane of ideas. His music is borne out of a thirst for the knowledge of everything — painting, writing, science, psychology, history. But it’s not a cold intellect that informs his art. At the center is a steadfast real concern for the human condition, and the charm he brings to his work is grounded in genuine love for his fellow man.”

Says Williams: “Hans is one of the most gracious spirits that I’ve ever come into contact with. His belief and his support and generosity with projects, and his willingness to be patient with me and teach me, has just been an experience that … I don’t know how to put it into words. His generosity is just unmatched.

“All my life I’ve had what I call ‘light towers,’ people who just see and signal you in the right way, and if you listen to them, you’ll always make it to your destination. At the age of 41, I found another one, and his name is Hans Zimmer. That’s what he was to me, from high school to Hans, my teachers. You can’t go to a university and get that.”