#version 150

#moj_import <fog.glsl>

uniform mat4 ProjMat;
uniform vec4 ColorModulator;
uniform vec4 FogColor;
uniform float FogStart;
uniform float FogEnd;

in vec4 vertexColor;
in float vertexDistance;

out vec4 fragColor;

// Custom cloud fog algorithm by Balint, for use in Sodium
void main() {
    if (color.a < 0.1) { discard; }
	
	// [1/1] 5TMOD: TINT FOG COLOR INTO CLOUD COLOR
	// Edit "(fogStart * [THIS])" to set amount
		vec4 color = (vertexColor * ColorModulator) * (FogColor * 0.4);
		//vec4 color = vertexColor = (vertexColor * ColorModulator) * (FogColor * 0.4);
		//vertexColor.a -= 0.5;
	// [1/1] 5TMOD_END

    float width = FogEnd - FogStart;
    float newWidth = width * 4.0;
    float fade = linear_fog_fade(vertexDistance, FogStart, FogStart + newWidth) * FogColor.a;
	
    fragColor = vec4(mix(FogColor.rgb, color.rgb, 0.7), clamp(color.a * fade, 0.0, 1.0));
}

