1
\$\begingroup\$

My anti-aliasing is not working in MonoGame. I'm not sure if I'm doing something wrong. See the image below (rotating the screen -- coordinates are all overlapping/adjacent, so should blend them):

https://i.stack.imgur.com/lcd2G.jpg

On the ctor of my Game, I have the following:

        Graphics = new GraphicsDeviceManager( this )
        {
            PreferredBackBufferHeight = 720,
            PreferredBackBufferWidth = 1280,
            PreferMultiSampling = true
        };

        Graphics.ApplyChanges();

Which, should enable Anti-Aliasing. Further, I have:

                GraphicsDevice.RasterizerState = new RasterizerState()
                {
                    CullMode = CullMode.None,
                    MultiSampleAntiAlias = true,
                };
                TileMeshEffect.CurrentTechnique.Passes[0].Apply();
                GraphicsDevice.SetVertexBuffer( TileMeshVertexBuffers[Coordinate] );
                GraphicsDevice.DrawPrimitives( PrimitiveType.TriangleList, 0, TileMeshVertexBuffers[Coordinate].VertexCount / 3 );

Right as I'm rendering the Mesh, which should, I would think, do everything necessary. I was able to confirm via debugger that both are set, and that furthermore, the number of passes was 4 (GraphicsDevice.PresentationParameters.MultiSampleCount).

Any clue what I'm doing wrong?

\$\endgroup\$
1
  • \$\begingroup\$ This is not a problem with antialiasing but rather texture blending. I assume you're rendering a tilemap right? If that's the case you need to pass in texture bounds to the shader to do antialiasing properly. Otherwise MSAA will sample outside of the texture bounds and produce seams. \$\endgroup\$
    – mklingen
    Dec 6, 2017 at 17:16

1 Answer 1

2
\$\begingroup\$

Solution

Try and add these lines just before Graphics.ApplyChanges();:

Graphics.GraphicsProfile = GraphicsProfile.HiDef;
GraphicsDevice.PresentationParameters.MultiSampleCount = 8;

You can, of course, change 8 to whatever level of AA you want. The available options are 2, 4, 8, 16, and 32. I would only use up to 8 as an absolute max though. 4 is the safest bet.

Explanation

To increase compatibility, MonoGame sets the graphics profile to Reach by default. This disables certain features (like MSAA) in order to target a wider range of devices.

You can change this profile to HiDef to get MSAA but your project may not run properly on mobiles or consoles, but if you're only targeting Windows then that's not a problem!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .