Tuesday, March 28, 2017

Lighting theory for 3D games, part 5: the rise and fall of the cult of hard shadows

This is part of a series about a critical theoretical approach to understanding video game lighting, while staying grounded in technical realities, and not focusing on a specific game engine.

Last time (part 4), we ended with the idea that video game lighting is a carefully assembled pile of hacks / effects that hopefully seems like a unified phenomenon of light. It might seem annoying to fuss over many details all the time, but this bespoke workflow exists because we need so much control to make sure the lighting calculations doesn't slow our game's framerate.

One of the most "expensive" (computer-intensive) parts of 3D video games is rendering shadows. To calculate a shadow in a video game, we must test-fire many light rays out from the light source. If these rays hit anything (see diagram above) then that means the light casts shadows past that object. To give you an idea of how much we sacrifice to shadows, Crytek said in a 2013 SIGGRAPH talk that they offer ~20% of their frame budget (5-7 FPS out of 30 FPS) to the shadows. (20% of their entire game! just for shadows!)

Since shadows are so expensive to do, it's impressive when we manage to do it anyway. But that also means we want shadows to pull their weight and help sell the game, to justify the work we put into them. We worship shadows while praying for something in return.

The cult of hard shadows began on February 21, 2001, at the Macworld conference in Tokyo:


