Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug / Crash  Fluid ignores colliders on certain amount of particles (compute backend)
#1
First off, I just want to say how amazing Obi Fluid is! I've had so much fun creating various liquids for my projects—huge thanks for the fantastic work. Keep it up!  Sonrisa

The Issue:
I initially ran into an issue with the compute backend struggling when handling a large number of colliders in the scene. The fluid wouldn't collide with anything, but I found a fix on the forum by adjusting:
Code:
#define MAX_CONTACTS_PER_SIMPLEX 32 → 512
This resolved the problem, but only up to a certain number of particles.

My Setup:
  • Colliders: ~150 (mostly Box Colliders), positioned close together.
  • Fluid Resolution: 3
  • Particle Count: Around 185k particles—at this point, the fluid starts ignoring colliders and becomes jittery.
The Problems:
  1. Instability at High Particle Count
    • Even with a high-end GPU, the compute backend becomes unpredictable when the particle count increases.
    • Reducing the resolution only delays the breaking point.
  2. Collisions Causing Jitter
    • The fluid behaves erratically when colliding with many objects, even with particle count around 100k.
    • This jitteriness leads to excessive foam generation.
Example Demos:
  1. Jittering Fluid at High Particle Count 
    demo
  2. Fluid Passing Through Multiple Colliders
    demo
Would love any insights on improving stability and handling high particle counts effectively. Thanks in advance! ?
Reply
#2
(17-02-2025, 03:00 PM)JulijaF Wrote: I initially ran into an issue with the compute backend struggling when handling a large number of colliders in the scene. The fluid wouldn't collide with anything, but I found a fix on the forum by adjusting:
Code:
#define MAX_CONTACTS_PER_SIMPLEX 32 → 512
This resolved the problem, but only up to a certain number of particles.

Hi there!

The problem is not the total amount of colliders in your scene, but the total amount of colliders near the same area. The reason for this is that it is not possible for a GPU to allocate memory dynamically, so memory for a maximum amount of colliders per voxel must be preallocated. This is hardcoded as 32 as you found out, you can increase it to 512 but this will have an impact on memory and performance.

Even then, there's a hard limit to the amount of simultaneous particle-collider contacts in a scene: 262144. Once this limit is surpassed, any new contacts will begin to be randomly discarded. This limit is established in ComputeColliderWorld.cs

It's not common to have more than 100k particles in a scene as performance starts to become a problem. Only particles near the surface of the fluid collide with anything directly, and when they do each particle usually doesn't collide with more than 2-3 colliders so this limit seemed reasonable.

However based on your videos, it doesn't seem like there's more than 32 colliders per voxel or more than 262k contacts. The fact that one or both limits seems to be reached in your game is maybe an indication of a pathological setup? Would it be possible for you to send an example project to support(at)virtualmethodstudio.com that reproduces this issue, so that we can take a closer look?

kind regards,
Reply
#3
Hi,

Just replied to your email.

For other users that may find this thread, the issue in this case was that colliders were not being disabled when no longer needed but instead were animated to have a size of 0. Unity does not support box colliders of size zero or negative, this lead to a large amount of warnings in the console and bad performance. Furthermore, contacts against these boxes were still being calculated and counting towards the limit of 266k contacts, even though none of them were actually progressing to collisions.

Also, 6 box colliders spanning the entire screen were used to keep the fluid inside a box, instead of a single inverted box collider. This also contributed towards generating a high amount of contacts.

Solving both problems greatly reduced the amount of contacts and allowed for more fluid particles to be used before missing collisions started to become a problem. Even then, this could be further optimized by batching together multiple blocks into larger colliders instead of having 1 collider per block.

kind regards,
Reply