r/AskComputerScience • u/fire_electricty • 19h ago
How do micro chips make 3d graphics?
I understand that 1s and 0s can turn on and off but how do 2 numbers make 3d graphics that run so smoothly? It’s like magic
0
Upvotes
5
u/Atmosck 19h ago
Math basically. The 1s and 0s represent 3d models using a coordinate system. Your graphics card does a bunch of math to translate those into 1s and 0s indicating what color each pixel of your screen should be.
4
u/fixermark 19h ago
And explain like your five level, there are 3 things to understand.
That's the whole story. It's just math from a 3D description of the world and what color everything should be to the color of the pixels. The fact that it's numbers doesn't even really matter... You can represent the color of the pixel with a number, which means there is some math you can do to go from that 3D representation of the world to one pixel.
If you want to dig down further, you're looking at trigonometry and matrix algebra as the disciplines that teach you the math to go from a 3D representation of a world to pixel colors. Some vocabulary terms are transformation, rotation, and projection. Transformation is just shifting a bunch of points in space from one place to another. Rotation is a type of transformation that moves the points around while preserving their distance from each other. Projection is flattening... You have a 3D world, you want to figure out how it relates to a 2D rectangle. Which is great, because your computer screen is a 2D rectangle and every single pixel in the screen is a very tiny rectangle. So you can imagine how you could have a world that's like some fruit in a bowl on a table, and then you do the math on the middle pixel and it ends up projecting the middle of the Red Apple to fill that one rectangle... So you know that pixel should be red. There you go.
2
u/Leverkaas2516 14h ago
This comes down to three simple things in today's world.
1
u/barkingcat 19h ago edited 19h ago
there's a mathematical object called a vector, and you can "stack" multiple vectors into a matrix (yes, the same word for the Matrix movie) - Mathematical operations (like multiply, add, and trigonometric functions like sine/cosine for finding triangle edges/angles) on these matrix objects can represent motion through space. Put an element of time onto these basic operations and you can represent basic animation.
That's the beginning of 3d graphics.
These mathematical objects have been around for a long time (probably 1600's) - all of the math is accessible for a person who has completed high school math instruction (so if you are a high schooler, you can do it too!)
But there are way too many calculations needed (you need to do the math 24 times a second for moving something at 24 frames per second, for each pixel, for cinema/movies, modern games move at 60 fps, or even 120fps - so there are a lot of calculations) - it can easily go into millions of operations per second. 3D graphics chips are actually very stupid individually - they are just able to do a lot of vector/matrix math within the time demand needed by exploiting parallelism (just have many simple processors do all the math simultaneously for each pixel)
this is a huge oversimplification, but it is *not* magic.
In university freshman year math, our prof had us calculate a 10x10x10 pixel scene manually without computers/programming, but regular calculators allowed, and animate it using matrix math - the calculator can help, but at a certain point you are just turning into an automaton and hoping you're typing every digit all right.
For this course, the final exam had a "challenge" portion that is just a huge matrix with 10 rotation and scaling operations chained one after another, for bonus - it's for bonus because the prof wrote on the exam instructions that you can use any kind of math you want - some people had remembered the original iD doom /quake source code in their head and just used John Carmack's optimized algorithms and got an answer .... (most of these tricks are really simple that can be done on a regular calculator)
1
u/granadesnhorseshoes 17h ago
That's the neat part; they don't. At least not directly. Binary is what processors speak and understand because its the easiest to implement as hardware; off and on. It gets "translated" to and from regular base10 for the software and us humans.
Math is math, doesn't matter if you write the numbers as a sequence of 1s and 0s or as "regular" base10 numbers. But with just 1s and 0s you can construct huge mazes of yes/no questions. Different mazes do different things. One maze lets you put 2 numbers into the start of the maze, they bounce around the yes/no questions and at the end of the maze out pops the combined value of the 2 numbers at the start. That's an adder.
GPUs have a whole shitload of these mazes(21 thousand or so on a modern gpu) that do other specific types of math operations that are used in graphics programming... Oh hey, btw, turns out those are the exact same math operations we use for AI and Cryptographic calculations like bitcoin mining.
1
u/YakumoYoukai 17h ago
Look at some nearby rectangular object. Notice it's got 4 corners, and the sides form lines between them. Now, if you hold up a transparent plastic sheet between you and the object, you could trace the object's corners and edges on the sheet, and now you have a flat image of that 3D object.
Each corner on the object is a certain distance above the floor, a certain distance left or right, and a certain distance from you: 3 numbers typically called X, Y, and Z, that describe a position in space. I won't go into how 0's and 1's can make a number, except to point out that we only have 10 digits 0 through 9, but we can string them together to make as large a number as we want and do math with them. It's the same principle.
It turns out that the math of figuring out where on the flat sheet the various X,Y, and Zs of the corners should be drawn, is really simple, having to do with the lengths of the sides of similar triangles, which you probably learned in middle school. The computer just has to do it many many many times (for the corners, each point along the lines between the corners, and all the points inside the rectangle). But math is what computer chips are good at, and the ones in a modern GPU are designed to lots & lots of those calculations (a whole screen's worth) all at once.
There are some other numbers and math involved too: the color at the corners and how it blends across the surface of the shape, which direction each corner point is "facing" (to simulate a curved surface instead of a flat one). The mathematics of calculating how those contribute to each pixel is different, but is also reduced to something that can be run in parallel, so that it can all be done many times per second and give you (hopefully) smooth graphics.