120 likes | 193 Views
XBLIG-UK 2011. Post Processing in XNA 4.0 By Charles Humphrey. 2nd March 2011. Wikipedia says:-
E N D
XBLIG-UK 2011 Post Processing in XNA 4.0 By Charles Humphrey 2nd March 2011
Wikipedia says:- “Post-processing is commonly used in 3D rendering, especially for video games. Instead of rendering 3D objects directly to the display, the scene is first rendered to a buffer in the memory of the video card. Pixel shaders are then used to apply post-processing filters to the image buffer before displaying it to the screen. Post-processing allows effects to be used that require awareness of the entire image (since normally each 3D object is rendered in isolation).” What is Post Processing?
Holds a list of BasePostProcessingEffect • Draw method • Receives the rendered scene and depth map as textures. • Loops through each BasePostProcessingEffect • Call their Draw methods. • Current scene is up dated after each BasePostProcessingEffect.Draw call to be passed onto next BasePostProcessingEffect • Renders the final scene texture PostProcessingManager
Holds a list of BasePostProcess • Draw Method • Stores a copy of the original scene. • Loop through each BasePostProcess. • Set Half Pixel value. • Pass original scene texture (not all need it) • Set the BasePostProcess render target • Set the BasePostProcess back buffer (current scene) • Set the BasePostProcess depth buffer • Call the BasePostProcess Draw method • Resolve the BasePostProcess render target • Record the last scene rendered texture (used for next BasePostProcess’s back buffer) BasePostProcessingEffect
Holds an Effect for the required pixel shader • Renders the scene texture and applies the pixel shader BasePostProcess
Depth of Field • Poison Disc Blur • Depth of Field • Bloom • Bright Pass • Gaussian Blur • Vertical • Horizontal • Bloom • Haze • Bump map Distort • Radial Blur • Radial Blur • Ripple • Ripple • Fog • Fog • Sun • Sun Post Process Samples
Write your pixel shader • Derive from BasePostProcess • public class Bloom : BasePostProcess • Override the Draw call public override void Draw(GameTimegameTime) { if (effect == null) { effect = Game.Content.Load<Effect>("Shaders/PostProcessing/Bloom"); effect.CurrentTechnique = effect.Techniques["BloomComposite"]; } effect.Parameters["SceneTex"].SetValue(orgBuffer); effect.Parameters["BloomIntensity"].SetValue(BloomIntensity); effect.Parameters["BloomSaturation"].SetValue(BloomSaturation); effect.Parameters["BaseIntensity"].SetValue(BaseIntensity); effect.Parameters["BaseSaturation"].SetValue(BaseSaturation); // Set Params. base.Draw(gameTime); } Creating a Post Process
Derive from BasePostProcessingEffect • public class BloomEffect : BasePostProcessingEffect • Create the Post Process instances you need bp = new BrightPass(game, threshold); gbv = new GaussBlurV(game, blurAmount); gbh = new GaussBlurH(game, blurAmount); b = new Bloom(game, intensity, saturation, baseIntensity, baseSatration); • Add them to your list of BasePostProcess’s AddPostProcess(bp); AddPostProcess(gbv); AddPostProcess(gbh); AddPostProcess(b); Creating a Post Process Effect
Create and instance of the Post Processing Manager • ppManager = new PostProcessingManager(this); • Create instance of your new effect • bloom = new BloomEffect(this, 1.25f, 1f, 1f, 1f, .25f, 4f); • Add to the Post Processing Manager • ppManager.AddEffect(bloom); Use the new Post Process Effect
Kyle Hayward aka Graphics Runner Blog http://graphicsrunner.blogspot.com Post Processing Sample http://graphicsrunner.blogspot.com/2008/06/post-process-framework-sample.html Inspiration from…