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); }
protected override void Draw(GameTime gameTime) { base.Draw(gameTime); GraphicsDevice.Clear(Color.Black); //Update lights and camera Camera.main.Update(); Lighting.Update(); //Update graphics state GraphicsDevice.BlendState = BlendState.Opaque; GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.CullClockwiseFace }; //Render shadow map GraphicsDevice.SetRenderTarget(Lighting.ShadowMap); GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.White, 1.0f, 0); effect.CurrentTechnique = effect.Techniques["ShadowMap"]; environment.Render(gameTime, GraphicsDevice, effect); player.Render(gameTime, effect); trafficManager.RenderTraffic(gameTime, effect); //Render scene GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.CullCounterClockwiseFace }; GraphicsDevice.SetRenderTarget(null); postProcessor.Begin(); effect.CurrentTechnique = effect.Techniques["ShadowedScene"]; environment.Render(gameTime, GraphicsDevice, effect); player.Render(gameTime, effect); trafficManager.RenderTraffic(gameTime, effect); postProcessor.End(player.crashed); //Render GUI spriteBatch.Begin(); scoreUI.Render(spriteBatch, inTargetLane); countdownUI.Render(spriteBatch); titleUI.Render(spriteBatch, gameTime); if (player.crashed && state != GameState.RESTARTING) { gameOverUI.Render(spriteBatch, gameTime); } spriteBatch.End(); //Render debug if (TrafficGame.DEBUG) { trafficManager.RenderDebug(debugView, Camera.main.View, Camera.main.Projection); debugView.RenderDebugData(Camera.main.Projection, Camera.main.View, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullNone, 0.8f); spriteBatch.Begin(); fpsUI.Render(spriteBatch); spriteBatch.End(); //DEBUG: show shadow map spriteBatch.Begin(0, BlendState.Opaque, SamplerState.AnisotropicClamp); spriteBatch.Draw(Lighting.ShadowMap, new Rectangle(0, GraphicsDevice.Viewport.Height - 256, 256, 256), Color.White); spriteBatch.End(); } }