Docsity

Post Processing in XNA - Slides - GPU Programming for Video Games | ECE 4893, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
Postprocessing in XNA
Prof. Aaron Lanterman
School of Electrical and Computer Engineering
Georgia Institute of Technology
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Post Processing in XNA - Slides - GPU Programming for Video Games | ECE 4893 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Postprocessing in XNA

Prof. Aaron Lanterman

School of Electrical and Computer Engineering

Georgia Institute of Technology

2

Giant warning

The code in these slides

has not been tested.

There may be bugs

and/or misconceptions.

4 Setup for postprocessing

SpriteBatch mySpriteBatch;

RenderTarget2D myRenderTarget;

Texture2D beforeProc;

Effect ppEffect;

ppEffect =

content.Load(@”Content\Effects\CoolEffect”);

Based on discussion on p. 277-281 of Chad Carter, “Microsoft XNA Unleashed,” 2008

5 Creating the rendertarget myRenderTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height, 1, // number of mipmap levels device.DisplayMode.Format // a SurfaceFormat) Vector2 offset = new Vector2(0,1 / device.Viewport.Height); Based on discussion on p. 277-281 of Chad Carter, “Microsoft XNA Unleashed,” 2008

7 SurfaceFormat enumeration Screenshot from msdn2.microsoft.com/en-us/library/microsoft.xna.framework.graphics.surfaceformat.aspx

8 Direct3D/XNA SurfaceFormat Conversions Screenshot from msdn2.microsoft.com/en-us/library/microsoft.xna.framework.graphics.surfaceformat.aspx

10 Setting up the postprocessing effect // Next sort of line only seems necessary if you have // more than one technique myEffect.CurrentTechnique = effect.Techniques[“BlurEffect”]; myEffect.Parameters[“offset”].SetValue(offset); Based on discussion on p. 277-281 of Chad Carter, “Microsoft XNA Unleashed,” 2008

11 Drawing the processed scene

device.Clear(Color.Black);

myEffect.Begin();

mySpriteBatch.Begin(SpriteBlendMode.None,

SpriteSortMode.Immediate, SpriteStateMode.None);

EffectPass pass = effect.CurrentTechnique.Passes[0]

pass.Begin();

mySpriteBatch.Draw(beforeProc, Vector2.Zero,

Color.White);

pass.End();

mySpriteBatch.End();

myEffect.End();

Based on discussion on p. 277-281 of Chad Carter, “Microsoft XNA Unleashed,” 2008

13 Just need a pixel shader Based on discussion on p. 277-281 of Chad Carter, “Microsoft XNA Unleashed,” 2008

sampler textureSampler

is sort of implicitly

sampler textureSampler : register(S0);

mySpriteBatch.Draw(beforeProc, Vector.Zero,

Color.White);

was sort of doing this somewhere:

device.Textures[0] = beforeProc;

14 Multiple textures From msdn2.microsoft.com/en- us/library/microsoft.xna.framework.graphics.graphicsdevice.textures.aspx

graphics.GraphicsDevice.Textures[0] = firstTexture;

graphics.GraphicsDevice.Textures[1] = secondTexture;

sampler firstSampler : register(s0);

sampler secondSampler : register(s1);

  • In your C# code:
  • In your shader code:

16 Rendertarget semantics on Xbox 360

  • Xenos GPU renders into only one physical rendertarget: 10 MB eDRAM - Cannot texture from eDRAM - Cannot render into main 512M RAM
  • Must “resolve” to copy rendering in eDRAM back to main memory - Hardware designed to make this fast - Note from Shawn: “It is less obvious why the resolve call needs to

clear the special memory, but apparently there is a performance

gain from doing this: I don't pretend to understand why but I'm not

going to complain as long as this keeps my Xbox running as fast

as it does!”

From Shawn Hargreaves, “XNA rendertarget semantics,” blogs.msdn.com/shawnhar/archive/2007/02/04/xna-rendertarget-semantics.aspx

17 Shawn Hargraves’ chart From Shawn Hargreaves, “XNA rendertarget semantics,” blogs.msdn.com/shawnhar/archive/2007/02/04/xna-rendertarget-semantics.aspx

Shawn’s advice: “If you play it safe by always assuming your buffer

contents will be lost when you call SetRenderTarget or Resolve,

that code will work consistently on all platforms.”