From c223bd47b9b2a83ed53201964e4912e2faec3d66 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Wed, 3 Aug 2016 02:01:36 +0200 Subject: VideoCommon: Implement depth range equation in vertex shader. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 19fb1f371d..0fb784167d 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -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(); -- cgit v1.2.3 From 92aa7669b58442c37b235755e2a6b6ce81963b9a Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 4 Aug 2016 18:26:45 +0200 Subject: VertexShaderManager: Use a more accurate depth range. This fixes the gxtest_depth hwtest. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 0fb784167d..83600463e9 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -388,8 +388,8 @@ void VertexShaderManager::SetConstants() 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; + constants.pixelcentercorrection[2] = xfmem.viewport.zRange / 16777215.0f; + constants.pixelcentercorrection[3] = xfmem.viewport.farZ / 16777215.0f; dirty = true; // This is so implementation-dependent that we can't have it here. -- cgit v1.2.3 From 4582853af48f67047e57b997bf923488bf444931 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sat, 6 Aug 2016 03:40:45 +0200 Subject: VertexShaderGen: Use reversed depth range. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 83600463e9..dabc7870fd 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -387,9 +387,12 @@ void VertexShaderManager::SetConstants() 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. + // The depth range is handled in the vertex shader. We need to reverse + // the far value to get a reversed depth range mapping. This is necessary + // because we have the most precision at the near plane, while the console + // has the most percision at the far plane. constants.pixelcentercorrection[2] = xfmem.viewport.zRange / 16777215.0f; - constants.pixelcentercorrection[3] = xfmem.viewport.farZ / 16777215.0f; + constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f; dirty = true; // This is so implementation-dependent that we can't have it here. -- cgit v1.2.3 From 7078216b61777ff89350d1bdc66c7c032b0b2296 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Mon, 15 Aug 2016 15:25:50 +0200 Subject: Improve documentation. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index dabc7870fd..9b1c3437fe 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -389,8 +389,9 @@ void VertexShaderManager::SetConstants() // The depth range is handled in the vertex shader. We need to reverse // the far value to get a reversed depth range mapping. This is necessary - // because we have the most precision at the near plane, while the console - // has the most percision at the far plane. + // because the standard depth range equation pushes all depth values towards + // the back of the depth buffer where conventionally depth buffers have the + // least precision. constants.pixelcentercorrection[2] = xfmem.viewport.zRange / 16777215.0f; constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f; -- cgit v1.2.3