Jump to content
  • Advertisement
Sign in to follow this  
Alundra

Get row from HLSL/GLSL matrix

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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 );

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!