Docs / Fabric simulation

Glossary: FabricParticle

The members of FabricParticle, in alphabetical order.

Color legend method

One point of the sheet as the solver stores it, 64 bytes. Lean, because every pass streams the whole grid: nothing that follows from the rest, such as the velocity or the texture coordinates, is stored.

A struct of public fields, in the namespace BorrowedTorch.FabricSimulator.Simulation, laid out in sequence and mirrored field for field by FabricParticle on the GPU. ReadBack returns them and SetParticles and UpdateParticles take them, in flat index order; a shader reads them from FabricParticles. The drawing page shows it in context, with code.

Names are colored by what they are: a method; values and fields keep the plain color.

Fields

AnchorIndex →

uint · The pin this point hangs from, as a flat index rather than a position, so a pin that moves is followed. Read only when MaxAnchorDistance is positive. With MaxAnchorDistance and IsPinned, what an upload, SetParticles or UpdateParticles, takes as the pins; the solver writes its own pins back into all three at every step, so a readback shows the pins in force as of the last step, and a SetPinned or a cut reaches the record at the next one.

IsPinned →

uint · Not 0 when the point is pinned: it never moves unless an upload moves it, and the cloth hangs from it. A uint rather than a bool, because HLSL’s bool is four bytes. FabricInterpolatedPosition draws a pin where it is, not between steps.

MaxAnchorDistance →

float · The furthest this point may get from its pin, AnchorIndex, in meters, measured along the weave: the shortest path through the threads, which holds however the pins move. Only pinning other points changes it. 0 for a pin, and negative when no pin reaches the point, through a cut or because nothing is pinned. See UseLongRangeAttachments.

Normal →

Vector3 · The facing of the pose the latest step ended in, of length 1, computed on the GPU at every step; the flat sheet’s facing as built, until the first step. It points one way only, so a shader drawing both sides flips it towards the camera. Shade with it rather than with each triangle’s own, or the shading disagrees with the physics along every crease.

Position →

Vector3 · Where the point is, as of the latest step, in world space: draw it with no world matrix.

PreviousNormal →

uint · The facing of the pose the latest step began in, packed into four bytes by PackNormal: with Normal, what a renderer blends between to draw between two steps, as it blends PrevPosition and Position. FabricInterpolatedNormal does it.

PrevPosition →

Vector3 · Where the point was a step before: the velocity, which isn’t stored, is the gap to Position over one step. A point uploaded with the two apart starts with that motion; keep them equal for a point at rest. A renderer drawing between steps blends from here to Position.

RestAngles →

Vector3 · The rest angles of the three folds this point owns, in radians: X the fold across, Y the fold down, Z the diagonal one. π is flat, and the sign says which way the fold closes. Set from the built shape; plasticity rewrites them, which is how creases stay, see BendingPlasticRate. Run reads them.

ShaderContractVersion →

int · Constant, 3. Must equal FabricShaderContractVersion in FabricParticle.fxh: the FabricEffect constructor checks it, when it can find the header, and throws InvalidOperationException if they differ. Moved on for any change of shape, a field added, removed, reordered or resized, a grid parameter renamed or the texture coordinates laid out differently, and for any new input the solver takes from the assembly: a byte count can’t see two fields swapped.

SizeInBytes →

int · Constant, 64. The size of one record, which must equal the GPU’s stride: SetParticles checks what the struct marshals to against it.

Methods

PackNormal() →

PackNormal(Vector3 normal) · Static. Returns uint: a direction in four bytes, as PreviousNormal holds it: folded onto an octahedron, then 16 bits a side, finer than a hundredth of a degree. Any length will do; a zero vector packs as +Z. Mirrors FabricPackNormal.

Parameter Type Description
normal Vector3 The direction to pack.

UnpackNormal() →

UnpackNormal(uint packed) · Static. Returns Vector3: the direction PackNormal packed, of length 1. Mirrors FabricUnpackNormal.

Parameter Type Description
packed uint A packed direction, such as PreviousNormal.