/// <summary>
        /// Draws scene components
        /// </summary>
        /// <param name="gameTime">Game time</param>
        /// <param name="scene">Scene</param>
        public override void Draw(GameTime gameTime, Scene scene)
        {
            if (this.Updated)
            {
                this.Updated = false;
#if DEBUG
                this.frameStats.Clear();

                Stopwatch swTotal = Stopwatch.StartNew();
#endif
                //Draw visible components
                var visibleComponents = scene.GetComponents(c => c.Visible);
                if (visibleComponents.Any())
                {
                    //Initialize context data from update context
                    this.DrawContext.GameTime       = gameTime;
                    this.DrawContext.DrawerMode     = DrawerModes.Forward;
                    this.DrawContext.ViewProjection = this.UpdateContext.ViewProjection;
                    this.DrawContext.CameraVolume   = this.UpdateContext.CameraVolume;
                    this.DrawContext.EyePosition    = this.UpdateContext.EyePosition;
                    this.DrawContext.EyeTarget      = this.UpdateContext.EyeDirection;

                    //Initialize context data from scene
                    this.DrawContext.Lights = scene.Lights;
                    this.DrawContext.ShadowMapDirectional = this.ShadowMapperDirectional;
                    this.DrawContext.ShadowMapPoint       = this.ShadowMapperPoint;
                    this.DrawContext.ShadowMapSpot        = this.ShadowMapperSpot;

                    //Shadow mapping
                    DoShadowMapping(gameTime, scene);

                    //Rendering
                    DoRender(scene, visibleComponents);
                }
#if DEBUG
                swTotal.Stop();

                this.frameStats.UpdateCounters(swTotal.ElapsedTicks);
#endif
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Draws scene components
        /// </summary>
        /// <param name="gameTime">Game time</param>
        /// <param name="scene">Scene</param>
        public override void Draw(GameTime gameTime, Scene scene)
        {
            if (this.Updated)
            {
                this.Updated = false;
#if DEBUG
                this.frameStats.Clear();

                Stopwatch swTotal = Stopwatch.StartNew();
#endif
                //Draw visible components
                var visibleComponents = scene.GetComponents(c => c.Visible);
                if (visibleComponents.Any())
                {
                    //Initialize context data from update context
                    this.DrawContext.GameTime       = gameTime;
                    this.DrawContext.DrawerMode     = DrawerModes.Deferred;
                    this.DrawContext.ViewProjection = this.UpdateContext.ViewProjection;
                    this.DrawContext.CameraVolume   = this.UpdateContext.CameraVolume;
                    this.DrawContext.EyePosition    = this.UpdateContext.EyePosition;
                    this.DrawContext.EyeTarget      = this.UpdateContext.EyeDirection;

                    //Initialize context data from scene
                    this.DrawContext.Lights = scene.Lights;
                    //Initialize context data from shadow mapping

                    this.DrawContext.ShadowMapDirectional = this.ShadowMapperDirectional;
                    this.DrawContext.ShadowMapPoint       = this.ShadowMapperPoint;
                    this.DrawContext.ShadowMapSpot        = this.ShadowMapperSpot;

                    //Shadow mapping
                    DoShadowMapping(gameTime, scene);

                    #region Deferred rendering

                    //Render to G-Buffer only opaque objects
                    var deferredEnabledComponents = visibleComponents.Where(c => c.DeferredEnabled);
                    if (deferredEnabledComponents.Any())
                    {
                        DoDeferred(scene, deferredEnabledComponents);
                    }

                    #region Final composition
#if DEBUG
                    Stopwatch swComponsition = Stopwatch.StartNew();
#endif
                    this.BindResult();

                    //Draw scene result on screen using g-buffer and light buffer
                    this.DrawResult(this.DrawContext);

#if DEBUG
                    swComponsition.Stop();

                    this.frameStats.DeferredCompose = swComponsition.ElapsedTicks;
#endif
                    #endregion

                    #endregion

                    #region Forward rendering

                    //Render to screen deferred disabled components
                    var deferredDisabledComponents = visibleComponents.Where(c => !c.DeferredEnabled);
                    if (deferredDisabledComponents.Any())
                    {
                        DoForward(scene, deferredDisabledComponents);
                    }

                    #endregion
                }
#if DEBUG
                swTotal.Stop();

                this.frameStats.UpdateCounters(swTotal.ElapsedTicks);
#endif
            }
        }