Skip to content

Pro Mode

This page is for people who write or edit their own shaders. If you do not, you can skip it - everything works without Pro Mode.

Normally the package draws each outlined object one extra time, with a shader so cheap it does almost nothing. Pro Mode removes even that draw: your own shader marks the object as it is already being drawn, and the package adds nothing for it at all.

The outline looks exactly the same either way.

Add a Stencil block to the shader’s opaque pass, and expose the layer number as a material property:

Properties
{
// ... your properties ...
[IntRange] _OutlineStencilRef ("Outline Layer (stencil ref)", Range(1, 4)) = 1
}
SubShader
{
Pass
{
Tags { "LightMode" = "UniversalForward" }
Stencil
{
Ref [_OutlineStencilRef]
ReadMask 15
WriteMask 15
Comp Always
Pass Replace
}
// ... the rest of your shader, unchanged ...
}
}

Then on the object:

  1. Add the Outlined component and set Layer.
  2. Turn Auto Tag off.
  3. Set the material’s Outline Layer to the same number as the component’s Layer.

You still need the component. It is what tells the package that the layer is in use, and it keeps the outline’s cost limited to the part of the screen your outlined objects occupy.

The Layers Showcase sample includes a working example. Its shader is Outline Zero Samples/Pro Mode, and it is exactly the code above.

ReadMask 15 and WriteMask 15 are not optional. URP uses the upper half of the stencil for its own features, and these two lines keep your outline out of its way. Without them you get occasional, hard-to-reproduce breakage in whatever else uses the stencil, most often decals.

Shader Graph has the same settings in the graph rather than in code:

  1. Open the graph and show the Graph Inspector, then the Graph Settings tab.
  2. Under Render State, set Stencil: Reference 1 to 4, Read Mask 15, Write Mask 15, Comparison Always, Pass Replace.
  3. The reference has to be typed in as a number here - Shader Graph cannot take it from a material property. So you need one graph per layer you use this way.

The Inspector’s check reads shader code, so it cannot see what a Shader Graph is set to. When it cannot check a material it says so, rather than warning you about a shader that is fine.

Objects with cut-out transparency (leaves, chain-link fences, anything using alpha clip). Without Pro Mode the outline follows the whole quad rather than the cut-out shape, because the package cannot see your material’s cutout settings. Put the stencil block in your own cut-out shader, keep your clip(), and the outline follows the real shape.

Objects drawn by Entities Graphics or Unity 6’s GPU Resident Drawer. These cannot be outlined automatically at all. With Pro Mode they work normally. The project validator warns you when it sees the GPU Resident Drawer turned on.

Very large numbers of outlined objects. The extra draw per object is the one cost that grows with how many objects you outline. It is small, around 0.3 to 1.0 ms for 120 objects on an S20 FE, but Pro Mode makes it exactly zero.

Select the object. With Auto Tag off, the Inspector compares the material’s layer number with the component’s:

  • They match: nothing is shown.
  • They differ: a warning with both numbers. This is the mistake that gives you an outline in the wrong colour rather than no outline at all.
  • It could not be read (a Shader Graph, or a value set from a script): a short note saying so. Not a warning, because there is probably nothing wrong.