Пример #1
0
        protected override void OnRender(float dt, float betweenFrameAlpha)
        {
            int enableFrameSmoothing = CVars.Get <bool>("graphics_frame_smoothing") ? 1 : 0;

            betweenFrameAlpha = betweenFrameAlpha * enableFrameSmoothing + (1 - enableFrameSmoothing);

            _fxaaPPE.Enabled = CVars.Get <bool>("graphics_fxaa");
            _smaaPPE.Enabled = CVars.Get <bool>("graphics_smaa");

            GameManager.GraphicsDevice.Clear(Color.Black);

            Camera camera = Camera;

#if DEBUG
            if (CVars.Get <bool>("debug_force_debug_camera"))
            {
                camera = DebugCamera;
            }
#endif

            PostProcessor.Begin();
            {
                RenderSystem.DrawEntities(Camera,
                                          Constants.Render.RENDER_GROUP_GAME_ENTITIES,
                                          dt,
                                          betweenFrameAlpha,
                                          camera);
                RenderSystem.SpriteBatch.Begin(SpriteSortMode.Deferred,
                                               null,
                                               null,
                                               null,
                                               null,
                                               null,
                                               camera.GetInterpolatedTransformMatrix(betweenFrameAlpha));
                if (!CVars.Get <bool>("particle_gpu_accelerated"))
                {
                    VelocityParticleManager.Draw(RenderSystem.SpriteBatch);
                }
                RenderSystem.SpriteBatch.End();
                if (CVars.Get <bool>("particle_gpu_accelerated"))
                {
                    GPUParticleManager.UpdateAndDraw(Camera, dt, betweenFrameAlpha, camera);
                }
            }
            // We have to defer drawing the post-processor results
            // because of unexpected behavior within MonoGame.
            RenderTarget2D postProcessingResult = PostProcessor.End(false);

            // Stars
            RenderSystem.DrawEntities(Camera,
                                      Constants.Render.RENDER_GROUP_STARS,
                                      dt,
                                      betweenFrameAlpha, camera);   // Stars
            RenderSystem.SpriteBatch.Begin();
            RenderSystem.SpriteBatch.Draw(postProcessingResult,
                                          postProcessingResult.Bounds,
                                          Color.White); // Post-processing results
            RenderSystem.SpriteBatch.End();
            // Shield Resource
            RenderSystem.DrawEntities(Camera,
                                      Constants.Render.RENDER_GROUP_NO_GLOW,
                                      dt,
                                      betweenFrameAlpha, camera);

#if DEBUG
            if (CVars.Get <bool>("debug_show_collision_shapes"))
            {
                CollisionDebugRenderSystem.Draw(camera.GetInterpolatedTransformMatrix(betweenFrameAlpha), dt);
            }
#endif
#if DEBUG
            if (CVars.Get <bool>("debug_show_render_culling"))
            {
                Camera debugCamera = CVars.Get <bool>("debug_force_debug_camera") ? DebugCamera : null;
                RenderCullingDebugRenderSystem.Draw(Camera, dt, debugCamera);
            }
#endif
#if DEBUG
            if (CVars.Get <bool>("debug_show_quad_trees"))
            {
                Camera debugCamera = CVars.Get <bool>("debug_force_debug_camera") ? DebugCamera : null;
                QuadTreeDebugRenderSystem.Draw(Camera, dt, debugCamera);
            }
#endif

            base.OnRender(dt, betweenFrameAlpha);
        }
Пример #2
0
        void DrawPong(float dt, float betweenFrameAlpha)
        {
            GameManager.GraphicsDevice.SetRenderTarget(_pongRenderTarget);
            Matrix center = Matrix.CreateTranslation(_pongRenderTarget.Bounds.Width / 2,
                                                     _pongRenderTarget.Bounds.Height / 2,
                                                     0);

            _renderSystem.DrawEntities(center,
                                       Constants.Pong.RENDER_GROUP,
                                       dt,
                                       betweenFrameAlpha);
            _renderSystem.SpriteBatch.Begin(SpriteSortMode.Deferred,
                                            null,
                                            null,
                                            null,
                                            null,
                                            null,
                                            center);
            VelocityParticleManager.Draw(_renderSystem.SpriteBatch);
            _renderSystem.SpriteBatch.Draw(Content.Load <Texture2D>(Constants.Resources.TEXTURE_PONG_EDGE),
                                           new Vector2(0, Constants.Pong.PLAYFIELD_HEIGHT / 2
                                                       + Constants.Pong.EDGE_HEIGHT
                                                       + 100 / 2),
                                           null,
                                           null,
                                           new Vector2(0.5f, 0.5f),
                                           0,
                                           new Vector2(Constants.Pong.PLAYFIELD_WIDTH,
                                                       100),
                                           Color.Black,
                                           SpriteEffects.None,
                                           0);
            _renderSystem.SpriteBatch.Draw(Content.Load <Texture2D>(Constants.Resources.TEXTURE_PONG_EDGE),
                                           new Vector2(0, -(Constants.Pong.PLAYFIELD_HEIGHT / 2
                                                            + Constants.Pong.EDGE_HEIGHT
                                                            + 100 / 2)),
                                           null,
                                           null,
                                           new Vector2(0.5f, 0.5f),
                                           0,
                                           new Vector2(Constants.Pong.PLAYFIELD_WIDTH,
                                                       100),
                                           Color.Black,
                                           SpriteEffects.None,
                                           0);
            _renderSystem.SpriteBatch.End();
            GameManager.GraphicsDevice.SetRenderTarget(null);

            _quadEffect.View       = _pongCamera.TransformMatrix;
            _quadEffect.Projection = _pongCamera.PerspectiveMatrix;
            _quadEffect.Texture    = _pongRenderTarget;

            PongPostProcessor.Begin();
            foreach (EffectPass pass in _quadEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                _quad.Draw(GameManager.GraphicsDevice);
            }

            RenderTarget2D processedPongRender = PongPostProcessor.End(false);

            _renderSystem.SpriteBatch.Begin(SpriteSortMode.Deferred,
                                            null,
                                            null,
                                            null,
                                            null,
                                            null,
                                            _mainCamera.TransformMatrix);
            _renderSystem.SpriteBatch.Draw(processedPongRender, new Rectangle((int)(processedPongRender.Bounds.X - processedPongRender.Bounds.Width / 2 + Constants.Pong.BUFFER_RENDER_POSITION.X),
                                                                              (int)(processedPongRender.Bounds.Y - processedPongRender.Bounds.Height / 2 + Constants.Pong.BUFFER_RENDER_POSITION.Y),
                                                                              processedPongRender.Bounds.Width,
                                                                              processedPongRender.Bounds.Height), Color.White);
            _renderSystem.SpriteBatch.End();
        }