jrouwe / JoltPhysics

A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West.
MIT License
6.42k stars 414 forks source link

Implemented better algorithm to split soft body constraints into parallel groups #1042

Closed jrouwe closed 5 months ago

jrouwe commented 5 months ago

This makes the soft body simulation 10-20% faster and also enables multithreading LRA, bend and volume constraints.

sonarcloud[bot] commented 5 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
2 Accepted issues

Measures
0 Security Hotspots
69.1% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

mihe commented 4 months ago

I haven't had time to dive into why exactly yet, but just as a heads up, I am seeing some type of regression from this change.

Before:

https://github.com/jrouwe/JoltPhysics/assets/4884246/6dd56b0f-feee-4f89-8afb-930f7ab72997

After:

https://github.com/jrouwe/JoltPhysics/assets/4884246/5bfcb7ec-5fa8-49ec-97bb-348cfd4dff0d

Everything is obviously fine in your samples though, so I'm guessing it's gonna be something funky on my end.

Given that it seems to mostly affect the soft bodies with kinematic vertices I'm guessing it's going to be related to that somehow.

jrouwe commented 4 months ago

Can you give me that scene?

mihe commented 4 months ago

Sure, here it is: SoftBody.zip

I've omitted the addons folder.

You'll see some errors about "undefined behavior for SoftBody3D", but those are unrelated and have been fixed in Godot 4.3.

jrouwe commented 4 months ago

Hmmm, I can reproduce the issue but I have no idea why yet. I'll look at it some more tomorrow.

jrouwe commented 4 months ago

B.t.w. the issue seems to go away if I change:

const float stiffness = MAX(Math::pow(stiffness_coefficient, 3.0f) * 1000000.0f, 0.000001f);

to

const float stiffness = MAX(Math::pow(stiffness_coefficient, 3.0f) * 100000.0f, 0.000001f);

The order of constraint evaluation has changed by the change you mentioned.