#version 420

uniform float seed;
uniform float d_t;
uniform float d_ice;
uniform sampler2D prev;
uniform float ice;

layout(location = 1) in vec2 tex_coord;
layout(location = 0) out vec4 color_out;
layout(location = 0) in vec3 tex_norm;

float gold_noise(vec2 coordinate, float seed_1)
{
    return fract(sin(dot(coordinate * (seed_1 + 0.1618033945560455322265625), vec2(0.1618033945560455322265625, 0.31415927410125732421875))) * 14142.1357421875);
}

float origin_distance()
{
    if (tex_coord.x < 0.100000001490116119384765625)
    {
        return length(vec2((0.100000001490116119384765625 - tex_coord.x) * 10.0, tex_coord.y - 0.5));
    }
    if (tex_coord.x > 0.89999997615814208984375)
    {
        return length(vec2((tex_coord.x - 0.89999997615814208984375) * 10.0, tex_coord.y - 0.5));
    }
    return abs(tex_coord.y - 0.5);
}

vec4 remove_ice(float prev_depth)
{
    vec2 param = gl_FragCoord.xy;
    float param_1 = seed;
    float rand_val = gold_noise(param, param_1);
    float dist = clamp(1.0 - origin_distance(), 0.0, 1.0);
    float extra_ice = 0.0;
    if (rand_val < (d_t * (((((dist * dist) * dist) * dist) * dist) * dist)))
    {
        extra_ice = min(100.0 * d_ice, -0.001000000047497451305389404296875);
    }
    return vec4(max(prev_depth + extra_ice, 0.0), 0.0, 0.0, 1.0);
}

void main()
{
    float prev_depth = texture(prev, tex_coord).x;
    float param = prev_depth;
    color_out = remove_ice(param);
}

