# Get row from HLSL/GLSL matrix

This topic is 1331 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all,

I have a compute shader which needs the row of a matrix, I use column major (translation in the last column).

The problem is when you do Matrix[0] you have the float4/vec4 of the first column not the row.

Does a way exists to get the row without access each value of the matrix to set the vector ?

I have a constant/uniform buffer which is updated each frame with the projection in it, I want to reuse it, not send a transposed matrix.

Thanks

Edited by Alundra

##### Share on other sites

While there's no "get row" function, in HLSL you can swizzle a matrix.  So, you could do something like this:

float4 vecVar = matVar._m00_m01_m02_m03;

If your goal is to get away from piece-wise setting a vector from a matrix, that can work.  You can find a lot more information about matrix member access and swizzling in HLSL here.  This would seem to indicate that you cannot do a similar operation in GLSL, but I'm not nearly as familiar with OpenGL so someone with more experience might be able to tell you otherwise.

Edited by MattSutherlin

##### Share on other sites

Thanks, I didn't knew that way in HLSL.

About GLSL then I saw : "Swizzling does not work with matrices.", https://www.opengl.org/wiki/Data_Type_(GLSL)#Matrices

But that is not a problem, if you convert HLSL to GLSL using binary HLSL that works very good.

Edited by Alundra

##### Share on other sites

float4 vecVar = matVar._m00_m01_m02_m03;

I believe so much that this compiles to much likely this:

float4 vecVar = float4(matVar[0],matVar[4],matVar[8],matVar[12]);

But why on earth you want to avoid performing this?

##### Share on other sites

It's nice to know HLSL allows that but I have updated to use directly the column to get value because it's more readable at the end :

float3 Row0 = float3( Projection[ 0 ].x, Projection[ 1 ].x, Projection[ 2 ].x );

• 10
• 17
• 9
• 14
• 41
• ### Forum Statistics

• Total Topics
631067
• Total Posts
2997734
×