precision highp int;
precision highp float;
 #include<OgreUnifiedShader.h>;
float calculateHalfWidth_(float lineWidth, float lineGapWidth)
{
    return lineGapWidth == 0.0 ? lineWidth / 2.0 : lineGapWidth / 2.0 + lineWidth;
}
float calculateHalfWidth(float lineWidth, float lineGapWidth)
{
    return 1.0 + calculateHalfWidth_(lineWidth, lineGapWidth);
}
varying float vUV_x;
varying float vUV_y;
varying vec3 vLineData;
varying float vHalfWidth;
varying vec4 vHazeColor;
vec3 grad0 = vec3(238.0 / 255.0, 175.0 / 255.0, 11.0 / 255.0);
vec3 grad1 = vec3(252.0 / 255.0, 82.0 / 255.0, 0.0);
vec3 grad2 = vec3(77.0 / 255.0, 0.0, 0.0);
uniform vec4 animatedGradientColorMask;
float _getScreenGradientInterpolationT(vec2 pixelSize, float pixelRatio)
{
    vec2 screenCoords = gl_FragCoord.xy * pixelSize / pixelRatio;
    float gradientT = length(vec2(screenCoords.x, 1.0 - screenCoords.y)) / sqrt(2.0);
    return gradientT;
}
vec3 _gradientColor(float gradientT)
{
    return gradientT < 0.5 ? mix(grad0, grad1, gradientT * 2.0)
                           : mix(grad1, grad2, gradientT * 2.0 - 1.0);
}
vec3 animatedRouteGradientColor(vec3 originalColor, float gradientT)
{
    float maskDist = length(originalColor - animatedGradientColorMask.rgb);
    if (animatedGradientColorMask.a == 0.0 || maskDist > 0.2)
    {
        return originalColor;
    }
    float blend = animatedGradientColorMask.a * (1.0 - maskDist / 0.2);
    return mix(originalColor, _gradientColor(gradientT), blend);
}
varying float vGradientT;
float antialiasedBorder(float value, float border)
{
    float epsilon = 0.2;
    float f = (value - border + epsilon) / (epsilon * 2.0);
    f = clamp(f, 0.0, 1.0);
    return f;
}
float calculateFactor(float distanceFromCenter, float lineGapWidth, float lineWidth)
{
    return lineGapWidth == 0.0
               ? antialiasedBorder(lineWidth / 2.0, distanceFromCenter)
               : antialiasedBorder(distanceFromCenter, lineGapWidth / 2.0) *
                     antialiasedBorder(lineGapWidth / 2.0 + lineWidth, distanceFromCenter);
}
vec4 calculateColor(float distanceFromCenter, vec3 lineData, vec4 lineColor, float lineDash,
                    float lineDashGap, float opacityMultiplier)
{
    float lineWidth = lineData[0];
    float lineGapWidth = lineData[1];
    float lineOpacity = lineData[2];
    vec4 color = lineColor;
    color.a *= lineOpacity * opacityMultiplier;
    float lineFactor = calculateFactor(distanceFromCenter, lineGapWidth, lineWidth);
    color.a *= lineFactor;
    return color;
}
uniform vec4 lineColor;
uniform float lineDash;
uniform float lineDashGap;
uniform float opacityMultiplier;
uniform float visibleDistance;
uniform float fadeOutLength;
void main()
{
    float distanceFromCenter = abs(vUV_x - 0.5) / 0.5 * vHalfWidth;
    float vertexDistance = vUV_y - 1.0;
    if ((visibleDistance >= 0.0) && (vertexDistance >= visibleDistance))
    {
        gl_FragColor = vec4(0.0);
        return;
    }
    vec4 baseColor = lineColor;
    vec4 color = calculateColor(distanceFromCenter, vLineData, baseColor, lineDash, lineDashGap,
                                opacityMultiplier);
    color.rgb = animatedRouteGradientColor(lineColor.rgb, vGradientT);
    if (fadeOutLength > 0.0)
    {
        float fadeOutStart = visibleDistance - fadeOutLength;
        float lighten = clamp((vertexDistance - fadeOutStart) / fadeOutLength, 0.0, 1.0);
        color.rgb = mix(color.rgb, grad0 + vec3(0.3), sqrt(lighten) * 0.5);
    }
    color.rgb = mix(color.rgb, vHazeColor.rgb, vHazeColor.a);
    color.rgb *= color.a;
    gl_FragColor = color;
}