(The awkward silence at 3:13, before the audience realizes they're supposed to applaud, is fucking beautiful? I can't even imagine how ugly and appalling and artless that would've looked to a Japanese audience in Tokyo.)

Watch the video above. Yes, that's pre-dead pre-turtleneck Steve Jobs (!) hosting John Carmack, one of the founding fathers of first person shooters and 3D game rendering. Literally every surface in this tech demo is swimming in flickering shadows, only possible with the new state-of-the-art Geforce 3, implying that all those graphics-loving gamers will definitely buy a Mac now! Notice that Carmack has a somewhat different agenda: he can't stop talking about his "unified shadows" system and how it will revolutionize video game rendering. This is a sermon, a proposed vision of the future.

This was also the long-awaited first showing of the hotly-anticipated Doom 3 to the entire world. Does Carmack tell us what the game is about, or even how many different guns it has?... No, in fact, Carmack never tells us anything about the game itself. Who cares how Doom 3 plays? What matters is how it looks and how expensive it will look: shadows, shadows, unified shadows, hard shadows, shadows shadows.

Carmack does accurately sum up the state of video game shadow technology in 2001: a loose patchwork approach with separate shadow systems for the game world and its inhabitants. Popular first person games at the time like Counter-Strike or Serious Sam didn't even have any projected character shadows... and here was Doom 3, ejaculating per-pixel shadows all over the place. Preach it!!!

It was a huge shock to a game industry that was neglecting shadows, and given Carmack's influence and stature, a generation of level designers and modders internalized that shock for more than a decade afterward. We all got hard for hard shadows.


In the Natural Selection map ns_nothing (2002), I remember its "high-res" (well, at the time) high-contrast lighting from recessed ceiling grills seemed so impressive. That effect required advanced knowledge of mapping tricks like invisible light-blocking brushes, spotlights with high constant falloff, and hacking "lightchop" luxel density. Likewise, when working on Black Mesa Source, I also remember the Blast Pit maps (circa 2007-2008) impressing me and fellow designers with its high contrast grating shadows, requiring similar advanced level designer tricks, but at a sharper resolution beyond even Half-Life 2's levels (2004).

When I say "hard shadows", I mean "hard" in two senses: visually crisp and high contrast, as well as difficult to craft. This wasn't a thoughtful artistic homage to film noir aesthetics, this was about proving who had the sharpest shadow penis. This lighting style was about pushing technical boundaries, to render sharper crisper shadows than the engine was intended to do. In the case of ns_nothing and other colossal Natural Selection maps with distinct lighting, the modders were even afraid of breaking the Half-Life 1 engine's core memory limits. We wanted shadows so bad that we were willing to break the entire game.

And while we recognized and accepted that technical cost, I think there was also a deep unconscious design cost: Shadows only exist if we build surfaces to cast and receive those shadows. Notice that Blast Pit room pictured above has to use plain (boring?) concrete textures and a simple boxy shape, to make sure the shadows stay crisp and legible. Does that result in a better game, or a better screenshot?

In this way, we sacrificed entire levels, rooms, and hallways, to feed the shadows and our notions of high craft and perceived production value. But let's not stop there! What if you sacrificed an entire game just to render cool-looking hard shadows?



id re-debuted a Doom 3 demo at E3 2002. Just like in 2001, lights compulsively flicker. The wildly swinging ceiling lamp at the end seems especially desperate. More than a year later, and Doom 3 basically still didn't grow past its tech demo roots. In gamer culture, I'd say we still fondly replay Doom 1 or 2, and adore the recent Doom 4 as a fresh return to form -- but Doom 3 is now remembered as this awkward aberration most people can skip.

Instead of flying around huge demonic blood castles to fight a dozen flaming skulls, Doom 3 had us creep along narrow corridors and pause every few minutes for a "monster closet" cutscene. It also shipped with a notoriously infuriating flashlight-juggling mechanic, provoking a fan-made "duct tape" hate-mod downloaded 80,000 times within 24 hours of its release. (The Doom 3 BFG edition admits this was a mistake, and patches in a Half-Life-style flashlight instead.)

Many of Doom 3's design problems in 2004 stemmed from that fateful announcement in 2001 to showcase its shadow volume tech. I argue that it basically strangled the level design. Modders note that Doom 3's shadow-casting lights need to be kept small and spaced-out with little overlap. To make sure small lights don't feel so small, we need to keep the room small... etc. Apply that claustrophobic thinking to every level of the entire game, and you can imagine how disastrous it'd feel at a time when the open world design was taking over the industry. If Crytek recommended giving 20% of your game to the shadows, then I'd say Doom 3 sacrificed maybe 50%+ of its soul.

Ignoring us impressionable Carmack-fanboy modders, why didn't the rest of the game industry jump on the unified-hard-shadow bandwagon?


Well, the problem with casting everything in your entire game with hard shadows is that it's not particularly photorealistic, nor useful for lighting design.

In real-life, shadows are rarely so dark and crisp. Instead, shadows are usually soft and blurry and translucent, with umbras and penumbras and layers. In the diagram above, notice how the umbra is the darkest inner part of the shadow, and the penumbra is the fuzzier outer boundary of the shadow. Doom 3's shadows don't have penumbras, just umbras. If you're obsessed with photorealism in games like the AAA industry, then this is one huge glaring deal-breaker. (Notably, cartoon cyberpunk game Quadrilateral Cowboy cleverly uses these crispy shadows to strengthen its non-photorealistic aesthetic.)

And remember part 3 of our series, where we talked about three point lighting? To review, three point lighting is a standard style of lighting setup where you overlap light coverage to soften shadows and create interesting gradients. If your lighting engine doesn't let you overlap lights or soften shadows at all, you're literally ignoring centuries of lighting design theory. Basically the only mood that Doom 3 could reliably pull-off was "INTERROGATION" / "DEER IN HEADLIGHTS", which is interesting a few times, but ultimately gets pretty boring pretty fast if you repeat it over and over, even for a horror game. It doesn't allow for enough range in different moods.

Today, no modern game engine uses Doom 3's shadow volume technique due to its inflexibility and the many constraints it imposes on lighting systems. Instead, everyone (even Doom 4) uses shadow mapping / "cascading shadow maps" which thinks of shadows more like "maps" -- pictures that we overlay over the world.


These days, if you wanted a specific shadow pattern, you might just paint a "light cookie" (Unity) or "light function" (Unreal 4) texture, which burns a picture of a shadow into the light falloff. These are conceptually similar to a "cuculoris" ("cookie") or "gobo" in stage lighting, a sheet / stencil that you attach to a lamp to project patterns.

This texture-based approach solves our earlier problem with casting shadows: we no longer need to physically build out light recesses or metal grates to cast a specific shadow. Instead, we can just paint whatever we want in Photoshop, and then throw any quality of light wherever we want -- soft, hard, crispy, blurry, rainbow, whatever. And now because it's so easy to do, casting a dark sharp shadow across a room no longer earns as much street cred as it did before. In fact, sharp "hard shadows" now signify a poorly-tuned lighting setup, and makes a photorealistic game seem less expensive / "worse" in comparison.

Surprisingly, Doom 3 had a similar "light texture" function all along, but used it relatively rarely. Late-stage Doom 3 modders like Matthew "Lunaran" Breit (who later worked on Quake 4 in the same engine), or the team at The Dark Mod, experimented with light textures to fake soft blurry texture-based shadow falloff in the Doom 3 engine -- a laborious one-off level designer hack that Carmack likely would've detested as an attack on his beautiful grand "unified shadow" sermon from 2001.

Personally, I just think it's funny how Half-Life 2 modders worked so hard to fake hard shadows, and Doom 3 modders worked so hard to fake soft shadows... but that also suggests a false equivalence. The cult of hard shadows never really had a chance.

Of course, that doesn't mean the cult is completely dead. It just means there's a new god to worship.

We'll meet this new god next time, in part 6: the holy grail of real-time radiosity.

(PREVIOUSLY: part 4, "how to light a video game world.")