Jump to content
  • Advertisement
Sign in to follow this  
mroberts759

Can't Enable MSAA

This topic is 2125 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

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.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
        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, 
            &m_RenderTarget);

        Resource->Release();
        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;
        m_Device->CreateTexture2D(&TextureDescription, 
            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;

        m_Device->CreateDepthStencilView(DepthResource, 
            &DSDescription, &m_DepthStencil);

        DepthResource->Release();
        DepthResource = NULL;

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

        m_DeviceContext->
            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;

        m_Device->CreateRasterizerState
            (&RasterizerDescription, &RasterizerState);

        m_DeviceContext->RSSetState(RasterizerState);

        RasterizerState->Release();
        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!

Share this post


Link to post
Share on other sites
Advertisement

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->Release();
        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?

Share this post


Link to post
Share on other sites

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;

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!