1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; public class RendererPassTest : ScriptableRenderPass { Color m_Color; Material m_Mat = new Material(Shader.Find("Hidden/URPBaseTest")); public FilterMode filterMode { get; set; } RenderTargetIdentifier m_Source; RenderTargetHandle m_TemporaryColorTexture; ProfilingSampler m_ProfilingSampler = new ProfilingSampler("URPTest"); public RendererPassTest() { renderPassEvent = RenderPassEvent.AfterRenderingOpaques; m_TemporaryColorTexture.Init("URPBaseTest"); } public void Setup(RenderTargetIdentifier source, Color color) { m_Source = source; m_Color = color; m_Mat.SetColor("_Color", m_Color); } public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(); using (new ProfilingScope(cmd, m_ProfilingSampler)) { RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor; opaqueDesc.depthBufferBits = 0; cmd.GetTemporaryRT(m_TemporaryColorTexture.id, opaqueDesc, filterMode); Blit(cmd, m_Source, m_TemporaryColorTexture.Identifier(), m_Mat); Blit(cmd, m_TemporaryColorTexture.Identifier(), m_Source); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); } public override void FrameCleanup(CommandBuffer cmd) { base.FrameCleanup(cmd); cmd.ReleaseTemporaryRT(m_TemporaryColorTexture.id); } }
|