One Formula That Demystifies 3D Graphics
94 points
5 days ago
| 5 comments
| youtube.com
| HN
smokel
1 day ago
[-]
The formula is f(x, y, z) = [x/z, y/z], which does perspective projection of a 3D coordinate onto a 2D plane.

I can't really say that this formula demystifies things, but the video is nice if you're eager to learn about this.

reply
ndepoel
23 hours ago
[-]
The real "a-ha" demystifying moment for me was not so much learning about the elementary rotation, translation or even perspective projection operations. It was understanding how all of those operations can be composed together into a single transformation and that all that 3D graphics really is, is transforming coordinates from one relative space to another.

One important revelation in that regard for instance, was that moving a camera within a world is mathematically exactly the same as moving the world in the opposite direction relative to the camera. Once you get a feel for how transformations and coordinate spaces work, you can start playing around with them and a whole new world of possibilities opens up to you.

reply
rabf
22 hours ago
[-]
I've always walked to the shops by pulling the earth around beneath my feet!
reply
Terr_
8 hours ago
[-]
Though in the real-world case, there's an important difference that breaks the symmetry: You experience acceleration, whereas everybody else standing around you doesn't.
reply
fifilura
22 hours ago
[-]
Once, an angry guy tried to explain that the world does not revolve around me.

I had to walk him away.

reply
sebular
1 day ago
[-]
The way he animated points with an increasing z value made it click for me. Now, when I look at the formula it makes sense. The larger the value of z, the smaller your projected x and y will be. This checks out because things get smaller as they move farther away. Something that’s twice as far away will seem half as big.

The rotation formula eludes me.

reply
smokel
1 day ago
[-]
> The rotation formula eludes me.

Interestingly, in a way, rotation is less mystical than the perspective projection. The rotation is linear: x' = Rx, but the perspective projection is non-linear.

This is where things become fun. Next up are homogeneous coordinates or quaternions. Takes a few years of your life to actually enjoy this though :)

reply
chuckadams
23 hours ago
[-]
I get how quaternions beat Euler angles, but I still can't visualize the damn things 8-/
reply
aleph_minus_one
22 hours ago
[-]
> I get how quaternions beat Euler angles, but I still can't visualize the damn things 8-/

And spin groups beat quaternions since they work in every (finite) dimension. :-)

reply
corysama
1 day ago
[-]
I recently appreciated this vid explaining that 3D translation using the traditional 4x4 transform matrix is performing a shear operation in 4D.

https://youtu.be/x1F4eFN_cos

reply
storus
1 day ago
[-]
This formula also leads to weird geometric perceptual distortions like when one stands in front of a tall building, looks up and down and the shape of the building changes depending on the angle of the view. VR got rid of that.
reply
d-lisp
1 day ago
[-]
To me the formula mystifies things. It should be made clear that it is a simple application of pythagore's theorem,

(i didn't see the video except the beginning to check what was the "mysterious formula".)

reply
msephton
23 hours ago
[-]
He does get to that after the foreplay.
reply
olivergregory
22 hours ago
[-]
Don't you mean Thales?
reply
d-lisp
21 hours ago
[-]
Yes !!
reply
dustbunny
1 day ago
[-]
I've been watching a ton of Tsoding lately. I really like nob.h his build system and I've been using it in my projects. Why we ever used a different language to build C/C++ seems so insane. Using the same language for the build system is just far simpler
reply
rabf
22 hours ago
[-]
His application `boomer` is the best desktop zoom app for X11! Bound to a keyboard shortcut its very useful for debugging graphics layout errors during development.
reply
diabllicseagull
1 day ago
[-]
if you are a little bit familiar with graphics you go: duh, things appear smaller with increasing distance. if you are not tho, it's a great intro to perspective projection. I love how accessibly educative his videos are.
reply
macintux
1 day ago
[-]
I always found it odd that perspective had to be "discovered" by artists, but a little digging online turned up this interesting, detailed look at its history.

https://www.essentialvermeer.com/technique/perspective/histo...

reply
gmiller123456
1 day ago
[-]
It's a lot less about being discovered, or invented, and a lot more about the idea of using it at all. The Renaissance was a massive change in culture. Before that, art was a tool used in rituals or storytelling rather than something to be enjoyed on its own. There was more emphasis on reproducing things as they actually were than how they looked from a particular vantage point.
reply
smokel
1 day ago
[-]
Artists are still struggling with the fact that human perception arises from binocular vision. Two distinct retinal inputs are integrated by distributed neural processes into a single, coherent 3D experience. This integration is neither a simple planar stitching nor a direct representation of the world, but an active construction shaped by neural computation and subjective awareness.

It is quite likely that artists in earlier periods struggled with this as well, and were less concerned with adhering strictly to a photographic or geometrically exact perspective, as we are. The adoption of the camera obscura probably influenced things a lot.

reply
fenwick67
1 day ago
[-]
Even ignoring binocular vision it's very unintuitive to "draw what you see" because of this. Our brain usually interprets our environment as objects, 3d shapes, and things. Turning that off and trying to grab a literal image from it is difficult
reply
Demiurge
1 day ago
[-]
Is “neural computation” a thing, or a poetic metaphor?
reply
smokel
1 day ago
[-]
reply
qingcharles
16 hours ago
[-]
When I was a little kid trying to do 3D graphics on my Spectrum I couldn't find any books with the algorithm for how it worked. I remember my artistic friend and I sitting down with reams of graph paper trying to figure out how to do it. It's so simple and obvious after you learn, but until you do I felt like a caveman.
reply
0xfaded
1 day ago
[-]
The world of homogeneous coordinates (https://en.wikipedia.org/wiki/Homogeneous_coordinates) is magical and extends beyond just points and lines to conics.

The Multiview Geometry Book begins with a great deep dive on the topic.

https://www.cambridge.org/us/universitypress/subjects/comput...

reply
boslo-km
1 day ago
[-]
Jim Blinn's Corner (1996) also has a good chapter/article, "The Homogenous Perspective Transform."
reply
pengaru
13 hours ago
[-]
Nothing demystifies 3D graphics more than learning the relevant rudimentary parts of linear algebra.

Casey Muratori's Handmade Hero series has several excellent explainers aimed at aspiring game developers, there's even a math playlist:

https://www.youtube.com/playlist?list=PLEMXAbCVnmY7lyKDlQbdb...

Learning that perspective happens via /z is nowhere near sufficiently demystifying IMO

reply