Color legend method
The layout the solver and a renderer share: one particle, the grid’s size, the texture coordinates and the packed normal. No buffers, since the solver and a renderer bind different ones.
An HLSL header, copied by the package into your content at Content/Effects/Fabric/FabricParticle.fxh on every build, and refreshed every build too, so an edit made to it in place is lost at the next one. A shader that draws the cloth includes FabricParticleBuffer.fxh, which includes this one and adds the buffer to read; include this one directly only for the struct without the binding, as the solver does. 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.
Functions
FabricOctahedronWrap() →
float2 FabricOctahedronWrap(float2 v) · Folds a point of the octahedron’s lower half out over the square’s corners, (1 - abs(v.yx)) with the signs of v: the step FabricPackNormal and FabricUnpackNormal share for normals that face away from +Z. A helper of the two.
| Parameter | Type | Description |
|---|---|---|
v |
float2 |
The normal’s X and Y, after dividing it by the sum of its components’ sizes. |
FabricPackNormal() →
uint FabricPackNormal(float3 normal) · A direction in four bytes, as PreviousNormal holds it: folded onto an octahedron, then 16 bits a side, X in the low half and Y in the high, which is finer than a hundredth of a degree. The solver packs with it; FabricParticle.PackNormal is its twin in C#, bit for bit.
| Parameter | Type | Description |
|---|---|---|
normal |
float3 |
The direction; it needn’t be of length 1. |
FabricTextureCoordinates() →
float2 FabricTextureCoordinates(uint vertexId) · A particle’s texture coordinate, from its place in the grid: U from 0 at column 0 to 1 at the last column, V flipped, from 1 at row 0 to 0 at the top row, so row 0, the free edge of a hanging sheet, is the bottom of the texture. Index-space, so neither Orientation nor Rotation changes it, and a stretched or folded sheet keeps its texture where it was woven. Reads FabricWidthInParticles and FabricHeightInParticles, so bind them. For particles only: a cut mesh’s lip vertex carries its own, in FabricSeamVertex.TexCoord.
| Parameter | Type | Description |
|---|---|---|
vertexId |
uint |
The particle’s index, row by row from row 0: what SV_VertexID is when the plain triangle list is drawn. |
FabricUnpackNormal() →
float3 FabricUnpackNormal(uint packed) · The direction FabricPackNormal packed, of length 1. FabricInterpolatedNormal reads PreviousNormal with it; FabricParticle.UnpackNormal is its twin in C#.
| Parameter | Type | Description |
|---|---|---|
packed |
uint |
Four bytes from FabricPackNormal. |
Defines
FabricShaderContractVersion →
3 · The version of the contract between the headers and the assembly, which must equal FabricParticle.ShaderContractVersion. It moves for any change of shape, a field added, removed, reordered or resized, a grid name renamed or the texture coordinates laid out differently, and for any new input the solver needs from the assembly, which a mismatched pair would silently miss; a byte count can’t catch a reorder, as both sides still measure 64 bytes. The FabricEffect constructor reads it from the copy in your content and throws InvalidOperationException when it differs, or is missing, since a header without it is older than the contract. Best effort: it walks up from the executable looking for Content/Effects/Fabric/, and a deployment that kept only the compiled shader has nothing to compare and isn’t failed for it.
Uniforms
FabricHeightInParticles →
uint · The grid’s rows. On your own effect, set it every frame from Fabric.HeightInParticles, the sheet as built, which the settings may run ahead of. The solver’s copy is set by SetParticles; never set it on the solver’s effect, which would break the solve.
FabricWidthInParticles →
uint · The grid’s columns, the points across. Set it every frame from Fabric.WidthInParticles, as above. A vertex id’s column and row are worked out from it, and with the height the particle count that tells FabricEvaluateVertex a particle from a lip vertex.
Structs
FabricParticle →
float3 PrevPosition; float3 Position; float3 Normal; uint AnchorIndex; float MaxAnchorDistance; float3 RestAngles; uint IsPinned; uint PreviousNormal; · The twin of FabricParticle, field for field, 64 bytes. Lean, since every pass streams the whole grid: the velocity is the gap from PrevPosition to Position, and the texture coordinates follow from the index. A renderer reads Position and Normal, and to draw between steps PrevPosition, PreviousNormal and IsPinned as well.