public void Setup(ScriptableRenderer renderer, ref RenderingData renderingData) { Init(); renderer.SetupPerObjectLightIndices(ref renderingData.cullResults, ref renderingData.lightData); RenderTextureDescriptor baseDescriptor = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData); RenderTextureDescriptor shadowDescriptor = baseDescriptor; shadowDescriptor.dimension = TextureDimension.Tex2D; renderer.EnqueuePass(m_SetupForwardRenderingPass); RenderTargetHandle colorHandle = RenderTargetHandle.CameraTarget; RenderTargetHandle depthHandle = RenderTargetHandle.CameraTarget; var sampleCount = (SampleCount)renderingData.cameraData.msaaSamples; m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount); renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass); Camera camera = renderingData.cameraData.camera; var perObjectFlags = ScriptableRenderer.GetPerObjectLightFlags(renderingData.lightData.mainLightIndex, 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, perObjectFlags); renderer.EnqueuePass(m_RenderOpaqueForwardPass); }
public void Setup(ScriptableRenderer renderer, ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) { Init(); renderer.Clear(); renderer.SetupPerObjectLightIndices(ref cullResults, ref renderingData.lightData); RenderTextureDescriptor baseDescriptor = ScriptableRenderer.CreateRTDesc(ref renderingData.cameraData); RenderTextureDescriptor shadowDescriptor = baseDescriptor; shadowDescriptor.dimension = TextureDimension.Tex2D; renderer.EnqueuePass(m_SetupForwardRenderingPass); RenderTargetHandle colorHandle = RenderTargetHandle.CameraTarget; RenderTargetHandle depthHandle = RenderTargetHandle.CameraTarget; var sampleCount = (SampleCount)renderingData.cameraData.msaaSamples; m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount); renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass); Camera camera = renderingData.cameraData.camera; bool dynamicBatching = renderingData.supportsDynamicBatching; RendererConfiguration rendererConfiguration = ScriptableRenderer.GetRendererConfiguration(renderingData.lightData.totalAdditionalLightsCount); m_SetupLightweightConstants.Setup(renderer.maxVisibleLocalLights, renderer.perObjectLightIndices); renderer.EnqueuePass(m_SetupLightweightConstants); m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, ScriptableRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration, dynamicBatching); renderer.EnqueuePass(m_RenderOpaqueForwardPass); }
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; 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); } 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); foreach (var pass in camera.GetComponents <IAfterMainLightShadowCasterPass>()) { renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, MainLightShadowmap)); } } } 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(baseDescriptor, DepthTexture)); } } 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); 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 && 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); } 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 }