Greeting,
I represent my matrix buffer with the following data on the GPU:
Address: Data:
0x00 0 1 2 3
0x01 4 5 6 7
0x02 8 9 10 11
0x03 12 13 14 15
With the following shading code:
float4 (out) = float4x4 (m) * float4 (in)
According to apple's documentation
float3 u = m * v;
is equivalent to:
u = v.x * m[0];
u += v.y * m[1];
u += v.z * m[2];
My question is does m[0] refer to <0, 1, 2, 3> or <0, 4, 8, 12>?
As my experiment shows the GPU does compute the matrix as m[0] = <0, 1, 2, 3>
But common sense tell us m[0] should be the column <0, 4, 8, 12> otherwise it's very hard to read and debug
If m[0] did refer to <0, 1, 2, 3>, is there any way to transpose a matrix in shading file?
Or we have to work on transposed matrix all the time?
Thanks!
Matrix components are constructed and consumed in column-major order.
The reason that the results are not consistent with your expectations is that you are not constructing your matrix in column major order. Here's the matrix you're making:
0 | 4 | 8 | 12
1 | 5 | 9 | 13
2 | 6 | 10 | 14
3 | 7 | 11 | 15