Unformatted text preview:

1 Postprocessing Prof. Aaron Lanterman School of Electrical and Computer Engineering Georgia Institute of Technology 2 Bloom effect - before http://creators.xna.com/en-us/sample/bloom 3 Bloom effect - after http://creators.xna.com/en-us/sample/bloom Motion blur in Valve’s Portal - roll 4 http://www.valvesoftware.com/publications/2008/GDC2008_PostProcessingInTheOrangeBox.pdf2 Motion blur in Valve’s Portal - falling 5 http://www.valvesoftware.com/publications/2008/GDC2008_PostProcessingInTheOrangeBox.pdf 6 Giant warning The code in these slides has not been tested. There may be bugs and/or misconceptions. 7 Typical XNA setup code GraphicsDeviceManager graphics =! new GraphicsDeviceManager(this);!ContentManager content = ! new ContentManager(Services);!GraphicsDevice device =! graphics.GraphicsDevice;!Based on discussion on p. 277-281 of Chad Carter, “Microsoft XNA Unleashed,” 2008 8 Setup for postprocessing SpriteBatch mySpriteBatch;!RenderTarget2D myRenderTarget;!Texture2D beforeProc;!Effect ppEffect;!ppEffect = ! content.Load<Effect>(@”Content\Effects\CoolEffect”);!Based on discussion on p. 277-281 of Chad Carter, “Microsoft XNA Unleashed,” 20083 9 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 10 Creating the rendertarget (advanced) myRenderTarget = new RenderTarget2D(device,!device.Viewport.Width,!device.Viewport.Height,!1, ! ! ! ! ! // number of mipmap levels!device.DisplayMode.Format,! // a SurfaceFormat!sevice.PresentationParameters.MultiSampleType,!sevice.PresentationParameters.MultiSampleQuality)!Based on discussion on p. 277-281 of Chad Carter, “Microsoft XNA Unleashed,” 2008 11 SurfaceFormat enumeration Screenshot from msdn2.microsoft.com/en-us/library/microsoft.xna.framework.graphics.surfaceformat.aspx 12 Direct3D/XNA SurfaceFormat conversions Screenshot from msdn2.microsoft.com/en-us/library/microsoft.xna.framework.graphics.surfaceformat.aspx4 13 Rendering the preprocessed scene device.SetRenderTarget(0,myRenderTarget);!// On Xbox 360, first argument must be set to zero!// since you only can set one Render Target on the 360!// PUT CODE TO DRAW STUFF HERE!// in XNA 1.0, needed to ResolveRenderTarget on Xbox 360!// to copy eDRAM contents to main RAM, but not on Windows!// in XNA 2.0, don’t need this line anymore on either platform!// device.ResolveRenderTarget(0); <- don’t need now!// Set render target to the usual backbuffer !// in XNA 2.0, resolving happens automatically here!device.SetRenderTarget(0, null);!beforeProc = myRenderTarget.GetTexture();!Based on discussion on p. 277-281 of Chad Carter, “Microsoft XNA Unleashed,” 2008 and http://blogs.msdn.com/shawnhar/archive/2007/11/21/rendertarget-changes-in-xna-game-studio-2-0.aspx 14 Setting up the postprocessing effect myEffect.CurrentTechnique = !!!effect.Techniques[“BlurEffect”];!myEffect.Parameters[“offset”].SetValue(offset);!Based on discussion on p. 277-281 of Chad Carter, “Microsoft XNA Unleashed,” 2008 15 Drawing the processed scene device.Clear(Color.Black);!myEffect.Begin();!mySpriteBatch.Begin(SpriteBlendMode.None, !SpriteSortMode.Immediate, SaveStateMode.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 This can be problematic – we’ll come back to this 16 Just need a pixel shader Based on discussion on p. 277-281 of Chad Carter, “Microsoft XNA Unleashed,” 2008 // CoolEffect.fx!sampler textureSampler; !// globals default to uniform & extern!float2 offset;!float4 threewayBlurPS(float2 texCoord : TEXCOORD0) : COLOR0 !{! float4 color =! (tex2D(textureSampler,texCoord)! + tex2D(textureSampler,texCoord + offset)! + tex2D(textureSampler,texCoord - offset)) / 3;! return color;!}!technique BlurEffect {!!pass P0 {!!!PixelShader = compile ps_2_0 threewayBlurPS();!!}!}!5 17 Behind the scenes 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;!18 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: 19 Rendertarget semantics on Windows • If not multisampling, a single area of video memory can be used for rendering or as a texture – In XNA 1.0: • Contents of rendertarget not lost in XNA 1.0 on Windows • Resolve is a no-op – Rendertarget cleared in XNA 2.0 to emulate Xbox 360 behavior • If multisampling, need large area to render into and small area to copy into – Resolve copies, downsampling as it goes – Contents of both buffers not lost (in XNA 1.0) From Shawn Hargreaves, “Rendertarget changes in XNA Game Studio 2.0,” http://blogs.msdn.com/shawnhar/archive/2007/11/21/ rendertarget-changes-in-xna-game-studio-2-0.aspx 20 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 – Rendertarget in eDRAM is cleared From Shawn Hargreaves, “XNA rendertarget semantics,” blogs.msdn.com/shawnhar/archive/2007/02/04/xna-rendertarget-semantics.aspx6 What about SaveStateMode.None? • May mess up rendering of 3-D objects • SpriteBatch will change renderstates to things inappropriate for 3-D drawing 21 mySpriteBatch.Begin(SpriteBlendMode.None, !SpriteSortMode.Immediate, SaveStateMode.None);!From


View Full Document

GT ECE 4893 - Postprocessing

Documents in this Course
Load more
Download Postprocessing
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Postprocessing and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Postprocessing 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?