From 91036ae160b82bd58a6c93fe80f8ace9226428d2 Mon Sep 17 00:00:00 2001 From: pierre Date: Thu, 23 Sep 2010 19:38:49 +0000 Subject: [PATCH] Slightly adjust z-values calculated in the vertex shader so OGL does not clip the final rendering of (at least) Sonic Unleashed. This should be (nearly) invisible in Z16 depth copies and in games, but there is some chance that it collides with other such border cases. There probably is some room to decrease the adjustment but 9999999/10000000 is not enough. A static offset may be an option, too. I don't know if the game can/does set something like that. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6225 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Core/VideoCommon/Src/VertexShaderGen.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index ab9e46182b..9b231e229e 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -507,13 +507,20 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type) // this results in a scale from -1..0 to -1..1 after perspective // divide WRITE(p, "o.pos.z = o.pos.w + o.pos.z * 2.0f;\n"); + + // Sonic Unleashed puts its final rendering at the near or + // far plane of the viewing frustrum(actually box, they use + // orthogonal projection for that), and we end up putting it + // just beyond, and the rendering gets clipped away. (The + // primitive gets dropped) + WRITE(p, "o.pos.z = o.pos.z * 1048575.0f/1048576.0f;\n"); + // the next steps of the OGL pipeline are: - // o.pos.xyz /= o.pos.w; //perspective divide - // o.pos.z = clamp(o.pos.z,-1,1) //clamp to -1..1 - // o.pos.z = (o.pos.z+1)/2; //scale to 0..1 - // o.pos.z = o.pos.z/(glFar-glNear))+glNear - //scale to glNear..glFar of glDepthRange - // o.pos.z now contains the value to go to the 0..1 depth buffer + // (x_c,y_c,z_c,w_c) = o.pos //switch to OGL spec terminology + // clipping to -w_c <= (x_c,y_c,z_c) <= w_c + // (x_d,y_d,z_d) = (x_c,y_c,z_c)/w_c//perspective divide + // z_w = (f-n)/2*z_d + (n+f)/2 + // z_w now contains the value to go to the 0..1 depth buffer //trying to get the correct semantic while not using glDepthRange //seems to get rather complicated