Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Mixing Fluids
#40
(25-08-2022, 09:44 AM)josemendez Wrote: MeshColliders are by far the most expensive type of collider. They get more expensive the more triangles they have, and the smaller the triangles are in comparison to the objects colliding against it. They get even more expensive if they're dynamic, and even more if they're concave.

To understand why this is the case: somehow, each object in the scene (in Obi's case, the fluid particles) must collide against all triangles in each MeshCollider. In your screenshot with only the bucket visible, Unity reports +60000 triangles being rendered. A brute force approach (test all particles against all triangles) against 60000 triangles would result in 60000x3000 = 180 million particle/triangle intersection tests per simulation step, and there's usually more than 1 simulation step per frame. This is intractable even for simple scenes.

So usually, the brute force approach is not used: a spatial subdivision approach is used to quickly prune triangles and cut down the amount of tests. Obi uses a BIH (bounding interval hierarchy) for this. At startup, all triangles in each MeshCollider is inserted into this structure, at runtime particles traverse it to cut down the number of tests to only the triangles that are close enough to each particle. However the smaller the triangles are, the more triangles each particle needs to test regardless. In a detailed MeshCollider, this can mean 10-20 tests per particle, which is still an awful amount of work for such a complex collider.

The takeaway message is that MeshColliders should only be used for low-poly objects, and even then they should be used sparingly. This applies not just to Obi, but to games in general, and those made with Unity in particular: https://docs.unity3d.com/Manual/class-MeshCollider.html


Obi offers a much faster alternative to MeshColliders: signed distance fields. The cost of colliding against SDFs is comparable to a primitive collider (box, sphere or capsule).

My advice would be to replace both your MeshColliders with distance fields, or with compound colliders made of primitives (boxes/capsules).
So i created the distance fields and the frame rate was hardly improved its went from 30 to around 37 but drops down abruptly to 27 Huh I have attached the profiler


Attached Files Thumbnail(s)
       
Reply


Messages In This Thread
Mixing Fluids - by canaydiin - 28-03-2022, 12:00 PM
RE: Mixing Fluids - by josemendez - 28-03-2022, 12:15 PM
RE: Mixing Fluids - by canaydiin - 28-03-2022, 01:14 PM
RE: Mixing Fluids - by josemendez - 28-03-2022, 02:49 PM
RE: Mixing Fluids - by canaydiin - 28-03-2022, 10:20 PM
RE: Mixing Fluids - by josemendez - 29-03-2022, 07:31 AM
RE: Mixing Fluids - by canaydiin - 29-03-2022, 01:48 PM
RE: Mixing Fluids - by josemendez - 29-03-2022, 02:18 PM
RE: Mixing Fluids - by canaydiin - 29-03-2022, 02:53 PM
RE: Mixing Fluids - by josemendez - 29-03-2022, 02:59 PM
RE: Mixing Fluids - by canaydiin - 30-03-2022, 07:29 AM
RE: Mixing Fluids - by josemendez - 30-03-2022, 07:45 AM
RE: Mixing Fluids - by canaydiin - 30-03-2022, 07:51 AM
RE: Mixing Fluids - by josemendez - 30-03-2022, 08:13 AM
RE: Mixing Fluids - by canaydiin - 30-03-2022, 08:22 AM
RE: Mixing Fluids - by josemendez - 30-03-2022, 08:24 AM
RE: Mixing Fluids - by canaydiin - 30-03-2022, 08:33 AM
RE: Mixing Fluids - by josemendez - 30-03-2022, 09:12 AM
RE: Mixing Fluids - by canaydiin - 30-03-2022, 09:15 AM
RE: Mixing Fluids - by josemendez - 30-03-2022, 09:18 AM
RE: Mixing Fluids - by khanx078 - 23-08-2022, 10:21 AM
RE: Mixing Fluids - by josemendez - 23-08-2022, 04:56 PM
RE: Mixing Fluids - by khanx078 - 24-08-2022, 04:53 AM
RE: Mixing Fluids - by josemendez - 24-08-2022, 07:32 AM
RE: Mixing Fluids - by khanx078 - 24-08-2022, 08:51 AM
RE: Mixing Fluids - by josemendez - 24-08-2022, 10:18 AM
RE: Mixing Fluids - by khanx078 - 24-08-2022, 12:22 PM
RE: Mixing Fluids - by josemendez - 24-08-2022, 12:50 PM
RE: Mixing Fluids - by khanx078 - 24-08-2022, 01:10 PM
RE: Mixing Fluids - by josemendez - 24-08-2022, 01:39 PM
RE: Mixing Fluids - by khanx078 - 25-08-2022, 03:33 AM
RE: Mixing Fluids - by josemendez - 25-08-2022, 07:57 AM
RE: Mixing Fluids - by khanx078 - 25-08-2022, 08:49 AM
RE: Mixing Fluids - by josemendez - 25-08-2022, 09:44 AM
RE: Mixing Fluids - by khanx078 - 25-08-2022, 10:05 AM
RE: Mixing Fluids - by josemendez - 25-08-2022, 10:23 AM
RE: Mixing Fluids - by khanx078 - 25-08-2022, 10:35 AM
RE: Mixing Fluids - by josemendez - 25-08-2022, 11:04 AM
RE: Mixing Fluids - by khanx078 - 25-08-2022, 11:35 AM
RE: Mixing Fluids - by josemendez - 25-08-2022, 11:57 AM
RE: Mixing Fluids - by khanx078 - 25-08-2022, 12:07 PM
RE: Mixing Fluids - by josemendez - 25-08-2022, 12:11 PM