8 ms·
> As a side note, Geometric Algebra contains more than just Rotors, and is a very useful tool to have in one's toolbox. I worked in a game engine where a pair
by dahart 7y ago
> As a side note, Geometric Algebra contains more than just Rotors, and is a very useful tool to have in one's toolbox.
I worked in a game engine where a pair of mathy programmers fell in love with Geometric Algebra, and use this same argument that quarternions ought to be replaced to overhaul all of the math code in the engine using Geometric Algebra. The character rigging system removed matrices and used GA instead.
This caused several large problems in the code base:
For one, it slowed the code down a little because the GPU interface is all matrices, so there were conversions to matrices all over the place, rigging in particular.
And only two guys in the studio knew Geometric Algebra, and they didn’t invest time in teaching it or helping people understand it, they just hoisted it on everyone. All the rest of the programmers knew matrix math but not Geometric Algebra, so they would end up avoiding touching any of the GA code, i.e., any code that dealt in transformations. The two guys ended up with a lot of support of their own creation, but they were short with their answers, in part because they got so many questions, so the problem never went away.
The third problem is this whole rewrite was unnecessary. Fixing gimbal lock with quaternions is a tiny corner of the game engine, whereas using GA throughout is a massive rewrite. Matrices work really well for 98% of the code, and it’s not really a huge problem to have one or two routines that convert to quaternions and back while they do a rotation. It is a problem when any transform at all involves bivectors and rotors and you have no idea what the hell those are nor do you have time in your schedule to take a math class at work.
Personally, I’m intrigued by GA and have wanted to learn it for a while, but having used it in production, I’m mildly against replacing quaternions with GA, and very wildly against replacing matrices with GA.
- jessermeyer 7y agoThese problems are not inherent of GA, but of (flawed) implementation details and deeper social problems. GA code boils down to essentially the same computations as 'raw' Linear Algebra, and should be implemented as such. Your math centered programmers fell in love with the idea without ever figuring out how to really use it.
- dahart 7y agoI completely agree it wasn’t inherent to GA, but I wouldn’t summarize it as they didn’t figure out how to use it. They were fluent, the problem is the rest of us weren’t. The problem with what they did, and what this article is doing, is suggesting we “fix” something that takes 2 or 3 math classes to understand by replacing it with something that takes an entire semester to understand. I honestly believe that GA has insights to offer, but I don’t believe it will save any time to upgrade the use of quaternions in any 3d engine.
- jessermeyer 7y agoWithout knowing more context it's a bit hard to respond, but from what you said, it sounds like they wrote an abstraction layer above matrices that observed GA semantics, which required a lot of run-time conversion. This is a flawed implementation, especially for a game engine. It's like writing a v-table for matrices to support every general case when you only need 3 or 4 specific instances anywhere in your code. Time spent -- You're probably right. For new technology, it's probably worth the research to see if code clarity is worthwhile...
- sdenton4 7y agoNot necessarily on top of matrices... I can easily imagine a part of an engine working with GA and then having to translate back or forth to matrices whenever it needs to interact with another (outside) part of the system.
- jessermeyer 7y agoTranslations like this are probably not a great idea in a game engine but I'm willing to be shown an example where it's the Thing You Want To Do.
- sdenton4 7y agoOh, yeah, it's a terrible thing to do, absolutely. All I'm saying is that you can have a perfectly consistent /component/ using GA, but if it's living in a larger ecosystem of matrix-based code, you're going to have to do these translations somewhere. (eg, we rewrote the camera compoent in GA, but the dudes doing grass modeling haven't converted.) You get an all-or-nothing problem: it's efficient if the whole codebase is using the same abstraction, but converting around between a bunch of abstractions will come with a cost.
- notduncansmith 7y agoThank you for the anecdote! Sorry to leave such a small comment but I believe you meant “foisted it on everyone”, not “hoisted”.
- dahart 7y agoFoisted is indeed a better choice there, whatever I thought I meant. Thanks! I thought about editing, but I’ll leave it so as not to disturb your comment.
- mrspuratic 7y agoI'm sure everyone's been in a situation where so much sh*t was dropped on them that a hoist must have been involved ;-)
- smcameron 7y ago> Fixing gimbal lock with quaternions Huh? I thought quaternions don't have any problem with gimbal lock. That's a problem with Euler angles and matrices. Edit: I think you meant using quaternions to fix gimbal lock problems with matrices, which makes sense.
- ur-whale 7y agoThe wikipedia page for GA, and in particular the introduction, is an absolutely perfect example of the horrible quality of math pages on wikipedia.
- GeorgeTirebiter 7y agoThanks for saying this. On other math topics on wikipedia, I've read, re-read, and re-read them and still felt like I didn't understand. Maybe it wasn't all my fault.
- AnimalMuppet 7y agoI think the Wikipedia math articles are not horrible, if you already know the concepts involved and just need a bit of a reminder on something. If you don't know them, though, they're not a good way to learn, IMHO.
- TwoBit 7y agoI've multiple times heard mathematicians says Wikipedia math pages are bad, and even experts in an area can be confused by the pissing of other experts in that same area.
- WAHa_06x36 7y agoMath on Wikipedia is just absolutely atrocious.
- harmoat 7y agoRemember, wikipedia is an encyclopedia, not a textbook
- SkyBelow 7y agoI feel like this requires the same concern when replacing any system. Even if the new tool is better in theory, does it have enough people using it/experts working on it that it is better in practice and does the costs of replacing it justify the improvement. Just look at something like a 50 year old IBM mainframe vs. the newest Sql Server with .Net Core running on the server of your choice. Is the latter the better choice for a new application? Yes. Yet many very successful businesses don't replace their mainframes because the benefits do not justify the costs.
- BlueTemplar 7y agoThe main issue here is that they tried to port what sounds like a mature code base. Imagine changing programming languages! They should have restarted from scratch, and with a team fluent in Geometric Algebra...
- BlueTemplar 7y agoIIRC matrices are still required in Geometric Algebra ? Maybe by "matrix math" you mean "Vector Algebra? "
- gugagore 7y agoI'm not the grandparent. I'm not sure what you mean by "required", but, no, I don't think so. You can represent a lot of algebraic objects and operations using matrices and linear algebra operations. The most accessible example of that is probably complex numbers: https://en.wikipedia.org/wiki/Complex_number#Matrix_representation_of_complex_numbers https://en.wikipedia.org/wiki/Complex_number#Matrix_represen... and I wouldn't say that "matrices are still required in complex numbers" any more than I'd say "matrices are still required in geometric algebra".
- BlueTemplar 7y agoOK, after refreshing my memory on GA, it seems that one of the nice things about it is that you don't have to think about the "row" vs "column" vectors present in "Vector Algebra". Which are usually represented in the form of matrices. But you don't "need" them in GA, since you can directly work with vectors (= arrays) ! (Which makes it even more curious as to why matrices would be more efficient for 3D work ??)
- gugagore 7y agoI think I understand roughly what you mean when you distinguish row and column vectors. For example, let [x, y] represent a row vector and [x, y]^T represent a column vector. If you have a function f that maps [x, y]^T -> z, (you might write it z=f(x,y)), then the gradient(f) is a function [x, y]^T -> [x, y]. That is to say, the gradient is a row vector. It's a different kind of vector than the input to f. And it transforms different (c.f. https://math.stackexchange.com/a/3200912/ https://math.stackexchange.com/a/3200912/) So using that kind of thinking, the cross product of two column vectors is a row vector: https://www.youtube.com/watch?v=BaM7OCEm3G0 https://www.youtube.com/watch?v=BaM7OCEm3G0 As you say, Geometric Algebra doesn't talk about row vectors and column vectors. For example, in 3D GA,you can choose a representation in R^8. That's 1 scalar, 1 pseudo-scalar, 3 column-y components, and 3 row-y components.
- agumonkey 7y agoAlthough the fact that GPUs are not ready for GA .. forcing a model that cannot fit onto hardware is quite a massive naive mistake.
- janoc 7y agoThat's not about "not being ready", the GPU really doesn't care whether the numbers it is multiplying are coefficients of a matrix or a bivector. The problem is that all libraries, drivers, etc. use matrices, quaternions and vectors. So you would have to constantly convert back and forth, which is both error-prone and a non-trivial performance problem. Of course, you could build your own libraries for everything, but that's just crazy. Who has time for doing that? Not to mention that writing a mathematical library like that is a highly non-trivial task. Not just the algebra part but also numerical stability and accuracy are a big deal. That requires a very skilled person, naive implementations will rapidly blow up in your face. And doing all this what for, exactly? So that the GA explanation of rotations doesn't require 4 dimensions while the math complexity of rotor algebra ends up being the same as with quaternions? So there isn't really a performance benefit neither.
- gliese1337 7y agoWho has time for that? Me. And, presumably, Marc ten Bosch. When you want to make a game that uses full 4D graphics, existing libraries just don't cut it, and writing GPU code to understand arbitrary-dimensional rotors is worth it.
- oppositelock 7y agoI'm a former game engine lead from many years ago, from around the time that quaternions were becoming popular, since we never used them before the early 2000's, really, as 3D was young and rotation matrices sufficed. Quaternions came into favor to solve the problem of gimbal lock in composed Euler rotation matrices. This happens when you create a rotation which rotates one axis into another, and end up with a matrix that loses one axis (it loses an eigenvector), and you become "trapped" in the new rotated frame and can't ever rotate out of it. Quaternions don't suffer from this problem, but they're also tricky to work with and reason about, and their rotations can become funny when composed - instead of rotating from orientation A to B, they'll go through a C in a very different place. You need to create heuristics to keep rotations looking sane with quaternions. In the games that I've worked on, we took other precautions to avoid gimbal lock in rotations and stuck to Euler matrices. For example, in a flight simulator, you always computed the final rotation matrix for the plane location directly from its heading, pitch and roll, and so, you'd never suffer gimbal lock. Why stick to Euler matrices and not some better Geometric Algebra or Quaternions? Because it's really easy to interpolate, and think about plain old rotations about a vector, and you can teach anyone to avoid gimbal lock. It's easier to avoid that problem than to train a bunch of junior engineers on higher level math.
- pfedak 7y agoCould you elaborate more on interpolation and weirdness of composing quaternions? I thought a big selling point for quaternions was the ease and naturalness of just using slerp, whereas with euler angles a similar approach gives bad results. When you mention rotations about a vector, do you mean you decompose the desired rotation matrix into axis/angle? Otherwise I'm very impressed by your ability to visualize compositions of arbitrary rotations.
- oppositelock 7y agoYou can't solve the problem of avoiding gimbal lock in arbitrary rotations, so you rig the game not to ever have arbitrary rotations. You cheat, basically. Gimbal lock is a huge problem in software where free form rotations are allowed, such as 3D modeling packages, CAD, but in games, since we control the world, we can set it up not to have these problems. Quaternion interpolation works well, but it introduces twist, which is sometimes not what you expect. When you start composing many quaterions, you get some wild rotations, going the long way, or doing an additional 360 twist, and whatnot. Mind you, I'm digging 20 years back in my brain here, I don't remember many specifics anymore.
- nautilus12 7y agoIsn't the data structure that supports quaternions just one dimension up from matrices? Why not continue using matrices and retain that last dimension seperately somehow? Then it doesn't require having to retool the GPU/matrix side of it. IE you will have multiple matrices where you would have had one otherwise.
- madrox 7y agoAs an engineering manager who's had to push adoption of new technologies, I feel this argument in my bones. That said, taking your argument to the extreme, we all probably should've stuck with PHP, since everyone understood it and, well, was it really worth the switching cost? Naturally that's dumb, so there's a certain amount of "how do we get there?" with any new technology that's probably a good idea. That's probably not going to get answered by the principal engineer who says This Tech Is The Future. It's going to get answered by people like you who think about switching costs and the impact new tech has on people.
- deleted 7y ago[deleted]
- Chirono 7y agoI would hope any good principal engineer spends a decent amount of time considering switching costs and impacts of new technology. Sounds like this isn't your experience though?
- jaw 7y ago> taking your argument to the extreme, we all probably should've stuck with PHP, since everyone understood it and, well, was it really worth the switching cost? There are multiple paths for honing a new technology, without dumping it on a large group of developers while it's in its experimental stages: - Use it for a series of side-projects - Use it in a startup or startup-like team in which all the developers are bought into it, and happy to work through the obstacles - Use it at an organization that's both able and willing to devote a large amount of resources to making it work (e.g. devoting a full-time team to its development & support & related training) Once the kinks have been sufficiently worked out in one of those contexts, and a solid ecosystem with good documentation exists, then there's a much better chance that the benefits will be worth the switching costs for the average project.
- pfranz 7y agoI haven't worked on large gaming projects, but I've worked on large CG feature films. I was a little horrified about how aggressively they adopted some technologies. The theory was that Pixar proved a lot of their technologies in their short films (Disney a bit of that, too, in previous years). The studio I was at didn't do that and both Disney and Pixar seem to have moved away from that at least a decade ago. Very very rarely, they'd repurpose old projects or chose a sequence or specific department for releasing something--that often was a mess (resources spent at the "boundaries" instead of shoring up the new tech). I imagine AAA games are similar. You have 4 years and ship one monolithic game. Maybe you could prove out this idea in a small area like artist's tools or an engine fork (similar to the approaches above). Trying to incrementally adopt something would take 2 or 4 games (10+ years) and I just don't see technology roadmaps like that. Especially if it's not a huge win.
- moralestapia 7y agoThis is more or less the thing with "Category Theory". Very fancy and neatly structured code but in the end you accomplish pretty much the same; and now nobody on the team understands a bit about what you're doing.
- asdfman123 7y agoYou mean there's a way to establish yourself as an arcane code wizard and make yourself irreplaceable? Sign me up!
- moralestapia 7y agoIt's more like: "Why would we use a framework that nobody understands but you, to accomplish the same stuff a few SQL statements can do?" The former option never wins.
- crimsonalucard 7y agoExcept what you said is not true at all. Whats going on here is you're scoffing at something you don't understand. Before you scoff, understand it. Then scoff. Until then you're just as good as the ignorant people who ridiculed the theory of a heliocentric solar system.
- moralestapia 7y agoNice preconceptions, they truly add to your argument. CT brings nothing new to the table in terms of "now we can do X that we couldn't do otherwise". If you can provide an example to prove its usefulness, please do. Funny thing is that every time it comes down to "just show me" the hand-waving and "you wouldn't get it" begins. Things that work speak for themselves. >you're scoffing at something you don't understand Actually ... I was also very excited by the promise of CT a few years ago and since then I have read a lot about it and I'm quite confident "I understand" what I'm talking about. I've been programming for about 20 years, half of them with functional languages (or languages with first-class functional constructs: lisp, haskell, scala). I have read the most famous books on CT touching on programming, some of them are signed as I have spent my own money going to some CT conferences and meeting with the people there. As a conclusion, I don't mean that CT is useless in itself. It definitely is a nice mathematical framework and has proven a great tool for a few things here and there in different areas of math. But in the context of computer science, as I said it before, it does not bring anything new to the table.
- earenndil 7y agoGPUs don't have dedicated matrix hardware anymore, making it questionable whether you really need to convert your GA structures to matrices first. [1] finds that quaternions are faster than matrices on modern hardware; I find that questionable, but it at least shows that they are comparable. 1: https://tech.metail.com/performance-quaternions-gpu/ https://tech.metail.com/performance-quaternions-gpu/
- dahart 7y agoThe APIs (D3D, etc.) do use matrices, and that's all that matters from the point of view of an engine developer. Composing quats together is certainly faster than composing matrices, but quats are limited (no translation / skew / perspectivce / etc.), so there is no direct apples-to-apples comparison between quats and mats.
- earenndil 7y agoThey let you upload matrix data to the gpu, but all functions like glUniformMatrix4fv() really do is upload a 16-vector into gpu memory (and optionally reshuffle its layout). The shading languages also have matrix primitives, that's just sugar.
- Const-me 7y ago> The APIs (D3D, etc.) do use matrices D3D API exposes a way to pass constant buffers to shaders. You can pass whatever you want there, even integers. There're couple limitations, size must be multiple of 16 bytes, and can't exceed 64kb, but I don't remember anything specific to matrices. Now, the only place I can remember which specifically targets matrices - mul intrinsic in HLSL. But that thing is just a syntactic sugar, usually compiling into dp4 dxbc instructions.