Two stability fixes found while rendering surface-fluid frames:
- FluidSimulator::ensureGpu set gpuOk_ only after uploadSdf(), whose guard
early-returned on !gpuOk_, so the GPU SDF buffer was never filled. The
compute kernels then saw an all-zero field: projection used the fallback
normal (0,1,0) and pushed every particle off the model by one particle
radius per frame. Upload now happens after gpuOk_ is set.
- PBF position corrections were unbounded: overlapping particles amplify the
spiky gradient and got flung apart. Both the CPU reference and the GLSL
apply-delta kernel now clamp the correction to 0.05 * support radius.
- Regression guard: fluids.gpu.surfaceFlow asserts particles stay within
|p| < 3 of the model origin (the zero-SDF path drifted to |p| ~ 7).
Phase 3 of the surface fluid simulation:
- Bingham yield stress in the CPU solver and integrate kernel: effective
viscosity grows as local shear rate drops, so mud piles up and freezes
instead of spreading like water.
- FluidSurfaceRenderer: screen-space fluid rendering pipeline (splat depth+
thickness with atomic min/add, bilateral depth smoothing, view-space normal
reconstruction from depth gradients, water/mud shading), mirrored 1:1 in
FluidSsfKernels.h and driven through the gpgpu compute queue with a CPU
fallback and PPM debug output.
- Script API: Fluids.newSurfaceRenderer + FluidSurface (render/setCamera/
setMode/writePpm).
- Design + usage spec under docs/dev/specs.
- Tests: yield-stress freeze, SSF single-particle depth/normal/thickness,
water-vs-mud shading, GPU SSF pipeline with PPM artifact (17 fluids cases).
Phase 2 of the surface fluid simulation:
- PBF density constraint: per-substep lambda/gradient accumulation and
position corrections (3 passes on GPU: density+lambda, delta, apply),
mirrored exactly in the CPU reference solver.
- Akinci-style cohesion kernel (fluid-fluid surface tension) and SDF-based
adhesion (fluid-solid contact), so scattered films pull into droplets and
drops stick to model undersides.
- Script API: setCohesion/setAdhesion/setPbfIterations on FluidSim.
- New tests: compressed-cloud relaxation, cohesion clumping, underside
adhesion, and a GPU PBF+cohesion cluster run (13 fluids cases total).
Phase 1 of the interactive surface fluid simulation:
- New 'fluids' module (LAYER 5, deps gpgpu/graphics), registered in the
module manifest with Squirrel binding (Fluids + FluidSim classes).
- MeshSdf: voxelized signed distance fields (analytic sphere/plane plus a
closed-triangle-mesh baker) with trilinear sampling and gradient queries.
- FluidSimulation: CPU reference solver — uniform-grid neighbor search, SPH
density, XSPH viscosity, gravity, and SDF surface projection so water
sticks to the model and only flows tangentially downhill.
- FluidGpuKernels: GLSL compute kernels (clear/build grid, density,
integrate+project) mirroring the CPU reference 1:1, driven through the
gpgpu module with a CPU fallback.
- Tests: SPH kernels, sphere + triangle-mesh SDFs, CPU surface flow,
viscosity damping, density, module wiring, and a headless GPU surface
flow run (9 cases).