Skip to content

How to Add Outlines to 3D Models in Unity URP

There are two ways to outline a 3D model in Unity. The material can draw a slightly larger copy of the model behind it in the outline colour, an inverse hull, or a post processing pass can find the edges of everything on screen from depth and normals, a screen space outline. Which one suits you depends on your meshes and on what should be outlined, so that comes first.

The demo's green puppet turning on its platform while a gold outline grows around it, holds, and fades away

The inverse hull draws the model a second time: only its back faces, pushed outwards along the vertex normals, in a flat colour. Whatever sticks out past the model is the outline.

  • Each object gets its own colour, width and on or off, which is what hover and selection highlights need.
  • It works in any pipeline and follows animation, skinning and vertex effects.
  • It costs one more draw for each outlined object.
  • It depends on the mesh’s normals. Where a hard edge splits them, the copy splits too and the outline opens up.

A screen space outline runs once over the finished image, and draws a line wherever depth or normals jump.

  • Any mesh outlines cleanly, hard edges included, and it can find the creases inside a model as well as its silhouette.
  • Its cost is per screen, not per object.
  • It outlines everything it sees, unless you mask it to some objects or layers, and a different colour for each object takes extra work.

All In 1 3D Shader draws the first kind. If outlines are the heart of your game’s look and you want them on every edge, across every object, a dedicated screen space asset such as Linework is the better buy, and the Outlines page says the same.

A shader for the inverse hull. This is a whole URP shader. Put it on a material and add that material as a second material on the model’s Mesh Renderer, under the one it already has. Unity draws the extra material over the mesh again (the Inspector warns that the renderer has more materials than submeshes, which is the point here).

Shader "Custom/InverseHullOutline"
{
Properties
{
_OutlineColor ("Outline Color", Color) = (0, 0, 0, 1)
_OutlineWidth ("Outline Width", Float) = 0.02
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
Pass
{
Name "Outline"
// Draw only the back faces, so the grown copy shows around the model and never over it
Cull Front
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
CBUFFER_START(UnityPerMaterial)
half4 _OutlineColor;
float _OutlineWidth;
CBUFFER_END
struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
};
Varyings vert(Attributes input)
{
Varyings output;
// Push every vertex out along its normal by the width, in the object's own units
float3 grown = input.positionOS.xyz + input.normalOS * _OutlineWidth;
output.positionCS = TransformObjectToHClip(grown);
return output;
}
half4 frag(Varyings input) : SV_Target
{
return _OutlineColor;
}
ENDHLSL
}
}
}

In Shader Graph it is an Unlit graph with Render Face set to Back in the Graph Settings, the vertex Position node plus the Normal Vector node times a width going into the Vertex block’s Position, and a colour into Base Color.

URP’s Render Objects feature, for a whole layer. Add a Render Objects feature to the URP Renderer asset, set its event to After Rendering Opaques, its Layer Mask to the layer to outline, and its Override Material to an outline material like the one above. Every object on that layer then gets the outline without a second material slot.

What you will run into:

  • Hard edges split the outline. A cube, or any low poly mesh with flat shading, has several normals at each corner, so the hull tears open there. Smooth the normals: in the model’s import settings set Normals to Calculate, Smoothness Source to From Angle, and a high Smoothing Angle. That makes the lighting smooth too, which is what the 3D Shader’s Flat Normals effect then undoes; see Handling Sharp Corners.
  • The width follows the object. It is in the object’s own units, so a scaled object gets a scaled outline, and like any object the outline gets thinner on screen as it moves away.
  • Inner overlaps show. Where an arm crosses the body, the arm’s hull shows over the body. Hiding that needs the stencil buffer.

A screen space outline in URP (post processing)

Section titled “A screen space outline in URP (post processing)”

A screen space outline is a full screen pass: once the scene is drawn, a shader looks at the camera’s depth and normals around every pixel and draws a line wherever either one jumps. URP builds one from its own parts, the Full Screen Pass Renderer Feature and a shader for it.

  1. Save the shader below as a file and make a material with it.
  2. Select your URP Renderer asset, press Add Renderer Feature and pick Full Screen Pass Renderer Feature.
  3. Set its Pass Material to that material and its Injection Point to Before Rendering Post Processing, and tick Depth and Normal under Requirements. Leave Fetch Color Buffer on, which is how the shader receives the image it draws on.
