Please help with unwanted interpolation?

Started by
3 comments, last by Adam Miles 5 years, 8 months ago

Hi Guys,

I have a problem where a textured quad is being severely interpolated. I am trying to achieve the clean pixelated look on the right hand of the example.

mVivMXo.png

There is no MSAA enabled on the back buffer


	DXGI_SWAP_CHAIN_DESC swapChainDesc;
	ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
	swapChainDesc.BufferCount = 2;
	swapChainDesc.BufferDesc.Width = width;
	swapChainDesc.BufferDesc.Height = height;
	swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
	swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
	swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapChainDesc.OutputWindow = hWnd;
	swapChainDesc.Windowed = true;
	swapChainDesc.SampleDesc.Count = 1;
	swapChainDesc.SampleDesc.Quality = 0;
	swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
	swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

 

I have verified in the debugger that my sampler is being applied, without asking for any anti-aliasing.


	D3D11_SAMPLER_DESC samplerDesc;

	samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
	samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
	samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
	samplerDesc.MipLODBias = 0.0f;
	samplerDesc.MaxAnisotropy = 1;
	samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
	samplerDesc.MinLOD = -FLT_MAX;
	samplerDesc.MaxLOD = FLT_MAX;

	if (FAILED(d3dDevice->CreateSamplerState(&samplerDesc, &d3dSamplerDefault)))
		return E_WINDOW_SAMPLER_DESC;

	d3dContext->PSSetSamplers(0, 1, &d3dSamplerDefault);

 

And the default blend state, which as far as I can tell should be ok.


	// Create default blend state
	ID3D11BlendState* d3dBlendState = NULL;
	D3D11_BLEND_DESC omDesc;
	ZeroMemory(&omDesc, sizeof(D3D11_BLEND_DESC));
	omDesc.RenderTarget[0].BlendEnable = true;
	omDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
	omDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
	omDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
	omDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
	omDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
	omDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
	omDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

	if (FAILED(d3dDevice->CreateBlendState(&omDesc, &d3dBlendState)))
		return E_WINDOW_DEVICE_BLEND_STATE;

	d3dContext->OMSetBlendState(d3dBlendState, 0, 0xffffffff);
	if (d3dBlendState)
		d3dBlendState->Release();

 

And the pixel shader, which is as basic as can be.


SamplerState samLinear : register(s0);
Texture2D squareMap : register(t0);

struct VS_OUTPUT
{
	float4 position : SV_POSITION;
	float2 textureCoord : TEXCOORD0;
};

float4 ps_main(VS_OUTPUT input) : SV_TARGET
{
	return squareMap.Sample(samLinear, input.textureCoord);
}

 

I have a ton of error checking and there are no failed calls and the debugger shows that everything is running great.

Any ideas as to why I am still getting interpolation would be hugely appreciated :)

Advertisement

samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR

That's requesting bilinear filtering of your texture data. You want point / nearest neighbour filtering. 

18 minutes ago, Hodgman said:

samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR

That's requesting bilinear filtering of your texture data. You want point / nearest neighbour filtering. 

Awesome! Thanks Hodgman.

samplerDesc.Filter = D3D11_FILTER_MAXIMUM_MIN_MAG_MIP_POINT seemed to do the job.

You don't want to use D3D11_FILTER_MAXIMUM_MIN_MAG_MIP_POINT. You want D3D11_FILTER_MIN_MAG_MIP_POINT instead.

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

This topic is closed to new replies.

Advertisement