     // The double normalize below works around a bug in Firefox on Android devices.
     vec3 normalizedpositionToEyeEC = normalize(normalize(positionToEyeEC));
     
-    // fade is a function of the distance from the fragment and the frequency of the waves
-    //float fade = max(1.0, (positionToEyeECLength / 10000000000.0) * frequency * fadeFactor);
-    float waveIntensity = 1.0 - linearstep(70000.0, 700000.0, positionToEyeECLength);
-    //float fade = 1.0;
+    // Fade out the waves as the camera moves far from the surface.
+    float waveIntensity = waveFade(70000.0, 1000000.0, positionToEyeECLength);
             
     vec4 noise = getNoise(textureCoordinates * frequency, time);
     vec3 normalTangentSpace = noise.xyz * vec3(1.0, 1.0, (1.0 / amplitude));

    
    material.normal = enuToEye * normalTangentSpace;

    float diffuseIntensity = max(dot(czm_sunDirectionEC, material.normal), 0.0);

    material.emission = imageryColor + mix(vec3(0.3, 0.45, 0.6) * 5.0 * (1.0 - tsPerturbationRatio), vec3(0.0), diffuseIntensity);
    material.diffuse = vec3(0.3, 0.45, 0.6);
    //material.diffuse = vec3(0.2, 0.2, 0.3);
    //material.diffuse = vec3(mix(0.0, 0.2 * tsPerturbationRatio, specularMapValue));
    material.specular = mix(0.0, mix(zoomedOutSpecularIntensity, specularIntensity, waveIntensity), specularMapValue);
    material.shininess = 10.0;
    
    return czm_phong(normalizedpositionToEyeEC, material);
    //return vec4(1.0 / fade, 0.0, 0.0, 1.0);
    //return vec4(normalTangentSpace.x, normalTangentSpace.y, normalTangentSpace.z, 1.0);
}

    return ((noise / 4.0) - 0.5) * 2.0;
}

float waveFade(float edge0, float edge1, float x)
{
	float y = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
	return pow(1.0 - y, 5.0);
}

vec4 computeWaterColor(vec3 positionEyeCoordinates, vec2 textureCoordinates, mat3 enuToEye, vec3 imageryColor, float specularMapValue)
