1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 03:35:27 +00:00

Minor water shader cleanup - avoid redundant calculations

This commit is contained in:
bzzt 2019-02-20 13:37:00 +00:00 committed by Andrei Kortunov
parent d707eaac36
commit 4708db258e

View File

@ -6,7 +6,7 @@
// tweakables -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- // tweakables -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
const float VISIBILITY = 2.5; const float VISIBILITY = 2500;
const float BIG_WAVES_X = 0.1; // strength of big waves const float BIG_WAVES_X = 0.1; // strength of big waves
const float BIG_WAVES_Y = 0.1; const float BIG_WAVES_Y = 0.1;
@ -36,7 +36,7 @@ const vec3 SUN_EXT = vec3(0.45, 0.55, 0.68); //sunlight extinction
const float SPEC_HARDNESS = 256.0; // specular highlights hardness const float SPEC_HARDNESS = 256.0; // specular highlights hardness
const float BUMP_SUPPRESS_DEPTH = 0.3; // at what water depth bumpmap will be supressed for reflections and refractions (prevents artifacts at shores) const float BUMP_SUPPRESS_DEPTH = 300; // at what water depth bumpmap will be supressed for reflections and refractions (prevents artifacts at shores)
const vec2 WIND_DIR = vec2(0.5f, -0.8f); const vec2 WIND_DIR = vec2(0.5f, -0.8f);
const float WIND_SPEED = 0.2f; const float WIND_SPEED = 0.2f;
@ -151,11 +151,11 @@ uniform float rainIntensity;
float frustumDepth; float frustumDepth;
float linearizeDepth(float depth) // takes <0,1> non-linear depth value and returns <0,1> linearized value float linearizeDepth(float depth)
{ {
float z_n = 2.0 * depth - 1.0; float z_n = 2.0 * depth - 1.0;
depth = 2.0 * near * far / (far + near - z_n * frustumDepth); depth = 2.0 * near * far / (far + near - z_n * frustumDepth);
return depth / frustumDepth; return depth;
} }
void main(void) void main(void)
@ -239,10 +239,9 @@ void main(void)
fresnel = clamp(fresnel, 0.0, 1.0); fresnel = clamp(fresnel, 0.0, 1.0);
#if REFRACTION #if REFRACTION
float normalization = frustumDepth / 1000; float depthSample = linearizeDepth(texture2D(refractionDepthMap,screenCoords).x);
float depthSample = linearizeDepth(texture2D(refractionDepthMap,screenCoords).x) * normalization; float depthSampleDistorted = linearizeDepth(texture2D(refractionDepthMap,screenCoords-(normal.xy*REFR_BUMP)).x);
float depthSampleDistorted = linearizeDepth(texture2D(refractionDepthMap,screenCoords-(normal.xy*REFR_BUMP)).x) * normalization; float surfaceDepth = linearizeDepth(gl_FragCoord.z);
float surfaceDepth = linearizeDepth(gl_FragCoord.z) * normalization;
float realWaterDepth = depthSample - surfaceDepth; // undistorted water depth in view direction, independent of frustum float realWaterDepth = depthSample - surfaceDepth; // undistorted water depth in view direction, independent of frustum
float shore = clamp(realWaterDepth / BUMP_SUPPRESS_DEPTH,0,1); float shore = clamp(realWaterDepth / BUMP_SUPPRESS_DEPTH,0,1);
#else #else