Soft Mask
Shader-based soft masking for UI graphics
Overview
Soft Mask applies smooth, alpha-based masking to all child UI graphics using a custom shader. Unlike Unity's built-in stencil mask, Soft Mask reads the mask graphic's alpha channel (or shape, when the source is a Procedural Rect) and writes it per-pixel to every child, producing feathered, anti-aliased edges with no stencil budget cost.
Supported mask sources are standard UI Image components (including sliced sprites), and ProceduralRect. TextMeshPro text is intercepted and masked through a dedicated TMP shader variant.
Usage
Add the Soft Mask component to the same object that holds your mask graphic (e.g. an Image or Procedural Rect)
Place the UI elements you want to mask as children of that object
Toggle Show Mask Graphic to control whether the mask source itself is visible at runtime
Supported Mask Sources
Image
Standard Image components are supported in all configurations:
- Simple: masks using the sprite's outer UV region, with correct aspect-ratio handling when
Preserve Aspectis enabled - Sliced: masks respect the nine-slice border, scaling border thickness proportionally when the rect is smaller than the combined border size
Procedural Rect
When the mask graphic is a ProceduralRect, the shader uses the SDF shape directly instead of a texture sample:
- Corner radii, softness, and clip settings are all forwarded to the mask shader automatically
- Produces pixel-perfect feathered edges that stay sharp at any resolution
TextMeshPro
Soft Mask detects TextMeshPro shaders by name and automatically swaps them for a dedicated TMP variant. Font atlas textures are preserved during the swap to prevent the SDF rendering from falling back to a solid quad.
Custom Shaders
Any material whose shader exposes the _SoftMask_Rect property is treated as natively soft-mask–aware. The mask properties are written directly onto the existing material, and no shader swap occurs.
Properties
Soft Mask
| Name | Type | Description |
|---|---|---|
showMaskGraphic | bool | When enabled, the graphic driving the mask is drawn normally. Disable to make it invisible while the mask still applies |