Logo

Procedural Rect

Anti-aliased rounded rectangles rendered via an SDF shader

Overview

Procedural Rect is a custom MaskableGraphic that renders smooth, anti-aliased rounded rectangles using a signed distance field (SDF) shader. It replaces sprite-based UI panels with a fully procedural alternative, supporting fills, outlines, inner shadows, outer shadows, and corner radii — all without any textures.

Color for each layer can be a flat color, a gradient, or inherited from the graphic's base color. Materials and gradient textures are pooled automatically so identical configurations share a single GPU resource.

This component is availabe to preview/test and will replace the background/border handling in version 2.0 once it's thoroughly tested in multiple environments.

Usage

Add the Procedural Rect component to any UI object

Customize the component to your needs

Fill Center can be disabled if you only want to draw an outline or shadow


Notes

  • Materials and gradient textures are reference-counted and shared across all ProceduralRect instances with identical settings, minimising draw calls and memory usage.
  • The component requires TexCoord1, TexCoord2, TexCoord3, Tangent, and Normal canvas shader channels. These are enabled automatically on the parent Canvas.
  • The component accepts a source image (sprite) graphic, so it can be used for masking. For example, you can assign a profile picture and increase the corner radius to get a perfect masking with better performance.

Properties

Rendering

NameTypeDescription
bypassPostProcessingboolRenders using the bypass shader pass so the graphic is unaffected post-processing volumes. HDRP only.

Graphic

NameTypeDescription
spriteSpriteOptional source sprite image rendered inside the rect
scaleModeScaleModeHow the sprite is scaled: Cover, Fit, or Stretch
raycastModeRaycastModeRaycast detection method: None, Standard (rect bounds), or Shape (precise rounded/clipped geometry)

Fill

NameTypeDescription
fillCenterboolFill the interior of the shape. Disable to render only the outline
softnessfloatExtra edge feathering in pixels beyond the default 1 px AA band
fillColorModeColorModeBase, Custom, or Gradient
fillColorColorSolid fill color (used when mode is Custom)
fillGradientGradientGradient used when mode is Gradient
fillGradientAnglefloatRotation of the gradient in degrees (0–360)
fillGradientZoomfloatZoom factor — values above 1 compress the gradient, below 1 stretch it
fillGradientReverseboolSwap the gradient start and end colors

Outline

NameTypeDescription
outlineWidthfloatWidth in pixels, drawn inward from the shape edge
outlineColorModeColorModeBase, Custom, or Gradient
outlineColorColorSolid outline color
outlineGradientGradientGradient used when mode is Gradient
outlineGradientAnglefloatRotation of the gradient in degrees
outlineGradientZoomfloatZoom factor for the gradient
outlineGradientReverseboolSwap the gradient start and end colors

Corner Radius

NameTypeDescription
radiusModeRadiusModePixels or Percentage (percentage of half the shortest side)
independentCornersboolAllow each corner to have a different radius
squircleCornersboolUse smooth squircle corners instead of standard circular rounding
cornerRadiusVector4Radii for all four corners: X = Top Left, Y = Top Right, Z = Bottom Right, W = Bottom Left

Clipping

NameTypeDescription
clipMethodClipMethodNone, Horizontal, Vertical, or Radial360
clipOriginintEdge or quadrant from which clipping begins (range depends on method)
clipAmountfloatHow much of the shape is visible (0–1)
clipClockwiseboolDirection of the radial clip sweep

Inner Shadow

NameTypeDescription
innerShadowOffsetVector2Pixel offset of the inner shadow
innerShadowSizefloatExpansion or contraction size
innerShadowSoftnessfloatBlur radius of the inner shadow
innerShadowColorModeColorModeBase, Custom, or Gradient
innerShadowColorColorSolid inner shadow color
innerShadowGradientGradientGradient used when mode is Gradient
innerShadowGradientAnglefloatRotation of the gradient in degrees
innerShadowGradientZoomfloatZoom factor for the gradient
innerShadowGradientReverseboolSwap the gradient start and end colors

Outer Shadow

NameTypeDescription
outerShadowOffsetVector2Pixel offset of the outer shadow
outerShadowSizefloatExpansion or contraction size
outerShadowSoftnessfloatBlur radius of the outer shadow
outerShadowColorModeColorModeBase, Custom, or Gradient
outerShadowColorColorSolid outer shadow color
outerShadowGradientGradientGradient used when mode is Gradient
outerShadowGradientAnglefloatRotation of the gradient in degrees
outerShadowGradientZoomfloatZoom factor for the gradient
outerShadowGradientReverseboolSwap the gradient start and end colors

Enums

Scale Mode

ValueDescription
CoverFills the rect, cropping the sprite if needed
FitPreserves aspect ratio, leaving gaps if needed
StretchIgnores aspect ratio and fills the rect exactly

Raycast Mode

ValueDescription
NoneDisables raycasting entirely
StandardUses the rect bounds for hit detection
ShapeUses the precise rounded and clipped geometry for hit detection

Clip Method

ValueDescription
NoneNo clipping applied
HorizontalClips from the left or right edge
VerticalClips from the top or bottom edge
Radial360Sweeps a radial clip around the full 360°

Color Mode

ValueDescription
BaseInherits from the graphic's color property
CustomUses the dedicated solid color field
GradientSamples from a baked gradient texture

Radius Mode

ValueDescription
PixelsCorner radius is expressed in screen pixels
PercentageCorner radius is a percentage (0–100) of half the shortest rect side

Code Example

ProceduralRectExample.cs
using UnityEngine;
using Evo.UI;

public class ProceduralRectExample : MonoBehaviour
{
    public ProceduralRect rect;

    void Start()
    {
        // Set a sprite
        rect.sprite = mySprite;

        // Rounded card with a white fill
        rect.fillColorMode = ProceduralRect.ColorMode.Custom;
        rect.fillColor = Color.white;
        rect.cornerRadius = new Vector4(16, 16, 16, 16);

        // Subtle drop shadow
        rect.outerShadowOffset = new Vector2(0, -4);
        rect.outerShadowSoftness = 12f;
        rect.outerShadowColor = new Color(0, 0, 0, 0.25f);

        // Thin outline
        rect.outlineWidth = 1f;
        rect.outlineColorMode = ProceduralRect.ColorMode.Custom;
        rect.outlineColor = new Color(0, 0, 0, 0.1f);

        // Reveal the shape with a radial wipe
        rect.clipMethod = ProceduralRect.ClipMethod.Radial360;
        rect.clipAmount = 0.75f;

        // Update the rect to apply some changes that require vertices or material to be updated
        rect.UpdateRect();
    }
}

On this page