forked from Dynamitos/Seele
More fluid simulation settings
This commit is contained in:
1 parent
b1004d5c80
commit
f2a3f59ab1
5 files changed
+221
-19
No files matched your search
@@ -0,0 +1,68 @@
|
||||
import FluidGridData;
|
||||
|
||||
// Diagnostics-only: sums the interior of several fields so we can watch
|
||||
// "mass" over time on the CPU. Not part of the simulation.
|
||||
struct Params
|
||||
{
|
||||
// read-only
|
||||
FluidGridData<float> density;
|
||||
FluidGridData<float> phi;
|
||||
FluidGridData<float> velocityX;
|
||||
FluidGridData<float> velocityY;
|
||||
FluidGridData<float> velocityZ;
|
||||
// read-write: [0]=density sum, [1]=phi sum, [2]=|velocity| sum
|
||||
RWStructuredBuffer<float> out;
|
||||
};
|
||||
ParameterBlock<Params> params;
|
||||
|
||||
// Reduce the 32x8 thread group via shared memory, then one atomic add per group.
|
||||
groupshared float laneD[256];
|
||||
groupshared float laneP[256];
|
||||
groupshared float laneV[256];
|
||||
// One thread group per z-slice; each thread covers a 32x8 tile of the x/y plane.
|
||||
[numthreads(32, 8, 1)]
|
||||
[shader("compute")]
|
||||
void massProbe(uint3 dispatchThreadID : SV_DispatchThreadID)
|
||||
{
|
||||
FluidGridData<float> density = params.density;
|
||||
FluidGridData<float> phi = params.phi;
|
||||
FluidGridData<float> velocityX = params.velocityX;
|
||||
FluidGridData<float> velocityY = params.velocityY;
|
||||
FluidGridData<float> velocityZ = params.velocityZ;
|
||||
RWStructuredBuffer<float> out = params.out;
|
||||
|
||||
// Interior only: skip the 1-cell boundary shell (matches the other passes).
|
||||
int x = dispatchThreadID.x + 1;
|
||||
int y = dispatchThreadID.y + 1;
|
||||
int z = dispatchThreadID.z + 1;
|
||||
if (x >= gridParams.gridSize.x - 1 || y >= gridParams.gridSize.y - 1 || z >= gridParams.gridSize.z - 1)
|
||||
return;
|
||||
|
||||
float dSum = density[x, y, z];
|
||||
float pSum = phi[x, y, z];
|
||||
float vSum = sqrt(velocityX[x, y, z] * velocityX[x, y, z] +
|
||||
velocityY[x, y, z] * velocityY[x, y, z] +
|
||||
velocityZ[x, y, z] * velocityZ[x, y, z]);
|
||||
|
||||
|
||||
uint lane = dispatchThreadID.x + dispatchThreadID.y * 32; // 0..255
|
||||
laneD[lane] = dSum;
|
||||
laneP[lane] = pSum;
|
||||
laneV[lane] = vSum;
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
// Lane 0 of the group sums all 256 lanes and atomically adds to the global total.
|
||||
if (lane == 0)
|
||||
{
|
||||
float td = 0.0f, tp = 0.0f, tv = 0.0f;
|
||||
for (uint i = 0; i < 256; ++i)
|
||||
{
|
||||
td += laneD[i];
|
||||
tp += laneP[i];
|
||||
tv += laneV[i];
|
||||
}
|
||||
InterlockedAdd(out[0], td);
|
||||
InterlockedAdd(out[1], tp);
|
||||
InterlockedAdd(out[2], tv);
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,14 @@ void setBound(uint3 dispatchThreadID : SV_DispatchThreadID)
|
||||
|
||||
if (numAffecting > 0)
|
||||
{
|
||||
// For all quantities (velocity components AND scalars: pressure,
|
||||
// divergence, density) the boundary cell takes the (factor-scaled)
|
||||
// interior neighbor value. For scalars the factor is 1 (Neumann / copy),
|
||||
// which is the correct boundary condition for the pressure Poisson solve
|
||||
// (zero normal gradient) and for the divergence. Do NOT zero the scalar
|
||||
// boundary: zeroing the pressure shell breaks the Poisson Neumann
|
||||
// condition, corrupts the projection, and injects energy into the
|
||||
// velocity field (observed as |vel|_sum runaway).
|
||||
grid[uint3(pos)] = valueSum / float(numAffecting);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user