From fbc7cf5e651ecb5b5d762a9aeca3aae0d44a5ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20St=C3=B6ckel?= Date: Thu, 4 Nov 2021 00:37:09 -0400 Subject: [PATCH 1/2] Fix #6386 Use `gl_FragCoords` instead passing the normalised screen-space coordinates to the fragment shader in a numerically unstable way. --- files/shaders/water_fragment.glsl | 6 +++--- files/shaders/water_vertex.glsl | 9 --------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/files/shaders/water_fragment.glsl b/files/shaders/water_fragment.glsl index 26f83e052c..1dbe7d14cf 100644 --- a/files/shaders/water_fragment.glsl +++ b/files/shaders/water_fragment.glsl @@ -132,7 +132,6 @@ vec2 normalCoords(vec2 uv, float scale, float speed, float time, float timer1, f return uv * (WAVE_SCALE * scale) + WIND_DIR * time * (WIND_SPEED * speed) -(previousNormal.xy/previousNormal.zz) * WAVE_CHOPPYNESS + vec2(time * timer1,time * timer2); } -varying vec3 screenCoordsPassthrough; varying vec4 position; varying float linearDepth; @@ -152,6 +151,8 @@ uniform vec3 nodePosition; uniform float rainIntensity; +uniform vec2 screenRes; + #define PER_PIXEL_LIGHTING 0 #include "shadows_fragment.glsl" @@ -178,8 +179,7 @@ void main(void) float shadow = unshadowedLightRatio(linearDepth); - vec2 screenCoords = screenCoordsPassthrough.xy / screenCoordsPassthrough.z; - screenCoords.y = (1.0-screenCoords.y); + vec2 screenCoords = gl_FragCoord.xy / screenRes; #define waterTimer osg_SimulationTime diff --git a/files/shaders/water_vertex.glsl b/files/shaders/water_vertex.glsl index 8e506a57f8..3a6c352ac8 100644 --- a/files/shaders/water_vertex.glsl +++ b/files/shaders/water_vertex.glsl @@ -2,7 +2,6 @@ uniform mat4 projectionMatrix; -varying vec3 screenCoordsPassthrough; varying vec4 position; varying float linearDepth; @@ -13,14 +12,6 @@ void main(void) { gl_Position = projectionMatrix * (gl_ModelViewMatrix * gl_Vertex); - mat4 scalemat = mat4(0.5, 0.0, 0.0, 0.0, - 0.0, -0.5, 0.0, 0.0, - 0.0, 0.0, 0.5, 0.0, - 0.5, 0.5, 0.5, 1.0); - - vec4 texcoordProj = ((scalemat) * ( gl_Position)); - screenCoordsPassthrough = texcoordProj.xyw; - position = gl_Vertex; vec4 viewPos = gl_ModelViewMatrix * gl_Vertex; From 81f2fa992f42c7a51e0d7c85c0dddb0ccd658ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20St=C3=B6ckel?= Date: Tue, 9 Nov 2021 23:27:32 -0500 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3cbf9802e..e50b77229a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ Bug #6354: SFX abruptly cut off after crossing max distance; implement soft fading of sound effects Bug #6363: Some scripts in Morrowland fail to work Bug #6376: Creatures should be able to use torches + Bug #6386: Artifacts in water reflection due to imprecise screen-space coordinate computation Feature #890: OpenMW-CS: Column filtering Feature #2554: Modifying an object triggers the instances table to scroll to the corresponding record Feature #2780: A way to see current OpenMW version in the console