public override void Draw() { // Set values for horizontal pass Effect.Parameters["Offsets"].SetValue(offsetsH); Effect.Parameters["Weights"].SetValue(weightsH); // Render this pass into the RenderCapture capture.Begin(); base.Draw(); capture.End(); // Get the results of the first pass Input = capture.GetTexture(); if (ResultCapture != null) { ResultCapture.Begin(); } // Set values for the vertical pass Effect.Parameters["Offsets"].SetValue(offsetsV); Effect.Parameters["Weights"].SetValue(weightsV); // Render the final pass base.Draw(); if (ResultCapture != null) { ResultCapture.End(); } }
// Called when the game should draw itself protected override void Draw(GameTime gameTime) { // Capture the render renderCapture.Begin(); GraphicsDevice.Clear(Color.CornflowerBlue); // Draw all of the models foreach (CModel model in models) { if (camera.BoundingVolumeIsInView(model.BoundingSphere)) { model.Draw(camera.View, camera.Projection, ((FreeCamera)camera).Position); } } // End capturing renderCapture.End(); GraphicsDevice.Clear(Color.Black); // Perform postprocessing with teh render of the scene postprocessor.Input = renderCapture.GetTexture(); postprocessor.Draw(); base.Draw(gameTime); }
// Called when the game should draw itself protected override void Draw(GameTime gameTime) { // Begin capturing the glow render glowCapture.Begin(); GraphicsDevice.Clear(Color.Black); // Draw all models with the glow effect/texture applied, reverting // the effect when finished foreach (CModel model in models) { if (camera.BoundingVolumeIsInView(model.BoundingSphere)) { model.CacheEffects(); model.SetModelEffect(glowEffect, false); model.Draw(camera.View, camera.Projection, ((FreeCamera)camera).Position); model.RestoreEffects(); } } // Finish capturing the glow glowCapture.End(); // Draw the scene regularly into the other RenderCapture renderCapture.Begin(); GraphicsDevice.Clear(Color.Black); // Draw all models foreach (CModel model in models) { if (camera.BoundingVolumeIsInView(model.BoundingSphere)) { model.Draw(camera.View, camera.Projection, ((FreeCamera)camera).Position); } } // Finish capturing renderCapture.End(); // Blur the glow render back into the glow RenderCapture blur.Input = glowCapture.GetTexture(); blur.ResultCapture = glowCapture; blur.Draw(); GraphicsDevice.Clear(Color.Black); // Draw the blurred glow render over the normal render additively spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive); spriteBatch.Draw(renderCapture.GetTexture(), Vector2.Zero, Color.White); spriteBatch.Draw(glowCapture.GetTexture(), Vector2.Zero, Color.White); spriteBatch.End(); // Clean up after the SpriteBatch GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.BlendState = BlendState.Opaque; base.Draw(gameTime); }
// Called when the game should draw itself protected override void Draw(GameTime gameTime) { // Start rendering to depth map depthCapture.Begin(); // Clear to white (max depth) GraphicsDevice.Clear(Color.White); foreach (CModel model in models) { if (camera.BoundingVolumeIsInView(model.BoundingSphere)) { model.CacheEffects(); // Cache effect model.SetModelEffect(depthEffect, false); // Set depth effect model.Draw(camera.View, camera.Projection, ((FreeCamera)camera).Position); model.RestoreEffects(); // Restore effects } } // Finish rendering to depth map depthCapture.End(); // Begin rendering the main render renderCapture.Begin(); GraphicsDevice.Clear(Color.CornflowerBlue); // Draw all models foreach (CModel model in models) { if (camera.BoundingVolumeIsInView(model.BoundingSphere)) { model.Draw(camera.View, camera.Projection, ((FreeCamera)camera).Position); } } // Finish the main render renderCapture.End(); // Prepare to blur results of main render postprocessor.Input = renderCapture.GetTexture(); // Output blur to our RenderCapture ((GaussianBlur)postprocessor).ResultCapture = blurCapture; // Perform blur postprocessor.Draw(); // Set the three images to the DOF class dof.DepthMap = depthCapture.GetTexture(); dof.Unblurred = renderCapture.GetTexture(); dof.Input = ((GaussianBlur)postprocessor).ResultCapture.GetTexture(); // Combine the images into the final result dof.Draw(); base.Draw(gameTime); }
// Called when the game should draw itself protected override void Draw(GameTime gameTime) { renderCapture.Begin(); GraphicsDevice.Clear(Color.CornflowerBlue); foreach (CModel model in models) { if (camera.BoundingVolumeIsInView(model.BoundingSphere)) { model.Draw(camera.View, camera.Projection, ((FreeCamera)camera).Position); } } renderCapture.End(); GraphicsDevice.Clear(Color.Black); postprocessor.Input = renderCapture.GetTexture(); postprocessor.Draw(); base.Draw(gameTime); }