     return ((noise / 4.0) - 0.5) * 2.0;
 }
 
-float linearstep(float edge0, float edge1, float x)
+float waveFade(float edge0, float edge1, float x)
 {
-    return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
+	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)

    // 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;
            
    vec4 noise = getNoise(textureCoordinates * frequency, time);
    vec3 normalTangentSpace = noise.xyz * vec3(1.0, 1.0, (1.0 / amplitude));

    
    material.normal = enuToEye * normalTangentSpace;

    float diffuseIntensity = getLambertDiffuse(czm_sunDirectionEC, material);
    
    const vec3 waveHighlightColor = vec3(0.3, 0.45, 0.6);

    material.emission = imageryColor + mix(waveHighlightColor * 5.0 * (1.0 - tsPerturbationRatio), vec3(0.0), diffuseIntensity);
    material.diffuse = waveHighlightColor;
    material.specular = mix(0.0, mix(zoomedOutSpecularIntensity, specularIntensity, waveIntensity), specularMapValue);
    material.shininess = 10.0;
    
    return czm_phong(normalizedpositionToEyeEC, material);
}
