forked from BilalY/Rasagar
50 lines
2.2 KiB
C#
50 lines
2.2 KiB
C#
using UnityEngine.Experimental.Rendering;
|
|
using UnityEngine.Rendering.RenderGraphModule;
|
|
using UnityEngine.Rendering.Universal.Internal;
|
|
|
|
namespace UnityEngine.Rendering.Universal
|
|
{
|
|
/// <summary>
|
|
/// Used by DBuffer to copy depth into different texture.
|
|
/// In future this should be replaced by proper depth copy logic, as current CopyDepthPass do not implement RecordRenderGraph.
|
|
/// </summary>
|
|
internal class DBufferCopyDepthPass : CopyDepthPass
|
|
{
|
|
public DBufferCopyDepthPass(RenderPassEvent evt, Shader copyDepthShader, bool shouldClear = false, bool copyToDepth = false, bool copyResolvedDepth = false)
|
|
: base(evt, copyDepthShader, shouldClear, copyToDepth, copyResolvedDepth)
|
|
{
|
|
}
|
|
|
|
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
|
|
{
|
|
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
|
|
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
|
|
|
|
UniversalRenderer renderer = (UniversalRenderer)cameraData.renderer;
|
|
|
|
TextureHandle cameraDepthTexture = resourceData.cameraDepthTexture;
|
|
|
|
TextureHandle src, dest;
|
|
if (renderer.renderingModeActual == RenderingMode.Deferred)
|
|
{
|
|
src = resourceData.activeDepthTexture;
|
|
dest = cameraDepthTexture;
|
|
}
|
|
else
|
|
{
|
|
var depthDesc = cameraData.cameraTargetDescriptor;
|
|
depthDesc.graphicsFormat = GraphicsFormat.None; //Depth only rendering
|
|
depthDesc.depthStencilFormat = cameraData.cameraTargetDescriptor.depthStencilFormat;
|
|
depthDesc.msaaSamples = 1;
|
|
var depthTarget = UniversalRenderer.CreateRenderGraphTexture(renderGraph, depthDesc, DBufferRenderPass.s_DBufferDepthName, true);
|
|
resourceData.dBufferDepth = depthTarget;
|
|
|
|
src = cameraDepthTexture;
|
|
dest = cameraData.cameraTargetDescriptor.msaaSamples > 1 ? depthTarget : resourceData.activeDepthTexture;
|
|
}
|
|
|
|
Render(renderGraph, dest, src, resourceData, cameraData, false);
|
|
}
|
|
}
|
|
}
|