4 ms·
> I don't get how the matrix operations somehow magically work out. There's two secrets to this. The first trick is remembering what matrices do to vectors, bo
by Jasper_ 5y ago
> I don't get how the matrix operations somehow magically work out.
There's two secrets to this. The first trick is remembering what matrices do to vectors, boils down to equations of this form:
x' = M[0] * x + M[1] * y + M[2] * z
y' = M[3] * x + M[4] * y + M[5] * z
z' = M[6] * x + M[7] * y + M[8] * z
I won't write the function for matrix/matrix multiplication, but when we invented it, we chose a function that's associative with respect to matrix/vector multiplication. That means that Ma * (Mb * v) = (Ma * Mb) * v. This turns out to be a very good property, because we can then "collapse" every single linear transform we ever want into a single matrix. Stack these however high you want: (Ma * Mb * Mc * Md * Me * Mf * ...) will always collapse down to a constant number of numbers.
In computer graphics, we tend to have a few "standard" matrices converting up the chain of spaces like this:
vProjectiveSpacePosition = mProjectiveFromView * mViewFromWorld * mWorldFromModel * mModelFromBone * vBoneSpacePosition
And you can add your own if you want!
The second thing is that we cheat when it comes to perspective. The "correct" way to think about it is that your 4x4 matrix transforms into a 4-dimensional space known as "projective space" where parallel lines meet at some point.
But that's confusing, the better way to think about it is that we can't elegantly represent perspective with just 3 coordinates, so we cheat and add a weird fourth one. Don't worry about it too much, the math is mostly handled by higher-level libraries. Once you need to figure things out yourself, you should be able to learn what you need to learn. But for now, just get comfortable with the above.
> I don't get how it is that light bouncing/reflectivity works itself out in any reapectable amount of time
We actually don't do "light bouncing" in real-time, we typically emulate it. Think of it like this: if you shoot a bunch of light rays at a thing in the real world and measure the light back, you'll come back with a bunch of light reflected back (towards a sensor, but it could also be towards your eye).
Now try to curve fit that data to some equation. That's one of the most popular models for object materials, "Trowbridge-Reitz": https://www.desmos.com/calculator/8otf8w37ke https://www.desmos.com/calculator/8otf8w37ke . In practice, it's a combination of curve fitting to real-world data and a lot of smart people thinking about how to make it make physical sense. This models parameterized to work on some known set of materials (the working theory is "microfacets", which are tiny grooves on an object assumed to be mirrors). There are other models you can have, too, but this is the workhorse of the games industry.
To get reflections, we play tricks: pre-compute the incoming light for a given reflection vector, so it doesn't have to be done at runtime. But this comment is already long enough. Contact info is in profile if you want to ask me more questions.