Esempio n. 1
0
        public static void RenderSingleCamera(LightweightRenderPipeline pipelineInstance, ScriptableRenderContext context, Camera camera, ref CullResults cullResults, IRendererSetup setup = null)
        {
            if (pipelineInstance == null)
            {
                Debug.LogError("Trying to render a camera with an invalid render pipeline instance.");
                return;
            }

            ScriptableCullingParameters cullingParameters;

            if (!CullResults.GetCullingParameters(camera, IsStereoEnabled(camera), out cullingParameters))
            {
                return;
            }

            CommandBuffer cmd = CommandBufferPool.Get(k_RenderCameraTag);

            using (new ProfilingSample(cmd, k_RenderCameraTag))
            {
                CameraData         cameraData;
                PipelineSettings   settings = pipelineInstance.settings;
                ScriptableRenderer renderer = pipelineInstance.renderer;
                InitializeCameraData(settings, camera, out cameraData);
                SetupPerCameraShaderConstants(cameraData);

                cullingParameters.shadowDistance = Mathf.Min(cameraData.maxShadowDistance, camera.farClipPlane);

                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

#if UNITY_EDITOR
                // Emit scene view UI
                if (cameraData.isSceneViewCamera)
                {
                    ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
                }
#endif
                CullResults.Cull(ref cullingParameters, context, ref cullResults);

                RenderingData renderingData;
                InitializeRenderingData(settings, ref cameraData, ref cullResults,
                                        renderer.maxVisibleAdditionalLights, renderer.maxPerObjectAdditionalLights, out renderingData);

                var setupToUse = setup;
                if (setupToUse == null)
                {
                    setupToUse = defaultRendererSetup;
                }

                renderer.Clear();
                setupToUse.Setup(renderer, ref renderingData);
                renderer.Execute(context, ref renderingData);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
            context.Submit();
#if UNITY_EDITOR
            Handles.DrawGizmos(camera);
#endif
        }