Wednesday, April 15, 2009

Improving the rendering of your models with MultiSampling in XNA

When you first compile, build and render your models in XNA, they can look pretty bad.  By default MultiSampling isn’t enabled for your game.  If you enable MultiSampling, the appearance of your models will be greatly enhanced. 

MultiSampling will antialias the edges of the triangles for your model. According the XNA Developer Center

Antialiasing is the process of smoothing the edges of triangles by averaging neighboring pixels in a render target. Because this process samples multiple pixels, it is also known as multisampling.

The first screen capture is from the Windows version of my game that does not have MultiSampling enabled.

NoMultiSampling

 

The second screen capture show how this looks with MultiSampling enabled.

MultiSampling

 

As you can see the grid lines look much better as well as the guns and the edges of the ships.

 

Enabling MultiSampling is easy, in the constructor of your game you will need to set a property and hookup an event.

The instructions can be found at:

http://msdn.microsoft.com/en-us/library/bb975403.aspx

 

It’s important to note that you MUST setup your graphics device in the constructor.  I had done this in the Initialize function, at that point the Graphics Device has already been setup and resetting it causes very bad things to happen once you deploy your game to the XBOX 360 (this cost me about 4 hours that I’ll never get back).

Enjoy!

-ec

No comments:

Post a Comment