#version 130 

uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;

uniform vec3 sunPosition;
uniform vec3 pickedPos;
uniform float textureScale;
uniform float blockAlpha;

in vec3 vPosition;
in vec3 vNormal;
in vec3 vMaterial;
in vec3 vAlpha;
in float vIntensity;

out vec3 fNormal;
out vec3 fMaterial;
out vec3 fWorldPos;
out vec3 fAlpha;
out float fIntensity;
out float fAmbientOcclusion;
out float fDistance;
out float pickDistance;

void main()
{	
	mat4 modelViewProjectionMatrix = projectionMatrix * modelViewMatrix;
	
	vec3 vVertex = vec3(modelViewProjectionMatrix * vec4(vPosition, 1));
	
	fWorldPos = vPosition;
	fNormal = vNormal;
	fMaterial = vMaterial;
	fAlpha = vAlpha;
	fDistance = length(vVertex);
	fAmbientOcclusion = vIntensity;
	
	vec3 positionToSun = sunPosition - vPosition;
	float seeSun = dot(normalize(positionToSun), normalize(vPosition));
	float C = 0.6;	 
	seeSun = clamp(seeSun, 0, C);
	fIntensity = seeSun / C;
	
	//pickDistance = max(0, 2.0 - length(pickedPos - vPosition));
			
	//----- Output to fragment shader (required by triplanar texturing)		
	gl_Position = modelViewProjectionMatrix * vec4(vPosition, 1);
}
