How Cameras Really Work: Dividing by Depth to Project 3D onto a Screen
Every 3D camera boils down to simple arithmetic. Game developer Gabriel O’Flaherty-Chan walks through the core insight behind rendering: a point in space at coordinates (x, y, z) lands on the 2D screen at (x/z, y/z). Divide the horizontal and vertical positions by depth, and objects farther away naturally shrink toward the vanishing point — the same effect that makes a ball appear to move and scale as it orbits a camera. This one operation, perspective division, is the foundation of the illusion of depth.
The naive divide-by-z trick only works for points already positioned relative to the camera, so real engines generalize it into the perspective projection matrix. That matrix folds in field of view, aspect ratio, and near and far clipping planes, encoding them as focal scale and depth-mapping terms. Multiplying a point by this matrix yields clip-space coordinates; dividing by the resulting w component produces normalized device coordinates ready to map onto pixels. The author shows that setting focal scale and aspect ratio to 1 collapses the full matrix back into the original x/z, y/z formula — proving the beginner trick is just a special case of the professional machinery.
The practical takeaway is demystification. The pipeline runs world space to view space to clip space, then divides by w into NDC, then to pixels and rasterization. Each stage is a discrete, understandable transformation, and once you know what each does you can implement only the parts a given project needs — sometimes the whole chain, sometimes just a single depth division. For developers intimidated by graphics math, the piece argues that the ‘magic’ Camera object is far less mysterious than it looks.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.