Skip to content

Draft: Refraction fog based on water depth

Qlonever requested to merge qlonvirniriy/depth-refraction:master into master

Similar to a merge request made by wareya !672 (merged) two years ago, but using different math to mitigate the issues people had with it.

The way the water shader currently handles refraction fog isn't very realistic. How visible an object is through water should be based on the amount of water between it and the camera, not just its distance from the camera. With the current refraction fog calculation, water turns completely opaque if the player moves too far away from it. This looks bad, and it's especially jarring if the player clears the visibility threshold quickly, as they might when falling or using jump spells. This MR changes the shader to calculate refraction fog based on water depth, using a curve instead of a linear fade to keep it from looking too transparent.

Changes:

water.frag

  • depthSampleDistorted and waterDepthDistorted are calculated after screenCoordsOffset is modified, fixing an issue where refraction fog would be misaligned when there was a sharp change in depth
  • screenCoordsOffset is modified twice to further reduce shore artifacts
  • waterDepthDistorted is interpolated with realWaterDepth to prevent splotchy coloring at shores
  • Refraction fog is calculated using waterDepthDistorted instead of depthSampleDistorted

water.cpp

  • To prevent shore artifacts at greater distances, the offset of reflection/refraction cull planes scales based on the camera's distance from the water plane and the current FOV setting

Notes:

This MR lessens the problem in #7036, but doesn't fix it completely. To fix that issue, something else needs to be done with the way reflection/refraction textures are culled, since they don't perfectly align with the actual edge of the water.

Screenshots:

Before: screenshot008 screenshot009 screenshot010 screenshot011 screenshot012
After: screenshot002 screenshot003 screenshot004 screenshot005 screenshot006

Comparisons using imgsli:
https://imgsli.com/MTc0ODY3
https://imgsli.com/MTc0ODY4
https://imgsli.com/MTc0ODY5
https://imgsli.com/MTc0ODcw
https://imgsli.com/MTc0ODcx

Edited by Qlonever

Merge request reports