{"action":"created","issue":{"url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/4085","repository_url":"https://api.github.com/repos/dolphin-emu/dolphin","labels_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/4085/labels{/name}","comments_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/4085/comments","events_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/4085/events","html_url":"https://github.com/dolphin-emu/dolphin/pull/4085","id":169367238,"number":4085,"title":"VideoCommon: Implement depth range equation in vertex shader.","user":{"login":"Armada651","id":2028870,"avatar_url":"https://avatars.githubusercontent.com/u/2028870?v=3","gravatar_id":"","url":"https://api.github.com/users/Armada651","html_url":"https://github.com/Armada651","followers_url":"https://api.github.com/users/Armada651/followers","following_url":"https://api.github.com/users/Armada651/following{/other_user}","gists_url":"https://api.github.com/users/Armada651/gists{/gist_id}","starred_url":"https://api.github.com/users/Armada651/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Armada651/subscriptions","organizations_url":"https://api.github.com/users/Armada651/orgs","repos_url":"https://api.github.com/users/Armada651/repos","events_url":"https://api.github.com/users/Armada651/events{/privacy}","received_events_url":"https://api.github.com/users/Armada651/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dolphin-emu/dolphin/labels/RFC","name":"RFC","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":23,"created_at":"2016-08-04T12:54:35Z","updated_at":"2016-08-09T22:01:54Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/4085","html_url":"https://github.com/dolphin-emu/dolphin/pull/4085","diff_url":"https://github.com/dolphin-emu/dolphin/pull/4085.diff","patch_url":"https://github.com/dolphin-emu/dolphin/pull/4085.patch"},"body":"### Fixes\r\n\r\n- [DKCR-fast-depth](https://fifoci.dolphin-emu.org/compare/1923906-1922806/)\r\n- haruhi\r\n- [metroid-visor](https://fifoci.dolphin-emu.org/compare/1923832-1922750/)\r\n- [mini-ninjas](https://fifoci.dolphin-emu.org/compare/1923896-1922758/)\r\n- [goldeneye-depth](https://fifoci.dolphin-emu.org/compare/1923875-1922805/)\r\n- [ss-timestone on ogl-lin-mesa](https://fifoci.dolphin-emu.org/compare/1923824-1922716/), already works on other setups.\r\n- [fifa-street on ogl-lin-mesa](https://fifoci.dolphin-emu.org/compare/1927370-1924784/), already works on other setups.\r\n\r\n### Breaks\r\n\r\n- [line-width-test on ogl-lin-intel](https://fifoci.dolphin-emu.org/compare/1923697-1922688/), but it works fine on Windows\r\n- [mkdd-efb on ogl-lin-mesa](https://fifoci.dolphin-emu.org/compare/1923816-1922743/), it was already broken on [ogl-lin-intel](https://fifoci.dolphin-emu.org/compare/1923634-1922641/) and Nvidia\r\n- [simpsons-game on ogl-lin-mesa](https://fifoci.dolphin-emu.org/compare/1923841-1922785/), it was already broken on [ogl-lin-intel](https://fifoci.dolphin-emu.org/compare/1923681-1922705/) and it works fine on Nvidia\r\n- [mii-channel on ogl-lin-mesa](https://fifoci.dolphin-emu.org/compare/1923867-1922762/), it was already broken on [ogl-lin-intel](https://fifoci.dolphin-emu.org/result/1923675/) and it works fine on Nvidia\r\n- [mkwii-bluebox on ogl-lin-mesa](https://fifoci.dolphin-emu.org/compare/1923852-1922767/), it was already broken on [ogl-lin-intel](https://fifoci.dolphin-emu.org/compare/1923623-1922689/) and it works fine on Nvidia\r\n\r\n### Driver bug reports\r\n\r\n[Bug 97231 - GL_DEPTH_CLAMP doesn't clamp to the far plane](https://bugs.freedesktop.org/show_bug.cgi?id=97231)\r\n[Bug 97232 - Line rendering broken in Dolphin when using gl_ClipDistance](https://bugs.freedesktop.org/show_bug.cgi?id=97232)\r\n\r\n### Explanation\r\n\r\nThere are quite a few edge cases that use a depth range beyond 2^24. What that effectively does is apply a depth bias, but rather than try a bunch of workarounds again I've decided to move the depth range code to the vertex shader.\r\n\r\nIn the vertex shader we're not bound by the limitations of setting the depth range through the graphics API. Thus we can much more closely match the equation that the console uses, though with a compensation for the perspective division and the reversed depth: `z = farZ * w - zRange * z`.\r\n\r\nHowever, since we're now processing the depth range before the perspective division we end up with depth clipping happening on `-w <= farZ * w + zRange * z <= w` instead of `-w <= z <= w`. To fix that we use a user-defined near clipping plane. We also disable depth clipping to get rid of the incorrect equation and to clamp depth values to the far plane to match console behavior.\r\n\r\nAt first I also wanted to revert the reversed depth trick, however this caused us to be inaccurate. This is caused by the fact that what we consider to be the far plane, the console considers to be the near plane. Without reversed depth we would place all objects at the far plane where the depth buffer has the least accuracy. With reversed depth we force these objects to be placed at the near plane where we have the most accuracy.\r\n\r\n### Fallback\r\n\r\nOpenGL ES doesn't support user-defined clipping nor depth clamping. In this case we will fallback to the old depth range code. This will cause the depth values to be incorrect again, but that can simply be solved with slow depth.\r\n\r\nIf we do not fall back to the old depth range code we will get inaccurate clipping, which slow depth can't solve. Therefore I think that it's more important to have accurate clipping than accurate depth in this case.\r\n\r\nThere are also potentially devices that do support user-defined clipping, but don't support depth clamping. In this we have no way to disable the incorrect  `-w <= farZ * w + zRange * z <= w` clipping, so that will still give inaccurate clipping. In this case we also fall back to the old depth range code.\r\n\r\n### Previous attempts\r\n\r\nPR #3587 and PR #3676.\r\n\r\n<!-- Reviewable:start -->\r\n---\r\nThis change is [<img src=\"https://reviewable.io/review_button.svg\" height=\"34\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.io/reviews/dolphin-emu/dolphin/4085)\r\n<!-- Reviewable:end -->\r\n"},"comment":{"url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/comments/238706145","html_url":"https://github.com/dolphin-emu/dolphin/pull/4085#issuecomment-238706145","issue_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/4085","id":238706145,"user":{"login":"GitToTheHub","id":13721821,"avatar_url":"https://avatars.githubusercontent.com/u/13721821?v=3","gravatar_id":"","url":"https://api.github.com/users/GitToTheHub","html_url":"https://github.com/GitToTheHub","followers_url":"https://api.github.com/users/GitToTheHub/followers","following_url":"https://api.github.com/users/GitToTheHub/following{/other_user}","gists_url":"https://api.github.com/users/GitToTheHub/gists{/gist_id}","starred_url":"https://api.github.com/users/GitToTheHub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GitToTheHub/subscriptions","organizations_url":"https://api.github.com/users/GitToTheHub/orgs","repos_url":"https://api.github.com/users/GitToTheHub/repos","events_url":"https://api.github.com/users/GitToTheHub/events{/privacy}","received_events_url":"https://api.github.com/users/GitToTheHub/received_events","type":"User","site_admin":false},"created_at":"2016-08-09T22:01:54Z","updated_at":"2016-08-09T22:01:54Z","body":"Ok, thank you for your explanation. If graphic changes are done, i always looked the diffs in the FifoCI and thought the things shown there, bugs or enhancements, i can see in my games if use that pr version by using DirectX. Now i understand, that things are primaly developed and tested for OpenGL. Thanks."}}
{"actor":{"display_login":"GitToTheHub"}}