The solver as a host sees it: the effect FabricEffect loads and dispatches, the two names an effect of your own defines to change it, and the names a wind function of yours can read.
An HLSL effect, copied by the package into your content at Content/Effects/Fabric/FabricCompute.fx on every build with the header that holds its body, FabricSimulation.fxh, and built by the package’s own response file, Content/BorrowedTorch.FabricSimulator.mgcb, into Content/Effects/Fabric/FabricCompute.xnb: FabricEffect.DefaultEffectPath for a ContentManager rooted at Content. Every build refreshes the copies, so an edit made in place is lost at the next one. To change the solver, wrap it rather than edit it: an .fx of your own in Content/Effects that defines what it needs, includes "Fabric/FabricCompute.fx", adds anything after, and is built by your own Content.mgcb; load it by its path, as the third argument of the FabricEffect constructor. Without anything defined, the solver compiles exactly as shipped. The wind page shows it in context, with code.
Defines
ContactCandidateCapacity →
32 · The self-collision partners a particle keeps per step, gathered once a step and tested in every round that solves contacts; in FabricSimulation.fxh. Must equal FabricEffect.ContactCandidateCapacity: the FabricEffect constructor reads it from the copy in your content and throws InvalidOperationException when it differs. A pile crushed hard enough to want more loses partners for that step, which SampleSpatialHashOverflow reports.
FABRIC_COUNT_COINCIDENT →
Not defined by the package. Define it, to anything, before the include in an effect of your own, and the solver counts the contacts between particles it finds at the same point with no history to tell them apart, which it pushes apart along an axis picked from their indices, a guess that can swap two layers. FabricEffect.SampleCoincidentContacts reads the count, and reads zero without it. Off by default because the count costs an atomic in the innermost contact loop.
#define FABRIC_COUNT_COINCIDENT
#include "Fabric/FabricCompute.fx"
FABRIC_WIND_AT →
Not defined by the package. The name of a wind function of yours, float3 f(float3 position): air that varies across the sheet. The solver calls it every step for every particle that isn’t pinned, at the particle’s world position as the step begins, and takes the answer as the air’s velocity there, in meters per second, where it would otherwise take Wind. Declare the function before the include, define the name, include the solver, then define the function after it, where Wind and FabricTime are in scope. An answer that isn’t finite falls back to Wind, since one NaN would spread through the whole sheet within a few steps. The function’s own uniforms are set through FabricEffect.Shader, the sheet’s own copy of the effect, not the instance Content.Load returns. Each formula is a solver of its own, compiled with your content, so changing one is a content rebuild.
// Content/Effects/ClothSolver.fx
float3 GustBands(float3 position); // declared before the solver, defined after it
#define FABRIC_WIND_AT GustBands
#include "Fabric/FabricCompute.fx"
float GustStrength; // set through FabricEffect.Shader
float3 GustBands(float3 position)
{
float band = saturate(sin(position.x * 1.5 - FabricTime * 2.5));
return Wind * (1.0 + GustStrength * band * band);
}
GroupSize →
256 · Threads per group of every kernel, one per particle; in FabricSimulation.fxh. Must equal FabricEffect.ComputeGroupSize, or each dispatch covers only part of the sheet: the FabricEffect constructor reads it from the copy in your content and throws InvalidOperationException when it differs.
Uniforms
FabricTime →
float · Simulated seconds since the sheet was uploaded, set before every step: FabricEffect.Time. A clock for a wind function, which follows the cloth rather than the frame when the solver falls behind.
Wind →
float3 · The air’s velocity, in meters per second, from FabricSettings.Wind, uploaded with the other settings at every Apply, so at every Fabric.Update. Not a force: drag acts on the cloth’s motion relative to it. The whole sheet feels it unless a FABRIC_WIND_AT function answers instead, which can read it, to scale its own air by what the host set this frame, so still air stays still.
Technique
FabricTechnique →
technique · The solver’s eight compute passes, cs_5_0, which FabricEffect.Step dispatches by name, one thread per particle, in this order:
IntegratePass: pins, normals, plasticity, forces and the Verlet step.ReducePressurePassandApplyPressurePass, withUseAerodynamicPressureon: the reduce once per level of the pressure pyramid, then the apply.ClearSpatialHashPass,BuildSpatialHashPassandGatherCandidatesPass, withUseSelfCollisionon: the hash rebuilt, then each particle’s contact partners gathered once for the step.- Then the constraint rounds,
ConstraintsPassonce per round, each round that solves bending preceded byBendPass, which solves every fold once for the round to gather.
A wrapping effect keeps the technique and every pass: the FabricEffect constructor throws InvalidOperationException when the effect it loads has no FabricTechnique, or lacks one of the passes, as an effect compiled from another release’s solver may.