这篇文章的主要内容是讲Unity的内置可编程渲染管线LWRP的渲染流程。即这一帧内从开始到结束所经过的渲染步骤。
由于版本时效性,我写博文时所用的Unity版本和LWRP的package版本分别是:
Unity版本:2018.3.0f2 LWRP的版本为:4.10.0.preview
先上LWRP里面关于核心渲染步骤的源代码脚本(DefaultRendererSetup.cs):
using System;
using UnityEngine.Rendering;
using System.Collections.Generic;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
internal class DefaultRendererSetup : IRendererSetup
{
private DepthOnlyPass m_DepthOnlyPass;
private MainLightShadowCasterPass m_MainLightShadowCasterPass;
private AdditionalLightsShadowCasterPass m_AdditionalLightsShadowCasterPass;
private SetupForwardRenderingPass m_SetupForwardRenderingPass;
private ScreenSpaceShadowResolvePass m_ScreenSpaceShadowResolvePass;
private CreateLightweightRenderTexturesPass m_CreateLightweightRenderTexturesPass;
private BeginXRRenderingPass m_BeginXrRenderingPass;
private SetupLightweightConstanstPass m_SetupLightweightConstants;
private RenderOpaqueForwardPass m_RenderOpaqueForwardPass;
private OpaquePostProcessPass m_OpaquePostProcessPass;
private DrawSkyboxPass m_DrawSkyboxPass;
private CopyDepthPass m_CopyDepthPass;
private CopyColorPass m_CopyColorPass;
private RenderTransparentForwardPass m_RenderTransparentForwardPass;
private TransparentPostProcessPass m_TransparentPostProcessPass;
private FinalBlitPass m_FinalBlitPass;
private EndXRRenderingPass m_EndXrRenderingPass;
private CustomRenderPass m_CustomPass;
#if UNITY_EDITOR
private SceneViewDepthCopyPass m_SceneViewDepthCopyPass;
#endif
private RenderTargetHandle ColorAttachment;
private RenderTargetHandle DepthAttachment;
private RenderTargetHandle DepthTexture;
private RenderTargetHandle OpaqueColor;
private RenderTargetHandle MainLightShadowmap;
private RenderTargetHandle AdditionalLightsShadowmap;
private RenderTargetHandle ScreenSpaceShadowmap;
private List<IBeforeRender> m_BeforeRenderPasses = new List<IBeforeRender>(10);
[NonSerialized]
private bool m_Initialized = false;
private void Init()
{
if (m_Initialized)
return;
m_DepthOnlyPass = new DepthOnlyPass();
m_MainLightShadowCasterPass = new MainLightShadowCasterPass();
m_AdditionalLightsShadowCasterPass = new AdditionalLightsShadowCasterPass();
m_SetupForwardRenderingPass = new SetupForwardRenderingPass();
m_ScreenSpaceShadowResolvePass = new ScreenSpaceShadowResolvePass();
m_CreateLightweightRenderTexturesPass = new CreateLightweightRenderTexturesPass();
m_BeginXrRenderingPass = new BeginXRRenderingPass();
m_SetupLightweightConstants = new SetupLightweightConstanstPass();
m_RenderOpaqueForwardPass = new RenderOpaqueForwardPass();
m_OpaquePostProcessPass = new OpaquePostProcessPass();
m_DrawSkyboxPas