diff --git a/desmume/src/OGLRender.cpp b/desmume/src/OGLRender.cpp index 5944ec282..b5ee2c2a4 100644 --- a/desmume/src/OGLRender.cpp +++ b/desmume/src/OGLRender.cpp @@ -331,7 +331,8 @@ static const char *fragmentShader_100 = {"\ discard; \n\ } \n\ \n\ - gl_FragDepth = (oglWBuffer) ? vtxPosition.w/4096.0 : vtxPosition.z/4096.0; \n\ + float vertW = (vtxPosition.w == 0.0f) ? 0.00000001f : vtxPosition.w; \n\ + gl_FragDepth = (oglWBuffer) ? vtxPosition.w/4096.0 : (vtxPosition.z / vertW) * 0.5 + 0.5; \n\ gl_FragColor = fragColor; \n\ } \n\ "}; diff --git a/desmume/src/OGLRender_3_2.cpp b/desmume/src/OGLRender_3_2.cpp index 543ab9e2b..902ba4c43 100644 --- a/desmume/src/OGLRender_3_2.cpp +++ b/desmume/src/OGLRender_3_2.cpp @@ -181,7 +181,8 @@ static const char *fragmentShader_150 = {"\ discard; \n\ } \n\ \n\ - gl_FragDepth = (oglWBuffer) ? vtxPosition.w/4096.0 : vtxPosition.z/4096.0; \n\ + float vertW = (vtxPosition.w == 0.0f) ? 0.00000001f : vtxPosition.w; \n\ + gl_FragDepth = (oglWBuffer) ? vtxPosition.w/4096.0 : (vtxPosition.z / vertW) * 0.5 + 0.5; \n\ outFragColor = fragColor; \n\ } \n\ "};