OpenShadingLanguage
OpenShadingLanguage copied to clipboard
Matrix layout is only partially documented
The documentation of matrix() points out that the 16-float constructor form accepts values in row major order, and the [][] operator accepts first a row and then a column. However that by itself is not meaningful, it also needs to specify if matrices have basis vectors in rows or columns. Depending on that choice:
- A translation matrix may be either
matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1), or
matrix(1, 0, 0, tx, 0, 1, 0, ty, 0, 0, 1, tz, 0, 0, 0, 1). - The expression
point p3 = transform(M1 * M2, p1)may be equivalent to either
point p2 = transform(M1, p1) ; point p3 = transform(M2, p2);, or
point p2 = transform(M2, p1) ; point p3 = transform(M1, p2);
In algebraic terms, that matrix multiplication would look like $\mathbf{p}\mathbf{M}_1\mathbf{M}_2$ (if vectors are rows), or $\mathbf{M}_2\mathbf{M}_1\mathbf{p}$ (if vectors are columns).