using UnityEngine.Rendering; namespace UnityEngine.Experimental.Rendering.LightweightPipeline { public class CopyDepthPass : ScriptableRenderPass { Material m_DepthCopyMaterial; private RenderTargetHandle source { get; set; } private RenderTargetHandle destination { get; set; } public CopyDepthPass(LightweightForwardRenderer renderer) : base(renderer) { m_DepthCopyMaterial = renderer.GetMaterial(MaterialHandles.DepthCopy); } public void Setup(RenderTargetHandle source, RenderTargetHandle destination) { this.source = source; this.destination = destination; } public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get("Depth Copy"); RenderTargetIdentifier depthSurface = source.Identifier(); RenderTargetIdentifier copyDepthSurface = destination.Identifier(); RenderTextureDescriptor descriptor = renderer.CreateRTDesc(ref renderingData.cameraData); descriptor.colorFormat = RenderTextureFormat.Depth; descriptor.depthBufferBits = 32; //TODO: fix this ; descriptor.msaaSamples = 1; descriptor.bindMS = false; cmd.GetTemporaryRT(destination.id, descriptor, FilterMode.Point); if (renderingData.cameraData.msaaSamples > 1) { cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa); if (renderingData.cameraData.msaaSamples == 4) { cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); } else { cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); } cmd.Blit(depthSurface, copyDepthSurface, m_DepthCopyMaterial); } else { cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa); cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, m_DepthCopyMaterial); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); } public override void Dispose(CommandBuffer cmd) { if (destination != RenderTargetHandle.CameraTarget) { cmd.ReleaseTemporaryRT(destination.id); destination = RenderTargetHandle.CameraTarget; } } } }