private void BeginForwardRendering(ref ScriptableRenderContext context, FrameRenderingConfiguration renderingConfig, CameraContext cameraContext) { RenderTargetIdentifier colorRT = BuiltinRenderTextureType.CameraTarget; RenderTargetIdentifier depthRT = BuiltinRenderTextureType.None; StereoRendering.Start(ref context, renderingConfig, cameraContext.Camera); CommandBuffer cmd = CommandBufferPool.Get("SetCameraRenderTarget"); bool intermediateTexture = LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture); if (intermediateTexture) { if (!cameraContext.IsOffscreenCamera) { colorRT = m_TextureUtil.CurrCameraColorRT; } if (m_TextureUtil.RequireDepthTexture) { depthRT = m_DepthRT; } } ClearFlag clearFlag = ClearFlag.None; CameraClearFlags cameraClearFlags = cameraContext.Camera.clearFlags; if (cameraClearFlags != CameraClearFlags.Nothing) { clearFlag |= ClearFlag.Depth; if (cameraClearFlags == CameraClearFlags.Color || cameraClearFlags == CameraClearFlags.Skybox) { clearFlag |= ClearFlag.Color; } } m_TextureUtil.SetRenderTarget(cmd, colorRT, depthRT, cameraContext.Camera.backgroundColor, clearFlag); // If rendering to an intermediate RT we resolve viewport on blit due to offset not being supported // while rendering to a RT. if (!intermediateTexture && !LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DefaultViewport)) { cmd.SetViewport(cameraContext.Camera.pixelRect); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public void ShadowCollectPass(List <VisibleLight> visibleLights, ref ScriptableRenderContext context, ref LightData lightData, FrameRenderingConfiguration frameRenderingConfiguration, Camera currentCamera) { if (!m_ShadowSettings.screenSpace) { return; } CommandBuffer cmd = CommandBufferPool.Get("Collect Shadows"); SetShadowCollectPassKeywords(cmd, visibleLights[lightData.mainLightIndex], ref lightData); // TODO: Support RenderScale for the SSSM target. Should probably move allocation elsewhere, or at // least propogate RenderTextureDescriptor generation if (LightweightUtils.HasFlag(frameRenderingConfiguration, FrameRenderingConfiguration.Stereo)) { var desc = XRSettings.eyeTextureDesc; desc.depthBufferBits = 0; desc.colorFormat = m_ShadowSettings.screenspaceShadowmapTextureFormat; cmd.GetTemporaryRT(m_ScreenSpaceShadowMapRTID, desc, FilterMode.Bilinear); } else { cmd.GetTemporaryRT(m_ScreenSpaceShadowMapRTID, currentCamera.pixelWidth, currentCamera.pixelHeight, 0, FilterMode.Bilinear, m_ShadowSettings.screenspaceShadowmapTextureFormat); } // Note: The source isn't actually 'used', but there's an engine peculiarity (bug) that // doesn't like null sources when trying to determine a stereo-ized blit. So for proper // stereo functionality, we use the screen-space shadow map as the source (until we have // a better solution). // An alternative would be DrawProcedural, but that would require further changes in the shader. cmd.Blit(m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowsMaterial); StereoRendering.Start(ref context, frameRenderingConfiguration, currentCamera); context.ExecuteCommandBuffer(cmd); StereoRendering.Stop(ref context, frameRenderingConfiguration, currentCamera); CommandBufferPool.Release(cmd); }
private void DepthPass(ref ScriptableRenderContext context, FrameRenderingConfiguration frameRenderingConfiguration, FilterResults visibleRenderers, Camera camera) { CommandBuffer cmd = CommandBufferPool.Get("Depth Prepass"); m_TextureUtil.SetRenderTarget(cmd, m_DepthRT, camera.backgroundColor, ClearFlag.Depth); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); var opaqueDrawSettings = new DrawRendererSettings(camera, m_DepthPrepass); opaqueDrawSettings.sorting.flags = SortFlags.CommonOpaque; var opaqueFilterSettings = new FilterRenderersSettings(true) { renderQueueRange = RenderQueueRange.opaque }; StereoRendering.Start(ref context, frameRenderingConfiguration, camera); context.DrawRenderers(visibleRenderers, ref opaqueDrawSettings, opaqueFilterSettings); StereoRendering.Stop(ref context, frameRenderingConfiguration, camera); }