VideoCommon: Implement depth range equation in vertex shader.
This commit is contained in:
parent
0015d2e86b
commit
c223bd47b9
|
@ -1115,12 +1115,6 @@ void Renderer::SetViewport()
|
|||
(float)scissorYOff);
|
||||
float Width = EFBToScaledXf(2.0f * xfmem.viewport.wd);
|
||||
float Height = EFBToScaledYf(-2.0f * xfmem.viewport.ht);
|
||||
float GLNear = MathUtil::Clamp<float>(
|
||||
xfmem.viewport.farZ -
|
||||
MathUtil::Clamp<float>(xfmem.viewport.zRange, -16777216.0f, 16777216.0f),
|
||||
0.0f, 16777215.0f) /
|
||||
16777216.0f;
|
||||
float GLFar = MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f;
|
||||
if (Width < 0)
|
||||
{
|
||||
X += Width;
|
||||
|
@ -1142,7 +1136,7 @@ void Renderer::SetViewport()
|
|||
auto iceilf = [](float f) { return static_cast<GLint>(ceilf(f)); };
|
||||
glViewport(iceilf(X), iceilf(Y), iceilf(Width), iceilf(Height));
|
||||
}
|
||||
glDepthRangef(GLFar, GLNear);
|
||||
glDepthRangef(0.0f, 1.0f);
|
||||
}
|
||||
|
||||
void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable,
|
||||
|
|
|
@ -399,14 +399,14 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da
|
|||
out.Write("o.colors_1 = color1;\n");
|
||||
}
|
||||
|
||||
// We have to handle the depth range in the vertex shader, because some games will use a depth range beyond
|
||||
// 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");
|
||||
|
||||
// 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
|
||||
if (g_ActiveConfig.backend_info.bSupportsClipControl)
|
||||
{
|
||||
out.Write("o.pos.z = -o.pos.z;\n");
|
||||
}
|
||||
else // OGL
|
||||
if (!g_ActiveConfig.backend_info.bSupportsClipControl)
|
||||
{
|
||||
// this results in a scale from -1..0 to -1..1 after perspective
|
||||
// divide
|
||||
|
|
|
@ -386,6 +386,11 @@ void VertexShaderManager::SetConstants()
|
|||
const float pixel_size_y = 2.f / Renderer::EFBToScaledXf(2.f * xfmem.viewport.ht);
|
||||
constants.pixelcentercorrection[0] = pixel_center_correction * pixel_size_x;
|
||||
constants.pixelcentercorrection[1] = pixel_center_correction * pixel_size_y;
|
||||
|
||||
// The depth range is handled in the vertex shader.
|
||||
constants.pixelcentercorrection[2] = (xfmem.viewport.zRange) / 16777216.0f;
|
||||
constants.pixelcentercorrection[3] = (xfmem.viewport.farZ) / 16777216.0f;
|
||||
|
||||
dirty = true;
|
||||
// This is so implementation-dependent that we can't have it here.
|
||||
g_renderer->SetViewport();
|
||||
|
|
Loading…
Reference in New Issue