6 ms·
What I don't get is why nearly all resources on 3D graphics assume the reader is familiar with matrices and linear algebra. For those who don't speak that lang
by clarry 10y ago
What I don't get is why nearly all resources on 3D graphics assume the reader is familiar with matrices and linear algebra. For those who don't speak that language, what you're doing is plotting numbers into a magic box, doing a magic multiply, and hey presto, we got 3D! Magic.
Meanwhile a teenager could easily get an intuitive grasp of 3D graphics if you just explained how translation is nothing besides addition, and that to rotate, you just use good old trig functions to generate rotated basis vectors along which to plot your vertices (really easy to show with images and animations too). And that magic perspective, to make things get smaller as they get further from the camera, is just one divide by the depth away... yes, all very basic arithmetic. And no need for magic such as homogeneous coordinates. They're just a convenience for when you do things a certain way.
You don't need to go to college or even high school for 3D rasterization. But most if not all texts pretty much want to assume such a background?
Actually, I'm quite tempted to try write such a tutorial for the 12-year-old me. Too bad I can't travel back in time to see if I'd actually understand it (but I have a strong feeling I could come up with something good enough). Yeah, the lack of approachable material was very frustrating for me back then. In the end I wrote a very primitive renderer (with plenty of trigonometry per vertex) which was way too slow and complicated to be useful. Because I didn't realize how simple the problem actually is.
- sillysaurus3 10y agoYes. I was able to make a Quake-like clone when I was 17 with no knowledge of how matrices worked or linear algebra. This was before Unity et al, so I had to build it from scratch. You can get surprisingly far by stringing magical utility functions together. The reason I know those things now is because I wasn't forced to learn them then. Detail comes after engagement.
- liamzebedee 10y agoWould love to see the source for that, if you still had it.
- dahart 10y ago> I'm quite tempted to try write such a tutorial You should do it! I agree and think that making 3D approachable is possible, and that most tutorials fail to make it easier than already available materials. I'm not sure it's easy to do, but if you succeed then people will benefit and if it turns out to be hard, you'll have developed a stronger appreciation for the problem and/or the motivation to solve it.
- ivan_ah 10y agoSpeaking of short tutorials on linear algebra, you should check out this one I wrote last year. It's more of a "prepare for an exam" document, but it gets to the core idea of matrix-vector product serving as a way to "implement" linear transformations: https://minireference.com/static/tutorials/linear_algebra_in_4_pages.pdf https://minireference.com/static/tutorials/linear_algebra_in... I'm personally fine with using the computer as a "magic box" to do all the calculations, but it's important to have a geomtrical intuition about the operations. This is another short tutorial that does a good job at conveying the geometrical aspects of linear algebra: http://www.cns.nyu.edu/~eero/NOTES/geomLinAlg.pdf http://www.cns.nyu.edu/~eero/NOTES/geomLinAlg.pdf For those interested in learning LA in full detail, you can check out my upcoming book which covers all the essential material and discusses lots of applications, including the homogenous coordinates used in computer graphics: https://minireference.com/static/excerpts/noBSguide2LA_preview.pdf#page=88 https://minireference.com/static/excerpts/noBSguide2LA_previ...
- clarry 10y agoI skimmed through the book preview, and it looks very nice. Though I already have a few books on LA, I wouldn't mind having yours on my bookshelf too... any ETA on when it's available for purchase? Actually I'm planning to quit my job and go study mathematics starting next semester (if I can afford it...) so it might come in handy.
- ivan_ah 10y agoThe editor is doing a final pass through it this summer, so the first print version will be ready for August. But, when I say August, it probably means September ;) The eBook version has been ready for a while now, and it gets constantly updated. I can also print you a one-off copy of the current version if you need it sooner.
- deleted 10y ago[deleted]
- arthurdarbinyan 10y agoSeems wonderful book. Is there an epub version?
- saganus 10y agoFor those interested I found this book quite good: "Linux 3-D Graphics Programming" [1] That explains how to build a 3d engine almost from scratch and it does explain 2D math (cross product, etc) and also 3D stuff of course (matrix operations, perspective projection, etc). It's a bit dense in that it pretty much builds everything from zero, but it's a very nice way to go through everything needed to work with 3D graphics. You can check the content table in Amazon I think. The second book "Advanced Linux 3D Graphics" is a bit less interesting for me since it talks a lot about Blender and other software which it doesn't really go with the theme of the first one, but there's still a lot of good info in there. [1] http://www.amazon.com/Linux-3-D-Graphics-Programming-Norman/dp/155622723X http://www.amazon.com/Linux-3-D-Graphics-Programming-Norman/...
- lastofus 10y agoWhat you are wanting is this book: "Tricks of the 3D Game Programming Gurus" by Andre LaMothe. The book teaches you how to write a 3D software rasterizer from first principles. The first part of the book is nothing but a well written linear algebra primer. The book then assumes you have nothing but a C++ compiler and a pointer to the frame buffer like you might get using SDL. Unfortunately the book appears to be out of print, and the APIs used are a bit out of date at this point (Win32 and old DirectX used to set up a window w/ a frame buffer ptr). All the same, I would still highly recommend it to anyone who wants to understand the foundations of 3D math and fixed function rendering pipelines.
- clarry 10y agoThanks for the recommendation, I'll see if I can find a copy somewhere. But I think the 12-yo-me wouldn't have bought a book and certainly wouldn't have appreciated one that starts with a linear algebra primer (no matter how well written). Really, what I would've needed back then would've been a relatively short tutorial somewhere online, preferrably one that doesn't require me to start with linear algebra. Just the basic arithmetic I was familiar with back then. Maybe I will indeed have to try write one now some day. Short enough that it would be easy for people to contribute translations. Indeed, a math heavy book in English would've been totally inappropriate.
- tripzilch 10y agoI just had the Asphyxia Demotutorials (look them up on one of those oldskool textfiles websites, maybe it's exactly what you are referring to? except of course the bits were they also learn you Turbo Pascal and ASM :p) But the arithmetic, goniometry (trigonometry?) and geometry were the hard parts, which I learned in school, but were still tricky (because I liked learning, not memorizing formulas). Linear algebra was the new and easy part. You don't need matrix inversions, eigenvectors or triangular decompositions or any of the complex Linear Algebra stuff. It's just vector math. And you probably already know arrays. It's merely a notational convenience when you recognize that you're doing the exact same operations on three x,y,z-variables all the time. When I saw it first as a teenager I was like "hey that's clever, lots less to write!" (when working out formulas on pen and paper, not having to write everything thrice, yay!).
- Jasper_ 10y agoI recently gave an internal tech talk at our company about just that, and my main goal was exactly that: no matrices whatsoever. Basic trig and points and lines on a canvas tag. Eventually, I switch over to OpenGL. Video and audio quality aren't great, but you might enjoy it. https://www.youtube.com/watch?v=v8jUNC5WdYE https://www.youtube.com/watch?v=v8jUNC5WdYE
- khedoros 10y agoI remember doing something similar (ignoring matrix transforms and hand-calculating everything with trig because I wasn't comfortable with it). It works fine, and it's great for a theoretical understanding of how rasterization works. I like starting from the basics that way too, then building on it. I think that most tutorials and such have a more practical focus though, with the goal of getting you to practical use of a 3D programming API (or at least skipping to the more-efficient combined transformations that matrices allow). I know that I found enough resources that covered the low-level view of things when I was teaching myself about this stuff, but I had to sift through a lot, and I ended up mostly dropping it. Recently, I've been looking for info on doing UV mapping in software. That's pretty hard to find practical information on too.
- alejohausner 10y agoIgnoring matrix transformations is easy, as long as the eye point is at the origin. Then yes, the algebra is almost trivial: projection is just divide-by-z. But the moment you move the camera, or stretch and turn objects, or worry about clipping, you need the full machinery that matrices provide. They're not that mysterious. I wish they were taught in high school, because they would motivate kids to learn graphics and programming.
- clarry 10y agoNope, you totally don't need matrices to rotate, scale, and translate stuff. It's all very simple addition, multiplication and a wee tiny bit of trigonometry. As trivial as the perspective divide. In a 3D renderer, this is among the simplest and most straightforward of things. You can take it step by step and each step should be pretty straightforward to explain and illustrate. That is what is needed to build intuition and dispel the magic. After that, matrices are just a convenient abstraction, and perhaps more importantly, a reasonable way to express your intent to the underlying graphics library or hardware. Which you don't necessarily want to use.
- alejohausner 10y agoAgreed: moving, turning and stretching don't need matrices, to be understood. But moving the camera away from (0 0 0) is going to require a change of coordinates. I'm not sure how to explain that process in a simple way that avoids matrices.
- greggman 10y agoI tried to do that here http://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html http://webglfundamentals.org/webgl/lessons/webgl-2d-matrices... It expands to 3d in the following article
- dyarosla 10y agoI still have this one labelled as my all-time favorite intro to matrices.
- angersock 10y agoWe learned basic vector arithmetic back in highschool doing our own gamedev stuff, and it's pretty straightforward. The use of matrices as "mapping" one space to another likewise so. Any approach that ignores the relevant parts of linear algebra, though, is probably going to collapse under its own weight as things get more complicated--experiencing that collapse may be interesting from a learning perspective, but I suspect it is not needed. The real problem is that the useful parts of linear algebra--for graphics anyways--may never be seen before college, and even then they may be presented in the abstract form which prevents their utility from being realized. Really, any 3D primer should just assume no familiarity with the subject, and then teach exactly those bits which are relevant to computer graphics.
- alejohausner 10y agoThis. You went to the right high school. Matrices and vectors are just a subset of linear algebra, and can definitely be taught to teenagers. When I teach graphics to 3rd-year college undergraduates, I tell them "this is what all that point-and-vector stuff you learnt in high school was really meant for". They've usually forgotten it all, but it comes back to them quickly, and the matrix stuff on top of that isn't very hard, so I can get them up to speed pretty quickly. Most CS degrees require linear algebra, which talks about vector spaces, gaussian elimination, diagonalization, rank, which is all useless for graphics! Too bad that course is usually relegated to the math department, which doesn't know how fun and useful a small subset of linear algebra is!
- rectang 10y agoFor learning comp-sci-focused linear algebra with programmatic exercises in Python, see http://codingthematrix.com http://codingthematrix.com
- angersock 10y agoA minor clarification: the vector/matrix stuff we picked up outside of class by hanging out at Barnes & Nobles and reading books. :) I was fortunate in college to have a professor teaching graphics (Ron Goldman) whose training was in differential geometry. So, graphics to him was a beautiful if trivial application of mathematics and linear algebra and he taught it as such. I will always value his teaching of mass-point stuff as an approach, because it just is so nice in how it ends up.
- dyarosla 10y agoThey don't assume anything here and they even provide the required learning in the intro, themselves walking through everything you wanted. http://scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/geometry/how-does-matrix-work-part-1 http://scratchapixel.com/lessons/mathematics-physics-for-com...
- alejohausner 10y agoThe reason that 4x4 matrices are used so much in graphics is their versatility: you can use them to implement modeling (placing an object into the world), viewing (changing a world point into camera coords), projection and clipping (putting a camera-coord point into clipping coords), color transformations (after all, both x,y,z,w and r,g,b,a are coordinates of a 4D point). That's why there's matrix multipliers built into all graphics hardware. I understand where you're coming from: translating a point is just 3 additions, so why do a full matrix x point multiply? Scaling is just 3 multiplies, and so on. But if you've got a hardware matrix-point multiplier, all those transformations cost the same, so you're not saving time by devoting special code to each kind of transformation. Moreover, you don't have to learn full linear algebra: to do graphics, you don't have to know how to invert a matrix, nor solve a system of linear equations, nor diagonalize a matrix. Graphics just needs a tiny subset of linear algebra. When I teach graphics, I describe points, vectors, lines, circles, matrix-point multiplication, and matrix-matrix multiplication. It takes maybe two lectures, and it provides tools for lots of other parts of the graphics pipeline. Once you have those tools, you can talk about the viewing transformation (just a special matrix), composite transformations (matrix-matrix multiplication), hierarchical objects (more matrix-matrix multiplication), projection (another special matrix), color transformations (another special matrix). I also find that when describing ray tracing, you need to talk about going from (row col) pixel coordinates to a 3D point in space, where the ray starts. That's partly the INVERSE view transformation, and (yay) it's just a matrix. When I was a wee lad in 1981 I did indeed try what you suggest: I worked out the algebra of projection, knowing just where the image plane was (using some points and vectors), and where the world point was. This give me an image point. I was very proud to be able to squeeze this into 50 opcodes on a TI-57 calculator. But when I became a man, and put away childish things, I saw that matrices describe the same process much more cleanly and simply. I wish I had known about them much earlier. Hell, I wish high school math taught some points and vectors, and some simple matrix operations as I described above (not full-blown linear algebra). Then, they could use those tools to make pictures starting from just numerical descriptions of shapes! It would give many kids more enthusiasm for mathematics, and would start them on the way towards operators, groups, linear spaces, and all those things they might see later. All we would have to do is get education departments to teach the math teachers all this stuff. It would be exhilarating for everyone involved.
- Fr0styMatt88 10y agoIn addition to the recommendation by lastofus, I highly highly recommend this presentation: https://www.youtube.com/watch?v=GNO_CYUjMK8 https://www.youtube.com/watch?v=GNO_CYUjMK8 Despite the title, the talk is NOT WebGL specific. It's a fantastic, FANTASTIC tour of 3D graphics fundamentals. This is, IMHO, quite simply the best presentation I've ever seen on how matrix math relates to graphics programming. Also see Stevens' site: http://acko.net http://acko.net Side note - There are some great pages there, be sure to check this one out if you're at all interested in how math is applied to animation: http://acko.net/blog/animate-your-way-to-glory/ http://acko.net/blog/animate-your-way-to-glory/
- mast4as 10y agowww.scratchapixel.com was exactly designed/created for that: teaching cg programming from the ground up with simple words assuming readers have 0 mathematical bg (well you still need to know what a + and - are and a few more things).