hn.today

Divide by Depth for Instant 3D

gabrieloc.com10 points1 comments
Screenshot of Divide by Depth for Instant 3D

Explains how simple depth division underlies perspective in 3D graphics and how that idea scales into the full camera pipeline. It starts from the elementary projection x' = x / z, y' = y / z and shows shader examples that place and scale points and line geometry by dividing XY by Z, which causes distant points to converge toward the vanishing point. Those demos are useful but limited; full camera behavior also needs orientation, position, field of view, aspect ratio and near/far clipping. The practical solution is the 4x4 perspective projection matrix, which encodes a focal scale f = 1/tan(fov/2), aspect a = width/height, and depth mapping coefficients A = (F+n)/(F-n), B = -2Fn/(F-n). That matrix produces clip-space coordinates ready for perspective division.

Describes how homogeneous coordinates and the matrix produce clip-space (fx/a, fy, Az+B, z), after which dividing by w (here z) yields normalized device coordinates: x_ndc = (f/a)x / z, y_ndc = fy / z. Setting f=1 and a=1 recovers the simple x/z trick, so depth division is just a special case of the projection matrix. Lays out the pipeline: world → view → clip → /w → NDC → pixels → rasterization, and argues that understanding each transform lets you choose which pieces to implement, optimize, and reason about visibility, culling and rendering.

Read on gabrieloc.com1 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Web

Vibecoding isn't a crime How Distribute Your App on Linux after Flathub refusal

Vibecoding isn't a crime How Distribute Your App on Linux after Flathub refusal

Flathub updated its policy to ban applications containing AI-generated or AI-assisted content, including code and documentation, effectively blocking many developers from distributing their apps. The policy is criticized for being unclear, overly broad, and unfairly punishing transparency, especially for open-source projects using AI tools during development. (grigio.org)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.