Angella Andrea - English Blog

Infinite passion for software development !
posts - 15, comments - 20, trackbacks - 16

XNA – Multisampling

Multisampling is an antialiasing technique directly supported by DirectX and obviously by XNA. The problem of aliasing occurs when you draw a line on a monitor with low resolution. In that cases you see a stair step when approximating a line by a matrix of pixels. Multisampling use neighbouring pixels (called samples) to calculate the final color of a pixel.

You can enable multisampling in XNA in this simple way:

graphics.PreferMultiSampling = true;


Then you should also specify two options.

The type is an enumerator (MultiSampleType) that represent the number of samples to use in multisampling. The quality is an integer that represent the quality level. This value is always set to zero. Before to set the type of multisampling you should always check if the graphic adapter support it using the method adapter.CheckDeviceMultiSampleType()

graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>((sender, e) => 
{
PresentationParameters parameters = e.GraphicsDeviceInformation.PresentationParameters;
parameters.MultiSampleQuality = 0;

#if XBOX
pp.MultiSampleType = MultiSampleType.FourSamples;
return;
#else

int
quality;
GraphicsAdapter adapter = e.GraphicsDeviceInformation.Adapter;
SurfaceFormat format = adapter.CurrentDisplayMode.Format;

if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format, false, MultiSampleType.FourSamples, out quality))
{
parameters.MultiSampleType = MultiSampleType.FourSamples;
}
else if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format, false, MultiSampleType.TwoSamples, out quality))
{
parameters.MultiSampleType = MultiSampleType.TwoSamples;
}
});

 

For more information:

http://en.wikipedia.org/wiki/Multisample_anti-aliasing

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

Print | posted on sabato 29 maggio 2010 03:00 | Filed Under [ XNA ]

Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET