// BTS Patches V1 — Replacement code for calcSkyColor()
// This file contains ONLY our original replacement code. It does NOT contain
// any code from Sildur's Enhanced Default. The mod reads the user's own copy
// of gbuffers_skybasic.fsh from their Sildur's shaderpack and applies these
// replacements at runtime.
//
// Two replacements are performed:
// 1. Insert "uniform vec3 sunPosition;" after "uniform vec3 skyColor;"
// 2. Replace the calcSkyColor() function body with the version below

// --- REPLACEMENT 1: Uniform declaration ---
// FIND:   uniform vec3 skyColor;\nvarying vec4 glColor;
// REPLACE WITH: (adds sunPosition uniform)
uniform vec3 skyColor;
uniform vec3 sunPosition;
varying vec4 glColor;

// --- REPLACEMENT 2: calcSkyColor function ---
// FIND: (the original function)
//   vec3 calcSkyColor(vec3 pos) {
//       float up = max(dot(pos, gbufferModelView[1].xyz), 0.0);
//       return mix(skyColor, fogColor, 0.025 / (up * up + 0.025));
//   }
// REPLACE WITH: (sun-position-driven sky override)
vec3 calcSkyColor(vec3 pos) {
	float up = max(dot(pos, gbufferModelView[1].xyz), 0.0);
	vec3 vanillaGradient = mix(skyColor, fogColor, 0.025 / (up * up + 0.025));
	float sunUp = dot(normalize(sunPosition), gbufferModelView[1].xyz);
	float t = clamp((sunUp - (-0.1)) / (0.3 - (-0.1)), 0.0, 1.0);
	float override = 1.0 - t * t * (3.0 - 2.0 * t);
	return mix(vanillaGradient, fogColor, override);
}
