M. Night Shyamalan’s next film will be a happening at 20th Century Fox.

Studio has pledged a green light for “The Happening,” a spec script thriller that Shyamalan wrote and will direct in Philadelphia this August. Fox has earmarked the film for a June, 2008 release.

The Fox deal, which was spearheaded by Fox Filmed Entertainment chairman/CEO Tom Rothman, ends an unusually complex and public process for Shyamalan, who, since “The Sixth Sense,” had made all his films for Disney. That was until a falling out over “Lady in the Water” which led him to make that picture for Warner Bros.

Shyamalan will produce with Sam Mercer. He also reunites with “Munich” producer Barry Mendel, who produced the Shyamalan-directed “The Sixth Sense” and “Unbreakable.”

Pic, which will mark Shyamalan’s first R-rated effort, is a paranoid thriller about a family on the run from a natural crisis that presents a large-scale threat to humanity. The pic is expected to carry a budget of around $57 million, and Shyamalan told Daily Variety he expects to cast a big male star for the lead.

Shyamalan will prep and shoot “The Happening” as he continues to write the script for “Avatar: The Last Airbender.” Shyamalan will follow with that live action film for Paramount.

When he visited Hollywood to seal his “Avatar” deal, Shyamalan and his new CAA reps met with execs atop almost every studio. Each read an early draft of “The Happening,” which at the time was titled “The Green Effect.” The buzz around Hollywood was that no studio loved the draft enough to make a deal.

Shyamalan said he wasn’t at all bothered by that. Though he didn’t return to Philadelphia with a deal, he got strong notes and observations from several top studio execs like Rothman that helped him hone his vision.

Shyamalan, who by then reunited with Mendel, then rewrote the film.

By the time he was done six weeks later, several studios offered to green light it, Shyamalan said. He landed at Fox partly because of Rothman’s enthusiasm, and also, he said, because the studio has demonstrated acumen in marketing similar apocalyptic fare like “Independence Day” and “The Day After Tomorrow.”

“Because I’d been so lucky in making successful movies in the past, I was in monogamous relationships with a few studios and the isolation meant I’d never really met anybody,” Shyamalan said. “Instead of me just being a name, I was a guy in a room. The thing that’s different about me is, when I go out with a script, I am looking for a green light, not some deal where they will develop for two years and then maybe make it.”One palpable change in the film, Shyamalan said, was the decision to dial up the scare factor, thus inviting the R rating.

Rothman also craved an edgier version, which made Fox enticing to the director.

“Tom felt strongly about making this my first R-rated picture,” Shyamalan said. “We talked about trying to get the kind of intensity that is present in ‘Silence of the Lambs,’ and the kind that Guillermo del Toro got in `Pan’s Labyrinth.’ The impact of the beautiful things in that movie wouldn’t have landed as strongly if the film had not been R rated.”

The failure of “Lady in the Water,” and a making-of book that detailed Disney’s rejection of the project, gave the impression that Shyamalan was not changeable. His decision to broaden his studio relationships was a step toward dispelling that.

“That is a misconception, and people who work with me know that I’m collaborative,” Shyamalan said. “If you can give me a good idea that can help me to make a better movie, then there is no ego issue in taking that advice. Ultimately, this was a very positive process, and one that will ultimately help in making this movie the best it can be.”

The deal gives Fox another piece for summer, 2008. The studio has so far earmarked the Eddie Murphy-starrer “Starship Dave” for a likely May 30 release.