Beispiel #1
0
        /// <summary>
        /// Do forward rendering (UI, transparents, etc.)
        /// </summary>
        /// <param name="scene">Scene</param>
        /// <param name="deferredDisabledComponents">Components</param>
        private void DoForward(Scene scene, IEnumerable <SceneObject> deferredDisabledComponents)
        {
#if DEBUG
            Stopwatch swCull = Stopwatch.StartNew();
#endif
            var toCullNotDeferred = deferredDisabledComponents.Where(s => s.Is <ICullable>()).Select(s => s.Get <ICullable>());

            bool draw = false;
            if (scene.PerformFrustumCulling)
            {
                //Frustum culling
                draw = this.cullManager.Cull(this.DrawContext.CameraVolume, CullIndexDrawIndex, toCullNotDeferred);
            }
            else
            {
                draw = true;
            }

            if (draw)
            {
                var groundVolume = scene.GetSceneVolume();
                if (groundVolume != null)
                {
                    //Ground culling
                    draw = this.cullManager.Cull(groundVolume, CullIndexDrawIndex, toCullNotDeferred);
                }
            }
#if DEBUG
            swCull.Stop();

            this.frameStats.DisabledDeferredCull = swCull.ElapsedTicks;
#endif

            if (draw)
            {
#if DEBUG
                Stopwatch swDraw = Stopwatch.StartNew();
#endif
                //Set forward mode
                this.DrawContext.DrawerMode = DrawerModes.Forward;

                //Draw scene
                this.DrawResultComponents(this.DrawContext, CullIndexDrawIndex, deferredDisabledComponents);

                //Set deferred mode
                this.DrawContext.DrawerMode = DrawerModes.Deferred;
#if DEBUG
                swDraw.Stop();

                this.frameStats.DisabledDeferredDraw = swDraw.ElapsedTicks;
#endif
            }
        }
        /// <summary>
        /// Do rendering
        /// </summary>
        /// <param name="scene">Scene</param>
        /// <param name="components">Components</param>
        private void DoRender(Scene scene, IEnumerable <SceneObject> components)
        {
            #region Preparation
#if DEBUG
            Stopwatch swPreparation = Stopwatch.StartNew();
#endif
            //Set default render target and depth buffer, and clear it
            var graphics = this.Game.Graphics;
            graphics.SetDefaultViewport();
            graphics.SetDefaultRenderTarget();
#if DEBUG
            swPreparation.Stop();

            this.frameStats.ForwardStart = swPreparation.ElapsedTicks;
#endif
            #endregion

            //Forward rendering
            if (components.Any())
            {
                #region Cull
#if DEBUG
                Stopwatch swCull = Stopwatch.StartNew();
#endif
                var toCullVisible = components.Where(s => s.Is <ICullable>()).Select(s => s.Get <ICullable>());

                bool draw = false;
                if (scene.PerformFrustumCulling)
                {
                    //Frustum culling
                    draw = this.cullManager.Cull(this.DrawContext.CameraVolume, CullIndexDrawIndex, toCullVisible);
                }
                else
                {
                    draw = true;
                }

                if (draw)
                {
                    var groundVolume = scene.GetSceneVolume();
                    if (groundVolume != null)
                    {
                        //Ground culling
                        draw = this.cullManager.Cull(groundVolume, CullIndexDrawIndex, toCullVisible);
                    }
                }

#if DEBUG
                swCull.Stop();

                this.frameStats.ForwardCull = swCull.ElapsedTicks;
#endif
                #endregion

                #region Draw

                if (draw)
                {
#if DEBUG
                    Stopwatch swDraw = Stopwatch.StartNew();
#endif
                    //Draw solid
                    this.DrawResultComponents(this.DrawContext, CullIndexDrawIndex, components);
#if DEBUG
                    swDraw.Stop();

                    this.frameStats.ForwardDraw = swDraw.ElapsedTicks;
#endif
                }

                #endregion
            }
        }
Beispiel #3
0
        /// <summary>
        /// Do deferred rendering
        /// </summary>
        /// <param name="scene">Scene</param>
        /// <param name="deferredEnabledComponents">Components</param>
        private void DoDeferred(Scene scene, IEnumerable <SceneObject> deferredEnabledComponents)
        {
#if DEBUG
            Stopwatch swCull = Stopwatch.StartNew();
#endif
            var toCullDeferred = deferredEnabledComponents.Where(s => s.Is <ICullable>()).Select(s => s.Get <ICullable>());

            bool draw = false;
            if (scene.PerformFrustumCulling)
            {
                //Frustum culling
                draw = this.cullManager.Cull(this.DrawContext.CameraVolume, CullIndexDrawIndex, toCullDeferred);
            }
            else
            {
                draw = true;
            }

            if (draw)
            {
                var groundVolume = scene.GetSceneVolume();
                if (groundVolume != null)
                {
                    //Ground culling
                    draw = this.cullManager.Cull(groundVolume, CullIndexDrawIndex, toCullDeferred);
                }
            }
#if DEBUG
            swCull.Stop();

            this.frameStats.DeferredCull = swCull.ElapsedTicks;
#endif

            if (draw)
            {
#if DEBUG
                Stopwatch swGeometryBuffer = Stopwatch.StartNew();

                Stopwatch swGeometryBufferInit = Stopwatch.StartNew();
#endif
                this.BindGBuffer();
#if DEBUG
                swGeometryBufferInit.Stop();

                Stopwatch swGeometryBufferDraw = Stopwatch.StartNew();
#endif
                //Draw scene on g-buffer render targets
                this.DrawResultComponents(this.DrawContext, CullIndexDrawIndex, deferredEnabledComponents);
#if DEBUG
                swGeometryBufferDraw.Stop();

                swGeometryBuffer.Stop();

                this.frameStats.DeferredGbuffer     = swGeometryBuffer.ElapsedTicks;
                this.frameStats.DeferredGbufferInit = swGeometryBufferInit.ElapsedTicks;
                this.frameStats.DeferredGbufferDraw = swGeometryBufferDraw.ElapsedTicks;
#endif

#if DEBUG
                Stopwatch swLightBuffer = Stopwatch.StartNew();
#endif
                this.BindLights();

                //Draw scene lights on light buffer using g-buffer output
                this.DrawLights(this.DrawContext);
#if DEBUG
                swLightBuffer.Stop();

                this.frameStats.DeferredLbuffer = swLightBuffer.ElapsedTicks;
#endif
            }
        }