I'm building a simple 3d software renderer, and this can't get "truer" then reality. Everything in game dev in general is infact linear algebra. After learning this fact, I'm astonished that no game dev tutorial talk about this enough.
There is one place in the standard raster pipeline that isn't *technically* linear algebra. That'd be the perspective divide because obviously 1/x isn't linear.
Affine functions also aren't linear, but thanks to using 4d homogenous coordinates we can get away with making all of that linear. (This is a fancy math way of say ax+b instead of just ax. The former is not linear but the latter is).
You seem to be violently agreeing with me? All I said was that the presence of nonlinear transforms doesn't make it "not linear algebra". I didn't claim that those transformations are actually linear ...
If that was your entire point, I'm not sure what you said to me up there. All I said was certain transforms in the pipeline aren't linear, and that is correct.
There is one place in the standard raster pipeline that isn't technically linear algebra.
My only point, which definitely did not warrant this digression into a whole thread, was that "linear algebra" isn't restricted to algebra that is linear; it's an umbrella term for a field of study that can encompass even operations such as the definitely-nonlinear 1/x when performed in a relevant context.
As a mathematician you presumably know this, and maybe your use of "technically" was meant to restrict the definition further, but I didn't read it that way and I was just replying to your statement that it "isn't [...] linear algebra".
I thought it was clear that the point was the linearity of the operations since we are talking about operations that GPUs can accelerate in this comment chain. We are not, despite that one sentence in my comment which I suppose was ambiguous, talking about the field of linear algebra since GPUs don't care what's discussed in that field. The perspective divide is interesting for that reason only, since the GPU handles that in hardware between rasterizer stages.
Your comment is essentially a non-sequitur for that reason.
? The comment you replied to is a top-level comment; that's the whole chain. /u/DasKapitalV1 said they're building a game engine and agree with the point of the OP comic that "everything [...] is linear algebra".
Then you came along and said that one of the operations technically isn't linear algebra.
Given that context, I interpreted your comment as being about the field. I'm not sure where we are supposed to have jumped to GPUs and their ability to accelerate (non)linear operations...
Perspective division is genuinely not linear algebra. You can cheat affine transforms by bumping up a dimension (3d -> 4d). That's one reason why GPUs use 4x4 matrices and not 3x3.
The perspective divide causes no end of conceptual problems because it means something non-reversible happens after the geometry shader and before the fragment shader. That makes it impossible to back your way out just using equations. This is why we often pass world coordinates directly from prior stages to the frag shader, so we have a sort of "inverse function" available to us when we normally wouldn't be able to know.
Some might say, "Well, there's also calculus, etc." There's truth to that... But in calculus, what's a derivative? It's a linear transformation. Okay, fine, but what about integrals? Also a kind of linear transformation (a linear functional). People are usually taught these facts as the "sum rule" or "constant multiple rule," but those are just the defining properties of a linear transformation! Multivariable calculus, in particular, makes way more sense if you learn linear algebra first (most students don't, at least in the US).
This exact gap is why I teach advanced math one-on-one... It's much easier to connect the dots for someone's specific background, especially in computer graphics. Learning linear algebra is actually easier for graphics devs because it gives really good reasons for the math to be the way that it is. In this context, we can discover matrix multiplication from scratch very easily, actually! But it's hard to find tutorials, even ones aimed at graphics devs, that really make this clear. Argh. If anyone here is hitting a wall with their linear algebra, feel free to shoot me a DM!
the Feynman lectures (i know, i know) has a famous quote:
Finally, we make some remarks on why linear systems are so important. The answer is simple: because we can solve them! So most of the time we solve linear problems. Second ( and most important), it turns out that the fundamental laws of physics are often linear. The Maxwell equations for the laws of electricity are linear, for example. The great laws of quantum mechanics turn out, so far as we know, to be linear equations. That is why we spend so much time on linear equations: because if we understand linear equations, we are ready, in principle, to understand a lot of things.
Linear algebra and sometimes software architecture(if you’re building performant stuff) are literally the only two skills you need to do this stuff truly.
I keep slowly adding to a 3d engine I'm making. every time I think "this next part is going to take a lot of complicated effort". and I come back to it and it's just more algebra
There's a lot of data structures and algorithms when you get passed the basic implementations as well, and some of that can be expressed with probability math, graph theory etc... but it's almost all just organizing when the linear algebra happens under the hood.
I was in a horrible accident at university: Took graphics programming before linear algebra. It's much better that way. Made linear algebra just… click.
imo CUDA programming isn't about linear algebra, it's about decomposing your brain into thinking like ten thousand stupid dudes doing competitive eating
Now that i think about it, i can probably ditch interviews and watch someone play dwarf fortress to see how good they would be at GPU programming in general
The easiest part of a 3d game engine is the graphics I swear. Writing all the systems so they work effectively with each other without each contact surface between systems being a source of bugs is way harder. Also in C/C++ I've yet to see a build system that feels coherent in all analysis.
That’s why I do my hobby work in Rust. C is more suited to graphics in some way, since it lets you just manipulate the damn memory, but Rust tooling is so much more ergonomic.
Rust is a breath of fresh air on build systems in comparison. I do feel slower working in it, but I imagine with practice it can be extremely effective for games
I was working on a game at one point, and we were something like $40M into the development (.... and it was not going to release on time and needed about another $10M.....) The company was trying to drum up hype for the game and invited members of mainstream media into the building to do a tour. They could go anywhere (except some "off-limits" area) and ask anyone any questions they liked.
The off-limits area was engineering.
One of my co-workers observed that we were basically the representatives of the "stay in school, study math, profit" philosophy, but the company didn't want to scare the kids with the fact that math is very, very fucking useful.
As a mathematician who loves graphics programming, it's funny to me that people tend to somehow grasp the wizardry that is graphics APIs and all these crazy concepts about programming optimisations that I cannot understand at all, but struggle with LA which to me is an elementary topic. Goes to show the difference in perspective.
I feel like the GPU rendering pipeline is harder to grasp than linear algebra, like, wtf are VBOs, VAOs, why do need to call all these magic functions to draw a triangle, etc. Building a CPU renderer, on the other hand, is pretty straightforward, the ONLY obstacle you have there is linear algebra, and it's not a lot of it.
Yeah I got kinda sad when glm abstracted a lot away but man writing shaders is a linear algebra curve ball, shadow mapping blew my mind first time around..
I'm actually curious, why are homogeneous coordinates so important? (I actually know linear algebra but I'm picking up a bit of graphics programming out of interest.)
I see they condense many movements into 4d matrix multiplications (e.g. translations), but apart from notational convenience all I could find was that these matrix operations have been optimized in GPUs.
What's really going on here? Why are they so essential?
a linear transformation can not map the origin to any other point: A(0) must equal 0.
this means you can't have translation in a purely linear formulation, which is a conundrum, because keeping things linear is really, really nice. as a general life rule, linear things are nice, nonlinear things are not nice.
so, you lift it from an n dimensional space to an n dimensional subset (not subspace!) of an n+1 dimensional space. by convention the subset is chosen such that the extra dimension is kept equal to 1 (arbitrary but convenient).
certain linear shears of this n+1 dimensional space look like a translation within that n dimensional subset.
you can also naturally restrict yourself to those linear operations which ensure that every point within this subset still maps to another point within that same subset (eg, closure).
thus you get the best of both worlds. you just need to be extra careful with the perspective divide (which isn't linear anyways), and you can things express all your transforms in a nice composable way that doesn't require special case handling (no branching, no edge cases, etc, just consistent math)
also the matrix-vector product ends up being the computationally cheapest way to express (say) rotations under the conditions most commonly encountered in 3d graphics (many points undergoing the same rotation). plus you get scaling+shearing "for free", and translation at no extra cost.
I'm familiar (well, since yesterday) with how homogeneous coordinates amount to adding a dimension in which we can "shear" to encode translation. I think the thing I'm looking for is a mathematically lucid and computationally thoughtful text on the subject.
Also, I'm still curious why exactly the matrix-vector formulation is better. I thought encoding things as matrix-matrix helped with memory locality, etc.?
Full disclosure, I got interested in projective geometry because the Hilbert metric was used in a proof that every "positive" Markov transition matrix will have a unique stationary distribution for its corresponding process. Then I wanted to tie things together with CS and found this. I want to get very "tangible."
So like... is there a good discussion that ties the two together?
but really i dont think you need any motivation beyond "A(0)=0 is a problem for translation" or a justification beyond "lift it to a subset of a higher dimensional space, then restrict yourself to the linear operators that give you closure, so it looks kinda like a subspace even if it isn't"
I want to get very "tangible"
i don't know what word you meant to use, but that is the wrong one
no, matrix form hurts memory locality because it is relatively wasteful with memory
you're using 12 elements (plus 4 implicit) to represent (usually) Sim(3), which is 7 dimensional. The extra 5 elements come from shears (3) and uneven scaling (2), which are rarely used.
however it is very SIMD friendly, and is FLOPs efficient for the most common case, for the reason i outlined before
(technically if there is no shear or uneven scaling you could have another 3 elements be implicit, or represented by a single bit if you want to support improper rotations, but that usually tips the space-time tradeoff in the other direction)
becaus ethen you can reduce perspective projection to one amtrix product and scalar division. Fantastic both for theoretical simplicity and to optimize things through hardware.
I never understood why some graphics programmers hyper focus on the math. The math is just facilitation for the art. It helps to understand it somewhat, but in my experience it is much more useful and important to understand the established conventions, hardware limitations and the structures you will work with to get what you want. If you are inventing new hardware or brand new paradigms, sure math chops will be important but even then you can get really far just leaning on well established conventions and libraries of existing code.
In the next meme I will show a 3d game Paladin swinging a holy war hammer. It will have a bounding box around the hammer. The enemy will have a (rotated, translated) bounding box.
I will ask these genuises how to determine if these bounding boxes intersect -- and hence whether the hammer hit the enemy. But they must code this up USING NO LINEAR ALGEBRA.
Is not a decision, the bounding box of an object is what it is, the minimal box enclosing the geometry. Graphics can use that to do frustum culling for example. Gameplay could use it to determine if there's a collision although that's usually done with a physics object...
I think there's a Mortal Kombat entry that did that. They used the render model for hit detection. It lead to zero gameplay improvement, for an obviously more computationally intensive and complicated hit detection. You're already using bounding boxes, which are wildly approximate. Get over yourself.
Just because you haven't done it doesn't mean no one else is. javid is a Youtuber who wrote a 3d graphics engine that rasterizes using the CMD prompt in windows. And yes his series is heavy on the linear algebra because that is what you need.
If you think there is "literally zero math", then you are not writing a 3d graphics engine, you are USING one. Which is fine, but not what the comic is about.
Because there are people that have, they're called graphics programmers and this is a job that still very much exists.
Taking your car analogy, like yeah sure you don't need to know how a car works to drive it. But you're claiming that nowadays there's no need for people who know how a car works, and that's obviously wrong.
Just as much as there is a need for linear algebra in pretty much every programming field related to 3d graphics. You're just shielded from it because you're using the tools by people that know the maths.
Why are you here in a discussion about making 3d engines? The post is about making 3d engines. You seem to think no one makes 3d engines, but this entire comic is about someone who is making a 3d engine.
But again. You're in a thread about creating a 3d engine. Whatever your opinions on why people would do that, just realize that this conversation is not for you. No one is talking about making industry standard engines. They are talking about making a 3d engine, for fun or otherwise.
I know this is prob ragebait but that last take is so shit. We still need mechanics even though you dont need one to operate a car. Hell, some cars drive themselves. If no one understands the underlying math of 3D graphics, who is going to maintain all the engines? Fix rendering bugs or optimize games?
If knowing fundamental or "primitive" math had zero value in your society and everyone stopped doing it, no one would know how to fix all the shit you use on a daily basis. There would be no innovation or improvements, everything would just eventually fall apart
the high level abstractions are built on the work of people who do need to know how things work under the hood, not everyone can be a crud webdev monkey
This person consistently has some of the worst takes in this subreddit. I'm not sure why they're even here, when they seem to hate anything that isn't a package or a third-party engine.
Graphics is not just threeJS. ThreeJS is just an abstraction over WebGL.
There are much lower level API's - Vulkan, Metal, DX11, DX12, OpenGL.
How would you write shaders then? If you want to do procedural programming then one has to learn linear algebra and apply it in the shaders. How would it be done "automatically"?
174
u/[deleted] Mar 15 '26
I'm building a simple 3d software renderer, and this can't get "truer" then reality. Everything in game dev in general is infact linear algebra. After learning this fact, I'm astonished that no game dev tutorial talk about this enough.
55
u/AnthonBerg Mar 15 '26
That's how you teach linear algebra!
I was in a horrible accident at university: Took graphics programming before linear algebra. It's much better that way. Made linear algebra just… click.
imo CUDA programming isn't about linear algebra, it's about decomposing your brain into thinking like ten thousand stupid dudes doing competitive eating
It changes you.
(comments: "THAT'S LINEAR ALGEBRA!!!")
42
u/Gumichi Mar 15 '26
I feel like this topic filters senior engineers from the juniors, and neither knows which is which.
20
u/nubrozaref Mar 15 '26
The easiest part of a 3d game engine is the graphics I swear. Writing all the systems so they work effectively with each other without each contact surface between systems being a source of bugs is way harder. Also in C/C++ I've yet to see a build system that feels coherent in all analysis.
51
u/goldswol Mar 14 '26
I mean, aren’t CUDA and ray tracing both built on a foundation of linear algebra?
23
u/Secret_USB Mar 15 '26
Trigonometry is huge too
11
u/snigherfardimungus Mar 15 '26
I was working on a game at one point, and we were something like $40M into the development (.... and it was not going to release on time and needed about another $10M.....) The company was trying to drum up hype for the game and invited members of mainstream media into the building to do a tour. They could go anywhere (except some "off-limits" area) and ask anyone any questions they liked.
The off-limits area was engineering.
One of my co-workers observed that we were basically the representatives of the "stay in school, study math, profit" philosophy, but the company didn't want to scare the kids with the fact that math is very, very fucking useful.
10
u/OhItsuMe Mar 15 '26
As a mathematician who loves graphics programming, it's funny to me that people tend to somehow grasp the wizardry that is graphics APIs and all these crazy concepts about programming optimisations that I cannot understand at all, but struggle with LA which to me is an elementary topic. Goes to show the difference in perspective.
5
u/susosusosuso Mar 15 '26
Both are necessary
3
u/ForzentoRafe Mar 15 '26
I'll need to revise again but I once really understood how matrice transformation work.
The whole thing with changing between different coordinate systems is fun too
Never did get an intuitive feel for quartenions though. They are like trying to grasp at some forbidden lore or eldritch text
3
u/Daniikk1012 Mar 15 '26
I feel like the GPU rendering pipeline is harder to grasp than linear algebra, like, wtf are VBOs, VAOs, why do need to call all these magic functions to draw a triangle, etc. Building a CPU renderer, on the other hand, is pretty straightforward, the ONLY obstacle you have there is linear algebra, and it's not a lot of it.
1
u/rio_sk Mar 15 '26
You'll get the most photorealistic engine ever, at 2 fps
1
u/Southern-Most-4216 Mar 15 '26
Yeah I got kinda sad when glm abstracted a lot away but man writing shaders is a linear algebra curve ball, shadow mapping blew my mind first time around..
1
u/RepresentativeBee600 Mar 16 '26
I'm actually curious, why are homogeneous coordinates so important? (I actually know linear algebra but I'm picking up a bit of graphics programming out of interest.)
I see they condense many movements into 4d matrix multiplications (e.g. translations), but apart from notational convenience all I could find was that these matrix operations have been optimized in GPUs.
What's really going on here? Why are they so essential?
1
u/Fabio11North Mar 16 '26
It's always been about vectors and matrices. Always has been.
-37
u/garlopf Mar 15 '26
I never understood why some graphics programmers hyper focus on the math. The math is just facilitation for the art. It helps to understand it somewhat, but in my experience it is much more useful and important to understand the established conventions, hardware limitations and the structures you will work with to get what you want. If you are inventing new hardware or brand new paradigms, sure math chops will be important but even then you can get really far just leaning on well established conventions and libraries of existing code.
0
u/[deleted] Mar 15 '26
[deleted] — view deleted comment