Using Directx11 without using a Microsoft math library

Started by
8 comments, last by tragic 9 years, 11 months ago

So as the title states I want to try to use my own math lib (please don't tell me not to reinvent the wheel i enjoy learning and thats what im doing) with directx11 in place of DirectXMath. It would be greatly appreciated if someone could point me in the right direction or even show how this done.

Advertisement

Direct3D has no special requirements about math libraries you happen to use with it.

In general, when you have calculated something on the CPU side, you send the result to the device in a constant buffer or a texture (or some other buffer types). The system does not care what data goes in there; it is the responsibility of the shaders to load the data and do something meaningful with it.

The shader stages are optimized to work with single-precision floating point numbers (float) so it would be beneficial if a CPU-side math library should be able to output them.

Note that internally, DirectXMath matrices and vectors are just arrays of float values. The library does impose some alignment restrictions to the types in order to leverage accelerated vector processing such as SSE2, but other than that, it is just basic math.

Niko Suni

Yeah D3D doesn't come with a math library so has no requirements really.

The way that you construct your matrices will have an effect on your HLSL code.

By default, matrices in HLSL are stored in column-major element order - e.g. for [column,row], the floats are stored in the order [0,0], [0,1], [0,2], [0,3], [1,0], [1,1], etc....

You can explicitly state the storage convention you want to use by using the appropriate keyword in front of your declaration, like this:

column_major float4x4 myMat;

or

row_major float4x4 myMat;

If you use the column-vector convention in your maths, then you'll write mul(myMat, myVec), otherwise if you're using the row-vector convention you'll write mul(myVec, myMat).

You can also change the default to row-major storage by specifying the /Zpr flag when compiling your shaders. It's probably a good idea to use the same convention for everything across your project.

Visit http://www.mugsgames.com

Stroids, a retro style mini-game for Windows PC. http://barryskellern.itch.io/stroids

Mugs Games on Twitter: [twitter]MugsGames[/twitter] and Facebook: www.facebook.com/mugsgames

Me on Twitter [twitter]BarrySkellern[/twitter]

Yeah D3D doesn't come with a math library so has no requirements really.

The way that you construct your matrices will have an effect on your HLSL code.

By default, matrices in HLSL are stored in column-major element order - e.g. for [column,row], the floats are stored in the order [0,0], [0,1], [0,2], [0,3], [1,0], [1,1], etc....

You can explicitly state the storage convention you want to use by using the appropriate keyword in front of your declaration, like this:

column_major float4x4 myMat;

or

row_major float4x4 myMat;

If you use the column-vector convention in your maths, then you'll write mul(myMat, myVec), otherwise if you're using the row-vector convention you'll write mul(myVec, myMat).

You can also just tell the runtime when compiling your shaders which order to use with a compile flag.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

Or you can write #pragma pack_matrix(row_major/column_major) to set the default storage convention for everything that comes after.

As far as examples, my own engine doesn't use DirectXMath. I based my math classes on the Wild Magic engine by Dave Eberly long ago, and they have evolved a little since then. If you have any specific questions, please be sure to post them and I'm sure there are answers around here!

Sorry for late reply but i have been rather busy recently but anyways thanks for the advice. Good to know that microsoft doesn't lock you into using their stuff and I do plan on using consistent conventions for making changes and use easier. I browsed through a little bit of your engine Jason and looks like a solid place to start learning :).

Thanks - if you have any questions about the engine, feel free to post here or in the codeplex discussion forum. I check both regularly, and I'm always happy to discuss the various design options.

Thanks - if you have any questions about the engine, feel free to post here or in the codeplex discussion forum. I check both regularly, and I'm always happy to discuss the various design options.

For sure thank you!

This topic is closed to new replies.

Advertisement