Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!

Can't Enable MSAA

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 mroberts759   Members   -  Reputation: 102


Posted 22 September 2013 - 04:07 PM



I've been doing some development in Direct3D 11 and C++ and I can't seem to be able to enable MSAA. I am getting horrible jagged lines when rendering a simple primitive. Here is what I have done so far:


SwapChain Creation

        // Display Mode
        // --------------------------------------------------------------------

        DXGI_RATIONAL RefreshRate = {60, 1};

        DXGI_MODE_DESC DisplayMode = {0};

        DisplayMode.Width = Width;
        DisplayMode.Height = Height;
        DisplayMode.RefreshRate = RefreshRate;
        DisplayMode.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

        // --------------------------------------------------------------------

        // SwapChain Description
        // --------------------------------------------------------------------

        DXGI_SAMPLE_DESC Sampling = {4, 0};

        DXGI_SWAP_CHAIN_DESC SCDescription = {0};

        SCDescription.BufferCount = 1;
        SCDescription.BufferDesc = DisplayMode;
        SCDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
        SCDescription.OutputWindow = RenderWindow;
        SCDescription.SampleDesc = Sampling;
        SCDescription.Windowed = TRUE;

        // --------------------------------------------------------------------

RenderTarget and DepthStencil and Rasterizer

        // Create RenderTarget
        // --------------------------------------------------------------------

        ID3D11Texture2D *Resource = NULL;
        m_SwapChain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&Resource);

        D3D11_RENDER_TARGET_VIEW_DESC RTDescription;
        ZeroMemory(&RTDescription, sizeof(D3D11_RENDER_TARGET_VIEW_DESC));

        RTDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
        RTDescription.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;

        m_Device->CreateRenderTargetView(Resource, &RTDescription, 

        Resource = NULL;

        // --------------------------------------------------------------------

        // Create DepthStencil
        // --------------------------------------------------------------------

        D3D11_TEXTURE2D_DESC TextureDescription = {0};

        TextureDescription.BindFlags = D3D11_BIND_DEPTH_STENCIL;

        TextureDescription.Width = Width;
        TextureDescription.Height = Height;
        TextureDescription.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
        TextureDescription.SampleDesc = Sampling;

        TextureDescription.ArraySize = 1;
        TextureDescription.MipLevels = 1;

        ID3D11Texture2D *DepthResource = NULL;
            NULL, &DepthResource);

        D3D11_DEPTH_STENCIL_VIEW_DESC DSDescription;
        ZeroMemory(&DSDescription, sizeof(D3D11_DEPTH_STENCIL_VIEW_DESC));

        DSDescription.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
        DSDescription.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;

            &DSDescription, &m_DepthStencil);

        DepthResource = NULL;

        // --------------------------------------------------------------------

            OMSetRenderTargets(1, &m_RenderTarget, m_DepthStencil);

        // Customize Rasterizer
        // --------------------------------------------------------------------

        D3D11_RASTERIZER_DESC RasterizerDescription;
        ZeroMemory(&RasterizerDescription, sizeof(D3D11_RASTERIZER_DESC));

        RasterizerDescription.AntialiasedLineEnable = TRUE;
        RasterizerDescription.CullMode = D3D11_CULL_BACK;
        RasterizerDescription.DepthClipEnable = TRUE;
        RasterizerDescription.FillMode = D3D11_FILL_SOLID;
        RasterizerDescription.MultisampleEnable = TRUE;

        ID3D11RasterizerState *RasterizerState = NULL;

            (&RasterizerDescription, &RasterizerState);


        RasterizerState = NULL;

        // --------------------------------------------------------------------

Am I missing something? It should be noted that I am targeting D3D_FEATURE_LEVEL_9_3 and that my graphics card is capable of handling the above sampling count and quality.


Any help would be greatly appreciated!


#2 Erik Rufelt   Crossbones+   -  Reputation: 4338


Posted 22 September 2013 - 04:38 PM

I think you need to set the quality higher. You select 4 samples at quality 0, while you probably want to use a higher number. Try calling CheckMultisampleQualityLevels (http://msdn.microsoft.com/en-us/library/windows/desktop/ff476499%28v=vs.85%29.aspx) and using numQualityLevels - 1 for the quality.

#3 mroberts759   Members   -  Reputation: 102


Posted 22 September 2013 - 06:46 PM

Thanks for the reply Erik.


I've actually managed to track down my problem and it is not anti-aliasing based. The jagged edges I am seeing are actually because of the filtering on my texture. 

        D3D11_SAMPLER_DESC SamplerDescription;
        ZeroMemory(&SamplerDescription, sizeof(D3D11_SAMPLER_DESC));

        SamplerDescription.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
        SamplerDescription.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
        SamplerDescription.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
        SamplerDescription.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
        SamplerDescription.Filter = D3D11_FILTER_ANISOTROPIC;
        SamplerDescription.MaxAnisotropy = 1;
        SamplerDescription.MaxLOD = D3D11_FLOAT32_MAX;

        ID3D11SamplerState *SamplerState = NULL;

        m_Device->CreateSamplerState(&SamplerDescription, &SamplerState);
        m_DeviceContext->PSSetSamplers(0, 1, &SamplerState);

        SamplerState = NULL;

When my filter is set to D3D11_FILTER_MIN_MAG_MIP_POINT, I get some insane jaggedness. So I changed my filter to D3D11_FILTER_ANISOTROPIC. Now my jaggedness is gone, but my texture is incredibly blurry. Does anyone have any thoughts?

#4 DwarvesH   Members   -  Reputation: 482


Posted 23 September 2013 - 03:00 AM

SamplerDescription.MaxAnisotropy = 1;


Maybe that is your issue. Try setting it to 16. Or determine the maximum supported:

if (deviceCaps->RasterCaps & D3DPRASTERCAPS_ANISOTROPY)
        SamplerDescrition.MaxAnisotrophy = deviceCaps->MaxAnisotropy;

#5 MJP   Moderators   -  Reputation: 13631


Posted 23 September 2013 - 11:19 AM

The "Quality" level doesn't literally refer to the quality of the antialiasing, it's primarily used to expose different MSAA variations supported by the driver. For instance you can use Nvidia's CSAA functionality through a quality level. A quality of 0 always gives you standard MSAA using the specified number of samples.

As for the bluriness, if it's occurring on surfaces being viewed at a grazing angle then you should follow the above suggestion and try increasing your MaxAnisotropy. 

Edited by MJP, 23 September 2013 - 11:20 AM.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.