/*
 * Visuality border fog
 *
 * Minecraft simply stops sending chunks past your render distance, so
 * without this the world ends with a hard edge - terrain, trees, and
 * anything else just vanishes into the void the moment it crosses that
 * line. This fades everything into the horizon fog colour over the last
 * stretch before that edge instead, so it reads as the world dissolving
 * into haze rather than popping out of existence.
 *
 * This runs independently from the day/rain atmospheric fog just above it
 * in composite.fsh. That fog is tuned for mood/time of day (fogAmount is
 * tiny on a clear day) and is often nowhere near strong enough to hide the
 * render distance edge on its own, especially at higher render distances.
 * Border fog ignores fogAmount entirely and always reaches full opacity
 * right at `far`, whatever the weather or time of day is doing.
 *
 * Requires (already available wherever this is included from composite.fsh):
 *   far (render distance far-plane, in blocks - standard pipeline uniform)
 */

#define BORDER_FOG //Fades terrain into the sky/fog colour near the edge of your render distance instead of letting it cut off abruptly
#define BORDER_FOG_START 0.64 //[0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95] Fraction of your render distance where the fade begins - lower starts fading sooner, higher keeps things clear for longer
#define BORDER_FOG_CURVE 1.9 //[1.0 1.5 2.0 2.5 3.0 4.0 5.0 6.0 8.0] How sharply the fade ramps up - higher stays clearer for most of the fade then thickens fast right at the border, lower spreads it out more evenly

#ifdef BORDER_FOG
/* Returns 0 (untouched) to 1 (fully replaced by fog colour) based on how
 * close this fragment is to the edge of the render distance. */
float getBorderFog(float dist, float farPlane){
	float fadeStart = farPlane*BORDER_FOG_START;
	float t = clamp((dist-fadeStart)/max(farPlane-fadeStart, 1.0), 0.0, 1.0);
	return pow(t, BORDER_FOG_CURVE);
}
#endif
