# 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.

## 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 on other sites

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 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 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 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 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 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 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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634046
• Total Posts
3015219
×