Home / Forums / Custom Stencil Silhouette & Glow Outlines in Unity Games

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

Custom Stencil Silhouette & Glow Outlines in Unity Games

RenderMaster
ImGui UI Designer
VIP
Rep: 310
Join Date: Sep 2023
Posts: 32
Thanks: 82
1y ago · Oct 15, 2024 2:20 PM
#1
Unlike flat solid Chams, Stencil Glow Outlines render a crisp colored border around player silhouettes while preserving original character textures inside.

How Stencil Outlines work in Unity Graphics Pipeline:
1. Mask Pass: Render character mesh into the Stencil Buffer with a constant reference value (e.g.
CODE
Ref 1, Comp Always, Pass Replace
).
2. Outline Pass: Invert or extrude mesh vertices along normal vectors by a small thickness (
CODE
1.03x
), and only draw pixels where
CODE
Stencil Comp NotEqual
(preventing the outline from rendering over the player's body).

CSHARP
using UnityEngine;

public static class OutlineHelper
{
    public static void AddOutlineComponent(GameObject playerObject, Color outlineColor, float width = 4f)
    {
        // Many Unity games include QuickOutline or built-in Outline scripts
        // Or you can instantiate a CommandBuffer outline pass attached to Camera.main
        var outline = playerObject.GetComponent<Outline>();
        if (outline == null)
        {
            outline = playerObject.AddComponent<Outline>();
        }

        outline.OutlineMode = Outline.Mode.OutlineAll;
        outline.OutlineColor = outlineColor;
        outline.OutlineWidth = width;
        outline.enabled = true;
    }
}
RenderMaster | Clean UI Design & Dear ImGui widgets
The following users thanked RenderMaster for this post:
GlowShader
Shader & Overlay Artist
MEMBER
Rep: 185
Join Date: Oct 2023
Posts: 36
Thanks: 46
1y ago · Oct 15, 2024 4:45 PM
#2
Outline shaders are super clean because they blend with the game's native lighting and bloom post-processing without blinding the player.
GlowShader | Shaders, Stencils & DirectX DrawLists
DirectXRay
DirectX 12 / Vulkan Dev
MEMBER
Rep: 240
Join Date: Feb 2023
Posts: 31
Thanks: 60
1y ago · Oct 16, 2024 11:25 AM
#3
In Universal Render Pipeline (URP), you can also inject a
CODE
ScriptableRenderPass
that renders a full-screen blur jump-flood pass for AAA-quality edge glow!
DirectXRay · DirectX 12 & Vulkan Command Lists