Shader "Custom/ScreenSpaceOutline"
{
Properties
{
_OutlineColor ("Outline Color", Color) = (0, 0, 0, 1)
_Thickness ("Thickness (pixels)", Float) = 1
_DepthThreshold ("Depth Threshold", Float) = 0.05
_NormalThreshold ("Normal Threshold", Float) = 0.8
}
SubShader
{
Tags { "RenderPipeline" = "UniversalPipeline" }
ZWrite Off
ZTest Always
Cull Off
Blend Off
Pass
{
Name "ScreenSpaceOutline"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
half4 _OutlineColor;
float _Thickness;
float _DepthThreshold;
float _NormalThreshold;
half4 frag(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord;
// The camera's image so far, which the feature passes in as _BlitTexture
half4 color = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
float2 texel = _Thickness * _ScreenSize.zw;
float2 offsets[4] = { float2(texel.x, 0), float2(-texel.x, 0), float2(0, texel.y), float2(0, -texel.y) };
float depth = LinearEyeDepth(SampleSceneDepth(uv), _ZBufferParams);
float3 normal = SampleSceneNormals(uv);
float depthEdge = 0;
float normalEdge = 0;
for (int i = 0; i < 4; i++)
{
float d = LinearEyeDepth(SampleSceneDepth(uv + offsets[i]), _ZBufferParams);
// Relative to the distance, so far objects are not all edges
depthEdge = max(depthEdge, abs(d - depth) / depth);
// Only where both pixels have a normal: the sky and other empty pixels have none
float3 n = SampleSceneNormals(uv + offsets[i]);
float bothDrawn = step(0.5, dot(normal, normal)) * step(0.5, dot(n, n));
normalEdge = max(normalEdge, bothDrawn * (1 - dot(normal, n)));
}
float edge = max(step(_DepthThreshold, depthEdge), step(_NormalThreshold, normalEdge));
return lerp(color, _OutlineColor, edge * _OutlineColor.a);
}
ENDHLSL
}
}
}

In Shader Graph it is a Fullscreen graph: the URP Sample Buffer node gives the image (Blit Source) and the normals (World Normal), the Scene Depth node in Eye mode gives the depth, both read at the pixel and at offset UVs, then the same comparisons, a Step, and a Lerp from the image to the outline colour. Its material goes in the same feature.

The same three props outlined two ways. With the inverse hull only the props get an outline, around their silhouettes. With the screen space pass every edge the camera sees gets a line, the props' inner shapes and the ground's creases included

What it costs and where it falls short:

  • Every edge on screen. It outlines whatever the camera sees, the ground included. Limiting it to some objects means drawing those into a mask of their own and reading that in the shader.
  • One colour. A colour per object needs that mask too, or an ID per object.
  • Thresholds to tune. The two thresholds decide what counts as an edge, and a value that suits close objects can draw too much or too little far away. Lines keep their pixel width at any distance, so where objects are small they fill up with lines.
  • Normal maps add lines. URP writes normal maps into the normals the pass reads, so a stony or bumpy surface gets lines across it. Raise Normal Threshold until only the shapes remain; 0.8 is what the picture above uses.
  • Transparent objects write neither depth nor normals, so they get no outline, and the lines of whatever is behind them are drawn on top of them, since the pass runs after them.
  • Its cost is a full screen pass with eleven texture reads per pixel, plus the extra pass URP makes to draw the scene’s normals once Normal is required, whatever is on screen.

All In 1 3D Shader draws the per model kind. If the screen space kind is what you need, the pass above or a dedicated asset such as Linework, which handles masks, colours and line quality for you, is the honest answer.

Don’t own it yet? → Get it on the Unity Asset Store

