MSAA artifacts

Started by
5 comments, last by dr4cula 9 years, 9 months ago

Hello,

I have a bit of a problem with MSAA and DX11. It seems to be working but causing visual artifacts at the same time. On the image below, from left to right, MSAA settings as count-quality pairs: {1,0}, {4,16}, {8,32}:

msaaproblem.png

To enable MSAA, I used following code pieces:

On SwapChain creation:


swapChainDesc.SampleDesc.Count = 4;
swapChainDesc.SampleDesc.Quality = 16;
Relevant rasterizer settings:

rasterizerDesc.MultisampleEnable = true;
rasterizerDesc.AntialiasedLineEnable = true;
Render target and depth-stencil setup:


// get the backbuffer texture
ID3D11Texture2D* bufferTex;
HRESULT texGet = swapChain_->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&bufferTex));
if(FAILED(texGet)) {
MessageBox(nullptr, L"Failed getting the backbuffer texture.", L"Error", 0);
return;
}
 
// get the backbuffer texture's description
D3D11_TEXTURE2D_DESC texDesc;
bufferTex->GetDesc(&texDesc);
 
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = texDesc.Format;
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
 
HRESULT rtvCreation = device_->CreateRenderTargetView(bufferTex, &rtvDesc, &defaultRenderTargetView_);
if(FAILED(rtvCreation)) {
MessageBox(nullptr, L"Failed creating the default render-target view.", L"Error", 0);
return;
}
 
// define the depth stencil view texture
D3D11_TEXTURE2D_DESC depthStencilTexDesc;
depthStencilTexDesc.Width = texDesc.Width;
depthStencilTexDesc.Height = texDesc.Height;
depthStencilTexDesc.MipLevels = 1;
depthStencilTexDesc.ArraySize = 1;
depthStencilTexDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilTexDesc.SampleDesc.Count = texDesc.SampleDesc.Count;
depthStencilTexDesc.SampleDesc.Quality = texDesc.SampleDesc.Quality;
depthStencilTexDesc.Usage = D3D11_USAGE_DEFAULT;
depthStencilTexDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthStencilTexDesc.CPUAccessFlags = 0;
depthStencilTexDesc.MiscFlags = 0;
 
ID3D11Texture2D* depthStencilTex;
HRESULT depthStencilTexCreation = device_->CreateTexture2D(&depthStencilTexDesc, nullptr, &depthStencilTex);
if(FAILED(depthStencilTexCreation)) {
MessageBox(nullptr, L"Failed creating the depth-stencil texture.", L"Error", 0);
return;
}
 
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
dsvDesc.Format = depthStencilTexDesc.Format;
dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
dsvDesc.Flags = 0;
 
HRESULT depthStencilViewCreation = device_->CreateDepthStencilView(depthStencilTex, &dsvDesc, &defaultDepthStencilView_);
if(FAILED(depthStencilViewCreation)) {
MessageBox(nullptr, L"Failed creating the default depth-stencil view.", L"Error", 0);
return;
}
 
// clean up
SAFE_RELEASE(depthStencilTex);
SAFE_RELEASE(bufferTex);
None of the other objects in the scene seem to get this kind of problem. Don't really understand why multisampling would cause this...
Thanks in advance!
Advertisement

It appears the 3 pix are also of different resolutions. If you do lighting calcs in a pixel shader, are you sure it's not a specular (or other) lighting artifact? If you turn off lighting do you still have the problem?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

It appears the 3 pix are also of different resolutions. If you do lighting calcs in a pixel shader, are you sure it's not a specular (or other) lighting artifact? If you turn off lighting do you still have the problem?

Thanks for the suggestion! Looks like you are right. If I comment out the specular term then the artifact disappears. I really don't know where I've gone wrong with the equation though:


float3 V = normalize(-positionVS);
float3 H = normalize(L + V);
result += lightSpecular.rgb * Ks.rgb * pow(max(dot(H, normalVS), 0.0f), Ns);

Would it be safe to assume that the model itself has a bit funky normals? Thanks again!

EDIT: it seems that other models exhibit the same sort of behavior on very thin mesh parts: for example the legs of a chair, but not all of them, have these artifacts as well.

In the 1x MSAA case, do you get flickering/crawling specular artifacts on the mesh when you move the camera around? If that's the case, then you're probably just experiencing run-of-the-mill shader aliasing. Shader aliasing occurs when you have high-frequency detail in the geometry or normal maps combined with high-frequency specular in the pixel shader, there's not enough pixels to sample the specular without noticable artifacts.

In the 1x MSAA case, do you get flickering/crawling specular artifacts on the mesh when you move the camera around? If that's the case, then you're probably just experiencing run-of-the-mill shader aliasing. Shader aliasing occurs when you have high-frequency detail in the geometry or normal maps combined with high-frequency specular in the pixel shader, there's not enough pixels to sample the specular without noticable artifacts.

Thanks for replying.

There's no flickering what-so-ever with 1x MSAA. That part of the speaker model doesn't even have a texture - it's all just color shaded. Odd, to say the least...

Try max(dot(H, normalVS), 0.0001f) and/or max(Ns, 0.0001f)? IIRC if both are zero you get NaN.

Try max(dot(H, normalVS), 0.0001f) and/or max(Ns, 0.0001f)? IIRC if both are zero you get NaN.

Didn't have time to test this out until now: unfortunately this didn't fix the issue...

This topic is closed to new replies.

Advertisement