protected override void Draw(GameTime gameTime) { renderer.Draw(gameTime); if (PostProcessingOn) { STHpEffect.normalMap = renderer.normalMap; ppManager.Draw(gameTime, renderer.finalBackBuffer, renderer.finalDepthBuffer, renderer.normalMap); } else { if (!renderer.StopRender) { GraphicsDevice.Clear(renderer.ClearColor); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.AnisotropicClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise); spriteBatch.Draw(renderer.finalBackBuffer, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White); spriteBatch.End(); } } renderer.RenderDebug(); if (hWnd != IntPtr.Zero) { GraphicsDevice.Present(null, null, hWnd); } }
/// <summary> /// Called when the DrawableGameComponent needs to be drawn. Override this method with component-specific drawing code. Reference page contains links to related conceptual articles. /// </summary> /// <param name="gameTime">Time passed since the last call to Draw.</param> public override void Draw(GameTime gameTime) { // Set the GBuffer SetGBuffer(); // Clear the GBuffer ClearGBuffer(); // Render sky if enabled if (SkyRenderer.Enabled) { // To create a Static SunLight, uncomment this line //SkyRenderer.Parameters.LightDirection = new Vector4(LightManager.Light.Direction, 1); skyRenderer.Draw(gameTime, camera); } // Render the scene scene.DrawScene(gameTime); // Resolve the GBuffer ResolveGBuffer(); // Draw Depth for Shadow Mapping DrawDepth(gameTime); // Render Shadows var shadowOcclusion = shadowRenderer.Draw(scene, depthTexture, LightManager.Light, camera); // Draw Lights lightManager.DrawLights(GraphicsDevice, colorRT, normalRT, depthRT, lightRT, camera, scene); // Combine the Final scene CombineFinal(shadowOcclusion); // Render SSAO if enabled if (SSAORenderer.Enabled) { ssaoRenderer.Draw(GraphicsDevice, normalRT, depthRT, sceneRT, scene, camera, null); } // Post Processing Render postProcessingManager.Draw(null, camera); // Render output spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, null, null); spriteBatch.Draw((Texture2D)colorRT, new Rectangle(0, 0, 128, 128), Color.White); spriteBatch.Draw((Texture2D)depthRT, new Rectangle(128, 0, 128, 128), Color.White); spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { // Lets set up our RT's GraphicsDevice.SetRenderTargets(finalBackBuffer, finalDepthBuffer); GraphicsDevice.Clear(clearColor); // Make sure our device is how we want it GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.BlendState = BlendState.Opaque; base.Draw(gameTime); // Now get the data back from the GPU GraphicsDevice.SetRenderTarget(null); // Once we have rendered the scene we ca do our post processing ppManager.Draw(gameTime, finalBackBuffer, finalDepthBuffer); }
public void PostSceneDraw(GameTime gameTime) { #region Bring all the RT together GraphicsDevice.SetRenderTarget(null); #region Create Light Maps // Create the Light map DeferredLighting(gameTime, camera); #endregion #region Combine all the maps and create final scene GraphicsDevice.SetRenderTarget(camera.DeferredRenderTarget); GraphicsDevice.Clear(Color.Black); DrawDeferred(camera); GraphicsDevice.SetRenderTarget(null); // Combine to Final output. camera.FinalRenderTexture = camera.DeferredRenderTarget; #endregion #region Optional Post Processing (see RandomchaosMGPostProcessingSandBox // Plug in Post processing here.. if (PostProcessingManager != null && PostProcessingManager.Enabled) { GraphicsDevice.Clear(Color.Magenta); PostProcessingManager.Draw(gameTime, camera.FinalRenderTexture, camera.DepthBuffer); } #endregion #region Render the final scene // Render final out put to the screen. GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(camera.FinalRenderTexture, new Rectangle(0, 0, Game.GraphicsDevice.PresentationParameters.BackBufferWidth, Game.GraphicsDevice.PresentationParameters.BackBufferHeight), Color.White); spriteBatch.End(); #endregion #endregion }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { // This looks WAY more comlicated than it is, but it's pretty simple, // Draw the objects you wan to have occlude the rays in black and store them in an RT, this creates a mask. // Hand this RT onto the pp manager, it will render all the rays for you to a new RT // Re render the scene in color this time to another RT // Finaly do an additive blend with the godray RT and the scene you just rendered. // Give me a shout if you need any help implementing it :D // Draw the stuff that is infront of the rays source GraphicsDevice.SetRenderTarget(scene); GraphicsDevice.Clear(Color.White); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied); for (int bg = 0; bg < bgCnt; bg++) { spriteBatch.Draw(Content.Load <Texture2D>(backgroundAssets[bg]), new Rectangle((int)bgPos[bg].X, (int)bgPos[bg].Y, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), new Rectangle(0, 0, Content.Load <Texture2D>(backgroundAssets[bg]).Width, Content.Load <Texture2D>(backgroundAssets[bg]).Height), Color.Black); spriteBatch.Draw(Content.Load <Texture2D>(backgroundAssets[bg]), new Rectangle((int)bgPos2[bg].X, (int)bgPos[bg].Y, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), new Rectangle(0, 0, Content.Load <Texture2D>(backgroundAssets[bg]).Width, Content.Load <Texture2D>(backgroundAssets[bg]).Height), Color.Black); } // Draw mouse icon mask. spriteBatch.Draw(Content.Load <Texture2D>("Textures/mousemask"), new Rectangle(Mouse.GetState().X - 64, Mouse.GetState().Y - 64, 128, 128), Color.Black); spriteBatch.End(); GraphicsDevice.SetRenderTarget(null); // Apply the post processing maanger (just the rays in this one) ppm.Draw(gameTime, scene); //ppm.SaveTexture(scene, "c:\\temp\\godray.jpeg"); // Now blend that source with the scene.. GraphicsDevice.SetRenderTarget(scene); // Draw the scene in color now GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied); for (int bg = 0; bg < bgCnt; bg++) { spriteBatch.Draw(Content.Load <Texture2D>(backgroundAssets[bg]), new Rectangle((int)bgPos[bg].X, (int)bgPos[bg].Y, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), new Rectangle(0, 0, Content.Load <Texture2D>(backgroundAssets[bg]).Width, Content.Load <Texture2D>(backgroundAssets[bg]).Height), Color.White); spriteBatch.Draw(Content.Load <Texture2D>(backgroundAssets[bg]), new Rectangle((int)bgPos2[bg].X, (int)bgPos[bg].Y, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), new Rectangle(0, 0, Content.Load <Texture2D>(backgroundAssets[bg]).Width, Content.Load <Texture2D>(backgroundAssets[bg]).Height), Color.White); } // Draw mouse icon. spriteBatch.Draw(Content.Load <Texture2D>("Textures/mousemask"), new Rectangle(Mouse.GetState().X - 64, Mouse.GetState().Y - 64, 128, 128), Color.White); spriteBatch.End(); GraphicsDevice.SetRenderTarget(null); GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive); spriteBatch.Draw(ppm.Scene, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White); spriteBatch.Draw(scene, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White); spriteBatch.End(); for (int b = 0; b < bgCnt; b++) { bgPos[b] -= new Vector2(bgSpeeds[b], 0); bgPos2[b] -= new Vector2(bgSpeeds[b], 0); if (bgPos[b].X < -bgPos2Base[b].X) { bgPos[b] = new Vector2(bgPos2[b].X + bgPos2Base[b].X, 0); } if (bgPos2[b].X < -bgPos2Base[b].X) { bgPos2[b] = new Vector2(bgPos[b].X + bgPos2Base[b].X, 0); } } spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive); spriteBatch.DrawString(Content.Load <SpriteFont>("Fonts/font"), "F1 - F4 change light source texture", new Vector2(8, Content.Load <SpriteFont>("Fonts/font").LineSpacing * 1), Color.Gold); spriteBatch.DrawString(Content.Load <SpriteFont>("Fonts/font"), string.Format("WASD move light source [{0}]", rays.lightSource), new Vector2(8, Content.Load <SpriteFont>("Fonts/font").LineSpacing * 2), Color.Gold); spriteBatch.DrawString(Content.Load <SpriteFont>("Fonts/font"), string.Format("Q/Z Exposure up/down [{0}]", rays.Exposure), new Vector2(8, Content.Load <SpriteFont>("Fonts/font").LineSpacing * 3), Color.Gold); spriteBatch.DrawString(Content.Load <SpriteFont>("Fonts/font"), string.Format("E/C Size up/down [{0}]", rays.LightSourceSize), new Vector2(8, Content.Load <SpriteFont>("Fonts/font").LineSpacing * 4), Color.Gold); spriteBatch.DrawString(Content.Load <SpriteFont>("Fonts/font"), string.Format("R/V Density up/down [{0}]", rays.Density), new Vector2(8, Content.Load <SpriteFont>("Fonts/font").LineSpacing * 5), Color.Gold); spriteBatch.DrawString(Content.Load <SpriteFont>("Fonts/font"), string.Format("T/B Decay up/down [{0}]", rays.Decay), new Vector2(8, Content.Load <SpriteFont>("Fonts/font").LineSpacing * 6), Color.Gold); spriteBatch.DrawString(Content.Load <SpriteFont>("Fonts/font"), string.Format("Y/N Weight up/down [{0}]", rays.Weight), new Vector2(8, Content.Load <SpriteFont>("Fonts/font").LineSpacing * 7), Color.Gold); spriteBatch.End(); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { // Set up RT's GraphicsDevice.SetRenderTargets(backBuffer, depthBuffer); GraphicsDevice.Clear(Color.CornflowerBlue); base.Draw(gameTime); //Resolve targets. GraphicsDevice.SetRenderTarget(null); ppManager.Draw(gameTime, backBuffer, depthBuffer); line = 0; int x = 8; spriteBatch.Begin(); spriteBatch.Draw(Content.Load <Texture2D>("Textures/HUD/HUDBackground"), new Rectangle(0, 0, 250, lineHeight * lineCount), Color.White); WriteLine("Post Processing", x, Color.Gold); WriteLine($"[F1 ] - Bloom On: {bloom.Enabled}", x, bloom.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[F2 ] - God Rays On: {GodRays.Enabled}", x, GodRays.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[F3 ] - Depth of Field On: {dof.Enabled}", x, dof.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[F4 ] - Fog On: {fog.Enabled}", x, fog.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[F5 ] - Heat Haze On: {haze.Enabled}", x, haze.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[F6 ] - Radial Blur On: {radialBlur.Enabled}", x, radialBlur.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[F7 ] - Ripple On: {ripple.Enabled}", x, ripple.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[F8 ] - Sun On: {sun.Enabled}", x, sun.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[F9 ] - Sepia On: {sepia.Enabled}", x, sepia.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[F10] - Grey Scale On: {greyScale.Enabled}", x, greyScale.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[F11] - Invert Color On: {invert.Enabled}", x, invert.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[F12] - DeRezed On: {deRezed.Enabled}", x, deRezed.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[D1 ] - Color Filter ON: {colorFilter.Enabled}", x, colorFilter.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[D2 ] - Bleach ON: {bleach.Enabled}", x, bleach.Enabled ? Color.Yellow : Color.Gold); WriteLine($"[D3 ] - Scan Lines ON: {scanLines.Enabled}", x, scanLines.Enabled ? Color.Yellow : Color.Gold); WriteLine($"", x, Color.Gold); WriteLine($"", x, Color.Gold); WriteLine($"[ESC] - Exit", x, Color.Gold); line = 0; x += 255; if (selectedEffect != null) { spriteBatch.Draw(Content.Load <Texture2D>("Textures/HUD/HUDBackground"), new Rectangle(255, 0, 250, lineHeight * 9), Color.White); WriteLine($"[{selectedEffect.GetType().Name}]", x, Color.Gold); WriteLine($"[SPC] - Toggle Enabled", x, selectedEffect.Enabled ? Color.LimeGreen : Color.Green); if (selectedEffect.Enabled) { if (selectedEffect == bloom) { WriteLine($"[G ] Galre On: {bloom.Glare}", x, bloom.Glare ? Color.LimeGreen : Color.Green); WriteLine($"[Y/H] Bloom Threshold +- : {bloom.BloomThreshold}", x, Color.LimeGreen); WriteLine($"[U/J] Blur Amount +- : {bloom.BlurAmount}", x, Color.LimeGreen); } if (selectedEffect == GodRays) { WriteLine($"[R/F] Light Source Size +-: {GodRays.LightSourceSize}", x, Color.LimeGreen); WriteLine($"[T/G] Density +-: {GodRays.Density}", x, Color.LimeGreen); WriteLine($"[Y/H] Decay +-: {GodRays.Decay}", x, Color.LimeGreen); WriteLine($"[U/J] Weight +-: {GodRays.Weight}", x, Color.LimeGreen); WriteLine($"[I/K] Exposure +-: {GodRays.Exposure}", x, Color.LimeGreen); WriteLine($"[O/L] Bright Threshold +-: {GodRays.BrightThreshold}", x, Color.LimeGreen); } if (selectedEffect == dof) { WriteLine($"[R/F] Disc Radius +- : {dof.DiscRadius}", x, Color.LimeGreen); WriteLine($"[T/G] Focal Distance +- : {dof.FocalDistance}", x, Color.LimeGreen); WriteLine($"[Y/H] Focal Range +- : {dof.FocalRange}", x, Color.LimeGreen); } if (selectedEffect == fog) { WriteLine($"[R/F] - Fog Distance +- : {fog.FogDistance}", x, Color.LimeGreen); WriteLine($"[T/G] - Fog Range +- : {fog.FogRange}", x, Color.LimeGreen); WriteLine($"[Y/H] - Fog Color (R) +- : {fog.FogColor.ToVector4().X}", x, Color.LimeGreen); WriteLine($"[U/J] - Fog Color (G) +- : {fog.FogColor.ToVector4().Y}", x, Color.LimeGreen); WriteLine($"[I/K] - Fog Color (B) +- : {fog.FogColor.ToVector4().Z}", x, Color.LimeGreen); WriteLine($"[O/L] - Fog Color (A) +- : {fog.FogColor.ToVector4().W}", x, Color.LimeGreen); } if (selectedEffect == haze) { WriteLine($"[H ] - High On: {haze.High}", x, haze.High ? Color.LimeGreen : Color.Green); } if (selectedEffect == radialBlur) { WriteLine($"[R/F] - Sale +=: {radialBlur.Scale}", x, Color.LimeGreen); } if (selectedEffect == ripple) { WriteLine($"[T/G] - Distortion +=: {ripple.Distortion}", x, Color.LimeGreen); WriteLine($"[Y/H] - Screen Position X +=: {ripple.ScreenPosition.X}", x, Color.LimeGreen); WriteLine($"[U/J] - Screen Position Y +=: {ripple.ScreenPosition.Y}", x, Color.LimeGreen); } if (selectedEffect == colorFilter) { WriteLine($"[R/F] - Bright +=: {colorFilter.Bright}", x, Color.LimeGreen); WriteLine($"[T/G] - Saturation +=: {colorFilter.Saturation}", x, Color.LimeGreen); WriteLine($"[Y/H] - Burn +=: {colorFilter.Burn}", x, Color.LimeGreen); WriteLine($"[U/J] - Color (R) +- : {colorFilter.Color.ToVector3().X}", x, Color.LimeGreen); WriteLine($"[I/K] - Color (G) +- : {colorFilter.Color.ToVector3().Y}", x, Color.LimeGreen); WriteLine($"[O/L] - Color (B) +- : {colorFilter.Color.ToVector3().Z}", x, Color.LimeGreen); } if (selectedEffect == bleach) { WriteLine($"[R/F] - Opacity +=: {bleach.Opacity}", x, Color.LimeGreen); } if (selectedEffect == scanLines) { WriteLine($"[R/F] - Noise Intensity +=: {scanLines.NoiseIntensity}", x, Color.LimeGreen); WriteLine($"[T/G] - Line Intensity +=: {scanLines.LineIntensity}", x, Color.LimeGreen); WriteLine($"[Y/H] - Line Count +=: {scanLines.LineCount}", x, Color.LimeGreen); } if (selectedEffect == deRezed) { WriteLine($"[R/F] - Number Of Tiles +=: {deRezed.NumberOfTiles}", x, Color.LimeGreen); } } } line = (lineCount + 2) * lineHeight; WriteLine("", 8, Color.Gold); WriteLine("Camera Controls: [WASD - Translate] [Arrow Keys - Rotate]", 8, Color.Gold); spriteBatch.End(); }
public override void Draw(GameTime gameTime) { Camera.GraphicsDevice.SetRenderTarget(m_godRayTexture); Camera.GraphicsDevice.Clear(Color.White); Camera.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.LinearClamp, null, null); m_smallCloud1.DrawOutline(Camera); m_smallCloud3.DrawOutline(Camera); m_smallCloud4.DrawOutline(Camera); Camera.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp; m_castle.DrawOutline(Camera); Camera.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; m_smallCloud2.DrawOutline(Camera); m_smallCloud5.DrawOutline(Camera); m_logo.DrawOutline(Camera); m_dlcIcon.DrawOutline(Camera); m_crown.DrawOutline(Camera); Camera.End(); m_ppm.Draw(gameTime, m_godRayTexture); Camera.GraphicsDevice.SetRenderTarget(m_godRayTexture); Camera.GraphicsDevice.Clear(Color.Black); Camera.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null); m_bg.Draw(Camera); m_smallCloud1.Draw(Camera); m_smallCloud3.Draw(Camera); m_smallCloud4.Draw(Camera); Camera.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp; m_castle.Draw(Camera); Camera.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; m_smallCloud2.Draw(Camera); m_smallCloud5.Draw(Camera); m_largeCloud1.Draw(Camera); m_largeCloud2.Draw(Camera); m_largeCloud3.Draw(Camera); m_largeCloud4.Draw(Camera); Camera.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp; Camera.Draw(Game.GenericTexture, new Rectangle(-10, -10, 1400, 800), Color.Black * m_hardCoreModeOpacity); Camera.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; m_logo.Draw(Camera); m_crown.Draw(Camera); m_copyrightText.Draw(Camera); m_versionNumber.Draw(Camera); m_pressStartText2.Opacity = m_pressStartText.Opacity; m_pressStartText.Draw(Camera); m_pressStartText2.Draw(Camera); if (!m_startNewLegacy) { m_profileCardKey.Draw(Camera); } m_creditsKey.Draw(Camera); m_optionsKey.Draw(Camera); m_profileSelectKey.Draw(Camera); Camera.GraphicsDevice.SamplerStates[0] = SamplerState.PointWrap; if (!m_startNewLegacy) { m_profileCard.Draw(Camera); } m_dlcIcon.Draw(Camera); m_optionsIcon.Draw(Camera); m_creditsIcon.Draw(Camera); Camera.End(); Camera.GraphicsDevice.SetRenderTarget((ScreenManager as RCScreenManager).RenderTarget); Camera.GraphicsDevice.Clear(Color.Black); Camera.Begin(SpriteSortMode.Immediate, BlendState.Additive); Camera.Draw(m_ppm.Scene, new Rectangle(0, 0, Camera.GraphicsDevice.Viewport.Width, Camera.GraphicsDevice.Viewport.Height), Color.White); Camera.Draw(m_godRayTexture, new Rectangle(0, 0, Camera.GraphicsDevice.Viewport.Width, Camera.GraphicsDevice.Viewport.Height), Color.White); Camera.End(); base.Draw(gameTime); }