Index: binaries/data/mods/public/shaders/glsl/water_high.fs
===================================================================
--- binaries/data/mods/public/shaders/glsl/water_high.fs	(revision 17749)
+++ binaries/data/mods/public/shaders/glsl/water_high.fs	(working copy)
@@ -127,19 +127,13 @@
 }
 
 void main()
-{
-	//gl_FragColor = texture2D(waterEffectsTex, gl_FragCoord.xy/screenSize);
-	//return;
-	
+{	
 	float fresnel;
-	float t;				// Temporary variable
 	vec2 reflCoords, refrCoords;
 	vec3 reflColor, refrColor, specular;
-	float losMod;
+	float losMod, reflMod;
 	
-	vec3 l = -sunDir;
 	vec3 v = normalize(cameraPos - worldPos);
-	vec3 h = normalize(l + v);
 	
 	// Calculate water normals.
 
@@ -147,16 +141,11 @@
 	float baseScale = waveParams1.g;
 	float flattenism = waveParams1.b;
 	float baseBump = waveParams1.a;
-
-	float smallIntensity = waveParams2.r;
-	float smallBase = waveParams2.g;
 	float BigMovement = waveParams2.b;
-	float SmallMovement = waveParams2.a;
 	
 	float moddedTime = mod(time * 60.0, 8.0) / 8.0;
 	
 	// This method uses 60 animated water frames. We're blending between each two frames
-	// TODO: could probably have fewer frames thanks to this blending.
 	// Scale the normal textures by waviness so that big waviness means bigger waves.
 	vec3 ww1 = texture2D(normalMap, (normalCoords.st + normalCoords.zw * BigMovement*waviness/10.0) * (baseScale - waviness/wavyEffect)).xzy;
 	vec3 ww2 = texture2D(normalMap2, (normalCoords.st + normalCoords.zw * BigMovement*waviness/10.0) * (baseScale - waviness/wavyEffect)).xzy;
@@ -165,18 +154,6 @@
 	ww1.x = wwInterp.x * WindCosSin.x - wwInterp.z * WindCosSin.y;
 	ww1.z = wwInterp.x * WindCosSin.y + wwInterp.z * WindCosSin.x;
 	ww1.y = wwInterp.y;
-	
-	vec3 smallWW = texture2D(normalMap, (normalCoords.st + normalCoords.zw * SmallMovement*waviness/10.0) * baseScale*3.0).xzy;
-	vec3 smallWW2 = texture2D(normalMap2, (normalCoords.st + normalCoords.zw * SmallMovement*waviness/10.0) * baseScale*3.0).xzy;
-	vec3 smallWWInterp = mix(smallWW, smallWW2, moddedTime) - vec3(0.5,0.0,0.5);
-
-	smallWW.x = smallWWInterp.x * WindCosSin.x - smallWWInterp.z * WindCosSin.y;
-	smallWW.z = smallWWInterp.x * WindCosSin.y + smallWWInterp.z * WindCosSin.x;
-	smallWW.y = smallWWInterp.y;
-
-	ww1 += vec3(smallWW)*(fwaviness/10.0*smallIntensity + smallBase);
-	
-	ww1 = mix(smallWW, ww1, waterInfo.r);
 		
 	// Flatten them based on waviness.
 	vec3 n = normalize(mix(vec3(0.0,1.0,0.0),ww1, clamp(baseBump + fwaviness/flattenism,0.0,1.0)));
@@ -189,17 +166,20 @@
 		n = mix(vec3(0.0,1.0,0.0), n,0.5 + waterInfo.r/2.0);
 	#endif
 
-	n = vec3(-n.x,n.y,-n.z);
+	n = vec3(-n.x,n.y,-n.z); // The final wave normal vector.
 	
-	// simulates how parallel the "point->sun", "view->point" vectors are.
-	float ndoth = dot(n , h);
-	
-	// how perpendicular to the normal our view is. Used for fresnel.
+	// How perpendicular to the normal our view is. Used for fresnel.
 	float ndotv = clamp(dot(n, v),0.0,1.0);
 	
-	// diffuse lighting-like. used for shadows?
-	float ndotl = (dot(n, l) + 1.0)/2.0;
+	// Fresnel for "how much reflection vs how much refraction".
+	fresnel = clamp(((pow(1.1 - ndotv, 3.0)) * 1.5), 0.2, 1.0); // Approximation. I'm using 1.1 and not 1.0 because it causes artifacts, see #1714
 	
+	// Specular lighting vectors
+	vec3 specVector = normalize(reflect(sunDir, n));
+	float specIntensity = pow(abs(dot(specVector, v)), 256.0);
+
+	specular = specIntensity * sunColor * fresnel;
+	
 	float depth;
 #if USE_REAL_DEPTH
 	// Don't change these two. They should match the values in the config (TODO: dec uniforms).
@@ -238,18 +218,6 @@
 	depth = max(depth,fancyeffects.a);
 #endif
 	
-	// Fresnel for "how much reflection vs how much refraction".
-	// Since we're not trying to simulate a realistic ocean 100%, aim for something that gives a little too much reflection
-	// because we're not used to seeing the see from above.
-	fresnel = clamp(pow(1.05 - ndotv, 1.1),0.0,0.8); // approximation. I'm using 1.05 and not 1.0 because it causes artifacts, see #1714
-	// multiply by v.y so that in the distance refraction wins.
-	// TODO: this is a hack because reflections don't work in the distance.
-	fresnel = clamp(fresnel*1.5,0.0,0.9);
-	fresnel *= min(1.0,log(1.0 + v.y*5.0));
-	
-	//gl_FragColor = vec4(fresnel,fresnel,fresnel,1.0);
-	//return;
-	
 #if USE_SHADOWS_ON_WATER && USE_SHADOW
 	float shadow = get_shadow(vec4(v_shadow.xy, v_shadow.zw));
 #endif
@@ -256,104 +224,78 @@
 	
 	// for refraction, we want to adjust the value by v.y slightly otherwise it gets too different between "from above" and "from the sides".
 	// And it looks weird (again, we are not used to seeing water from above).
-	float fixedVy = max(v.y,0.1);
+	float fixedVy = max(v.y,0.01);
 	
-	float distoFactor = clamp(depth/2.0,0.0,7.0);
-	
 	float murky = mix(200.0,0.1,pow(murkiness,0.25));
 	
 #if USE_REFRACTION
-	refrCoords = clamp( (0.5*refractionCoords.xy - n.xz * distoFactor*7.0) / refractionCoords.z + 0.5,0.0,1.0);	// Unbias texture coords
+	// distoFactor controls the amount of distortion relative to wave normals.
+	const float distoFactor = 3.5;
+	
+	// Distort the texture coords under where the water is to simulate refraction.
+	refrCoords = (0.5 * refractionCoords.xy - n.xz * distoFactor) / refractionCoords.z + 0.5;
 	vec3 refColor = texture2D(refractionMap, refrCoords).rgb;
-	if (refColor.r > refColor.g + refColor.b + 0.25)
+	
+	// Note, the refraction map is cleared using (255, 0, 0), so pixels outside of the water plane are pure red.
+	// If we get a pure red fragment, use an undistorted/less distorted coord instead.
+	if (refColor.r == 1.0)
 	{
-		refrCoords = clamp( (0.5*refractionCoords.xy + n.xz) / refractionCoords.z + 0.5,0.0,1.0);	// Unbias texture coords
+		refrCoords = (0.5*refractionCoords.xy) / refractionCoords.z + 0.5;
 		refColor = texture2D(refractionMap, refrCoords).rgb;
 	}
 	
-	// TODO: make murkiness (both types rematter on that.
-	// linearly extinct the water. This is how quickly we see nothing but the pure water color
+	// Apply water tint and murk color.
 	float extFact = max(0.0,1.0 - (depth*fixedVy/murky));
-	// This is how tinted the water is, ie how quickly the refracted floor takes the tint of the water
 	float ColextFact = max(0.0,1.0 - (depth*fixedVy/murky));
 	vec3 colll = mix(refColor*tint,refColor,ColextFact);
 	
-#if USE_SHADOWS_ON_WATER && USE_SHADOW
-	// TODO:
 	refrColor = mix(color, colll, extFact);
 #else
+	// Apply water tint and murk color only.
+	float extFact = max(0.0,1.0 - (depth*fixedVy/murky));
+	float ColextFact = max(0.0,1.0 - (depth*fixedVy/murky));
+	vec3 colll = mix(color*tint,color,ColextFact);
+	
 	refrColor = mix(color, colll, extFact);
 #endif
-#else
-	// linearly extinct the water. This is how quickly we see nothing but the pure water color
-	float extFact = max(0.0,1.0 - (depth*fixedVy/20.0));
-	// using both those factors, get our transparency.
-	// This will be our base transparency on top.
-	float base = 0.4 + depth*fixedVy/15.0; // TODO: murkiness.
-	float alphaCoeff = mix(1.0, base, extFact);
-	refrColor = color;
-#endif
 	
 #if USE_REFLECTION
 	// Reflections
-	// we use real reflections against th skybox, and distort a texture of objects closer.
+	// We use real reflections against the skybox, and distort a texture of objects closer.
 	vec3 eye = reflect(v,n);
-	//eye.y = min(-0.2,eye.y);
-	// let's calculate where we intersect with the skycube.
+	
+	// Calculate where we intersect with the skycube.
 	Ray myRay = Ray(vec3(worldPos.x/4.0,worldPos.y,worldPos.z/4.0),eye);
 	vec3 start = vec3(-1500.0 + mapSize/2.0,-100.0,-1500.0 + mapSize/2.0);
 	vec3 end = vec3(1500.0 + mapSize/2.0,500.0,1500.0 + mapSize/2.0);
 	float tmin = IntersectBox(myRay,start,end);
 	vec4 newpos = vec4(-worldPos.x/4.0,worldPos.y,-worldPos.z/4.0,1.0) + vec4(eye * tmin,0.0) - vec4(-mapSize/2.0,worldPos.y,-mapSize/2.0,0.0);
-	//newpos = normalize(newpos);
 	newpos *= skyBoxRot;
 	newpos.y *= 4.0;
 	reflColor = textureCube(skyCube, newpos.rgb).rgb;
-	
-	// Reflections appear more distorted when viewed from a lower angle. Simulate this.
-	float angleEffect = clamp(1.3 - dot(vec3(0.0,1.0,0.0), v),0.0,1.0);
 
-	reflCoords = clamp( (0.5*reflectionCoords.xy - 40.0 * n.zx * angleEffect) / reflectionCoords.z + 0.5,0.0,1.0);	// Unbias texture coords
+	// Distort the reflection coords based on waves.
+	reflCoords = (0.5*reflectionCoords.xy - 15.0 * n.zx) / reflectionCoords.z + 0.5;
 	vec4 refTex = texture2D(reflectionMap, reflCoords);
-	fresnel = clamp(fresnel+refTex.a/3.0,0.0,1.0);
-	reflColor = refTex.rgb * refTex.a + reflColor*(1.0-refTex.a);
 	
+	// Interpolate between the sky color and nearby objects.
+	reflColor = mix(reflColor.rgb, refTex.rgb, refTex.a);
+	// reflMod is used to reduce the intensity of sky reflections, which otherwise are too extreme.
+	reflMod = max(refTex.a, 0.55);
+	
 #else
-	// Temp fix for some ATI cards (see irc logs on th 1st of august betwee, fexor and wraitii)
-	//reflCoords = clamp( (0.5*reflectionCoords.xy - waviness * mix(1.0, 20.0,waviness/10.0) * n.zx) / reflectionCoords.z + 0.5,0.0,1.0);	// Unbias texture coords
-	//vec3 refTex = texture2D(reflectionMap, reflCoords).rgb;
-	//reflColor = refTex.rgb;
 	reflColor = vec3(0.15, 0.7, 0.82);
 #endif
 	
-	// TODO: At very low angles the reflection stuff doesn't really work any more:
-	// IRL you would get a blur of the sky, but we don't have that precision (would require mad oversampling)
-	// So tend towards a predefined color (per-map) which looks like what the skybox would look like if you really blurred it.
-	// The TODO here would be to precompute a band (1x32?) that represents the average color around the map.
-	// TODO: another issue is that at high distances (half map) the texture blurs into flatness. Using better mipmaps won't really solve it
-	// So we'll need to stop showing reflections and default to sky color there too.
-	// Unless maybe waviness is so low that you would see like in a mirror anyways.
-	//float disttt = distance(worldPos,cameraPos);
-	//reflColor = mix(vec3(0.5,0.5,0.55), reflColor, clamp(1.0-disttt/600.0*disttt/600.0,0.0,1.0));//clamp(-0.05 + v.y*20.0,0.0,1.0));
-	
-	// Specular.
-	specular = pow(ndoth, mix(5.0,2000.0, clamp(v.y*v.y*2.0,0.0,1.0)))*sunColor * 1.5;// * sunColor * 1.5 * ww.r;
-	
 	losMod = texture2D(losMap, losCoords.st).a;
 	losMod = losMod < 0.03 ? 0.0 : losMod;
 	
-	float wavesFresnel = 1.0;
-	
-#if USE_FANCY_EFFECTS
-	wavesFresnel = mix(1.0-fancyeffects.a,1.0,clamp(depth,0.0,1.0));
-#endif
-	
 	vec3 color;
 #if USE_SHADOWS_ON_WATER && USE_SHADOW
 	float fresShadow = mix(fresnel, fresnel*shadow, 0.05 + murkiness*0.2);
-	color = mix(refrColor, reflColor, fresShadow * wavesFresnel);
+	color = mix(refrColor, reflColor, fresShadow);
 #else
-	color = mix(refrColor, reflColor, fresnel * wavesFresnel);
+	color = mix(refrColor, reflColor, fresnel * reflMod);
 #endif
 	
 #if USE_SHADOWS_ON_WATER && USE_SHADOW
@@ -373,26 +315,18 @@
 	foaminterp *= mix(foam3, foam4, moddedTime);
 	
 	foam1.x = foaminterp.x * WindCosSin.x - foaminterp.z * WindCosSin.y;
-	//foam1.z = foaminterp.x * WindCosSin.y + foaminterp.z * WindCosSin.x;
-	//foam1.y = foaminterp.y;
+	
 	float foam = FoamEffects.r * FoamEffects.a*0.4 + pow(foam1.x*(5.0+waviness),(2.6 - waviness/5.5));
-	foam *= ndotl;
 	
-	gl_FragColor.rgb = get_fog(color) * losMod + foam * losMod;// + fancyeffects.a * losMod;
+	gl_FragColor.rgb = get_fog(color) * losMod + foam * losMod;
 #else
 	gl_FragColor.rgb = get_fog(color) * losMod;
 #endif
 	
-#if !USE_REFRACTION
-	gl_FragColor.a = clamp(depth*2.0,0.0,1.0) * alphaCoeff;
-#else
-	gl_FragColor.a = clamp(depth*5.0,0.0,1.0);
-#endif
+gl_FragColor.a = 1.0;
 	
 #if USE_FANCY_EFFECTS
 	if (fancyeffects.a < 0.05 && waterDepth < -1.0 )
 		gl_FragColor.a = 0.0;
 #endif
-	
-	//gl_FragColor = vec4(sunColor,1.0);
 }
Index: source/renderer/Renderer.cpp
===================================================================
--- source/renderer/Renderer.cpp	(revision 17749)
+++ source/renderer/Renderer.cpp	(working copy)
@@ -1119,8 +1119,8 @@
 	camera.ClipFrustum(CVector4D(0, 1, 0, -wm.m_WaterHeight));
 
 	SViewPort vp;
-	vp.m_Height = wm.m_ReflectionTextureSize;
-	vp.m_Width = wm.m_ReflectionTextureSize;
+	vp.m_Height = wm.m_RefTextureSize;
+	vp.m_Width = wm.m_RefTextureSize;
 	vp.m_X = 0;
 	vp.m_Y = 0;
 	camera.SetViewPort(vp);
@@ -1155,8 +1155,8 @@
 	camera.ClipFrustum(CVector4D(0, -1, 0, wm.m_WaterHeight + 0.5f));	// add some to avoid artifacts near steep shores.
 
 	SViewPort vp;
-	vp.m_Height = wm.m_RefractionTextureSize;
-	vp.m_Width = wm.m_RefractionTextureSize;
+	vp.m_Height = wm.m_RefTextureSize;
+	vp.m_Width = wm.m_RefTextureSize;
 	vp.m_X = 0;
 	vp.m_Y = 0;
 	camera.SetViewPort(vp);
@@ -1188,8 +1188,8 @@
 	// Save the model-view-projection matrix so the shaders can use it for projective texturing
 	wm.m_ReflectionMatrix = m_ViewCamera.GetViewProjection();
 
-	float vpHeight = wm.m_ReflectionTextureSize;
-	float vpWidth = wm.m_ReflectionTextureSize;
+	float vpHeight = wm.m_RefTextureSize;
+	float vpWidth = wm.m_RefTextureSize;
 
 	SScreenRect screenScissor;
 	screenScissor.x1 = (GLint)floor((scissor[0].X*0.5f+0.5f)*vpWidth);
@@ -1271,8 +1271,8 @@
 	// Save the model-view-projection matrix so the shaders can use it for projective texturing
 	wm.m_RefractionMatrix = m_ViewCamera.GetViewProjection();
 
-	float vpHeight = wm.m_RefractionTextureSize;
-	float vpWidth = wm.m_RefractionTextureSize;
+	float vpHeight = wm.m_RefTextureSize;
+	float vpWidth = wm.m_RefTextureSize;
 
 	SScreenRect screenScissor;
 	screenScissor.x1 = (GLint)floor((scissor[0].X*0.5f+0.5f)*vpWidth);
Index: source/renderer/WaterManager.cpp
===================================================================
--- source/renderer/WaterManager.cpp	(revision 17749)
+++ source/renderer/WaterManager.cpp	(working copy)
@@ -91,8 +91,7 @@
 	
 	m_ReflectionTexture = 0;
 	m_RefractionTexture = 0;
-	m_ReflectionTextureSize = 0;
-	m_RefractionTextureSize = 0;
+	m_RefTextureSize = 0;
 	
 	m_ReflectionFbo = 0;
 	m_RefractionFbo = 0;
@@ -236,19 +235,11 @@
 		m_FoamTex = texture;
 	}
 	
