*R&B crooner John Legend has contributed a song to the new documentary “Waiting for Superman,” a film by Davis Guggenheim – director of Al Gore’s Oscar-winning global warming documentary “An Inconvenient Truth” – which examines the challenges of America’s public school system.

The film chronicles efforts by innovative educators to turn around failing systems in Washington, D.C., Harlem, Los Angeles and other places where many schools have come to be known as “dropout factories.”

At the heart of the film are segments following a handful of promising students whose best hopes for a decent future rest in longshot lotteries to determine which children will get to attend a choice alternative school.

Before he was even aware that Guggenheim was working on such a film, Legend was inspired to produce his own project about the topic, which came about during recording sessions with hip-hop group the Roots. The musicians are collaborating on an album exploring 1960s and ’70s music, which led to a discussion about the civil-rights movement and then education, which Legend considers the civil-rights issue of our time.

“We were going to meet with Davis to see if he wanted to direct it,” Legend said. “When my manager met with him, he was like, `Uh, I’m already making this film. This film you’re talking about, I’m already making it, and it’ll be done in three months.'”

Legend, 31, eagerly agreed to sign on with “Waiting for Superman,” writing the song “Shine” for the closing credits of the documentary, which premiered over the weekend at the Sundance Film Festival.

“Shine” “was completely inspired from seeing the film and seeing the stories of the children in the film, because it follows these kids who have potential, have a certain desire to do well,” Legend said. “They are in circumstances where they are surrounded by failing public schools, and they see the light, they see a few schools in their area that are succeeding. But you have to win a lottery to get into these schools. …

“When you think about someone’s fate being decided by a lottery, the choice is usually … `Am I going to end up at a school with a super-high dropout rate and end up like a lot of those kids who drop out, in the criminal-justice system, working a low-wage job, or am I going to get a good education and go to college and make something of myself?'”

“Waiting for Superman” has been picked up by Paramount Vantage for theatrical release. Legend hopes the film will be a call to action for public schools the way an “Inconvenient Truth” was for global warming.