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.

This commit is contained in:
rogerman 2019-01-14 12:08:33 -08:00
parent 9b1ce0efc3
commit 0f045d430c
2 changed files with 9 additions and 7 deletions

View File

@ -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\

View File

@ -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\