12
XBLIG-UK 2011 Post Processing in XNA 4.0 By Charles Humphrey 2nd March 2011

XBLIG-UK 2011

  • Upload
    merlin

  • View
    23

  • Download
    0

Embed Size (px)

DESCRIPTION

XBLIG-UK 2011. Post Processing in XNA 4.0 By Charles Humphrey. 2nd March 2011. Wikipedia says:- - PowerPoint PPT Presentation

Citation preview

Page 1: XBLIG-UK 2011

XBLIG-UK 2011Post Processing in XNA 4.0

By Charles Humphrey

2nd March 2011

Page 2: XBLIG-UK 2011

What is Post Processing?

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).”

Page 3: XBLIG-UK 2011

Post Processing Pipeline

Set Render Target

Render Scene

Resolve Render Target

Apply Pixel Shader

Render Result

Page 4: XBLIG-UK 2011

PostProcessingManager

Holds a list of BasePostProcessingEffectDraw 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

Page 5: XBLIG-UK 2011

BasePostProcessingEffect

Holds a list of BasePostProcessDraw 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)

Page 6: XBLIG-UK 2011

BasePostProcess

Holds an Effect for the required pixel shader

Renders the scene texture and applies the pixel shader

Page 7: XBLIG-UK 2011

Post Process Samples

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

Page 8: XBLIG-UK 2011

Creating a Post Process

Write your pixel shader Derive from BasePostProcess

◦ public class Bloom : BasePostProcess

Override the Draw callpublic override void Draw(GameTime gameTime)

{ 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); }

Page 9: XBLIG-UK 2011

Creating a Post Process Effect

Derive from BasePostProcessingEffect◦ public class BloomEffect : BasePostProcessingEffect

Create the Post Process instances you needbp = 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’sAddPostProcess(bp);AddPostProcess(gbv);AddPostProcess(gbh);AddPostProcess(b);

Page 10: XBLIG-UK 2011

Use the new 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);

Page 11: XBLIG-UK 2011

Questions?

Page 12: XBLIG-UK 2011

Inspiration from…

Kyle Hayward aka Graphics RunnerBloghttp://graphicsrunner.blogspot.com

Post Processing Samplehttp://graphicsrunner.blogspot.com/2008/06/post-process-framework-sample.html