Hey guys, I'm copying my full screen render target to another surface that's 1/4 the dimensions, it looks terrible with jaggies. I'm not doing anything fancy and just can't figure out the problem.
Here is how I create the render target, the smaller post target is the same except for the width and height:
D3D11_TEXTURE2D_DESC textureDesc;
memset(&textureDesc, 0, sizeof(D3D11_TEXTURE2D_DESC));
textureDesc.Width = _render_width;
textureDesc.Height = _render_height;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
textureDesc.SampleDesc.Count = 1;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
HRESULT hResult = d3d_device->CreateTexture2D(&textureDesc, NULL, &d3d_offscreen0_tex);
if (FAILED(hResult))
return -1;
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
memset(&rtvDesc, 0, sizeof(D3D11_RENDER_TARGET_VIEW_DESC));
rtvDesc.Format = textureDesc.Format;
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
hResult = d3d_device->CreateRenderTargetView(d3d_offscreen0_tex, &rtvDesc, &d3d_offscreen0_rtv);
if (FAILED(hResult))
return -1;
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
memset(&srvDesc, 0, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));
srvDesc.Format = textureDesc.Format;
srvDesc.Texture2D.MipLevels = 1;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
hResult = d3d_device->CreateShaderResourceView(d3d_offscreen0_tex, &srvDesc, &d3d_offscreen0_srv);
if (FAILED(hResult))
return -1;
Here is the sampler:
D3D11_SAMPLER_DESC samplerDesc;
memset(&samplerDesc, 0, sizeof(D3D11_SAMPLER_DESC));
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;
samplerDesc.MaxAnisotropy = 1;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
samplerDesc.MinLOD = 0.0f;
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
HRESULT hResult = d3d_device->CreateSamplerState(&samplerDesc, &point_c_sampler);
Here is the simple shader:
struct VS_INPUT
{
float3 position : POSITION;
float2 uv : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
};
VS_OUTPUT vshader(VS_INPUT input)
{
VS_OUTPUT output = (VS_OUTPUT)0;
output.position = float4(input.position.xyz, 1);
output.uv = input.uv;
return output;
}
float4 pshader(VS_OUTPUT input) : SV_TARGET
{
return Texture0.Sample(Sampler0, input.uv);
}
I render to the full screen surface, then draw a full screen quad (-1 to +1) to the smaller surface using the full screen surface as the texture, then finally draw that to the full screen back buffer. It's quite jagged, it's supposed to have the opposite effect. I just don't get it.
I did a test where I skipped the first part and instead copied a 1/4 screen sized texture to the smaller surface then drew that to the back buffer like above and it looked like it should, so it seems the minification process is the problem.
What I am doing wrong?