Search code examples
matrixdirect3dhlsl

Accessing members of a matrix in HLSL


I am a bit new to using Direct3D and HLSL and I was wondering about the following: How would one access a member of a matrix in one of the shader functions. It seems to me that it should be the dot operator and some stuff after that just as with the vectors. However, I am not exactly sure what I would put down after the dot if I were to use it. Would it be something like .m12 to access the member of the 2nd row and 3rd column?


Solution

  • Assuming you matrix is

    float4x4 myTransform;
    

    You can access members 1-based (eg m11 to m44) like :

    float member = myTransform._11;
    float member = myTransform._44;
    

    or zero based as:

    float member = myTransform._m00;
    float member = myTransform._m33;