Skip to content

Reverse-Z depth buffer

This MR introduces a reverse-Z depth buffer by rendering to a FBO and blitting the result to fullscreen geometry. It is setup so that using it for our eventual post-processing framework is seamless. This technique relies on glClipControl which only became core in OpenGL 4.5, but is still widely supported on desktops through extensions.

Introduced are some fundamental changes to the rendering side of things that will need to be considered from here on out if this is merged. Depth values now map to [1,0], near plane values can now be set to pretty much any non-zero value. Whenever the engine needs to use a RTT camera or deal with anything that relies on depth, these things need to be taken into consideration. This may sound like a headache (and it might be for some things in the future), but it allows for virtually infinite viewing distances.

Here are some comparisons with a 24 UNORM and a 32 FP depth buffer with reverse depth. Z-Fighting on terrain and the notorious scum and lava is eliminated (tested up to 5 million viewing distance with all of TR loaded).

https://streamable.com/j6o84y

https://streamable.com/bq64tt

https://streamable.com/bq3f11

https://streamable.com/slno2j

Issues:

  • Shadows are re-broken. Since directional shadows don't benefit from this, I've just went back to standard projection for shadows.
  • Dialog text not rendering.
  • Saved game screenshots corrupted.
  • Reflection RTT artifacting with small near clip. Cause of this is unknown.
  • With OPENMW_DISABLE_REVERSEZ variable faced object bound calculations seem to be broken - under some angles tooltips just do not appear
  • Culling is not working as intended with reverse-z enabled (BLOCKER)
  • Debug modes broken (moved to shader path)
  • Water ripples not showing. Note, they look weird depending on view angle in master as well.

Update:

I've since moved away from trying to support near clip < 1 for some performance concerns. With water, for example, I stuck with the default 24 UNORM format.

Edited by Cody Glassman

Merge request reports