Grand Theft Auto IV on PC suffers from severe z-fighting due to the use of a conventional 24-bit depth buffer. This repository provides a logarithmic depth implementation for the game's shaders, which brings it up to par with the console versions. A showcase is available here.
There are some prerequisites for these shaders to work correctly and examples of each of them are implemented in FusionFix:
- Depth bounds test (specifically D3DRS_ADAPTIVETESS_X) needs to be disabled to fix light pop-in on Nvidia graphics cards, and on AMD if using DXVK.
- The game's current near and far clip values need to be sent to the c227 vertex shader register for corona depth test to work (in deferred_lightingVS11).
- Near and far clip overrides need to be removed from cutscenes and timecycmodifiers in order to prevent flickering, as the game tends to update their values erratically.
- Since the game uses the same registers for orthographic and perspective projection, we only write logarithmic depth in the case of the latter to not break rain, UI and such.
- The incorrect ZShift sign in gta_emissivestrong was fixed. We also provide edited traffic light models to go with this because newer versions have emissive depth write always enabled.
- Emissives have a few other tweaks to prevent them from being visible through the fog at the far clip.
- Soft particles have been fixed as well, courtesy of Robi.
Special thanks to RaphaelK12, AssaultKifle47, robi29, ThirteenAG and Shvab. Fixing this monumental issue wouldn't have been possible without their help.
- Brano Kemen - Maximizing Depth Buffer Range and Precision
- Thatcher Ulrich - Logarithmic Depth Buffer (we used the function from here)