Game.Rendering.OutlinesWorldUIPass
Assembly:
Assembly-CSharp
Namespace:
Game.Rendering
Type:
public class
Base:
UnityEngine.Rendering.HighDefinition.CustomPass
Summary:
Custom HDRP pass used to render object outlines and world UI elements into a separate render target, then composite them into the camera color buffer. It collects renderers on a configured layer mask, draws them into an intermediate outline buffer with a specialized shader pass, handles objects that must be drawn after dynamic resolution scaling (DRS), and finally composites the outline buffer to the camera via a fullscreen material. The pass supports MSAA for the outline render target and reads MSAA settings from the game's shared graphics settings.
Fields
-
public LayerMask m_OutlineLayer = 0
Layer mask that controls which objects produce outlines. Renderers on these layers will be included when drawing outline meshes. -
public Material m_FullscreenOutline
Fullscreen material used to composite the outline buffer onto the final camera color buffer. This material should sample the_OutlineBuffer
texture and apply any desired outline blur/composite logic. -
public float m_MaxDistance = 16000f
Maximum distance (in world units) at which outlines are applied. This value is uploaded as a global float (_Outlines_MaxDistance
) before drawing outline meshes. -
private MaterialPropertyBlock m_OutlineProperties
MaterialPropertyBlock used to supply the outline buffer texture to the fullscreen material when compositing. -
private ShaderTagId[] m_ShaderTags
Array of ShaderTagIds used when building renderer lists for outlines (contains tags like "Forward", "ForwardOnly", "SRPDefaultUnlit"). -
private RTHandle m_OutlineBuffer
Render target (RTHandle) that stores the outline rendering output. Allocated with appropriate MSAA based on the active outline MSAA quality setting. -
private CustomSampler m_OutlinesSampler
GPU/CPU sampler used for profiling the outlines pass ("Outlines pass"). -
private static class ShaderID
(nested static type)
Contains precomputed shader property IDs used by the pass: public static readonly int _OutlineBuffer
-> Shader.PropertyToID("_OutlineBuffer")public static readonly int _Outlines_MaxDistance
-> Shader.PropertyToID("_Outlines_MaxDistance")public static readonly int _DRSScale
-> Shader.PropertyToID("_DRSScale")public static readonly int _DRSScaleSquared
-> Shader.PropertyToID("_DRSScaleSquared")
These IDs are used to set global/material properties quickly.
Properties
public RTHandle outlineBuffer => m_OutlineBuffer
Read-only property exposing the internal outline RTHandle. Useful if other systems need to sample or inspect the outline texture.
Constructors
public OutlinesWorldUIPass()
No explicit constructor is defined in the source; the default parameterless constructor is used. Initialization of runtime resources happens in Setup, and GPU resources are created on demand in CheckResource/CreateResources.
Methods
-
private void CheckResource()
Ensures the outline RTHandle exists and matches the current outline MSAA setting. Queries the game's SharedSettings graphics quality for an outlines MSAA setting (AntiAliasingQualitySettings.outlinesMSAA), clamps it to the supported range, and recreates the outline buffer if MSAA changed or the buffer is missing. -
private void CreateResources(MSAASamples msaaSamples)
Allocatesm_OutlineBuffer
as an RTHandle with the requested MSAA sample count. Uses GraphicsFormat.R8G8B8A8_SRGB and point filtering. The allocation parameters match HDRP/TextureXR conventions. -
private void ReleaseResources()
Releases the RTHandle (m_OutlineBuffer
) if allocated. -
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
Called when the custom pass is set up. Creates theCustomSampler
("Outlines pass"), initializesm_OutlineProperties = new MaterialPropertyBlock()
, and fillsm_ShaderTags
with the shader passes used for the outline draw. -
protected override void AggregateCullingParameters(ref ScriptableCullingParameters cullingParameters, HDCamera hdCamera)
Addsm_OutlineLayer
to the culling mask so objects on that layer are included in culling results used by this pass. -
private static RendererListDesc CreateOpaqueRendererListDesc(CullingResults cull, Camera camera, ShaderTagId passName, PerObjectData rendererConfiguration = PerObjectData.None, RenderQueueRange? renderQueueRange = null, RenderStateBlock? stateBlock = null, Material overrideMaterial = null, bool excludeObjectMotionVectors = false)
Helper that builds a RendererListDesc configured for opaque renderer lists (common opaque sorting, default opaque render queue range if not provided). -
private static RendererListDesc CreateTransparentRendererListDesc(CullingResults cull, Camera camera, ShaderTagId passName, PerObjectData rendererConfiguration = PerObjectData.None, RenderQueueRange? renderQueueRange = null, RenderStateBlock? stateBlock = null, Material overrideMaterial = null, bool excludeObjectMotionVectors = false)
Helper that builds a RendererListDesc configured for transparent renderer lists (transparent sorting + renderer priority, default transparent render queue range if not provided). -
private void DrawOutlineMeshes(CustomPassContext ctx)
Builds a renderer list usingm_ShaderTags
and the pass' culling results and camera, configures renderer list options (PerObjectData for light probes/lightmaps, sorting back-to-front, layerMask = m_OutlineLayer), sets the global_Outlines_MaxDistance
, enables shader keywordSHADERPASS_OUTLINES
, setsm_OutlineBuffer
as the current render target and clears it, then draws the renderer list. Disables the outline shader keyword afterward. -
private void DrawAfterDRSObjects(CustomPassContext ctx)
Handles objects that must be drawn after dynamic resolution scaling (AfterDRS). Sets_DRSScale
and_DRSScaleSquared
globals from DynamicResolutionHandler.instance.GetCurrentScale() and draws two renderer lists: AfterDRSOpaque and AfterDRSTransparent, using the forward-only HD shader pass. -
protected override void Execute(CustomPassContext ctx)
Main execution entry for the pass. Calls CheckResource(), profiles the pass, calls DrawOutlineMeshes(ctx), sets the camera color buffer as the render target, draws AfterDRS objects, sets_OutlineBuffer
on the fullscreen material property block, and finally draws the fullscreen composite using m_FullscreenOutline and m_OutlineProperties. -
protected override void Cleanup()
Called when the pass is destroyed/unloaded; releases GPU resources by calling ReleaseResources().
Usage Example
// Typical usage: attach/configure this CustomPass as an asset in an HDRP Custom Pass Volume.
// At runtime the pass will:
// - collect renderers on m_OutlineLayer and render them with the SHADERPASS_OUTLINES shader pass into m_OutlineBuffer
// - draw AfterDRS objects
// - composite m_OutlineBuffer via m_FullscreenOutline material into the camera color buffer
// Example: configuring the pass from code (if creating/adjusting at runtime)
OutlinesWorldUIPass outlinesPass = /* obtain reference to the pass */;
outlinesPass.m_OutlineLayer = LayerMask.GetMask("OutlineLayer");
outlinesPass.m_FullscreenOutline = myOutlineCompositeMaterial;
outlinesPass.m_MaxDistance = 12000f;
// The pass will handle resource allocation/cleanup automatically (CreateResources/ReleaseResources).
// Ensure the composite material samples _OutlineBuffer and applies the desired outline/blur logic.
Additional notes:
- The outline shader used by renderers must implement/handle the SHADERPASS_OUTLINES
keyword or a pass matching the ShaderTagIds used by this pass.
- MSAA for the outline buffer is read from the game's AntiAliasingQualitySettings.outlinesMSAA; changing quality settings will cause the buffer to be recreated with the appropriate sample count.
- _DRSScale
and _DRSScaleSquared
are supplied to shaders that need to account for dynamic resolution scaling when sampling/resolving outlines.