NAKASSEIN
NAKASSEIN

Reputation: 45

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?

Upvotes: 2

Views: 7143

Answers (2)

Young Kim
Young Kim

Reputation: 41

Adding to catflier's answer. You can also use array subscript syntax (zero based) like you would expect in C++ to get matrix members.

float4x4 myMatrix;
float x = myMatrix[0][1];

Upvotes: 2

mrvux
mrvux

Reputation: 8963

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;

Upvotes: 5

Related Questions