bepu / bepuphysics2

Pure C# 3D real time physics simulation library, now with a higher version number.
Apache License 2.0
2.25k stars 261 forks source link

BepuUtilities: Implementation for Matrix4x4Wide? #323

Closed BlueCyro closed 2 months ago

BlueCyro commented 2 months ago

Hi, I'm a real big fan of this library particularly for the amount of consideration put into optimizing not just the written code, but the considerations for the quality of the JIT output as well.

I'm working on a software rasterizer - your typical good exercise in optimization and learning - and I find the "wide" variants of System.Numerics types in this library to be quite useful. I realize this is rather off topic considering the scope of this repository, but BepuUtilities is in and of itself a useful library outside of physics.

I'm particularly looking to vectorize a large part of my pipeline so I can transform a gigachad huge amount of triangles at once, but found that there's no wide analog for Vector3.Transform(Matrix4x4 matrix) for the Vector3Wide, and there seems to only be a Matrix3x3Wide which as I understand doesn't let you describe full transforms like screen projection requires.

I realize I could potentially implement this myself in the meantime, but I found it rather curious why there's no such thing in the library by default. Is it simply because describing such a matrix in a wide fashion is a rather huge chunk of data? In any case, I hope my somewhat niche use-case of BepuUtilities is worthy of being a valid issue. :p

RossNordby commented 2 months ago

Not much justification for its nonexistence; turns out, nothing in bepuphysics2 required it! My usual policy was to avoid including something unless it had a specific and direct need. All the non-constraint use cases top out at 3x3, and while constraints go up to 6DOF in some cases, they use a symmetric representation (e.g. Symmetric6x6Wide).

BlueCyro commented 2 months ago

Can't fault you for a fairly pragmatic policy, especially for a library designed primarily for the physics engine and not vectorized software rasterizer pipelines ;)c

I ended up mostly creating a carbon copy based on the 3x3 implementation and .NET's transform math anyhow so I can perspective project delicious Vector3Wide triangle points. I'm kinda trying to take a page out of your book to make this software rasterizer at least semi-practical. Who needs GPUs when you have w i d e math?

Anyhow though, thanks for the quick answer. ^^