VertexShaderGen: Correct vertex shader output to consider shifted pixel centers.

Fixes issue 267.
This commit is contained in:
Tony Wasserka 2014-04-23 23:42:28 +02:00
parent 65e0579d9f
commit c47c32d4a8
2 changed files with 19 additions and 0 deletions

View File

@ -419,6 +419,14 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
//seems to get rather complicated //seems to get rather complicated
} }
// The console GPU places the pixel center at 7/12 in screen space unless
// antialiasing is enabled, while D3D and OpenGL place it at 0.5. This results
// in some primitives being placed one pixel too far to the bottom-right,
// which in turn can be critical if it happens for clear quads.
// Hence, we compensate for this pixel center difference so that primitives
// get rasterized correctly.
out.Write("o.pos.xy = o.pos.xy - " I_DEPTHPARAMS".zw;\n");
if (api_type == API_OPENGL) if (api_type == API_OPENGL)
{ {
// Bit ugly here // Bit ugly here

View File

@ -360,6 +360,17 @@ void VertexShaderManager::SetConstants()
bViewportChanged = false; bViewportChanged = false;
constants.depthparams[0] = xfregs.viewport.farZ / 16777216.0f; constants.depthparams[0] = xfregs.viewport.farZ / 16777216.0f;
constants.depthparams[1] = xfregs.viewport.zRange / 16777216.0f; constants.depthparams[1] = xfregs.viewport.zRange / 16777216.0f;
// The console GPU places the pixel center at 7/12 unless antialiasing
// is enabled, while D3D and OpenGL place it at 0.5. See the comment
// in VertexShaderGen.cpp for details.
// NOTE: If we ever emulate antialiasing, the sample locations set by
// BP registers 0x01-0x04 need to be considered here.
const float pixel_center_correction = 7.0f / 12.0f - 0.5f;
const float pixel_size_x = 2.f / Renderer::EFBToScaledXf(2.f * xfregs.viewport.wd);
const float pixel_size_y = 2.f / Renderer::EFBToScaledXf(2.f * xfregs.viewport.ht);
constants.depthparams[2] = pixel_center_correction * pixel_size_x;
constants.depthparams[3] = pixel_center_correction * pixel_size_y;
dirty = true; dirty = true;
// This is so implementation-dependent that we can't have it here. // This is so implementation-dependent that we can't have it here.
g_renderer->SetViewport(); g_renderer->SetViewport();