I'm currently studying matrix operations in shaders, and I might be mistaken because I'm still quite confused, but isn't the calculation shown in the “Matrix * Matrix” section incorrect?
Hi! Both are correct. Remember the order of operations is important. matA * matB != matB * matA. view_matrix * projection_matrix != projection_matrix * view_matrix.
I confirmed with this:
float a = 1., b= 2., c = 3., d=5., x = 7., y=11., z = 13., w= 17.;
I'm currently studying matrix operations in shaders, and I might be mistaken because I'm still quite confused, but isn't the calculation shown in the “Matrix * Matrix” section incorrect?
Shouldn't it be:
mat2(a,b,c,d) * mat2(x,y,z,w) = mat2(x*a+y*c, x*b+y*d, z*a+w*c, z*b+w*d)
mat2(x,y,z,w) * mat2(a,b,c,d) = mat2(a*x+b*z, a*y+b*w, c*x+d*z, c*y+d*w)
Hi! Both are correct. Remember the order of operations is important. matA * matB != matB * matA. view_matrix * projection_matrix != projection_matrix * view_matrix.
I confirmed with this:
float a = 1., b= 2., c = 3., d=5., x = 7., y=11., z = 13., w= 17.;
bool test1 = mat2(a,b,c,d) * mat2(x,y,z,w) == mat2(x*a+y*c, x*b+y*d, z*a+w*c, z*b+w*d);
bool test2 = mat2(x,y,z,w) * mat2(a,b,c,d) == mat2(a*x+b*z, a*y+b*w, c*x+d*z, c*y+d*w);
Thank you for your reply.
I'm sorry, my previous comment was not written clearly, and I couldn't express my intention well.
I'm not a native speaker, so writing in English is difficult for me.
In the "Matrix * Matrix" section of the article, it says:
mat2(a,b,c,d) * mat2(x,y,z,w) == mat2(x*a + y*b, x*c + y*d, z*a + w*b, z*c + w*d)
mat2(x,y,z,w) * mat2(a,b,c,d) == mat2(a*x + b*y, a*z + b*w, c*x + d*y, c*z + d*w)
However, in your reply, you wrote:
mat2(a,b,c,d) * mat2(x,y,z,w) == mat2(x*a + y*c, x*b + y*d, z*a + w*c, z*b + w*d);
mat2(x,y,z,w) * mat2(a,b,c,d) == mat2(a*x + b*z, a*y + b*w, c*x + d*z, c*y + d*w);
Which one of these is correct?