#version 330


layout (std140) uniform Matrices {
	mat4 m_pvm;
	mat3 m_normal;	
	mat4 m_model;
	mat4 m_viewModel;
};

layout (std140) uniform Materials {
	vec4 diffuse;
	vec4 ambient;
	vec4 specular;
	vec4 emissive;
	float shininess;	
};

layout (std140) uniform Lights {
	vec3 l_dir;	   // camera space
};
layout (std140) uniform UserClip {
	vec4 cl_Plane0;
	vec4 cl_Plane1;
	vec4 cl_Plane2;
	vec4 cl_Plane3;
	vec4 cl_Plane4;
};

layout(location=0) in vec4 position;	// local space
layout(location=1) in vec3 normal;		// local space

out float gl_ClipDistance[1];

// the data to be sent to the fragment shader
out Data {
	vec3 norm;
	vec3 lightDir;
	vec4 colr;
} DataOut;

void main () {
	// compute normals and projected position
	DataOut.norm = normalize(m_normal * normal);
	gl_Position = m_pvm * position;

	//pass through color and light direction to fragment shader
	DataOut.colr = diffuse;
	DataOut.lightDir = l_dir;
	
	// only 1 clipping plane enabled
	gl_ClipDistance[0] = dot(m_model * position, cl_Plane0);	
}