修改水

This commit is contained in:
2026-01-01 22:00:33 +08:00
parent 040a222bd6
commit 9ceffccd39
1800 changed files with 103929 additions and 139495 deletions

View File

@@ -26,42 +26,25 @@ namespace Obi
[ReadOnly] public float velocityScale;
[ReadOnly] public float sleepThreshold;
[ReadOnly] public float maxVelocity;
[ReadOnly] public float maxAngularVelocity;
// The code actually running on the job
public void Execute(int index)
{
int i = activeParticles[index];
float4 velocity = velocities[i];
float4 angVelocity = angularVelocities[i];
// damp velocities:
velocity *= velocityScale;
angVelocity.xyz *= velocityScale;
// clamp velocities:
float velMagnitude = math.length(velocity);
float angularVelMagnitude = math.length(angVelocity.xyz);
if (velMagnitude > BurstMath.epsilon)
velocity *= math.min(maxVelocity, velMagnitude) / velMagnitude;
if (angularVelMagnitude > BurstMath.epsilon)
angVelocity.xyz *= math.min(maxAngularVelocity, angularVelMagnitude) / angularVelMagnitude;
velocities[i] *= velocityScale;
angularVelocities[i] *= velocityScale;
// if the kinetic energy is below the sleep threshold, keep the particle at its previous position.
if (velMagnitude * velMagnitude * 0.5f + angularVelMagnitude * angularVelMagnitude * 0.5f <= sleepThreshold)
if (math.lengthsq(velocities[i]) * 0.5f + math.lengthsq(angularVelocities[i]) * 0.5f <= sleepThreshold)
{
positions[i] = previousPositions[i];
orientations[i] = previousOrientations[i];
velocity = float4.zero;
angVelocity.xyz = float3.zero;
velocities[i] = float4.zero;
angularVelocities[i] = float4.zero;
}
velocities[i] = velocity;
angularVelocities[i] = angVelocity;
}
}
}