/*
 * fragment shader for rendering the skysphere
 *
 * does simple texturing
 *
 * written by:
 * christian moellinger <ch.moellinger@gmail.com>
 * 11/2010
 */

#version 330 core

out vec4 out_Color;
in vec3 my_Texcoord;
in vec3 my_EyeDir;
in vec3 my_Position;

uniform sampler2D color_texture;

void main(void)
{
    vec4 texture_value = texture(color_texture, my_Texcoord.st);

    const float LOG2 = 1.442695;
    float z = length(my_EyeDir);
    const float fog_density = 0.01;
    vec4 fogColor = vec4(0.4, 0.4, 0.6, 1.0);
    float fogFactor = exp2( -fog_density * fog_density * z * z * LOG2 ) * max(1.0 - min(-my_Position.y/6.0,0.0), 0.0);
    fogFactor = clamp(fogFactor, 0.0, 1.0);

    out_Color = mix(fogColor, texture_value, fogFactor);
}
