Artifacts in water reflection due to imprecise screen-space coordinate computation
When positioning the camera right above the water surface, there are weird artifacts in the reflection:
(No, those are not micro-ripples
Operating system, OpenMW version, etc.
OpenMW version is master, OS is Fedora 33, GPU/Mesa version is Radeon RX 560 Series (POLARIS11, DRM 3.42.0, 5.14.13-100.fc33.x86_64, LLVM 11.0.0) (0x67ff)
.
Root cause
The root cause of this are numerical issues in the reconstruction of screen-space coordinates; when the viewing direction is parallel to the water surface, and the camera is just above the surface, the screen-space projected location of the water quad can take on extreme values. water_vertex.glsl
attaches those projected locations to the vertex locations.
water_fragment.glsl
then accesses the interpolated information attached to the vertices; at some point in this process funny numerical shenanigans happen.
Potential solution
Use gl_FragCoord
directly to access the screen-space coordinates. This makes the vertex shader unnecessary. Problem with this is that the viewport size needs to be passed to water_fragment.glsl
. While this is simple in principle, and I'll open MR that kind of does this, OSG makes this frustratingly difficult. Viewport coordinates are also required by (not directly, see below) maybe there should be some unified way to access those (maybe using the PostProcessing
shaders;SharedUniformStateUpdater
)?