Improving distant terrain distance
Posted: 17 Sep 2017, 13:26
This topic is to discuss/plan relatively simple ways distant terrain can be improved, both from a user perspective, and a design perspective. If some consensus can be reached, I could attempt to do something (or if not, we'll have something down for someone else). Note also that this is relatively simple things -- not distant statics, LODs, or such things -- what I'm discussing should be doable now with (hopefully) little hassle.
To start with, an issue that arises is that simply enabling distant terrain does nothing from the user's perspective. This is because the far clipping plane remains tied to the viewing distance, which is set for being in the default 3x3 cell configuration. The user has to also increase the viewing distance to see the distant terrain, but this causes a few problems. First, most users will have no idea what appropriate values would be, or what effect it will actually have on certain aspects of rendering (e.g. depth buffer resolution). Secondly, increasing the viewing distance has an effect on the atmospheric fog (all but removes it, because the viewing distance is both the far clip plane and the fog end point, with various weathers altering fog relative to that). Third, because the viewing distance is vastly increased, it makes the in-game viewing distance option a liability; touching it will undo the extended view distance and there's no way to set it back other than exiting and re-editing the config. Fourth, the viewing distance that gets set (for the far clipping plane) is ultimately arbitrary because there's no ideal (or even "good enough") value. Given that the purpose of distant terrain is to include everything the eye can see, the far clip plane should be set as far as realistically possible and not need any adjustment.
The first issue can be easily fixed by automatically using a more distant far clip plane when distant terrain is enabled. The viewing distance setting can still control the fog distance, but having the fog end separate from the far clip plane when distant terrain is enabled would then solve the second and third issues (fixing the fog itself to look good with an increased view can then be done with shaders or something). The remaining points (the effects of the far clip distance on depth resolution, and an arbitrary far clip distance) are a little trickier to deal with, but I think are more than doable.
For the far clip distance, it can default to something that works okay for a typical Morrowind install (with Tamriel Rebuilt in mind, if possible). Doesn't have to necessarily be able to show everything if it would cause issues with Z-fighting, but a good chunk would be nice. Eventually, we can try utilizing a reversed depth buffer to be able to set a far clip distance so large, no mod would realistically hit it (practically infinite, even if technically not). Note that while that post mentions that trick only works in Direct3D, and OpenGL needs to use a custom projection matrix and the GL_NV_depth_buffer_float extension to make it work, there is GL_ARB_clip_control which allows it to work like in Direct3D (without the custom projection matrix or NV extension).
To sum up, when distant terrain is enabled:
Separate the far clip plane from the fog end distance, leaving the fog end distance controlled by the viewing distance setting.
Automatically use a farther far clip plane not tied to the viewing distance setting.
Set the far clip plane to something that's okay for most games, possibly with a new setting to adjust it (separate from the already-existing viewing distance setting). And consider the option to use a reversed depth buffer for extending the far clip plane to no man's land, where no further adjustments are needed.
I could work on separating the fog distance and far clip plane and setting an alternative far clip plane distance for distant terrain. However, I'm not quite as well-versed in OSG as I'd like, and it's been a while since I poked around in the rendering code, so I may stumble when it comes to that.
To start with, an issue that arises is that simply enabling distant terrain does nothing from the user's perspective. This is because the far clipping plane remains tied to the viewing distance, which is set for being in the default 3x3 cell configuration. The user has to also increase the viewing distance to see the distant terrain, but this causes a few problems. First, most users will have no idea what appropriate values would be, or what effect it will actually have on certain aspects of rendering (e.g. depth buffer resolution). Secondly, increasing the viewing distance has an effect on the atmospheric fog (all but removes it, because the viewing distance is both the far clip plane and the fog end point, with various weathers altering fog relative to that). Third, because the viewing distance is vastly increased, it makes the in-game viewing distance option a liability; touching it will undo the extended view distance and there's no way to set it back other than exiting and re-editing the config. Fourth, the viewing distance that gets set (for the far clipping plane) is ultimately arbitrary because there's no ideal (or even "good enough") value. Given that the purpose of distant terrain is to include everything the eye can see, the far clip plane should be set as far as realistically possible and not need any adjustment.
The first issue can be easily fixed by automatically using a more distant far clip plane when distant terrain is enabled. The viewing distance setting can still control the fog distance, but having the fog end separate from the far clip plane when distant terrain is enabled would then solve the second and third issues (fixing the fog itself to look good with an increased view can then be done with shaders or something). The remaining points (the effects of the far clip distance on depth resolution, and an arbitrary far clip distance) are a little trickier to deal with, but I think are more than doable.
For the far clip distance, it can default to something that works okay for a typical Morrowind install (with Tamriel Rebuilt in mind, if possible). Doesn't have to necessarily be able to show everything if it would cause issues with Z-fighting, but a good chunk would be nice. Eventually, we can try utilizing a reversed depth buffer to be able to set a far clip distance so large, no mod would realistically hit it (practically infinite, even if technically not). Note that while that post mentions that trick only works in Direct3D, and OpenGL needs to use a custom projection matrix and the GL_NV_depth_buffer_float extension to make it work, there is GL_ARB_clip_control which allows it to work like in Direct3D (without the custom projection matrix or NV extension).
To sum up, when distant terrain is enabled:
Separate the far clip plane from the fog end distance, leaving the fog end distance controlled by the viewing distance setting.
Automatically use a farther far clip plane not tied to the viewing distance setting.
Set the far clip plane to something that's okay for most games, possibly with a new setting to adjust it (separate from the already-existing viewing distance setting). And consider the option to use a reversed depth buffer for extending the far clip plane to no man's land, where no further adjustments are needed.
I could work on separating the fog distance and far clip plane and setting an alternative far clip plane distance for distant terrain. However, I'm not quite as well-versed in OSG as I'd like, and it's been a while since I poked around in the rendering code, so I may stumble when it comes to that.