Jump to content
  • Advertisement
Sign in to follow this  
magicstix

[DX 11] XNA Matrices and transpose

This topic is 2562 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

Sorry if this question has been asked before, but I didn't see it in the FAQs or the first 5 pages of forum topics, but I've noticed in the D3D11 tutorials, when they set a constant buffer to an XNA generated matrix, they always transpose it first. Does anyone know the reasoning behind this? My understanding was D3D matrices were row major, so that (0,0) is the top left entry in the matrix, and (3,3) is the bottom right. Is HLSL supposed to be different?

The reason I'm asking is because I'm seeing oddities pop up when working with boost ublas matrices, which are also row-major, and converting them to their D3D counterparts.

Share this post


Link to post
Share on other sites
Advertisement
HLSL (and GLSL) use column major storage by default. When compiling HLSL shaders, you can override this default to be row-major if you wanted to (e.g. via a command-line switch in FXC).

Also, when writing HLSL code, you can use the [font="Courier New"]row_major[/font] and [font="Courier New"]column_major[/font] prefix keywords to specify the storage layout on a per-variable basis, if for some reason you wanted to use both storage conventions within the one shader.

N.B. regardless of whether you're using row-major or column-major storage, [0,0] is the top left, [3,3] is the bottom right, and [0,3] is the top right. The difference is that with row-major, [0,3] is the 4th item in memory whereas in column-major it's the 13th item.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!