#version 330

in vec2 pPos;
out vec4 FragColor;

uniform float chill;
uniform float vortex;
uniform float vsnow;
uniform float red;
uniform int red_freq;

uniform int time;

float pi = 3.14159265358979323;

int xorshift(in int value) {
    value ^= value << 13;
    value ^= value >> 17;
    value ^= value << 5;
    return value;
}

float nextFloat(int seed) {
	seed = xorshift(seed);
	return mod(abs(fract(float(seed) / 3141.592653)), 1);
}

float smoothStep(float a) {
	return a * a * (3 - 2 * a);
}

float squared(float a) {
	return a * a;
}

void main()
{
	float distance = sqrt(pPos.x * pPos.x + pPos.y * pPos.y);

	//float vsnow_v = nextFloat(xorshift(floatBitsToInt(pPos.x)) + xorshift(floatBitsToInt(pPos.y)) + xorshift(time)) * vsnow;
	float red_v = distance * (1 - (abs(time / red_freq) % 100) / 100.0) * red;
	float vortex_v = (1 - distance) * squared(sin(distance * 10 + (time % 3141) / 100.0)) * vortex;
	float chill_v = (distance - 1 + chill) * nextFloat(xorshift(floatBitsToInt(pPos.x)) + xorshift(floatBitsToInt(pPos.y)));
	
	chill_v = (chill_v < 0.25 ? 0 : 1) * chill;

	FragColor = vec4(red_v, 0, 0, red_v) + vec4(0, 0, 0, vortex_v) + vec4(chill_v, chill_v, chill_v, chill_v);
}