#version 330

uniform float exposure;
uniform float far;
uniform vec3 camPos;
uniform vec3 sunDir;
uniform mat4 viewT;
uniform mat4 proj;

layout(location = 0) in vec4 position;
layout(location = 4) in vec4 coord;

out PS {
	vec2 coord;
	vec2 sun;
	float exposure;
} ps;

void main(void){
	vec4 sunCoord = proj * (vec4(camPos.xyz + sunDir.xyz * far, 1.0) * viewT);
	sunCoord /= sunCoord.w;

	vec3 viewDir = -viewT[2].xyz;

	gl_Position = position;
	ps.coord = coord.xy;
	ps.sun = sunCoord.xy*0.5 + 0.5;
	// note: pow value must be a non power of 2 value to keep the sign
	ps.exposure = exposure * max(0, pow(dot(viewDir.xyz, sunDir.xyz), 3));
}