#include "core.fsh"
#include "light.fsh"
#include "commonInput.fsh"

in highp vec4 pos_f;
in highp float ViewDepth_f;
flat in int ColorIdx_i;
uniform vec2 fadeRange;
uniform float baseIntensity;

uniform vec4  colorIntensity;
uniform float alphaIntensity;

uniform vec3 colors[7];

layout(location = 0) out vec4 fragColor;
void main()
{

    float alpha = clamp(pos_f.z, 0.0, 30.0) * 0.0333;
    alpha = pow((1.0 - alpha), 3.0) * baseIntensity;
    
    float fade = 1.0 - (ViewDepth_f - fadeRange.x) / (fadeRange.y - fadeRange.x);
    float fading = clamp(fade, 0.0, 1.0);
    alpha = alpha * fading;
    vec3 lightIntensity = CalLightIntensity(getNormal(), 1.0);
    
    float alpha_ = clamp(alpha - 0.25, 0.0, 1.0);
    fragColor = vec4(colors[ColorIdx_i] * lightIntensity * colorIntensity.rgb, alpha_ * alphaIntensity);
}
