Color legend method
The read side of the solver, for a shader that draws the cloth: the particle buffer, the lip vertices of a cut mesh, and the functions that turn a vertex id into a position, a normal and a texture coordinate, at the latest step or between two.
An HLSL header, copied by the package into your content at Content/Effects/Fabric/FabricParticleBuffer.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 of yours in Content/Effects includes it with #include "Fabric/FabricParticleBuffer.fxh", a path relative to the including .fx, as MGCB resolves includes. It includes FabricParticle.fxh, so the particle struct, the grid sizes and the texture coordinates come with it, and you declare nothing yourself. What a shader doesn’t use compiles away. 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
FabricEvaluateVertex() →
void FabricEvaluateVertex(uint vertexId, float fraction, out float3 position, out float3 normal, out float2 texCoord) · Any vertex id of a cut mesh or of the plain triangle list, at a fraction of the way from the previous step’s pose to the latest. An id below the particle count, FabricWidthInParticles × FabricHeightInParticles, is a particle: its position as FabricInterpolatedPosition gives it, its normal as FabricInterpolatedNormal does, its texture coordinate from FabricTextureCoordinates. An id at or above it is the lip vertex FabricSeamVertices[vertexId - count], blended from its carrier particles, each taken at the same fraction: three by their weights, or two by their weights plus an offset across the cloth along cross(normal, positionB - positionA), see FabricSeamVertex. Its normal is the carriers’ normals blended by the same weights, or the first carrier’s when they cancel out, and its texture coordinate is stored. One vertex shader draws both kinds of mesh alike.
void FabricEvaluateVertex(uint vertexId, out float3 position, out float3 normal, out float2 texCoord) · The latest step exactly: the overload above at a fraction of 1.
| Parameter | Type | Description |
|---|---|---|
vertexId |
uint |
The vertex’s SV_VertexID: an index of FabricCutMesh.Indices or of CreateTriangleIndices’ list. |
fraction |
float |
FabricEffect.InterpolationFraction, bound every frame to a uniform of your own: 0 the previous step’s pose, 1 the latest. |
position |
out float3 |
The vertex in world space: draw it with no world matrix. |
normal |
out float3 |
The solver’s normal, of length 1, facing one way only: flip it toward the camera in the pixel shader. |
texCoord |
out float2 |
Its texture coordinate. |
FabricInterpolatedNormal() →
float3 FabricInterpolatedNormal(FabricParticle p, float fraction) · The particle’s normal, the given fraction of the way from the pose the latest step began in, PreviousNormal unpacked, to the one it ended in, Normal, made length 1 again: shading turns as smoothly as the cloth moves. Exactly Normal at a fraction of 1 or more, and when the two are opposite and blend through zero. Pins’ normals blend too, since they turn with the cloth around them.
| Parameter | Type | Description |
|---|---|---|
p |
FabricParticle |
A record fetched from FabricParticles. |
fraction |
float |
0 the previous step’s pose, 1 the latest. |
FabricInterpolatedPosition() →
float3 FabricInterpolatedPosition(FabricParticle p, float fraction) · The particle’s position, the given fraction of the way from PrevPosition to Position: for a renderer that fetches particles itself rather than through FabricEvaluateVertex. Exactly Position at a fraction of 1 or more. A pin is always drawn at Position, where it is: a host that moves one between steps moves it at once.
| Parameter | Type | Description |
|---|---|---|
p |
FabricParticle |
A record fetched from FabricParticles. |
fraction |
float |
0 the previous step’s pose, 1 the latest. |
Buffers
FabricParticles →
StructuredBuffer<FabricParticle> · The sheet’s particles, indexed by vertex id. Bind FabricEffect.ParticleBuffer to it on your effect every frame: the solver keeps two record buffers and swaps them as it steps, and SetParticles replaces them. Read-only on purpose: the solver binds the same memory for writing, and a resource bound for reading and writing at once silently binds nothing. The solver’s own effect declares no FabricParticles, so the parameter is null there.
FabricSeamVertices →
StructuredBuffer<FabricSeamVertex> · The lip vertices of the cut mesh being drawn, FabricCutMesh.SeamVertices uploaded to a structured buffer of your own. Bind it every frame when a shader evaluates vertices with FabricEvaluateVertex, and keep it at least one element long on whole cloth too: the shader declares it, so a real resource has to sit behind the binding. Unused by a shader that fetches only particles, and compiled away there.
Structs
FabricSeamVertex →
uint IndexA; uint IndexB; uint IndexC; float WeightA; float WeightB; float WeightC; float2 TexCoord; · The twin of FabricSeamVertex, 32 bytes: three carrier particles and their weights, or two and an offset when IndexC equals IndexA, and the texture coordinate.