flashmatrixvertex-shaderstage3dagal

Can Matrices exist on vertex registers other than vertex constants in AGAL?


I've mostly seen examples where a Matrix3D object is passed as a vertex constant register in AS3 to the Context3D object. But never seen a matrix in any other types of registers (temporary or attribute).

Would there be any way to copy a Matrix vertex constant to a temporary register, and then manipulate individual fields of that Matrix temporary register (ex:for the rotation), with other supplied values (vertex attributes or other constants)?

Could a simple mov dest, source operation do the trick?


Solution

  • Yes, that works (take it from the Mole :)). Just make sure to copy enough (3 or 4) registers. Also a good way to think about matrix operations is that they are just a shortcut for 3 or 4 dot product instructions. There is really nothing typed in AGAL, a matrix is just a few consecutive registers. The matrix upload functions are only convenience for uploading to 4 registers in one call. And in the shader

    m44 dest, src, srcmatrix

    is the exact same as:

    dp4 dest.x srx, srcmatrix  
    dp4 dest.y srx, srcmatrix+1  
    dp4 dest.z srx, srcmatrix+2  
    dp4 dest.w srx, srcmatrix+3
    

    The +1 etc here means register number +1 etc.