浏览代码

Created ScriptableRenderPass class to abstract passes. Ported DepthOnlyPass to new SRP.

/main
Felipe Lira 6 年前
当前提交
05b422c1
共有 11 个文件被更改,包括 163 次插入40 次删除
  1. 55
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  2. 9
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs
  3. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/DepthCopy.hlsl
  4. 8
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes.meta
  5. 78
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DepthOnlyPass.cs
  6. 11
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DepthOnlyPass.cs.meta
  7. 29
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScriptableRenderPass.cs
  8. 11
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScriptableRenderPass.cs.meta
  9. 0
      /ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/LightweightShadowPass.cs.meta
  10. 0
      /ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/LightweightShadowPass.cs

55
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


// we need use copyColor RT as a work RT.
public static int copyColor;
// Camera depth target. Only used when post processing, soft particles, or screen space shadows are enabled.
public static int depth;
// If soft particles are enabled and no depth prepass is performed we need to copy depth.
public static int depthCopy;

{
private readonly LightweightPipelineAsset m_Asset;
DepthOnlyPass m_DepthOnlyPass;
private LightweightShadowPass m_ShadowPass;
// Maximum amount of visible lights the shader can process. This controls the constant global light buffer size.

CameraRenderTargetID.color = Shader.PropertyToID("_CameraColorRT");
CameraRenderTargetID.copyColor = Shader.PropertyToID("_CameraCopyColorRT");
CameraRenderTargetID.depth = Shader.PropertyToID("_CameraDepthTexture");
CameraRenderTargetID.depthCopy = Shader.PropertyToID("_CameraCopyDepthTexture");
CameraRenderTargetID.opaque = Shader.PropertyToID("_CameraOpaqueTexture");

m_ColorRT = new RenderTargetIdentifier(CameraRenderTargetID.color);
m_CopyColorRT = new RenderTargetIdentifier(CameraRenderTargetID.copyColor);
m_DepthRT = new RenderTargetIdentifier(CameraRenderTargetID.depth);
m_CopyDepth = new RenderTargetIdentifier(CameraRenderTargetID.depthCopy);
m_PostProcessRenderContext = new PostProcessRenderContext();

m_MaxLocalLightsShadedPerPass = m_UseComputeBuffer ? kMaxVisibleLocalLights : kMaxNonIndexedLocalLights;
m_LocalLightIndices = new List<int>(m_MaxLocalLightsShadedPerPass);
m_DepthOnlyPass = new DepthOnlyPass(null, RenderTextureFormat.Depth);
m_ShadowPass = new LightweightShadowPass(m_Asset, kMaxVisibleLocalLights);
// Let engine know we have MSAA on for cases where we support MSAA backbuffer

context.SetupCameraProperties(m_CurrCamera, stereoEnabled);
if (CoreUtils.HasFlag(frameRenderingConfiguration, FrameRenderingConfiguration.DepthPrePass))
DepthPass(ref context, frameRenderingConfiguration);
m_DepthOnlyPass.Execute(context, camera, ref m_CullResults, stereoEnabled);
if (screenspaceShadows)
m_ShadowPass.CollectShadows(m_CurrCamera, frameRenderingConfiguration, ref context);

{
cmd = CommandBufferPool.Get("Copy Depth to Camera");
cmd.DisableShaderKeyword(kMSAADepthKeyword);
CopyTexture(cmd, CameraRenderTargetID.depth, BuiltinRenderTextureType.CameraTarget, m_CopyDepthMaterial, true);
CopyTexture(cmd, m_DepthOnlyPass.depthTextureID, BuiltinRenderTextureType.CameraTarget, m_CopyDepthMaterial, true);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

cmd.ReleaseTemporaryRT(CameraRenderTargetID.depthCopy);
cmd.ReleaseTemporaryRT(CameraRenderTargetID.depth);
m_DepthOnlyPass.Dispose(cmd);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

}
private void DepthPass(ref ScriptableRenderContext context, FrameRenderingConfiguration frameRenderingConfiguration)
{
CommandBuffer cmd = CommandBufferPool.Get("Depth Prepass");
SetRenderTarget(cmd, m_DepthRT, ClearFlag.Depth);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
var opaqueDrawSettings = new DrawRendererSettings(m_CurrCamera, m_DepthPrepass);
opaqueDrawSettings.sorting.flags = SortFlags.CommonOpaque;
var opaqueFilterSettings = new FilterRenderersSettings(true)
{
renderQueueRange = RenderQueueRange.opaque
};
StartStereoRendering(m_CurrCamera, ref context, frameRenderingConfiguration);
context.DrawRenderers(m_CullResults.visibleRenderers, ref opaqueDrawSettings, opaqueFilterSettings);
StopStereoRendering(m_CurrCamera, ref context, frameRenderingConfiguration);
}
private void OpaqueTexturePass(ref ScriptableRenderContext context, FrameRenderingConfiguration frameRenderingConfiguration)
{
var opaqueScaler = m_OpaqueScalerValues[(int)m_Asset.OpaqueDownsampling];

if (m_RequireDepthTexture)
{
CommandBuffer cmd = CommandBufferPool.Get("After Opaque");
cmd.SetGlobalTexture(CameraRenderTargetID.depth, m_DepthRT);
bool setRenderTarget = false;
RenderTargetIdentifier depthRT = m_DepthRT;

}
else
cmd.DisableShaderKeyword(kMSAADepthKeyword);
cmd.SetGlobalTexture(CameraRenderTargetID.depth, m_CopyDepth);
cmd.SetGlobalTexture(m_DepthOnlyPass.depthTextureID, m_CopyDepth);
}
if (setRenderTarget)

// This also means we don't do a depth copy
bool doesDepthPrepass = CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DepthPrePass);
if (!doesDepthPrepass)
{
depthRTDesc.bindMS = msaaSamples > 1;
depthRTDesc.msaaSamples = msaaSamples;
}
if (doesDepthPrepass)
m_DepthOnlyPass.BindSurface(cmd, baseDesc, msaaSamples);
//if (!doesDepthPrepass)
//{
// depthRTDesc.bindMS = msaaSamples > 1;
// depthRTDesc.msaaSamples = msaaSamples;
//}
cmd.GetTemporaryRT(CameraRenderTargetID.depth, depthRTDesc, FilterMode.Point);
//cmd.GetTemporaryRT(CameraRenderTargetID.depth, depthRTDesc, FilterMode.Point);
if (!doesDepthPrepass)
{

9
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs


using System;
using System.Collections.Generic;
using UnityEngine.Rendering;
using UnityEngine.XR;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{

{
if (CoreUtils.HasFlag(renderingConfiguration, FrameRenderingConfiguration.Stereo))
context.StopMultiEye(camera);
}
public static int GetRenderTargetDepthSlice(bool stereoRendering)
{
if (stereoRendering && XRSettings.eyeTextureDesc.dimension == TextureDimension.Tex2DArray)
return -1;
else
return 0;
}
public static void GetLightCookieMatrix(VisibleLight light, out Matrix4x4 cookieMatrix)

2
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/DepthCopy.hlsl


for (int i = 0; i < samples; ++i)
outDepth = DEPTH_OP(LOAD(uv, i), outDepth);
return outDepth;
#else
return SAMPLE(uv);

8
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes.meta


fileFormatVersion: 2
guid: c2a16f045b3148e4f9d0d62614a81a61
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

78
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DepthOnlyPass.cs


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class DepthOnlyPass : ScriptableRenderPass
{
public int depthTextureID { get; private set; }
public RenderTargetIdentifier depthTexture { get; private set; }
const string kProfilerTag = "Depth Prepass Setup";
const string kCommandBufferTag = "Depth Prepass";
int kDepthBufferBits = 32;
bool m_Disposed;
FilterRenderersSettings m_FilterSettings;
public DepthOnlyPass(RenderTextureFormat[] inputColorAttachments, RenderTextureFormat inputDepthAttachment) :
base(inputColorAttachments, inputDepthAttachment)
{
RegisterShaderPassName("DepthOnly");
depthTextureID = Shader.PropertyToID("_CameraDepthTexture");
depthTexture = new RenderTargetIdentifier(depthTextureID);
m_Disposed = true;
m_FilterSettings = new FilterRenderersSettings(true)
{
renderQueueRange = RenderQueueRange.opaque
};
}
public override void BindSurface(CommandBuffer cmd, RenderTextureDescriptor attachmentDescriptor, int samples)
{
attachmentDescriptor.colorFormat = depthAttachment;
attachmentDescriptor.depthBufferBits = kDepthBufferBits;
if (samples > 1)
{
attachmentDescriptor.bindMS = samples > 1;
attachmentDescriptor.msaaSamples = samples;
}
cmd.GetTemporaryRT(depthTextureID, attachmentDescriptor, FilterMode.Point);
m_Disposed = false;
}
public override void Execute(ScriptableRenderContext context, Camera camera, ref CullResults cullResults, bool stereoRendering)
{
CommandBuffer cmd = CommandBufferPool.Get(kCommandBufferTag);
using (new ProfilingSample(cmd, kProfilerTag))
{
int depthSlice = LightweightPipeline.GetRenderTargetDepthSlice(stereoRendering);
CoreUtils.SetRenderTarget(cmd, depthTexture, ClearFlag.Depth, 0, CubemapFace.Unknown, depthSlice);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
var opaqueDrawSettings = new DrawRendererSettings(camera, m_ShaderPassNames[0]);
opaqueDrawSettings.sorting.flags = SortFlags.CommonOpaque;
if (stereoRendering)
{
context.StartMultiEye(camera);
context.DrawRenderers(cullResults.visibleRenderers, ref opaqueDrawSettings, m_FilterSettings);
context.StopMultiEye(camera);
}
else
context.DrawRenderers(cullResults.visibleRenderers, ref opaqueDrawSettings, m_FilterSettings);
}
cmd.SetGlobalTexture(depthTextureID, depthTexture);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void Dispose(CommandBuffer cmd)
{
if (!m_Disposed)
cmd.ReleaseTemporaryRT(depthTextureID);
}
}
}

11
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DepthOnlyPass.cs.meta


fileFormatVersion: 2
guid: 2b327960b30da614ca5f44f2fef0137a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

29
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScriptableRenderPass.cs


using System.Collections.Generic;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public abstract class ScriptableRenderPass
{
public ScriptableRenderPass(RenderTextureFormat[] inputColorAttachments, RenderTextureFormat inputDepthAttachment)
{
colorAttachments = inputColorAttachments;
depthAttachment = inputDepthAttachment;
}
public abstract void BindSurface(CommandBuffer cmd, RenderTextureDescriptor attachmentDescriptor, int samples);
public abstract void Execute(ScriptableRenderContext context, Camera camera, ref CullResults cullResults, bool stereoRendering);
public abstract void Dispose(CommandBuffer cmd);
public RenderTextureFormat[] colorAttachments { get; set; }
public RenderTextureFormat depthAttachment { get; set; }
protected List<ShaderPassName> m_ShaderPassNames = new List<ShaderPassName>();
public void RegisterShaderPassName(string passName)
{
m_ShaderPassNames.Add(new ShaderPassName(passName));
}
}
}

11
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScriptableRenderPass.cs.meta


fileFormatVersion: 2
guid: edba24b6007b9dd41824b4656ed8ebcf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

/ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShadowPass.cs.meta → /ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/LightweightShadowPass.cs.meta

/ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShadowPass.cs → /ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/LightweightShadowPass.cs

正在加载...
取消
保存