3

I'm trying to understand molehill and would like to multiple a vertex by two matrices, say:

output = theVertex * scaleMatrix * rotationMatrix

Im guessing my vertex shader would look something like:

"m44 vt0, va0, vc0\n" +
"mul op, vt0, vc1\n";

And i would set the matrices with

context3d.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, scaleMatrix);
context3d.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 1, rotationMatrix);

But its not working. What am i doing wrong?

Im aware that i could multiple the matrix before putting on the shader, but i am trying to understand AGAL.

Cheers

J. Holmes
  • 18,466
  • 5
  • 47
  • 52
user346443
  • 4,672
  • 15
  • 57
  • 80

1 Answers1

4

A m44 matrix is 4x4 floats, it takes 4 registers as each register is 128bits (4 floats) so you have to load your rotation matrix into vc4 register:

"m44 vt0, va0, vc0\n" +
"mul op, vt0, vc4\n";

context3d.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, scaleMatrix);
context3d.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 4, rotationMatrix);
Patrick
  • 15,702
  • 1
  • 39
  • 39
  • 1
    Shouldn't the second instruction be `m44` as well? – Johannes Bittner Jun 10 '11 at 16:01
  • The second instruction should be m44 as well. And, depending on how you build your matrices, you probably want to set the last "transpose" parameter of setProgramConstantsFromMatrix to true in most cases. – starmole Aug 29 '11 at 08:29