|
|
@ -76,7 +76,7 @@ uniform float near;
|
|
|
|
uniform float far;
|
|
|
|
uniform float far;
|
|
|
|
uniform vec3 nodePosition;
|
|
|
|
uniform vec3 nodePosition;
|
|
|
|
|
|
|
|
|
|
|
|
float transformDepth(float depth) // helper for transforming refraction depth
|
|
|
|
float transformDepth(float depth) // helper for transforming water 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 * (far - near));
|
|
|
|
depth = 2.0 * near * far / (far + near - z_n * (far - near));
|
|
|
@ -156,27 +156,30 @@ void main(void)
|
|
|
|
|
|
|
|
|
|
|
|
fresnel = clamp(fresnel, 0.0, 1.0);
|
|
|
|
fresnel = clamp(fresnel, 0.0, 1.0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if REFRACTION
|
|
|
|
float realWaterDepth = transformDepth(texture2D(refractionDepthMap, screenCoords).x);
|
|
|
|
float realWaterDepth = transformDepth(texture2D(refractionDepthMap, screenCoords).x);
|
|
|
|
|
|
|
|
|
|
|
|
float shore = clamp(realWaterDepth / REFLECTION_BUMP_SUPPRESS_DEPTH,0,1);
|
|
|
|
float shore = clamp(realWaterDepth / REFLECTION_BUMP_SUPPRESS_DEPTH,0,1);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
float shore = 1.0;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// reflection
|
|
|
|
// reflection
|
|
|
|
vec3 reflection = texture2D(reflectionMap, screenCoords+(normal.xy*REFL_BUMP*shore)).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
|
|
|
|
#if REFRACTION
|
|
|
|
float refractionDepth = transformDepth(texture2D(refractionDepthMap, screenCoords-(normal.xy*REFR_BUMP)).x);
|
|
|
|
float refractionDepth = transformDepth(texture2D(refractionDepthMap, screenCoords-(normal.xy*REFR_BUMP)).x);
|
|
|
|
float waterDepth = refractionDepth - depthPassthrough;
|
|
|
|
float waterDepth = refractionDepth - depthPassthrough;
|
|
|
|