public void Setup(ScriptableRenderer renderer, ref RenderingData renderingData) { Init(); Camera camera = renderingData.cameraData.camera; renderer.SetupPerObjectLightIndices(ref renderingData.cullResults, ref renderingData.lightData); RenderTextureDescriptor baseDescriptor = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData); RenderTextureDescriptor shadowDescriptor = baseDescriptor; shadowDescriptor.dimension = TextureDimension.Tex2D; bool mainLightShadows = false; if (renderingData.shadowData.supportsMainLightShadows) { mainLightShadows = m_MainLightShadowCasterPass.Setup(MainLightShadowmap, ref renderingData); if (mainLightShadows) { renderer.EnqueuePass(m_MainLightShadowCasterPass); } } if (renderingData.shadowData.supportsAdditionalLightShadows) { bool additionalLightShadows = m_AdditionalLightsShadowCasterPass.Setup(AdditionalLightsShadowmap, ref renderingData, renderer.maxVisibleAdditionalLights); if (additionalLightShadows) { renderer.EnqueuePass(m_AdditionalLightsShadowCasterPass); } } bool resolveShadowsInScreenSpace = mainLightShadows && renderingData.shadowData.requiresScreenSpaceShadowResolve; bool requiresDepthPrepass = resolveShadowsInScreenSpace || renderingData.cameraData.isSceneViewCamera || (renderingData.cameraData.requiresDepthTexture && (!CanCopyDepth(ref renderingData.cameraData) || renderingData.cameraData.isOffscreenRender)); // For now VR requires a depth prepass until we figure out how to properly resolve texture2DMS in stereo requiresDepthPrepass |= renderingData.cameraData.isStereoEnabled; renderer.EnqueuePass(m_SetupForwardRenderingPass); /*if (requiresDepthPrepass) * { * m_DepthOnlyPass.Setup(baseDescriptor, DepthTexture, SampleCount.One); * renderer.EnqueuePass(m_DepthOnlyPass); * * foreach (var pass in camera.GetComponents<IAfterDepthPrePass>()) * renderer.EnqueuePass(pass.GetPassToEnqueue(m_DepthOnlyPass.descriptor, DepthTexture)); * }*/ // LINDEN DEPTH PASS if (true) { m_LindenDepthPass.Setup(baseDescriptor, DepthTexture); renderer.EnqueuePass(m_LindenDepthPass); } if (resolveShadowsInScreenSpace) { m_ScreenSpaceShadowResolvePass.Setup(baseDescriptor, ScreenSpaceShadowmap); renderer.EnqueuePass(m_ScreenSpaceShadowResolvePass); } bool requiresRenderToTexture = ScriptableRenderer.RequiresIntermediateColorTexture(ref renderingData.cameraData, baseDescriptor); RenderTargetHandle colorHandle = RenderTargetHandle.CameraTarget; RenderTargetHandle depthHandle = RenderTargetHandle.CameraTarget; if (requiresRenderToTexture) { colorHandle = ColorAttachment; depthHandle = DepthAttachment; var sampleCount = (SampleCount)renderingData.cameraData.msaaSamples; m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount); renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass); } if (renderingData.cameraData.isStereoEnabled) { renderer.EnqueuePass(m_BeginXrRenderingPass); } RendererConfiguration rendererConfiguration = ScriptableRenderer.GetRendererConfiguration(renderingData.lightData.additionalLightsCount); m_SetupLightweightConstants.Setup(renderer.maxVisibleAdditionalLights, renderer.perObjectLightIndices); renderer.EnqueuePass(m_SetupLightweightConstants); m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, ScriptableRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration); renderer.EnqueuePass(m_RenderOpaqueForwardPass); foreach (var pass in camera.GetComponents <IAfterOpaquePass>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } if (renderingData.cameraData.postProcessEnabled && renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessingContext)) { m_OpaquePostProcessPass.Setup(baseDescriptor, colorHandle); renderer.EnqueuePass(m_OpaquePostProcessPass); foreach (var pass in camera.GetComponents <IAfterOpaquePostProcess>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } } if (camera.clearFlags == CameraClearFlags.Skybox) { m_DrawSkyboxPass.Setup(colorHandle, depthHandle); renderer.EnqueuePass(m_DrawSkyboxPass); } foreach (var pass in camera.GetComponents <IAfterSkyboxPass>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } /*if (renderingData.cameraData.requiresDepthTexture && !requiresDepthPrepass) * { * m_CopyDepthPass.Setup(depthHandle, DepthTexture); * renderer.EnqueuePass(m_CopyDepthPass); * }*/ if (renderingData.cameraData.requiresOpaqueTexture) { m_CopyColorPass.Setup(colorHandle, OpaqueColor); renderer.EnqueuePass(m_CopyColorPass); } m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, rendererConfiguration); renderer.EnqueuePass(m_RenderTransparentForwardPass); foreach (var pass in camera.GetComponents <IAfterTransparentPass>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } if (!renderingData.cameraData.isStereoEnabled && renderingData.cameraData.postProcessEnabled) { m_TransparentPostProcessPass.Setup(baseDescriptor, colorHandle, BuiltinRenderTextureType.CameraTarget); renderer.EnqueuePass(m_TransparentPostProcessPass); } else if (!renderingData.cameraData.isOffscreenRender && colorHandle != RenderTargetHandle.CameraTarget) { m_FinalBlitPass.Setup(baseDescriptor, colorHandle); renderer.EnqueuePass(m_FinalBlitPass); } foreach (var pass in camera.GetComponents <IAfterRender>()) { renderer.EnqueuePass(pass.GetPassToEnqueue()); } if (renderingData.cameraData.isStereoEnabled) { renderer.EnqueuePass(m_EndXrRenderingPass); } /*#if UNITY_EDITOR * if (renderingData.cameraData.isSceneViewCamera) * { * m_SceneViewDepthCopyPass.Setup(DepthTexture); * renderer.EnqueuePass(m_SceneViewDepthCopyPass); * } #endif*/ }
public void Setup(ScriptableRenderer renderer, ref RenderingData renderingData) { Init(); Camera camera = renderingData.cameraData.camera; camera.GetComponents(m_BeforeRenderPasses); renderer.SetupPerObjectLightIndices(ref renderingData.cullResults, ref renderingData.lightData); RenderTextureDescriptor baseDescriptor = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData); RenderTextureDescriptor shadowDescriptor = baseDescriptor; ClearFlag clearFlag = ScriptableRenderer.GetCameraClearFlag(renderingData.cameraData.camera); shadowDescriptor.dimension = TextureDimension.Tex2D; bool requiresRenderToTexture = ScriptableRenderer.RequiresIntermediateColorTexture(ref renderingData.cameraData, baseDescriptor) || m_BeforeRenderPasses.Count != 0; //var requiresRenderToTexture = true; RenderTargetHandle colorHandle = RenderTargetHandle.CameraTarget; RenderTargetHandle depthHandle = RenderTargetHandle.CameraTarget; if (requiresRenderToTexture) { colorHandle = ColorAttachment; depthHandle = DepthAttachment; var sampleCount = (SampleCount)renderingData.cameraData.msaaSamples; m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount); renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass); //FIX camera stacking with RT by liyingbo. Copy current screen content to the newly created RT. if (clearFlag == ClearFlag.Depth) { m_CopyToRenderTexturePass.Setup(baseDescriptor, sampleCount, RenderTargetHandle.CameraTarget, ColorCopyIntermediateHandle, colorHandle); renderer.EnqueuePass(m_CopyToRenderTexturePass); } } #if UNUSED_FEATURE foreach (var pass in m_BeforeRenderPasses) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle, clearFlag)); } #endif bool mainLightShadows = false; if (renderingData.shadowData.supportsMainLightShadows) { mainLightShadows = m_MainLightShadowCasterPass.Setup(MainLightShadowmap, ref renderingData); if (mainLightShadows) { renderer.EnqueuePass(m_MainLightShadowCasterPass); } } if (renderingData.shadowData.supportsAdditionalLightShadows) { bool additionalLightShadows = m_AdditionalLightsShadowCasterPass.Setup(AdditionalLightsShadowmap, ref renderingData, renderer.maxVisibleAdditionalLights); if (additionalLightShadows) { renderer.EnqueuePass(m_AdditionalLightsShadowCasterPass); } } bool resolveShadowsInScreenSpace = mainLightShadows && renderingData.shadowData.requiresScreenSpaceShadowResolve; bool requiresDepthPrepass = resolveShadowsInScreenSpace || renderingData.cameraData.isSceneViewCamera || (renderingData.cameraData.requiresDepthTexture && (!CanCopyDepth(ref renderingData.cameraData) || renderingData.cameraData.isOffscreenRender)); #if VR_SUPPORT // For now VR requires a depth prepass until we figure out how to properly resolve texture2DMS in stereo requiresDepthPrepass |= renderingData.cameraData.isStereoEnabled; #endif renderer.EnqueuePass(m_SetupForwardRenderingPass); if (requiresDepthPrepass) { m_DepthOnlyPass.Setup(baseDescriptor, DepthTexture, SampleCount.One); renderer.EnqueuePass(m_DepthOnlyPass); #if UNUSED_FEATURE foreach (var pass in camera.GetComponents <IAfterDepthPrePass>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(m_DepthOnlyPass.descriptor, DepthTexture)); } #endif } if (resolveShadowsInScreenSpace) { m_ScreenSpaceShadowResolvePass.Setup(baseDescriptor, ScreenSpaceShadowmap); renderer.EnqueuePass(m_ScreenSpaceShadowResolvePass); } #if VR_SUPPORT if (renderingData.cameraData.isStereoEnabled) { renderer.EnqueuePass(m_BeginXrRenderingPass); } #endif RendererConfiguration rendererConfiguration = ScriptableRenderer.GetRendererConfiguration(renderingData.lightData.additionalLightsCount); m_SetupLightweightConstants.Setup(renderer.maxVisibleAdditionalLights, renderer.perObjectLightIndices); renderer.EnqueuePass(m_SetupLightweightConstants); #if UNUSED_FEATURE // If a before all render pass executed we expect it to clear the color render target if (m_BeforeRenderPasses.Count != 0) { clearFlag = ClearFlag.None; } #endif m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, clearFlag, camera.backgroundColor, rendererConfiguration); renderer.EnqueuePass(m_RenderOpaqueForwardPass); //used by CharacterAddPass foreach (var pass in camera.GetComponents <IAfterOpaquePass>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } if (renderingData.cameraData.postProcessEnabled && renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessingContext)) { m_OpaquePostProcessPass.Setup(baseDescriptor, colorHandle); renderer.EnqueuePass(m_OpaquePostProcessPass); #if UNUSED_FEATURE foreach (var pass in camera.GetComponents <IAfterOpaquePostProcess>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } #endif } if (camera.clearFlags == CameraClearFlags.Skybox && RenderSettings.skybox != null) { m_DrawSkyboxPass.Setup(colorHandle, depthHandle); renderer.EnqueuePass(m_DrawSkyboxPass); } #if UNUSED_FEATURE foreach (var pass in camera.GetComponents <IAfterSkyboxPass>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } #endif if (renderingData.cameraData.requiresDepthTexture && !requiresDepthPrepass) { m_CopyDepthPass.Setup(depthHandle, DepthTexture); renderer.EnqueuePass(m_CopyDepthPass); } if (renderingData.cameraData.requiresOpaqueTexture) { m_CopyColorPass.Setup(colorHandle, OpaqueColor); renderer.EnqueuePass(m_CopyColorPass); } m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, rendererConfiguration); renderer.EnqueuePass(m_RenderTransparentForwardPass); if (renderingData.cameraData.requiresRenderedTexture) { m_CopyRenderedPass.Setup(baseDescriptor, colorHandle, depthHandle, RenderedColor); renderer.EnqueuePass(m_CopyRenderedPass); foreach (var pass in camera.GetComponents <IAfterTransparentPass>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } } //copied to above, within rendered texture condition #if UNUSED_FEATURE foreach (var pass in camera.GetComponents <IAfterTransparentPass>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } #endif if (renderingData.cameraData.postProcessEnabled) { m_TransparentPostProcessPass.Setup(baseDescriptor, colorHandle, BuiltinRenderTextureType.CameraTarget); renderer.EnqueuePass(m_TransparentPostProcessPass); } else if (!renderingData.cameraData.isOffscreenRender && colorHandle != RenderTargetHandle.CameraTarget) { m_FinalBlitPass.Setup(baseDescriptor, colorHandle); renderer.EnqueuePass(m_FinalBlitPass); } #if UNUSED_FEATURE foreach (var pass in camera.GetComponents <IAfterRender>()) { renderer.EnqueuePass(pass.GetPassToEnqueue()); } #endif #if VR_SUPPORT if (renderingData.cameraData.isStereoEnabled) { renderer.EnqueuePass(m_EndXrRenderingPass); } #endif #if UNITY_EDITOR if (renderingData.cameraData.isSceneViewCamera) { m_SceneViewDepthCopyPass.Setup(DepthTexture); renderer.EnqueuePass(m_SceneViewDepthCopyPass); } #endif }
public void Setup(ScriptableRenderer renderer, ref RenderingData renderingData) { Init(); Camera camera = renderingData.cameraData.camera; renderer.postProcessingContext.camera = camera; camera.GetComponents(m_BeforeRenderPasses); renderer.SetupPerObjectLightIndices(ref renderingData.cullResults, ref renderingData.lightData); RenderTextureDescriptor baseDescriptor = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData); RenderTextureDescriptor shadowDescriptor = baseDescriptor; ClearFlag clearFlag = ScriptableRenderer.GetCameraClearFlag(renderingData.cameraData.camera); shadowDescriptor.dimension = TextureDimension.Tex2D; bool requiresRenderToTexture = ScriptableRenderer.RequiresIntermediateColorTexture(ref renderingData.cameraData, baseDescriptor) || m_BeforeRenderPasses.Count != 0; RenderTargetHandle colorHandle = RenderTargetHandle.CameraTarget; RenderTargetHandle depthHandle = RenderTargetHandle.CameraTarget; var sampleCount = (SampleCount)renderingData.cameraData.msaaSamples; if (requiresRenderToTexture) { colorHandle = ColorAttachment; depthHandle = DepthAttachment; m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount); renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass); } foreach (var pass in m_BeforeRenderPasses) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle, clearFlag)); } bool mainLightShadows = false; if (renderingData.shadowData.supportsMainLightShadows) { mainLightShadows = m_MainLightShadowCasterPass.Setup(MainLightShadowmap, ref renderingData); if (mainLightShadows) { renderer.EnqueuePass(m_MainLightShadowCasterPass); } } if (renderingData.shadowData.supportsMainCharacterShadows) { if (m_MainCharacterShadowCasterPass.Setup(MainCharacterShadowmap, ref renderingData)) { renderer.EnqueuePass(m_MainCharacterShadowCasterPass); } } bool renderDeepShadowMap = renderingData.shadowData.supportsDeepShadowMaps; if (renderDeepShadowMap) { renderDeepShadowMap &= _DeepShadowCasterPass.Setup(renderer, ref renderingData); if (renderDeepShadowMap) { renderer.EnqueuePass(_DeepShadowCasterPass); } } if (renderingData.shadowData.supportsAdditionalLightShadows) { bool additionalLightShadows = m_AdditionalLightsShadowCasterPass.Setup(AdditionalLightsShadowmap, ref renderingData, renderer.maxVisibleAdditionalLights); if (additionalLightShadows) { renderer.EnqueuePass(m_AdditionalLightsShadowCasterPass); } } bool resolveShadowsInScreenSpace = mainLightShadows && renderingData.shadowData.requiresScreenSpaceShadowResolve; bool requiresDepthPrepass = resolveShadowsInScreenSpace || renderingData.cameraData.isSceneViewCamera || (renderingData.cameraData.requiresDepthTexture && (!CanCopyDepth(ref renderingData.cameraData) || renderingData.cameraData.isOffscreenRender)); // For now VR requires a depth prepass until we figure out how to properly resolve texture2DMS in stereo requiresDepthPrepass |= renderingData.cameraData.isStereoEnabled; renderer.EnqueuePass(m_SetupForwardRenderingPass); bool supportsOIT = renderingData.cameraData.supportsOIT; requiresDepthPrepass |= supportsOIT; if (requiresDepthPrepass) { m_DepthOnlyPass.Setup(baseDescriptor, DepthTexture, sampleCount); renderer.EnqueuePass(m_DepthOnlyPass); depthHandle = DepthTexture; foreach (var pass in camera.GetComponents <IAfterDepthPrePass>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(m_DepthOnlyPass.descriptor, DepthTexture)); } if (supportsOIT) { _CopyDepthForOITPass.Setup(depthHandle, OITDepthTexture); renderer.EnqueuePass(_CopyDepthForOITPass); _OITDepthOnlyPass.Setup(baseDescriptor, OITDepthTexture, sampleCount); renderer.EnqueuePass(_OITDepthOnlyPass); } } bool requiresDepthNormalsPass = renderingData.cameraData.requiresDepthNormalsTexture; if (requiresDepthNormalsPass) { m_DepthNormalsPass.Setup(baseDescriptor, DepthNormalsTexture, depthHandle, requiresDepthPrepass, sampleCount); renderer.EnqueuePass(m_DepthNormalsPass); } if (renderDeepShadowMap) { if (_ScreenSpaceDeepShadowMapsPass.Setup(renderer, baseDescriptor, ScreenSpaceDeepShadowLut, ref renderingData)) { renderer.EnqueuePass(_ScreenSpaceDeepShadowMapsPass); } } if (resolveShadowsInScreenSpace) { m_ScreenSpaceShadowResolvePass.Setup(baseDescriptor, ScreenSpaceShadowmap); renderer.EnqueuePass(m_ScreenSpaceShadowResolvePass); } if (renderingData.cameraData.isStereoEnabled) { renderer.EnqueuePass(m_BeginXrRenderingPass); } RendererConfiguration rendererConfiguration = ScriptableRenderer.GetRendererConfiguration(renderingData.lightData.additionalLightsCount); m_SetupLightweightConstants.Setup(renderer.maxVisibleAdditionalLights, renderer.perObjectLightIndices); renderer.EnqueuePass(m_SetupLightweightConstants); // If a before all render pass executed we expect it to clear the color render target if (m_BeforeRenderPasses.Count != 0) { clearFlag = ClearFlag.None; } m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, clearFlag, camera.backgroundColor, rendererConfiguration, requiresDepthPrepass); renderer.EnqueuePass(m_RenderOpaqueForwardPass); foreach (var pass in camera.GetComponents <IAfterOpaquePass>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } if (renderingData.cameraData.postProcessEnabled) { renderingData.cameraData.postProcessLayer.SetupContext(renderer.postProcessingContext); if (renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessingContext)) { m_OpaquePostProcessPass.Setup(baseDescriptor, colorHandle); renderer.EnqueuePass(m_OpaquePostProcessPass); foreach (var pass in camera.GetComponents <IAfterOpaquePostProcess>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } } } if (camera.clearFlags == CameraClearFlags.Skybox && RenderSettings.skybox != null) { m_DrawSkyboxPass.Setup(colorHandle, depthHandle); renderer.EnqueuePass(m_DrawSkyboxPass); } foreach (var pass in camera.GetComponents <IAfterSkyboxPass>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } if (renderingData.cameraData.requiresDepthTexture && !requiresDepthPrepass) { m_CopyDepthPass.Setup(depthHandle, DepthTexture); renderer.EnqueuePass(m_CopyDepthPass); } if (renderingData.cameraData.requiresOpaqueTexture) { m_CopyColorPass.Setup(colorHandle, OpaqueColor); renderer.EnqueuePass(m_CopyColorPass); } //_RenderWeightedOITForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, rendererConfiguration, sampleCount); //renderer.EnqueuePass(_RenderWeightedOITForwardPass); if (supportsOIT) { if (_RenderMomentOITForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, rendererConfiguration, sampleCount, renderingData)) { renderer.EnqueuePass(_RenderMomentOITForwardPass); } } m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, rendererConfiguration); renderer.EnqueuePass(m_RenderTransparentForwardPass); foreach (var pass in camera.GetComponents <IAfterTransparentPass>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } if (renderingData.cameraData.postProcessEnabled) { m_TransparentPostProcessPass.Setup(baseDescriptor, colorHandle, BuiltinRenderTextureType.CameraTarget); renderer.EnqueuePass(m_TransparentPostProcessPass); } else if (!renderingData.cameraData.isOffscreenRender && colorHandle != RenderTargetHandle.CameraTarget) { m_FinalBlitPass.Setup(baseDescriptor, colorHandle); renderer.EnqueuePass(m_FinalBlitPass); } foreach (var pass in camera.GetComponents <IAfterRender>()) { renderer.EnqueuePass(pass.GetPassToEnqueue()); } if (renderingData.cameraData.isStereoEnabled) { renderer.EnqueuePass(m_EndXrRenderingPass); } #if UNITY_EDITOR if (renderingData.cameraData.isSceneViewCamera) { m_SceneViewDepthCopyPass.Setup(DepthTexture); renderer.EnqueuePass(m_SceneViewDepthCopyPass); } #endif }
public void Setup(ScriptableRenderer renderer, ref RenderingData renderingData) { Init(); Camera camera = renderingData.cameraData.camera; renderer.SetupPerObjectLightIndices(ref renderingData.cullResults, ref renderingData.lightData); RenderTextureDescriptor baseDescriptor = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData); RenderTextureDescriptor shadowDescriptor = baseDescriptor; shadowDescriptor.dimension = TextureDimension.Tex2D; bool mainLightShadows = false; if (renderingData.shadowData.supportsMainLightShadows) { mainLightShadows = m_MainLightShadowCasterPass.Setup(m_MainLightShadowmap, ref renderingData); if (mainLightShadows) { renderer.EnqueuePass(m_MainLightShadowCasterPass); } } if (renderingData.shadowData.supportsAdditionalLightShadows) { bool additionalLightShadows = m_AdditionalLightsShadowCasterPass.Setup(m_AdditionalLightsShadowmap, ref renderingData, renderer.maxVisibleAdditionalLights); if (additionalLightShadows) { renderer.EnqueuePass(m_AdditionalLightsShadowCasterPass); } } bool resolveShadowsInScreenSpace = mainLightShadows && renderingData.shadowData.requiresScreenSpaceShadowResolve; bool requiresDepthPrepass = resolveShadowsInScreenSpace || renderingData.cameraData.isSceneViewCamera || (renderingData.cameraData.requiresDepthTexture && (!CanCopyDepth(ref renderingData.cameraData))); // For now VR requires a depth prepass until we figure out how to properly resolve texture2DMS in stereo requiresDepthPrepass |= renderingData.cameraData.isStereoEnabled; renderer.EnqueuePass(m_SetupForwardRenderingPass); camera.GetComponents(m_AfterDepthpasses); camera.GetComponents(m_AfterOpaquePasses); camera.GetComponents(m_AfterOpaquePostProcessPasses); camera.GetComponents(m_AfterSkyboxPasses); camera.GetComponents(m_AfterTransparentPasses); camera.GetComponents(m_AfterRenderPasses); if (requiresDepthPrepass) { m_DepthOnlyPass.Setup(baseDescriptor, m_DepthTexture, SampleCount.One); renderer.EnqueuePass(m_DepthOnlyPass); foreach (var pass in m_AfterDepthpasses) { renderer.EnqueuePass(pass.GetPassToEnqueue(m_DepthOnlyPass.descriptor, m_DepthTexture)); } } if (resolveShadowsInScreenSpace) { m_ScreenSpaceShadowResolvePass.Setup(baseDescriptor, m_ScreenSpaceShadowmap); renderer.EnqueuePass(m_ScreenSpaceShadowResolvePass); } bool requiresRenderToTexture = RequiresIntermediateColorTexture(ref renderingData.cameraData, baseDescriptor) || m_AfterDepthpasses.Count != 0 || m_AfterOpaquePasses.Count != 0 || m_AfterOpaquePostProcessPasses.Count != 0 || m_AfterSkyboxPasses.Count != 0 || m_AfterTransparentPasses.Count != 0 || m_AfterRenderPasses.Count != 0; RenderTargetHandle colorHandle = RenderTargetHandle.CameraTarget; RenderTargetHandle depthHandle = RenderTargetHandle.CameraTarget; var sampleCount = (SampleCount)renderingData.cameraData.msaaSamples; if (requiresRenderToTexture) { colorHandle = m_ColorAttachment; depthHandle = m_DepthAttachment; m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount); renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass); } if (renderingData.cameraData.isStereoEnabled) { renderer.EnqueuePass(m_BeginXrRenderingPass); } var rendererConfiguration = ScriptableRenderer.GetRendererConfiguration(renderingData.lightData.additionalLightsCount); m_SetupLightweightConstants.Setup(renderer.maxVisibleAdditionalLights, renderer.perObjectLightIndices); renderer.EnqueuePass(m_SetupLightweightConstants); m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, ScriptableRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration); renderer.EnqueuePass(m_RenderOpaqueForwardPass); foreach (var pass in m_AfterOpaquePasses) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } if (renderingData.cameraData.postProcessEnabled && renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessingContext)) { m_CreatePostOpaqueColorPass.Setup(baseDescriptor, m_ColorAttachmentAfterOpaquePost, sampleCount); renderer.EnqueuePass(m_CreatePostOpaqueColorPass); m_OpaquePostProcessPass.Setup(baseDescriptor, colorHandle, m_ColorAttachmentAfterOpaquePost, true, false); renderer.EnqueuePass(m_OpaquePostProcessPass); colorHandle = m_ColorAttachmentAfterOpaquePost; foreach (var pass in m_AfterOpaquePostProcessPasses) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } } if (camera.clearFlags == CameraClearFlags.Skybox) { m_DrawSkyboxPass.Setup(colorHandle, depthHandle); renderer.EnqueuePass(m_DrawSkyboxPass); } foreach (var pass in m_AfterSkyboxPasses) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } if (renderingData.cameraData.requiresDepthTexture && !requiresDepthPrepass) { m_CopyDepthPass.Setup(depthHandle, m_DepthTexture); renderer.EnqueuePass(m_CopyDepthPass); } if (renderingData.cameraData.requiresOpaqueTexture) { m_CopyColorPass.Setup(colorHandle, m_OpaqueColor); renderer.EnqueuePass(m_CopyColorPass); } m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, rendererConfiguration); renderer.EnqueuePass(m_RenderTransparentForwardPass); foreach (var pass in m_AfterTransparentPasses) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } bool afterRenderExists = m_AfterRenderPasses.Count != 0; // if we have additional filters // we need to stay in a RT if (afterRenderExists) { // perform post with src / dest the same if (!renderingData.cameraData.isStereoEnabled && renderingData.cameraData.postProcessEnabled) { m_CreatePostTransparentColorPass.Setup(baseDescriptor, m_ColorAttachmentAfterTransparentPost, sampleCount); renderer.EnqueuePass(m_CreatePostTransparentColorPass); m_PostProcessPass.Setup(baseDescriptor, colorHandle, m_ColorAttachmentAfterTransparentPost, false, false); renderer.EnqueuePass(m_PostProcessPass); colorHandle = m_ColorAttachmentAfterTransparentPost; } //execute after passes foreach (var pass in m_AfterRenderPasses) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle)); } //now blit into the final target if (colorHandle != RenderTargetHandle.CameraTarget) { m_FinalBlitPass.Setup(baseDescriptor, colorHandle); renderer.EnqueuePass(m_FinalBlitPass); } } else { if (!renderingData.cameraData.isStereoEnabled && renderingData.cameraData.postProcessEnabled) { m_PostProcessPass.Setup(baseDescriptor, colorHandle, RenderTargetHandle.CameraTarget, false, (!renderingData.cameraData.isStereoEnabled && renderingData.cameraData.camera.targetTexture == null)); renderer.EnqueuePass(m_PostProcessPass); } else if (colorHandle != RenderTargetHandle.CameraTarget) { m_FinalBlitPass.Setup(baseDescriptor, colorHandle); renderer.EnqueuePass(m_FinalBlitPass); } } if (renderingData.cameraData.isStereoEnabled) { renderer.EnqueuePass(m_EndXrRenderingPass); } #if UNITY_EDITOR if (renderingData.cameraData.isSceneViewCamera) { m_SceneViewDepthCopyPass.Setup(m_DepthTexture); renderer.EnqueuePass(m_SceneViewDepthCopyPass); } #endif }