Advertisement Jump to content
Sign in to follow this  
Hawkblood

HLSL float4x4 vs float3x3

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

I understand that float3x3 and float4x4 are each matrices, but is there a functional difference if I'm just using it as a rotation matrix?

Share this post


Link to post
Share on other sites
Advertisement

No.

For example, in order to transform an tangent space normal to objects space (while applying normal mapping) I use a 3x3 matrix since translation doesn't affect normals (vectors).

Edited by TiagoCosta

Share this post


Link to post
Share on other sites

Oh, I forgot to mention, I will have a uniform scale and translation separately. The only thing I want a 3x3 is for rotation. Will it work?

Share this post


Link to post
Share on other sites

You only need 4x4 matrices if you want to encode translation in it. The rotation and the uniform scaling can be expressed in a 3x3 matrix just fine.

Share this post


Link to post
Share on other sites

The goal is to use as small a format as possible for instancing. The number of instances will only be around 100-200 or so. I'm wondering if I'm thinking too much on this..... Would it be worth it to have a float3x3, float, and a float3 for rotation, scale, and location, respectively, and then do 3 separate math computations in the shader (to save space)? Or would it be better to sacrifice space for speed/simplicity by using a float4x4 with all 3 in it?????

Edited by Hawkblood

Share this post


Link to post
Share on other sites
A float3 for the rotation (as a quaternion's imaginary part, with the convention that the real part is positive), a float for the scale and a float3 for translation is all you really need, if you really want your format to be as small as possible.

Share this post


Link to post
Share on other sites

I haven't yet tried any of this because I want to get as much info as possible so I can "do it right". If I used your suggestion, how would I change the float3 into some type of rotation matrix? Would it be a float3x3 with [0,0] for x axis, [1,1] for y axis, and [2,2] for z axis? I don't actually know how to set it up.....

 

And the question remains, would I be sacrificing speed for a smaller size?

Share this post


Link to post
Share on other sites

I haven't yet tried any of this because I want to get as much info as possible so I can "do it right". If I used your suggestion, how would I change the float3 into some type of rotation matrix? Would it be a float3x3 with [0,0] for x axis, [1,1] for y axis, and [2,2] for z axis? I don't actually know how to set it up.....

 

And the question remains, would I be sacrificing speed for a smaller size?

Look up quaternion <-> matrix conversions, or how to set up transformations directly as quaternions. It's easier to start with float4 and then apply the float3 optimization later.

 

As for speed, it depends on your bottleneck. If you've got ALU to spare but bandwidth or interpolators are a problem, you win from the conversion. This is probably the case for instancing.

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!