0

I am creating a small game engine in Direct X 11 which is going great but i noticed that 3D objects as well as 2D Objects seem very rough around the edges when rendering. I previously came from Direct X 9 and this issue did not exist there. I was wondering how can I properly enable anti aliasing or some kind of multi-sampling so that my textures don't come out with jagged edges.

swapChainDesc.SampleDesc.Count = 2;
swapChainDesc.SampleDesc.Quality = 0;

depthBufferDesc.SampleDesc.Count = 2;
depthBufferDesc.SampleDesc.Quality = 0;

These are the count and quality combinations but no matter what setting is here there is no visual difference or Direct3D will fail to create the device. My GPU is not overwriting anything since the settings are designed to use whatever the application decides.

2 Answers2

2

In addition to enabling the MSAA sample count for the swap chain's render target, your depth/stencil buffer, and using the correct values for related views (D3D11_TEX2DMS_RTV, D3D11_DSV_DIMENSION_TEXTURE2DMS), you need to actually set D3D11_RASTERIZER_DESC.MultisampleEnable to TRUE in your rasterizer states:

CD3D11_RASTERIZER_DESC rastDesc(D3D11_FILL_SOLID, D3D11_CULL_NONE, FALSE,
    D3D11_DEFAULT_DEPTH_BIAS, D3D11_DEFAULT_DEPTH_BIAS_CLAMP,
    D3D11_DEFAULT_SLOPE_SCALED_DEPTH_BIAS, TRUE, FALSE,
    TRUE /*this is MSAA enable*/, FALSE);

See the Simple rendering lesson for DirectX Tool Kit for a more detailed example.

With Direct3D Feature Level 10.1 or greater hardware will support 4x MSAA. Direct3D Feature Level 11.0 or greater hardware will support 4x and 8x MSAA. Everything should support 2x MSAA.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • This seemed to work for the edges, but my texture is still slightly disorted. For example, a simple ring texture is slightly distorted and you can see a box inside of it. I have a screenshot that compares the source image to what is actually rendered in game. https://www.dropbox.com/s/epkipy37o0b3yq7/comparison.png?dl=0 Could there be some other issue? This doesn't happen in Direct3D 9 or anywhere else for that matter. – user5901143 Apr 01 '16 at 02:14
  • There are a lot of states in the pipeline, so there could be any number of reasons. You have different backgrounds in the two images, so that also contributes to differences in blending. Are you doing any [texel shifting](https://msdn.microsoft.com/en-us/library/windows/desktop/bb205073.aspx#Mapping_Texels_to_Pixels_DX10) in your shaders? – Chuck Walbourn Apr 01 '16 at 05:21
  • For the source image I added a black background using gimp. But that is how it is supposed to look. I don't do any shifting, my shader only does basic texturing no effects or modifications applied. – user5901143 Apr 01 '16 at 05:44
  • Distorsion is not the same as aliasing, and msaa only works for triangle edges, not surfaces. I can imagine these issues to double check for you. 1, you are using point filtering and are not perfectly align on pixels and 2, your window client rectangle is slighty smaller than the swap chain surface and there is a poor rescale apply at the presentation. – galop1n Apr 01 '16 at 17:18
  • Ah, I noticed that the AdjustWindowRect parameters I supplied didn't actually do anything so I looked at the code I had in my DirectX 9 engine to fix it. Such a silly mistake. Thank you. – user5901143 Apr 01 '16 at 20:35
0

you can call ResolveSubresource to apply MSAA filtering

For example: pDeviceContext->ResolveSubresource(DstTexture, 0, MultisampledTexture, 0, MultisampledTexture.Format);

DstTexture gets filtered and staircase visual distortions should be reduced or eliminated.