浏览代码

Remove Pass Dependency on Renderer (#1794)

* Remove pass dependency on renderer. This causes issues with the custom passes as cleanup is not handeld properly.
/main
GitHub 6 年前
当前提交
43aa9fb2
共有 25 个文件被更改,包括 218 次插入171 次删除
  1. 11
      TestProjects/LWGraphicsTest/Assets/TestScripts/CustomLWPipe.cs
  2. 45
      com.unity.render-pipelines.lightweight/LWRP/DefaultRendererSetup.cs
  3. 2
      com.unity.render-pipelines.lightweight/LWRP/IRendererSetup.cs
  4. 25
      com.unity.render-pipelines.lightweight/LWRP/LightweightForwardRenderer.cs
  5. 4
      com.unity.render-pipelines.lightweight/LWRP/LightweightPipeline.cs
  6. 6
      com.unity.render-pipelines.lightweight/LWRP/Passes/BeginXRRenderingPass.cs
  7. 19
      com.unity.render-pipelines.lightweight/LWRP/Passes/CopyColorPass.cs
  8. 21
      com.unity.render-pipelines.lightweight/LWRP/Passes/CopyDepthPass.cs
  9. 9
      com.unity.render-pipelines.lightweight/LWRP/Passes/CreateLightweightRenderTexturesPass.cs
  10. 17
      com.unity.render-pipelines.lightweight/LWRP/Passes/DepthOnlyPass.cs
  11. 8
      com.unity.render-pipelines.lightweight/LWRP/Passes/DirectionalShadowsPass.cs
  12. 6
      com.unity.render-pipelines.lightweight/LWRP/Passes/DrawSkyboxPass.cs
  13. 7
      com.unity.render-pipelines.lightweight/LWRP/Passes/EndXRRenderingPass.cs
  14. 13
      com.unity.render-pipelines.lightweight/LWRP/Passes/FinalBlitPass.cs
  15. 13
      com.unity.render-pipelines.lightweight/LWRP/Passes/LightweightForwardPass.cs
  16. 24
      com.unity.render-pipelines.lightweight/LWRP/Passes/LocalShadowsPass.cs
  17. 13
      com.unity.render-pipelines.lightweight/LWRP/Passes/OpaquePostProcessPass.cs
  18. 19
      com.unity.render-pipelines.lightweight/LWRP/Passes/RenderOpaqueForwardPass.cs
  19. 20
      com.unity.render-pipelines.lightweight/LWRP/Passes/RenderTransparentForwardPass.cs
  20. 15
      com.unity.render-pipelines.lightweight/LWRP/Passes/SceneViewDepthCopy.cs
  21. 14
      com.unity.render-pipelines.lightweight/LWRP/Passes/ScreenSpaceShadowResolvePass.cs
  22. 16
      com.unity.render-pipelines.lightweight/LWRP/Passes/ScriptableRenderPass.cs
  23. 6
      com.unity.render-pipelines.lightweight/LWRP/Passes/SetupForwardRenderingPass.cs
  24. 42
      com.unity.render-pipelines.lightweight/LWRP/Passes/SetupLightweightConstanstPass.cs
  25. 14
      com.unity.render-pipelines.lightweight/LWRP/Passes/TransparentPostProcessPass.cs

11
TestProjects/LWGraphicsTest/Assets/TestScripts/CustomLWPipe.cs


if (m_Initialized)
return;
m_SetupForwardRenderingPass = new SetupForwardRenderingPass(renderer);
m_CreateLightweightRenderTexturesPass = new CreateLightweightRenderTexturesPass(renderer);
m_SetupLightweightConstants = new SetupLightweightConstanstPass(renderer);
m_RenderOpaqueForwardPass = new RenderOpaqueForwardPass(renderer);
m_SetupForwardRenderingPass = new SetupForwardRenderingPass();
m_CreateLightweightRenderTexturesPass = new CreateLightweightRenderTexturesPass();
m_SetupLightweightConstants = new SetupLightweightConstanstPass();
m_RenderOpaqueForwardPass = new RenderOpaqueForwardPass(renderer.GetMaterial(MaterialHandles.Error));
m_Initialized = true;
}

renderer.Clear();
renderer.SetupPerObjectLightIndices(ref cullResults, ref renderingData.lightData);
RenderTextureDescriptor baseDescriptor = renderer.CreateRTDesc(ref renderingData.cameraData);
RenderTextureDescriptor baseDescriptor = LightweightForwardRenderer.CreateRTDesc(ref renderingData.cameraData);
RenderTextureDescriptor shadowDescriptor = baseDescriptor;
shadowDescriptor.dimension = TextureDimension.Tex2D;

bool dynamicBatching = renderingData.supportsDynamicBatching;
RendererConfiguration rendererConfiguration = LightweightForwardRenderer.GetRendererConfiguration(renderingData.lightData.totalAdditionalLightsCount);
m_SetupLightweightConstants.Setup(renderer.maxVisibleLocalLights, renderer.perObjectLightIndices);
renderer.EnqueuePass(m_SetupLightweightConstants);
m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, LightweightForwardRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration, dynamicBatching);

45
com.unity.render-pipelines.lightweight/LWRP/DefaultRendererSetup.cs


if (m_Initialized)
return;
m_DepthOnlyPass = new DepthOnlyPass(renderer);
m_DirectionalShadowPass = new DirectionalShadowsPass(renderer);
m_LocalShadowPass = new LocalShadowsPass(renderer);
m_SetupForwardRenderingPass = new SetupForwardRenderingPass(renderer);
m_ScreenSpaceShadowResovePass = new ScreenSpaceShadowResolvePass(renderer);
m_CreateLightweightRenderTexturesPass = new CreateLightweightRenderTexturesPass(renderer);
m_BeginXrRenderingPass = new BeginXRRenderingPass(renderer);
m_SetupLightweightConstants = new SetupLightweightConstanstPass(renderer);
m_RenderOpaqueForwardPass = new RenderOpaqueForwardPass(renderer);
m_OpaquePostProcessPass = new OpaquePostProcessPass(renderer);
m_DrawSkyboxPass = new DrawSkyboxPass(renderer);
m_CopyDepthPass = new CopyDepthPass(renderer);
m_CopyColorPass = new CopyColorPass(renderer);
m_RenderTransparentForwardPass = new RenderTransparentForwardPass(renderer);
m_TransparentPostProcessPass = new TransparentPostProcessPass(renderer);
m_FinalBlitPass = new FinalBlitPass(renderer);
m_EndXrRenderingPass = new EndXRRenderingPass(renderer);
m_DepthOnlyPass = new DepthOnlyPass();
m_DirectionalShadowPass = new DirectionalShadowsPass();
m_LocalShadowPass = new LocalShadowsPass();
m_SetupForwardRenderingPass = new SetupForwardRenderingPass();
m_ScreenSpaceShadowResovePass = new ScreenSpaceShadowResolvePass(renderer.GetMaterial(MaterialHandles.ScrenSpaceShadow));
m_CreateLightweightRenderTexturesPass = new CreateLightweightRenderTexturesPass();
m_BeginXrRenderingPass = new BeginXRRenderingPass();
m_SetupLightweightConstants = new SetupLightweightConstanstPass();
m_RenderOpaqueForwardPass = new RenderOpaqueForwardPass(renderer.GetMaterial(MaterialHandles.Error));
m_OpaquePostProcessPass = new OpaquePostProcessPass();
m_DrawSkyboxPass = new DrawSkyboxPass();
m_CopyDepthPass = new CopyDepthPass(renderer.GetMaterial(MaterialHandles.DepthCopy));
m_CopyColorPass = new CopyColorPass(renderer.GetMaterial(MaterialHandles.Sampling));
m_RenderTransparentForwardPass = new RenderTransparentForwardPass(renderer.GetMaterial(MaterialHandles.Error));
m_TransparentPostProcessPass = new TransparentPostProcessPass();
m_FinalBlitPass = new FinalBlitPass(renderer.GetMaterial(MaterialHandles.Blit));
m_EndXrRenderingPass = new EndXRRenderingPass();
m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(renderer);
m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(renderer.GetMaterial(MaterialHandles.DepthCopy));
#endif
// RenderTexture format depends on camera and pipeline (HDR, non HDR, etc)

renderer.Clear();
renderer.SetupPerObjectLightIndices(ref cullResults, ref renderingData.lightData);
RenderTextureDescriptor baseDescriptor = renderer.CreateRTDesc(ref renderingData.cameraData);
RenderTextureDescriptor baseDescriptor = LightweightForwardRenderer.CreateRTDesc(ref renderingData.cameraData);
RenderTextureDescriptor shadowDescriptor = baseDescriptor;
shadowDescriptor.dimension = TextureDimension.Tex2D;

if (renderingData.shadowData.renderLocalShadows)
{
m_LocalShadowPass.Setup(LocalShadowmap);
m_LocalShadowPass.Setup(LocalShadowmap, renderer.maxVisibleLocalLights);
renderer.EnqueuePass(m_LocalShadowPass);
}

