VideoBackends: Enable depth clamping.

This commit is contained in:
Jules Blok 2016-08-03 21:54:22 +02:00
parent b1ed7e80fb
commit e9e81ece65
6 changed files with 7 additions and 21 deletions

View File

@ -440,7 +440,7 @@ ID3D11RasterizerState* StateCache::Get(RasterizerState state)
return it->second;
D3D11_RASTERIZER_DESC rastdc = CD3D11_RASTERIZER_DESC(D3D11_FILL_SOLID, state.cull_mode, false, 0,
0.f, 0, true, true, false, false);
0.f, 0, false, true, false, false);
ID3D11RasterizerState* res = nullptr;

View File

@ -578,14 +578,7 @@ void Renderer::SetViewport()
Wd = (X + Wd <= GetTargetWidth()) ? Wd : (GetTargetWidth() - X);
Ht = (Y + Ht <= GetTargetHeight()) ? Ht : (GetTargetHeight() - Y);
D3D11_VIEWPORT vp = CD3D11_VIEWPORT(
X, Y, Wd, Ht,
1.0f - MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f,
1.0f -
MathUtil::Clamp<float>(xfmem.viewport.farZ - MathUtil::Clamp<float>(xfmem.viewport.zRange,
0.0f, 16777216.0f),
0.0f, 16777215.0f) /
16777216.0f);
D3D11_VIEWPORT vp = CD3D11_VIEWPORT(X, Y, Wd, Ht, D3D11_MIN_DEPTH, 16777215.0f / 16777216.0f);
D3D::context->RSSetViewports(1, &vp);
}

View File

@ -329,7 +329,7 @@ D3D12_RASTERIZER_DESC StateCache::GetDesc12(RasterizerState state)
0,
0.f,
0,
true,
false,
true,
false,
0,

View File

@ -484,12 +484,8 @@ void Renderer::SetViewport()
D3D12_VIEWPORT vp = {
x, y, width, height,
1.0f - MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f,
1.0f -
MathUtil::Clamp<float>(xfmem.viewport.farZ - MathUtil::Clamp<float>(xfmem.viewport.zRange,
0.0f, 16777216.0f),
0.0f, 16777215.0f) /
16777216.0f};
D3D12_MIN_DEPTH,
16777215.0f / 16777216.0f };
D3D::current_command_list->RSSetViewports(1, &vp);
}

View File

@ -725,6 +725,7 @@ Renderer::Renderer()
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_CLIP_DISTANCE0);
glEnable(GL_DEPTH_CLAMP);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment
@ -1137,7 +1138,7 @@ void Renderer::SetViewport()
auto iceilf = [](float f) { return static_cast<GLint>(ceilf(f)); };
glViewport(iceilf(X), iceilf(Y), iceilf(Width), iceilf(Height));
}
glDepthRangef(0.0f, 1.0f);
glDepthRangef(0.0f, 16777215.0f / 16777216.0f);
}
void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable,

View File

@ -407,10 +407,6 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da
// the normal depth range of 0..1.
out.Write("o.pos.z = o.pos.w * " I_PIXELCENTERCORRECTION".w + o.pos.z * " I_PIXELCENTERCORRECTION".z;\n");
// We have to clamp to 2^24 - 1 here, because we map our depth range to 0..2^24 to prevent round-trip errors.
// Thus we test for values that will result in 2^24 or higher after the perspective divide.
out.Write("if (o.pos.z / o.pos.w >= 1.0) o.pos.z = 16777215.0 / 16777216.0 * o.pos.w;\n");
// write the true depth value, if the game uses depth textures pixel shaders will override with
// the correct values
// if not early z culling will improve speed