Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting Direction of Increasing Userdata per-particle
#4
Ok, now I understand better what you're trying to do: propagate a direction vector trough all particles using diffusion. Correct?

You seem to be relying on particles in a pair being in a specific order: they aren't, and the same pair might even swap its particles between frames. This is because particle pairs are created in parallel from multiple threads so depending on which thread runs first the order may change. The reason we don't care about this is that fluid interactions are symmetric, all we care about is the difference in data values between them.

This is Obi's code for diffusion:
Code:
float4 userDelta = (userData[pair.particleB] - userData[pair.particleA]) * diffusionSpeed;

// i've removed the volume ratios vA and vB for clarity
userData[pair.particleA] += userDelta;
userData[pair.particleB] -= userDelta;

Imagine userData is 0.3 for one particles and 0.7 for the other, using a diffusionSpeed of 0.5.

If particleB = 0.3 and particleA = 0.7:
userDelta will be -0.4 * 0.5 = -0.2.
particleA will end up with a userData value of 0.7 + (-0.2)  = 0.5
particleB will end up with a userData value of 0.3 - (-0.2) = 0.5

Now swap both particles:

userDelta will be 0.4 * 0.5 = 0.2.
particleA will end up with a userData value of 0.3 + 0.2  = 0.5
particleB will end up with a userData value of 0.7 - 0.2 = 0.5

As you can see, the order in which particles appear in the pair doesn't matter at all for diffusion as we arrive at the same result. The same behavior is true for all other fluid formulas (density, vorticity, viscosity, etc).

However, your formula for calculating the difference in directions does this:
Code:
float4 oneDeltaA2B = dataDelta * math.normalizesafe(distA2B);

dataDelta and distA2B will always have the same sign since they're both calculated by subtracting particleB data from particleA, so they're both either negative or positive. This is a problem when multiplying them together, because (+)*(+) = (+) and (-)*(-) = (+). Since your formula does not preserve the sign of distA2B, oneDeltaA2B will randomly point in the direction of distA2B or the opposite direction depending on particle ordering.

I'm not entirely sure what dataDelta is in your code, as it's a single float value. I assume this is the distance from the pathfinding goal?
Reply


Messages In This Thread
RE: Getting Direction of Increasing Userdata per-particle - by josemendez - 23-11-2023, 12:07 PM