Water shaders, OpenMW vs MGEXE
Posted: 12 Jul 2018, 09:40
OpenMW
MGEXE
MGEXE
Yep, we already have the depth data. We're currently discussing the water shader improvements at GitLab, will add this feature.AnyOldName3 wrote: ↑12 Jul 2018, 12:15 I'm pretty sure the depth of the water is used for something already (as at the very least it's something that needs to be known to get refraction right. If the effect isn't there, we do already have all the data we need to implement it.
Code: Select all
diff --git a/files/shaders/water_fragment.glsl b/files/shaders/water_fragment.glsl
index 7511375..4025c1c 100644
--- a/files/shaders/water_fragment.glsl
+++ b/files/shaders/water_fragment.glsl
@@ -253,10 +253,10 @@ void main(void)
// refraction
#if REFRACTION
- vec3 refraction = texture2D(refractionMap, screenCoords - screenCoordsOffset).rgb;
+ vec3 underwater = texture2D(refractionMap, screenCoords - screenCoordsOffset).rgb;
// brighten up the refraction underwater
- refraction = (cameraPos.z < 0.0) ? clamp(refraction * 1.5, 0.0, 1.0) : refraction;
+ vec3 refraction = (cameraPos.z < 0.0) ? clamp(underwater * 1.5, 0.0, 1.0) : underwater;
#endif
// specular
vec3 R = reflect(vVec, normal);
@@ -269,7 +269,11 @@ void main(void)
if (cameraPos.z > 0.0)
refraction = mix(refraction, waterColor, clamp(depthSampleDistorted/VISIBILITY, 0.0, 1.0));
- gl_FragData[0].xyz = mix( mix(refraction, scatterColour, lightScatter), reflection, fresnel) + specular * gl_LightSource[0].specular.xyz;
+ vec3 output = mix( mix(refraction, scatterColour, lightScatter), reflection, fresnel) + specular * gl_LightSource[0].specular.xyz;
+ output = mix( underwater, output, pow(shore,10));
+
+ gl_FragData[0].xyz = output;
+
#else
gl_FragData[0].xyz = mix(reflection, waterColor, (1.0-fresnel)*0.5) + specular * gl_LightSource[0].specular.xyz;
#endif
I agree, however I noticed that this is how it's usually done in games, e.g. 0 A. D.:AnyOldName3 wrote: ↑12 Jul 2018, 15:48 I think the transparency effect there is way too strong. IRL, it's easy to see where the water starts and the ground stops, but in those screenshots, it isn't.