Unity-Technologies / Unity.Mathematics

The C# math library used in Unity providing vector types and math functions with a shader like syntax
Other
1.38k stars 156 forks source link

Performance convert Matrix4x4 into float4x4 #223

Open YomYomNuts opened 2 years ago

YomYomNuts commented 2 years ago

I spot a little improve to convert Matrix4x4 into float4x4 In the current version: public static implicit operator float4x4(Matrix4x4 m) { return new float4x4(m.GetColumn(0), m.GetColumn(1), m.GetColumn(2), m.GetColumn(3)); } My suggestion: public static implicit operator float4x4(Matrix4x4 m) { return new float4x4(m.m00, m.m01, m.m02, m.m03, m.m10, m.m11, m.m12, m.m13, m.m20, m.m21, m.m22, m.m23, m.m30, m.m31, m.m32, m.m33); }

In the current version, you call the column to give you an Vector4 that you convert by an implicit cast into a float4. For the construction, that's not very efficient, i think it's because you want to use a "mirror" function with the cast float4x4 into Matrix4x4

Guillaume