Table of Contents

MSDF Sprite

Shader for rendering 2D images with effects. Supports both UI and Sprite-based usage.

(Sprite here meaning any mesh on the world, not restricted to usage with Unity's Sprite Renderer!)

It is made of up to three layers of effects:

  1. Fill color following the sharp contour of the shape;
  2. Outline color following the expanded contour of the shape, either sharp or smooth;
  3. Shadow that fades from the entire

Demonstration of the layer stacking

Surface Inputs

Name Property ID Description
Distance Field _MainTex The distance field to use for all effects.
Pixel Range _MainTex_PixelRange Pixel range of the distance field, automatically detected by the inspector. Must be provided manually when creating materials programmatically.
Base Color _Color Color of the interior of the shape.

Outline

Name Property ID Description
Outline Style One of _OUTLINE_MODE_OFF, _OUTLINE_MODE_SHARP, _OUTLINE_MODE_TRUE keywords Off: No outline.
Sharp: Outline of sharp edges will be sharp too.
True: Outline of sharp edges will have rounded corners.
Color _OutlineColor Color to use for the outline.
Thickness _OutlineThickness Distance in pixels from the shape's contour.

Shadow

Name Property ID Description
Enable Presence of _ENABLE_SHADOW keywords Whether to draw a shadow or not.
Color _ShadowColor Color of the center of the shadow, which will fade down to completely transparent at the edge.
Range _ShadowLimits In normalized range, where the start and end points of the penumbra are along the distance field's range.
Power _ShadowPower Exponent to apply to the penumbra. Higher values mean a sharper transition from shadow to light. Values less than 1 can cause artifacts.
Offset _ShadowOffset In UV units, offset to apply to the center of the shadow.

Advanced Options

Name Property ID Description
Perspective-aware Pixel Range _PERSPECTIVE_AWARE_PIXEL_RANGE keyword When enabled, performs decoding of the pixel range in the shader, accounting for perspective to maintain smoothness.

When disabled, expects the value of _MainTex_PixelRange to be scaled on the CPU. This is done automatically by the SpriteDistanceField and ImageDistanceField components.