Unity-Technologies / Unity-Technologies/Unity.Mathematics
Performance convert Matrix4x4 into float4x4
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 1.4k
- Forks
- 159
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by searching the Unity.Mathematics source for the implicit operator float4x4(Matrix4x4 m) entry point and inspect the reverse float4x4-to-Matrix4x4 cast mentioned in the issue. Compare the conversion paths and verify that all matrix elements are preserved without the current column-based construction; done means the optimized conversion remains equivalent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, unity
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100