precision mediump float;

uniform mat4 modelmat;
uniform mat4 pmat;
uniform mat3 normalmat;
uniform float t;
uniform vec3 lpos;
uniform float w;

attribute vec3 position;
attribute vec3 normal;
attribute float face;

varying float light;
varying vec3 color;

void main() {
	vec4 wpos = modelmat * vec4(position, w);
	gl_Position = pmat * wpos;
	light = max(0.2, .9 * dot(normalize(lpos - wpos.xyz), normalize(normalmat * normal)));
	color = mod(face, 2.0) > 0.0 ? vec3(1.0, 0.5, 0.0) : vec3(0.5, 1.0, 0.0);
}
precision mediump float;

varying float light;
varying vec3 color;

void main() {
	gl_FragColor = vec4(color, light);
}