Tuesday, September 1, 2009

XNA BloomComponent and Multisampling

The Bloom Postprocess sample provided on the XNA website has issues if you use the component in a game that is using multisampling.

You'll get the following error:

"The active render target and depth stencil surface must have the same pixel size and multisampling type."

The issue is that the render targets created by the component do not respect the multisampling settings of the graphics device. This is easy to fix, however. In the LoadContent() method of BloomComponent.cs, find the code that is initializing renderTarget1 and renderTarget2.

Replace it with the following:

           renderTarget1 = new RenderTarget2D(GraphicsDevice, width, height, 1,
format, GraphicsDevice.DepthStencilBuffer.MultiSampleType, GraphicsDevice.PresentationParameters.MultiSampleQuality);
renderTarget2 = new RenderTarget2D(GraphicsDevice, width, height, 1,
format, GraphicsDevice.DepthStencilBuffer.MultiSampleType, GraphicsDevice.PresentationParameters.MultiSampleQuality);

1 comment: