Search code examples
c#xnamonogameantialiasingmsaa

Can't enable MSAA in MonoGame


I want to enable/disable MSAA in runtime and in order to do that I have this function:

GraphicsDeviceManager _graphics = new GraphicsDeviceManager(this)
...

private void ChangeMsaaSetting(bool enable)
{
    _graphics.PreferMultiSampling = enable;

    var rasterizerState = new RasterizerState
    {
        MultiSampleAntiAlias = enable,
    };

    GraphicsDevice.RasterizerState = rasterizerState;
    GraphicsDevice.PresentationParameters.MultiSampleCount = enable ? 2 : 0;

    _graphics.ApplyChanges();
}

Before I call it everything is normal: the objects in the scene are rendered with pixelated edges. As soon as I call the function passing true, the models disappear and I'm left with the CornflowerBlue background I clear my GraphicsDevice with.

But after I call ChangeMsaaSetting(false) objects start getting rendered again.

I've experimented a bit and it seems that objects disappear if MultiSampleCount is set to an integer greater than 1. Singular samples are useless so I need to have a bigger value there. Am I doing something wrong?


Solution

  • MSAA is not currently supported in monogame. Use https://github.com/SeriousMaxx/FXAAMonoGame instead.

    It will provide a very high quality post process AA.