-	m_ReflectionTextureSize = g_Renderer.GetHeight() * 0.66;	// Higher settings give a better result
-	m_RefractionTextureSize = g_Renderer.GetHeight() * 0.33;	// Lower settings actually sorta look better since it blurs.
+	// Use screen-sized textures for minimum artifacts.
+	m_RefTextureSize = g_Renderer.GetHeight();
 	
-	if (round_down_to_pow2(m_ReflectionTextureSize)/m_ReflectionTextureSize < 0.65)
-		m_ReflectionTextureSize = round_up_to_pow2(m_ReflectionTextureSize);
-	else
-		m_ReflectionTextureSize = round_down_to_pow2(m_ReflectionTextureSize);
+	m_RefTextureSize = round_up_to_pow2(m_RefTextureSize);
 	
-	if (round_down_to_pow2(m_RefractionTextureSize)/m_RefractionTextureSize < 0.7)
-		m_RefractionTextureSize = round_up_to_pow2(m_RefractionTextureSize);
-	else
-		m_RefractionTextureSize = round_down_to_pow2(m_RefractionTextureSize);
-	
 	// Create reflection texture
 	glGenTextures(1, &m_ReflectionTexture);
 	glBindTexture(GL_TEXTURE_2D, m_ReflectionTexture);
@@ -256,7 +247,7 @@
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
-	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)m_ReflectionTextureSize, (GLsizei)m_ReflectionTextureSize, 0,  GL_RGBA, GL_UNSIGNED_BYTE, 0);
+	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)m_RefTextureSize, (GLsizei)m_RefTextureSize, 0,  GL_RGBA, GL_UNSIGNED_BYTE, 0);
 	
 	// Create refraction texture
 	glGenTextures(1, &m_RefractionTexture);
