Reading — step 1 of 5
Read
4x4 Matrix Multiply
Matrix multiplication is the engine of 3D transformation. Concatenating Model * View * Projection collapses three transforms into a single 4x4 you can hand to a vertex shader.
For 4x4 matrices A and B, the product C = A * B is defined as:
C[i][j] = sum over k of A[i][k] * B[k][j]
That is, the (i,j) entry of C is the dot product of row i of A with column j of B. Sixteen entries, each a sum of four products — 64 multiplies, 48 adds.
Row-major vs column-major matters for memory layout, not for the math. In GLSL/HLSL/Eigen, matrices are column-major; in DirectX/raw C arrays, row-major is common. The convention determines whether v' = M * v or v' = v * M reads naturally, but it does not change which transformation is applied — only the indexing.
Non-commutative: A * B != B * A in general. Translation then rotation differs from rotation then translation; the right multiply happens first when you read P * V * M * vertex right-to-left.
Identity: A * I = I * A = A, where I has 1s on the diagonal.
GPUs do this in one instruction per row. Modern CPUs use SIMD intrinsics (_mm_mul_ps, vfmaq_f32) to fuse 4 multiplies and 4 adds per cycle. The naive triple loop is fine for prototypes; ship the SIMD version once correctness is locked.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…