bool dynamicBatching = renderingData.supportsDynamicBatching;
RendererConfiguration rendererConfiguration = LightweightForwardRenderer.GetRendererConfiguration(renderingData.lightData.totalAdditionalLightsCount);
m_SetupLightweightConstants.Setup(renderer.maxVisibleLocalLights, renderer.perObjectLightIndices);
renderer.EnqueuePass(m_SetupLightweightConstants);
m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, LightweightForwardRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration,dynamicBatching);

renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessRenderContext))
{
m_OpaquePostProcessPass.Setup(baseDescriptor, colorHandle);
m_OpaquePostProcessPass.Setup(renderer.postProcessRenderContext, baseDescriptor, colorHandle);
renderer.EnqueuePass(m_OpaquePostProcessPass);
}

if (renderingData.cameraData.postProcessEnabled)
{
m_TransparentPostProcessPass.Setup(baseDescriptor, colorHandle);
m_TransparentPostProcessPass.Setup(renderer.postProcessRenderContext, baseDescriptor, colorHandle);
renderer.EnqueuePass(m_TransparentPostProcessPass);
}
else if (!renderingData.cameraData.isOffscreenRender && colorHandle != RenderTargetHandle.CameraTarget)

2
com.unity.render-pipelines.lightweight/LWRP/IRendererSetup.cs


{
public interface IRendererSetup
{
}
}

25
com.unity.render-pipelines.lightweight/LWRP/LightweightForwardRenderer.cs


