I've always thought that one of the best things about The Witcher 3 is the way the characters feel so believable, and the dialogue interactions went far to add that extra spark of immersion and magic to the game. Contrary to popular belief, CD Projekt RED aren't actual wizards--their sorcery is built around code and algorithms rather than grimoires--and the studio reveals how it spun those magical dialogue sequences.

At a recent talk at GDC, CD Projekt RED animation technical director Piotr Tomsinski discussed the science behind The Witcher 3's natural character dialogue. Rather than animate each individual scene by hand and piece together the dialogue, the devs utilized a rather powerful algorithm that compiles different ingredients like location, character type, and dialogue into a fully animated scene. Since the game has some 35 hours of dialogue alone, handcrafting each individual scene with custom mo-capture sequences would take an eternity.
"The generator requires three different types of inputs: information about the actors, [some cinematic instructions], and finally the extracted data from voiceovers," Tomsinski said at the talk. "We use an algorithm to generate markers, or accents, from the voiceovers, so later we can match the events in animation with the sound. It generates camera movement and placement, facial animation, body animations, and the lookats."

Using this generator, the devs could easily click a button and recreate scenes over and over until they find something they like. One of Tomsinski's slides compared CDPR's dialogue generator to Lego bricks: "one set of bricks, many dialogues". The generator doesn't always spit out a finished product, however. The devs still have to go in and touch-up the scene, but some of the lesser one-liner dialogues don't need touch-ups.
"It sounds crazy, especially for the artist, but we do generate dialogues by code. The generator's purpose is to fill the timeline with basic units. It creates the first pass of the dialogue loop. We found out it's much faster to fix or modify existing events than to preset every event every time for every character. The generator works so well that some less important dialogues will be untouched by the human hand."
I absolutely love seeing the science of game development magic laid out like this, especially when we get to see CD Projekt RED's spellbook. The devs are absolute masters of their craft, and I bet we'll see this kind of algorithm used in Cyberpunk 2077 and the studio's new unannounced game coming later this year.