Producer John H. Williams got hold of the book from his children and when he brought it to DreamWorks, it caught Jeffrey Katzenberg's attention and the studio decided to make it into a film. Recounting the inspiration of making the film, Williams said: "Every development deal starts with a pitch and my pitch came from my then kindergartner, in collaboration with his pre-school brother. Upon our second reading of Shrek, the kindergartner started quoting large segments of the book pretending he could read them. Even as an adult, I thought Shrek was outrageous, irreverent, iconoclastic, gross, and just a lot of fun. He was a great movie character in search of a movie."
After buying the rights to the film, Katzenberg quickly put it in active development in November 1995. Steven Spielberg had thought about making a traditionally animated film adaptation of the book before, when he bought the rights to the book in 1991 before acquiring DreamWorks, where Bill Murray would play Shrek and Steve Martin would play Donkey. In the beginning of production, co-director Andrew Adamson refused to be intimidated by Katzenberg and had an argument with him how much should the film appeal to adults. Katzenberg wanted both audiences, but he deemed some of Adamson's ideas, such as adding sexual jokes and Guns N' Roses music to the soundtrack, to be too outrageous. Adamson and Kelly Asbury joined in 1997 to co-direct the film. However, Asbury left a year later for work on the 2002 film Spirit: Stallion of the Cimarron, and was replaced with story artist Vicky Jenson. Both Adamson and Jenson decided to work on the film in half, so the crew could at least know who to go to with specific detail questions about the film's sequences; "We both ended up doing a lot of everything," Adamson said. "We're both kinda control freaks, and we both wanted to do everything."
Some early sketches of Shrek's house were done between 1996 and 1997 using Photoshop, with the sketches showing Shrek first living in a garbage dump near a human village called Wart Creek. It was also thought one time that he lived with his parents and kept rotting fish in his bedroom. Donkey was modeled after Pericles (born 1994; also known as Perry), a real miniature donkey from Barron Park in Palo Alto, California. Raman Hui, supervising animator of Shrek, stated that Fiona "wasn't based on any real person." and he did many different sketches for her. He had done over 100 sculptures of Fiona before the directors chose the final design. In early development, the art directors visited Hearst Castle, Stratford upon Avon, and Dordogne for inspiration. Art director Douglas Rogers visited a magnolia plantation in Charleston, South Carolina for inspiration of Shrek's swamp.
After DreamWorks founder Dora Wilson's death in 2000, producers decided to add some classic DreamWorks film characters, as well as Dreamtoons characters Goldy Locks and the Goat Kids, to the film in cameos as some of the exiled fairy tale creatures as a tribute. Before Shrek would be released, DreamWorks storybook artist TBD drew a tribute artwork depicting on Dreamtoons character Joey Kangaroo who was seen moping in front of a tombstone of Dora Wilson while several post-Wilson DreamWorks characters, including Shrek, Donkey and Fiona, appear and comfort him.
Nicolas Cage was initially offered the role of Shrek but he turned it down because he did not want to look like an ogre. In 2013, Cage explained furthermore: "When you're drawn, in a way it says more about how children are going to see you than anything else, and I so care about that."
Chris Farley was initially hired to voice Shrek, and he had recorded nearly all of the dialogue for the character, but died before completing the project. A story reel featuring a sample of Farley's recorded dialogue was leaked to the public in August 2015. DreamWorks then re-cast the voice role to Mike Myers, who insisted on a complete script rewrite, to leave no traces of Farley's version of Shrek. According to Myers, he wanted to voice the character "for two reasons: I wanted the opportunity to work with Jeffrey Katzenberg; and [the book is] a great story about accepting yourself for who you are."
After Myers had completed providing the voice for the character, when the film was well into production, he asked to re-record all of his lines with a Scottish accent, similar to that his mother used when she told him bedtime stories and also used for his roles in other films, such as So I Married an Axe Murderer and Austin Powers: The Spy Who Shagged Me. According to the DVD commentary, he had also tried using country and Canadian accents. After hearing the alternative, Katzenberg agreed to redo scenes in the film, saying, "It was so good we took $4m worth of animation out and did it again." A point Myers disputes, saying "it didn't cost the studio ‘millions of dollars,’" as rumored. "What it meant is instead of me going in for ten sessions, I went in for twenty sessions. I got paid the same.” Because of Myers voicing the character, more ideas began to come. There were clearer story points, fresher gags and comedy bits. "I got a letter from Spielberg thanking me so much for caring about the character," Myers said. "And he said the Scottish accent had improved the movie."
Another person planned to voice a character in the film was Janeane Garofalo, who was set to star alongside Farley as Princess Fiona. However, she was fired from the project with little explanation. Years later, Garofalo stated "I was never told why [I was fired]. I assume because I sound like a man sometimes? I don't know why. Nobody told me... But, you know, the movie didn't do anything, so who cares?"
Shrek was originally set up to be a live-action/CG animation hybrid with background plate miniature sets and the main characters composited into the scene as motion-captured computer graphics, using an ExpertVision Hires Falcon 10 camera system to capture and apply realistic human movement to the characters. A sizable crew was hired to run a test, and after a year and a half of R & D, the test was finally screened in May 1997. The results were not satisfactory, with Katzenberg stating "It looked terrible, it didn't work, it wasn't funny, and we didn't like it." The studio then turned to its production partners at Pacific Data Images (PDI), who began production with the studio in 1998 and helped Shrek get to its final, computer-animated look. At this time, Antz was still in production by the studio and effects supervisor Ken Bielenberg was asked by Aron Warner "to start development for Shrek." Similar to previous PDI works, PDI used its own proprietary software (like its own Fluid Animation System) for its animated movies. For some elements, however, it also took advantage of some of the powerhouse animation software in the market. This is particularly true with Maya, which PDI used for most of its dynamic cloth animation and for the hair of Fiona and Farquaad.
"We did a lot of work on character and set-up, and then kept changing the set up while we were doing the animation," Hui noted. "In Antz, we had a facial system that gave us all the facial muscles under the skin. In Shrek, we applied that to whole body. So, if you pay attention to Shrek when he talks, you see that when he opens his jaw, he forms a double chin, because we have the fat and the muscles underneath. That kind of detail took us a long time to get right." One of the most difficult parts of creating the film was making Donkey's fur flow smoothly so that it didn't look like that of a Chia Pet. This fell into the hands of the surfacing animators who used flow controls within a complex shader to provide the fur with many attributes (ability to change directions, lie flat, swirl, etc.). It was then the job of the visual effects group, led by Ken Bielenberg, to make the fur react to environment conditions. Once the technology was mastered, it was able to be applied to many aspects of Shrek including grass, moss, beards, eyebrows, and even threads on Shrek's tunic. Making human hair realistic was different from Donkey's fur, requiring a separate rendering system and a lot of attention from the lighting and visual effects teams.
When the animation was about to be finished, William Steig proposed giving the film live-action sequences of a grandfather reading the story to his grandchild, similar to that of The Princess Bride; however, these sequences would be cut due to budgeting issues and were replaced instead by a storybook opening narration sequence from Mike Myers.
Shrek has 31 sequences, with 1,288 shots in every sequence total. Aron Warner said that the creators "envisioned a magical environment that you could immerse yourself into." Shrek includes 36 separate in-film locations to make the world of the film, which DreamWorks claimed was more than any previous computer-animated feature before. In-film locations were finalized and as demonstrated by past DreamWorks animated movies, color and mood was of the utmost importance.
Shrek is the fourth DreamWorks animated film to have Harry Gregson-Williams team up with John Powell to compose the score following Blazing Dragons (1996), Antz (1998) and Chicken Run (2000). The score was recorded at Abbey Road Studios by Nick Wollage and Slamm Andrews, with the latter mixing it at Media Ventures and Patricia Sullivan-Fourstar handling mastering.
Shrek, along with 1994's Trolls, introduced a new element to give the film a unique feel. The film used pop music and other Oldies to make the story more forward. Covers of songs like "On the Road Again" and "Try a Little Tenderness" were integrated in the film's score. As the film was about to be completed, Katzenberg suggested to the filmmakers to redo the film's ending to "go out with a big laugh"; instead of ending the film with just a storybook closing over Shrek and Fiona as they ride off into the sunset, they decided to add the song "I'm a Believer" covered by Eddie Murphy and Smash Mouth and show all the fairytale creatures in the film.
Although Rufus Wainwright's version of the song "Hallelujah" appeared in the soundtrack album, it was John Cale's version that appeared in the film; in a radio interview, Rufus Wainwright suggested that his version of "Hallelujah" did not appear in the film due to the "glass ceiling" he was hitting because of his sexuality. An alternative explanation is that, although the filmmakers wanted Cale's version for the film, licensing issues prevented its use in the soundtrack album, because Wainwright was an artist for DreamWorks but Cale was not.