In “Don Jon’s Addiction,” Joseph Gordon-Levitt plays Jon Martello, a modern-day Don Juan from New Jersey whose entire lifestyle follows a set routine: He tends bar in the service industry, makes eyes with the pretty girls and takes them home, then meticulously smooths down the sheets the next morning. He confesses at church, does bicep curls while reciting a litany, and has dinner with his traditional Italian-American family once a week.

There’s just one thing. He’s also addicted to Internet porn.

In “Don Jon’s Addiction,” written and directed by Gordon-Levitt, the main character, nicknamed Don Jon by his friends, finds porn more satisfying than his real-life sexual conquests. He logs onto porn sites multiple times a day and pleases himself. Once a week at church, he confesses to the late-night viewings.

But when Don Jon meets bombshell Barbara Sugarman, played to the hilt by Scarlett Johansson, she comes dangerously close to learning his secret, and he decides to put a stop to it.

“I wanted to tell a love story and what I noticed a lot about what gets in the way of love is how people objectify each other,” Gordon-Levitt said in an interview at Sundance. “So I thought a story about a relationship between a guy who watches too much porn and a girl who watches too many romantic Hollywood movies, would really tell that story and be hilarious.”

It is indeed hilarious. Don Jon’s journey is set to a soundtrack that includes “Good Vibrations” by Marky Mark and the Funky Bunch. It’s interspersed with clips of porn, carefully selected and edited so we don’t see more than we do in an average R-rated flick, Gordon-Levitt points out.

But the comedy blends into serious, moving territory when Don Jon meets a quirky woman named Esther (in a beautiful performance by Julianne Moore) and things really begin to change. Esther is a cryer, a meddler and an all-around mess. But it turns out she’s a lot more central to Jon’s reformation than he realizes.

“Within this world of people objectifying each other, not quite meeting, there was this person who due to her personal circumstances, crave nothing but real contact because of where she was, what has happened to her,” Moore said in an interview. “She can’t bear to be anything less than authentic 100% of the time.”

Esther has experienced tremendous loss just 14 months before she meets Don Jon, making her extremely vulnerable, but also extremely present and insightful, and able to see Don Jon for who he truly is.

The genesis of her character came to Gordon-Levitt at a similarly difficult time in his own life. His brother Daniel, the person closest to him, died in 2010. He mourned the loss and couldn’t leave the house for a long time. But he had been scheduled to attend the annual retreat for Sundance board members that takes place at the Sundance resort in the mountains of Utah.

“I was like, you know what? It’s going to be good for me to go,” Gordon-Levitt said. “There’s such good energy up there and Dan had been up at Sundance a few times and that was really special for us.”

During the retreat, he was hiking alone one day in the mountains and thinking about everything that had happened. A couple months before his brother’s death, Gordon-Levitt had also started writing the screenplay for “Don Jon’s Addiction.” He was still searching for Esther’s character, her true nature. As he hiked and thought about Daniel, he realized, “Oh, what if she’s going through this?” So he decided to write the pain into Esther’s character, where she has lost her husband and son.

“She says in the movie that they died 14 months ago,” Gordon-Levitt said, “and Dan had died 14 months ago when we shot.”

Like Moore described of her character, experiencing the death of the person he loved changed Gordon-Levitt. “Look, if there’s one thing in my life I wish could be different, it’s that,” he said, visibly emotional. “But on the other hand I acknowledge that it’s blessed me with a lot of things.”

The Wall Street Journal will have more on “Don Jon’s Addiction,” so check back in. For more updates from the Sundance Film Festival, follow @barbarachai