Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Mixing Fluids
#39
(25-08-2022, 08:49 AM)khanx078 Wrote: I have a total of 2 colliders in the scene ( both mesh colliders with obi colliders) and an obi rigid body, the number of particles is 3000 in total, currently the scene is a simple bucket in which 2 colors are poured( 2 emitters) then with the help of a mixer ( which has a collider) I mix those colors to get a new one

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

Quote:The benefit [of MeshColliders] is that you can make the shape of the Collider exactly the same as the shape of the visible Mesh for the GameObject, which creates more precise and authentic collisions. However, this precision comes with a higher processing overhead than collisions involving primitive colliders (such as Sphere, Box, and Capsule), so it is best to use Mesh Colliders sparingly.

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).
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