public ComputeBuffer perObjectLightIndices { get; private set; }
public FilterRenderersSettings opaqueFilterSettings { get; private set; }
public FilterRenderersSettings transparentFilterSettings { get; private set; }
Material[] m_Materials;
readonly Material[] m_Materials;
m_Materials = new Material[(int)MaterialHandles.Count]
this.pipelineAsset = pipelineAsset;
m_Materials = new[]
{
CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader"),
CoreUtils.CreateEngineMaterial(pipelineAsset.copyDepthShader),

};
postProcessRenderContext = new PostProcessRenderContext();
}
opaqueFilterSettings = new FilterRenderersSettings(true)
{
renderQueueRange = RenderQueueRange.opaque,
};
transparentFilterSettings = new FilterRenderersSettings(true)
{
renderQueueRange = RenderQueueRange.transparent,
};
}
public LightweightPipelineAsset pipelineAsset { get; private set; }
public void Dispose()
{

CoreUtils.Destroy(m_Materials[i]);
}
public RenderTextureDescriptor CreateRTDesc(ref CameraData cameraData, float scaler = 1.0f)
public static RenderTextureDescriptor CreateRTDesc(ref CameraData cameraData, float scaler = 1.0f)
{
Camera camera = cameraData.camera;
RenderTextureDescriptor desc;

CommandBuffer cmd = CommandBufferPool.Get("Release Resources");
for (int i = 0; i < m_ActiveRenderPassQueue.Count; ++i)
m_ActiveRenderPassQueue[i].Dispose(cmd);
m_ActiveRenderPassQueue[i].FrameCleanup(cmd);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

4
com.unity.render-pipelines.lightweight/LWRP/LightweightPipeline.cs


public LightweightPipelineAsset pipelineAsset { get; private set; }
private IRendererSetup m_DefaultRendererSetup;
private IRendererSetup defaultRendererSetup
{
get

List<int> m_LocalLightIndices = new List<int>();
bool m_IsCameraRendering;
private IRendererSetup m_DefaultRendererSetup;
public LightweightPipeline(LightweightPipelineAsset asset)
{

setup = defaultRendererSetup;
setup.Setup(m_Renderer, ref context, ref m_CullResults, ref renderingData);
m_Renderer.Execute(ref context, ref m_CullResults, ref renderingData);
}
#if UNITY_EDITOR

6
com.unity.render-pipelines.lightweight/LWRP/Passes/BeginXRRenderingPass.cs


{
public class BeginXRRenderingPass : ScriptableRenderPass
{
public BeginXRRenderingPass(LightweightForwardRenderer renderer) : base(renderer)
{}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults,
ref RenderingData renderingData)
{
Camera camera = renderingData.cameraData.camera;
context.StartMultiEye(camera);

19
com.unity.render-pipelines.lightweight/LWRP/Passes/CopyColorPass.cs


{
public class CopyColorPass : ScriptableRenderPass
{
Material m_SamplingMaterial;
private Material samplingMaterial { get; set; }
public CopyColorPass(LightweightForwardRenderer renderer) : base(renderer)
public CopyColorPass(Material samplingMaterial)
m_SamplingMaterial = renderer.GetMaterial(MaterialHandles.Sampling);
this.samplingMaterial = samplingMaterial;
m_SampleOffsetShaderHandle = Shader.PropertyToID("_SampleOffset");
}

this.destination = destination;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get("Copy Color");

RenderTextureDescriptor opaqueDesc = renderer.CreateRTDesc(ref renderingData.cameraData, opaqueScaler);
RenderTextureDescriptor opaqueDesc = LightweightForwardRenderer.CreateRTDesc(ref renderingData.cameraData, opaqueScaler);
RenderTargetIdentifier colorRT = source.Identifier();
RenderTargetIdentifier opaqueColorRT = destination.Identifier();

cmd.Blit(colorRT, opaqueColorRT);
break;
case Downsampling._4xBox:
m_SamplingMaterial.SetFloat(m_SampleOffsetShaderHandle, 2);
cmd.Blit(colorRT, opaqueColorRT, m_SamplingMaterial, 0);
samplingMaterial.SetFloat(m_SampleOffsetShaderHandle, 2);
cmd.Blit(colorRT, opaqueColorRT, samplingMaterial, 0);
break;
case Downsampling._4xBilinear:
cmd.Blit(colorRT, opaqueColorRT);

}
public override void Dispose(CommandBuffer cmd)
public override void FrameCleanup(CommandBuffer cmd)
{
if (destination != RenderTargetHandle.CameraTarget)
{

21
com.unity.render-pipelines.lightweight/LWRP/Passes/CopyDepthPass.cs


{
public class CopyDepthPass : ScriptableRenderPass
{
Material m_DepthCopyMaterial;
private Material depthCopyMaterial { get; set; }
public CopyDepthPass(LightweightForwardRenderer renderer) : base(renderer)
public CopyDepthPass(Material depthCopyMaterial)
m_DepthCopyMaterial = renderer.GetMaterial(MaterialHandles.DepthCopy);
this.depthCopyMaterial = depthCopyMaterial;
public void Setup(RenderTargetHandle source, RenderTargetHandle destination)
{

public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
RenderTextureDescriptor descriptor = renderer.CreateRTDesc(ref renderingData.cameraData);
RenderTextureDescriptor descriptor = LightweightForwardRenderer.CreateRTDesc(ref renderingData.cameraData);
descriptor.colorFormat = RenderTextureFormat.Depth;
descriptor.depthBufferBits = 32; //TODO: fix this ;
descriptor.msaaSamples = 1;

cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
}
cmd.Blit(depthSurface, copyDepthSurface, m_DepthCopyMaterial);
cmd.Blit(depthSurface, copyDepthSurface, depthCopyMaterial);
}
else
{

LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, m_DepthCopyMaterial);
LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, depthCopyMaterial);
public override void Dispose(CommandBuffer cmd)
public override void FrameCleanup(CommandBuffer cmd)
{
if (destination != RenderTargetHandle.CameraTarget)
{

9
com.unity.render-pipelines.lightweight/LWRP/Passes/CreateLightweightRenderTexturesPass.cs


{
public class CreateLightweightRenderTexturesPass : ScriptableRenderPass
{
public CreateLightweightRenderTexturesPass(LightweightForwardRenderer renderer) : base(renderer)
{}
const int k_DepthStencilBufferBits = 32;
private RenderTargetHandle colorAttachmentHandle { get; set; }
private RenderTargetHandle depthAttachmentHandle { get; set; }

descriptor = baseDescriptor;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get("");
if (colorAttachmentHandle != RenderTargetHandle.CameraTarget)

CommandBufferPool.Release(cmd);
}
public override void Dispose(CommandBuffer cmd)
public override void FrameCleanup(CommandBuffer cmd)
{
if (colorAttachmentHandle != RenderTargetHandle.CameraTarget)
{

17
com.unity.render-pipelines.lightweight/LWRP/Passes/DepthOnlyPass.cs


private RenderTargetHandle depthAttachmentHandle { get; set; }
private RenderTextureDescriptor descriptor { get; set; }
public FilterRenderersSettings opaqueFilterSettings { get; private set; }
public void Setup(
RenderTextureDescriptor baseDescriptor,

descriptor = baseDescriptor;
}
public DepthOnlyPass(LightweightForwardRenderer renderer) : base(renderer)
public DepthOnlyPass()
opaqueFilterSettings = new FilterRenderersSettings(true)
{
renderQueueRange = RenderQueueRange.opaque,
};
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get(k_DepthPrepassTag);
using (new ProfilingSample(cmd, k_DepthPrepassTag))

{
Camera camera = renderingData.cameraData.camera;
context.StartMultiEye(camera);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.opaqueFilterSettings);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, opaqueFilterSettings);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.opaqueFilterSettings);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, opaqueFilterSettings);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

public override void Dispose(CommandBuffer cmd)
public override void FrameCleanup(CommandBuffer cmd)
{
if (depthAttachmentHandle != RenderTargetHandle.CameraTarget)
{

8
com.unity.render-pipelines.lightweight/LWRP/Passes/DirectionalShadowsPass.cs


private RenderTargetHandle destination { get; set; }
public DirectionalShadowsPass(LightweightForwardRenderer renderer) : base(renderer)
public DirectionalShadowsPass()
{
RegisterShaderPassName("ShadowCaster");

this.destination = destination;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
{
if (renderingData.shadowData.renderDirectionalShadows)
{

}
public override void Dispose(CommandBuffer cmd)
public override void FrameCleanup(CommandBuffer cmd)
{
if (m_DirectionalShadowmapTexture)
{

6
com.unity.render-pipelines.lightweight/LWRP/Passes/DrawSkyboxPass.cs


{
public class DrawSkyboxPass : ScriptableRenderPass
{
public DrawSkyboxPass(LightweightForwardRenderer renderer) : base(renderer)
{}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults,
public override void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
{
context.DrawSkybox(renderingData.cameraData.camera);

7
com.unity.render-pipelines.lightweight/LWRP/Passes/EndXRRenderingPass.cs


{
public class EndXRRenderingPass : ScriptableRenderPass
{
public EndXRRenderingPass(LightweightForwardRenderer renderer) : base(renderer)
{}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
{
Camera camera = renderingData.cameraData.camera;
context.StopMultiEye(camera);

13
com.unity.render-pipelines.lightweight/LWRP/Passes/FinalBlitPass.cs


{
public class FinalBlitPass : ScriptableRenderPass
{
Material m_BlitMaterial;
private Material blitMaterial { get; set; }
public FinalBlitPass(LightweightForwardRenderer renderer) : base(renderer)
public FinalBlitPass(Material blitMaterial)
m_BlitMaterial = renderer.GetMaterial(MaterialHandles.Blit);
this.blitMaterial = blitMaterial;
}
public void Setup(RenderTextureDescriptor baseDescriptor, RenderTargetHandle colorAttachmentHandle)

}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
Material material = renderingData.cameraData.isStereoEnabled ? null : m_BlitMaterial;
Material material = renderingData.cameraData.isStereoEnabled ? null : blitMaterial;
RenderTargetIdentifier sourceRT = colorAttachmentHandle.Identifier();
CommandBuffer cmd = CommandBufferPool.Get("Final Blit Pass");

13
com.unity.render-pipelines.lightweight/LWRP/Passes/LightweightForwardPass.cs


private RenderTargetHandle colorAttachmentHandle { get; set; }
private RenderTargetHandle depthAttachmentHandle { get; set; }
private RenderTextureDescriptor descriptor { get; set; }
private Material errorMaterial { get; set; }
Material m_ErrorMaterial;
protected LightweightForwardPass(LightweightForwardRenderer renderer) : base(renderer)
protected LightweightForwardPass(Material errorMaterial)
m_ErrorMaterial = renderer.GetMaterial(MaterialHandles.Error);
m_LegacyShaderPassNames = new List<ShaderPassName>();
m_LegacyShaderPassNames.Add(new ShaderPassName("Always"));
m_LegacyShaderPassNames.Add(new ShaderPassName("ForwardBase"));

m_LegacyShaderPassNames.Add(new ShaderPassName("VertexLM"));
this.errorMaterial = errorMaterial;
RegisterShaderPassName("LightweightForward");
RegisterShaderPassName("SRPDefaultUnlit");

[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")]
protected void RenderObjectsWithError(ref ScriptableRenderContext context, ref CullResults cullResults, Camera camera, FilterRenderersSettings filterSettings, SortFlags sortFlags)
{
if (m_ErrorMaterial != null)
if (errorMaterial != null)
{
DrawRendererSettings errorSettings = new DrawRendererSettings(camera, m_LegacyShaderPassNames[0]);
for (int i = 1; i < m_LegacyShaderPassNames.Count; ++i)

errorSettings.rendererConfiguration = RendererConfiguration.None;
errorSettings.SetOverrideMaterial(m_ErrorMaterial, 0);
errorSettings.SetOverrideMaterial(errorMaterial, 0);
context.DrawRenderers(cullResults.visibleRenderers, ref errorSettings, filterSettings);
}
}

24
com.unity.render-pipelines.lightweight/LWRP/Passes/LocalShadowsPass.cs


using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline

private RenderTargetHandle destination { get; set; }
public LocalShadowsPass(LightweightForwardRenderer renderer) : base(renderer)
public LocalShadowsPass()
int maxVisibleLocalLights = renderer.maxVisibleLocalLights;
m_LocalShadowMatrices = new Matrix4x4[maxVisibleLocalLights];
m_LocalLightSlices = new ShadowSliceData[maxVisibleLocalLights];
m_LocalShadowStrength = new float[maxVisibleLocalLights];
m_LocalShadowMatrices = new Matrix4x4[0];
m_LocalLightSlices = new ShadowSliceData[0];
m_LocalShadowStrength = new float[0];
LocalShadowConstantBuffer._LocalWorldToShadowAtlas = Shader.PropertyToID("_LocalWorldToShadowAtlas");
LocalShadowConstantBuffer._LocalShadowStrength = Shader.PropertyToID("_LocalShadowStrength");

: RenderTextureFormat.Depth;
}
public void Setup(RenderTargetHandle destination)
public void Setup(RenderTargetHandle destination, int maxVisibleLocalLights)
if (m_LocalShadowMatrices.Length != maxVisibleLocalLights)
{
m_LocalShadowMatrices = new Matrix4x4[maxVisibleLocalLights];
m_LocalLightSlices = new ShadowSliceData[maxVisibleLocalLights];
m_LocalShadowStrength = new float[maxVisibleLocalLights];
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults,
ref RenderingData renderingData)
{
if (renderingData.shadowData.renderLocalShadows)
{

}
public override void Dispose(CommandBuffer cmd)
public override void FrameCleanup(CommandBuffer cmd)
{
if (m_LocalShadowmapTexture)
{

13
com.unity.render-pipelines.lightweight/LWRP/Passes/OpaquePostProcessPass.cs


using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
public OpaquePostProcessPass(LightweightForwardRenderer renderer) : base(renderer)
{}
private PostProcessRenderContext postContext { get; set; }
PostProcessRenderContext postProcessRenderContext,
this.postContext = postProcessRenderContext;
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults,
ref RenderingData renderingData)
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref renderingData.cameraData, descriptor.colorFormat, source, colorAttachmentHandle.Identifier(), true);
LightweightPipeline.RenderPostProcess(cmd, postContext, ref renderingData.cameraData, descriptor.colorFormat, source, colorAttachmentHandle.Identifier(), true);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

19
com.unity.render-pipelines.lightweight/LWRP/Passes/RenderOpaqueForwardPass.cs


{
public class RenderOpaqueForwardPass : LightweightForwardPass
{
public FilterRenderersSettings opaqueFilterSettings { get; private set; }
public RenderOpaqueForwardPass(LightweightForwardRenderer renderer) : base(renderer)
{}
public RenderOpaqueForwardPass(Material errorMaterial) : base(errorMaterial)
{
opaqueFilterSettings = new FilterRenderersSettings(true)
{
renderQueueRange = RenderQueueRange.opaque,
};
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get(k_RenderOpaquesTag);
using (new ProfilingSample(cmd, k_RenderOpaquesTag))

Camera camera = renderingData.cameraData.camera;
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonOpaque, rendererConfiguration, dynamicBatching);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.opaqueFilterSettings);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, opaqueFilterSettings);
RenderObjectsWithError(ref context, ref cullResults, camera, renderer.opaqueFilterSettings, SortFlags.None);
RenderObjectsWithError(ref context, ref cullResults, camera, opaqueFilterSettings, SortFlags.None);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

20
com.unity.render-pipelines.lightweight/LWRP/Passes/RenderTransparentForwardPass.cs


{
const string k_RenderTransparentsTag = "Render Transparents";
public RenderTransparentForwardPass(LightweightForwardRenderer renderer) : base(renderer)
{}
private FilterRenderersSettings transparentFilterSettings { get; set; }
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public RenderTransparentForwardPass(Material errorMaterial) : base(errorMaterial)
{
transparentFilterSettings = new FilterRenderersSettings(true)
{
renderQueueRange = RenderQueueRange.transparent,
};
}
public override void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get(k_RenderTransparentsTag);
using (new ProfilingSample(cmd, k_RenderTransparentsTag))

Camera camera = renderingData.cameraData.camera;
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonTransparent, rendererConfiguration, dynamicBatching);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.transparentFilterSettings);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, transparentFilterSettings);
RenderObjectsWithError(ref context, ref cullResults, camera, renderer.transparentFilterSettings, SortFlags.None);
RenderObjectsWithError(ref context, ref cullResults, camera, transparentFilterSettings, SortFlags.None);
}
context.ExecuteCommandBuffer(cmd);

15
com.unity.render-pipelines.lightweight/LWRP/Passes/SceneViewDepthCopy.cs


public class SceneViewDepthCopyPass : ScriptableRenderPass
{
private RenderTargetHandle source { get; set; }
private Material depthCopyMaterial { get; set; }
public SceneViewDepthCopyPass(LightweightForwardRenderer renderer) : base(renderer)
{}
public SceneViewDepthCopyPass(Material depthCopyMaterial)
{
this.depthCopyMaterial = depthCopyMaterial;
}
public void Setup(RenderTargetHandle source)
{

public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
cmd.SetGlobalTexture("_CameraDepthAttachment", source.Identifier());
cmd.Blit(source.Identifier(), BuiltinRenderTextureType.CameraTarget, renderer.GetMaterial(MaterialHandles.DepthCopy));
cmd.Blit(source.Identifier(), BuiltinRenderTextureType.CameraTarget, depthCopyMaterial);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

14
com.unity.render-pipelines.lightweight/LWRP/Passes/ScreenSpaceShadowResolvePass.cs


public class ScreenSpaceShadowResolvePass : ScriptableRenderPass
{
RenderTextureFormat m_ColorFormat;
Material m_ScreenSpaceShadowsMaterial;
private Material screenSpaceShadowsMaterial { get; set; }
public ScreenSpaceShadowResolvePass(LightweightForwardRenderer renderer) : base(renderer)
public ScreenSpaceShadowResolvePass(Material screenSpaceShadowsMaterial)
m_ScreenSpaceShadowsMaterial = renderer.GetMaterial(MaterialHandles.ScrenSpaceShadow);
this.screenSpaceShadowsMaterial = screenSpaceShadowsMaterial;
}
private RenderTargetHandle colorAttachmentHandle { get; set; }

descriptor = baseDescriptor;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults,
ref RenderingData renderingData)
{
if (renderingData.shadowData.renderedDirectionalShadowQuality == LightShadows.None)
return;

RenderTargetIdentifier screenSpaceOcclusionTexture = colorAttachmentHandle.Identifier();
SetRenderTarget(cmd, screenSpaceOcclusionTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
ClearFlag.Color | ClearFlag.Depth, Color.white, descriptor.dimension);
cmd.Blit(screenSpaceOcclusionTexture, screenSpaceOcclusionTexture, m_ScreenSpaceShadowsMaterial);
cmd.Blit(screenSpaceOcclusionTexture, screenSpaceOcclusionTexture, screenSpaceShadowsMaterial);
if (renderingData.cameraData.isStereoEnabled)
{

CommandBufferPool.Release(cmd);
}
public override void Dispose(CommandBuffer cmd)
public override void FrameCleanup(CommandBuffer cmd)
{
if (colorAttachmentHandle != RenderTargetHandle.CameraTarget)
{

16
com.unity.render-pipelines.lightweight/LWRP/Passes/ScriptableRenderPass.cs


using System;
using System.Collections.Generic;
using UnityEngine.Rendering;

{
protected LightweightForwardRenderer renderer { get; }
protected ScriptableRenderPass(LightweightForwardRenderer renderer)
{
this.renderer = renderer;
}
public virtual void Dispose(CommandBuffer cmd)
public virtual void FrameCleanup(CommandBuffer cmd)
public abstract void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData);
public abstract void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData);
protected void RegisterShaderPassName(string passName)
{

6
com.unity.render-pipelines.lightweight/LWRP/Passes/SetupForwardRenderingPass.cs


{
public class SetupForwardRenderingPass : ScriptableRenderPass
{
public SetupForwardRenderingPass(LightweightForwardRenderer renderer) : base(renderer)
{}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults,
ref RenderingData renderingData)
{
// SetupCameraProperties does the following:
// Setup Camera RenderTarget and Viewport

42
com.unity.render-pipelines.lightweight/LWRP/Passes/SetupLightweightConstanstPass.cs


Vector4[] m_LightDistanceAttenuations;
Vector4[] m_LightSpotDirections;
Vector4[] m_LightSpotAttenuations;
private int maxVisibleLocalLights { get; set; }
private ComputeBuffer perObjectLightIndices { get; set; }
public SetupLightweightConstanstPass(LightweightForwardRenderer renderer) : base(renderer)
public SetupLightweightConstanstPass()
{
PerCameraBuffer._MainLightPosition = Shader.PropertyToID("_MainLightPosition");
PerCameraBuffer._MainLightColor = Shader.PropertyToID("_MainLightColor");

PerCameraBuffer._AdditionalLightSpotAttenuation = Shader.PropertyToID("_AdditionalLightSpotAttenuation");
PerCameraBuffer._LightIndexBuffer = Shader.PropertyToID("_LightIndexBuffer");
int maxVisibleLocalLights = renderer.maxVisibleLocalLights;
m_LightPositions = new Vector4[maxVisibleLocalLights];
m_LightColors = new Vector4[maxVisibleLocalLights];
m_LightDistanceAttenuations = new Vector4[maxVisibleLocalLights];
m_LightSpotDirections = new Vector4[maxVisibleLocalLights];
m_LightSpotAttenuations = new Vector4[maxVisibleLocalLights];
m_LightPositions = new Vector4[0];
m_LightColors = new Vector4[0];
m_LightDistanceAttenuations = new Vector4[0];
m_LightSpotDirections = new Vector4[0];
m_LightSpotAttenuations = new Vector4[0];
}
public void Setup(int maxVisibleLocalLights, ComputeBuffer perObjectLightIndices)
{
this.maxVisibleLocalLights = maxVisibleLocalLights;
this.perObjectLightIndices = perObjectLightIndices;
if (m_LightColors.Length != maxVisibleLocalLights)
{
m_LightPositions = new Vector4[maxVisibleLocalLights];
m_LightColors = new Vector4[maxVisibleLocalLights];
m_LightDistanceAttenuations = new Vector4[maxVisibleLocalLights];
m_LightSpotDirections = new Vector4[maxVisibleLocalLights];
m_LightSpotAttenuations = new Vector4[maxVisibleLocalLights];
}
}
void InitializeLightConstants(List<VisibleLight> lights, int lightIndex, out Vector4 lightPos, out Vector4 lightColor, out Vector4 lightDistanceAttenuation, out Vector4 lightSpotDir,

void SetupShaderLightConstants(CommandBuffer cmd, ref LightData lightData)
{
// Clear to default all light constant data
for (int i = 0; i < renderer.maxVisibleLocalLights; ++i)
for (int i = 0; i < maxVisibleLocalLights; ++i)
InitializeLightConstants(lightData.visibleLights, -1, out m_LightPositions[i],
out m_LightColors[i],
out m_LightDistanceAttenuations[i],

void SetupAdditionalLightConstants(CommandBuffer cmd, ref LightData lightData)
{
int maxVisibleLocalLights = renderer.maxVisibleLocalLights;
List<VisibleLight> lights = lightData.visibleLights;
if (lightData.totalAdditionalLightsCount > 0)
{

// if not using a compute buffer, engine will set indices in 2 vec4 constants
// unity_4LightIndices0 and unity_4LightIndices1
if (renderer.perObjectLightIndices != null)
cmd.SetGlobalBuffer("_LightIndexBuffer", renderer.perObjectLightIndices);
if (perObjectLightIndices != null)
cmd.SetGlobalBuffer("_LightIndexBuffer", perObjectLightIndices);
}
else
{

CoreUtils.SetKeyword(cmd, "SOFTPARTICLES_ON", cameraData.requiresSoftParticles);
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get("SetupShaderConstants");
SetupShaderLightConstants(cmd, ref renderingData.lightData);

14
com.unity.render-pipelines.lightweight/LWRP/Passes/TransparentPostProcessPass.cs


using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
public TransparentPostProcessPass(LightweightForwardRenderer renderer) : base(renderer)
{}
private PostProcessRenderContext postContext { get; set; }
PostProcessRenderContext postProcessRenderContext,
this.postContext = postProcessRenderContext;
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref renderingData.cameraData, descriptor.colorFormat, colorAttachmentHandle.Identifier(), BuiltinRenderTextureType.CameraTarget, false);
LightweightPipeline.RenderPostProcess(cmd, postContext, ref renderingData.cameraData, descriptor.colorFormat, colorAttachmentHandle.Identifier(), BuiltinRenderTextureType.CameraTarget, false);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
正在加载...
取消
保存