#version 130

uniform vec2 screenSize = vec2(1024, 768);
uniform float renderScale = 1;
uniform vec2 mapScroll = vec2(0, 0);
uniform float lightLevel = 1;
uniform float time = 0;

uniform vec4 fogColour = vec4(1, 1, 1, 1);
uniform float fogDensity = 0.1;

uniform vec2 windVector = vec2(0, 0);
uniform vec4 lightColour = vec4(1, 1, 1, 1);

#include "Shared/Perlin.frag"

void main()
{
	vec4 pixel = gl_Color;

	vec2 screenPos = gl_FragCoord.xy;
	screenPos.y = screenSize.y - screenPos.y;

	vec2 uvPerlin = (mapScroll + (screenPos / renderScale)) * 0.001;

	uvPerlin -= windVector * time * 0.01;
	
	float sample1 = perlin2D(uvPerlin, 2, 1, 18231u);
	float sample2 = perlin2D(uvPerlin, 2, 1, 329342u);

	float sample = (sample1 + sample2) * 0.5;
	sample = clamp(sample + 0.45, 0.1, 0.9);


	vec4 noisePixel = vec4(sample * fogColour.r, sample * fogColour.g, sample * fogColour.b, 1);
	pixel = noisePixel;

	pixel = mix(pixel, lightColour, 0.3);

	pixel.a = clamp(sample * min(fogDensity, 1.0) * 1.25, 0, 1);

	gl_FragColor = pixel;
}
