Mod Loader/Reference/Fabric render API
FabricRenderApi changes a fabric's material in selected game views. Use it for shader replacement or material effects on the shop bolt, cutting cloth, and garment panels. For a working plugin example, see Add a custom fabric shader.
Register a hook
FabricRenderRegistration FabricRenderApi.Register(
Fabric fabric,
FabricRenderSurface surfaces,
Action<FabricRenderContext> configure,
int priority = 0)
Call on Unity's main thread after the fabric is registered, normally inside FabricModApi.WhenReady. The fabric must have a material. The surface mask must contain at least one supported value.
Each callback applies to one fabric. It receives the material used to draw that fabric in a particular place, such as the shop bolt or a garment panel. The original at Fabric.material stays unchanged. The loader also finds existing views when you register. Higher priorities run later; equal priorities run in registration order. Use separate registrations when two fabrics need the same effect.
Register the callback each time your plugin starts; registrations aren't saved with the dress. When sharing a fabric that needs your shader, include the plugin and its assets. Dress exports don't bundle them.
Surfaces
| Value | View |
|---|---|
Shop
|
Fabric shop bolt. |
Preview
|
Unfolded bolt preview and fabric preview camera. |
CuttingTable
|
Cloth sheet and roll on the cutting table. |
Garment
|
Cut and mannequin panels, including loaded dresses. A cut panel's flat and mannequin views can share one material. |
Hover
|
Translucent panel placement preview. |
Animation
|
Panel placement/removal animation. |
Unlock
|
Fabric unlock celebration bolts. |
All
|
Every surface listed above. |
Combine flags with |. Your callback runs when the material is set up. It runs again if the game rebuilds that material, rather than on every frame. The sketchbook's flat fabric image and unrelated accessory materials are not part of this API.
Callback context
| Member | Use |
|---|---|
Fabric Fabric
|
The fabric being drawn. |
FabricRenderSurface Surface
|
The view being configured. |
Material Material
|
The view material to edit with Unity's material methods. |
Shader OriginalShader
|
The shader used for this view before your callback runs. |
void UseShader(Shader shader)
|
Assign a non-null supported shader without clearing the material's properties. |
bool HasOriginalProperty(string name)
|
Check a property on the original view material. |
Texture GetOriginalTexture(string name)Color GetOriginalColor(string name)float GetOriginalFloat(string name)Vector4 GetOriginalVector(string name)
|
Read the original property using its shader property name and matching type. Check it exists before reading. |
Vector2 GetOriginalTextureScale(string name)Vector2 GetOriginalTextureOffset(string name)
|
Read the original texture slot's tiling or offset. |
Use the context only during its callback. Don't retain or destroy its material. Load textures and shaders separately, keep them alive while registered hooks use them, and release them after removing the hooks.
The GetOriginal... methods read the game's material values before callbacks change them. Use these to copy normal maps, masks, or hover opacity to your shader's matching properties.
For garment panels, sample the fabric texture with UV1. See Choose where the shader is used for the cutting and hover requirements.
Refresh and dispose
void FabricRenderRegistration.Refresh() void FabricRenderRegistration.Dispose()
Refresh starts from the game's material values and applies the registered callbacks again. Call it after a setting changes. It does not reload image files or shader bundles.
Dispose removes your callback and applies the remaining mods' changes again. If no hooks remain for a view, it restores the original material. Calling Dispose again is harmless; Refresh on a disposed registration does nothing. All calls must be on Unity's main thread.
Calling Register, Refresh, or Dispose from a callback is rejected. If a callback throws or selects an unsupported shader, its changes are rolled back. The first error for that registration is logged, and later callbacks still run.