@@ -265,7 +256,7 @@
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
-	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, (GLsizei)m_RefractionTextureSize, (GLsizei)m_RefractionTextureSize, 0,  GL_RGB, GL_UNSIGNED_BYTE, 0);
+	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, (GLsizei)m_RefTextureSize, (GLsizei)m_RefTextureSize, 0,  GL_RGB, GL_UNSIGNED_BYTE, 0);
 
 	// Create depth textures
 	glGenTextures(1, &m_ReflFboDepthTexture);
@@ -274,7 +265,7 @@
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-	glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, (GLsizei)m_ReflectionTextureSize, (GLsizei)m_ReflectionTextureSize, 0,  GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL);
+	glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, (GLsizei)m_RefTextureSize, (GLsizei)m_RefTextureSize, 0,  GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL);
 	
 	glGenTextures(1, &m_RefrFboDepthTexture);
 	glBindTexture(GL_TEXTURE_2D, m_RefrFboDepthTexture);
@@ -282,7 +273,7 @@
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-	glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, (GLsizei)m_RefractionTextureSize, (GLsizei)m_RefractionTextureSize, 0,  GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL);
+	glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, (GLsizei)m_RefTextureSize, (GLsizei)m_RefTextureSize, 0,  GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL);
 
 	// Create the Fancy Effects texture
 	glGenTextures(1, &m_FancyTextureNormal);
Index: source/renderer/WaterManager.h
===================================================================
--- source/renderer/WaterManager.h	(revision 17749)
+++ source/renderer/WaterManager.h	(working copy)
@@ -103,8 +103,7 @@
 	// Reflection and refraction textures for fancy water
 	GLuint m_ReflectionTexture;
 	GLuint m_RefractionTexture;
-	size_t m_ReflectionTextureSize;
-	size_t m_RefractionTextureSize;
+	size_t m_RefTextureSize;
 
 	// framebuffer objects
 	GLuint m_RefractionFbo;