Set Outline Type in the material’s Other Effects. The material switches itself to the Outline variant of the shader, the one with the extra pass. In URP the pass is drawn by two renderer features, Render Feature - Outline Opaque and Render Feature - Outline Transparent, which the asset offers to add when the editor loads and adds from the Asset Window at any time; it only adds them to the first renderer of your URP asset. See URP Setup. The Built-in pipeline needs nothing.

The outline settings under Other Effects: Outline Type set to Simple, a note to enable Depth Write on transparent materials, Outline Color, Outline Thickness and Outline Mode set to Clean
  • Outline Type picks how the width behaves:
    • Simple: a width in world units, 0.01 units for each 1 of Outline Thickness, whatever the object’s scale.
    • Constant: the same width on screen at any distance, for perspective cameras. Max Camera Distance sets how thick that is: a larger value gives a thinner outline.
    • Fade With Distance: the width shrinks with distance and reaches nothing at Max Fade Distance.
  • Outline Color is an HDR colour, so with Bloom the outline can glow.
  • Outline Thickness is the width.
  • Outline Mode: Basic draws the whole hull, inner overlaps included. Clean uses the stencil buffer to keep the outline off the model’s own surface, so only the silhouette is outlined. It also keeps one outlined object’s outline off another, so outlined objects that overlap share a single outline around them both. For an outline on each, use Basic.
Simple, Constant and Fade With Distance while the camera moves away and back: Simple gets thinner on screen, Constant holds its width, Fade With Distance thins out until it disappears

The outline pass runs the material’s vertex effects, so wind, inflation and other mesh movement keep their outline. It draws a flat colour, without lighting or colour effects.

For low poly and hard edged meshes, smooth the normals on import and tick Flat Normals in the material to keep the faceted lighting:

A turning cube with hard normals, whose outline breaks open at every corner, next to the same cube with smooth normals plus Flat Normals, whose outline stays closed

Turn the outline on in the material in the editor, and switch it from code by its Outline Thickness: 0 hides it, your width shows it. Changing a number keeps the material on the same shader, so it behaves the same in a build.

Enabling the outline from code with EnableKeyword is the one route that does not work here. The outline pass only exists in the Outline variant of the shader, and only the material inspector switches a material to it, so at runtime the keyword alone draws nothing.

using UnityEngine;
using UnityEngine.EventSystems;
public class OutlineOnHover : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
private static readonly int OutlineThickness = Shader.PropertyToID("_OutlineThickness");
[SerializeField] private float thickness = 2f;
private Material mat;
private void Awake()
{
mat = GetComponent<Renderer>().material;
mat.SetFloat(OutlineThickness, 0f);
}
public void OnPointerEnter(PointerEventData eventData) => mat.SetFloat(OutlineThickness, thickness);
public void OnPointerExit(PointerEventData eventData) => mat.SetFloat(OutlineThickness, 0f);
}

The pointer events need an EventSystem in the scene, a Physics Raycaster on the camera and a Collider on the object. A hidden outline still costs its draw, so with many interactables, swapping between two saved materials, one with the outline and one without, is cheaper. How to Enable/Disable Effects at Runtime and Scripting cover both routes.

Three props on the demo floor. A gold outline appears on each in turn and goes again, the way the script switches it as the pointer moves across them

An outlined object behind glass keeps its outline. In URP the outlines of opaque objects are drawn right after the opaque objects, before anything transparent, so glass in front tints the outline like everything else behind it. That holds with URP Lit glass and with the 3D Shader’s own transparent materials, in both outline modes.

The case to watch is an outlined object that is itself transparent. Its outline is drawn after every transparent object, and with Depth Write off nothing stops the hull from covering the object, so the whole object fills with the outline colour. Keep Depth Write on for a transparent material with an outline; it is under Show Advanced Configuration, and the material inspector reminds you next to the outline settings.

  • Screen space outlines. No outline on edges inside a model, and no outline on objects that do not use the 3D Shader.
  • A clean outline on split normals. The hull follows the mesh’s normals, so hard edges need the smoothing above.
  • A fixed width on screen in an orthographic view. Constant relies on perspective.