public static void RenderSingleCamera(ScriptableRenderContext context, Camera camera)
        {
            if (!camera.TryGetCullingParameters(IsStereoEnabled(camera), out var cullingParameters))
            {
                return;
            }

            var settings = asset;
            LWRPAdditionalCameraData additionalCameraData = null;

            if (camera.cameraType == CameraType.Game || camera.cameraType == CameraType.VR)
#if UNITY_2019_2_OR_NEWER
            { camera.gameObject.TryGetComponent(out additionalCameraData); }
#else
            { additionalCameraData = camera.gameObject.GetComponent <LWRPAdditionalCameraData>(); }
#endif

            InitializeCameraData(settings, camera, additionalCameraData, out var cameraData);
            SetupPerCameraShaderConstants(cameraData);

            ScriptableRenderer renderer = (additionalCameraData != null) ? additionalCameraData.scriptableRenderer : settings.scriptableRenderer;
            if (renderer == null)
            {
                Debug.LogWarning(string.Format("Trying to render {0} with an invalid renderer. Camera rendering will be skipped.", camera.name));
                return;
            }

#if UNITY_EDITOR
            string tag = camera.name;
#else
            string tag = k_RenderCameraTag;
#endif
            CommandBuffer cmd = CommandBufferPool.Get(tag);
            using (new ProfilingSample(cmd, tag))
            {
                renderer.Clear();
                renderer.SetupCullingParameters(ref cullingParameters, ref cameraData);

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

#if UNITY_EDITOR
                // Emit scene view UI
                if (cameraData.isSceneViewCamera)
                {
                    ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
                }
#endif

                var cullResults = context.Cull(ref cullingParameters);
                InitializeRenderingData(settings, ref cameraData, ref cullResults, out var renderingData);

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

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
            context.Submit();
        }
Esempio n. 2
0
        public static void RenderSingleCamera(ScriptableRenderContext context, Camera camera)
        {
            if (!camera.TryGetCullingParameters(IsStereoEnabled(camera), out var cullingParameters))
            {
                return;
            }

            var settings = asset;
            LWRPAdditionalCameraData additionalCameraData = null;

            if (camera.cameraType == CameraType.Game || camera.cameraType == CameraType.VR)
            {
                additionalCameraData = camera.gameObject.GetComponent <LWRPAdditionalCameraData>();
            }

            InitializeCameraData(settings, camera, additionalCameraData, out var cameraData);
            SetupPerCameraShaderConstants(cameraData);

            ScriptableRenderer renderer = (additionalCameraData != null) ? additionalCameraData.scriptableRenderer : settings.scriptableRenderer;

            if (renderer == null)
            {
                Debug.LogWarning(string.Format("Trying to render {0} with an invalid renderer. Camera rendering will be skipped.", camera.name));
                return;
            }

            camera.cullingMatrix = Matrix4x4.Ortho(-99999, 99999, -99999, 99999, 0.001f, 99999) *
                                   Matrix4x4.Translate(Vector3.forward * -99999 / 2f) *
                                   camera.worldToCameraMatrix;

            CommandBuffer cmd = CommandBufferPool.Get(camera.name);

            using (new ProfilingSample(cmd, camera.name))
            {
                renderer.Clear();
                renderer.SetupCullingParameters(ref cullingParameters, ref cameraData);

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

#if UNITY_EDITOR
                // Emit scene view UI
                if (cameraData.isSceneViewCamera)
                {
                    ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
                }
#endif

                var cullResults = context.Cull(ref cullingParameters);
                InitializeRenderingData(settings, ref cameraData, ref cullResults, out var renderingData);

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

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
            context.Submit();
        }
Esempio n. 3
0
        public static void RenderSingleCamera(LightweightRenderPipeline pipelineInstance, ScriptableRenderContext context, Camera camera)
        {
            if (pipelineInstance == null)
            {
                Debug.LogError("Trying to render a camera with an invalid render pipeline instance.");
                return;
            }

            if (!camera.TryGetCullingParameters(IsStereoEnabled(camera), out var cullingParameters))
            {
                return;
            }

            CommandBuffer cmd = CommandBufferPool.Get(k_RenderCameraTag);

            using (new ProfilingSample(cmd, k_RenderCameraTag))
            {
                ScriptableRenderer renderer = pipelineInstance.renderer;
                var settings = asset;
                LWRPAdditionalCameraData additionalCameraData = camera.gameObject.GetComponent <LWRPAdditionalCameraData>();
                InitializeCameraData(settings, camera, additionalCameraData, out var cameraData);
                SetupPerCameraShaderConstants(cameraData);

                // TODO: PerObjectCulling also affect reflection probes. Enabling it for now.
                // if (asset.additionalLightsRenderingMode == LightRenderingMode.Disabled ||
                //     asset.maxAdditionalLightsCount == 0)
                // {
                //     cullingParameters.cullingOptions |= CullingOptions.DisablePerObjectCulling;
                // }

                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

                var cullResults = context.Cull(ref cullingParameters);

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

                renderer.Clear();

                IRendererSetup rendererSetup = (additionalCameraData != null) ? additionalCameraData.rendererSetup : settings.rendererSetup;
                rendererSetup.Setup(renderer, ref renderingData);
                renderer.Execute(context, ref renderingData);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
            context.Submit();
        }
Esempio n. 4
0
        public static void RenderSingleCamera(LightweightRenderPipeline pipelineInstance, ScriptableRenderContext context, Camera camera, IRendererSetup setup = null)
        {
            if (pipelineInstance == null)
            {
                Debug.LogError("Trying to render a camera with an invalid render pipeline instance.");
                return;
            }

            if (!camera.TryGetCullingParameters(IsStereoEnabled(camera), out var cullingParameters))
            {
                return;
            }

            CommandBuffer cmd = CommandBufferPool.Get(k_RenderCameraTag);

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

                if (pipelineInstance.settings.additionalLightsRenderingMode == LightRenderingMode.Disabled ||
                    pipelineInstance.settings.maxAdditionalLights == 0)
                {
                    cullingParameters.cullingOptions |= CullingOptions.DisablePerObjectCulling;
                }

                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

                var cullResults = context.Cull(ref cullingParameters);

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

                renderer.Clear();

                var rendererSetup = setup ?? settings.rendererSetup;
                rendererSetup.Setup(renderer, ref renderingData);
                renderer.Execute(context, ref renderingData);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
            context.Submit();
        }
Esempio n. 5
0
        public static void RenderSingleCamera(ScriptableRenderContext context, Camera camera, Camera uiCamera = null)
        {
            if (!camera.TryGetCullingParameters(IsStereoEnabled(camera), out var cullingParameters))
            {
                return;
            }

            var settings = asset;
            LWRPAdditionalCameraData additionalCameraData = null;

            if (camera.cameraType == CameraType.Game || camera.cameraType == CameraType.VR || camera.cameraType == CameraType.Reflection)
            {
                additionalCameraData = camera.gameObject.GetComponent <LWRPAdditionalCameraData>();
            }

            InitializeCameraData(settings, camera, additionalCameraData, out var cameraData);
            SetupPerCameraShaderConstants(cameraData);

            ScriptableRenderer renderer = camera.name == FeedbackGlobals.FeedbackCamName ? settings.feedbackRenderer : (additionalCameraData != null) ? additionalCameraData.scriptableRenderer : settings.scriptableRenderer;

            // renderer = settings.scriptableRenderer;
            if (renderer == null)
            {
                Debug.LogWarning(string.Format("Trying to render {0} with an invalid renderer. Camera rendering will be skipped.", camera.name));
                return;
            }

            string        camera_tag_string = string.Format("{0},{1}", k_RenderCameraTag, camera.name);
            CommandBuffer cmd = CommandBufferPool.Get(camera_tag_string);

            using (new ProfilingSample(cmd, camera_tag_string))
            {
                renderer.Clear();
                renderer.SetupCullingParameters(ref cullingParameters, ref cameraData);
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

#if UNITY_EDITOR
                // Emit scene view UI
                if (cameraData.isSceneViewCamera)
                {
                    ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
                }
#endif

                var cullResults = context.Cull(ref cullingParameters);
                InitializeRenderingData(settings, ref cameraData, ref cullResults, out var renderingData);
                renderingData.uiCmaera = uiCamera;
                renderer.Setup(context, ref renderingData);
                renderer.Execute(context, ref renderingData);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
            context.Submit();
        }