fluidSim
A fluid the engine solves every frame.
fluidSim<TParams>(build: (params: GpuFragmentParams, root: FluidRoot) => FluidSimConfig<TParams>): {compute: GpuComputeNode}
Import sim from shaders/std and use sim.fluids.fluidSim.
Spread it into a definition next to a gpu.fragment that samples the output texture under output.key.
The build callback runs once per instance of the layer, with the GPU device, and returns the grid size, the solver, the output pass, the parts and the values function. Everything created inside it belongs to that instance. Without a GPU nothing runs and the fragment should fall back to transparent.
Parameters
| Name | Type | Notes |
|---|---|---|
build | (params: GpuFragmentParams, root: FluidRoot) => FluidSimConfig<TParams> |
Example
...fluidSim(() => ({resolution: 256, layout: fluidLayout, outputLayout, paramsSchema: FluidParams, solver: {kernels: solverKernels, jacobiIters: 10}, output: {kernel: outputKernel, key: 'smokeTexture'}, pointer: {minDrag: 0.0005}, inject: [splat({kernel: splatKernel})], values: (f) => ({dt: f.dt, emitX: 0.5 * 256, emitY: 256, emitRad: f.num('emitRadius', 0.06) * 256, dyeFade: f.num('dissipation', 1), velFade: 0.2, curlStrength: f.num('detail', 30), colorDecay: 1})}))
Tip. Positions and radii in
valuesare in grid cells, not uv: multiply a uv value byresolution.
See also
splat— An emitter at a fixed source: one pass per frame that adds dye and momentum where your pass function says (a cone from a point, a line along an edge).cursorRibbon— An emitter that paints along the pointer's stroke: a ribbon of stamps between last frame's position and this one, so a fast flick leaves a continuous line, not dots.seededFieldInit— A field that starts full: seed it from a pass function, then run the solve silentlywarm.stepstimes so the first visible frame already flows.ambientForce— A force applied to the whole field before every solve: a turbulence field, a steady wind.restoreToward— A correction applied after every solve: re-seed a color that the solve slowly blurs away.simulate— Declare a simulation the engine runs for you.