|
|
@ -6,7 +6,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
// tweakables -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
|
// tweakables -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
|
|
|
|
|
|
|
|
|
const float VISIBILITY = 1200.0; // how far you can look through water
|
|
|
|
const float VISIBILITY = 2.5;
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
@ -31,6 +31,8 @@ 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 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;
|
|
|
|
|
|
|
|
|
|
|
@ -56,9 +58,9 @@ float fresnel_dielectric(vec3 Incoming, vec3 Normal, float eta)
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
varying vec3 screenCoordsPassthrough;
|
|
|
|
varying vec3 screenCoordsPassthrough;
|
|
|
|
varying vec4 position;
|
|
|
|
varying vec4 position;
|
|
|
|
varying float depthPassthrough;
|
|
|
|
varying float depthPassthrough;
|
|
|
|
|
|
|
|
|
|
|
|
uniform sampler2D normalMap;
|
|
|
|
uniform sampler2D normalMap;
|
|
|
|
|
|
|
|
|
|
|
@ -74,8 +76,18 @@ uniform float near;
|
|
|
|
uniform float far;
|
|
|
|
uniform float far;
|
|
|
|
uniform vec3 nodePosition;
|
|
|
|
uniform vec3 nodePosition;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float frustumDepth;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float linearizeDepth(float depth) // takes <0,1> non-linear depth value and returns <0,1> linearized value
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
float z_n = 2.0 * depth - 1.0;
|
|
|
|
|
|
|
|
depth = 2.0 * near * far / (far + near - z_n * frustumDepth);
|
|
|
|
|
|
|
|
return depth / frustumDepth;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void main(void)
|
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
frustumDepth = abs(far - near);
|
|
|
|
vec3 worldPos = position.xyz + nodePosition.xyz;
|
|
|
|
vec3 worldPos = position.xyz + nodePosition.xyz;
|
|
|
|
vec2 UV = worldPos.xy / (8192.0*5.0) * 3.0;
|
|
|
|
vec2 UV = worldPos.xy / (8192.0*5.0) * 3.0;
|
|
|
|
UV.y *= -1.0;
|
|
|
|
UV.y *= -1.0;
|
|
|
@ -147,32 +159,37 @@ void main(void)
|
|
|
|
|
|
|
|
|
|
|
|
fresnel = clamp(fresnel, 0.0, 1.0);
|
|
|
|
fresnel = clamp(fresnel, 0.0, 1.0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if REFRACTION
|
|
|
|
|
|
|
|
float normalization = frustumDepth / 1000;
|
|
|
|
|
|
|
|
float depthSample = linearizeDepth(texture2D(refractionDepthMap,screenCoords).x) * normalization;
|
|
|
|
|
|
|
|
float depthSampleDistorted = linearizeDepth(texture2D(refractionDepthMap,screenCoords-(normal.xy*REFR_BUMP)).x) * normalization;
|
|
|
|
|
|
|
|
float surfaceDepth = linearizeDepth(gl_FragCoord.z) * normalization;
|
|
|
|
|
|
|
|
float realWaterDepth = depthSample - surfaceDepth; // undistorted water depth in view direction, independent of frustum
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float shore = clamp(realWaterDepth / BUMP_SUPPRESS_DEPTH,0,1);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
float shore = 1.0;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// reflection
|
|
|
|
// reflection
|
|
|
|
vec3 reflection = texture2D(reflectionMap, screenCoords+(normal.xy*REFL_BUMP)).rgb;
|
|
|
|
vec3 reflection = texture2D(reflectionMap, screenCoords+(normal.xy*REFL_BUMP*shore)).rgb;
|
|
|
|
|
|
|
|
|
|
|
|
// refraction
|
|
|
|
// refraction
|
|
|
|
#if REFRACTION
|
|
|
|
#if REFRACTION
|
|
|
|
vec3 refraction = texture2D(refractionMap, screenCoords-(normal.xy*REFR_BUMP)).rgb;
|
|
|
|
vec3 refraction = texture2D(refractionMap, screenCoords-(normal.xy*REFR_BUMP*shore)).rgb;
|
|
|
|
|
|
|
|
|
|
|
|
// brighten up the refraction underwater
|
|
|
|
// brighten up the refraction underwater
|
|
|
|
refraction = (cameraPos.z < 0.0) ? clamp(refraction * 1.5, 0.0, 1.0) : refraction;
|
|
|
|
refraction = (cameraPos.z < 0.0) ? clamp(refraction * 1.5, 0.0, 1.0) : refraction;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// specular
|
|
|
|
// specular
|
|
|
|
vec3 R = reflect(vVec, normal);
|
|
|
|
vec3 R = reflect(vVec, normal);
|
|
|
|
float specular = pow(max(dot(R, lVec), 0.0),SPEC_HARDNESS) * shadow;
|
|
|
|
float specular = pow(max(dot(R, lVec), 0.0),SPEC_HARDNESS) * shadow;
|
|
|
|
|
|
|
|
|
|
|
|
vec3 waterColor = WATER_COLOR;
|
|
|
|
vec3 waterColor = WATER_COLOR;
|
|
|
|
waterColor = waterColor * length(gl_LightModel.ambient.xyz);
|
|
|
|
waterColor = waterColor * length(gl_LightModel.ambient.xyz);
|
|
|
|
#if REFRACTION
|
|
|
|
|
|
|
|
float refractionDepth = texture2D(refractionDepthMap, screenCoords-(normal.xy*REFR_BUMP)).x;
|
|
|
|
|
|
|
|
float z_n = 2.0 * refractionDepth - 1.0;
|
|
|
|
|
|
|
|
refractionDepth = 2.0 * near * far / (far + near - z_n * (far - near));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float waterDepth = refractionDepth - depthPassthrough;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if REFRACTION
|
|
|
|
if (cameraPos.z > 0.0)
|
|
|
|
if (cameraPos.z > 0.0)
|
|
|
|
refraction = mix(refraction, waterColor, clamp(waterDepth/VISIBILITY, 0.0, 1.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;
|
|
|
|
gl_FragData[0].xyz = mix( mix(refraction, scatterColour, lightScatter), reflection, fresnel) + specular * gl_LightSource[0].specular.xyz;
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|