Imagination PowerVR SDK Blog

mat3 construction


#1

Hi there,


            Is there a nice way of construction a mat3 from a mat4 in a vertex shader?


I see in most of the PowerVR demos this is mostly avoided by passing in the 3x3 matrix.





The glsl spec lists a number of ways including:





uniform highp mat4 c;





mat3 a©;


mat3 b(c[0].xyz,c[1].xyz,c[2].xyz);





Both of which return the rather unhelpful “syntax error: syntax error” compilation error :frowning:





The only way I seem to be able to make one, is to copy the individual vectors over.





Thanks,





Steve.



#2

The problem you are encountering is because the syntax for the assignment differs from that which can be done in a language such as C++. Instead, you should write the following:







highp mat3 a = mat3©;

highp mat3 b = mat3(c[0].xyz,c[1].xyz,c[2].xyz);

[/CODE]



Unlike C++ syntax where (depending on the compiler) this could cause the default constructor to be called and then an assignment, the GLSL ES compiler interprets the code I’ve written above as a call to the assignment constructor.



JoeJoe2010-11-08 12:49:32<br /> <br />highp mat3 a = mat3(c);<br /> <br />highp mat3 b = mat3(c[0].xyz,c[1].xyz,c[2].xyz);<br /> <br />





Unlike C++ syntax where (depending on the compiler) this could cause the default constructor to be called and then an assignment, the GLSL ES compiler interprets the code I’ve written above as a call to the assignment constructor.





JoeJoe2010-11-08 12:49:32