< Summary

Class:OutlineScreenEffectFeature
Assembly:Outliner
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/Outliner/OutlineScreenEffectFeature.cs
Covered lines:7
Uncovered lines:57
Coverable lines:64
Total lines:125
Line coverage:10.9% (7 of 64)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OutlinePass()0%2100%
OutlinePass(...)0%110100%
Setup(...)0%2100%
Execute(...)0%2100%
FrameCleanup(...)0%2100%
OutlineSettings()0%2100%
OutlineScreenEffectFeature()0%2100%
Create()0%110100%
AddRenderPasses(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/Outliner/OutlineScreenEffectFeature.cs

#LineLine coverage
 1// unset:none
 2using UnityEngine;
 3using UnityEngine.Rendering;
 4using UnityEngine.Rendering.Universal;
 5
 6public class OutlineScreenEffectFeature : ScriptableRendererFeature
 7{
 8    private class OutlinePass : ScriptableRenderPass
 9    {
 010        private static readonly int _InnerColor = Shader.PropertyToID("_InnerColor");
 011        private static readonly int _OutlineColor = Shader.PropertyToID("_OutlineColor");
 012        private static readonly int _OutlineSize = Shader.PropertyToID("_OutlineSize");
 013        private static readonly int _BlurColor = Shader.PropertyToID("_BlurColor");
 014        private static readonly int _BlurSize = Shader.PropertyToID("_BlurSize");
 015        private static readonly int _Sigma = Shader.PropertyToID("_BlurSigma");
 016        private static readonly int _Fade = Shader.PropertyToID("_Fade");
 17
 18        private readonly OutlineSettings settings;
 19        private const string PROFILER_TAG = "Outline Screen Effect Pass";
 20        private readonly Material material = null;
 21
 022        private RenderTargetIdentifier source { get; set; }
 023        private RenderTargetHandle destination { get; set; }
 024        private RenderTargetHandle outlineMask { get; set; }
 25
 26        private enum ShaderPasses
 27        {
 28            Outline = 0,
 29            BlurHorizontal = 1,
 30            BlurVertical = 2,
 31            Compose = 3
 32        }
 33
 234        public OutlinePass(OutlineSettings settings)
 35        {
 236            this.settings = settings;
 237            material = CoreUtils.CreateEngineMaterial("DCL/OutlinerEffect");
 238        }
 39
 40        public void Setup(RenderTargetIdentifier source, RenderTargetHandle destination, RenderTargetHandle outlineTextu
 41        {
 042            this.source = source;
 043            this.destination = destination;
 044            this.outlineMask = outlineTexture;
 045        }
 46
 47        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
 48        {
 049            material.SetColor(_InnerColor, settings.innerColor);
 050            material.SetColor(_OutlineColor, settings.outlineColor);
 051            material.SetFloat(_OutlineSize, settings.outlineSize);
 052            material.SetColor(_BlurColor, settings.blurColor);
 053            material.SetFloat(_BlurSize, settings.blurSize);
 054            material.SetFloat(_Sigma, settings.blurSigma);
 055            material.SetFloat(_Fade, settings.effectFade);
 056            CommandBuffer cmd = CommandBufferPool.Get(PROFILER_TAG);
 57
 058            using (new ProfilingScope(cmd, new ProfilingSampler(PROFILER_TAG)))
 59            {
 060                RenderTextureDescriptor descriptor = renderingData.cameraData.cameraTargetDescriptor;
 061                descriptor.depthBufferBits = 0;
 062                RenderTargetHandle camera = new RenderTargetHandle() { id = Shader.PropertyToID("_OutlinerEffect_Camera"
 063                RenderTargetHandle outline1 = new RenderTargetHandle() { id = Shader.PropertyToID("_OutlinerEffect_Outli
 064                RenderTargetHandle outline2 = new RenderTargetHandle() { id = Shader.PropertyToID("_OutlinerEffect_Outli
 065                cmd.GetTemporaryRT(camera.id, descriptor, FilterMode.Point);
 066                cmd.GetTemporaryRT(outline1.id, descriptor, FilterMode.Point);
 067                cmd.GetTemporaryRT(outline2.id, descriptor, FilterMode.Point);
 68
 069                Blit(cmd, outlineMask.id, outline1.id, material, (int)ShaderPasses.Outline); // Get the outline. Output 
 070                Blit(cmd, outline1.id, outline2.id, material, (int)ShaderPasses.BlurHorizontal); // Apply Vertical blur.
 071                Blit(cmd, outline2.id, outline1.id, material, (int)ShaderPasses.BlurVertical); // Apply Horizontal blur.
 72
 073                Blit(cmd, source, camera.id); // Get camera in a RT
 074                cmd.SetGlobalTexture("_Source", camera.id); // Apply RT as _Source for the material
 075                cmd.SetGlobalTexture("_ComposeMask", outlineMask.id); // Set the original outline mask
 076                Blit(cmd, outline1.id, source, material, (int)ShaderPasses.Compose);
 77
 078                cmd.ReleaseTemporaryRT(camera.id);
 079                cmd.ReleaseTemporaryRT(outline1.id);
 080                cmd.ReleaseTemporaryRT(outline2.id);
 81
 82
 083            }
 84
 085            context.ExecuteCommandBuffer(cmd);
 086            CommandBufferPool.Release(cmd);
 087        }
 88
 89        public override void FrameCleanup(CommandBuffer cmd)
 90        {
 091        }
 92    }
 93
 94    [System.Serializable]
 95    public class OutlineSettings
 96    {
 097        public float outlineSize = 0.001f;
 098        public float blurSize = 0.001f;
 099        public float blurSigma = 1;
 0100        public Color outlineColor = Color.cyan;
 0101        public Color blurColor = Color.cyan;
 0102        public Color innerColor = Color.cyan;
 0103        [Range(0, 1)] public float effectFade = 1;
 104    }
 105
 0106    public OutlineSettings settings = new ();
 107    private OutlinePass outlinePass;
 108    private RenderTargetHandle outlineTexture;
 109
 110    public override void Create()
 111    {
 2112        outlinePass = new OutlinePass(settings)
 113        {
 114            renderPassEvent = RenderPassEvent.AfterRenderingTransparents,
 115        };
 116
 2117        outlineTexture.Init("_OutlineTexture");
 2118    }
 119
 120    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
 121    {
 0122        outlinePass.Setup(renderer.cameraColorTarget, RenderTargetHandle.CameraTarget, outlineTexture);
 0123        renderer.EnqueuePass(outlinePass);
 0124    }
 125}