miuradio
How It SpawnsThe tricks inside famous games, shown running.›

How It Spawns

How does the mirror in Duke Nukem 3D show you?

Story

You step up to the bathroom sink, and there you are, moving when you move.

Duke Nukem 3D (3D Realms, 1996) runs on Ken Silverman's Build engine, which draws the level from one spot: your eyes. In your own view the game doesn't draw you at all (look down: no body). So who's in the glass? And if you walk at a mirror, the game puts you right back where you stood.

The answer is in the game's own code, released by 3D Realms on 1 April 2003. Behind every mirror the level's mapper builds a real room, and the game won't let you stand in it: its floor carries the mirror's picture, and any move into it is undone (unless you switch clipping off with the walk-through-walls cheat). Each frame a mirror is on screen, the game takes the mirror nearest to you, reflects your eye and your view across the glass (Ken's preparemirror), and draws the level again from there, starting in that hidden room and looking back through the glass. This time it draws you: your own figure is only removed when the view isn't a mirror's. Then it turns that patch of the screen around ("Reverse screen x-wise in this function", says the comment on the call) and draws your normal view around it. Only one mirror gets this each frame: the nearest.

Ken Silverman's own notes for the engine list "Functions to help with mirrors (they weren't fully built in to the engine)". So Duke's mappers built them a room.

The bathroom, the mirrors and the pawn are our own simplified version, drawn in code; our renderer makes its mirrors the same way (a second camera at your reflection, the patch flipped).

Which game had the best mirrors?

Sources: Duke Nukem 3D source code (3D Realms, 2003: GAME.C, PLAYER.C, PREMAP.C) and Ken Silverman's Build engine source and notes (2000, advsys.net/ken/buildsrc).
Sounds and music: our own, made in code.
Unofficial. Not affiliated with or endorsed by 3D Realms, the rights holders of Duke Nukem 3D or Ken Silverman.

Follow

TikTok@howitspawns›Instagram@howitspawns›YouTube@howitspawns›X@howitspawns›
Link copied