Public Member Functions | |
| LaplaceOverlay (ScreenManager screenManager) | |
| Creates a bloom overay. | |
| void | LoadContent () |
| Load effects, create textures and prepare filters for filtering from a specified source area on the screen. | |
| void | UnloadContent () |
| Unload textures. | |
| void | Draw (GameTime gameTime) |
| This is where it all happens. Grabs a scene that has already been rendered, and uses postprocess magic to add a glowing bloom effect over the top of it. | |
Definition at line 24 of file LaplaceOverlay.cs.
| NewGamePhysics.GraphicalElements.LaplaceOverlay.LaplaceOverlay | ( | ScreenManager | screenManager | ) |
Creates a bloom overay.
| screenManager | The screen manager to use. |
Definition at line 71 of file LaplaceOverlay.cs.
| void NewGamePhysics.GraphicalElements.LaplaceOverlay.Draw | ( | GameTime | gameTime | ) |
This is where it all happens. Grabs a scene that has already been rendered, and uses postprocess magic to add a glowing bloom effect over the top of it.
| gameTime | The current game time. |
Definition at line 152 of file LaplaceOverlay.cs.
00153 { 00154 // Resolve the scene into a texture, so we can 00155 // use it as input data for laplace processing. 00156 this.ScreenManager.GraphicsDevice.ResolveBackBuffer(resolveTarget); 00157 00158 // Pass 1: draw the scene into rendertarget 1, using a 00159 // shader that binarizes the image. 00160 this.extractEffect.Parameters["threshold"].SetValue(0.25f); 00161 DrawQuadWithEffect(resolveTarget, renderTarget1, this.extractEffect); 00162 00163 // Repeat Pass 2 several times 00164 for (int i = 0; i < 12; i++) 00165 { 00166 // Pass 2a: draw from rendertarget 1 into rendertarget 2, 00167 // using a shader to apply laplacian relaxation. 00168 // Look up the sample weight and offset effect parameters. 00169 this.offsetsParameter.SetValue(tapOffsets); 00170 DrawQuadWithEffect(renderTarget1.GetTexture(), renderTarget2, this.laplaceEffect); 00171 00172 // Pass 2b: draw from rendertarget 2 back into rendertarget 1, 00173 // using a shader to apply laplacian relaxation. 00174 this.offsetsParameter.SetValue(tapOffsets); 00175 DrawQuadWithEffect(renderTarget2.GetTexture(), renderTarget1, this.laplaceEffect); 00176 } 00177 00178 // Pass 4: draw both rendertarget 1 and the original scene 00179 // image back into the main backbuffer, using a shader that 00180 // combines them to produce the final bloomed result 00181 this.ScreenManager.GraphicsDevice.Textures[1] = resolveTarget; 00182 this.combineEffect.Parameters["ContourFrequency"].SetValue(128.0f); 00183 Viewport viewport = this.ScreenManager.GraphicsDevice.Viewport; 00184 this.ScreenManager.SpriteBatch.Begin( 00185 SpriteBlendMode.None, 00186 SpriteSortMode.Immediate, 00187 SaveStateMode.None); 00188 this.combineEffect.Begin(); 00189 this.combineEffect.CurrentTechnique.Passes[0].Begin(); 00190 this.ScreenManager.SpriteBatch.Draw( 00191 renderTarget1.GetTexture(), 00192 new Rectangle(0, 0, viewport.Width, viewport.Height), 00193 Color.White); 00194 this.ScreenManager.SpriteBatch.End(); 00195 this.combineEffect.CurrentTechnique.Passes[0].End(); 00196 this.combineEffect.End(); 00197 }
| void NewGamePhysics.GraphicalElements.LaplaceOverlay.LoadContent | ( | ) |
Load effects, create textures and prepare filters for filtering from a specified source area on the screen.
Definition at line 81 of file LaplaceOverlay.cs.
00082 { 00083 this.extractEffect = 00084 this.ScreenManager.Game.Content.Load<Effect>("Effects/GreyscaleCutoff"); 00085 this.laplaceEffect = 00086 this.ScreenManager.Game.Content.Load<Effect>("Effects/Laplace"); 00087 this.combineEffect = 00088 this.ScreenManager.Game.Content.Load<Effect>("Effects/CombineContour"); 00089 00090 // Look up the resolution and format of our main backbuffer. 00091 PresentationParameters presentationParams = 00092 this.ScreenManager.GraphicsDevice.PresentationParameters; 00093 int width = presentationParams.BackBufferWidth; 00094 int height = presentationParams.BackBufferHeight; 00095 SurfaceFormat format = presentationParams.BackBufferFormat; 00096 00097 // Create a texture for reading back the backbuffer contents. 00098 this.resolveTarget = new ResolveTexture2D( 00099 this.ScreenManager.GraphicsDevice, 00100 width, 00101 height, 00102 1, 00103 format); 00104 00105 // Create 4th-size render targets for relaxation 00106 width /= 8; 00107 height /= 8; 00108 renderTarget1 = new RenderTarget2D( 00109 this.ScreenManager.GraphicsDevice, 00110 width, 00111 height, 00112 1, 00113 format, 00114 this.ScreenManager.GraphicsDevice.DepthStencilBuffer.MultiSampleType, 00115 this.ScreenManager.GraphicsDevice.PresentationParameters.MultiSampleQuality); 00116 renderTarget2 = new RenderTarget2D( 00117 this.ScreenManager.GraphicsDevice, 00118 width, 00119 height, 00120 1, 00121 format, 00122 this.ScreenManager.GraphicsDevice.DepthStencilBuffer.MultiSampleType, 00123 this.ScreenManager.GraphicsDevice.PresentationParameters.MultiSampleQuality); 00124 00125 this.offsetsParameter = this.laplaceEffect.Parameters["TapOffsets"]; 00126 00127 // Precalculate offsets 00128 this.tapOffsets = new Vector2[4]; 00129 float dx = 1.0f / width; 00130 float dy = 1.0f / height; 00131 this.tapOffsets[0] = new Vector2(0.0f, dy); 00132 this.tapOffsets[1] = new Vector2(0.0f, -dy); 00133 this.tapOffsets[2] = new Vector2( dx, 0.0f); 00134 this.tapOffsets[3] = new Vector2(-dx, 0.0f); 00135 }
| void NewGamePhysics.GraphicalElements.LaplaceOverlay.UnloadContent | ( | ) |
Unload textures.
Definition at line 140 of file LaplaceOverlay.cs.
1.6.2