using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; public class OutlineRenderFeature : ScriptableRendererFeature { class OutlineRenderPass : ScriptableRenderPass { public Material outlineMaterial; public LayerMask outlineLayer; private string profilerTag = "OutlineRenderPass"; private ProfilingSampler profilingSampler; public OutlineRenderPass(Material material, LayerMask layer) { outlineMaterial = material; outlineLayer = layer; profilingSampler = new ProfilingSampler(profilerTag); renderPassEvent = RenderPassEvent.AfterRenderingTransparents; } public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { if (outlineMaterial == null) return; CommandBuffer cmd = CommandBufferPool.Get(); using (new ProfilingScope(cmd, profilingSampler)) { var drawingSettings = CreateDrawingSettings(new ShaderTagId("UniversalForward"), ref renderingData, SortingCriteria.CommonOpaque); drawingSettings.overrideMaterial = outlineMaterial; var filteringSettings = new FilteringSettings(RenderQueueRange.all, outlineLayer); context.ExecuteCommandBuffer(cmd); cmd.Clear(); // Рисуем объекты с обводкой context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filteringSettings); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); } } public Material outlineMaterial; public LayerMask outlineLayer; OutlineRenderPass outlinePass; public override void Create() { outlinePass = new OutlineRenderPass(outlineMaterial, outlineLayer); } public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) { if (outlineMaterial == null) return; renderer.EnqueuePass(outlinePass); } }