From 0f045d430c525e19ecb9b7f497c7007dba805599 Mon Sep 17 00:00:00 2001 From: rogerman Date: Mon, 14 Jan 2019 12:08:33 -0800 Subject: [PATCH] OpenGL Renderer: When rendering the main geometry, adjusts all Z-positions in the vertex shader so that Z is more likely to naturally fall between the depth range of 0.0 and 1.0. Further mitigates the performance cost of using the NDS-Style Depth Calculation option. --- desmume/src/OGLRender.cpp | 9 +++++---- desmume/src/OGLRender_3_2.cpp | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/desmume/src/OGLRender.cpp b/desmume/src/OGLRender.cpp index d75ea542d..c23afbeab 100755 --- a/desmume/src/OGLRender.cpp +++ b/desmume/src/OGLRender.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2006 yopyop Copyright (C) 2006-2007 shash - Copyright (C) 2008-2018 DeSmuME team + Copyright (C) 2008-2019 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -294,7 +294,8 @@ void main() \n\ \n\ vtxTexCoord = texScaleMtx * inTexCoord0; \n\ vtxColor = vec4(inColor / 63.0, polyAlpha); \n\ - gl_Position = inPosition; \n\ + gl_Position.xyw = inPosition.xyw;\n\ + gl_Position.z = (inPosition.z + inPosition.w) / 2.0;\n\ } \n\ "}; @@ -419,10 +420,10 @@ void main()\n\ #endif\n\ #else\n\ #if ENABLE_W_DEPTH\n\ - gl_FragDepth = clamp( (4096.0/gl_FragCoord.w) / 16777215.0, 0.0, 1.0 );\n\ + gl_FragDepth = (4096.0/gl_FragCoord.w) / 16777215.0;\n\ #else\n\ // hack: when using z-depth, drop some LSBs so that the overworld map in Dragon Quest IV shows up correctly\n\ - gl_FragDepth = clamp( (floor(gl_FragCoord.z * 4194303.0) * 4.0) / 16777215.0, 0.0, 1.0 );\n\ + gl_FragDepth = (floor(gl_FragCoord.z * 4194303.0) * 4.0) / 16777215.0;\n\ #endif\n\ #endif\n\ #endif\n\ diff --git a/desmume/src/OGLRender_3_2.cpp b/desmume/src/OGLRender_3_2.cpp index 729a40023..d6a57a410 100755 --- a/desmume/src/OGLRender_3_2.cpp +++ b/desmume/src/OGLRender_3_2.cpp @@ -146,7 +146,8 @@ void main()\n\ \n\ vtxTexCoord = texScaleMtx * inTexCoord0;\n\ vtxColor = vec4(inColor / 63.0, polyAlpha);\n\ - gl_Position = inPosition;\n\ + gl_Position.xyw = inPosition.xyw;\n\ + gl_Position.z = (inPosition.z + inPosition.w) / 2.0;\n\ }\n\ "}; @@ -290,10 +291,10 @@ void main()\n\ #endif\n\ #else\n\ #if ENABLE_W_DEPTH\n\ - gl_FragDepth = clamp( (4096.0/gl_FragCoord.w) / 16777215.0, 0.0, 1.0 );\n\ + gl_FragDepth = (4096.0/gl_FragCoord.w) / 16777215.0;\n\ #else\n\ // hack: when using z-depth, drop some LSBs so that the overworld map in Dragon Quest IV shows up correctly\n\ - gl_FragDepth = clamp( (floor(gl_FragCoord.z * 4194303.0) * 4.0) / 16777215.0, 0.0, 1.0 );\n\ + gl_FragDepth = (floor(gl_FragCoord.z * 4194303.0) * 4.0) / 16777215.0;\n\ #endif\n\ #endif\n\ #endif\n\