#version 400 core

uniform transform {
	mat4 ModelViewMatrix;
	mat4 ProjectionMatrix;
} Transform;

uniform vec3 LightDir;


layout(location = 0) in vec3 VertexPosition;
layout(location = 1) in vec3 VertexNormal;
layout(location = 2) in vec2 VertexTexCoord;
layout(location = 3) in vec4 InstancePosition;

out vec4 FogParam;
out vec3 InterpNormal;
out vec2 InterpTexCoord;
out vec3 InterpViewDir;
out vec3 InterpLightDir;

void main(void) {

	//Get instance position from texture buffer and add the local vertex coordinate to it
	vec4 ObjectSpacePosition = InstancePosition + vec4(VertexPosition, 1.0);
	
	//Transform into view space
	vec4 ViewSpacePosition = Transform.ModelViewMatrix * ObjectSpacePosition;
	
	//Calculate fog related information 
	vec3 FogColor = vec3(0, 0, 0);
	FogParam.xyz = FogColor;
	FogParam.w = exp(length(ViewSpacePosition.xyz) / 600.0) / 2.6;
    
	InterpNormal = VertexNormal;
	InterpTexCoord = VertexTexCoord;	
	InterpViewDir = vec3( 0.0, 0.0, 1.0 );
	InterpLightDir = LightDir; 

	gl_Position = Transform.ProjectionMatrix * ViewSpacePosition;
}
